From t.roberts at cqu.edu.au Sun Feb 1 00:36:43 2009 From: t.roberts at cqu.edu.au (Tim Roberts) Date: Sun, 1 Feb 2009 15:36:43 +1000 Subject: nth root References: <1AE19A80523D5F40BE0044A1447A53FF0ADB972E@UNIMAIL.staff.ad.cqu.edu.au> Message-ID: <1AE19A80523D5F40BE0044A1447A53FF0ADB9733@UNIMAIL.staff.ad.cqu.edu.au> Actually, all I'm interested in is whether the 100 digit numbers have an exact integral root, or not. At the moment, because of accuracy concerns, I'm doing something like for root in powersp: nroot = round(bignum**(1.0/root)) if bignum==long(nroot)**root: ......... which is probably very inefficient, but I can't see anything better..... Tim From steve at savechicago.org Sun Feb 1 00:40:52 2009 From: steve at savechicago.org (steve at savechicago.org) Date: Sat, 31 Jan 2009 21:40:52 -0800 (PST) Subject: Please help to play 5 jpegs as a slideshow in JES(Jython) --- BEGINNER. Message-ID: <28dec764-64e4-4a47-87d5-ba3b52e3b051@r36g2000prf.googlegroups.com> Hello, I am a brand brand new programming student in Jython and I have been working on a simple homework assignment in JES for the last 12 hours and am completely lost. Basically, we have to make a jpeg slideshow with 5 different pictures with audio background that lasts 60 seconds. I have absolutely no idea where to begin and am more lost than I was 12 hours ago. def pickAndShow(): myfile = pickAFile() mypicture = makePicture(myfile) show(mypicture) I know this is how to call up a picture from your hard drive. That?s about all I know. I have no idea how to call up 5 of them, one at a time, and with audio in the background. And how to make this happen with a command. Can someone help me? From dchandran1 at tinkercell.com Sun Feb 1 00:47:27 2009 From: dchandran1 at tinkercell.com (Deepak Chandran) Date: Sat, 31 Jan 2009 21:47:27 -0800 Subject: Embedding numpy works once, but not twice?? Message-ID: <5dfe78f40901312147i957450ei187b08028c068a6@mail.gmail.com> I have a program in which I have successfully embedded Python. Now, I want to include NumPy as well (and other modules). I am able to import numpy once. Then I close the python console in my program and then re-open it. When I try to import numpy for a second time, the program crashes. Below is a simple version of the problem. The main() import numpy twice. The first import works fine -- prints "no errors.". But the second load crashes the program. What is going on here? By the way, this is all in Windows (XP and Vista have same problem) using python25.dll (since numpy does not work for python26.dll). I am using MinGW compiler. #include #include #include int load(char * code) { PyObject *errobj, *errdata, *errtraceback, *pystring; int retval; Py_Initialize(); PyObject *main = PyImport_AddModule("__main__"); PyObject* main_dict = PyModule_GetDict( main ); PyObject * rstring = PyRun_String( code, Py_file_input, main_dict, main_dict ); //the second main_dict was my_program_dict originally PyErr_Fetch (&errobj, &errdata, &errtraceback); if (errdata != NULL) { PyObject *s = PyObject_Str(errdata); char * c = PyString_AS_STRING(s); printf("%s\n",c); //print any errors Py_DECREF(s); } else { printf("no errors.\n"); } Py_XDECREF(errobj); Py_XDECREF(errdata); Py_XDECREF(errtraceback); Py_Finalize(); return 0; } int main() { load("import numpy\n"); load("import numpy\n"); } //output is: // no errors // -------------- next part -------------- An HTML attachment was scrubbed... URL: From http Sun Feb 1 00:53:23 2009 From: http (Paul Rubin) Date: 31 Jan 2009 21:53:23 -0800 Subject: nth root References: <1AE19A80523D5F40BE0044A1447A53FF0ADB972E@UNIMAIL.staff.ad.cqu.edu.au> Message-ID: <7x4ozen1nw.fsf@ruckus.brouhaha.com> "Tim Roberts" writes: > Actually, all I'm interested in is whether the 100 digit numbers > have an exact integral root, or not. At the moment, because of > accuracy concerns, I'm doing something like > > for root in powersp: > nroot = round(bignum**(1.0/root)) > if bignum==long(nroot)**root: > ......... > which is probably very inefficient, but I can't see anything better..... First of all, convert the bignum to a float outside of the loop. Second, precompute the inverses 1.0/2.0, 1.0/3.0, .... Third, do the exponentiation and comparison only if the float equivalent is very close. I bet almost all the time you're spending is in bignum to float conversion. The article Daniel J. Bernstein (1998). "Detecting perfect powers in essentially linear time". Mathematics of Computation 67 (223): 1253-1283 (http://cr.yp.to/papers/powers-ams.pdf) may be of interest. From sjmachin at lexicon.net Sun Feb 1 01:14:38 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 31 Jan 2009 22:14:38 -0800 (PST) Subject: Searching a file for multiple strings (PS) References: <7b0df317-c3cb-4013-9b68-42d0ee9869df@f24g2000vbf.googlegroups.com> <4984AA57.3050106@tim.thechases.com> <4984ADDB.2070509@tim.thechases.com> Message-ID: <6ecdebf6-a422-4f5a-a99b-2c3ed461d980@w1g2000prk.googlegroups.com> On Feb 1, 3:39?pm, Shawn Milochik wrote: > Not to discourage the use of Python, but it seems that fgrep with the > -f flag already does exactly what you want. If you're on Windows, you > can get the Windows version of fgrep here: http://unxutils.sourceforge.net/ That URL is antique and a dead end. When you find the actual sourceforge project page (http://sourceforge.net/projects/unxutils/) and browse the forums and the CVS repository, you'll see tumbleweed blowing down Main Street and not much else (besides a few whinges about that dead end URL, and many unanswered issues). Alternative: http://gnuwin32.sourceforge.net/ From http Sun Feb 1 01:17:07 2009 From: http (Paul Rubin) Date: 31 Jan 2009 22:17:07 -0800 Subject: nth root References: <1AE19A80523D5F40BE0044A1447A53FF0ADB972E@UNIMAIL.staff.ad.cqu.edu.au> Message-ID: <7xk58a7kbg.fsf@ruckus.brouhaha.com> "Tim Roberts" writes: > for root in powersp: > nroot = round(bignum**(1.0/root)) > if bignum==long(nroot)**root: > ......... > which is probably very inefficient, but I can't see anything better..... Actually that will not be accurate enough to know if bignum is, say, a perfect square. You will have to do the small-power tests at full precision (or use a fancy algorithm). Larger powers can be done with floats. From t.roberts at cqu.edu.au Sun Feb 1 01:17:53 2009 From: t.roberts at cqu.edu.au (Tim Roberts) Date: Sun, 1 Feb 2009 16:17:53 +1000 Subject: nth root References: <1AE19A80523D5F40BE0044A1447A53FF0ADB972E@UNIMAIL.staff.ad.cqu.edu.au> <7x4ozen1nw.fsf@ruckus.brouhaha.com> Message-ID: <1AE19A80523D5F40BE0044A1447A53FF0ADB9737@UNIMAIL.staff.ad.cqu.edu.au> Paul, Yes, very good, on all counts. Many thanks. Tim ________________________________ From: Paul Rubin [mailto:"http://phr.cx"@NOSPAM.invalid] Sent: Sun 01-Feb-09 3:53 PM To: python-list at python.org Subject: Re: nth root "Tim Roberts" writes: > Actually, all I'm interested in is whether the 100 digit numbers > have an exact integral root, or not. At the moment, because of > accuracy concerns, I'm doing something like > > for root in powersp: > nroot = round(bignum**(1.0/root)) > if bignum==long(nroot)**root: > ......... > which is probably very inefficient, but I can't see anything better..... First of all, convert the bignum to a float outside of the loop. Second, precompute the inverses 1.0/2.0, 1.0/3.0, .... Third, do the exponentiation and comparison only if the float equivalent is very close. I bet almost all the time you're spending is in bignum to float conversion. The article Daniel J. Bernstein (1998). "Detecting perfect powers in essentially linear time". Mathematics of Computation 67 (223): 1253-1283 (http://cr.yp.to/papers/powers-ams.pdf) may be of interest. -- http://mail.python.org/mailman/listinfo/python-list From cournape at gmail.com Sun Feb 1 01:27:18 2009 From: cournape at gmail.com (David Cournapeau) Date: Sun, 1 Feb 2009 15:27:18 +0900 Subject: Embedding numpy works once, but not twice?? In-Reply-To: <5dfe78f40901312147i957450ei187b08028c068a6@mail.gmail.com> References: <5dfe78f40901312147i957450ei187b08028c068a6@mail.gmail.com> Message-ID: <5b8d13220901312227i1db85215wf3d544622beeaa2e@mail.gmail.com> On Sun, Feb 1, 2009 at 2:47 PM, Deepak Chandran wrote: > I have a program in which I have successfully embedded Python. Now, I want > to include NumPy as well (and other modules). I am able to import numpy > once. Then I close the python console in my program and then re-open it. > When I try to import numpy for a second time, the program crashes. Below is > a simple version of the problem. > The main() import numpy twice. The first import works fine -- prints "no > errors.". But the second load crashes the program. What is going on here? > > By the way, this is all in Windows (XP and Vista have same problem) using > python25.dll (since numpy does not work for python26.dll). I am using MinGW > compiler. FYI, numpy can work with python 2.6 if you build from recent svn. numpy 1.3.0 will have 2.6 binaries I can't really help you for your problem, I am not familiar with python embedding. But inside python, when doing a double import, doesn't python check against double import (e.g. the second time, it does almost nothing) ? Is this specific to numpy, or other python modules do that as well ? cheers, David From aleksandr.goretoy at gmail.com Sun Feb 1 02:08:26 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Sun, 1 Feb 2009 01:08:26 -0600 Subject: PyNutButter BETA 1.0.0 - Automates CSV data Importation into any website http/https and/or mysql database Message-ID: Introducing PynutButter BETA 1.0.0 Automates csv data importation into any website. Or your money back. Programs like this idea of a program I have here cost $2500. Pynutbutter is opensource. You can use the code anyway you want. As long as I get my credit where it is due. I've worked on this project for roughly 1.5 years now. This is an idea I tried in 2 languages. PHP and python, now. No matter how much data in your csv file. No matter what the field names are. No matter how data is formatted With PyNutButter you can parse this data in custom functions and then send it to its destinations. You can map all the csv file headers to fields of a html page. It loops for each line in the csv file and imports your data. You must configure your configuration and create custom functions that you can call from this configuration. I've uploaded all the main files, except my configuration(I am working on examples and making the main project page better) You can find this project here: http://code.google.com/p/pynutbutter/ I've worked long and hard on this application and the idea behind it. Any help making this tool better would be greatly appreaciated. Please let me know what you this of this tool. Any ideas/features are also always welcome. I also have a presentation I am working on for this tool. I hope to find a nice job. This tools is very powerfuls. I was think next to try it with scapy. That would be sweet. You can add custom flavors(data parsing/sending libraries). My goal for this tool was to make everything as dynamic as possible. calling of functions and dealing with parsed data in functions. Only reason why I built is because I needed a tool like this. I know someone else woulnd't mind having a tool like this either, so here you go. If you can please donate or something somehow. Upcoming Features: use of parsed data from more than one file at a time. pyGTK for ease of configuration creation(any help?) gui creation of custom functions automatic form parsing based on given urls in config -Alex Goretoy http://www.alexgoretoy.com somebodywhocarez at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From rt8396 at gmail.com Sun Feb 1 02:10:39 2009 From: rt8396 at gmail.com (r) Date: Sat, 31 Jan 2009 23:10:39 -0800 (PST) Subject: Embedding numpy works once, but not twice?? References: <5dfe78f40901312147i957450ei187b08028c068a6@mail.gmail.com> Message-ID: <31b8b23d-ee9d-4da1-9961-b02c6221e089@p37g2000yqd.googlegroups.com> > Embedding numpy works once, but not twice?? That's what she said! From gandalf at shopzeus.com Sun Feb 1 02:37:13 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Sun, 01 Feb 2009 08:37:13 +0100 Subject: socket.unbind or socket.unlisten? - socket.error: (48, 'Address already in use') In-Reply-To: <004e01c98095$f90f9440$0d00a8c0@hendrik> References: <20090127134145.24460.1190938528.divmod.quotient.2653@henry.divmod.com> <004e01c98095$f90f9440$0d00a8c0@hendrik> Message-ID: <49855129.9070901@shopzeus.com> > 8<------------------------------ > > >> ....... Setting the >> SO_REUSEADDR flag on POSIX fixes this problem (don't set it on Windows, >> though). >> > > Why not? I have been merrily setting it, and I have not noticed anything weird. > (yet) > Please see my original post. I specifically stated that I do not want to use setsockopt and be able to listen on the same port from many processes. I knew that I could use SO_REUSEADDR, but I'm heistating to do so. I must guarantee that only one process listens on a given port at the same time. Maybe I could use some kind of locking, but it would be too difficult: - mutexes are great but they are platform dependent and they are not in the standard lib - the listening processes do not see each other's home directory so file locking cannot be used for this - these processes will probably listen on many ports at the same time, it is also a problem with mutexes/file locks (who wants 50 lock files to be created?) Best, Laszlo From mcheung63 at hotmail.com Sun Feb 1 02:42:42 2009 From: mcheung63 at hotmail.com (mcheung63 at hotmail.com) Date: Sat, 31 Jan 2009 23:42:42 -0800 (PST) Subject: what IDE is the best to write python? Message-ID: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> Hi all what IDE is the best to write python? thanks from Peter (mcheung63 at hotmail.com) From bj_666 at gmx.net Sun Feb 1 02:50:38 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 1 Feb 2009 07:50:38 GMT Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> Message-ID: <6ul2ieFg1sraU1@mid.uni-berlin.de> On Sat, 31 Jan 2009 15:28:14 -0800, thmpsn.m.k wrote: > On Jan 31, 2:27?pm, Christian Heimes wrote: >> Do you honestly believe that C++'s private members are really private? >> Privateness is only enforced during parsing time. Nobody can stop you >> from messing around with header files or memory. You can still access >> and modify private members but it's all messy and ugly. Even C# and >> .NET don't stop you from doing nasty things from unmananged assemblies. > > I don't know how you would do it in C# (or Java for that matter). In Java you can use reflection to get your fingers on private fields. > In C++ you can play with pointers to "get at" some memory location > somewhere in the object. > [Snipped pointer fiddling explanation] > So: Sometimes it may work, usually it will be unsafe and/or non- > portable, and in most cases the procedure will look complicated. Or ``#define private public`` before including the header files. Which doesn't look complicated to me. > It certainly isn't something I'd try in a real application. However, it > WOULD be tempting to access the member if the language allows me to just > write: > > print "obj.b =", obj.b > > and be done with it. And that's perfectly okay, because the author would have prepended an underscore to `b` if you should not mess with it. > Personally, in Python, I use double underscores for "private" members, > so the above would look like: > > print "obj.b =", obj._NonPOD__b > > but it's still easier than the C++ example. The name mangling is there to prevent name clashes, not to make attributes inaccessible. It's useful for mixin classes for example. >> Seriously, 'private' and 'protected' are merely tools to stop bad >> programmers from doing bad stuff. And the serve as documentation, too. > > It's not just documentation. For example, suppose you're reading a class > definition and see the declaration of a veryInterestingMember and forget > that you're not supposed to access it. If you try to access it, the > compiler will give you a diagnostic message at compile time. I can't forget that because if I'm not supposed to access it, its name would be `_very_interesting_member`. I don't have to wait till compile time to see that, it is really obvious at the time I write the code to access it, or decide not to because it is not part of the API. Ciao, Marc 'BlackJack' Rintsch From rt8396 at gmail.com Sun Feb 1 03:02:55 2009 From: rt8396 at gmail.com (r) Date: Sun, 1 Feb 2009 00:02:55 -0800 (PST) Subject: what IDE is the best to write python? References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> Message-ID: On Feb 1, 1:42?am, "mcheun... at hotmail.com" wrote: > Hi all > ? ?what IDE is the best to write python? That's like asking boxers or briefs, everybody thinks their choice is the best. I like freedom if that gives you a hint. :) From bj_666 at gmx.net Sun Feb 1 03:04:42 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 1 Feb 2009 08:04:42 GMT Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> <325fcc08-c090-44f9-b158-967e6dec212a@13g2000yql.googlegroups.com> Message-ID: <6ul3cpFg1sraU2@mid.uni-berlin.de> On Sat, 31 Jan 2009 09:08:25 -0800, thmpsn.m.k wrote: > On Jan 30, 12:15?am, Chris Rebert wrote: >> - Python supports encapsulation. Prefixing an attribute/method with an >> underscore indicates that other programmers should treat it as >> 'private'. However, unlike B&D languages, Python itself does nothing to >> enforce this privacy, leaving it instead to the good judgement of the >> programmer, under the philosophy that "We're all consenting adults >> here". > > How do you know? (I know I'm not.) Then stay with B&D languages. :-) > Seriously, though, the lack of private members does allow for ugly hacks > in user code, and you know there are always ugly hackers. So what? The hacks in Java to access private fields are even uglier IMHO. >> This allows people to meddle with internals, at their own risk, if it >> ends up being absolutely necessary. > > If it ends up being necessary, the class's design is flawed. Maybe that's the reason why it is really necessary. > (Though in this case, the flaw is easily solved by simply providing a > getter.) Simply providing a getter for a private attribute? I thought that's not easily possible in C++ or Java!? ;-) >> The enforcement point is >> largely academic anyway, as most languages' reflection APIs let you >> poke at ostensibly "private" things. > > If you're talking about getters, then note that this doesn't let you > modify the member (unless there's a corresponding setter). It's not about getters but about accessing private fields without any getters or setters through the reflection API. See the article `Subverting Java Access Protection for Unit Testing`_ for examples. .. _Subverting Java Access Protection for Unit Testing: http://www.onjava.com/pub/a/onjava/2003/11/12/reflection.html Ciao, Marc 'BlackJack' Rintsch From apt.shansen at gmail.com Sun Feb 1 03:14:27 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sun, 1 Feb 2009 00:14:27 -0800 (PST) Subject: what IDE is the best to write python? In-Reply-To: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> Message-ID: An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 269 bytes Desc: OpenPGP digital signature URL: From steve at pearwood.info Sun Feb 1 03:15:58 2009 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 01 Feb 2009 19:15:58 +1100 Subject: fastest way to detect a user type References: <49847EBB.4050307@jessikat.plus.net> Message-ID: <0195504e$0$20642$c3e8da3@news.astraweb.com> Robin Becker wrote: > Whilst considering a port of old code to python 3 I see that in several > places we are using type comparisons to control processing of user > instances (as opposed to instances of built in types eg float, int, str) > > I find that the obvious alternatives are not as fast as the current > code; func0 below. On my machine isinstance seems slower than type for > some reason. My 2.6 timings are First question is, why do you care that it's slower? The difference between the fastest and slowest functions is 1.16-0.33 = 0.83 microsecond. If you call the slowest function one million times, your code will run less than a second longer. Does that really matter, or are you engaged in premature optimization? In your test functions, the branches all execute "pass". Your real code probably calls other functions, makes calculations, etc, which will all take time. Probably milliseconds rather than microseconds. I suspect you're concerned about a difference of 0.1 of a percent, of one small part of your entire application. Unless you have profiled your code and this really is a bottleneck, I recommend you worry more about making your code readable and maintainable than worrying about micro-optimisations. Even more important that being readable is being *correct*, and I believe that your code has some unexpected failure modes (bugs). See below: > so func 3 seems to be the fastest option for the case when the first > test matches, but is poor when it doesn't. Can anyone suggest a better > way to determine if an object is a user instance? > > ############################## > from types import InstanceType I believe this will go away in Python 3, as all classes will be New Style classes. > class X: > __X__=True This is an Old Style class in Python 2.x, and a New Style class in Python 3. Using hasattr('__X__') is a curious way of detecting what you want. I suppose it could be argued that it is a variety of duck-typing: "if it has a duck's bill, it must be a duck". (Unless it is a platypus, of course.) However, attribute names with leading and trailing double-underscores are reserved for use as "special methods". You should rename it to something more appropriate: _MAGIC_LABEL, say. > class V(X): > pass > > def func0(ob): > t=type(ob) > if t is InstanceType: > pass This test is too broad. It will succeed for *any* old-style class, not just X and V instances. That's probably not what you want. It will also fail if ob is an instance of a New Style class. Remember that in Python 3, all classes become new-style. > elif t in (float, int): > pass This test will fail if ob is a subclass of float or int. That's almost certainly the wrong behavior. A better way of writing that is: elif issubclass(t, (float, int)): pass > else: > pass > > def func1(ob): > if isinstance(ob,X): > pass If you have to do type checking, that's the recommended way of doing so. > elif type(ob) in (float, int): > pass The usual way to write that is: if isinstance(ob, (float, int)): pass Hope this helps, -- Steven From steve at pearwood.info Sun Feb 1 03:23:58 2009 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 01 Feb 2009 19:23:58 +1100 Subject: accessing elements of a tuple References: Message-ID: <0195522e$0$31512$c3e8da3@news.astraweb.com> D'Arcy J.M. Cain wrote: > First of all, list is a reserved word. ?Don't use it as a variable name. Unless you mean to. Shadowing built-ins is only a bad thing when you do it by accident. -- Steven From http Sun Feb 1 03:25:30 2009 From: http (Paul Rubin) Date: 01 Feb 2009 00:25:30 -0800 Subject: fastest way to detect a user type References: <49847EBB.4050307@jessikat.plus.net> <0195504e$0$20642$c3e8da3@news.astraweb.com> Message-ID: <7xzlh6bm2t.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > First question is, why do you care that it's slower? The difference between > the fastest and slowest functions is 1.16-0.33 = 0.83 microsecond. That's a 71% speedup, pretty good if you ask me. > If you call the slowest function one million times, your code will > run less than a second longer. What if you call it a billion times, or a trillion times, or a quadrillion times, you see where this is going? If you're testing 100-digit numbers, there are an awful lot of them before you run out. From casevh at gmail.com Sun Feb 1 03:27:09 2009 From: casevh at gmail.com (casevh) Date: Sun, 1 Feb 2009 00:27:09 -0800 (PST) Subject: nth root References: <1AE19A80523D5F40BE0044A1447A53FF0ADB972E@UNIMAIL.staff.ad.cqu.edu.au> Message-ID: On Jan 31, 9:36?pm, "Tim Roberts" wrote: > Actually, all I'm interested in is whether the 100 digit numbers have an exact integral root, or not. ?At the moment, because of accuracy concerns, I'm doing something like > > ? ? ? ? ? ? ? ? ? ? for root in powersp: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? nroot = round(bignum**(1.0/root)) > ? ? ? ? ? ? ? ? ? ? ? ? ? ? if bignum==long(nroot)**root: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?......... > which is probably very inefficient, but I can't see anything better..... > > Tim Take a look at gmpy and the is_power function. I think it will do exactly what you want. http://code.google.com/p/gmpy/ casevh From Shawn at Milochik.com Sun Feb 1 03:34:30 2009 From: Shawn at Milochik.com (Shawn Milochik) Date: Sun, 1 Feb 2009 03:34:30 -0500 Subject: Searching a file for multiple strings (PS) In-Reply-To: <6ecdebf6-a422-4f5a-a99b-2c3ed461d980@w1g2000prk.googlegroups.com> References: <7b0df317-c3cb-4013-9b68-42d0ee9869df@f24g2000vbf.googlegroups.com> <4984AA57.3050106@tim.thechases.com> <4984ADDB.2070509@tim.thechases.com> <6ecdebf6-a422-4f5a-a99b-2c3ed461d980@w1g2000prk.googlegroups.com> Message-ID: <2dc0c81b0902010034p102cd9c2t2e20d656cb22fd9d@mail.gmail.com> On Sun, Feb 1, 2009 at 1:14 AM, John Machin wrote: > On Feb 1, 3:39 pm, Shawn Milochik wrote: > >> Not to discourage the use of Python, but it seems that fgrep with the >> -f flag already does exactly what you want. If you're on Windows, you >> can get the Windows version of fgrep here: http://unxutils.sourceforge.net/ > > That URL is antique and a dead end. When you find the actual > sourceforge project page (http://sourceforge.net/projects/unxutils/) > and browse the forums and the CVS repository, you'll see tumbleweed > blowing down Main Street and not much else (besides a few whinges > about that dead end URL, and many unanswered issues). > > Alternative: http://gnuwin32.sourceforge.net/ > -- > http://mail.python.org/mailman/listinfo/python-list > Thanks very much for the update. I had been using the older versions (on the rare occasions I've had to use Windows). I didn't know there was a currently-maintained version. From mail at microcorp.co.za Sun Feb 1 03:38:53 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sun, 1 Feb 2009 10:38:53 +0200 Subject: SimpleXMLRPCServer question References: <0ddb9364-02c9-4c52-aadb-e9d9b2d06b20@e1g2000pra.googlegroups.com> <185b44c2-fc78-480f-8eb1-6395f7fe7ad7@x6g2000pre.googlegroups.com> Message-ID: <021901c9844b$e41ba380$0d00a8c0@hendrik> "flagg" wrote: >Let me see if i can elaborate on the requirements. I have 20+ >different zone files. I want the xmlrpc server to be able to >determine what zone file to open by looking at the incoming xml >request. For example one of the functions I have now is to show a DNS >record (I am using dnspython for most of this work) > This is a wrong move, it is too magical - see below >If i send an xmlrpc request that uses the 'showRecord' function with >params of 'oracle1.foo.bar.com' I want to parse the "params" piece >and then instruct the xml-rpc server to open foo.bar.com.zone for >reading. The reason why i was looking at do_Post() and _dispatch was >to attempt to read the incoming params and do exactly that. > >Do you think there is an easier way of accomplishing this, than the >way I am going about it? Yes I do. Why don't you split the functionality into two bits - exactly as if you were doing it locally: - OpenTheThing(whatOrWhere) - ReadTheRecordAndShowIt(PossiblyWhichRecord) If it's a remote database you are accessing, then you may need even more steps, like first doing some select, or whatever - I would get it running locally, calling local functions directly on the server, and then make them remote xmlrpc proxy functions, after it's all working. If you are getting the request from some user input, you can either change the way you ask the questions, or you do the parsing at point of origen, to determine what to call, in which sequence. - Hendrik From gagsl-py2 at yahoo.com.ar Sun Feb 1 03:43:43 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 01 Feb 2009 06:43:43 -0200 Subject: Embedding numpy works once, but not twice?? References: <5dfe78f40901312147i957450ei187b08028c068a6@mail.gmail.com> Message-ID: En Sun, 01 Feb 2009 03:47:27 -0200, Deepak Chandran escribi?: > I have a program in which I have successfully embedded Python. Now, I > want > to include NumPy as well (and other modules). I am able to import numpy > once. Then I close the python console in my program and then re-open it. > When I try to import numpy for a second time, the program crashes. Below > is > a simple version of the problem. The problem is not with NumPy. You can't run Py_Initialize/Py_Finalize more than once. Python doesn't have any mechanism to un-initialize loaded modules, and any static data that NumPy had initialized the first time it is imported becomes invalid the second time. Call Py_Initialize at the start of your program, and Py_Finalize at the end, never more than once. -- Gabriel Genellina From sjmachin at lexicon.net Sun Feb 1 03:56:31 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 1 Feb 2009 00:56:31 -0800 (PST) Subject: Searching a file for multiple strings (PS) References: <7b0df317-c3cb-4013-9b68-42d0ee9869df@f24g2000vbf.googlegroups.com> <4984AA57.3050106@tim.thechases.com> <4984ADDB.2070509@tim.thechases.com> <6ecdebf6-a422-4f5a-a99b-2c3ed461d980@w1g2000prk.googlegroups.com> Message-ID: <3a6e40c1-da04-4c68-a6c4-fe373fbe3b72@p23g2000prp.googlegroups.com> On Feb 1, 7:34?pm, Shawn Milochik wrote: > On Sun, Feb 1, 2009 at 1:14 AM, John Machin wrote: > > On Feb 1, 3:39 pm, Shawn Milochik wrote: > > >> Not to discourage the use of Python, but it seems that fgrep with the > >> -f flag already does exactly what you want. If you're on Windows, you > >> can get the Windows version of fgrep here:http://unxutils.sourceforge.net/ > > > That URL is antique and a dead end. When you find the actual > > sourceforge project page (http://sourceforge.net/projects/unxutils/) > > and browse the forums and the CVS repository, you'll see tumbleweed > > blowing down Main Street and not much else (besides a few whinges > > about that dead end URL, and many unanswered issues). > > > Alternative:http://gnuwin32.sourceforge.net/ > > -- > >http://mail.python.org/mailman/listinfo/python-list > > Thanks very much for the update. I had been using the older versions > (on the rare occasions I've had to use Windows). I didn't know there > was a currently-maintained version. Read my lips: unxutils is *not* "currently-maintained". Use GnuWin32. From ntwrkd at gmail.com Sun Feb 1 04:09:13 2009 From: ntwrkd at gmail.com (Matthew Sacks) Date: Sun, 1 Feb 2009 01:09:13 -0800 Subject: what IDE is the best to write python? In-Reply-To: References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> Message-ID: Wingware IDE is pretty good. It's not free though. http://www.wingware.com/ On Sun, Feb 1, 2009 at 12:14 AM, Stephen Hansen wrote: > On Sat, Jan 31, 2009 at 11:42 PM, mcheung63 at hotmail.com > wrote: >> >> Hi all >> what IDE is the best to write python? >> thanks >> from Peter (mcheung63 at hotmail.com) > > What OS? And define "IDE"? Do you just want an editing environment with say > class browsing capabilities or do you want an integrated debugger and such? > > On the mac, I actually like TextMate and Wing IDE -- both commercial(ish). > TextMate is like a sex toy its so great to use, but recently I've started > migrating to WingIDE for my work projects. > > For Windows, I used Stani's Python Editor. http://pythonide.blogspot.com/ > > --S > > -- > http://mail.python.org/mailman/listinfo/python-list > > From lipun4u at gmail.com Sun Feb 1 04:27:26 2009 From: lipun4u at gmail.com (asit) Date: Sun, 1 Feb 2009 01:27:26 -0800 (PST) Subject: Handle SystemExit exception Message-ID: My program contains some sys.exit(1) and when its executed an exception known as SystemExit is thrown. I tried to handle bu using following code snippet if __name__ == "__main__": try: main() #main contains sys.exit(1) except KeyboardInterrupt: print "aborted by user" except SystemExit: pass But it does not work. Can anyone help me out ??? Though KeyboradInterrupt is handled, but why SystemExit is not handles ???? Regards Asit Dhal From steve at pearwood.info Sun Feb 1 04:32:58 2009 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 01 Feb 2009 20:32:58 +1100 Subject: fastest way to detect a user type References: <49847EBB.4050307@jessikat.plus.net> <0195504e$0$20642$c3e8da3@news.astraweb.com> <7xzlh6bm2t.fsf@ruckus.brouhaha.com> Message-ID: <0195625a$0$23675$c3e8da3@news.astraweb.com> Paul Rubin wrote: > Steven D'Aprano writes: >> First question is, why do you care that it's slower? The difference >> between the fastest and slowest functions is 1.16-0.33 = 0.83 >> microsecond. > > That's a 71% speedup, pretty good if you ask me. Don't you care that the code is demonstrably incorrect? The OP is investigating options to use in Python 3, but the fastest method will fail, because the "type is InstanceType" test will no longer work. (I believe the fastest method, as given, is incorrect even in Python 2.x, as it will accept ANY old-style class instead of just the relevant X or V classes.) That reminds me of something that happened to my wife some years ago: she was in a van with her band's roadies, and one asked the driver "Are you sure you know where you're going?", to which the driver replied, "Who cares? We're making great time." (True story.) If you're going to accept incorrect code in order to save time, then I can write even faster code: def func4(ob): pass Trying beating that for speed! >> If you call the slowest function one million times, your code will >> run less than a second longer. > > What if you call it a billion times, or a trillion times, or a > quadrillion times, you see where this is going? It doesn't matter. The proportion of time saved will remain the same. If you run it a trillion times, you'll save 12 minutes in a calculation that takes 278 hours to run. Big Effing Deal. Saving such trivial amounts of time is not worth the cost of hard-to-read or incorrect code. Of course, if you have profiled your code and discovered that *significant* amounts of time are being used in type-testing, *then* such a micro-optimization may be worth doing. But I already allowed for that: "Does that really matter...?" (the answer could be Yes) "Unless you have profiled your code and this really is a bottleneck ..." (it could be) > If you're testing > 100-digit numbers, there are an awful lot of them before you run out. Yes. So what? Once you've tested them, then what? If *all* you are doing them is testing them, your application is pretty boring. Even a print statement afterwards is going to take 1000 times longer than doing the type-test. In any useful application, the amount of time used in type-testing is almost surely going to be a small fraction of the total runtime. A 71% speedup on 50% of the runtime is significant; but a 71% speedup on 0.1% of the total execution time is not. -- Steven From gagsl-py2 at yahoo.com.ar Sun Feb 1 04:45:30 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 01 Feb 2009 07:45:30 -0200 Subject: Handle SystemExit exception References: Message-ID: En Sun, 01 Feb 2009 07:27:26 -0200, asit escribi?: > My program contains some sys.exit(1) and when its executed an > exception known as SystemExit is thrown. This is normal behaviour - but you should not "see" the SystemExit. Do you mean that a stack trace appears in the console? > I tried to handle bu using following code snippet > > if __name__ == "__main__": > try: > main() #main contains sys.exit(1) > except KeyboardInterrupt: > print "aborted by user" > except SystemExit: > pass > > But it does not work. I've tested adding this: def main(): sys.exit(1) and it exited normally, even after removing the SystemExit clause. > Can anyone help me out ??? > > Though KeyboradInterrupt is handled, but why SystemExit is not > handles ???? Perhaps there is another try/except somewhere else that handles SystemExit? Look for bare except clauses, like try: except: ... They should *not* be used. With Python 2.5 and above, theh "catch-all" should be written as: try: except Exception: ... If you are using 2.4 or earlier, should be: try: except (SystemExit, KeyboardInterrupt): raise except: ... -- Gabriel Genellina From steve at pearwood.info Sun Feb 1 04:46:20 2009 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 01 Feb 2009 20:46:20 +1100 Subject: Handle SystemExit exception References: Message-ID: <0195657c$0$20662$c3e8da3@news.astraweb.com> asit wrote: > My program contains some sys.exit(1) and when its executed an > exception known as SystemExit is thrown. > > I tried to handle bu using following code snippet > > if __name__ == "__main__": > try: > main() #main contains sys.exit(1) > except KeyboardInterrupt: > print "aborted by user" > except SystemExit: > pass > > But it does not work. It works for me: >>> try: ... sys.exit() ... except SystemExit: ... pass ... >>> What does it do for you? Crash? Exit? print garbage to the screen? I'm going to guess what you are doing. Do you have code like this? try: main() #main contains sys.exit(1) except KeyboardInterrupt: print "aborted by user" except SomeOtherException, SystemExit: pass This will mask SystemExit and stop it from being caught. It should be written like this: except (SomeOtherException, SystemExit): pass Or possibly something like this? try: main() #main contains sys.exit(1) except KeyboardInterrupt: print "aborted by user" except Exception: do_something() raise except SystemExit: pass The Exception clause will catch SystemExit before the SystemExit clause will see it. That should be written like this: except SystemExit: pass except Exception: do_something() raise -- Steven From steve at pearwood.info Sun Feb 1 04:51:47 2009 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 01 Feb 2009 20:51:47 +1100 Subject: Please help to play 5 jpegs as a slideshow in JES(Jython) --- BEGINNER. References: <28dec764-64e4-4a47-87d5-ba3b52e3b051@r36g2000prf.googlegroups.com> Message-ID: <019566c3$0$20644$c3e8da3@news.astraweb.com> steve at savechicago.org wrote: > Hello, I am a brand brand new programming student in Jython and I have > been working on a simple homework assignment in JES for the last 12 > hours and am completely lost. > > Basically, we have to make a jpeg slideshow with 5 different pictures > with audio background that lasts 60 seconds. I have absolutely no idea > where to begin and am more lost than I was 12 hours ago. > > > > def pickAndShow(): > > myfile = pickAFile() > mypicture = makePicture(myfile) > show(mypicture) > > I know this is how to call up a picture from your hard drive. That?s > about all I know. I have no idea how to call up 5 of them, one at a > time, and with audio in the background. If you can call up *one* picture, then you should be able to call up a second one, then a third, then a fourth, then a fifth, and then you're done. -- Steven From lipun4u at gmail.com Sun Feb 1 05:29:54 2009 From: lipun4u at gmail.com (asit) Date: Sun, 1 Feb 2009 02:29:54 -0800 (PST) Subject: Handle SystemExit exception References: <0195657c$0$20662$c3e8da3@news.astraweb.com> Message-ID: Thanx everyone This is my fault. Exception was thrown before the main function. From lipun4u at gmail.com Sun Feb 1 05:34:39 2009 From: lipun4u at gmail.com (asit) Date: Sun, 1 Feb 2009 02:34:39 -0800 (PST) Subject: exception in urllib2 Message-ID: I hv been developing a link scanner. Here the objective is to recursively scan a particular web site. During this, my script met http://images.google.co.in/imghp?hl=en&tab=wi and passed it to the scan function, whose body is like this.. def scan(site): log=open(logfile,'a') log.write(site + "\n") site = "http://" + site.lower() try: site_data = urllib.urlopen(site) parser = MyParser() parser.parse(site_data.read()) except(IOError),msg: print "Error in connecting site ", site print msg links = parser.get_hyperlinks() for l in links: log.write(l + "\n") But it throws a weird exception like this... Traceback (most recent call last): File "I:\Python26\linkscan1.py", line 104, in main() File "I:\Python26\linkscan1.py", line 95, in main scan(lk) File "I:\Python26\linkscan1.py", line 65, in scan site_data = urllib.urlopen(site) File "I:\Python26\lib\urllib.py", line 87, in urlopen return opener.open(url) File "I:\Python26\lib\urllib.py", line 203, in open return getattr(self, name)(url) File "I:\Python26\lib\urllib.py", line 327, in open_http h = httplib.HTTP(host) File "I:\Python26\lib\httplib.py", line 984, in __init__ self._setup(self._connection_class(host, port, strict)) File "I:\Python26\lib\httplib.py", line 656, in __init__ self._set_hostport(host, port) File "I:\Python26\lib\httplib.py", line 668, in _set_hostport raise InvalidURL("nonnumeric port: '%s'" % host[i+1:]) httplib.InvalidURL: nonnumeric port: '' How can i handle this ??? From bbxx789_05ss at yahoo.com Sun Feb 1 06:00:18 2009 From: bbxx789_05ss at yahoo.com (7stud) Date: Sun, 1 Feb 2009 03:00:18 -0800 (PST) Subject: exception in urllib2 References: Message-ID: <5ce2bf59-7923-457c-8141-e3ab65e531cd@y23g2000pre.googlegroups.com> On Feb 1, 3:34?am, asit wrote: > I hv been developing a link scanner. Here the objective is to > recursively scan a particular web site. > > During this, my script methttp://images.google.co.in/imghp?hl=en&tab=wi > and passed it to the scan function, whose body is like this.. > > def scan(site): > So you have this: site=http://images.google.co.in/imghp?hl=en&tab=wi ?? > ? ? log=open(logfile,'a') > ? ? log.write(site + "\n") > ? ? site = "http://" + site.lower() > So now: site = "http://" + "http://images.google.co.in/imghp?hl=en&tab=wi" Hmmm...let's see what happens when I run the following program: import urllib site = "http://" + "http://images.google.co.in/imghp?hl=en&tab=wi" html = urllib.urlopen(site) --output:-- Traceback (most recent call last): File "6test.py", line 4, in ? html = urllib.urlopen(site) File "/Library/Frameworks/Python.framework/Versions/2.4//lib/ python2.4/urllib.py", line 82, in urlopen return opener.open(url) File "/Library/Frameworks/Python.framework/Versions/2.4//lib/ python2.4/urllib.py", line 190, in open return getattr(self, name)(url) File "/Library/Frameworks/Python.framework/Versions/2.4//lib/ python2.4/urllib.py", line 303, in open_http h = httplib.HTTP(host) File "/Library/Frameworks/Python.framework/Versions/2.4//lib/ python2.4/httplib.py", line 1097, in __init__ self._setup(self._connection_class(host, port, strict)) File "/Library/Frameworks/Python.framework/Versions/2.4//lib/ python2.4/httplib.py", line 586, in __init__ self._set_hostport(host, port) File "/Library/Frameworks/Python.framework/Versions/2.4//lib/ python2.4/httplib.py", line 598, in _set_hostport raise InvalidURL("nonnumeric port: '%s'" % host[i+1:]) httplib.InvalidURL: nonnumeric port: '' From bbxx789_05ss at yahoo.com Sun Feb 1 06:20:26 2009 From: bbxx789_05ss at yahoo.com (7stud) Date: Sun, 1 Feb 2009 03:20:26 -0800 (PST) Subject: exception in urllib2 References: Message-ID: <81681f17-4b92-46b5-9875-a1b8ae191ae5@v18g2000pro.googlegroups.com> On Feb 1, 3:34?am, asit wrote: > I hv been developing a link scanner. Here the objective is to > recursively scan a particular web site. > > During this, my script methttp://images.google.co.in/imghp?hl=en&tab=wi > and passed it to the scan function, whose body is like this.. > > def scan(site): > ? ? log=open(logfile,'a') > ? ? log.write(site + "\n") > ? ? site = "http://" + site.lower() > ? ? try: > ? ? ? ? site_data = urllib.urlopen(site) > ? ? ? ? parser = MyParser() > ? ? ? ? parser.parse(site_data.read()) > ? ? except(IOError),msg: > ? ? ? ? print "Error in connecting site ", site > ? ? ? ? print msg > ? ? links = parser.get_hyperlinks() > ? ? for l in links: > ? ? ? ? log.write(l + "\n") > > But it throws a weird exception like this... > > Traceback (most recent call last): > ? File "I:\Python26\linkscan1.py", line 104, in > ? ? main() > ? File "I:\Python26\linkscan1.py", line 95, in main > ? ? scan(lk) > ? File "I:\Python26\linkscan1.py", line 65, in scan > ? ? site_data = urllib.urlopen(site) > ? File "I:\Python26\lib\urllib.py", line 87, in urlopen > ? ? return opener.open(url) > ? File "I:\Python26\lib\urllib.py", line 203, in open > ? ? return getattr(self, name)(url) > ? File "I:\Python26\lib\urllib.py", line 327, in open_http > ? ? h = httplib.HTTP(host) > ? File "I:\Python26\lib\httplib.py", line 984, in __init__ > ? ? self._setup(self._connection_class(host, port, strict)) > ? File "I:\Python26\lib\httplib.py", line 656, in __init__ > ? ? self._set_hostport(host, port) > ? File "I:\Python26\lib\httplib.py", line 668, in _set_hostport > ? ? raise InvalidURL("nonnumeric port: '%s'" % host[i+1:]) > httplib.InvalidURL: nonnumeric port: '' > > How can i handle this ??? "Handle" as in how do I catch that exception? The exception's name is give in the error message. Look at the last line. To catch that exception, you can do this: import httplib #that's the module the exception lives in #as indicated in error message try: .... .... .... except httplib.InvalidURL, e: print e print "Bad url" From hubaghdadi at gmail.com Sun Feb 1 06:22:36 2009 From: hubaghdadi at gmail.com (Hussein B) Date: Sun, 1 Feb 2009 03:22:36 -0800 (PST) Subject: What is wrong in my list comprehension? Message-ID: <44116a3e-0f4a-418f-9ada-dc917ec592d5@j35g2000yqh.googlegroups.com> Hey, I have a log file that doesn't contain the word "Haskell" at all, I'm just trying to do a little performance comparison: ++++++++++++++ from datetime import time, timedelta, datetime start = datetime.now() print start lines = [line for line in file('/media/sda4/Servers/Apache/ Tomcat-6.0.14/logs/catalina.out') if line.find('Haskell')] print 'Number of lines contains "Haskell" = ' + str(len(lines)) end = datetime.now() print end ++++++++++++++ Well, the script is returning the whole file's lines number !! What is wrong in my logic? Thanks. From a at nospam.org Sun Feb 1 06:35:52 2009 From: a at nospam.org (Armin) Date: Sun, 01 Feb 2009 12:35:52 +0100 Subject: py2exe + SQLite problem In-Reply-To: References: <54542453-3479-4953-94c7-b9df50714761@k36g2000pri.googlegroups.com> Message-ID: Hello, Thanks to all ... it's working now ! Google isn't always your friend :) I found in the net a lot but wrong examples for specification of "data_files". Now I have the correct one. Best Regards --Armin Gabriel Genellina wrote: > En Sat, 31 Jan 2009 11:51:16 -0200, Armin escribi?: >> Gabriel Genellina wrote: >>> En Fri, 30 Jan 2009 09:50:08 -0200, Armin escribi?: > >>> Right at the end: "To install data files directly in the target >>> directory, an empty string should be given as the directory." >>> setup(..., >>> data_files=[ >>> ('', ['list/of/file/names', >>> 'perhaps/including/source/directory']), >>> ] >>> ) >>> >> Yes ... so far the theory :) >> >> As posted before ... set's my script (python 2.3): > > You didn't tell us that you were using version 2.3 -- it's important, as > the current stable releases are 2.6 and 3.0. Anyway, this should work in > 2.3 too. > >> from distutils.core import setup >> import py2exe >> >> setup(windows=['dpconf.py'], >> data_files=[ "", ["proj_db","gsd_db","dachs2.xbm"]] >> ) >> > > Comparing my example and yours, you lack a parenthesis level: > > setup(windows=['dpconf.py'], > data_files=[("", ["proj_db","gsd_db","dachs2.xbm"])] > ) > >> When I create the distribution I got the following err msg: >> >> *** copy data files *** >> warning: install_data: setup script did not provide a directory for '' >> -- installing right in 'C:\pyDPCONF.2.3-dev\dist' >> error: can't copy '': doesn't exist or not a regular file >> >> Looks a little bit inconsistent ? > > O thou of little faith, try again... > From __peter__ at web.de Sun Feb 1 06:37:00 2009 From: __peter__ at web.de (Peter Otten) Date: Sun, 01 Feb 2009 12:37:00 +0100 Subject: What is wrong in my list comprehension? References: <44116a3e-0f4a-418f-9ada-dc917ec592d5@j35g2000yqh.googlegroups.com> Message-ID: Hussein B wrote: > Hey, > I have a log file that doesn't contain the word "Haskell" at all, I'm > just trying to do a little performance comparison: > ++++++++++++++ > from datetime import time, timedelta, datetime > start = datetime.now() > print start > lines = [line for line in file('/media/sda4/Servers/Apache/ > Tomcat-6.0.14/logs/catalina.out') if line.find('Haskell')] > print 'Number of lines contains "Haskell" = ' + str(len(lines)) > end = datetime.now() > print end > ++++++++++++++ > Well, the script is returning the whole file's lines number !! > What is wrong in my logic? > Thanks. """ find(...) S.find(sub [,start [,end]]) -> int Return the lowest index in S where substring sub is found, such that sub is contained within s[start:end]. Optional arguments start and end are interpreted as in slice notation. Return -1 on failure. """ a.find(b) returns -1 if b is no found. -1 evaluates to True in a boolean context. Use [line for line in open(...) if line.find("Haskell") != -1] or, better [line for line in open(...) if "Haskell" in line] to get the expected result. Peter From clp2 at rebertia.com Sun Feb 1 06:39:06 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 1 Feb 2009 03:39:06 -0800 Subject: What is wrong in my list comprehension? In-Reply-To: <44116a3e-0f4a-418f-9ada-dc917ec592d5@j35g2000yqh.googlegroups.com> References: <44116a3e-0f4a-418f-9ada-dc917ec592d5@j35g2000yqh.googlegroups.com> Message-ID: <50697b2c0902010339r4d3cdd85n5060f74515f8d28c@mail.gmail.com> On Sun, Feb 1, 2009 at 3:22 AM, Hussein B wrote: > Hey, > I have a log file that doesn't contain the word "Haskell" at all, I'm > just trying to do a little performance comparison: > ++++++++++++++ > from datetime import time, timedelta, datetime > start = datetime.now() > print start > lines = [line for line in file('/media/sda4/Servers/Apache/ > Tomcat-6.0.14/logs/catalina.out') if line.find('Haskell')] >From the help() for str.find: find(...) Return -1 on failure. ~ $ python Python 2.6 (r26:66714, Nov 18 2008, 21:48:52) [GCC 4.0.1 (Apple Inc. build 5484)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> bool(-1) True str.find() returns -1 on failure (i.e. if the substring is not in the given string). -1 is considered boolean true by Python. Therefore, your list comprehension will contain all lines that don't *start* with "Haskell" rather than all lines that don't *contain* "Haskell". Use `if "Haskell" in line` instead of `if line.find("Haskell")`. It's even easier to read that way. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From jstroud at mbi.ucla.edu Sun Feb 1 06:39:27 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Sun, 01 Feb 2009 03:39:27 -0800 Subject: what IDE is the best to write python? In-Reply-To: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> Message-ID: <2Nfhl.9862$8_3.3929@flpi147.ffdc.sbc.com> mcheung63 at hotmail.com wrote: > Hi all > what IDE is the best to write python? > thanks > from Peter (mcheung63 at hotmail.com) vim in one terminal, ipython in the other. -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com From johan.de.taeye at gmail.com Sun Feb 1 06:52:58 2009 From: johan.de.taeye at gmail.com (jdetaeye) Date: Sun, 1 Feb 2009 03:52:58 -0800 (PST) Subject: Embedded python 2.6 interpreter can't "import sqlite3" on Windows XP Message-ID: I am porting an application which embeds a Python interpreter to Python 2.6. On version 2.5 all is working fine, but importing the sqlite3 module doesn't work any more on 2.6. The statement "import sqlite3" does work fine when executed from in the python command prompt, ie not from the embedded interpreter. The same import gives the following error when executed from the embedded interpreter. Python stacktrace: Traceback (most recent call last): File "", line 2, in File "C:\Python26\lib\sqlite3\__init__.py", line 24, in from dbapi2 import * File "C:\Python26\lib\sqlite3\dbapi2.py", line 27, in from _sqlite3 import * ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed. Windows popup window: Runtime Error! R6034 An application has made an attempt to load the C runtime library incorrectly. Please contact the application's support team for more information. Unfortunately the "application support team" (that is me :-) has no idea on how to move forward on this: a) I guess this is releated to the problem with manifest files, already reported in http://bugs.python.org/issue4120 ? b) What could be a solution or workaround for the problem? All the above is on Windows XP. Other modules with have an extension DLL (such as ssl) give exactly the same problem. All help appreciated, Johan From nemesis at nowhere.invalid Sun Feb 1 07:04:09 2009 From: nemesis at nowhere.invalid (Nemesis) Date: 01 Feb 2009 12:04:09 GMT Subject: [ANN] XPN 1.2.6 Message-ID: <49858fb9$0$1110$4fafbaef@reader3.news.tin.it> XPN (X Python Newsreader) is a multi-platform newsreader with Unicode support. It is written with Python+GTK. It has features like scoring/actions, X-Face and Face decoding, muting of quoted text, newsrc import/export, find article and search in the body, spoiler char/rot13, random taglines and configurable attribution lines. You can find it on: http://xpn.altervista.org/index-en.html or http://sf.net/projects/xpn Changes in this release: * v1.2.6: Now threads with unread watched articles are underlined * v1.2.6: added a visualization option that lets you hide threads without watched articles * v1.2.6: fixed a bug that caused XPN not to kill old articles reapplying rules * v1.2.6: fixed a bug that caused crashes when using ID with extended chars XPN is translated in Italian French and German, if you'd like to translate it in your language and you are familiar with gettext and po-files editing please contact me (xpn at altervista.org). -- To succeed in the world it is not enough to be stupid, you must also be well-mannered. _ _ _ | \| |___ _ __ ___ __(_)___ | .` / -_) ' \/ -_|_-< (_-< |_|\_\___|_|_|_\___/__/_/__/ http://xpn.altervista.org From matthewbdaly at googlemail.com Sun Feb 1 07:07:05 2009 From: matthewbdaly at googlemail.com (MattBD) Date: Sun, 1 Feb 2009 04:07:05 -0800 (PST) Subject: what IDE is the best to write python? References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> Message-ID: On Feb 1, 7:42?am, "mcheun... at hotmail.com" wrote: > Hi all > ? ?what IDE is the best to write python? > thanks > from Peter (mcheun... at hotmail.com) I like Vim, that works really well for me when coding in Python. Enable syntax highlighting and it's a great development environment. It's a little tough at first but run vimtutor and you'll soon start to get the hang of it. IMHO, scripting languages like Python are generally better suited to working with a text editor than an IDE. From stef.mientki at gmail.com Sun Feb 1 07:19:04 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Sun, 01 Feb 2009 13:19:04 +0100 Subject: what IDE is the best to write python? In-Reply-To: References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> Message-ID: <49859338.2000105@gmail.com> > IMHO, scripting languages like Python are generally better suited to > working with a text editor than an IDE. > I don't understand that, because in my opinion yields IDE = texteditor + (much) more please could you explain (as I'm very interested in user interfaces in general ) cheers, Stef From robin at NOSPAMreportlab.com Sun Feb 1 07:33:36 2009 From: robin at NOSPAMreportlab.com (Robin Becker) Date: Sun, 01 Feb 2009 12:33:36 +0000 Subject: fastest way to detect a user type In-Reply-To: <0195625a$0$23675$c3e8da3@news.astraweb.com> References: <49847EBB.4050307@jessikat.plus.net> <0195504e$0$20642$c3e8da3@news.astraweb.com> <7xzlh6bm2t.fsf@ruckus.brouhaha.com> <0195625a$0$23675$c3e8da3@news.astraweb.com> Message-ID: <498596A0.6030005@jessikat.plus.net> Steven D'Aprano wrote: > Paul Rubin wrote: > >> Steven D'Aprano writes: >>> First question is, why do you care that it's slower? The difference >>> between the fastest and slowest functions is 1.16-0.33 = 0.83 >>> microsecond. >> That's a 71% speedup, pretty good if you ask me. > > Don't you care that the code is demonstrably incorrect? The OP is > investigating options to use in Python 3, but the fastest method will fail, > because the "type is InstanceType" test will no longer work. (I believe the > fastest method, as given, is incorrect even in Python 2.x, as it will > accept ANY old-style class instead of just the relevant X or V classes.) I'm not clear why this is true? Not all instances will have the __X__ attribute or has something else changed in Python3? The original code was intended to be called with only a subset of all class instances being passed as argument; as currently written it was unsafe because an instance of an arbitrary old class would pass into branch 1. Of course it will still be unsafe as arbitrary instances end up in branch 3 The intent is to firm up the set of cases being accepted in the first branch. The problem is that when all instances are new style then there's no easy check for the other acceptable arguments eg float,int, str etc, as I see it, the instances must be of a known class or have a distinguishing attribute. As for the timing, when I tried the effect of func1 on our unit tests I noticed that it slowed the whole test suite by 0.5%. Luckily func 3 style improved things by about 0.3% so that's what I'm going for. -- Robin Becker From steve at holdenweb.com Sun Feb 1 07:45:42 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 01 Feb 2009 07:45:42 -0500 Subject: socket.unbind or socket.unlisten? - socket.error: (48, 'Address already in use') In-Reply-To: <49855129.9070901@shopzeus.com> References: <20090127134145.24460.1190938528.divmod.quotient.2653@henry.divmod.com> <004e01c98095$f90f9440$0d00a8c0@hendrik> <49855129.9070901@shopzeus.com> Message-ID: Laszlo Nagy wrote: > >> 8<------------------------------ >> >> >>> ....... Setting the >>> SO_REUSEADDR flag on POSIX fixes this problem (don't set it on Windows, >>> though). >>> >> >> Why not? I have been merrily setting it, and I have not noticed >> anything weird. >> (yet) >> > Please see my original post. I specifically stated that I do not want to > use setsockopt and be able to listen on the same port from many > processes. I knew that I could use SO_REUSEADDR, but I'm heistating to > do so. I must guarantee that only one process listens on a given port at > the same time. > This appears to demonstrate a misunderstanding of the purpose of the SO_REUSEADDR flag. SO_REUSEADDR should be used to avoid the TIME_WAIT state when the current listening process terminates. If you do not use it then there will be a certain period during which no other process can listen on that port, and it will be reusable only after the TIME_WAIT is over. This can easily be seen by using the netstat utility. See "Pitfall 3" in http://www.ibm.com/developerworks/linux/library/l-sockpit/index.html > Maybe I could use some kind of locking, but it would be too difficult: > > - mutexes are great but they are platform dependent and they are not in > the standard lib > - the listening processes do not see each other's home directory so file > locking cannot be used for this > - these processes will probably listen on many ports at the same time, > it is also a problem with mutexes/file locks (who wants 50 lock files to > be created?) > Complete red herring: there is no way for multiple processes to listen to the same port: this would lead to ambiguity in the protocol stack. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From notvalid2 at sbcglobal.net Sun Feb 1 07:47:00 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Sun, 01 Feb 2009 04:47:00 -0800 Subject: Tkinter w.pack()? In-Reply-To: References: Message-ID: <_Lghl.12218$D32.6047@flpi146.ffdc.sbc.com> Steve Holden wrote: > W. eWatson wrote: >> Steve Holden wrote: >>> W. eWatson wrote: >>>> r wrote: >>>>> On Jan 28, 10:12 pm, "W. eWatson" wrote: >>>>>> Where in the world is a description of pack() for Tkinter widgets? >>>>>> Is it >>>>>> some sort of general method for all widgets? I'm looking in a few >>>>>> docs that >>>>>> use it without ever saying where it is described. For one, >>>>>> . In the NM Tech pdf on >>>>>> Tkinter, >>>>>> it's not found anywhere. I see Universal methods for widgets, but no >>>>>> mention >>>>>> of pack(). package, packed, but no pack. >>>>> did you try here :) >>>>> http://effbot.org/tkinterbook/pack.htm >>>> Thanks. I have the site bookmarked, but it's hard to search. I posted a >>>> comment to them that they should have it in pdf form. >>>> >>> http://letmegooglethatforyou.com/?q=site%3Aeffbot.org%2Ftkinterbook+pack >>> >>> regards >>> Steve >> Well, that's an interesting "link". Another side of Google facilities? >> Maybe you're using Snagit or its brethern? However, I'm interested in >> searching a pdf, which, of course, doesn't yet exist. >> > OK, someone asked if you'd seen the HTML pages. You replied that you had > them bookmarked but they were difficult to search. So I simply > demonstrated that a search of the site for "pack" gave the right page as > its first result. > > Maybe you *do* want a PDF, but it will be less searchable than the > existing HTML, so I am somewhat confused about why. > > regards > Steve So what are you telling me? I should use Google to search the web site? If so, I guess I missed the method you used. Apparently, it hinges on the key "site:" The use of your video tool camouflaged your intent, IMHO. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From clp2 at rebertia.com Sun Feb 1 07:53:20 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 1 Feb 2009 04:53:20 -0800 Subject: is python Object oriented?? In-Reply-To: <325fcc08-c090-44f9-b158-967e6dec212a@13g2000yql.googlegroups.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> <325fcc08-c090-44f9-b158-967e6dec212a@13g2000yql.googlegroups.com> Message-ID: <50697b2c0902010453r6a2e7ef4ma6870cbe38032e83@mail.gmail.com> On Sat, Jan 31, 2009 at 9:08 AM, wrote: > On Jan 30, 12:15 am, Chris Rebert wrote: >> - Python supports encapsulation. Prefixing an attribute/method with an >> underscore indicates that other programmers should treat it as >> 'private'. However, unlike B&D languages, Python itself does nothing >> to enforce this privacy, leaving it instead to the good judgement of >> the programmer, under the philosophy that "We're all consenting adults >> here". > > How do you know? (I know I'm not.) > > Seriously, though, the lack of private members does allow for ugly > hacks in user code, and you know there are always ugly hackers. Marc already addressed your points excellently, but I'll add that I once read somewhere (can't be bothered to find the source, PG maybe?) that mediocre programming languages are designed for average programmers and presume the language designers are smarter than the programmer, whereas the truly great languages are designed for great programmers and presume that the programmer is smarter than (or at least knows better than) the designer. This allows smart programmers using great languages to say: "I don't like X about the language, I think I'll change it" or "The language needs Y, I'll add it". For example, see the amazing magic some Python people have worked using metaclasses. Whereas smart programmers using a mediocre language are stuck: "I don't like X about the language and there's nothing I can do about it short of hacking the language implementation. Darn. Now I'm going to have to write Y lines every time I want to workaround X since the language doesn't let me factor the solution out any further! (sigh)". For example, consider looping through an array in Java before the new 'for' statement was added. Therefore, Python wisely chooses to not give a damn about how "ugly hackers" may abuse the language; they'll abuse *any* language they get their grubby mitts on; just let them and their ugly code quietly rot in the corner while the elite are allowed by the language the extra leeway they need to write their code masterpieces, which the common people can then use to improve their programs. Not that I'm saying any of us are necessarily elite; just don't be /particularly/ stupid by using anything *clearly marked* with an initial underscore without *extremely* good reason. And this isn't to say the language shouldn't take average programmers into account; just don't overly restrict the the 90% that are decent programmers in the name of trying to save the bottom 10% from themselves (it's rather like the "Save the Children!" retort on /.) Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From steve at holdenweb.com Sun Feb 1 07:58:58 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 01 Feb 2009 07:58:58 -0500 Subject: socket.unbind or socket.unlisten? - socket.error: (48, 'Address already in use') In-Reply-To: <49855129.9070901@shopzeus.com> References: <20090127134145.24460.1190938528.divmod.quotient.2653@henry.divmod.com> <004e01c98095$f90f9440$0d00a8c0@hendrik> <49855129.9070901@shopzeus.com> Message-ID: Laszlo Nagy wrote: > >> 8<------------------------------ >> >> >>> ....... Setting the >>> SO_REUSEADDR flag on POSIX fixes this problem (don't set it on Windows, >>> though). >>> >> >> Why not? I have been merrily setting it, and I have not noticed >> anything weird. >> (yet) >> > Please see my original post. I specifically stated that I do not want to > use setsockopt and be able to listen on the same port from many > processes. I knew that I could use SO_REUSEADDR, but I'm heistating to > do so. I must guarantee that only one process listens on a given port at > the same time. My previous reply assumed you are running some UNIX-like operating system. If you are on Windows then Jean-Paul's advice stands, as Windows *does* allow several processes to listen on the same port and randomly delivers incoming connections to one of the listening processes. I believe this is because Microsoft failed to understand the original meaning of SO_REUSEADDR for their early TCP implementations, and persisted with this ghastly error in the name of backwards compatibility, justifying it by suggesting that listener pools could be created. Or some such nonsense. Perhaps someone with more insight into the development process could comment. It seems to me it's completely bizarre. However, under Windows 2000 and later you should find there's an SO_EXCLUSIVEADDRUSE flag which you can use to ensure a single listener - see http://msdn.microsoft.com/en-us/library/ms740621(VS.85).aspx. No need for separate locks. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sun Feb 1 08:00:42 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 01 Feb 2009 08:00:42 -0500 Subject: accessing elements of a tuple In-Reply-To: <0195522e$0$31512$c3e8da3@news.astraweb.com> References: <0195522e$0$31512$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > D'Arcy J.M. Cain wrote: > >> First of all, list is a reserved word. Don't use it as a variable name. > > Unless you mean to. Shadowing built-ins is only a bad thing when you do it > by accident. > Quite. And we should observe that "list" is not a reserved word in the sense of a keyword with a specific syntactic meaning, otherwise it wouldn't be possible to shadow it in the first place. It's just the name of one of Python's built-in types. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From p-santoro at sbcglobal.net Sun Feb 1 08:20:50 2009 From: p-santoro at sbcglobal.net (Peter) Date: Sun, 01 Feb 2009 08:20:50 -0500 Subject: Embedded python 2.6 interpreter can't "import sqlite3" on Windows XP In-Reply-To: References: Message-ID: jdetaeye wrote: > I am porting an application which embeds a Python interpreter to > Python 2.6. > On version 2.5 all is working fine, but importing the sqlite3 module > doesn't work any more on 2.6. > > The statement "import sqlite3" does work fine when executed from in > the python command prompt, ie not from the embedded interpreter. > The same import gives the following error when executed from the > embedded interpreter. > Python stacktrace: > Traceback (most recent call last): > File "", line 2, in > File "C:\Python26\lib\sqlite3\__init__.py", line 24, in > > from dbapi2 import * > File "C:\Python26\lib\sqlite3\dbapi2.py", line 27, in > > from _sqlite3 import * > ImportError: DLL load failed: A dynamic link library (DLL) > initialization routine failed. > Windows popup window: > Runtime Error! > R6034 > An application has made an attempt to load the C runtime > library incorrectly. > Please contact the application's support team for more > information. > > Unfortunately the "application support team" (that is me :-) has no > idea on how to move forward on this: > a) I guess this is releated to the problem with manifest files, > already reported in http://bugs.python.org/issue4120 ? > b) What could be a solution or workaround for the problem? > > All the above is on Windows XP. > Other modules with have an extension DLL (such as ssl) give exactly > the same problem. > > All help appreciated, > > Johan > Python 2.6+ was built with Visual Studio 2008; therefore, the Microsoft Visual C++ 2008 Redistributable Package (run time libraries) must be installed on the computer that you are trying to run your python application. If the computer already has Python 2.6+ installed "for all users", then the run time libraries should already be installed in c:\windows\winsxs. On computers that do not have Python 2.6+ installed (or it was installed using "Install Just for Me"), you probably will need to install the Visual C++ 2008 Redistributable Package. It is possible that some other application already installed the correct run time libraries in the c:\windows\winsxs directory. Visual C++ 2008 Redistributable Package: http://www.microsoft.com/downloads/details.aspx?FamilyID=9b2da534-3e03-4391-8a4d-074b9f2bc1bf&displaylang=en After installing the Visual C++ 2008 Redistributable, you can find it under the c:\windows\winsxs directory. Side-by-Side (sxs) Assemblies are Microsoft's answer to "DLL hell" and Visual C++ 2005 had them, too. I believe the reason the Python community didn't see these problems earlier was that most computers already had the proper run time libraries installed. See "Application Compatibility?Side-by-side Assemblies" in http://msdn.microsoft.com/en-us/magazine/cc302206.aspx and http://msdn.microsoft.com/en-us/magazine/ms997620.aspx for more information on Side-by-Side Assemblies. Note that if future versions of Python are built with Visual Studio 2008 with service pack (SP) #x and the build specifies that the SP #x updated run time libraries should be used, then you'll need to install the updated run time libraries. See http://msdn.microsoft.com/en-us/library/cc664727.aspx and http://msdn.microsoft.com/en-us/library/ms235299(VS.80).aspx for more information on binding applications to specific run time libraries. The following articles may also be of interest: http://msdn.microsoft.com/en-us/library/ms235531.aspx http://msdn.microsoft.com/en-us/library/ms235342.aspx http://msdn.microsoft.com/en-us/library/aa374224.aspx Of course everything I've just said may change with the next release of Python, because the Python maintainers are apparently looking at alternative ways around this issue. Although I'm not a Microsoft fan, I'm not yet convinced that trying to work around Microsoft's winsxs requirements is a smart thing to do. It might simplify things for python users and developers if the Python 2.6+ installers always installed the VS C++ run time libraries into the winsxs directory. Perhaps python tools that create embedded python applications could better document this issue, so that people using embedded applications will know that they have to install the proper run time libraries. It's also possible that Microsoft will someday install these new Visual Studio 2008 run time libraries via their update service or a future service pack. Peter From matthewbdaly at googlemail.com Sun Feb 1 08:25:53 2009 From: matthewbdaly at googlemail.com (MattBD) Date: Sun, 1 Feb 2009 05:25:53 -0800 (PST) Subject: what IDE is the best to write python? References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> Message-ID: On Feb 1, 12:19?pm, Stef Mientki wrote: > > IMHO, scripting languages like Python are generally better suited to > > working with a text editor than an IDE. > > I don't understand that, because in my opinion yields > ? IDE = texteditor + (much) more > please could you explain (as I'm very interested in user interfaces in > general ) > > cheers, > Stef Obviously, this is just my opinion. The great debate over which is better, an IDE or text editor, has been going on for years, and no doubt plenty of other people will disagree. Really it depends what you are doing. Some languages are very tightly integrated with an IDE, such as MS Visual C#, and as far as I can see it would be extremely difficult, if not impossible to use a text editor with that language. If you only use one language and that has an IDE you like, there's nothing wrong with sticking with that. IDE's are often (but not always) designed for a specific language. Text editors are more flexible and will generally work well with virtually any language. You may lose a little in terms of language- specific functionality such as autocompletion and fancy graphical tools, but you gain in flexibility because the one text editor will work well with many languages, so you can write programs in C, Perl, Python, Ruby, or whatever takes your fancy, and still use the same tools you're used to, which I'd argue makes you more productive as you're working within a familiar environment. However, there are IDE's which support multiple languages, such as Eclipse. Also, I'm strongly of the opinion that using a text editor when you get started is the way to go. You're more likely to take in every last detail of something if you type out the commands in detail rather than using autocompletion. Also, an IDE can add an unnecessary level of complication - as well as learning a language you have to learn an IDE, which can be extremely complex. So it can be simpler to just use a text editor, which is often simpler. Conversely, IDE's can be better for designing interfaces as they generally allow you to design them in a way that's more intuitive to most people. It's not exactly true to say that an IDE = text editor + much more. It's more about the nature of the features. A modern programmer's text editor such as Vim is an extremely powerful and flexible piece of software. I've just barely started to scratch the surface of what Vim can do and I learn something new virtually every time I use it. Although technically it can mean you have to do more typing than you would with an IDE, it also makes it a lot faster to type the text you put in. An IDE will roll everything you need into one package, including the compiler/interpreter, editor and debugger. A text editor does the text editing only, but in practice most of them allow you to access the command line from within the text editor (in Vim you just enter :! followed by the command you want to run), so you can use other tools from within the editor. I do most of my coding in Linux, so I would write a program in Vim, save it, then enter something like :!python example.py to run it. At the end of the day it's personal taste. I've tinkered with a few IDE's but I find text editors work better for me at the end of the day, and Vim in particular is one that really works well for me. It does depend on what you're doing. For larger projects sometimes a dedicated IDE is better, but most decent text editors can do a lot of the same things that an IDE can. It just requires a different approach. I'd recommend you check out this article: http://osteele.com/archives/2004/11/ides That gives a good insight into the whole IDE's vs text editors thing. From Platcool at gmail.com Sun Feb 1 08:47:49 2009 From: Platcool at gmail.com (BlakeF) Date: Sun, 1 Feb 2009 05:47:49 -0800 (PST) Subject: persistent TCP connection in python using socketserver References: Message-ID: <5b7dce20-c707-4372-8af8-e403ce8de82a@y23g2000pre.googlegroups.com> On Jan 29, 8:54?pm, Jean-Paul Calderone wrote: > On Thu, 29 Jan 2009 08:38:43 -0800 (PST), markobrie... at gmail.com wrote: > >G'day > > >I'm currently usingsocketserverto build a simple XMLSocket (an XML > >based protocol used for communication between flash and the outside > >world) server. I've got flash establishing a connection, sending a > >request and my python server responding. However at this point > >socketserverterminates the connection. Which is bad, since i need a > >persistentconnection so i can push data from the server to the client > >without the overhead of polling. > > If you don't want the connection to close, then don't let the request > complete. ?SocketServerimplements logic for single request/response > per connection. ?You can change this by making your requests take a > really long time (until you're done with the connection) or you can > override the behavior which closes the connection after a response. > > Or you could use the socket module, on which theSocketServermodule is > based. ?Or you could use Twisted, another higher-level package built on > the socket module (mostly). ?Actually, I recommend Twisted, since it will > mostly isolate you from boring low-level details and let you implement > whatever high-level behavior you're after (I know that a bunch of people > have used it to communicate with Flash, for example). > > Jean-Paul Hi, Jean-Paul has something like this in mind (I think): class Foobar(BaseRequestHandler): def handle(self): self.data = None while self.data != 'QUIT': self.data = self.request.recv(1024).strip().upper() if self.data == '': sleep(1) else: self.request.send(self.data) This will keep a persistent connection, only closing on 'quit' being received. I'm sure it's not the best way, but it certainly works. Cheers, -Blake From steve at holdenweb.com Sun Feb 1 08:56:27 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 01 Feb 2009 08:56:27 -0500 Subject: Tkinter w.pack()? In-Reply-To: <_Lghl.12218$D32.6047@flpi146.ffdc.sbc.com> References: <_Lghl.12218$D32.6047@flpi146.ffdc.sbc.com> Message-ID: W. eWatson wrote: > Steve Holden wrote: >> W. eWatson wrote: >>> Steve Holden wrote: >>>> W. eWatson wrote: >>>>> r wrote: >>>>>> On Jan 28, 10:12 pm, "W. eWatson" wrote: >>>>>>> Where in the world is a description of pack() for Tkinter widgets? >>>>>>> Is it >>>>>>> some sort of general method for all widgets? I'm looking in a few >>>>>>> docs that >>>>>>> use it without ever saying where it is described. For one, >>>>>>> . In the NM Tech pdf on >>>>>>> Tkinter, >>>>>>> it's not found anywhere. I see Universal methods for widgets, but no >>>>>>> mention >>>>>>> of pack(). package, packed, but no pack. >>>>>> did you try here :) >>>>>> http://effbot.org/tkinterbook/pack.htm >>>>> Thanks. I have the site bookmarked, but it's hard to search. I >>>>> posted a >>>>> comment to them that they should have it in pdf form. >>>>> >>>> http://letmegooglethatforyou.com/?q=site%3Aeffbot.org%2Ftkinterbook+pack >>>> >>>> >>>> regards >>>> Steve >>> Well, that's an interesting "link". Another side of Google facilities? >>> Maybe you're using Snagit or its brethern? However, I'm interested in >>> searching a pdf, which, of course, doesn't yet exist. >>> >> OK, someone asked if you'd seen the HTML pages. You replied that you had >> them bookmarked but they were difficult to search. So I simply >> demonstrated that a search of the site for "pack" gave the right page as >> its first result. >> >> Maybe you *do* want a PDF, but it will be less searchable than the >> existing HTML, so I am somewhat confused about why. >> >> regards >> Steve > So what are you telling me? I should use Google to search the web site? > If so, I guess I missed the method you used. Apparently, it hinges on > the key "site:" The use of your video tool camouflaged your intent, IMHO. > The use of "letmegooglethatforyou" (not my video tool, by the way) is to point out that with the right search string you could have answered the question for yourself. Since you didn't appear to know that Google allowed you to search a single site (something I perhaps take for granted) I am glad that point wasn't lost. Yes, you can just search the PIL documentation. Isn't the Internet great? ;-) regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From fasteliteprogrammer at yahoo.com Sun Feb 1 09:10:46 2009 From: fasteliteprogrammer at yahoo.com (Craig) Date: Sun, 1 Feb 2009 06:10:46 -0800 (PST) Subject: what IDE is the best to write python? Message-ID: <531189.66795.qm@web36504.mail.mud.yahoo.com> eclipse --- On Sun, 2/1/09, Dennis Lee Bieber wrote: From: Dennis Lee Bieber Subject: Re: what IDE is the best to write python? To: python-list at python.org Date: Sunday, February 1, 2009, 3:31 AM On Sat, 31 Jan 2009 23:42:42 -0800 (PST), "mcheung63 at hotmail.com" declaimed the following in comp.lang.python: > Hi all >? ? what IDE is the best to write python? ??? The one in which YOU are most comfortable. -- ??? Wulfraed??? Dennis Lee Bieber??? ??? KD6MOG ??? wlfraed at ix.netcom.com??? ??? wulfraed at bestiaria.com ??? ??? HTTP://wlfraed.home.netcom.com/ ??? (Bestiaria Support Staff:??? ??? web-asst at bestiaria.com) ??? ??? HTTP://www.bestiaria.com/ -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From darcy at druid.net Sun Feb 1 09:32:42 2009 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sun, 1 Feb 2009 09:32:42 -0500 Subject: accessing elements of a tuple In-Reply-To: <0195522e$0$31512$c3e8da3@news.astraweb.com> References: <0195522e$0$31512$c3e8da3@news.astraweb.com> Message-ID: <20090201093242.199b7e8c.darcy@druid.net> On Sun, 01 Feb 2009 19:23:58 +1100 Steven D'Aprano wrote: > D'Arcy J.M. Cain wrote: > > > First of all, list is a reserved word. ?Don't use it as a variable name. > > Unless you mean to. Shadowing built-ins is only a bad thing when you do it > by accident. I suppose but I am having a hard time trying to think of some good reason to replace a builtin function that creates a list with a list object. >>> list = list((1,2,3)) >>> list((1,2,3)) Traceback (most recent call last): File "", line 1, in TypeError: 'list' object is not callable -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From stef.mientki at gmail.com Sun Feb 1 09:33:51 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Sun, 01 Feb 2009 15:33:51 +0100 Subject: what IDE is the best to write python? In-Reply-To: References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> Message-ID: <4985B2CF.3080001@gmail.com> thanks Matthew, for the extended answer and the great link, I'm going to study that carefully. cheers, Stef MattBD wrote: > On Feb 1, 12:19 pm, Stef Mientki wrote: > >>> IMHO, scripting languages like Python are generally better suited to >>> working with a text editor than an IDE. >>> >> I don't understand that, because in my opinion yields >> IDE = texteditor + (much) more >> please could you explain (as I'm very interested in user interfaces in >> general ) >> >> cheers, >> Stef >> > > Obviously, this is just my opinion. The great debate over which is > better, an IDE or text editor, has been going on for years, and no > doubt plenty of other people will disagree. > > Really it depends what you are doing. Some languages are very tightly > integrated with an IDE, such as MS Visual C#, and as far as I can see > it would be extremely difficult, if not impossible to use a text > editor with that language. If you only use one language and that has > an IDE you like, there's nothing wrong with sticking with that. > > IDE's are often (but not always) designed for a specific language. > Text editors are more flexible and will generally work well with > virtually any language. You may lose a little in terms of language- > specific functionality such as autocompletion and fancy graphical > tools, but you gain in flexibility because the one text editor will > work well with many languages, so you can write programs in C, Perl, > Python, Ruby, or whatever takes your fancy, and still use the same > tools you're used to, which I'd argue makes you more productive as > you're working within a familiar environment. However, there are IDE's > which support multiple languages, such as Eclipse. > > Also, I'm strongly of the opinion that using a text editor when you > get started is the way to go. You're more likely to take in every last > detail of something if you type out the commands in detail rather than > using autocompletion. Also, an IDE can add an unnecessary level of > complication - as well as learning a language you have to learn an > IDE, which can be extremely complex. So it can be simpler to just use > a text editor, which is often simpler. > > Conversely, IDE's can be better for designing interfaces as they > generally allow you to design them in a way that's more intuitive to > most people. > > It's not exactly true to say that an IDE = text editor + much more. > It's more about the nature of the features. A modern programmer's text > editor such as Vim is an extremely powerful and flexible piece of > software. I've just barely started to scratch the surface of what Vim > can do and I learn something new virtually every time I use it. > Although technically it can mean you have to do more typing than you > would with an IDE, it also makes it a lot faster to type the text you > put in. > > An IDE will roll everything you need into one package, including the > compiler/interpreter, editor and debugger. A text editor does the text > editing only, but in practice most of them allow you to access the > command line from within the text editor (in Vim you just enter :! > followed by the command you want to run), so you can use other tools > from within the editor. I do most of my coding in Linux, so I would > write a program in Vim, save it, then enter something like :!python > example.py to run it. > > At the end of the day it's personal taste. I've tinkered with a few > IDE's but I find text editors work better for me at the end of the > day, and Vim in particular is one that really works well for me. It > does depend on what you're doing. For larger projects sometimes a > dedicated IDE is better, but most decent text editors can do a lot of > the same things that an IDE can. It just requires a different > approach. > > I'd recommend you check out this article: > http://osteele.com/archives/2004/11/ides > That gives a good insight into the whole IDE's vs text editors thing. > -- > http://mail.python.org/mailman/listinfo/python-list > From marko.loparic at gmail.com Sun Feb 1 10:13:36 2009 From: marko.loparic at gmail.com (markolopa) Date: Sun, 1 Feb 2009 07:13:36 -0800 (PST) Subject: python alternative to java rapid ajax platform (RAP)? Message-ID: <226786ae-5e21-4b27-a7e6-7143f03ca1cb@r41g2000prr.googlegroups.com> Hi, Do you know a python alternative to rapid ajax platform (RAP)? For the development of a user interface for mathematical models someone suggested to use eclipse and that tool: http://www.eclipse.org/rap/ http://www.eclipse.org/rap/about.php If I understand correctly it allows you to design very easily a web client interacting with your application (in particular you write no javascript and qooxdoo is called for you). It seems to be to be a very interesting package except that... it is in java. So I would like to know if there is something similar using python. Alternatively I would like to know if there is a way to use this tool doing the minimum in java and the most in python (probably not). Thanks! Marko From google at mrabarnett.plus.com Sun Feb 1 10:27:48 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sun, 01 Feb 2009 15:27:48 +0000 Subject: is python Object oriented?? In-Reply-To: References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> Message-ID: <4985BF74.9030300@mrabarnett.plus.com> David Bolen wrote: > thmpsn.m.k at gmail.com writes: > >> I don't know how you would do it in C# (or Java for that matter). >> >> In C++ you can play with pointers to "get at" some memory location >> somewhere in the object. The only portable way to know the exact >> location between the beginning of the object and the desired member is >> the offsetof() macro, but as I understand it this only works for POD >> types, which means that it won't work for classes such as: >> >> class NonPOD >> { >> private: >> int a; >> int b; >> public: >> NonPOD(); >> ~NonPOD(); >> int C(); >> }; >> >> (I haven't ever actually tried it, so I'm not sure.) >> >> Nevertheless, you can play and hope for the best. For example, if the >> member you want to get at is 'b', then you can do: >> >> NonPOD obj; >> std::cout << "obj.b = " << *(int*) ((unsigned char*) &obj + sizeof >> (int)) << std::endl; >> >> and hope that the compiler didn't leave a hole between the 'a' member >> and the 'b' member. > > Probably moving off topic, but I don't think you have to get anywhere > near that extreme in terms of pointers, unless you're trying to deal > with instances for which you have no source but only opaque pointers. > > I haven't gotten stuck having to do this myself yet, but I believe one > commmon "hack" for the sort of class you show above is to just > "#define private public" before including the header file containing > the class definition. No fiddling with pointers, offsets, or > whatever, just normal object access syntax past that point. > > Of course, I believe such a redefinition violates the letter of the > C++ standard, but most preprocessors do it anyway. Also, it won't > handle the case where the "private:" is not used, but the members are > just declared prior to any other definition, since a class is private > by default. > [snip] You can also "#define class struct" before including the header file. The only difference between 'class' and 'struct' in C++ is that the members of a class are private by default and the members of a struct are public by default. From cito at online.de Sun Feb 1 10:33:51 2009 From: cito at online.de (Christoph Zwerschke) Date: Sun, 01 Feb 2009 16:33:51 +0100 Subject: Problem with slow httplib connections on Windows (and maybe other platforms) Message-ID: It cost me a while to analyze the cause of the following problem. The symptom was that testing a local web app with twill was fast on Python 2.3, but very slow on Python 2.4-2.6 on a Win XP box. This boiled down to the problem that if you run a SimpleHTTPServer for localhost like this, BaseHTTPServer.HTTPServer(('localhost', 8000), SimpleHTTPServer.SimpleHTTPRequestHandler).serve_forever() and access it using httplib.HTTPConnection on the same host like this httplib.HTTPConnection('localhost', 8000).connect() then this call is fast using Py 2.3, but slow with Py 2.4-2.6. I found that this was caused by a mismatch of the ip version used by SimpleHTTPServer and HTTPConnection for a "localhost" argument. What actually happens is the following: * BaseHTTPServer binds only to the IPv4 address of localhost, because it's based on TCPServer which has address_family=AF_INET by default. * HTTPConnection.connect() however tries to connect to all IP addresses of localhost, in the order determined socket.getaddrinfo('localhost'). With Py 2.3 (without IPv6 support) this is only the IPv4 address, but with Py 2.4-2.6 the order is (on my Win XP host) the IPv6 address first, then the IPv4 address. Since the IPv6 address is checked first, this gives a timeout and causes the slow connect() call. The order by which getaddrinfo returns IPv4/v6 under Linux seems to vary depending on the glibc version, so it may be a problem on other platforms, too. You can see the cause of the slow connect() like this: import httplib conn = httplib.HTTPConnection('localhost', 8000) conn.set_debuglevel(1) conn.connect() This is what I get: connect: (localhost, 8000) connect fail: ('localhost', 8000) connect: (localhost, 8000) The first (failing) connect is the attempt to connect to the IPv6 address which BaseHTTPServer doesn't listen to. (This is the debug output of Py 2.5 which really should be improved to show the IP address that is actually used. Unfortunately, in Py 2.6 the debug output when connecting has even fallen prey to a refactoring. I think it should either be added again or set_debuglevel() is now pretty meaningless.) Can we do something about the mismatch that SimpleHTTPServer only serves IPv4, but HTTPConnection tries to connect with IPv6 first? I guess other people also stumbled over this, maybe without even noticing and just wondering about the slow performance. E.g.: http://schotime.net/blog/index.php/2008/05/27/slow-tcpclient-connection-sockets/ One possible solution would be to improve the TCPServer in the standard lib so that it determines the address_family and real server_address based on the first return value of socket.getaddrinfo, like this: class TCPServer(BaseServer): ... def __init__(self, server_address, RequestHandlerClass): if server_address and len(server_address) == 2: (self.address_family, dummy, dummy, dummy, server_address) = socket.getaddrinfo(*server_address)[0] else: raise TypeError("server_address must be a 2-tuple") BaseServer.__init__(self, server_address, RequestHandlerClass) ... That way, if you either serve as or connect to 'localhost', you will always consistently do this via IPv4 or IPv6, depending on what is preferred on your platform. Does this sound reasonable? Any better ideas? -- Christoph From vedrandekovic at yahoo.com Sun Feb 1 10:44:55 2009 From: vedrandekovic at yahoo.com (vedrandekovic at yahoo.com) Date: Sun, 1 Feb 2009 07:44:55 -0800 (PST) Subject: Python time measure question (timeit) Message-ID: <4bea652f-6935-47cb-9610-831d859a0b57@d36g2000prf.googlegroups.com> Hello, When I run following code with os.popen (for this time measure I'm using python module timeit): for i in range(50): print i I get this result: 0.00246958761519 But when I run same code from IDLE i get this result: 6.4533341528e-005 now, I have two questions: 1) Which of this results is correct? 2) Are this results in micro seconds? Regards, John From kimwlias at gmail.com Sun Feb 1 10:48:50 2009 From: kimwlias at gmail.com (kimwlias) Date: Sun, 1 Feb 2009 07:48:50 -0800 (PST) Subject: Problems installing PySQLite, SQLite and Trac Message-ID: <1f1e74d1-f8b4-49e8-92d7-24c2354c8ca7@o40g2000prn.googlegroups.com> My initial goal is to finally install Trac. This is the second day I've been trying to make this possible but I can't find, for the life of me, how to do this. OK, here is the story: My system is a VPS with CentOS 5. I found out that I have two versions of python: 2.4 at /usr/bin/ python2.4 and 2.5.2 at /usr/local/apps/python/bin/python2.5 My first try was to download the SQLite amalgamation, './configure', 'make' and 'make install'. Then I downloaded the PySQLite and 'python setup.py install'. The funny part is that python2.4 has sqlite while python2.5 doesn't: [root at xxx]# python Python 2.5.2 (r252:60911, May 10 2008, 17:42:40) [GCC 4.1.2 20070626 (Red Hat 4.1.2-14)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sqlite Traceback (most recent call last): File "", line 1, in ImportError: No module named sqlite [root at xxx]# python2.4 Python 2.4.3 (#1, Mar 14 2007, 18:51:08) [GCC 4.1.1 20070105 (Red Hat 4.1.1-52)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sqlite >>> After some more research I found out that the amalgamation is not the default way and I needed to run the extended_setup.py which isn't inside the pysqlite! -> http://oss.itsystementwicklung.de/trac/pysqlite/wiki/PysqliteAmalgamation I then thought, "OK, let's install the SQLite from the precompiled binary packages". So I downloaded the first two packages from here: http://www.sqlite.org/download.html . The one contains a .bin file and the other an .so file. I must admit, I'm relatively new in Linux so I don't know what do with these files. And there is NO DOCUMENTATION what so ever on how to use these two in the SQLite website. Not even a slight hint where to look for. The so called documentation is just a download version of the website.... You can find some more information about my problem here: http://stackoverflow.com/questions/500055/issues-installing-sqlite-pysqlite-trac-in-centos I really really really need your help. Thank you so much in advance. From berserker992 at gmail.com Sun Feb 1 11:01:43 2009 From: berserker992 at gmail.com (berserker992 at gmail.com) Date: Sun, 1 Feb 2009 08:01:43 -0800 (PST) Subject: Problem With py2exe and ConfigParser Message-ID: <8b776264-1a6f-4f75-9a06-2b68d908b2fe@p23g2000prp.googlegroups.com> Hello, i use python 2.6 + PyQt4. I compile my main.pyw. It is compile, but don't run. In "index.exe.log" error log: >>> File "index.pyw", line 100, in GetVal >>>ConfigParser.NoSectionError: No section: 'Main' >>>Code line 92 to 104 this is class that uses ConfigParser lib: >>>class ConfigAcces: >>> def __init__(self): >>> self.cnf = ConfigParser() >>> def GetLibUrl(self): >>> self.cnf.read("config.ini") >>> return self.cnf.get("Main","lib_path") >>> def GetVal(self, p, key): >>> self.cnf.read("config.ini") >>> return self.cnf.get(p,key) >>> def SetVal(self, selection, option, NewVal): >>> self.cnf.read("config.ini") >>> self.cnf.set(selection,option,NewVal) >>> self.cnf.write(open("config.ini", "w")) how do I fix this? From grante at visi.com Sun Feb 1 11:01:52 2009 From: grante at visi.com (Grant Edwards) Date: Sun, 01 Feb 2009 10:01:52 -0600 Subject: socket.unbind or socket.unlisten? - socket.error: (48, 'Address already in use') References: <20090127134145.24460.1190938528.divmod.quotient.2653@henry.divmod.com> <004e01c98095$f90f9440$0d00a8c0@hendrik> <49855129.9070901@shopzeus.com> Message-ID: On 2009-02-01, Steve Holden wrote: > I believe this is because Microsoft failed to understand the > original meaning of ___________________, and persisted with > this ghastly error in the name of backwards compatibility, > justifying it by suggesting that _________________________. Somebody should have cards printed up... -- Grant From steve at pearwood.info Sun Feb 1 11:02:17 2009 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 02 Feb 2009 03:02:17 +1100 Subject: fastest way to detect a user type References: <49847EBB.4050307@jessikat.plus.net> <0195504e$0$20642$c3e8da3@news.astraweb.com> <7xzlh6bm2t.fsf@ruckus.brouhaha.com> <0195625a$0$23675$c3e8da3@news.astraweb.com> <498596A0.6030005@jessikat.plus.net> Message-ID: <0195bd97$0$14422$c3e8da3@news.astraweb.com> Robin Becker wrote: > Steven D'Aprano wrote: >> Paul Rubin wrote: >> >>> Steven D'Aprano writes: >>>> First question is, why do you care that it's slower? The difference >>>> between the fastest and slowest functions is 1.16-0.33 = 0.83 >>>> microsecond. >>> That's a 71% speedup, pretty good if you ask me. >> >> Don't you care that the code is demonstrably incorrect? The OP is >> investigating options to use in Python 3, but the fastest method will >> fail, because the "type is InstanceType" test will no longer work. (I >> believe the fastest method, as given, is incorrect even in Python 2.x, as >> it will accept ANY old-style class instead of just the relevant X or V >> classes.) > > I'm not clear why this is true? Not all instances will have the __X__ > attribute or has something else changed in Python3? The func0() test doesn't look for __X__. > The original code was intended to be called with only a subset of all > class instances being passed as argument; as currently written it was > unsafe because an instance of an arbitrary old class would pass into > branch 1. Of course it will still be unsafe as arbitrary instances end > up in branch 3 > > The intent is to firm up the set of cases being accepted in the first > branch. The problem is that when all instances are new style then > there's no easy check for the other acceptable arguments eg float,int, > str etc, Of course there is. isinstance(ob, (float, int)) is the easy, and correct, way to check if ob is a float or int. > as I see it, the instances must be of a known class or have a > distinguishing attribute. Are you sure you need to check for different types in the first place? Just how polymorphic is your code, really? It's hard to judge because I don't know what your code actually does. > As for the timing, when I tried the effect of func1 on our unit tests I > noticed that it slowed the whole test suite by 0.5%. An entire half a percent slower. Wow. That's like one minute versus one minute and 0.3 second. Or one hour, versus one hour and 18 seconds. I find it very difficult to get worked up over such small differences. I think you're guilty of premature optimization: wasting time and energy trying to speed up parts of the code that are trivial. (Of course I could be wrong, but I doubt it.) > Luckily func 3 > style improved things by about 0.3% so that's what I'm going for. I would call that the worst solution. Not only are you storing an attribute which is completely redundant (instances already know what type they are, you don't need to manually store a badge on them to mark them as an instance of a class), but you're looking up this attribute only to immediately throw away the value you get. The only excuse for this extra redirection would be if it were significantly faster. But it isn't: you said it yourself, 0.3% speed up. That's like 60 seconds versus 59.82 seconds. -- Steven From dchandran1 at tinkercell.com Sun Feb 1 11:33:29 2009 From: dchandran1 at tinkercell.com (Deepak Chandran) Date: Sun, 1 Feb 2009 08:33:29 -0800 Subject: Embedding numpy works once, but not twice?? In-Reply-To: References: <5dfe78f40901312147i957450ei187b08028c068a6@mail.gmail.com> Message-ID: <5dfe78f40902010833o14097535k379cca019c47316e@mail.gmail.com> I sort of guessed that was the issue -- doing Py_Initialize/Py_Finalize more than once. Thanks for the help. On Sun, Feb 1, 2009 at 12:43 AM, Gabriel Genellina wrote: > En Sun, 01 Feb 2009 03:47:27 -0200, Deepak Chandran < > dchandran1 at tinkercell.com> escribi?: > > I have a program in which I have successfully embedded Python. Now, I want >> to include NumPy as well (and other modules). I am able to import numpy >> once. Then I close the python console in my program and then re-open it. >> When I try to import numpy for a second time, the program crashes. Below >> is >> a simple version of the problem. >> > > The problem is not with NumPy. You can't run Py_Initialize/Py_Finalize more > than once. Python doesn't have any mechanism to un-initialize loaded > modules, and any static data that NumPy had initialized the first time it is > imported becomes invalid the second time. > Call Py_Initialize at the start of your program, and Py_Finalize at the > end, never more than once. > > -- > Gabriel Genellina > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at nospam.web.de Sun Feb 1 11:39:29 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 01 Feb 2009 17:39:29 +0100 Subject: Problem With py2exe and ConfigParser In-Reply-To: <8b776264-1a6f-4f75-9a06-2b68d908b2fe@p23g2000prp.googlegroups.com> References: <8b776264-1a6f-4f75-9a06-2b68d908b2fe@p23g2000prp.googlegroups.com> Message-ID: <6um1i1FfqskrU1@mid.uni-berlin.de> berserker992 at gmail.com schrieb: > Hello, i use python 2.6 + PyQt4. > I compile my main.pyw. It is compile, but don't run. In > "index.exe.log" error log: > >>>> File "index.pyw", line 100, in GetVal >>>> ConfigParser.NoSectionError: No section: 'Main' > > > > >>>> Code line 92 to 104 this is class that uses ConfigParser lib: >>>> class ConfigAcces: >>>> def __init__(self): >>>> self.cnf = ConfigParser() >>>> def GetLibUrl(self): >>>> self.cnf.read("config.ini") >>>> return self.cnf.get("Main","lib_path") >>>> def GetVal(self, p, key): >>>> self.cnf.read("config.ini") >>>> return self.cnf.get(p,key) >>>> def SetVal(self, selection, option, NewVal): >>>> self.cnf.read("config.ini") >>>> self.cnf.set(selection,option,NewVal) >>>> self.cnf.write(open("config.ini", "w")) > > > > how do I fix this? By passing the right path for the configuration file? It's obviously not found. Diez From steve at holdenweb.com Sun Feb 1 11:42:37 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 01 Feb 2009 11:42:37 -0500 Subject: Python time measure question (timeit) In-Reply-To: <4bea652f-6935-47cb-9610-831d859a0b57@d36g2000prf.googlegroups.com> References: <4bea652f-6935-47cb-9610-831d859a0b57@d36g2000prf.googlegroups.com> Message-ID: vedrandekovic at yahoo.com wrote: > Hello, > > When I run following code with os.popen (for this time measure I'm > using python module timeit): > > > for i in range(50): > print i > > > I get this result: 0.00246958761519 > > > But when I run same code from IDLE i get this result: > 6.4533341528e-005 > > > now, I have two questions: > 1) Which of this results is correct? Both are. What makes you think that printing in IDLE (to a GUI) should take the same amount of time as it does "running with os.popen (whatever that means). The two environments are likely to be completely different, but you haven't show the exact code you ran so it's hard to be more exact. > 2) Are this results in micro seconds? > No, seconds, as it says in the documentation: """This executes the setup statement once, and then returns the time it takes to execute the main statement a number of times, measured in seconds as a float""". Even a modern computer doesn't do much in .0024 microseconds. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From cd at okunah.de Sun Feb 1 11:47:39 2009 From: cd at okunah.de (Christof Donat) Date: Sun, 01 Feb 2009 17:47:39 +0100 Subject: what IDE is the best to write python? References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> Message-ID: Hi, >> IMHO, scripting languages like Python are generally better suited to >> working with a text editor than an IDE. >> > I don't understand that, because in my opinion yields > IDE = texteditor + (much) more > please could you explain (as I'm very interested in user interfaces in > general ) Try to think of the operating system as the IDE. At least with Unix and similar systems that is a really powerfull solution. It includes not only vim, bash and make, but also stuff like e.g. ctags, awk, sed, etc. Even python itsself is part of the system and can be used for special purpous utilities like e.g. code generators. If you need User Interface Design, there are quite powerful stand alone tools, like e.g. the QtDesigner which can be used with that "OS IDE". Christof From thmpsn.m.k at gmail.com Sun Feb 1 11:52:35 2009 From: thmpsn.m.k at gmail.com (thmpsn.m.k at gmail.com) Date: Sun, 1 Feb 2009 08:52:35 -0800 (PST) Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> Message-ID: <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> On Feb 1, 1:50?am, Marc 'BlackJack' Rintsch wrote: > On Sat, 31 Jan 2009 15:28:14 -0800, thmpsn.m.k wrote: > > On Jan 31, 2:27?pm, Christian Heimes wrote: > >> Do you honestly believe that C++'s private members are really private? > >> Privateness is only enforced during parsing time. Nobody can stop you > >> from messing around with header files or memory. You can still access > >> and modify private members but it's all messy and ugly. Even C# and > >> .NET don't stop you from doing nasty things from unmananged assemblies. > > > I don't know how you would do it in C# (or Java for that matter). > > In Java you can use reflection to get your fingers on private fields. > > > In C++ you can play with pointers to "get at" some memory location > > somewhere in the object. > > [Snipped pointer fiddling explanation] > > So: Sometimes it may work, usually it will be unsafe and/or non- > > portable, and in most cases the procedure will look complicated. > > Or ``#define private public`` before including the header files. ?Which > doesn't look complicated to me. Which again won't always work, if: (a) the header defines another macro, say, "PRIVATE", as "private", and uses PRIVATE to declare private members (b) the members are preceded with neither "private:" nor "public:" nor "protected:", in which case they'll be private by default (c) someone else suggested that point (b) is defeated by defining a macro named "class" as "struct", which will make members public by default; well, we can do something similar to what we did in point (a): define a macro, say, "CLASS", as "class", and use CLASS the define the class Anyway, it doesn't matter. We're losing the point here. The point is that language support for private access, by disallowing user access to private data, provides an unambiguous information hiding mechanism which encourages encapsulation. Python's approach, however, which is only a naming convention rather than a language feature, merely TRUSTS the programmer not to break encapsulation. And sure, if we're all good programmers, everything will go well and we'll end up with an organized application. But the danger is still there: at any given time, we COULD break encapsulation! From apt.shansen at gmail.com Sun Feb 1 12:10:12 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sun, 1 Feb 2009 09:10:12 -0800 (PST) Subject: is python Object oriented?? In-Reply-To: <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> Message-ID: An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 269 bytes Desc: OpenPGP digital signature URL: From timmichelsen at gmx-topmail.de Sun Feb 1 12:17:34 2009 From: timmichelsen at gmx-topmail.de (Tim Michelsen) Date: Sun, 01 Feb 2009 18:17:34 +0100 Subject: Config files editor Message-ID: Hello Python, does anyone know of a Python based project that has a GUI based functionality to edit config files read/written by ConfigParser? I found a command line tool here: pyinieditor - Google Code - http://code.google.com/p/pyinieditor/ But I'd rather go with a GUI tool. Thanks in advance and kind regards, Timmie From kyrie at uh.cu Sun Feb 1 12:23:57 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Sun, 01 Feb 2009 12:23:57 -0500 Subject: is python Object oriented?? In-Reply-To: <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> Message-ID: <1233509037.4985daadd8b2a@mail.uh.cu> Quoting thmpsn.m.k at gmail.com: > > Or ``#define private public`` before including the header files. ?Which > > doesn't look complicated to me. > > Which again won't always work, if: > > (a) the header defines another macro, say, "PRIVATE", as "private", > and uses PRIVATE to declare private members [other reasons deleted] So, can I assume that most of the C++ code out there defines "PRIVATE" as "private" just to prevent breaking the encapsulation _intentionally_? Somehow I find that hard to believe. > Anyway, it doesn't matter. We're losing the point here. The point is > that language support for private access, by disallowing user access > to private data, provides an unambiguous information hiding mechanism > which encourages encapsulation. And Python, by providing a well defined convention of what is inaccessible, provides an unambiguous information hiding mechanism wich encourages encapsulation. > Python's approach, however, which is > only a naming convention rather than a language feature, merely TRUSTS > the programmer not to break encapsulation. And sure, if we're all good > programmers, everything will go well and we'll end up with an > organized application. But the danger is still there: at any given > time, we COULD break encapsulation! And what's the problem with that, exactly? I can break encapsulation... and I can jump off my roof. Why do _you_ care about what _I_ can do, as long as it doesn't harm _you_ (or others)? If you are worried about you breaking encapsulation, then just don't do it. It is not hard. Whenever you find yourself typing "._somehting", just check that the string before the dot is "self". If you can't trust yourself to access only the well identified "public" attributes, how can you trust that you will just not make "public" a private attribute anyway? -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie From vicente.soler at gmail.com Sun Feb 1 12:24:37 2009 From: vicente.soler at gmail.com (vsoler) Date: Sun, 1 Feb 2009 09:24:37 -0800 (PST) Subject: getting values from a text file (newby) Message-ID: Hi, My foo.txt file contains the following: 1,"house","2,5" 2,"table","6,7" 3,"chair","-4,5" ... as seen with notepad. This file was created with the OpenOffice Calc spreadsheet, but since I use comma as the decimal separator for numbers, the last value in each line appears sorrounded by quotes. I would like to obtain: [[1,"house",2.5], [2,"table",6.7], [3,"chair",-4.5]] in order to process the content of the file. However, so far, I have not obtained the desired result. I started testing with (only for first line): f=open('foo.txt','r') t=f.readline() print t t=t.split(',') print t f.close() But what I am getting is far more complex than what I expected: 1,"house","2,5" ['1', '"house"', '"2', '5"\n'] which is unprocessable. Can anyboby help? From steve at holdenweb.com Sun Feb 1 12:31:27 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 01 Feb 2009 12:31:27 -0500 Subject: is python Object oriented?? In-Reply-To: References: <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> Message-ID: <4985DC6F.4030106@holdenweb.com> Stephen Hansen wrote: > [...] > don't play with anyone else's > privates. > A good rule in life as well as programming. > The *idea* of encapsulation is good in many cases, it is quite often a > solid design point and admirable goal. The *implementation* of enforced > data encapsulation brings no value to any realistic situation. > I think it's noticeable that the people who have been arguing against what I might tipify as this "libertarian view" are those for whom the consequences of programming error are serious to extreme. I think we might have to accept that they are never going to be comfortable with Python as it's currently constituted, whether or not we suggest that discipline might replace enforcement. Just the same, it still doesn't save them from the consequences of interface miscommunication, as int he case of the Mars lander that crashed because one module provided a (probably strongly-typed) value in meters, and the recipient interpreted it as (probably strongly-typed) feet, cutting the engine out too early. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From vedrandekovic at yahoo.com Sun Feb 1 12:32:05 2009 From: vedrandekovic at yahoo.com (vedrandekovic at yahoo.com) Date: Sun, 1 Feb 2009 09:32:05 -0800 (PST) Subject: Python time measure question (timeit) References: <4bea652f-6935-47cb-9610-831d859a0b57@d36g2000prf.googlegroups.com> Message-ID: <7c8f3144-9c31-4e70-9644-c7bea46fe293@r15g2000prd.googlegroups.com> On 1 velj, 17:42, Steve Holden wrote: > vedrandeko... at yahoo.com wrote: > > Hello, > > > When I run following code with os.popen ?(for this time measure I'm > > using python module timeit): > > > for i in range(50): > > ? ? print i > > > I get this result: ?0.00246958761519 > > > But when I run same code from IDLE i get this result: > > 6.4533341528e-005 > > > now, I have two questions: > > ? ? ? ? ? ? ? 1) Which of this results is correct? > > Both are. What makes you think that printing in IDLE (to a GUI) should > take the same amount of time as it does "running with os.popen (whatever > that means). The two environments are likely to be completely different, > but you haven't show the exact code you ran so it's hard to be more exact. > > > ? ? ? ? ? ? ? 2) Are this results in micro seconds? > > No, seconds, as it says in the documentation: > > """This executes the setup statement once, and then returns the time it > takes to execute the main statement a number of times, measured in > seconds as a float""". > > Even a modern computer doesn't do much in .0024 microseconds. > > regards > ?Steve > -- > Steve Holden ? ? ? ?+1 571 484 6266 ? +1 800 494 3119 > Holden Web LLC ? ? ? ? ? ? ?http://www.holdenweb.com/ Hello again, This is the code that I ran: a) Main code: This code is in .exe: t = Timer("import os;os.popen('python myscript.py arg1 2 3')") print t.timeit() b) myscript.py code: import sys print sys.argv[1] var1=int(sys.argv[2]) var2=int(sys.argv[3]) var3=var1+var2 Regards, John From rt8396 at gmail.com Sun Feb 1 12:41:21 2009 From: rt8396 at gmail.com (r) Date: Sun, 1 Feb 2009 09:41:21 -0800 (PST) Subject: getting values from a text file (newby) References: Message-ID: <2428733e-2b4d-4f88-8bb5-bf31fffdf9ca@w24g2000prd.googlegroups.com> Try the csv module py> import csv py> reader = csv.reader(open(csvfile, "rb")) py> for row in reader: print row ['1', 'house', '2,5 '] ['2', 'table', '6,7 '] ['3', 'chair', '-4,5 '] From steve at holdenweb.com Sun Feb 1 12:50:55 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 01 Feb 2009 12:50:55 -0500 Subject: getting values from a text file (newby) In-Reply-To: <2428733e-2b4d-4f88-8bb5-bf31fffdf9ca@w24g2000prd.googlegroups.com> References: <2428733e-2b4d-4f88-8bb5-bf31fffdf9ca@w24g2000prd.googlegroups.com> Message-ID: r wrote: > Try the csv module > > py> import csv > py> reader = csv.reader(open(csvfile, "rb")) > py> for row in reader: > print row > > > ['1', 'house', '2,5 '] > ['2', 'table', '6,7 '] > ['3', 'chair', '-4,5 '] And then, to conert the last field to numbers? ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From joncle at googlemail.com Sun Feb 1 12:51:57 2009 From: joncle at googlemail.com (Jon Clements) Date: Sun, 1 Feb 2009 09:51:57 -0800 (PST) Subject: Problems installing PySQLite, SQLite and Trac References: <1f1e74d1-f8b4-49e8-92d7-24c2354c8ca7@o40g2000prn.googlegroups.com> Message-ID: <92ec1676-7c46-4cb5-beee-da25502ddd15@s1g2000prg.googlegroups.com> On 1 Feb, 15:48, kimwlias wrote: > My initial goal is to finally install Trac. This is the second day > I've been trying to make this possible but I can't find, for the life > of me, how to do this. OK, here is the story: > > My system is a VPS with CentOS 5. > > I found out that I have two versions of python: 2.4 at /usr/bin/ > python2.4 and 2.5.2 at /usr/local/apps/python/bin/python2.5 > > My first try was to download the SQLite amalgamation, './configure', > 'make' and 'make install'. Then I downloaded the PySQLite and 'python > setup.py install'. The funny part is that python2.4 has sqlite while > python2.5 doesn't: > > ? ? [root at xxx]# python > ? ? Python 2.5.2 (r252:60911, May 10 2008, 17:42:40) > ? ? [GCC 4.1.2 20070626 (Red Hat 4.1.2-14)] on linux2 > ? ? Type "help", "copyright", "credits" or "license" for more > information. > ? ? >>> import sqlite > ? ? Traceback (most recent call last): > ? ? File "", line 1, in > ? ? ImportError: No module named sqlite > > ? ? [root at xxx]# python2.4 > ? ? Python 2.4.3 (#1, Mar 14 2007, 18:51:08) > ? ? [GCC 4.1.1 20070105 (Red Hat 4.1.1-52)] on linux2 > ? ? Type "help", "copyright", "credits" or "license" for more > information. > ? ? >>> import sqlite > ? ? >>> > > After some more research I found out that the amalgamation is not the > default way and I needed to run the extended_setup.py which isn't > inside the pysqlite! ->http://oss.itsystementwicklung.de/trac/pysqlite/wiki/PysqliteAmalgama... > > I then thought, "OK, let's install the SQLite from the precompiled > binary packages". So I downloaded the first two packages from here:http://www.sqlite.org/download.html. The one contains a .bin file and > the other an .so file. I must admit, I'm relatively new in Linux so I > don't know what do with these files. And there is NO DOCUMENTATION > what so ever on how to use these two in the SQLite website. Not even a > slight hint where to look for. The so called documentation is just a > download version of the website.... > > You can find some more information about my problem here:http://stackoverflow.com/questions/500055/issues-installing-sqlite-py... > > I really really really need your help. Thank you so much in advance. IIRC, pysqlite was a wrapper for the SQLite library. However, in version 2.5+ of Python, it's part of the standard distribution and is in the module called sqlite3. Just walking throuh the instructions (although I only have 2.5.2 installed gives me this): Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sqlite3 >>> import pysqlite2 Are you trying to set up using 2.4 or 2.5? I'm just a little confused as to why if sqlite works on 2.4 which looking at the installation instruction [ref: http://www.installationwiki.org/Installing_Trac_and_Subversion#Python] is what's recommended, is what the problem is? As you're under a redhat derivative, perhaps it might be worth just getting the rpm(s) for pysqlite2 and that might well sort it out for you. Sorry to have not been of more help, Jon. From rt8396 at gmail.com Sun Feb 1 12:59:29 2009 From: rt8396 at gmail.com (r) Date: Sun, 1 Feb 2009 09:59:29 -0800 (PST) Subject: getting values from a text file (newby) References: <2428733e-2b4d-4f88-8bb5-bf31fffdf9ca@w24g2000prd.googlegroups.com> Message-ID: On Feb 1, 11:50?am, Steve Holden wrote: > And then, to conert the last field to numbers? ... Are you asking me Steve? Well i did not want to short-circuit the OP's learning process by spoon-feeding him the entire answer. I thought i would give him a push in the right direction and observe the outcome. A very intelligent professor once said: """ It's not about giving a student all the info, only just enough to spark their own thought process.""" From apt.shansen at gmail.com Sun Feb 1 13:02:37 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sun, 1 Feb 2009 10:02:37 -0800 (PST) Subject: getting values from a text file (newby) In-Reply-To: Message-ID: An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 269 bytes Desc: OpenPGP digital signature URL: From steve at holdenweb.com Sun Feb 1 13:05:11 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 01 Feb 2009 13:05:11 -0500 Subject: Python time measure question (timeit) In-Reply-To: <7c8f3144-9c31-4e70-9644-c7bea46fe293@r15g2000prd.googlegroups.com> References: <4bea652f-6935-47cb-9610-831d859a0b57@d36g2000prf.googlegroups.com> <7c8f3144-9c31-4e70-9644-c7bea46fe293@r15g2000prd.googlegroups.com> Message-ID: vedrandekovic at yahoo.com wrote: > On 1 velj, 17:42, Steve Holden wrote: >> vedrandeko... at yahoo.com wrote: >>> Hello, >>> When I run following code with os.popen (for this time measure I'm >>> using python module timeit): >>> for i in range(50): >>> print i >>> I get this result: 0.00246958761519 >>> But when I run same code from IDLE i get this result: >>> 6.4533341528e-005 >>> now, I have two questions: >>> 1) Which of this results is correct? >> Both are. What makes you think that printing in IDLE (to a GUI) should >> take the same amount of time as it does "running with os.popen (whatever >> that means). The two environments are likely to be completely different, >> but you haven't show the exact code you ran so it's hard to be more exact. >> >>> 2) Are this results in micro seconds? >> No, seconds, as it says in the documentation: >> >> """This executes the setup statement once, and then returns the time it >> takes to execute the main statement a number of times, measured in >> seconds as a float""". >> >> Even a modern computer doesn't do much in .0024 microseconds. >> >> regards >> Steve >> -- >> Steve Holden +1 571 484 6266 +1 800 494 3119 >> Holden Web LLC http://www.holdenweb.com/ > > Hello again, > > This is the code that I ran: > > a) Main code: > > This code is in .exe: > > t = Timer("import os;os.popen('python myscript.py arg1 2 3')") > print t.timeit() > Here in order to run the code os.popen() has to create a new subprocess and initialize the Python interpreter inside it before finally running myscript.py. I'd say that 2.5 milliseconds is quite acceptable for that. > > b) myscript.py code: > > import sys > print sys.argv[1] > var1=int(sys.argv[2]) > var2=int(sys.argv[3]) > var3=var1+var2 > In the IDLE case I presume you were running the code directly? Obviously that eliminates the interpreter startup overhead, and so will be much quicker. 65 microseconds, if I read the times correctly. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From gbofspam at gmail.com Sun Feb 1 13:46:56 2009 From: gbofspam at gmail.com (Andrew Parker) Date: Sun, 1 Feb 2009 13:46:56 -0500 Subject: subprocess.Popen not creating a pipe Message-ID: <6c3f5e6c0902011046i59655f3cp2a81b3deb9258c61@mail.gmail.com> I'm having some fun with Popen. I have the following line: process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) print process.stdout Under normal circumstances, this displays: ', mode 'w' at 0xb7f8e068> However, I have a binary that I use to kick off this script, and when that runs, it displays: None So, two questions: 1. What the heck is this binary doing that upsets Popen so much? 2. What can *my script* do to get around this problem. Unfortunately I'm stuck using this binary, so its the python where I have to solve this. Any ideas? From rantingrick at gmail.com Sun Feb 1 13:57:28 2009 From: rantingrick at gmail.com (rantingrick) Date: Sun, 1 Feb 2009 10:57:28 -0800 (PST) Subject: Pipe stdout && stderr to a TkLabel widget References: <3022e071-aaf9-4169-b394-c8b311d05d09@41g2000yqf.googlegroups.com> Message-ID: Hello, anybody. Any help would be good help Thanks From aahz at pythoncraft.com Sun Feb 1 13:57:56 2009 From: aahz at pythoncraft.com (Aahz) Date: 1 Feb 2009 10:57:56 -0800 Subject: Pythonic list/tuple/dict layout? References: <871vur39k7.fsf@benfinney.id.au> Message-ID: In article <871vur39k7.fsf at benfinney.id.au>, Ben Finney wrote: > >I actually use this style: > > foo = { > 0: 'spam', > 1: 'eggs', > 2: 'beans', > } > >because that makes it clear that *all* the indented lines are a >continuation of the same statement, just like a suite of statements >are all uniformly indented under (e.g.) a function definition. Ditto -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From rantingrick at gmail.com Sun Feb 1 14:00:40 2009 From: rantingrick at gmail.com (rantingrick) Date: Sun, 1 Feb 2009 11:00:40 -0800 (PST) Subject: Pipe stdout && stderr to a TkLabel widget References: <3022e071-aaf9-4169-b394-c8b311d05d09@41g2000yqf.googlegroups.com> Message-ID: PS: The braces are there because i used *arg in the fuction, so that is not a problem now. All i want to do is overide the print statement to sent all it's output to a Tkinter Label widget Thanks From rdmurray at bitdance.com Sun Feb 1 14:02:57 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Sun, 1 Feb 2009 19:02:57 +0000 (UTC) Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> Message-ID: Quoth thmpsn.m.k at gmail.com: > Anyway, it doesn't matter. We're losing the point here. The point is > that language support for private access, by disallowing user access > to private data, provides an unambiguous information hiding mechanism > which encourages encapsulation. Python's approach, however, which is > only a naming convention rather than a language feature, merely TRUSTS > the programmer not to break encapsulation. And sure, if we're all good > programmers, everything will go well and we'll end up with an > organized application. But the danger is still there: at any given > time, we COULD break encapsulation! You, sir, should be programming in some language other than Python. --RDM From berankin99 at yahoo.com Sun Feb 1 14:06:26 2009 From: berankin99 at yahoo.com (Bernard Rankin) Date: Sun, 1 Feb 2009 11:06:26 -0800 (PST) Subject: error on building 2.6.1. (_ctypes) References: <852876.9144.qm@web112210.mail.gq1.yahoo.com> <296542.92832.qm@web112216.mail.gq1.yahoo.com> Message-ID: <808820.1690.qm@web112216.mail.gq1.yahoo.com> > > >> > I am trying to build python 2.6 on a machine (web server) that I do not > have > >> root access to. (has 2.4 installed) > >> > > >> > Python 2.5 builds fine, but I am getting an error when I run "make" for > 2.6.1. > > >> Mmm... my 2.6.1 source show different line numbers, maybe you should check > it's > >> the right file? > > > > Wow, good catch. > > > > I just re-downloaded the archive and it works fine. > > > > I know for certain that I did no editing to the files, and even tried > expanding the original tar.gz a couple of times. > > > > There must be a corrupted package somewhere among the official Python > mirrors. (Sadly, I overwrote the old tar.gz file when I got the new one.) > > Oops... so bad. The python.org releases have PGP signatures and MD5 published so > you can verify their authenticity. > Yeah, I did that on the new archive. :) From ppearson at nowhere.invalid Sun Feb 1 14:11:39 2009 From: ppearson at nowhere.invalid (Peter Pearson) Date: 1 Feb 2009 19:11:39 GMT Subject: nth root References: <1AE19A80523D5F40BE0044A1447A53FF0ADB972E@UNIMAIL.staff.ad.cqu.edu.au> Message-ID: <6umafaFg436kU1@mid.individual.net> On Sun, 1 Feb 2009 15:36:43 +1000, Tim Roberts wrote: > > Actually, all I'm interested in is whether the 100 digit > numbers have an exact integral root, or not. At the > moment, because of accuracy concerns, I'm doing something > like > > for root in powersp: > nroot = round(bignum**(1.0/root)) > if bignum==long(nroot)**root: > ......... > which is probably very inefficient, but I can't see anything better..... You've gotten several promising leads on this thread, but here's one more thing that might help. Note that if c == b**13, then c%p == pow( b%p, 13, p ) for any prime p. So if you have a 100-digit c and a "candidate" 13-th root b, and you choose p = 101 (for example), a false b has only a 1% chance of passing the c%p == pow( b%p, 13, p ) test, which might save some fraction of the cost of whatever more rigorous test you subsequently apply. -- To email me, substitute nowhere->spamcop, invalid->net. From vicente.soler at gmail.com Sun Feb 1 14:18:01 2009 From: vicente.soler at gmail.com (vsoler) Date: Sun, 1 Feb 2009 11:18:01 -0800 (PST) Subject: getting values from a text file (newby) References: Message-ID: On 1 feb, 19:02, Stephen Hansen wrote: > On Sun, Feb 1, 2009 at 9:24 AM, vsolerwrote:Hi, > My foo.txt file contains the following: > 1,"house","2,5" > 2,"table","6,7" > 3,"chair","-4,5" > ... as seen with notepad. > This file was created with the OpenOffice Calc spreadsheet, but since > I use comma as the decimal separator for numbers, the last value in > each line appears sorrounded by quotes. > I would like to obtain: > [[1,"house",2.5], [2,"table",6.7], [3,"chair",-4.5]] > If I read your requirements, right, I think you want:import csv > data = [] > reader = csv.reader(open("filename", "r")) > for line in reader: > ???? data.append( > ???????? line[0], line[1], float(line[2].replace(",", ".")) > ???? ) > print data > Although you may want to replace that last bit with > ??? decimal.Decimal(line[2].replace(",",".")) > If you want an exact result and not the approximate floating point result. > Basically the csv module can read through the CSV file very easily, but because you're using commas instead of points you just have to edit that out before you convert it to a number. > --S > > ?signature.asc > < 1 KBVerDescargar with small modifications, your answers work perfectly!!! r: in the open statement, why do you use 'rb' as 2nd argument? b is supposed to be binary, and my file is text! Steve: your idea works Stephen: I got an error message saying that append can only take one argument while you add three; I have added [ ] around the three arguments; now it's fine; I've also added int() around first argument to turn it into an integer. Thank you all indeed! From aaron.watters at gmail.com Sun Feb 1 14:18:14 2009 From: aaron.watters at gmail.com (Aaron Watters) Date: Sun, 1 Feb 2009 11:18:14 -0800 (PST) Subject: search speed References: <4e53a2a6-058f-4265-a4d6-5565e2fec2c3@v39g2000pro.googlegroups.com> <6uft9aFf9kgbU1@mid.uni-berlin.de> Message-ID: <8a972421-cba3-4394-8651-c81fce1083da@i18g2000prf.googlegroups.com> On Jan 30, 3:49?am, "Diez B. Roggisch" wrote: > alex23 gave you a set of tools that you can use for full-text-search. > However, that's not necessarily the best thing to do if things have a > record-like structure. In Nucular (and others I think) you can do searches for terms anywhere (full text) searches for terms within fields, searches for prefixes in fields, searches based on field inequality, or searches for field exact value. I would argue this subsumes the standard "fielded approach". -- Aaron Watters === Oh, I'm a lumberjack and I'm O.K... From steve at holdenweb.com Sun Feb 1 14:19:55 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 01 Feb 2009 14:19:55 -0500 Subject: getting values from a text file (newby) In-Reply-To: References: Message-ID: Stephen Hansen wrote: > > > On Sun, Feb 1, 2009 at 9:24 AM, vsoler wrote: > > Hi, > > My foo.txt file contains the following: > > 1,"house","2,5" > 2,"table","6,7" > 3,"chair","-4,5" > > ... as seen with notepad. > > This file was created with the OpenOffice Calc spreadsheet, but since > I use comma as the decimal separator for numbers, the last value in > each line appears sorrounded by quotes. > > I would like to obtain: > > [[1,"house",2.5], [2,"table",6.7], [3,"chair",-4.5]] > > > If I read your requirements, right, I think you want: > > import csv > > data = [] > > reader = csv.reader(open("filename", "r")) > for line in reader: > data.append( > line[0], line[1], float(line[2].replace(",", ".")) > ) > > print data > > Although you may want to replace that last bit with > decimal.Decimal(line[2].replace(",",".")) > > If you want an exact result and not the approximate floating point result. > > Basically the csv module can read through the CSV file very easily, but > because you're using commas instead of points you just have to edit that > out before you convert it to a number. > alternatively look at locale.atof() to convert according to what I presume are the conventions of your locale ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From rdmurray at bitdance.com Sun Feb 1 14:33:28 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Sun, 1 Feb 2009 19:33:28 +0000 (UTC) Subject: Problem with slow httplib connections on Windows (and maybe other platforms) References: Message-ID: Quoth Christoph Zwerschke : > What actually happens is the following: > > * BaseHTTPServer binds only to the IPv4 address of localhost, because > it's based on TCPServer which has address_family=AF_INET by default. > > * HTTPConnection.connect() however tries to connect to all IP addresses > of localhost, in the order determined socket.getaddrinfo('localhost'). > > With Py 2.3 (without IPv6 support) this is only the IPv4 address, > but with Py 2.4-2.6 the order is (on my Win XP host) the IPv6 address > first, then the IPv4 address. Since the IPv6 address is checked first, > this gives a timeout and causes the slow connect() call. The order by > which getaddrinfo returns IPv4/v6 under Linux seems to vary depending > on the glibc version, so it may be a problem on other platforms, too. Based on something I read in another thread, this appears to be a problem only under Windows. Everybody else implemented the TCP/IP stack according to spec, and the IPV6 connect attempt times out immediately, producing no slowdown. Microsoft, however.... --RDM From matt.dubins at sympatico.ca Sun Feb 1 14:54:09 2009 From: matt.dubins at sympatico.ca (inkhorn) Date: Sun, 1 Feb 2009 11:54:09 -0800 (PST) Subject: Membership of multiple items to a list Message-ID: Dear all, I'd like to know how to elegantly check a list for the membership of any of its items to another list. Not caring for elegance, I would use the following code: blah = [1,2,3] yadda = [3,4,5,6] blah[0] or blah[1] or blah[2] in yadda Please tell me how to change the preceding code into something nicer where I don't have to keep extending the line based on the length of the first list. Cheers, Matt Dubins From gbofspam at gmail.com Sun Feb 1 15:00:36 2009 From: gbofspam at gmail.com (Andrew Parker) Date: Sun, 1 Feb 2009 15:00:36 -0500 Subject: subprocess.Popen not creating a pipe In-Reply-To: <6c3f5e6c0902011046i59655f3cp2a81b3deb9258c61@mail.gmail.com> References: <6c3f5e6c0902011046i59655f3cp2a81b3deb9258c61@mail.gmail.com> Message-ID: <6c3f5e6c0902011200s47372b8g49c794b7fa62a06b@mail.gmail.com> On Sun, Feb 1, 2009 at 1:46 PM, Andrew Parker wrote: > I'm having some fun with Popen. I have the following line: > > process = subprocess.Popen(command, stdout=subprocess.PIPE, > stderr=subprocess.STDOUT) > print process.stdout > > Under normal circumstances, this displays: > > ', mode 'w' at 0xb7f8e068> > > However, I have a binary that I use to kick off this script, and when > that runs, it displays: > > None > > So, two questions: > > 1. What the heck is this binary doing that upsets Popen so much? > 2. What can *my script* do to get around this problem. > > Unfortunately I'm stuck using this binary, so its the python where I > have to solve this. > > Any ideas? > so, tracing through subprocess.Popen, I see that os.pipe() is being invoked for stdout. This is returning (0, 3), and I assume the 0 is conflicting with what python is assuming is stdin. Calling pipe() before Popen gets around my problem, as the pipe the Popen gets then returns (4,5) which Popen seems happy with. Sounds like a bug. Should I report this, or is it expected/known behaviour? From http Sun Feb 1 15:00:51 2009 From: http (Paul Rubin) Date: 01 Feb 2009 12:00:51 -0800 Subject: Membership of multiple items to a list References: Message-ID: <7x63junczw.fsf@ruckus.brouhaha.com> inkhorn writes: > blah = [1,2,3] > yadda = [3,4,5,6] > > blah[0] or blah[1] or blah[2] in yadda if set(blah) & set(yadda): print "yes" From lists at cheimes.de Sun Feb 1 15:00:55 2009 From: lists at cheimes.de (Christian Heimes) Date: Sun, 01 Feb 2009 21:00:55 +0100 Subject: Membership of multiple items to a list In-Reply-To: References: Message-ID: inkhorn schrieb: > Dear all, > > I'd like to know how to elegantly check a list for the membership of > any of its items to another list. Not caring for elegance, I would > use the following code: > > blah = [1,2,3] > yadda = [3,4,5,6] > > blah[0] or blah[1] or blah[2] in yadda > > Please tell me how to change the preceding code into something nicer > where I don't have to keep extending the line based on the length of > the first list. You can and should use Python's set type for membership testing. >>> blah = set([1,2,3]) >>> yadda = set([3,4,5,6]) >>> blah.issubset(yadda) False >>> blah.difference(yadda) set([1, 2]) >>> blah.symmetric_difference(yadda) set([1, 2, 4, 5, 6]) Christian From apt.shansen at gmail.com Sun Feb 1 15:01:11 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sun, 1 Feb 2009 12:01:11 -0800 (PST) Subject: Membership of multiple items to a list In-Reply-To: Message-ID: An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 269 bytes Desc: OpenPGP digital signature URL: From matt.dubins at sympatico.ca Sun Feb 1 15:06:54 2009 From: matt.dubins at sympatico.ca (inkhorn) Date: Sun, 1 Feb 2009 12:06:54 -0800 (PST) Subject: Membership of multiple items to a list References: Message-ID: Wow thanks for the lightning fast reply! This does exactly the right job. Matt On Feb 1, 3:01?pm, Stephen Hansen wrote: > I'd like to know how to elegantly check a list for the membership of > any of its items to another list. ?Not caring for elegance, I would > use the following code: > That's one of the useful properties of sets: > >>> a = [1,2,3] > >>> b = [3,4,5,6] > >>> set(a) & set(b) > set([3]) > >>> set(a).intersection(b) > set([3]) > That's two spellings of the same thing. As for testing: an empty set like an empty list will return false, so "if set(a) & set(b):" will be true or false based on if there's any commonalities between the two lists. > --Stephen > > ?signature.asc > < 1KViewDownload From ianand0204 at gmail.com Sun Feb 1 15:35:47 2009 From: ianand0204 at gmail.com (flagg) Date: Sun, 1 Feb 2009 12:35:47 -0800 (PST) Subject: SimpleXMLRPCServer question References: <0ddb9364-02c9-4c52-aadb-e9d9b2d06b20@e1g2000pra.googlegroups.com> <185b44c2-fc78-480f-8eb1-6395f7fe7ad7@x6g2000pre.googlegroups.com> Message-ID: <542076e8-2585-4be1-a553-43dc674e02a4@a12g2000pro.googlegroups.com> On Feb 1, 12:38?am, "Hendrik van Rooyen" wrote: > ?"flagg" wrote: > >Let me see if i can elaborate on the requirements. ?I have 20+ > >different zone files. ?I want the xmlrpc server to be able to > >determine what zone file to open by looking at the incoming xml > >request. ?For example one of the functions I have now is to show a DNS > >record (I am using dnspython for most of this work) > > This is a wrong move, it is too magical - see below > > >If i send an xmlrpc request that uses the 'showRecord' function with > >params of 'oracle1.foo.bar.com' ?I want to parse the "params" piece > >and then instruct the xml-rpc server to open foo.bar.com.zone for > >reading. ?The reason why i was looking at do_Post() and _dispatch was > >to attempt to read the incoming params and do exactly that. > > >Do you think there is an easier way of accomplishing this, than the > >way I am going about it? > > Yes I do. > > Why don't you split the functionality into two bits - exactly as if you were > doing > it locally: > > - OpenTheThing(whatOrWhere) > - ReadTheRecordAndShowIt(PossiblyWhichRecord) > > If it's a remote database you are accessing, then you may need even more > steps, like first doing some select, or whatever - I would get it running > locally, calling local functions directly on the server, and then make them > remote xmlrpc proxy functions, after it's all working. > > If you are getting the request from some user input, you can either change > the way you ask the questions, or you do the parsing at point of origen, to > determine what to call, in which sequence. > > - Hendrik Actually I have it working as local functions, its wrapping those local functions up in a way that makes sense that is throwing me off. Your suggestion of making two functions one for opening the file and one for showing records makes sense. I will give it a shot From mensanator at aol.com Sun Feb 1 16:04:02 2009 From: mensanator at aol.com (Mensanator) Date: Sun, 1 Feb 2009 13:04:02 -0800 (PST) Subject: nth root References: <1AE19A80523D5F40BE0044A1447A53FF0ADB972E@UNIMAIL.staff.ad.cqu.edu.au> Message-ID: <44029925-ae8f-484e-8fcd-0d5ec484c184@z28g2000prd.googlegroups.com> On Feb 1, 2:27?am, casevh wrote: > On Jan 31, 9:36?pm, "Tim Roberts" wrote: > > > Actually, all I'm interested in is whether the 100 digit numbers have an exact integral root, or not. ?At the moment, because of accuracy concerns, I'm doing something like > > > ? ? ? ? ? ? ? ? ? ? for root in powersp: > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? nroot = round(bignum**(1.0/root)) > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? if bignum==long(nroot)**root: > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?......... > > which is probably very inefficient, but I can't see anything better..... > > > Tim > > Take a look at gmpy and the is_power function. I think it will do > exactly what you want. And the root function will give you the root AND tell you whether it was an integral root: >>> gmpy.root(a,13) (mpz(3221), 0) In this case, it wasn't. > > http://code.google.com/p/gmpy/ > > casevh From cito at online.de Sun Feb 1 17:44:11 2009 From: cito at online.de (Christoph Zwerschke) Date: Sun, 01 Feb 2009 23:44:11 +0100 Subject: Problem with slow httplib connections on Windows (and maybe other platforms) In-Reply-To: References: Message-ID: rdmurray at bitdance.com schrieb: > Quoth Christoph Zwerschke : >> With Py 2.3 (without IPv6 support) this is only the IPv4 address, >> but with Py 2.4-2.6 the order is (on my Win XP host) the IPv6 address >> first, then the IPv4 address. Since the IPv6 address is checked first, >> this gives a timeout and causes the slow connect() call. The order by >> which getaddrinfo returns IPv4/v6 under Linux seems to vary depending >> on the glibc version, so it may be a problem on other platforms, too. > > Based on something I read in another thread, this appears to be a problem > only under Windows. Everybody else implemented the TCP/IP stack according > to spec, and the IPV6 connect attempt times out immediately, producing > no slowdown. > > Microsoft, however.... The order in which getaddrinfo returns IPv4 and IPv6 is probably not written in the specs (Posix 1003.1g and RFC 2553). The fact that Windows returns IPv6 addresses first is not wrong in itself. For this discussion, see also http://www.ops.ietf.org/lists/v6ops/v6ops.2002/msg00869.html https://bugzilla.redhat.com/show_bug.cgi?id=190495 But yes, I also wonder why the connect to the IPv6 loopback address does not time out more quickly on Windows. -- Christoph From stef.mientki at gmail.com Sun Feb 1 17:56:28 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Sun, 01 Feb 2009 23:56:28 +0100 Subject: database wrapper ? Message-ID: <4986289C.3030205@gmail.com> hello, Until now I used a simple wrapper around pysqlite and pyodbc to manage my databases. Now I'm looking for a better solution, because I've to support a (for this moment) unknown database, and I'm not the one who will choose the database. Googling, I found SQLalchemy, which looks quit good. But as I only want to choose once, I googled for "SQLalchemy alternatives", but it didn't find many answers. (Storm / Grok are of no interest, because manipulating the structure of the database is a key issue). Is SQLalchemy the best / most popular database wrapper ? Are there any alternatives ? I don't know if it matters: but for the short term it's only for desktop applications, but in the future I'll certainly want to move to web based databases. thanks, Stef From sjmachin at lexicon.net Sun Feb 1 17:57:39 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 1 Feb 2009 14:57:39 -0800 (PST) Subject: getting values from a text file (newby) References: Message-ID: On Feb 2, 6:18?am, vsoler wrote: > > r: in the open statement, why do you use 'rb' as 2nd argument? b is > supposed to be binary, and my file is text! Because unlike Stephen, r has read the csv manual. Binary mode is required to handle properly cases like '\n' embedded in a field -- something which can easily happen when the data has been extracted from a database with slack data-entry validation. From vicente.soler at gmail.com Sun Feb 1 18:18:50 2009 From: vicente.soler at gmail.com (vsoler) Date: Sun, 1 Feb 2009 15:18:50 -0800 (PST) Subject: getting values from a text file (newby) References: Message-ID: On 1 feb, 23:57, John Machin wrote: > On Feb 2, 6:18?am, vsoler wrote: > > > > > r: in the open statement, why do you use 'rb' as 2nd argument? b is > > supposed to be binary, and my file is text! > > Because unlike Stephen, r has read the csv manual. Binary mode is > required to handle properly cases like '\n' embedded in a field -- > something which can easily happen when the data has been extracted > from a database with slack data-entry validation. Where can I get the csv manual? From rdmurray at bitdance.com Sun Feb 1 18:26:07 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Sun, 1 Feb 2009 23:26:07 +0000 (UTC) Subject: Problem with slow httplib connections on Windows (and maybe other platforms) References: Message-ID: Quoth Christoph Zwerschke : > rdmurray at bitdance.com schrieb: > > Quoth Christoph Zwerschke : > >> With Py 2.3 (without IPv6 support) this is only the IPv4 address, > >> but with Py 2.4-2.6 the order is (on my Win XP host) the IPv6 address > >> first, then the IPv4 address. Since the IPv6 address is checked first, > >> this gives a timeout and causes the slow connect() call. The order by > >> which getaddrinfo returns IPv4/v6 under Linux seems to vary depending > >> on the glibc version, so it may be a problem on other platforms, too. > > > > Based on something I read in another thread, this appears to be a problem > > only under Windows. Everybody else implemented the TCP/IP stack according > > to spec, and the IPV6 connect attempt times out immediately, producing > > no slowdown. > > > > Microsoft, however.... > > The order in which getaddrinfo returns IPv4 and IPv6 is probably not > written in the specs (Posix 1003.1g and RFC 2553). The fact that Windows > returns IPv6 addresses first is not wrong in itself. > > For this discussion, see also > http://www.ops.ietf.org/lists/v6ops/v6ops.2002/msg00869.html > https://bugzilla.redhat.com/show_bug.cgi?id=190495 > > But yes, I also wonder why the connect to the IPv6 loopback address does > not time out more quickly on Windows. Right, it's not the order of the returned items that's the Microsoft weirdness, it's the long timeout on an attempt to connect to something that doesn't exist. There was a long discussion about this, and it might even have been on python-dev, but I can't lay my hands on the thread. In short, Microsoft retries and waits a while when the far end says "no thanks" to a connection attempt, instead of immediately returning the connection failure the way Linux and etc and etc do. This applies to IPV4, too. --RDM From rhodri at wildebst.demon.co.uk Sun Feb 1 18:39:14 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sun, 01 Feb 2009 23:39:14 -0000 Subject: is python Object oriented?? In-Reply-To: <4985DC6F.4030106@holdenweb.com> References: <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <4985DC6F.4030106@holdenweb.com> Message-ID: On Sun, 01 Feb 2009 17:31:27 -0000, Steve Holden wrote: > Stephen Hansen wrote: >> [...] >> don't play with anyone else's >> privates. >> > A good rule in life as well as programming. Unless, of course, you're both consenting adults. What? Someone had to say it! -- Rhodri James *-* Wildebeeste Herder to the Masses From aahz at pythoncraft.com Sun Feb 1 18:42:00 2009 From: aahz at pythoncraft.com (Aahz) Date: 1 Feb 2009 15:42:00 -0800 Subject: what IDE is the best to write python? References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> Message-ID: In article , MattBD wrote: > >I like Vim, that works really well for me when coding in Python. >Enable syntax highlighting and it's a great development environment. >It's a little tough at first but run vimtutor and you'll soon start to >get the hang of it. Just to register a contrary opinion: I *hate* syntax highlighting -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From clp2 at rebertia.com Sun Feb 1 18:43:50 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 1 Feb 2009 15:43:50 -0800 Subject: database wrapper ? In-Reply-To: <4986289C.3030205@gmail.com> References: <4986289C.3030205@gmail.com> Message-ID: <50697b2c0902011543w7c022fel7c32e8e1ea7a920e@mail.gmail.com> On Sun, Feb 1, 2009 at 2:56 PM, Stef Mientki wrote: > hello, > > Until now I used a simple wrapper around pysqlite and pyodbc to manage my > databases. > Now I'm looking for a better solution, > because I've to support a (for this moment) unknown database, > and I'm not the one who will choose the database. > > Googling, I found SQLalchemy, > which looks quit good. > > But as I only want to choose once, > I googled for "SQLalchemy alternatives", > but it didn't find many answers. > (Storm / Grok are of no interest, because manipulating the structure of the > database is a key issue). > > Is SQLalchemy the best / most popular database wrapper ? > Are there any alternatives ? SQLObject is also probably worth looking at -- http://www.sqlobject.org/ Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From aahz at pythoncraft.com Sun Feb 1 18:45:10 2009 From: aahz at pythoncraft.com (Aahz) Date: 1 Feb 2009 15:45:10 -0800 Subject: Where to host a (Python) project? References: <387f23cd-90e2-46fc-8c91-1c2f6b31c89e@u13g2000yqg.googlegroups.com> Message-ID: In article <387f23cd-90e2-46fc-8c91-1c2f6b31c89e at u13g2000yqg.googlegroups.com>, andrew cooke wrote: > >However, i am thinking I could really do with: >- a mailing list >- simple bug tracking >- subversion >and am wondering which is the best (free) provider for these (the code >is LGPL open source). I'd prefer a mailing list to something like >google groups (although I guess it may be possible to configure a >gateway) and I could open up my personal subversion server, but that >seems like a lot of work (not really that interested in moving to >something other than svn). Note that it's fairly easy to get a new list hosted at python.org, just ask postmaster. I for one won't participate in any list hosted on Google because of the need for a Google login. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From apt.shansen at gmail.com Sun Feb 1 18:47:23 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sun, 1 Feb 2009 15:47:23 -0800 (PST) Subject: database wrapper ? In-Reply-To: <4986289C.3030205@gmail.com> Message-ID: An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 269 bytes Desc: OpenPGP digital signature URL: From bignose+hates-spam at benfinney.id.au Sun Feb 1 18:55:50 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Mon, 02 Feb 2009 10:55:50 +1100 Subject: database wrapper ? References: Message-ID: <87hc3d3e61.fsf@benfinney.id.au> Stef Mientki writes: > Is SQLalchemy the best / most popular database wrapper ? In my opinion, yes it's the best. It gives a good ORM (letting you treat your data as objects and have them persistently stored in the database), while still allowing all the power and flexibility of full SQL whenever you need it; and a continuum of options in between (e.g. a helpful query builder toolkit). -- \ ?We must respect the other fellow's religion, but only in the | `\ sense and to the extent that we respect his theory that his | _o__) wife is beautiful and his children smart.? ?Henry L. Mencken | Ben Finney From andrew at acooke.org Sun Feb 1 18:58:26 2009 From: andrew at acooke.org (andrew cooke) Date: Sun, 1 Feb 2009 15:58:26 -0800 (PST) Subject: database wrapper ? References: Message-ID: > Is SQLalchemy the best / most popular database wrapper ? SQLAlchemy is the best SQL library I have ever used. But it may depend on who you ask. For me, what makes SQLAlchemy so good is the way it allows you to use SQL from within Python. I have used the ORM side, and that's fine, but it's the way that it doesn't get in the way of "just" SQL that make it so good. If I had to choose a second reason why it's so good it would be the way it emphasises metadata - it will use table definitions from the database, and it will let you define schema yourself (in fact, it's an excellent way of defining complex schema in a platform-independent fashion). The main drawback is that it is rather complex. If something doesn't work, it can be tricky to work out why. On the other hand, the documentation is good, and the support (on google groups) is good too (a developer always replies within 24 hours in my experience). It does expect you to know SQL - it doesn't try to hide SQL at all. Whether that is good or bad depends on your POV I guess. I wish all DB solutions were like this - my hope is that EmpireDB will do the same for Java, but it's too early to tell... Andrew From andrew at acooke.org Sun Feb 1 19:02:52 2009 From: andrew at acooke.org (andrew cooke) Date: Sun, 1 Feb 2009 16:02:52 -0800 (PST) Subject: Where to host a (Python) project? References: <387f23cd-90e2-46fc-8c91-1c2f6b31c89e@u13g2000yqg.googlegroups.com> Message-ID: <952e4cda-e2a5-4395-8ac3-6b64aa3c5af0@e3g2000vbe.googlegroups.com> On Feb 1, 8:45?pm, a... at pythoncraft.com (Aahz) wrote: > Note that it's fairly easy to get a new list hosted at python.org, just > ask postmaster. ?I for one won't participate in any list hosted on > Google because of the need for a Google login. ah well - i guess you can use pyparsing ;o) http://code.google.com/p/lepl/ andrew From gdamjan at gmail.com Sun Feb 1 19:15:39 2009 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Mon, 02 Feb 2009 01:15:39 +0100 Subject: Using lxml to screen scrap a site, problem with charset Message-ID: So, I'm using lxml to screen scrap a site that uses the cyrillic alphabet (windows-1251 encoding). The sites HTML doesn't have the header, but does have a HTTP header that specifies the charset... so they are standards compliant enough. Now when I run this code: from lxml import html doc = html.parse('http://a1.com.mk/') root = doc.getroot() title = root.cssselect(('head title'))[0] print title.text the title.text is ? unicode string, but it has been wrongly decoded as latin1 -> unicode So.. is this a deficiency/bug in lxml or I'm doing something wrong. Also, what are my other options here? I'm running Python 2.6.1 and python-lxml 2.1.4 on Linux if matters. -- ?????? ( http://softver.org.mk/damjan/ ) "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." - Brian W. Kernighan From bignose+hates-spam at benfinney.id.au Sun Feb 1 19:26:24 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Mon, 02 Feb 2009 11:26:24 +1100 Subject: what IDE is the best to write python? References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> Message-ID: <874ozd3cr3.fsf@benfinney.id.au> aahz at pythoncraft.com (Aahz) writes: > Just to register a contrary opinion: I *hate* syntax highlighting On what basis? -- \ ?The man who is denied the opportunity of taking decisions of | `\ importance begins to regard as important the decisions he is | _o__) allowed to take.? ?C. Northcote Parkinson | Ben Finney From andrew at acooke.org Sun Feb 1 19:28:53 2009 From: andrew at acooke.org (andrew cooke) Date: Sun, 1 Feb 2009 16:28:53 -0800 (PST) Subject: database wrapper ? References: Message-ID: <7bdf4281-0f10-48ac-bf96-b91c481412b8@f33g2000vbf.googlegroups.com> > I wish all DB solutions were like this - my hope is that EmpireDB will > do the same for Java, but it's too early to tell... Hmmm - I should correct the above. I had assumed EmpireDB was new, because it's an Apache Incubator project, but now I look at their site I see it's actually been around for years. I need to try it out... Sorry about the error, Andrew From steven at REMOVE.THIS.cybersource.com.au Sun Feb 1 19:31:38 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 02 Feb 2009 00:31:38 GMT Subject: Membership of multiple items to a list References: Message-ID: On Sun, 01 Feb 2009 12:01:11 -0800, Stephen Hansen wrote: >
style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt > 0.8ex; padding-left: 1ex;">
I'd like to know how to elegantly check > a list for the membership of
any of its items to another list. >  Not caring for elegance, I would
use the following code:
>

That's one of the useful properties of > sets:

>>> a = [1,2,3]
>>> b = > [3,4,5,6]
>>> set(a) & > set(b)
set([3])
>>> > set(a).intersection(b)
set([3])

That's two spellings of the > same thing. As for testing: an empty set like an empty list will return > false, so "if set(a) & set(b):" will be true or false based on if > there's any commonalities between the two > lists.

--Stephen

Stephen, do you see the utter mess your posts look like to some others? Please ensure you send plain text messages to Usenet, not HTML. If you absolutely can't avoid using an insecure and bloated page layout language instead of text, please ensure that your News or mail client is set to send plain text as well as HTML. If your news/mail client doesn't follow Usenet standards, then (1) change the application you use to one that does; or (2) complain to the vendor until they fix their product. Thank you, -- Steven From steven at REMOVE.THIS.cybersource.com.au Sun Feb 1 20:00:18 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 02 Feb 2009 01:00:18 GMT Subject: is python Object oriented?? References: <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> Message-ID: On Sun, 01 Feb 2009 12:31:27 -0500, Steve Holden wrote: > I think it's noticeable that the people who have been arguing against > what I might tipify as this "libertarian view" are those for whom the > consequences of programming error are serious to extreme. ... > Just the same, it still doesn't save them from the consequences of > interface miscommunication, as int he case of the Mars lander that > crashed because one module provided a (probably strongly-typed) value in > meters, and the recipient interpreted it as (probably strongly-typed) > feet, cutting the engine out too early. Of course. Nor will data hiding prevent off-by-one errors, or errors of logic, or data corruption, or stray cosmic rays flipping bits in memory. But it will prevent *some* errors. It's one tool in an entire toolbox for writing correct code, not a magic bullet. Python already has enforced data hiding, but only for built-ins. Consequently, anyone who uses a list can absolutely, categorically trust that len(alist) will return the actual length of alist, and not some mangled value stuffed into alist by some arbitrary piece of code somewhere else. (For those unaware, in CPython lists are arrays. They store the current length as a private value inaccessible to Python code.) Short of cosmic rays flipping bits, any built-in list you receive from anywhere is going to have a valid length, and no pure-Python code can make it invalid. To read some of the posts in this thread, one would be forgiven for thinking that this most be a disaster of the highest consequences, unPythonic to the extreme, an example of unfree B&D programming so unpleasant to work with that people hate every second of it. Except of course it isn't. Nobody sensibly complains that they can't mangle the length of a list, or move keys around inside dicts, or whatever. This data hiding is a good thing. All I want is the ability to do with Python classes what I can do with C extension types. I don't think that's an *unreasonable* ask, even if it is *unpractical* given the current design of Python. -- Steven From steven at REMOVE.THIS.cybersource.com.au Sun Feb 1 20:06:53 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 02 Feb 2009 01:06:53 GMT Subject: accessing elements of a tuple References: <0195522e$0$31512$c3e8da3@news.astraweb.com> Message-ID: On Sun, 01 Feb 2009 09:32:42 -0500, D'Arcy J.M. Cain wrote: > On Sun, 01 Feb 2009 19:23:58 +1100 > Steven D'Aprano wrote: >> D'Arcy J.M. Cain wrote: >> >> > First of all, list is a reserved word. ?Don't use it as a variable >> > name. >> >> Unless you mean to. Shadowing built-ins is only a bad thing when you do >> it by accident. > > I suppose but I am having a hard time trying to think of some good > reason to replace a builtin function that creates a list with a list > object. > >>>> list = list((1,2,3)) >>>> list((1,2,3)) > Traceback (most recent call last): > File "", line 1, in > TypeError: 'list' object is not callable There may not be a positive reason in favour of it, but in a small function that doesn't call list() and never will, there's no reason *against* using the name 'list'. Sometimes generic names like 'list' (or if you prefer, 'alist') are sensible, and in those cases, shadowing the list built-in may be a matter of taste. I personally don't like it, but some people obviously do. -- Steven From clp2 at rebertia.com Sun Feb 1 20:19:39 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 1 Feb 2009 17:19:39 -0800 Subject: question about Z=[[x for y in range(1, 2) if AList[x]==y] for x in range(0,5)] In-Reply-To: <77e831100901301733s4ebe3ca7i251a79955894f00e@mail.gmail.com> References: <77e831100901301733s4ebe3ca7i251a79955894f00e@mail.gmail.com> Message-ID: <50697b2c0902011719p6fa50076yd79d2fc3dce8771e@mail.gmail.com> On Fri, Jan 30, 2009 at 5:33 PM, Vincent Davis wrote: > Z=[[x for y in range(1,2) if AList[x]==y] for x in range(0,5)] > I am not sure how to ask this but which "for" is looped first? I could > test but was wondering if there was a nice explanation I could apply > to future situations. The outer one. Remember that you can always rewrite (a) list comprehension(s) into (an) equivalent for-loop(s). In this case: Z = [] for x in range(0,5): _tmp = [] for y in range(1,2): if AList[x]==y: _tmp.append(x) Z.append(_tmp) Or alternatively, imagine if the inner list comprehension was instead a function call: #assuming AList is a global var def inner_list_comp(x): return [x for y in range(1,2) if AList[x]==y] Z=[inner_list_comp(x) for x in range(0,5)] Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From kyrie at uh.cu Sun Feb 1 20:46:41 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Sun, 1 Feb 2009 20:46:41 -0500 Subject: is python Object oriented?? In-Reply-To: References: <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> Message-ID: <200902012046.41286.kyrie@uh.cu> On Sunday 01 February 2009 08:00:18 pm Steven D'Aprano wrote: > On Sun, 01 Feb 2009 12:31:27 -0500, Steve Holden wrote: > Except of course it isn't. Nobody sensibly complains that they can't > mangle the length of a list, or move keys around inside dicts, or > whatever. This data hiding is a good thing. If lists and dictionaries were not C types, and python didn't have to shield us from the mess that is C and its pointers, that enforcement may not be such a good thing. And, while we are at it, that is not python having "selective" enforcement of data hiding but only for C, that's C/C++ having data hiding and not exporting the attributes back to python. > All I want is the ability to do with Python classes what I can do with C > extension types. I don't think that's an *unreasonable* ask, even if it > is *unpractical* given the current design of Python. Well, then. Do you want dynamic checks? Go fix Bastion/rexec (that would be a _good_ thing, valuable for way more than data hiding). Or do you want static checks? In that case, you have it already. -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From steve at holdenweb.com Sun Feb 1 20:49:20 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 01 Feb 2009 20:49:20 -0500 Subject: is python Object oriented?? In-Reply-To: References: <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <4985DC6F.4030106@holdenweb.com> Message-ID: Rhodri James wrote: > On Sun, 01 Feb 2009 17:31:27 -0000, Steve Holden > wrote: > >> Stephen Hansen wrote: >>> [...] >>> don't play with anyone else's >>> privates. >>> >> A good rule in life as well as programming. > > Unless, of course, you're both consenting adults. > > What? Someone had to say it! > Nearly included it myself, but decided not to deny someone else the simple pleasure of posting it :) regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sun Feb 1 20:53:55 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 01 Feb 2009 20:53:55 -0500 Subject: is python Object oriented?? In-Reply-To: References: <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> Message-ID: Steven D'Aprano wrote: > On Sun, 01 Feb 2009 12:31:27 -0500, Steve Holden wrote: > >> I think it's noticeable that the people who have been arguing against >> what I might tipify as this "libertarian view" are those for whom the >> consequences of programming error are serious to extreme. > ... >> Just the same, it still doesn't save them from the consequences of >> interface miscommunication, as int he case of the Mars lander that >> crashed because one module provided a (probably strongly-typed) value in >> meters, and the recipient interpreted it as (probably strongly-typed) >> feet, cutting the engine out too early. > > Of course. Nor will data hiding prevent off-by-one errors, or errors of > logic, or data corruption, or stray cosmic rays flipping bits in memory. > But it will prevent *some* errors. It's one tool in an entire toolbox for > writing correct code, not a magic bullet. > > Python already has enforced data hiding, but only for built-ins. > Consequently, anyone who uses a list can absolutely, categorically trust > that len(alist) will return the actual length of alist, and not some > mangled value stuffed into alist by some arbitrary piece of code > somewhere else. > Unless, of course, some piece of code masks (or worse still, replaces) the len() function in __builtins__ with one of their own. There's no such thing as a foolproof system. The minute you think you have one the world comes up with a superior class of fool. > (For those unaware, in CPython lists are arrays. They store the current > length as a private value inaccessible to Python code.) > > Short of cosmic rays flipping bits, any built-in list you receive from > anywhere is going to have a valid length, and no pure-Python code can > make it invalid. To read some of the posts in this thread, one would be > forgiven for thinking that this most be a disaster of the highest > consequences, unPythonic to the extreme, an example of unfree B&D > programming so unpleasant to work with that people hate every second of > it. > > Except of course it isn't. Nobody sensibly complains that they can't > mangle the length of a list, or move keys around inside dicts, or > whatever. This data hiding is a good thing. > > All I want is the ability to do with Python classes what I can do with C > extension types. I don't think that's an *unreasonable* ask, even if it > is *unpractical* given the current design of Python. > I think the whole issue has received far more attention than is good for it. Your requirements seem quite reasonable to me, even though I doubt I'd ever use them. But it isn't *me* you have to persuade to get them in the language, is it? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sun Feb 1 21:06:49 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 01 Feb 2009 21:06:49 -0500 Subject: Problem with slow httplib connections on Windows (and maybe other platforms) In-Reply-To: References: Message-ID: rdmurray at bitdance.com wrote: > Quoth Christoph Zwerschke : >> rdmurray at bitdance.com schrieb: >>> Quoth Christoph Zwerschke : >>>> With Py 2.3 (without IPv6 support) this is only the IPv4 address, >>>> but with Py 2.4-2.6 the order is (on my Win XP host) the IPv6 address >>>> first, then the IPv4 address. Since the IPv6 address is checked first, >>>> this gives a timeout and causes the slow connect() call. The order by >>>> which getaddrinfo returns IPv4/v6 under Linux seems to vary depending >>>> on the glibc version, so it may be a problem on other platforms, too. >>> Based on something I read in another thread, this appears to be a problem >>> only under Windows. Everybody else implemented the TCP/IP stack according >>> to spec, and the IPV6 connect attempt times out immediately, producing >>> no slowdown. >>> >>> Microsoft, however.... >> The order in which getaddrinfo returns IPv4 and IPv6 is probably not >> written in the specs (Posix 1003.1g and RFC 2553). The fact that Windows >> returns IPv6 addresses first is not wrong in itself. >> >> For this discussion, see also >> http://www.ops.ietf.org/lists/v6ops/v6ops.2002/msg00869.html >> https://bugzilla.redhat.com/show_bug.cgi?id=190495 >> >> But yes, I also wonder why the connect to the IPv6 loopback address does >> not time out more quickly on Windows. > > Right, it's not the order of the returned items that's the Microsoft > weirdness, it's the long timeout on an attempt to connect to something > that doesn't exist. There was a long discussion about this, and it might > even have been on python-dev, but I can't lay my hands on the thread. > In short, Microsoft retries and waits a while when the far end says > "no thanks" to a connection attempt, instead of immediately returning > the connection failure the way Linux and etc and etc do. This applies > to IPV4, too. > Search for the subject line "socket.create_connection slow" - this was discovered by Kristjan Valur Jonsson. It certainly seems like a Microsoft weirdness. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From casevh at gmail.com Sun Feb 1 21:20:15 2009 From: casevh at gmail.com (casevh) Date: Sun, 1 Feb 2009 18:20:15 -0800 (PST) Subject: nth root References: <1AE19A80523D5F40BE0044A1447A53FF0ADB972E@UNIMAIL.staff.ad.cqu.edu.au> <44029925-ae8f-484e-8fcd-0d5ec484c184@z28g2000prd.googlegroups.com> Message-ID: <9ae987f6-d7f8-4d81-a740-7bb838e328da@v5g2000pre.googlegroups.com> On Feb 1, 1:04?pm, Mensanator wrote: > On Feb 1, 2:27?am, casevh wrote: > > > On Jan 31, 9:36?pm, "Tim Roberts" wrote: > > > > Actually, all I'm interested in is whether the 100 digit numbers have an exact integral root, or not. ?At the moment, because of accuracy concerns, I'm doing something like > > > > ? ? ? ? ? ? ? ? ? ? for root in powersp: > > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? nroot = round(bignum**(1.0/root)) > > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? if bignum==long(nroot)**root: > > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?......... > > > which is probably very inefficient, but I can't see anything better..... > > > > Tim > > > Take a look at gmpy and the is_power function. I think it will do > > exactly what you want. > > And the root function will give you the root AND tell you whether > it was an integral root: > > >>> gmpy.root(a,13) > > (mpz(3221), 0) > > In this case, it wasn't. > I think the original poster wants to know if a large number has an exact integral root for any exponent. is_power will give you an answer to that question but won't tell you what the root or exponent is. Once you know that the number is a perfect power, you can root to find the root. > > >http://code.google.com/p/gmpy/ > > > casevh > > From flouger at gmail.com Sun Feb 1 21:23:37 2009 From: flouger at gmail.com (Sam Price) Date: Sun, 1 Feb 2009 18:23:37 -0800 (PST) Subject: Question about wx folder browser widget Message-ID: <2d570f6a-4e97-4ab0-8fd2-eb5cddc5e363@z27g2000prd.googlegroups.com> Is there any good wx widgets that provide the same feel as folder/file browser. I want to be notified when a user tries to drag and drop a file/folder on the widget, and then copy that file/folder to a new folder an do operations on it. Wanted to check first to see if something exists, and not reinvent the wheel. Thank you, Sam Price From lxkain at gmail.com Sun Feb 1 21:31:34 2009 From: lxkain at gmail.com (LX) Date: Sun, 1 Feb 2009 18:31:34 -0800 (PST) Subject: AssertionError not caught? Message-ID: <14fe6987-b03b-4d84-b4d3-8a68703fa0b1@k1g2000prb.googlegroups.com> This one has me mystified good! This works (print statement is executed as the Exception is caught) as advertised: try: raise AssertionError except AssertionError: print "caught AssertionError" But this one does not: def test(): raise AssertionError try: test() except AssertionError: print "caught AssertionError" other errors (e.g. IOError) work fine! This is on OSX 10.5.6, with the standard Python 2.5 (r25:51918, Sep 19 2006, 08:49:13) [GCC 4.0.1 (Apple Computer, Inc. build 5341)]. Is this a bug? Any hints / help would be much appreciated! Thank you. From clp2 at rebertia.com Sun Feb 1 21:44:14 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 1 Feb 2009 18:44:14 -0800 Subject: AssertionError not caught? In-Reply-To: <14fe6987-b03b-4d84-b4d3-8a68703fa0b1@k1g2000prb.googlegroups.com> References: <14fe6987-b03b-4d84-b4d3-8a68703fa0b1@k1g2000prb.googlegroups.com> Message-ID: <50697b2c0902011844n2007e5b2q19cfa2fb977f3818@mail.gmail.com> On Sun, Feb 1, 2009 at 6:31 PM, LX wrote: > This one has me mystified good! > > This works (print statement is executed as the Exception is caught) as > advertised: > try: > raise AssertionError > except AssertionError: > print "caught AssertionError" > > > But this one does not: > > def test(): > raise AssertionError > > try: > test() > except AssertionError: > print "caught AssertionError" > > other errors (e.g. IOError) work fine! This is on OSX 10.5.6, with the > standard Python 2.5 (r25:51918, Sep 19 2006, 08:49:13) > [GCC 4.0.1 (Apple Computer, Inc. build 5341)]. > > Is this a bug? Any hints / help would be much appreciated! Thank you. My Mac begs to differ: ~ $ cat Desktop/tmp.py def test(): raise AssertionError try: test() except AssertionError: print "caught AssertionError" ~ $ /System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5 Desktop/tmp.py caught AssertionError ~ $ /System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5 Python 2.5.1 (r251:54863, Feb 4 2008, 21:48:13) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin The problem must lie elsewhere. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From gdamjan at gmail.com Sun Feb 1 21:50:16 2009 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Mon, 02 Feb 2009 03:50:16 +0100 Subject: Completer with history for Python 3 ? Message-ID: <9k3i56-2d3.ln1@archaeopteryx.softver.org.mk> I've been long using this recipe [1] ?Completer with history viewer support and more features? with the interactive prompt of python 2.x But it's not compatible with Python 3.0 Anyone know of a similar functionality for Python 3.0 or I should try to port this script? [1] http://code.activestate.com/recipes/496822/ -- ?????? ( http://softver.org.mk/damjan/ ) Spammers scratch here with a diamond to find my address: ||||||||||||||||||||||||||||||||||||||||||||||| From lxkain at gmail.com Sun Feb 1 21:51:53 2009 From: lxkain at gmail.com (Alexander Kain) Date: Sun, 1 Feb 2009 18:51:53 -0800 Subject: AssertionError not caught? In-Reply-To: <50697b2c0902011844n2007e5b2q19cfa2fb977f3818@mail.gmail.com> References: <14fe6987-b03b-4d84-b4d3-8a68703fa0b1@k1g2000prb.googlegroups.com> <50697b2c0902011844n2007e5b2q19cfa2fb977f3818@mail.gmail.com> Message-ID: <88312E27-1EFD-4AEB-9C4C-87B7D9F196CA@gmail.com> Thank you for restoring sanity to my world! Indeed, it seems to have to do with the way that the WingIDE debugger works - it actually catches the error correctly , but it -->sets a breakpoint at the original raise first<---. This only occurs for the AssertionError. The debugger can then be continued. Thank you again! On Feb 1, 2009, at 6:44 PM, Chris Rebert wrote: > On Sun, Feb 1, 2009 at 6:31 PM, LX wrote: >> This one has me mystified good! >> >> This works (print statement is executed as the Exception is caught) >> as >> advertised: >> try: >> raise AssertionError >> except AssertionError: >> print "caught AssertionError" >> >> >> But this one does not: >> >> def test(): >> raise AssertionError >> >> try: >> test() >> except AssertionError: >> print "caught AssertionError" >> >> other errors (e.g. IOError) work fine! This is on OSX 10.5.6, with >> the >> standard Python 2.5 (r25:51918, Sep 19 2006, 08:49:13) >> [GCC 4.0.1 (Apple Computer, Inc. build 5341)]. >> >> Is this a bug? Any hints / help would be much appreciated! Thank you. > > My Mac begs to differ: > > ~ $ cat Desktop/tmp.py > def test(): > raise AssertionError > > try: > test() > except AssertionError: > print "caught AssertionError" > ~ $ /System/Library/Frameworks/Python.framework/Versions/2.5/bin/ > python2.5 > Desktop/tmp.py > caught AssertionError > ~ $ /System/Library/Frameworks/Python.framework/Versions/2.5/bin/ > python2.5 > Python 2.5.1 (r251:54863, Feb 4 2008, 21:48:13) > [GCC 4.0.1 (Apple Inc. build 5465)] on darwin > > The problem must lie elsewhere. > > Cheers, > Chris > > -- > Follow the path of the Iguana... > http://rebertia.com From bignose+hates-spam at benfinney.id.au Sun Feb 1 21:55:01 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Mon, 02 Feb 2009 13:55:01 +1100 Subject: AssertionError not caught? References: <14fe6987-b03b-4d84-b4d3-8a68703fa0b1@k1g2000prb.googlegroups.com> Message-ID: <87r62h1ray.fsf@benfinney.id.au> LX writes: > This works (print statement is executed as the Exception is caught) > as advertised: You don't actually show us the output you get. > try: > raise AssertionError > except AssertionError: > print "caught AssertionError" >>> try: ... raise AssertionError ... except AssertionError: ... print "caught AssertionError" ... caught AssertionError > But this one does not: > > def test(): > raise AssertionError > > try: > test() > except AssertionError: > print "caught AssertionError" >>> def test(): ... raise AssertionError ... >>> try: ... test() ... except AssertionError: ... print "caught AssertionError" ... caught AssertionError > other errors (e.g. IOError) work fine! This is on OSX 10.5.6, with > the standard Python 2.5 (r25:51918, Sep 19 2006, 08:49:13) [GCC > 4.0.1 (Apple Computer, Inc. build 5341)]. Python 2.5.2 (r252:60911, Jan 4 2009, 22:51:23) [GCC 4.3.2] on linux2 > Is this a bug? It's much more likely to be a difference between the code you posted here and the code you're actually running. -- \ ?It ain't so much the things we don't know that get us in | `\ trouble. It's the things we know that ain't so.? ?Artemus Ward | _o__) (1834-67), U.S. journalist | Ben Finney From steve at holdenweb.com Sun Feb 1 21:58:07 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 01 Feb 2009 21:58:07 -0500 Subject: Question about wx folder browser widget In-Reply-To: <2d570f6a-4e97-4ab0-8fd2-eb5cddc5e363@z27g2000prd.googlegroups.com> References: <2d570f6a-4e97-4ab0-8fd2-eb5cddc5e363@z27g2000prd.googlegroups.com> Message-ID: Sam Price wrote: > Is there any good wx widgets that provide the same feel as folder/file > browser. > I want to be notified when a user tries to drag and drop a file/folder > on the widget, and then copy that file/folder to a new folder an do > operations on it. > > Wanted to check first to see if something exists, and not reinvent the > wheel. > There's TreeCtrl, and CustomTreeCtrl. I don't know whether they can be used with drag and drop, but take alook at http://wiki.wxpython.org/DragAndDrop to see some code and get an idea of how to find out whether it will adapt to those controls. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sun Feb 1 22:01:29 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 01 Feb 2009 22:01:29 -0500 Subject: AssertionError not caught? In-Reply-To: <14fe6987-b03b-4d84-b4d3-8a68703fa0b1@k1g2000prb.googlegroups.com> References: <14fe6987-b03b-4d84-b4d3-8a68703fa0b1@k1g2000prb.googlegroups.com> Message-ID: LX wrote: > This one has me mystified good! > > This works (print statement is executed as the Exception is caught) as > advertised: > try: > raise AssertionError > except AssertionError: > print "caught AssertionError" > > > But this one does not: > > def test(): > raise AssertionError > > try: > test() > except AssertionError: > print "caught AssertionError" > > other errors (e.g. IOError) work fine! This is on OSX 10.5.6, with the > standard Python 2.5 (r25:51918, Sep 19 2006, 08:49:13) > [GCC 4.0.1 (Apple Computer, Inc. build 5341)]. > > Is this a bug? Any hints / help would be much appreciated! Thank you. This works for me under Cygwin: >>> def test(): ... raise AssertionError ... >>> try: ... test() ... except AssertionError: ... print "caught AssertionError" ... caught AssertionError >>> I note from your indentation that it looks as though your code was guarded by some other statement. Is it possible it wasn't executed at all? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From rdmurray at bitdance.com Sun Feb 1 22:11:39 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Mon, 2 Feb 2009 03:11:39 +0000 (UTC) Subject: Membership of multiple items to a list References: Message-ID: Quoth Steven D'Aprano : > On Sun, 01 Feb 2009 12:01:11 -0800, Stephen Hansen wrote: > > >
> style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt > > 0.8ex; padding-left: 1ex;">
I'd like to know how to elegantly check > > a list for the membership of
any of its items to another list. > >  Not caring for elegance, I would
use the following code:
> >

That's one of the useful properties of > > sets:

>>> a = [1,2,3]
>>> b = > > [3,4,5,6]
>>> set(a) & > > set(b)
set([3])
>>> > > set(a).intersection(b)
set([3])

That's two spellings of the > > same thing. As for testing: an empty set like an empty list will return > > false, so "if set(a) & set(b):" will be true or false based on if > > there's any commonalities between the two > > lists.

--Stephen

> > > Stephen, do you see the utter mess your posts look like to some others? I don't even see Stephen Hansen's posts. My newsreader just shows the header and says "[HTML part not displayed]". --RDM From apt.shansen at gmail.com Sun Feb 1 22:16:49 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sun, 1 Feb 2009 19:16:49 -0800 Subject: Membership of multiple items to a list In-Reply-To: References: Message-ID: <7a9c25c20902011916t7c0d4dd9n2225ba80ef49e75b@mail.gmail.com> > Stephen, do you see the utter mess your posts look like to some others? Whoops, I was experimenting with a new Firefox add-on that fiddled with Gmail, and hadn't noticed it changed my output format to HTML out from under me. Sorry! --S From apt.shansen at gmail.com Sun Feb 1 22:34:46 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sun, 1 Feb 2009 19:34:46 -0800 Subject: Auto Logon to site and get page In-Reply-To: <456128.62923.qm@web112207.mail.gq1.yahoo.com> References: <456128.62923.qm@web112207.mail.gq1.yahoo.com> Message-ID: <7a9c25c20902011934u62c61f83w40e4444fe883589@mail.gmail.com> > This doesn't however, it just sends me back to the main login page, doenst > say invalid password or anything. I've checked, yes the python hmac hash > function produces the same results (encrypted password) as the md5.js file. > Does anyone know what I am doing wrong?? My guess? After you successfully login the webpage is setting a cookie on your browser with a token to mark you as authenticated and let you in. Lots of websites do that: I don't think urllib2 is handling that by itself so you may need to. You also may have to set a User-agent header to convince it you're legitimate. I googled briefly and came up with http://www.voidspace.org.uk/python/articles/cookielib.shtml which may be totally useless or of great value. I am not providing it as a solution, it just at a brief glance looks potentially relevant :) --S From jabar004 at gmail.com Sun Feb 1 22:35:05 2009 From: jabar004 at gmail.com (JuanPablo) Date: Mon, 2 Feb 2009 00:35:05 -0300 Subject: call other program Message-ID: <110df1290902011935q275bccfag7f25121eb94125ac@mail.gmail.com> hi, I have a newbie question. In bash is posible call other program, send and recieve message with this. example: $ python > output << EOF > print "hello world" > EOF $ cat output hello world in python exist some similar ? many thanks JuanPablo -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Sun Feb 1 22:37:09 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 1 Feb 2009 19:37:09 -0800 Subject: call other program In-Reply-To: <110df1290902011935q275bccfag7f25121eb94125ac@mail.gmail.com> References: <110df1290902011935q275bccfag7f25121eb94125ac@mail.gmail.com> Message-ID: <50697b2c0902011937u42c6d437uad8f6b7d5726a24f@mail.gmail.com> On Sun, Feb 1, 2009 at 7:35 PM, JuanPablo wrote: > hi, > I have a newbie question. > In bash is posible call other program, send and recieve message with this. > > example: > $ python > output << EOF >> print "hello world" >> EOF > $ cat output > hello world > > in python exist some similar ? See the `subprocess` module -- http://docs.python.org/library/subprocess.html Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From gdamjan at gmail.com Sun Feb 1 22:38:12 2009 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Mon, 02 Feb 2009 04:38:12 +0100 Subject: Completer with history for Python 3 ? References: <9k3i56-2d3.ln1@archaeopteryx.softver.org.mk> Message-ID: <4e6i56-3e5.ln1@archaeopteryx.softver.org.mk> > I've been long using this recipe [1] ?Completer with history viewer > support and more features? with the interactive prompt of python 2.x > But it's not compatible with Python 3.0 > > Anyone know of a similar functionality for Python 3.0 or I should try > to port this script? > > [1] > http://code.activestate.com/recipes/496822/ Well, I've made a patch that makes it kinda work http://paste.lisp.org/display/74707 it does work except that the irlcompleter doesn't complete filenames or usernames... any idea why? -- ?????? ( http://softver.org.mk/damjan/ ) Give me the knowledge to change the code I do not accept, the wisdom not to accept the code I cannot change, and the freedom to choose my preference. From cjns1989 at gmail.com Sun Feb 1 22:46:54 2009 From: cjns1989 at gmail.com (Chris Jones) Date: Sun, 01 Feb 2009 22:46:54 -0500 Subject: what IDE is the best to write python? In-Reply-To: <874ozd3cr3.fsf@benfinney.id.au> References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> <874ozd3cr3.fsf@benfinney.id.au> Message-ID: <20090202034654.GD30237@turki.gavron.org> On Sun, Feb 01, 2009 at 07:26:24PM EST, Ben Finney wrote: > aahz at pythoncraft.com (Aahz) writes: > > > Just to register a contrary opinion: I *hate* syntax highlighting > > On what basis? Real men hate syntax highlighting. From bignose+hates-spam at benfinney.id.au Sun Feb 1 22:47:51 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Mon, 02 Feb 2009 14:47:51 +1100 Subject: Membership of multiple items to a list References: Message-ID: <87myd51ouw.fsf@benfinney.id.au> rdmurray at bitdance.com writes: > I don't even see Stephen Hansen's posts. My newsreader just shows > the header and says "[HTML part not displayed]". Likewise. Note to people who want to communicate in online fora: Set your client to generate a ?text/plain? body only. HTML is either irrelevant to your message (so don't generate it), or will result in your message not even being seen at all by some readers (as in this case). -- \ ?If it ain't bust don't fix it is a very sound principle and | `\ remains so despite the fact that I have slavishly ignored it | _o__) all my life.? ?Douglas Adams | Ben Finney From sjmachin at lexicon.net Sun Feb 1 22:52:04 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 1 Feb 2009 19:52:04 -0800 (PST) Subject: getting values from a text file (newby) References: Message-ID: <26d7ffc0-1bca-452c-b8c2-faca5e005e07@w1g2000prm.googlegroups.com> On Feb 2, 10:18?am, vsoler wrote: > On 1 feb, 23:57, John Machin wrote: > > > On Feb 2, 6:18?am, vsoler wrote: > > > > r: in the open statement, why do you use 'rb' as 2nd argument? b is > > > supposed to be binary, and my file is text! > > > Because unlike Stephen, r has read the csv manual. Binary mode is > > required to handle properly cases like '\n' embedded in a field -- > > something which can easily happen when the data has been extracted > > from a database with slack data-entry validation. > > Where can I get the csv manual? http://www.python.org/doc/2.6/library/csv.html If you're on Windows, you've got it already: Start > All Programs > Python 2.6 > Python Manuals type "csv" (without the quotes) into the textbox hit the Enter key From hungvn94 at gmail.com Sun Feb 1 23:16:45 2009 From: hungvn94 at gmail.com (Hung Vo) Date: Sun, 1 Feb 2009 20:16:45 -0800 (PST) Subject: is python Object oriented?? References: Message-ID: On Feb 2, 4:10?am, Stephen Hansen wrote: > Anyway, it doesn't matter. We're losing the point here. The point is > that language support for private access, by disallowing user access > to private data, provides an unambiguous information hiding mechanism > which encourages encapsulation. Python's approach, however, which is > only a naming convention rather than a language feature, merely TRUSTS > the programmer not to break encapsulation. And sure, if we're all good > programmers, everything will go well and we'll end up with an > organized application. But the danger is still there: at any given > time, we COULD break encapsulation! > > > I was long-winded the last time I responded to this point so no one probably read it :) Yes, we read it. You made good points!! Cheers, Hung From david.lyon at preisshare.net Sun Feb 1 23:17:50 2009 From: david.lyon at preisshare.net (David Lyon) Date: Sun, 01 Feb 2009 23:17:50 -0500 Subject: Python package Management GUI - New Project on Sourceforge In-Reply-To: <497FAFE4.4040602@gmail.com> References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> <497FAFE4.4040602@gmail.com> Message-ID: <83900549676010b8244969ece9319a78@preisshare.net> Hi all, I am pleased to announce that we have started a new python project on sourceforge. Python Package Manager pythonpkgmgr.sourceforge.net The goal is to provide a cross platform GUI tool that will vastly simplify loading and installing packages under python. - written in python - use WXWidgets for cross compatability - utilises distutils - provide a GUI wrapper for EasyInstall and pip - fetches packages from http://pypi.python.org/pypi using their XML-RPC interface. Feel free to apply to join the project and help us build the solution that we all need and deserve. Regards David Lyon From prologic at shortcircuit.net.au Sun Feb 1 23:47:29 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 2 Feb 2009 14:47:29 +1000 Subject: Python package Management GUI - New Project on Sourceforge In-Reply-To: <83900549676010b8244969ece9319a78@preisshare.net> References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> <497FAFE4.4040602@gmail.com> <83900549676010b8244969ece9319a78@preisshare.net> Message-ID: On Mon, Feb 2, 2009 at 2:17 PM, David Lyon wrote: > Hi all, > > I am pleased to announce that we have started a new python > project on sourceforge. > > Python Package Manager > pythonpkgmgr.sourceforge.net > > The goal is to provide a cross platform GUI tool that will > vastly simplify loading and installing packages under python. > > - written in python > - use WXWidgets for cross compatability > - utilises distutils > - provide a GUI wrapper for EasyInstall and pip > - fetches packages from http://pypi.python.org/pypi > using their XML-RPC interface. > > Feel free to apply to join the project and help us build the solution that > we all need and deserve. > > Regards David Lyon What's wrong with Enstaller from Enthought ? Can I make a few suggestions ? To be truly cross platform, consider using the Tcl/Tk toolkit rather tahn wxWindows. Why ? Because Tcl/TK is packaged and provided along with most Python distributions. Also, to reduce the amount of work you as developers need to do and to aid in the "code reuse" philosophy, I would not simply have wrappers around easy_install and pip, I would integrate as best as you can into these libraries without trying to add or rewrite too much. Also, consider integrating with yolk as well, as it provides some food features and functionality that easy_install and pip don't provide. cheers James From david.lyon at preisshare.net Sun Feb 1 23:57:05 2009 From: david.lyon at preisshare.net (David Lyon) Date: Sun, 01 Feb 2009 23:57:05 -0500 Subject: Python package Management GUI - New Project on Sourceforge In-Reply-To: References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> <497FAFE4.4040602@gmail.com> <83900549676010b8244969ece9319a78@preisshare.net> Message-ID: > What's wrong with Enstaller from Enthought ? for a start.... on https://svn.enthought.com/enthought/wiki/Enstaller it claims to be depracated... > Can I make a few suggestions ? Sure.. > To be truly cross platform, consider > using the Tcl/Tk toolkit rather tahn > wxWindows. Why ? Because Tcl/TK > is packaged and provided along with > most Python distributions. I agree with your point.. The problem is that Tcl/TK is a functionaly handicapped and results in a less powerful GUI. In an installer, it is not so hard to install the wxWidgets dll (under windows) But later, I won't mind redoing it in tk if it becomes too much of a hassle. > I would not simply have wrappers around > easy_install and pip, I would integrate > as best as you can into these libraries > without trying to add or rewrite too much. Sure... I agree > Also, consider integrating with yolk > as well, as it provides some food features > and functionality that easy_install and pip > don't provide. Thanks - I will check out your suggestions in detail. Take care David From prologic at shortcircuit.net.au Mon Feb 2 00:24:06 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 2 Feb 2009 15:24:06 +1000 Subject: Python package Management GUI - New Project on Sourceforge In-Reply-To: References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> <497FAFE4.4040602@gmail.com> <83900549676010b8244969ece9319a78@preisshare.net> Message-ID: On Mon, Feb 2, 2009 at 2:57 PM, David Lyon wrote: >> To be truly cross platform, consider >> using the Tcl/Tk toolkit rather tahn >> wxWindows. Why ? Because Tcl/TK >> is packaged and provided along with >> most Python distributions. > > I agree with your point.. > > The problem is that Tcl/TK is a functionaly > handicapped and results in a less powerful GUI. > > In an installer, it is not so hard to install > the wxWidgets dll (under windows) > > But later, I won't mind redoing it in tk if > it becomes too much of a hassle. David, I would really recommend that you seriously consider using the Tcp/Tk toolkit. Why ? Because of my point above, you'll find the tool will most likely have a greater impact and uptake than one requiring a user or developer to install a 3rd party toolkit and library just to use your gui package manager :) Trust me when I say this, the simpler you make this, the better. "Powerful" is meaningless in the context of programming - it has no meaning. If you meant wxWindows/wxWidgets are more feature-rich, then yes I agree - but at what cost ? :) My 2c, cheers James From an00na at gmail.com Mon Feb 2 01:01:17 2009 From: an00na at gmail.com (an0) Date: Sun, 1 Feb 2009 22:01:17 -0800 (PST) Subject: Why such different HTTP response results between 2.5 and 3.0 Message-ID: Below are two semantically same snippets for querying the same partial HTTP response, for Python2.5 and Python 3.0 respectively. However, the 3.0 version returns a not-so-right result(msg) which is a bytes of length 239775, while the 2.5 version returns a good msg which is a 239733 byte-long string that is the content of a proper zip file. I really can't figure out what's wrong, thought I've sought out some "\r\n" segments in msg 3.0 that is absent in msg 2.5. So are there anyone could give me some hints? Thanks in advance. Code: # Python 2.5 import urllib2 auth_handler = urllib2.HTTPBasicAuthHandler() auth_handler.add_password(realm="pluses and minuses", uri='http://www.pythonchallenge.com/pc/hex/ unreal.jpg', user='butter', passwd='fly') opener = urllib2.build_opener(auth_handler) req = urllib2.Request('http://www.pythonchallenge.com/pc/hex/ unreal.jpg') req.add_header('Range', 'bytes=1152983631-') res = opener.open(req) msg = res.read() # Python 3.0 import urllib.request auth_handler = urllib.request.HTTPBasicAuthHandler() auth_handler.add_password(realm="pluses and minuses", uri='http://www.pythonchallenge.com/pc/hex/ unreal.jpg', user='butter', passwd='fly') opener = urllib.request.build_opener(auth_handler) req = urllib.request.Request('http://www.pythonchallenge.com/pc/hex/ unreal.jpg') req.add_header('Range', 'bytes=1152983631-') res = opener.open(req) msg = res.read() From mensanator at aol.com Mon Feb 2 01:02:32 2009 From: mensanator at aol.com (Mensanator) Date: Sun, 1 Feb 2009 22:02:32 -0800 (PST) Subject: nth root References: <1AE19A80523D5F40BE0044A1447A53FF0ADB972E@UNIMAIL.staff.ad.cqu.edu.au> <44029925-ae8f-484e-8fcd-0d5ec484c184@z28g2000prd.googlegroups.com> <9ae987f6-d7f8-4d81-a740-7bb838e328da@v5g2000pre.googlegroups.com> Message-ID: <81c042d3-39a6-42c3-a529-7acc06d484b1@u14g2000yqg.googlegroups.com> On Feb 1, 8:20?pm, casevh wrote: > On Feb 1, 1:04?pm, Mensanator wrote: > > > > > On Feb 1, 2:27?am, casevh wrote: > > > > On Jan 31, 9:36?pm, "Tim Roberts" wrote: > > > > > Actually, all I'm interested in is whether the 100 digit numbers have an exact integral root, or not. ?At the moment, because of accuracy concerns, I'm doing something like > > > > > ? ? ? ? ? ? ? ? ? ? for root in powersp: > > > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? nroot = round(bignum**(1.0/root)) > > > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? if bignum==long(nroot)**root: > > > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?......... > > > > which is probably very inefficient, but I can't see anything better..... > > > > > Tim > > > > Take a look at gmpy and the is_power function. I think it will do > > > exactly what you want. > > > And the root function will give you the root AND tell you whether > > it was an integral root: > > > >>> gmpy.root(a,13) > > > (mpz(3221), 0) > > > In this case, it wasn't. > > I think the original poster wants to know if a large number has an > exact integral root for any exponent. is_power will give you an answer > to that question but won't tell you what the root or exponent is. Once > you know that the number is a perfect power, you can root to find the > root. But how do you know what exponent to use? > > > > > > > >http://code.google.com/p/gmpy/ > > > > casevh From BrianVanderburg2 at aim.com Mon Feb 2 01:37:13 2009 From: BrianVanderburg2 at aim.com (Brian Allen Vanderburg II) Date: Mon, 02 Feb 2009 01:37:13 -0500 Subject: Why such different HTTP response results between 2.5 and 3.0 In-Reply-To: References: Message-ID: <49869499.7070109@aim.com> an00na at gmail.com wrote: > Below are two semantically same snippets for querying the same partial > HTTP response, for Python2.5 and Python 3.0 respectively. > However, the 3.0 version returns a not-so-right result(msg) which is a > bytes of length 239775, while the 2.5 version returns a good msg which > is a 239733 byte-long string that is the content of a proper zip file. > I really can't figure out what's wrong, thought I've sought out some > "\r\n" segments in msg 3.0 that is absent in msg 2.5. > So are there anyone could give me some hints? Thanks in advance. > > Code: > > # Python 2.5 > import urllib2 > auth_handler = urllib2.HTTPBasicAuthHandler() > auth_handler.add_password(realm="pluses and minuses", > uri='http://www.pythonchallenge.com/pc/hex/ > unreal.jpg', > user='butter', > passwd='fly') > opener = urllib2.build_opener(auth_handler) > > req = urllib2.Request('http://www.pythonchallenge.com/pc/hex/ > unreal.jpg') > req.add_header('Range', 'bytes=1152983631-') > res = opener.open(req) > msg = res.read() > > # Python 3.0 > import urllib.request > auth_handler = urllib.request.HTTPBasicAuthHandler() > auth_handler.add_password(realm="pluses and minuses", > uri='http://www.pythonchallenge.com/pc/hex/ > unreal.jpg', > user='butter', > passwd='fly') > opener = urllib.request.build_opener(auth_handler) > > req = urllib.request.Request('http://www.pythonchallenge.com/pc/hex/ > unreal.jpg') > req.add_header('Range', 'bytes=1152983631-') > res = opener.open(req) > msg = res.read() > -- > http://mail.python.org/mailman/listinfo/python-list > From what I can tell, Python 2.5 returns the request automatically decoded as text. Python 3.0 returns a bytes object and doesn't decode it at all. I did a test with urlopen: In 2.5 for http://google.com just get the regular HTML In 3.0 I get some extras at the start and end: 191d\r\n at the start \r\n0\r\n\r\n at the end In 2.5, newlines are automatically decoded In 3.0, the \r\n pairs are kept I hope their is an easy way to decode it as it was in 2.x Brian Vanderburg II From cito at online.de Mon Feb 2 01:43:59 2009 From: cito at online.de (Christoph Zwerschke) Date: Mon, 02 Feb 2009 07:43:59 +0100 Subject: Problem with slow httplib connections on Windows (and maybe other platforms) In-Reply-To: References: Message-ID: Steve Holden schrieb: > Search for the subject line "socket.create_connection slow" - this was > discovered by Kristjan Valur Jonsson. It certainly seems like a > Microsoft weirdness. Thanks for the pointer, Steve. I hadn't seen that yet. I agree that's actually the real problem here. The solution suggested in that thread, using a dual-stacked socket for the TCPserver, seems a good one to me. -- Christoph From meswamy at gmail.com Mon Feb 2 01:44:35 2009 From: meswamy at gmail.com (swamynathan) Date: Mon, 2 Feb 2009 12:14:35 +0530 Subject: key capture Message-ID: <72218f020902012244g75593286x83f3157c0379a8e0@mail.gmail.com> hello, im making a virtual piano in python where on key stroke a wav is played from a location now to implement a fully functional piano i need to have multiple key stroke captures ie if 2 or 3 keys pressed then the function which playes the wav is called with 3 parameters how to implement this or any other suggestion(i was asked to try multi threading which dint seem optimal) -- your caring/loving/sincere/oyoyoy[select it urself] swamynathan. -------------- next part -------------- An HTML attachment was scrubbed... URL: From casevh at gmail.com Mon Feb 2 02:01:58 2009 From: casevh at gmail.com (casevh) Date: Sun, 1 Feb 2009 23:01:58 -0800 (PST) Subject: nth root References: <1AE19A80523D5F40BE0044A1447A53FF0ADB972E@UNIMAIL.staff.ad.cqu.edu.au> <44029925-ae8f-484e-8fcd-0d5ec484c184@z28g2000prd.googlegroups.com> <9ae987f6-d7f8-4d81-a740-7bb838e328da@v5g2000pre.googlegroups.com> <81c042d3-39a6-42c3-a529-7acc06d484b1@u14g2000yqg.googlegroups.com> Message-ID: <68b1337a-1938-4765-b28a-dc526dd8e8c1@x6g2000pre.googlegroups.com> On Feb 1, 10:02?pm, Mensanator wrote: > On Feb 1, 8:20 pm, casevh wrote: > > > > > On Feb 1, 1:04 pm, Mensanator wrote: > > > > On Feb 1, 2:27 am, casevh wrote: > > > > > On Jan 31, 9:36 pm, "Tim Roberts" wrote: > > > > > > Actually, all I'm interested in is whether the 100 digit numbers have an exact integral root, or not. At the moment, because of accuracy concerns, I'm doing something like > > > > > > for root in powersp: > > > > > nroot = round(bignum**(1.0/root)) > > > > > if bignum==long(nroot)**root: > > > > > ......... > > > > > which is probably very inefficient, but I can't see anything better..... > > > > > > Tim > > > > > Take a look at gmpy and the is_power function. I think it will do > > > > exactly what you want. > > > > And the root function will give you the root AND tell you whether > > > it was an integral root: > > > > >>> gmpy.root(a,13) > > > > (mpz(3221), 0) > > > > In this case, it wasn't. > > > I think the original poster wants to know if a large number has an > > exact integral root for any exponent. is_power will give you an answer > > to that question but won't tell you what the root or exponent is. Once > > you know that the number is a perfect power, you can root to find the > > root. > > But how do you know what exponent to use? That's the gotcha. :) You still need to test all prime exponents until you find the correct one. But it is much faster to use is_power to check whether or not a number has representation as a**b and then try all the possible exponents than to just try all the possible exponents on all the numbers. > > > > > > >http://code.google.com/p/gmpy/ > > > > > casevh > > From raykyoto at gmail.com Mon Feb 2 02:05:50 2009 From: raykyoto at gmail.com (Ray) Date: Sun, 1 Feb 2009 23:05:50 -0800 (PST) Subject: Import without executing module Message-ID: Hi all, I'm quite new to python as I've only just started to learn about it a few days ago... I am trying to do something and after reading about it, I'm still not sure whether or not it can be done. Basically, someone has created a python script and I would like to make use of his functions. I would prefer to not modify his file so what I would like to do is just write my script and import parts that are needed. i.e., I would like to separate my changes from his as best as I can. However, that other module has both functions (def's, which I would like to use) and top-level commands which I don't need and in fact, prints errors when I import it since it was meant to be run as a top-level module and not imported in. i.e., its expecting arguments to be supplied. For example, suppose I have a module test.py: ----- from test2 import foo foo() #import test2 #test2.foo() print "test says hello" ----- and test2.py: ----- def foo(): print "foo is being executed" print "test2 says hello" ----- and I would like to run "python test.py" without "test2 says hello" appearing. I figured "import test2" would not work, so I thought that maybe "from" would only take the functions listed, but no. In the end, it is just importing all of "test2" and then renaming it: foo = test2.foo . This isn't a very serious problem as I obviously have the source and can just copy the functions and attribute the original author (that's ok). But, it would be nice if I can make use of those functions without touching that file [test2.py in the above example]. Is this possible? Thank you! Ray From apt.shansen at gmail.com Mon Feb 2 02:19:09 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sun, 1 Feb 2009 23:19:09 -0800 Subject: Import without executing module In-Reply-To: References: Message-ID: <7a9c25c20902012319i2d217644k12bc926400f630c2@mail.gmail.com> On Sun, Feb 1, 2009 at 11:05 PM, Ray wrote: > Basically, someone has created a python script and I would like to > make use of his functions. I would prefer to not modify his file so > what I would like to do is just write my script and import parts that > are needed. i.e., I would like to separate my changes from his as > best as I can. However, that other module has both functions (def's, > which I would like to use) and top-level commands which I don't need > and in fact, prints errors when I import it since it was meant to be > run as a top-level module and not imported in. i.e., its expecting > arguments to be supplied. Unfortunately, that's not possible, I believe. All the top level commands in a particular Python script are executed: that's how the functions get created. --S From n.kottiyath at gmail.com Mon Feb 2 02:25:17 2009 From: n.kottiyath at gmail.com (Kottiyath) Date: Sun, 1 Feb 2009 23:25:17 -0800 (PST) Subject: Import without executing module References: Message-ID: On Feb 2, 12:19?pm, Stephen Hansen wrote: > On Sun, Feb 1, 2009 at 11:05 PM, Ray wrote: > > Basically, someone has created a python script and I would like to > > make use of his functions. ?I would prefer to not modify his file so > > what I would like to do is just write my script and import parts that > > are needed. ?i.e., I would like to separate my changes from his as > > best as I can. ?However, that other module has both functions (def's, > > which I would like to use) and top-level commands which I don't need > > and in fact, prints errors when I import it since it was meant to be > > run as a top-level module and not imported in. ?i.e., its expecting > > arguments to be supplied. > > Unfortunately, that's not possible, I believe. All the top level > commands in a particular Python script are executed: that's how the > functions get created. > > --S Maybe he can wrap the things he dont need inside if __name__ == '__main__': check. From gabriel.rossetti at arimaz.com Mon Feb 2 02:33:05 2009 From: gabriel.rossetti at arimaz.com (Gabriel Rossetti) Date: Mon, 02 Feb 2009 08:33:05 +0100 Subject: Python package Management GUI - New Project on Sourceforge In-Reply-To: References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> <497FAFE4.4040602@gmail.com> <83900549676010b8244969ece9319a78@preisshare.net> Message-ID: <4986A1B1.9070805@arimaz.com> James Mills wrote: > On Mon, Feb 2, 2009 at 2:57 PM, David Lyon wrote: > >>> To be truly cross platform, consider >>> using the Tcl/Tk toolkit rather tahn >>> wxWindows. Why ? Because Tcl/TK >>> is packaged and provided along with >>> most Python distributions. >>> >> I agree with your point.. >> >> The problem is that Tcl/TK is a functionaly >> handicapped and results in a less powerful GUI. >> >> In an installer, it is not so hard to install >> the wxWidgets dll (under windows) >> >> But later, I won't mind redoing it in tk if >> it becomes too much of a hassle. >> > > David, I would really recommend that you > seriously consider using the Tcp/Tk toolkit. > Why ? Because of my point above, you'll > find the tool will most likely have a greater > impact and uptake than one requiring a user > or developer to install a 3rd party toolkit > and library just to use your gui package > manager :) > Well, isn't tkinter being removed? (http://www.python.org/dev/peps/pep-3108/) So the user will have to install it anyways, I think wx is way better that tkinter from a user and a developer's perspective. I think it's time to let it go....but hey, that's just my two cents... Gabriel > Trust me when I say this, the simpler you > make this, the better. "Powerful" is meaningless > in the context of programming - it has no > meaning. If you meant wxWindows/wxWidgets > are more feature-rich, then yes I agree - but > at what cost ? :) > > My 2c, > > cheers > James > -- > http://mail.python.org/mailman/listinfo/python-list > From apt.shansen at gmail.com Mon Feb 2 02:36:53 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sun, 1 Feb 2009 23:36:53 -0800 Subject: Import without executing module In-Reply-To: References: Message-ID: <7a9c25c20902012336w1efeae6dre2de690943cf085b@mail.gmail.com> > Maybe he can wrap the things he dont need inside > if __name__ == '__main__': > check. > -- > http://mail.python.org/mailman/listinfo/python-list > Yeah but he said he doesn't want to modify the file itself-- if he can modify the file this can all go away readily, yes. --S From sibteym at infotechsw.com Mon Feb 2 02:41:55 2009 From: sibteym at infotechsw.com (sibteym at infotechsw.com) Date: Mon, 2 Feb 2009 13:11:55 +0530 (IST) Subject: how to create data to dump into yaml file Message-ID: <37638.203.200.218.112.1233560515.INFOTECHENTL@webmail.infotechsw.com> hi I have to create a yaml file using my list of objects.shall i need to create a string using my objects and then load and dump that string or is there any other way to create the yaml file. i want a yaml file to be created from [Text, Author,......]in this format Text: - value1 - value2 - value 3 Author: name: bookName Thanks Sibtey Mehdi From taskinoor.hasan at csebuet.org Mon Feb 2 02:43:56 2009 From: taskinoor.hasan at csebuet.org (Taskinoor Hasan) Date: Mon, 2 Feb 2009 13:43:56 +0600 Subject: Import without executing module In-Reply-To: <7a9c25c20902012336w1efeae6dre2de690943cf085b@mail.gmail.com> References: <7a9c25c20902012336w1efeae6dre2de690943cf085b@mail.gmail.com> Message-ID: <79153a2e0902012343t338dd85di9132d0c14f1b964b@mail.gmail.com> Can anyone explain what is the necessity of executing whole script when importing. Isn't it enough to just put the module name in the namespace and execute when some function is called? On Mon, Feb 2, 2009 at 1:36 PM, Stephen Hansen wrote: > > Maybe he can wrap the things he dont need inside > > if __name__ == '__main__': > > check. > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > Yeah but he said he doesn't want to modify the file itself-- if he can > modify the file this can all go away readily, yes. > > --S > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From apt.shansen at gmail.com Mon Feb 2 02:50:36 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sun, 1 Feb 2009 23:50:36 -0800 Subject: Python package Management GUI - New Project on Sourceforge In-Reply-To: <4986A1B1.9070805@arimaz.com> References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> <497FAFE4.4040602@gmail.com> <83900549676010b8244969ece9319a78@preisshare.net> <4986A1B1.9070805@arimaz.com> Message-ID: <7a9c25c20902012350r37502a5by99a631ad3d7f686c@mail.gmail.com> > Well, isn't tkinter being removed? > (http://www.python.org/dev/peps/pep-3108/) PEP3108 isn't only about removals, but some renaming and reorganizations of certain packages / modules to be consistent within the standard library. In that section of PEP3108 they're talking about grouping tkinter modules together in a different way. That said... > So the user will have to install it anyways, I think wx is way better that > tkinter > from a user and a developer's perspective. I think it's time to let it > go....but hey, Honestly, I agree. There's a point to a meta-app like this being "universally available" and since Tkinter is almost always available, that's a boon. But Tkinter is a really, really poor choice in just about every other category of how you make your decision IMHO. If the OP wants to use a wxPython-based GUI, all power to him. If he wants his utility to get wide adoption he just needs to make sure he can get some binary installers; deps, rpms, windows .exe's, etc. That's not at all impossible to do. Just takes extra work. If he wants to do the work -- and have a good UI -- good for him. --S From berserker992 at gmail.com Mon Feb 2 02:51:22 2009 From: berserker992 at gmail.com (berserker992 at gmail.com) Date: Sun, 1 Feb 2009 23:51:22 -0800 (PST) Subject: Problem With py2exe and ConfigParser References: <8b776264-1a6f-4f75-9a06-2b68d908b2fe@p23g2000prp.googlegroups.com> <6um1i1FfqskrU1@mid.uni-berlin.de> Message-ID: <7fad9e49-df2e-46db-a3cc-6e5b9f55e773@q36g2000vbn.googlegroups.com> You can set an example? My English is bad, so I do not quite understand > > Hello, i use python 2.6 + PyQt4. > > I compile my main.pyw. It is compile, but don't run. In > > "index.exe.log" error log: > > >>>> ?File "index.pyw", line 100, in GetVal > >>>> ConfigParser.NoSectionError: No section: 'Main' > > >>>> Code line 92 to 104 this is class that uses ConfigParser lib: > >>>> class ConfigAcces: > >>>> ? ?def __init__(self): > >>>> ? ? ? ?self.cnf = ConfigParser() > >>>> ? ?def GetLibUrl(self): > >>>> ? ? ? ?self.cnf.read("config.ini") > >>>> ? ? ? ?return self.cnf.get("Main","lib_path") > >>>> ? ?def GetVal(self, p, key): > >>>> ? ? ? ?self.cnf.read("config.ini") > >>>> ? ? ? ?return self.cnf.get(p,key) > >>>> ? ?def SetVal(self, selection, option, NewVal): > >>>> ? ? ? ?self.cnf.read("config.ini") > >>>> ? ? ? ?self.cnf.set(selection,option,NewVal) > >>>> ? ? ? ?self.cnf.write(open("config.ini", "w")) > > > how do I fix this? > > By passing the right path for the configuration file? It's obviously not > found. > > Diez From jwalana at vsnl.net Mon Feb 2 02:52:51 2009 From: jwalana at vsnl.net (jwalana at vsnl.net) Date: Mon, 02 Feb 2009 12:52:51 +0500 Subject: Exception error when accessing the class variable at the termination of the program Message-ID: Hi All, Here is a sample piece of code with which I am having a problem, with Python version 2.4.4 class Person: Count = 0 # This represents the count of objects of this class def __init__(self, name): self.name = name print name, ' is now created' Person.Count += 1 def __del__(self): print self.name, ' is now deleted' Person.Count -= 1 if Person.Count == 0: print 'The last object of Person class is now deleted' else: print 'There are still', Person.Count, ' objects of class Person' x2 = Person("Krishna") del x2 When the above code is executed, it works properly. If the last statement del x2, is removed, then when the program terminates, this throws up an exception as shown below Krishna is now created Krishna is now deleted Exception exceptions.AttributeError: "'NoneType' object has no attribute 'Count' " in > ignored Can someone please explain why the exception happens in the case where there is no explicit del statement? Thanks Jana From mail at microcorp.co.za Mon Feb 2 02:53:50 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Mon, 2 Feb 2009 09:53:50 +0200 Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com><50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com><4981985B.4070108@wildenhain.de><783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com><0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com><6ul2ieFg1sraU1@mid.uni-berlin.de><73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> Message-ID: <018801c9850e$3e019fe0$0d00a8c0@hendrik> wrote: > > You, sir, should be programming in some language other than Python. Why? - Python is object oriented, but I can write whole systems without defining a single class. By analogy, if data hiding is added to language, I could write a whole system without hiding a single item. Conversely, the lack of data hiding is perceived as a weakness, and IMO harms the advocacy of the language - This is proven by your statement above, whereby you are driving a user away, simply because the language, in one small aspect, does not give him what he wants, and the tenor of this thread has been very much: "That's how it is - like it or lump it", and no amount of careful explanation of why people want the feature has cut any ice - It has all the time been countered with statements about how the proponents of private attributes "don't need it", (as if they are plain dumb), that an underscore convention is "just as good", (It isn't), that you could crack it if you really tried, (so what?), and other more specious reasons. This is IMO an arrogant attitude - Surely if "we are all adults here" we have to accept that the other man has as much right to get what he wants, as anybody else, and that his reasons are as valid as those of anybody else. Somehow I don't think that the way this thread has run, is the way to "win friends and influence people" - not positively, anyway. - Hendrik From mail at microcorp.co.za Mon Feb 2 02:57:23 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Mon, 2 Feb 2009 09:57:23 +0200 Subject: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') References: <20090127134145.24460.1190938528.divmod.quotient.2653@henry.divmod.com> <004e01c98095$f90f9440$0d00a8c0@hendrik><49855129.9070901@shopzeus.com> Message-ID: <018901c9850e$3eba4180$0d00a8c0@hendrik> "Steve Holden" wrote: > > My previous reply assumed you are running some UNIX-like operating > system. If you are on Windows then Jean-Paul's advice stands, as Windows > *does* allow several processes to listen on the same port and randomly > delivers incoming connections to one of the listening processes. > > I believe this is because Microsoft failed to understand the original > meaning of SO_REUSEADDR for their early TCP implementations, and > persisted with this ghastly error in the name of backwards > compatibility, justifying it by suggesting that listener pools could be > created. Or some such nonsense. Perhaps someone with more insight into > the development process could comment. It seems to me it's completely > bizarre. > > However, under Windows 2000 and later you should find there's an > SO_EXCLUSIVEADDRUSE flag which you can use to ensure a single listener - > see http://msdn.microsoft.com/en-us/library/ms740621(VS.85).aspx. No > need for separate locks. > Thanks Steve - I am not the OP, I was just curious as to why Jean-Paul was saying what he did - so the only reason I have not been bitten on windoze yet must be either because I am lucky, or because my server side stuff is linux and there is the occasional windows client. So I don't really listen on windows. "a pool of listeners" - just think of the fun one can have trying to keep state between them - would be a marvellous job if someone else is paying top dollar by the hour - I can just see the team growing as the need for new specialists are discovered as one goes along. :-) - Hendrik From apt.shansen at gmail.com Mon Feb 2 02:58:25 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sun, 1 Feb 2009 23:58:25 -0800 Subject: Import without executing module In-Reply-To: <79153a2e0902012343t338dd85di9132d0c14f1b964b@mail.gmail.com> References: <7a9c25c20902012336w1efeae6dre2de690943cf085b@mail.gmail.com> <79153a2e0902012343t338dd85di9132d0c14f1b964b@mail.gmail.com> Message-ID: <7a9c25c20902012358u60a5d594hef6c81fcdc437f4@mail.gmail.com> On Sun, Feb 1, 2009 at 11:43 PM, Taskinoor Hasan wrote: > Can anyone explain what is the necessity of executing whole script when > importing. Isn't it enough to just put the module name in the namespace and > execute when some function is called? I'm not sure if I'm going to explain this right-- so bear with me. The code: def something(other): return other + 1 Doesn't exist until that def statement is executed. "def", "class" and such are not magical and immediately register something somewhere. Its a statement that has to be executed to get a result, and that result is bound as an assignment to the name specified. Its not really all that different from: something = lambda other: other + 1 It can't pick through the top level instructions to determine what to execute if imported vs run, as every statement has the possibility of producing some binding of name to value and until you go and execute it you won't know. You may do something like: try: import blah except: blah = None You have to execute all of that to get a value for 'blah'. In Python, there's nothing really special about a function vs any other value. They are all objects that are assigned to a name in a given namespace. You can do dynamic things at the top level to result in different things being bound to the modules namespace based upon the statements and expressions evaluated. Does that make sense? If not someone else'll have to explain :) --Stephen From apt.shansen at gmail.com Mon Feb 2 03:23:55 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 2 Feb 2009 00:23:55 -0800 Subject: Membership of multiple items to a list In-Reply-To: <87myd51ouw.fsf@benfinney.id.au> References: <87myd51ouw.fsf@benfinney.id.au> Message-ID: <7a9c25c20902020023kdb4e97eh16137c078fd64a8@mail.gmail.com> On Sun, Feb 1, 2009 at 7:47 PM, Ben Finney wrote: > rdmurray at bitdance.com writes: > >> I don't even see Stephen Hansen's posts. My newsreader just shows >> the header and says "[HTML part not displayed]". > > Likewise. Yeah, I know HTML is bad on newsgroups. I didn't realize that when I installed FireGPG to sign messages while in Gmail that it started handling my html/plain text content differently. Oops. That said: Is S/MIME / OpenPGP readable on these various clients? There's no HTML, the text body is just encoded in base64. I haven't actually subscribed to a usenet newsgroup in eons upon eons. If its not readable as S/MIME then I'll switch to inline PGP... that's just a slightly terrible solution for other places I have to talk and I'll have to take extra care to remember to manually check the settings based upon where I'm talking. I'm re-sending this same message as the OpenPGP S/MIME attachment format -- just so test if its actually readable by news clients in general. I have absolutely no idea. Not touched a news client in years and years, as I said. Sorry for the inconvenience. --Stephen From apt.shansen at gmail.com Mon Feb 2 03:24:19 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 2 Feb 2009 00:24:19 -0800 (PST) Subject: Membership of multiple items to a list In-Reply-To: <87myd51ouw.fsf@benfinney.id.au> Message-ID: On Sun, Feb 1, 2009 at 7:47 PM, Ben Finney wrote: > rdmurray at bitdance.com writes: > >> I don't even see Stephen Hansen's posts. My newsreader just shows >> the header and says "[HTML part not displayed]". > > Likewise. Yeah, I know HTML is bad on newsgroups. I didn't realize that when I installed FireGPG to sign messages while in Gmail that it started handling my html/plain text content differently. Oops. That said: Is S/MIME / OpenPGP readable on these various clients? There's no HTML, the text body is just encoded in base64. I haven't actually subscribed to a usenet newsgroup in eons upon eons. If its not readable as S/MIME then I'll switch to inline PGP... that's just a slightly terrible solution for other places I have to talk and I'll have to take extra care to remember to manually check the settings based upon where I'm talking. I'm re-sending this same message as the OpenPGP S/MIME attachment format -- just so test if its actually readable by news clients in general. I have absolutely no idea. Not touched a news client in years and years, as I said. Sorry for the inconvenience. --Stephen -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 269 bytes Desc: OpenPGP digital signature URL: From nospam at nospam.com Mon Feb 2 03:29:24 2009 From: nospam at nospam.com (Gilles Ganault) Date: Mon, 02 Feb 2009 09:29:24 +0100 Subject: [2.5.1] Comparing dates? Message-ID: Hello I have data in an SQL database where one column contains a date formated as DD/MM/YYYYY. I need to select all rows where the date is before, say Feb 1st 2009, ie. 01/02/2009. Is there a command in Python that does this easily, or should I look into whatever date() function the SQL database offers? Thank you. From taskinoor.hasan at csebuet.org Mon Feb 2 03:42:34 2009 From: taskinoor.hasan at csebuet.org (Taskinoor Hasan) Date: Mon, 2 Feb 2009 14:42:34 +0600 Subject: Import without executing module In-Reply-To: <7a9c25c20902012358u60a5d594hef6c81fcdc437f4@mail.gmail.com> References: <7a9c25c20902012336w1efeae6dre2de690943cf085b@mail.gmail.com> <79153a2e0902012343t338dd85di9132d0c14f1b964b@mail.gmail.com> <7a9c25c20902012358u60a5d594hef6c81fcdc437f4@mail.gmail.com> Message-ID: <79153a2e0902020042k6a8db234id906ff5a773d131f@mail.gmail.com> On Mon, Feb 2, 2009 at 1:58 PM, Stephen Hansen wrote: > On Sun, Feb 1, 2009 at 11:43 PM, Taskinoor Hasan > wrote: > > Can anyone explain what is the necessity of executing whole script when > > importing. Isn't it enough to just put the module name in the namespace > and > > execute when some function is called? > > I'm not sure if I'm going to explain this right-- so bear with me. > > The code: > > def something(other): > return other + 1 > > Doesn't exist until that def statement is executed. "def", "class" and > such are not magical and immediately register something somewhere. Its > a statement that has to be executed to get a result, and that result > is bound as an assignment to the name specified. > > Its not really all that different from: > something = lambda other: other + 1 > > It can't pick through the top level instructions to determine what to > execute if imported vs run, as every statement has the possibility of > producing some binding of name to value and until you go and execute > it you won't know. You may do something like: > > try: > import blah > except: > blah = None > > You have to execute all of that to get a value for 'blah'. In Python, > there's nothing really special about a function vs any other value. > They are all objects that are assigned to a name in a given namespace. > You can do dynamic things at the top level to result in different > things being bound to the modules namespace based upon the statements > and expressions evaluated. > > Does that make sense? If not someone else'll have to explain :) It make sense :-). So my reasoning......let A is imported in B, i.e. name A is put in B's namespace. When we call something like A.a then the interpreter first resolve A in B's namespace, then to get a, it need to look up A's namespace. And there is no way to populate A's namespace without executing A, and as all statements, including 'def', 'class' etc., are treated in the same way, whole script need to be executed. So whether a script can be imported as module or not is mainly dependent on how the script is written and largely on the intention of the coder. > > > --Stephen > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From raykyoto at gmail.com Mon Feb 2 03:53:54 2009 From: raykyoto at gmail.com (Ray) Date: Mon, 2 Feb 2009 00:53:54 -0800 (PST) Subject: Import without executing module References: Message-ID: <0b9638e5-3e23-42c1-b358-0037944abe5b@s1g2000prg.googlegroups.com> Hi Stephen and everyone, On Feb 2, 4:36?pm, Stephen Hansen wrote: > > Maybe he can wrap the things he dont need inside > > if __name__ == '__main__': > > check. > > -- > >http://mail.python.org/mailman/listinfo/python-list > > Yeah but he said he doesn't want to modify the file itself-- if he can > modify the file this can all go away readily, yes. Thank you for your posts and your explanations; and yes, as you (Stephen) said here, I'd prefer not to modify it and use it as-is. Ideally, the original author could have separated the functions from the top-level code and I would just import the module with the functions. But that's whining since the hard work of writing the functions was already done and I'm very grateful for it; likewise, I'd like to use of the module unchanged. As there is no way around it, I'll look into ways of minimizing the number of changes and the "if" statement mentioned by Kottiyath would be my next step. Thank you all for the replies! Ray From apt.shansen at gmail.com Mon Feb 2 03:55:36 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 2 Feb 2009 00:55:36 -0800 Subject: is python Object oriented?? In-Reply-To: <018801c9850e$3e019fe0$0d00a8c0@hendrik> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> Message-ID: <7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com> >> >> You, sir, should be programming in some language other than Python. > > Why? - Python is object oriented, but I can write whole systems > without defining a single class. > By analogy, if data hiding is added to language, I could write a > whole system without hiding a single item. > Conversely, the lack of data hiding is perceived as a weakness, > and IMO harms the advocacy of the language - This is an alarming statement. Advocacy should advocate the language-- it must not define the language. If a fundamental principle of the language harms the advocacy of the language: then the problem is not with the language but the advocacy. If you are going to advocate a thing: advocate that thing. Don't try to change that thing into what it is not so as to make your advocacy the end-goal. One of the reasons I love Python is because its practical first. It begins with its license, which some people argue allows companies to steal effort from its developers to use for their own purposes without contributing back. The Python license is about empowering people to accomplish things, to do things. It goes further. Guido and the core developers ask real questions: would this add a burden to practical use, or would it hinder another practical use? > This is proven > by your statement above, whereby you are driving a user away, > simply because the language, in one small aspect, does not > give him what he wants, and the tenor of this thread has been > very much: "That's how it is - like it or lump it", and no amount > of careful explanation of why people want the feature has cut > any ice - I'm missing the careful explanation. What I've heard is that the lack of enforced encapsulation is "a danger". What I've heard is that people want it because they've been told they should want it and believe that. Why? Part of my lack of understanding might be because people couldn't read my previous messages because my mail client's configuration accidentally got fubar'd and I was sending HTML mail instead of plain text. But my question remains: Why do you need forced encapsulation? There have been no "careful explanations" to answer that, in my mind. And thus my response is: the practical possibility of needing access vastly outweights the theoretical situation that might go bad if encapsulation wasn't there. Why? Because in any real situation, IMHO, *forced* encapsulation is pointless. If you are writing end-level code, you can achieve forced encapsulation by simply not playing with anyones privates. If you are in a corporate environment who has rules about accessing privates written by another team for valid reasons, your policy to not do so should be enough or your review process should pick it up. If you are in an open source environment accepting patches from various people, you should have a clear policy about the subject if you think breaking encapsulation is never acceptable and refuse the patches. Those who have commit access and violate encapsulation anyways against your projects policy are problems that you clearly need to deal with. The problem is not the language at that point, its the contributor. > It has all the time been countered with statements > about how the proponents of private attributes "don't need it", > (as if they are plain dumb), They don't need it. No one has shown a *real* reason why. The only reasons provided are "its a DANGER" that someone "MIGHT DO BAD". That's not a real reason. If its your project that someone is doing bad in, this is a situation which can be *clearly* specified in a projects policy and coding standards and can be *trivially* tested for with simple static analysis in nearly all cases. The problem is the person and not the code then. There's *countless* other ways that person can do bad if you're allowing them to commit blindly anything into your project. If its your projet which someone else is using, and accessing your internals that are clearly private and not documented: its not your problem if they stab themselves in the foot. On the contrary, why in the name of all that is holy, do you care if they manipulate your internals at their own risk, at their own cost, and achieve something positive for them? How in any way does this hurt you? > that an underscore convention is > "just as good", (It isn't), Why isn't it? > that you could crack it if you really > tried, (so what?), Exactly.. so what? WHY is the convention not enough? What REAL situation is there that the lack of *forced* encapsulation but policy based encapsulation not enough? > Surely if "we are all adults here" we have to accept that the > other man has as much right to get what he wants, as > anybody else, and that his reasons are as valid as those of > anybody else. Yes., We're all consenting adults. But if one adult decides to make rules that the other doesn't agree to, is that consenting adults, or is that rape? I apologize for the use of the term, but "consenting adults" has particular connotations that seem to apply very well here, in the context of that expression. Forced encapsulation allows one party to make absolute rules and hold absolute authority over another party. If you believe that encapsulation should never be broken: do not break it. If your organization, corporation or project believes that encapsulation should never be broken: specify that it must not be done. Your review process (you do have one, right?) will pick it up and you can very quickly deal with the situation. Encapsulation is a very, very good thing in general: but it is a question of *design* and not *implementation*. Python allows EVERYONE who wants encapsulation to HAVE it. Not forced encapsulation, but encapsulation. If you're producing a product in Python on your own simple policy and trivial review (even -automated- review; it is NOT hard to tell that "other._private" is not "self._private") provides encapsulation. If you're making a library for others to use, there is no valid reason for you to care if they screw with your internals. Really. I just don't get the problem. It seems to me that people who want this in Python will never be happy *in* Python. Its a very deep fundamental feature that Python exposes everything it can, even things that are potentially dangerous like sys._getframe. Recently on Python-dev(note: I only lurk) someone was working on a debugger and they were told in that situation it was OK to access a private member of sys to achieve an end: exposing that internal to general use just had no value. That's the Python Way. People can dig into things, classes, functions, and screw around in wild ways if they want to. That *is* what Python is. 95% of code by 95% of people won't ever go there, but its there. To remove it means its *not* Python. --S From rNOSPAMon at flownet.com Mon Feb 2 03:59:16 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Mon, 02 Feb 2009 00:59:16 -0800 Subject: Extreme Yaro weirdness Message-ID: I'm running the following WSGI app under Yaro: def error(req): try: req.non_existent_key except: try: return cgitb.html(sys.exc_info()) except: return 'foo' The result of running this is 'foo'. In other words, the reference to the non-existent key generates an exception as expected, but then the generation of the traceback generates ANOTHER exception, which I would not have expected. If I add another TRY/EXCEPT block to capture this exception, the result is attached at the bottom of this message. It gets better. I get the same result whether I run under Apache/mod_wsgi or standalone using wsgi_ref. But if I add the following code to try to capture a Yaro request object so I can noodle around with it: def error(req): global req1 req1=req try: ... it makes the problem go away! But it ONLY makes the problem go away when running under wsgi_ref, not under Apache! The problem seems to be specific to Yaro. If I make an instance of an object and try to dereference a non-existent attribute, the initial traceback gets generated with no problem. Also, the Yaro code for Request.__getattr__ ultimately calls req.__dict__[attr]. If I make this call directly, the problem also goes away. I am quite baffled by this. Any suggestions on how to debug this would be much appreciated. Thanks, rg ---- Python 2.5: /usr/local/bin/python Mon Feb 2 00:54:33 2009 A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred. /www/sites/mcia.cc/files/wsgi/test.wsgi in error(req=) 212 except: 213 try: 214 return cgitb.text(sys.exc_info()) 215 except: 216 try: global cgitb = cgitb.text = global sys = sys.exc_info = /www/sites/cgitb.py in text((etype=, evalue=KeyError('non_existent_key',), etb=), context=5) 215 try: return linecache.getline(file, lnum[0]) 216 finally: lnum[0] += 1 217 vars = scanvars(reader, frame, locals) 218 219 rows = [' %s %s' % (file, call)] builtinvars = global scanvars = reader = frame = locals = {'req': } /www/sites/cgitb.py in scanvars(reader=, frame=, locals={'req': }) 82 if lasttoken == '.': 83 if parent is not __UNDEF__: 84 value = getattr(parent, token, __UNDEF__) 85 vars.append((prefix + token, prefix, value)) 86 else: value = builtingetattr = parent = token = 'non_existent_key' __UNDEF__ undefined /www/sites/mcia.cc/files/wsgi/yaro.py in __getattr__(self=, attr='non_existent_key') 215 elif attr == 'cookie' and not 'cookie' in self.__dict__: 216 self._load_cookie() 217 return self.__dict__[attr] 218 219 def _parse_query(self): self = self.__dict__ = {'_start_response': , 'content_length': '', 'content_type': '', 'environ': {'DOCUMENT_ROOT': '/www/sites/mcia.cc/html', 'GATEWAY_INTERFACE': 'CGI/1.1', 'HTTP_ACCEPT': 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plai n;q=0.8,image/png,*/*;q=0.5', 'HTTP_ACCEPT_ENCODING': 'gzip, deflate', 'HTTP_ACCEPT_LANGUAGE': 'en-us', 'HTTP_CACHE_CONTROL': 'max-age=0', 'HTTP_CONNECTION': 'keep-alive', 'HTTP_COOKIE': 'sid=55UGS64T', 'HTTP_HOST': 'mcia.cc', 'HTTP_REFERER': 'http://mcia.cc/wtest/menu', ...}, 'exc_info': None, 'extra_props': None, 'method': 'GET', 'query': {}, 'res': , 'start_response_called': False, ...} attr = 'non_existent_key' : 'non_existent_key' The above is a description of an error in a Python program. Here is the original traceback: Traceback (most recent call last): File "/www/sites/mcia.cc/files/wsgi/test.wsgi", line 214, in error return cgitb.text(sys.exc_info()) File "cgitb.py", line 217, in text vars = scanvars(reader, frame, locals) File "cgitb.py", line 84, in scanvars value = getattr(parent, token, __UNDEF__) File "/www/sites/mcia.cc/files/wsgi/yaro.py", line 217, in __getattr__ return self.__dict__[attr] KeyError: 'non_existent_key' From pranny at gmail.com Mon Feb 2 04:05:59 2009 From: pranny at gmail.com (pranav) Date: Mon, 2 Feb 2009 01:05:59 -0800 (PST) Subject: Monitor Internet connections in XP/Vista Message-ID: Hi Folks, I am designing a project for Windows XP/Vista, one part of which is a background process that monitors internet connections. If the user tries to connect to any particular site, say myDummySite.com in then some actions are taken, based on fixed policies. This can be thought of a mini firewall. I am sure there must be some good libraries for this purpose. I need the names of those libraries. Thanks, Pranav Prakash From bignose+hates-spam at benfinney.id.au Mon Feb 2 04:06:02 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Mon, 02 Feb 2009 20:06:02 +1100 Subject: [2.5.1] Comparing dates? References: Message-ID: <87bptl1a4l.fsf@benfinney.id.au> Gilles Ganault writes: > I have data in an SQL database where one column contains a > date formated as DD/MM/YYYYY. > > I need to select all rows where the date is before, say Feb 1st > 2009, ie. 01/02/2009. The Python data types for date and time are in the ?datetime? module . Create a ?datetime? object for each value you want, then compare them. To create a ?datetime? value from a string, use ?datetime.strptime? (new in Python 2.5). -- \ ?Holy knit one purl two, Batman!? ?Robin | `\ | _o__) | Ben Finney From sjmachin at lexicon.net Mon Feb 2 04:17:32 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 2 Feb 2009 01:17:32 -0800 (PST) Subject: Comparing dates? References: Message-ID: <712e7c7b-4728-4e43-acad-bd80e9598dae@z27g2000prd.googlegroups.com> On Feb 2, 7:29?pm, Gilles Ganault wrote: > Hello > > ? ? ? ? I have data in an SQL database where one column contains a date > formated as DD/MM/YYYYY. > > I need to select all rows where the date is before, say Feb 1st 2009, > ie. 01/02/2009. > > Is there a command in Python that does this easily, or should I look > into whatever date() function the SQL database offers? It would help if you told us: (1) Which database software (2) What type that column was declared to be in the CREATE TABLE statement (3) Whether you have used the Python DB API on a database before (4) Whether you have used a stand-alone SQL query tool on a database before (5) How you came to the conclusion that one column contains a date formatted as dd/mm/yyyy ... Only one? Are there other date-containing columns in the same table or other tables in the database? If so, how are they formatted? Basically, you are going to have to execute some SQL like: SELECT * FROM the_table WHERE the_date < '2009-02-01' which a reasonable chance of being syntactically valid and giving the correct answer, if the column type is DATETIME/DATE/TIMESTAMP/similar. If it's CHAR/VARCHAR/TEXT/CHARACTER/similar, then it's going to be harder, and will depend on what database software it is. A really silly question: have you asked the database administrator (DBA)? From adelle at akemi.com.au Mon Feb 2 04:25:41 2009 From: adelle at akemi.com.au (Adelle Hartley) Date: Mon, 02 Feb 2009 20:25:41 +1100 Subject: English-like Python In-Reply-To: <49773E43.3050101@strout.net> References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> <49761EE6.4070306@strout.net> <5ea322bb-86f9-4b5c-94ec-e53e2f7cf193@r15g2000prh.googlegroups.com> <49773E43.3050101@strout.net> Message-ID: <4986BC15.6030703@akemi.com.au> Joe Strout wrote: > Aaron Brady wrote: > >> Where functions are first-class objects, a bare function object isn't >> distinguishable either from its call. > > That depends not on whether functions are first-class objects, but on > the *syntax* of function invocation vs. function reference. It just so > happens than in Python, the syntax for the latter is the bare function > identifier. But it wouldn't have to be -- you could use "@foo" or > "{foo}" or "ref foo" or (as in RB) "AddressOf foo" or any number of > other alternatives to accomplish the same thing, and functions would > still be first-class objects. > > I'll grant that having any such syntax makes them *odd* first-class > objects, since all other objects are referred to with a naked > identifier, and invoked (if they are callable) with some other syntax. > It'd be weird and inconsistent to have functions turn that around. But, > despite being inconsistent, it might still be sensible, based on the > observation that we generally need to invoke methods a lot more often > than we need to get a reference to them. I propose the following syntax for invoking foo: Computer, please foo that for me. I know Jean Luc would just say "Computer, foo that" but I think that just because it's a computer doesn't mean we shouldn't be polite. I have found English-like syntax to be useful in filtering sets. Eg. parents = people.that.have.children This looks nicer (at least to my eye) in languages that don't require parentheses everywhere, but that's entirely superficial. One way that I've thought it might be possible to avoid the problem of ambiguity in identifying parameters is to not use them. For example, instead of display(people.that.have.children) why not display.people.that.have.children or even display.a.list.of.people.that.have.children I think this could only work within a confined domain, since "display" needs to know about all of the things that could be displayed. Regarding ambiguities. The way NL users resolve them is often to ask their interlocutor for clarification. The problem for a program is that the programmer isn't around to answer questions when the answer is needed most - the problem of programming is in defining the desired behavior ahead of time. If we are ever to use English as a programming language, I think the "compiler" would need to ask us clarifying questions at compile time and amend or annotate the source based on our answers. The resulting source code may be a rarefied version of English or more like a "traditional" programming language, but our primary means of communicating with the computer could be more natural. Back in the 90's I used to say things to my computer like Computer, please Label this command button "Parents". I don't think it much of a stretch to have it respond to When the user clicks this button, bring up a list of all the people that have children. by generating the code display.a.list.of.people.that.have.children and to attach it to the right event. But even that level of apparent naturalness belies a problem that other posters in this thread have already raised: There are so many ways of saying the same thing, yet the computer will only ever understand a subset of them, making it harder to learn the "natural" system than any artificial programming language. I had at one time defined a number of voice commands for designing a form: Place a here. Place a > Move that ... Once I "got into it" I was pretty productive with it, but the experience is not unlike playing with text-based adventure games for the first time. That is, you know what you want the program to do, but you either don't know how to say it in a way that the program will understand or you know the program well enough to know that there is no way of directly representing what you want to do within the program's narrow grasp of English. I don't think the problem is fundamentally unsolvable, only that the scale of the problem is quite large, like writing a dictionary. Adelle. From s.selvamsiva at gmail.com Mon Feb 2 04:29:27 2009 From: s.selvamsiva at gmail.com (S.Selvam Siva) Date: Mon, 2 Feb 2009 14:59:27 +0530 Subject: importing module-performance Message-ID: Hi all, I have a small query, Consider there is a task A which i want to perform. To perform it ,i have two option. 1)Writing a small piece of code(approx. 50 lines) as efficient as possible. 2)import a suitable module to perform task A. I am eager to know,which method will produce best performance? -- Yours, S.Selvam -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Mon Feb 2 04:37:08 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 2 Feb 2009 01:37:08 -0800 Subject: Exception error when accessing the class variable at the termination of the program In-Reply-To: References: Message-ID: <50697b2c0902020137h7afabb1bt56dbea34a8db6246@mail.gmail.com> On Sun, Feb 1, 2009 at 11:52 PM, wrote: > Hi All, > > Here is a sample piece of code with which I am having a problem, with Python version 2.4.4 > > class Person: > Count = 0 # This represents the count of objects of this class > > def __init__(self, name): > self.name = name > print name, ' is now created' > Person.Count += 1 > > def __del__(self): > print self.name, ' is now deleted' > Person.Count -= 1 > if Person.Count == 0: > print 'The last object of Person class is now deleted' > else: > print 'There are still', Person.Count, ' objects of class Person' > > x2 = Person("Krishna") > del x2 > > When the above code is executed, it works properly. > > If the last statement del x2, is removed, then when the program terminates, this throws up an exception as shown below > > Krishna is now created > Krishna is now deleted > Exception exceptions.AttributeError: "'NoneType' object has no attribute 'Count' > " in > ignored > > Can someone please explain why the exception happens in the case where there is no explicit del statement? Without the `del`, the reference count of x2 remains >0 and so is not deleted until the program ends. This affects when __del__ is executed, which matters greatly. >From the section on __del__ on http://www.python.org/doc/2.3.5/ref/customization.html : Warning: Due to the precarious circumstances under which __del__() methods are invoked, exceptions that occur during their execution are ignored, and a warning is printed to sys.stderr instead. Also, when __del__() is invoked in response to a module being deleted (e.g., when execution of the program is done), ***other globals referenced by the __del__() method may already have been deleted***. For this reason, __del__() methods should do the absolute minimum needed to maintain external invariants. [etc., emphasis mine] Since without the `del`, __del__ is only called at the end of the program, Person and/or Count may have already been GC-ed by the time __del__ is called (the order objects are GC-ed in is a bit unpredictable), hence the error you get which is saying, in a slightly obtuse way, that Person has been GC-ed already. As the Warning states, __del__ shouldn't be relied upon to do fancy stuff like you're having it do. You would be better off using an explicit finalizer method in this case, like .close() for file objects. For example: try: x2 = Person("Krishna") #do stuff with x2 finally: x2.delete() #causes count to be decremented Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From duncan.booth at invalid.invalid Mon Feb 2 04:37:21 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 2 Feb 2009 09:37:21 GMT Subject: Exception error when accessing the class variable at the termination of the program References: Message-ID: jwalana at vsnl.net wrote: > Can someone please explain why the exception happens in the case > where there is no explicit del statement? When Python is ecleaning up as it exits, it clears all the global variables in each module by setting them to None. This happens in an arbitrary and unpredictable order: in this particular case it set Person to None before setting x2 to None. If you must have a __del__ method on a class then you should take care not to access any globals from inside the __del__ method (or any function it calls). Alternatively you could just catch and ignore any exceptions thrown from your __del__ method. In the example you gave, provided you never subclass Person you could use self.__class__.Count to access your class variable. However in many cases you'll probably find that a much better solution is to use weak references. e.g. a WeakValueDictionary mapping id(self) to self: from weakref import WeakValueDictionary class Person: _instances = WeakValueDictionary() def __init__(self, name): self.name = name self._instances[id(self)] = self print name, 'is now created' @property def Count(self): return len(self._instances) def __del__(self): print self.name, 'is now deleted' if self.Count==0: print 'The last object of Person class is now deleted' else: print 'There are still', self.Count, 'objects of class Person' x2 = Person('Krishna') # del x2 -- Duncan Booth http://kupuguy.blogspot.com From clp2 at rebertia.com Mon Feb 2 04:41:45 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 2 Feb 2009 01:41:45 -0800 Subject: importing module-performance In-Reply-To: References: Message-ID: <50697b2c0902020141i35e3acd6y4bbd40f75fc89244@mail.gmail.com> On Mon, Feb 2, 2009 at 1:29 AM, S.Selvam Siva wrote: > Hi all, > I have a small query, > Consider there is a task A which i want to perform. > > To perform it ,i have two option. > 1)Writing a small piece of code(approx. 50 lines) as efficient as possible. > 2)import a suitable module to perform task A. > > > I am eager to know,which method will produce best performance? A. Your question seems much too vague to answer. B. Premature optimization is the root of all evil. In all likelihood, the time taken by the `import` will be absolutely trivial compared to the rest of the script, so don't bother micro-optimizing ahead of time; write readable code first, then worry about optimization once it's working perfectly. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From banaouas.medialog at wanadoo.fr Mon Feb 2 04:46:41 2009 From: banaouas.medialog at wanadoo.fr (m.banaouas) Date: Mon, 02 Feb 2009 10:46:41 +0100 Subject: ElementTree and clone element toot Message-ID: <4986bfd7$0$9385$ba4acef3@news.orange.fr> Hi all, Working with the ElementTree module, I looked for clone element function but not found such tool: def CloneElment(fromElem, destRoot = None) fromElem is the element to clone destRoot is the parent element of the new element ; if None so the new element will be child of fromElem parent. The clone operation is recursive to make it process all subtree of the element to clone. here is my first implementation: def CloneElement(fromElem, destRoot = None): if destRoot == None: fromRoot = ET.ElementTree(fromElem).getroot() destRoot = fromRoot destElem = destRoot.makeelement(fromElem.tag, fromElem.attrib) destRoot.append(destElem) destElem.text = fromElem.text for e in fromElem.findall('*'): CloneElement(e, destElem) # this function works fine only if destRoot parameter is defined by the caller context. The problem is about retreiving parent element: I didn't found any way to determine the parent element of an element "elem" by asking elem itself! and ET.ElementTree(fromElem).getroot() is wrong because it returns fromElem itself, not its parent. Thanks for any help. From bruno.42.desthuilliers at websiteburo.invalid Mon Feb 2 04:59:59 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 02 Feb 2009 10:59:59 +0100 Subject: is python Object oriented?? In-Reply-To: References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <873af1vkgn.fsf@benfinney.id.au> Message-ID: <4986c41f$0$3659$426a34cc@news.free.fr> Michael Torrie a ?crit : > Steve Holden wrote: >> You can think what you like, but there is a fundamental difference >> between methods of a class and functions of a module. Until you >> appreciate that you will likely make mistakes. Don't worry, though, we >> all learn from our mistakes. > > And this fundamental difference is? That a method is bound to a class and (usually) an instance of this class. > From what I can tell an instance method is an object that encapsulates > the function object in a closure s/closure/object/ > that makes sure it has a reference to > "self." the method object is instanciated by the function object itself when it is looked up upon a class or instance (thanks to the descriptor protocol). It (the method object) stores the function, the class and (if bound) the instance as attributes, and it's __call__ method takes care of calling the function with the instance as first positional argument. > I know that you dynamically add functions to objects creating > methods dynamically, by using new.instancemethod or something. Or simply by manually invoking the descriptor protocol: def func(self): print "self is", self class Foo(object): pass f = Foo() f.func = func.__get__(f, type(f)) print dir(f.func) > > This seems to indicate to me that there are functions and there are > functions. Methods are in fact functions, just with a callable wrapper > around them. Methods *are* the callable wrapper around functions - so they can't be functions themselves. From this POV, the functions wrapped by methods are actually the *implementation* of the method. From ove.svensson at jeppesen.com Mon Feb 2 05:01:12 2009 From: ove.svensson at jeppesen.com (Ove Svensson) Date: Mon, 02 Feb 2009 11:01:12 +0100 Subject: Get thread pid References: <1f4ff371-447d-4eca-8c51-e73eb10ed8c5@a12g2000pro.googlegroups.com> <31508b6d-bebb-45e6-b57c-525d370e22c0@r37g2000prr.googlegroups.com> Message-ID: <9g8wopuphz.fsf@overberg.jeppesensystems.com> Alejandro writes: > On Jan 30, 1:40?pm, Christian Heimes wrote: >> May I ask why you want to get the TID? > > htop shows the TID of each thread. Knowing the TID allows me to know > which thread is hogging the CPU. If there is a better way to do this, > or there is something fundamentally wrong with this approach, please > let me know. > > Alejandro. Assuming we are talking about a posix (pthread) architecture, you can't really say anything about the thread id (TID). Pthreads identifies each thread with the anonymous type pthread_t. If you want to write a portable application, you must not assume anything regarding the real type. It could be an integer, pointer, struct or something else. Just because some operating systems use an integer for the pthread_t doesn't mean that others do the same. It is true that the operating system must have some way to identify each thread (within each process), but it is not visible or accessible to the application. If you have a threading *framework* on top of pthreads, which uses some TID, that is then either purely an artificial id or a non-portable architecture specific access to the operating system id. For example, python thread.get_ident() returns the `thread identifier' of the current thread. That TID can be *anything*. You must not assume that id has any meaning (other than being unique per thread). The python class threading.Thread has methods setName() and getName() for setting and fetching the *name* of a thread. That is a pure application name and has nothing to do with the id used by the operating system. The reason that python modules thread and threading doesn't return any real TID is simply that there isn't any TID that it can return. At least not in any portable way. If you find a way to get to the real TID, that will be specific to your architecture. If htop (or any other application) returns a TID, that is either artificial or architecture specific. From clp2 at rebertia.com Mon Feb 2 05:01:45 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 2 Feb 2009 02:01:45 -0800 Subject: how to create data to dump into yaml file In-Reply-To: <37638.203.200.218.112.1233560515.INFOTECHENTL@webmail.infotechsw.com> References: <37638.203.200.218.112.1233560515.INFOTECHENTL@webmail.infotechsw.com> Message-ID: <50697b2c0902020201p3ce5879bnd9bf1c10ec6d0756@mail.gmail.com> On Sun, Feb 1, 2009 at 11:41 PM, wrote: > hi > I have to create a yaml file using my list of objects.shall i need to > create a string using my objects and then load and dump that string or > is there any other way to create the yaml file. > > i want a yaml file to be created from [Text, Author,......]in this format > Text: > - value1 > - value2 > - value 3 > Author: > name: bookName The PyYAML library is available on http://pyyaml.org/ Also, since JSON is essentially a subset of YAML, you could use the `json` module (http://docs.python.org/library/json.html) in the Python std lib, albeit with differently formatted results. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From s.selvamsiva at gmail.com Mon Feb 2 05:11:56 2009 From: s.selvamsiva at gmail.com (S.Selvam Siva) Date: Mon, 2 Feb 2009 15:41:56 +0530 Subject: importing module-performance In-Reply-To: <50697b2c0902020141i35e3acd6y4bbd40f75fc89244@mail.gmail.com> References: <50697b2c0902020141i35e3acd6y4bbd40f75fc89244@mail.gmail.com> Message-ID: On Mon, Feb 2, 2009 at 3:11 PM, Chris Rebert wrote: > On Mon, Feb 2, 2009 at 1:29 AM, S.Selvam Siva > wrote: > > Hi all, > > I have a small query, > > Consider there is a task A which i want to perform. > > > > To perform it ,i have two option. > > 1)Writing a small piece of code(approx. 50 lines) as efficient as > possible. > > 2)import a suitable module to perform task A. > > > > > > I am eager to know,which method will produce best performance? > > A. Your question seems much too vague to answer. > B. Premature optimization is the root of all evil. In all likelihood, > the time taken by the `import` will be absolutely trivial compared to > the rest of the script, so don't bother micro-optimizing ahead of > time; write readable code first, then worry about optimization once > it's working perfectly. > > Cheers, > Chris > -- > Follow the path of the Iguana... > http://rebertia.com Thank you Chris, I faced a optimization problem as follow, For fuzzy string comparison initially i used 15 lines of code which compares a word with 29,000 words in a list .For each set of words compared, the 15-line code produce number of differences characters of the two words. But when i used python-levenshtein module for same reason it has run faster than the old method.This invoked me to raise that query. Now i understood that, it is not an issue of importing the module/writing the code, but the problem must be with my 15-line code. -- Yours, S.Selvam -------------- next part -------------- An HTML attachment was scrubbed... URL: From bruno.42.desthuilliers at websiteburo.invalid Mon Feb 2 05:12:52 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 02 Feb 2009 11:12:52 +0100 Subject: is python Object oriented?? In-Reply-To: <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> Message-ID: <4986c724$0$10268$426a74cc@news.free.fr> thmpsn.m.k at gmail.com a ?crit : (snip) > Anyway, it doesn't matter. We're losing the point here. The point is > that language support for private access, by disallowing user access > to private data, provides an unambiguous information hiding mechanism > which encourages encapsulation. Python's approach, however, which is > only a naming convention rather than a language feature, merely TRUSTS > the programmer not to break encapsulation. And sure, if we're all good > programmers, everything will go well and we'll end up with an > organized application. But the danger is still there: at any given > time, we COULD break encapsulation! Oh, my, What a shock! What a nightmare. Thanks, thanks thmpsn for opening our eyes. How can we have lived so many years with this permanent danger, and yet managed to write working, robust programs, I really wonder. Good God, we really need to fix this immediatly, because obviously, TRUSTING the programmer JUST CANT WORK. Or can it ? this-dead-horse-has-been-beaten-to-hell-and-back-pity-the-poor-animal-ly'yrs From cd at okunah.de Mon Feb 2 05:14:25 2009 From: cd at okunah.de (Christof Donat) Date: Mon, 02 Feb 2009 11:14:25 +0100 Subject: what IDE is the best to write python? References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> Message-ID: Hi, > Just to register a contrary opinion: I *hate* syntax highlighting With vim you simply don't turn it on. Would that be OK for you? Christof From bruno.42.desthuilliers at websiteburo.invalid Mon Feb 2 05:15:24 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 02 Feb 2009 11:15:24 +0100 Subject: is python Object oriented?? In-Reply-To: References: <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <4985DC6F.4030106@holdenweb.com> Message-ID: <4986c7bc$0$10268$426a74cc@news.free.fr> Rhodri James a ?crit : > On Sun, 01 Feb 2009 17:31:27 -0000, Steve Holden > wrote: > >> Stephen Hansen wrote: >>> [...] >>> don't play with anyone else's >>> privates. >>> >> A good rule in life as well as programming. > > Unless, of course, you're both consenting adults. > > What? Someone had to say it! > Indeed. Thanks for this useful clarification !-) From asmodai at in-nomine.org Mon Feb 2 05:18:48 2009 From: asmodai at in-nomine.org (Jeroen Ruigrok van der Werven) Date: Mon, 2 Feb 2009 11:18:48 +0100 Subject: what IDE is the best to write python? In-Reply-To: <531189.66795.qm@web36504.mail.mud.yahoo.com> References: <531189.66795.qm@web36504.mail.mud.yahoo.com> Message-ID: <20090202101848.GZ99614@nexus.in-nomine.org> -On [20090201 15:18], Craig (fasteliteprogrammer at yahoo.com) wrote: >eclipse With the pydev plugin of course. Personally I prefer to just use vim and (i)python. But at work I am using Eclipse with pydev as well. -- Jeroen Ruigrok van der Werven / asmodai ????? ?????? ??? ?? ?????? http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B Earth to earth, ashes to ashes, dust to dust... From thorsten at thorstenkampe.de Mon Feb 2 05:36:48 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Mon, 2 Feb 2009 11:36:48 +0100 Subject: what IDE is the best to write python? References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> Message-ID: * Christof Donat (Mon, 02 Feb 2009 11:14:25 +0100) > > Just to register a contrary opinion: I *hate* syntax highlighting > > With vim you simply don't turn it on. Would that be OK for you? No. Even the /possibility/ of having syntax highlighting would indicate wimpness and thus humiliate me. Thorsten From w.richert at gmx.net Mon Feb 2 05:42:23 2009 From: w.richert at gmx.net (Willi Richert) Date: Mon, 2 Feb 2009 11:42:23 +0100 Subject: what IDE is the best to write python? In-Reply-To: <20090202101848.GZ99614@nexus.in-nomine.org> References: <531189.66795.qm@web36504.mail.mud.yahoo.com> <20090202101848.GZ99614@nexus.in-nomine.org> Message-ID: <200902021142.23513.w.richert@gmx.net> Hi, I used eclipse/pydev quite some time. What pulled me back into the arms of emacs was: - ability to save bookmarks (meaning a point in a file) at all the keystrokes. Never found out how to do that in eclipse. In emacs I have now all the times "j" save at the current working position, "f" at the last failure I have to work on, and so on. - just faster then pydev. Once pydev tries to "understand" your python code (refactoring) you can go and get a coffee - ecb, tabbar, psvn provide the same functionality of eclipse you use in everyday. Of course, it takes some time to use emacs. But it pays back with a nice Python integration and the advantage to customize everything you want. wr On Montag, 2. Februar 2009 11:18:48 Jeroen Ruigrok van der Werven wrote: > -On [20090201 15:18], Craig (fasteliteprogrammer at yahoo.com) wrote: > >eclipse > > With the pydev plugin of course. > > Personally I prefer to just use vim and (i)python. But at work I am using > Eclipse with pydev as well. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tino at wildenhain.de Mon Feb 2 05:45:21 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Mon, 02 Feb 2009 11:45:21 +0100 Subject: key capture In-Reply-To: <72218f020902012244g75593286x83f3157c0379a8e0@mail.gmail.com> References: <72218f020902012244g75593286x83f3157c0379a8e0@mail.gmail.com> Message-ID: <4986CEC1.6060209@wildenhain.de> Hi, swamynathan wrote: > hello, > im making a virtual piano in python where on key stroke a wav is played > from a location > now to implement a fully functional piano i need to have multiple key > stroke captures ie if 2 or 3 keys pressed then the function which > playes the wav is called with 3 parameters > how to implement this or any other suggestion(i was asked to try multi > threading which dint seem optimal) Are you trying to do this with a computer keyboard or with an attached midi or usb music keybord? If the former, you are probably w/o luck because afaik there is no way to track the event of having random keys pressed the same time. (Last time I did it was with a real C=64 where you have access to the key matrix) If you manage to receive the keypress events, multithreading is probably easiest to do but it really depends on the way you play the sounds - at least the playback needs to be asynchronously so you can catch note-on, note-off events during playback. Good luck Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From deets at nospam.web.de Mon Feb 2 05:58:19 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 02 Feb 2009 11:58:19 +0100 Subject: Problem With py2exe and ConfigParser References: <8b776264-1a6f-4f75-9a06-2b68d908b2fe@p23g2000prp.googlegroups.com> <6um1i1FfqskrU1@mid.uni-berlin.de> <7fad9e49-df2e-46db-a3cc-6e5b9f55e773@q36g2000vbn.googlegroups.com> Message-ID: <6uo1ubFgdclfU1@mid.uni-berlin.de> berserker992 at gmail.com wrote: > > You can set an example? My English is bad, so I do not quite > understand You need to give a proper path to the config.ini. It's not found, which most probably occurs because you give a relative path ("config.ini") but that doesn't work because the current working directory has a different value from what it has when you run the problem differently. So, you need to give a full path. Diez From nospam at nospam.com Mon Feb 2 06:07:18 2009 From: nospam at nospam.com (Gilles Ganault) Date: Mon, 02 Feb 2009 12:07:18 +0100 Subject: [2.5.1] Comparing dates? References: <87bptl1a4l.fsf@benfinney.id.au> Message-ID: <5tkdo4l21dkm9kgv4ra4pftker89odebfu@4ax.com> On Mon, 02 Feb 2009 20:06:02 +1100, Ben Finney wrote: >The Python data types for date and time are in the ?datetime? module >. Create a >?datetime? object for each value you want, then compare them. Thanks guys. For those interested, here's how to perform the conversion from DD/MM/YYYY to YYYY-MM-DD: ===== import datetime connection = datetime.datetime.strptime("21/02/2008", "%d/%m/%Y").strftime("%Y-%m-%d") print connection ===== From mail at microcorp.co.za Mon Feb 2 06:13:42 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Mon, 2 Feb 2009 13:13:42 +0200 Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com><0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com><6ul2ieFg1sraU1@mid.uni-berlin.de><73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com> Message-ID: <003d01c98527$d9ea4ec0$0d00a8c0@hendrik> "Stephen Hansen" wrote: 8<----------- arguments for the status quo ------ > > I'm missing the careful explanation. What I've heard is that the lack > of enforced encapsulation is "a danger". What I've heard is that > people want it because they've been told they should want it and > believe that. Why? > > Part of my lack of understanding might be because people couldn't read > my previous messages because my mail client's configuration > accidentally got fubar'd and I was sending HTML mail instead of plain > text. But my question remains: Why do you need forced encapsulation? > > There have been no "careful explanations" to answer that, in my mind. > And thus my response is: the practical possibility of needing access > vastly outweights the theoretical situation that might go bad if > encapsulation wasn't there. Why? Because in any real situation, IMHO, > *forced* encapsulation is pointless. > > If you are writing end-level code, you can achieve forced > encapsulation by simply not playing with anyones privates. If you are > in a corporate environment who has rules about accessing privates > written by another team for valid reasons, your policy to not do so > should be enough or your review process should pick it up. If you are > in an open source environment accepting patches from various people, > you should have a clear policy about the subject if you think breaking > encapsulation is never acceptable and refuse the patches. Those who > have commit access and violate encapsulation anyways against your > projects policy are problems that you clearly need to deal with. The > problem is not the language at that point, its the contributor. > > > > It has all the time been countered with statements > > about how the proponents of private attributes "don't need it", > > (as if they are plain dumb), > > They don't need it. No one has shown a *real* reason why. The only Repeating it, (despite my assertion lately in another thread) does not make it true - what follows is simply an opinion on how to solve the problem "by management", instead of providing a different tool. > reasons provided are "its a DANGER" that someone "MIGHT DO BAD". > That's not a real reason. If its your project that someone is doing > bad in, this is a situation which can be *clearly* specified in a > projects policy and coding standards and can be *trivially* tested for > with simple static analysis in nearly all cases. The problem is the > person and not the code then. There's *countless* other ways that > person can do bad if you're allowing them to commit blindly anything > into your project. > > If its your projet which someone else is using, and accessing your > internals that are clearly private and not documented: its not your > problem if they stab themselves in the foot. On the contrary, why in > the name of all that is holy, do you care if they manipulate your > internals at their own risk, at their own cost, and achieve something > positive for them? How in any way does this hurt you? > > > > that an underscore convention is > > "just as good", (It isn't), > > Why isn't it? Because it needs human intervention. > > > that you could crack it if you really > > tried, (so what?), > > Exactly.. so what? WHY is the convention not enough? What REAL > situation is there that the lack of *forced* encapsulation but policy > based encapsulation not enough? > See human intervention above - and as for "real, forced data hiding" - have you ever coded anything that produced a segmentation fault? I wonder why the designers of processors do such silly things as having user and supervisor modes in the hardware - according to your arguments a code review would solve the problem, and then they could use the silicon saved to do other usefull stuff. - then any process could use any instruction, and it would be all right. - easy to manage out of the project - you just have to scan the object code for op codes that you have decided are dangerous (for whatever stupid reason). Another example out of the processor world is the fact that some modern processors actually force a process to keep in its own memory. What temerity! Who do these idiots think they are to try to keep "me" from accessing "your" memory - after all, I have a good reason - (I'm inquisitive) This is of course rather more difficult to pick up in a code review, as I could easily calculate the address, which makes it not immediately apparent that I will access something not belonging to me. And seeing that Python is not dynamic at all, there is no analogy here... > > Surely if "we are all adults here" we have to accept that the > > other man has as much right to get what he wants, as > > anybody else, and that his reasons are as valid as those of > > anybody else. > > Yes., We're all consenting adults. > > But if one adult decides to make rules that the other doesn't agree > to, is that consenting adults, or is that rape? I apologize for the > use of the term, but "consenting adults" has particular connotations > that seem to apply very well here, in the context of that expression. > > Forced encapsulation allows one party to make absolute rules and hold > absolute authority over another party. > I do not agree with this. If _I_ write a module, and _I_ use forced encapsulation for _my_ purposes ( however misguided you might think I am) then how does that affect _you_? Even if I release the thing into the wild - you do not have to use it if you feel you really *must* muck around with the equivalent of Steve D'A's example of the length of a builtin - you could write your own, or fork what I have done. - It seems that by denying me the use of such a feature, you are the one trying to make absolute rules, for *your* benefit - *you* want to use *my* stuff, on *your* terms, without having to bother to put any effort into it. 8<----- repeat of "code review cures all" argument ------ > Really. I just don't get the problem. It seems to me that people who > want this in Python will never be happy *in* Python. Its a very deep > fundamental feature that Python exposes everything it can, even things > that are potentially dangerous like sys._getframe. Recently on > Python-dev(note: I only lurk) someone was working on a debugger and > they were told in that situation it was OK to access a private member > of sys to achieve an end: exposing that internal to general use just > had no value. That's the Python Way. People can dig into things, > classes, functions, and screw around in wild ways if they want to. > That *is* what Python is. 95% of code by 95% of people won't ever go > there, but its there. To remove it means its *not* Python. Now there are a LOT of dicey statements in the above passionate plea - python is a language, and not a philosophy, but I won't go into that, as that would lead off onto a tangent, of which there have been a surfeit in this thread. But this needs addressing: Nobody is saying that "Python" should change the way "Python" exposes stuff - All that is being requested that *I* should be allowed to use python to expose as much of *my* class as *I* deem fit, for *my* purposes. And some form of "private" keyword would do that nicely, thank you, and keep the current "public" default unchanged. Now this is from a user perspective - It may prove to be difficult, if not impossible, to implement in CPython. I just don't know enough details of the implementation to be able to tell. Maybe what is needed is some form of *Interpreter* vs. *User* state, analogous to what is done in the hardware, with defined, "code reviewable, testable for", procedures for switching between one and the other. - Hendrik From digitig at gmail.com Mon Feb 2 06:14:10 2009 From: digitig at gmail.com (Tim Rowe) Date: Mon, 2 Feb 2009 11:14:10 +0000 Subject: what IDE is the best to write python? In-Reply-To: References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> Message-ID: 2009/2/1 MattBD : > Really it depends what you are doing. Some languages are very tightly > integrated with an IDE, such as MS Visual C#, and as far as I can see > it would be extremely difficult, if not impossible to use a text > editor with that language. Why so? I don't see how it would be any different to any other language. Admittedly I use the IDE because I like IDE's, but I don't see why it wouldn't work with a text editor and make -- the command line compiler is there. -- Tim Rowe From andrew at acooke.org Mon Feb 2 06:58:10 2009 From: andrew at acooke.org (andrew cooke) Date: Mon, 2 Feb 2009 03:58:10 -0800 (PST) Subject: what IDE is the best to write python? References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> Message-ID: > Just to register a contrary opinion: I *hate* syntax highlighting you can use it in surprising ways, if the implementation is good enough. when i used intellij with java i had the "syntax" highlighting set so that everything was simple black+white, but mutable state (i can't remember the exact details; perhaps it was just variables that were assigned, i am not sure what happened with attributes) was in bold. very neat - showed where the likely bugs were in the code - and nothing to do with what you'd normally consider syntax highlighting... andrew (last time i looked, intellij's support for python was not very good. which is a pity, because it was an excellent ide - better than eclipse, imho). From deets at nospam.web.de Mon Feb 2 07:01:28 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 02 Feb 2009 13:01:28 +0100 Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com><0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com><6ul2ieFg1sraU1@mid.uni-berlin.de><73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com> Message-ID: <6uo5koFg8q28U1@mid.uni-berlin.de> > I wonder why the designers of processors do such silly things as having > user and supervisor modes in the hardware - according to your > arguments a code review would solve the problem, and then they > could use the silicon saved to do other usefull stuff. - then any process > could use any instruction, and it would be all right. - easy to manage > out of the project - you just have to scan the object code for op codes > that you have decided are dangerous (for whatever stupid reason). This is comparing apples to oranges. Forced data encapsulation or not take place *inside one process*. So this whole argument is a straw-man. I've seen a lot of programs segfault that are written in C++ with data encapsulation. And also a lot of them that overcame the restrictions the compiler or even runtime in java imposed on them, either by pointer-magic, or through some available backdoors that have been put in place for good reasons. So far I haven't seen any argument for forced data encapsulation that went beyond a matter of personal taste. That's fine, but also just that. Diez From cd at okunah.de Mon Feb 2 07:07:57 2009 From: cd at okunah.de (Christof Donat) Date: Mon, 02 Feb 2009 13:07:57 +0100 Subject: what IDE is the best to write python? References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> Message-ID: Hi, >> > Just to register a contrary opinion: I *hate* syntax highlighting >> >> With vim you simply don't turn it on. Would that be OK for you? > > No. Even the /possibility/ of having syntax highlighting would indicate > wimpness and thus humiliate me. Ah, I guess you are using butterflies then: http://xkcd.com/378/ Christof From zasaconsulting at gmail.com Mon Feb 2 07:10:15 2009 From: zasaconsulting at gmail.com (Alessandro Zivelonghi) Date: Mon, 2 Feb 2009 13:10:15 +0100 Subject: sorting mesh data an from abaqus simulation Message-ID: Hello there :) , I am a python newbie who needs help with tables(lists?) and other data structures. My mechanical engineering simulation program (Abaqus) use a Python env to access model data and results from a simulation. For me a model means a "mesh" of that model, i.e. a lists of nodes and elements which discretized the CAD model. In Abaqus each mesh has the following structure (see " http://www.tecnopolis.eu/upload/mesh.inp"): - a list of NODES in form of a table ( nodelabel_n, coordinatex, coordinatey) - and a list of ELEMENTS also in form of a table. Each element refers to three nodes (which must be in the list of nodes) and the table looks like this (elementlabel_n, node_n1, node_n2, node_n3) Through following py script I can access all nodes (--> *N*) and elements (--> *EL*) from the "mesh-1.odb" file ( http://www.tecnopolis.eu/upload/mesh-1.odb) where the simulation results are stored. *from odbAccess import * from odbSection import * nameodb = 'mesh-1' path = '/onepath/' + nameodb + '.odb' odb = openOdb(path) **N = odb.rootAssembly.instances['PART-1-1'].nodes * *EL = odb.rootAssembly.instances['PART-1-1'].elements * Info: to get a node label, for example the label of the node object n5 in the list Ntop: *Ntop[5].label* to get the x coordinates of that node: *Ntop[5].coordinates[0]* In particular I am interested in the node subset "TOP" (which represents all the nodes at the top of my model) *Ntop = odb.rootAssembly.instances['PART-1-1'].nodeSets['TOP'].nodes * Problem: 1) the list of nodes Ntop contains all the node labels [2673, 2675, 2676, 2677, 2678, 3655, 3656, 119939, 124154, 127919] already ordered in ascending order. What I need is the same list *ordered by coordinate_x* of each node, i.e. from left to right in the model (unfortunately, for example node 124154 cames before node 3656 in the model, if you read the model from left to right) 1b) I don't understand which kind of data are EL, N, Ntop (list?) and how can I sort Ntop with the criterium based on coordinate_x (coordinate[0]) Many thanks, Alex -- > Alessandro Zivelonghi > > http://www.tecnopolis.eu > > skype: alexzive > > "Energy and persistence conquer all things." > Benjamin Franklin (1706 - 1790) > -------------- next part -------------- An HTML attachment was scrubbed... URL: From feliphil at gmx.net Mon Feb 2 07:15:55 2009 From: feliphil at gmx.net (Wolfgang Keller) Date: Mon, 2 Feb 2009 13:15:55 +0100 Subject: Python package Management GUI - New Project on Sourceforge References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> <497FAFE4.4040602@gmail.com> <83900549676010b8244969ece9319a78@preisshare.net> Message-ID: <20090202131555.3d4ff2a4.feliphil@gmx.net> > David, I would really recommend that you > seriously consider using the Tcp/Tk toolkit. I would seriously disrecommend using Tcl/Tk. > Why ? Because it doesn't allow to build a GUI application with not-ridiculous functionality, "look-and-feel" and quirk-free behaviour. > Because of my point above, you'll find the tool will most likely have > a greater impact and uptake than one requiring a user or developer to > install a 3rd party toolkit and library just to use your gui package > manager :) I'm using applications that use wxPython, PyGTK, PyQt etc. every day that don't require to "install" anything, not even _themselves_. In fact this (zero-install applications) is the _only_ actually "simple" way to distribute applications. And it is the standard way to distribute applications for the Mac. From rdmurray at bitdance.com Mon Feb 2 07:40:08 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Mon, 2 Feb 2009 12:40:08 +0000 (UTC) Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com><50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com><4981985B.4070108@wildenhain.de><783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com><0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com><6ul2ieFg1sraU1@mid.uni-berlin.de><73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> Message-ID: Quoth "Hendrik van Rooyen" : > wrote: > > > > > You, sir, should be programming in some language other than Python. > > Why? - Python is object oriented, but I can write whole systems > without defining a single class. > By analogy, if data hiding is added to language, I could write a > whole system without hiding a single item. > Conversely, the lack of data hiding is perceived as a weakness, > and IMO harms the advocacy of the language - This is proven > by your statement above, whereby you are driving a user away, > simply because the language, in one small aspect, does not > give him what he wants, and the tenor of this thread has been > very much: "That's how it is - like it or lump it", and no amount > of careful explanation of why people want the feature has cut > any ice - It has all the time been countered with statements > about how the proponents of private attributes "don't need it", > (as if they are plain dumb), that an underscore convention is > "just as good", (It isn't), that you could crack it if you really > tried, (so what?), and other more specious reasons. > > This is IMO an arrogant attitude - My apologies!! There was a smiley missing from the end of that statement above. However, you are right, even with the smiley added it would still be arrogant, and I regret that. The problem is that there is a fundamental philosophical divide here, and I don't think the advocates on either side are going to convince the other. This debate has happened many times. --RDM From python at bdurham.com Mon Feb 2 07:51:10 2009 From: python at bdurham.com (python at bdurham.com) Date: Mon, 02 Feb 2009 07:51:10 -0500 Subject: Import without executing module In-Reply-To: <7a9c25c20902012319i2d217644k12bc926400f630c2@mail.gmail.com> References: <7a9c25c20902012319i2d217644k12bc926400f630c2@mail.gmail.com> Message-ID: <1233579070.32519.1298029177@webmail.messagingengine.com> If the output is coming from a print command, couldn't the OP temporarily redirect STDIO to a file to prevent the output from being displayed? Malcolm ----- Original message ----- From: "Stephen Hansen" To: "Ray" Cc: python-list at python.org Date: Sun, 1 Feb 2009 23:19:09 -0800 Subject: Re: Import without executing module On Sun, Feb 1, 2009 at 11:05 PM, Ray wrote: > Basically, someone has created a python script and I would like to > make use of his functions. I would prefer to not modify his file so > what I would like to do is just write my script and import parts that > are needed. i.e., I would like to separate my changes from his as > best as I can. However, that other module has both functions (def's, > which I would like to use) and top-level commands which I don't need > and in fact, prints errors when I import it since it was meant to be > run as a top-level module and not imported in. i.e., its expecting > arguments to be supplied. Unfortunately, that's not possible, I believe. All the top level commands in a particular Python script are executed: that's how the functions get created. --S -- http://mail.python.org/mailman/listinfo/python-list From rdmurray at bitdance.com Mon Feb 2 07:59:56 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Mon, 2 Feb 2009 12:59:56 +0000 (UTC) Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com><0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com><6ul2ieFg1sraU1@mid.uni-berlin.de><73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com> <003d01c98527$d9ea4ec0$0d00a8c0@hendrik> Message-ID: Quoth "Hendrik van Rooyen" : > Now there are a LOT of dicey statements in the above passionate > plea - python is a language, and not a philosophy, but I won't go > into that, as that would lead off onto a tangent, of which there have > been a surfeit in this thread. Ah, now I understand. This is where you part company from the people you are arguing against. Python _is_ a philosophy. There is no smiley after that statement. :) --RDM PS: More accurately, Python _embodies_ a philosophy, and to advocate changes that go against that philosophy is to advocate changing Python into something that would no longer be Python. You can do that, but you aren't likely to get the community to follow you. From rdmurray at bitdance.com Mon Feb 2 08:14:52 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Mon, 2 Feb 2009 13:14:52 +0000 (UTC) Subject: Membership of multiple items to a list References: <87myd51ouw.fsf@benfinney.id.au> Message-ID: My client can handle your Mime and shows me the text part of the signed message. It's not as pretty as just seeing an unsigned text message, but that's a client problem, not yours :) I would like to think that all newsreader clients could handle mime at this point, but who knows. --RDM From mal at egenix.com Mon Feb 2 08:21:31 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Mon, 02 Feb 2009 14:21:31 +0100 Subject: install modules for specific python version In-Reply-To: <4984F415.6090902@catphive.net> References: <4984F415.6090902@catphive.net> Message-ID: <4986F35B.2080003@egenix.com> On 2009-02-01 02:00, Brendan Miller wrote: > I have several version of python running side by side on my ubuntu > install (2.5,2.6,3.0). > > I'm installing a module with a setup.py script, in this case > logilab-common, so that I can get pylint going. However, I need to > install into python 2.6, but by default it picks out 2.5 and throws > things in the site packages for that version. > > Is there a standard way to specify what version of python you want to > install into? I originally installed my other python versions with the > altinstall method. That's easy: just call the setup.py script with the version you want the modules installed to, e.g. python2.5 setup.py install python2.6 setup.py install etc. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Feb 02 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From mail at microcorp.co.za Mon Feb 2 08:45:48 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Mon, 2 Feb 2009 15:45:48 +0200 Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com><50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com><4981985B.4070108@wildenhain.de><783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com><0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com><6ul2ieFg1sraU1@mid.uni-berlin.de><73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com><018801c9850e$3e019fe0$0d00a8c0@hendrik> Message-ID: <005101c98549$d33a7420$0d00a8c0@hendrik> wrote: > Quoth "Hendrik van Rooyen" : > > wrote: > > > > > > > > You, sir, should be programming in some language other than Python. 8<------------- reasons given ---------------- > > This is IMO an arrogant attitude - > > My apologies!! There was a smiley missing from the end of that statement > above. However, you are right, even with the smiley added it would > still be arrogant, and I regret that. It was not actually aimed at you personally - more of a rant about the intolerance displayed by the "it's fine as it is" group. > > The problem is that there is a fundamental philosophical divide here, > and I don't think the advocates on either side are going to convince > the other. It certaintly looks like that - so far it has produced more heat than light, and very few funny comments > > This debate has happened many times. > So why are we dumb enough to repeat it? :-) - Hendrik From mail at microcorp.co.za Mon Feb 2 08:54:08 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Mon, 2 Feb 2009 15:54:08 +0200 Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com><0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com><6ul2ieFg1sraU1@mid.uni-berlin.de><73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com><018801c9850e$3e019fe0$0d00a8c0@hendrik><7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com><003d01c98527$d9ea4ec0$0d00a8c0@hendrik> Message-ID: <005201c98549$d3eb74a0$0d00a8c0@hendrik> wrote: > Quoth "Hendrik van Rooyen" : > > Now there are a LOT of dicey statements in the above passionate > > plea - python is a language, and not a philosophy, but I won't go > > into that, as that would lead off onto a tangent, of which there have > > been a surfeit in this thread. > > Ah, now I understand. This is where you part company from the > people you are arguing against. > > Python _is_ a philosophy. > > There is no smiley after that statement. :) > > --RDM > > PS: More accurately, Python _embodies_ a philosophy, and to advocate > changes that go against that philosophy is to advocate changing > Python into something that would no longer be Python. You can do > that, but you aren't likely to get the community to follow you. *sits on his hands to try to avoid the tangent, with the gaping hole of religion looming beneath the spiderweb of philosophy, and the language spec gathering dust in the corner, forgotten and forlorn* :-) - Hendrik From RLComstock3 at gmail.com Mon Feb 2 09:06:02 2009 From: RLComstock3 at gmail.com (Robert Comstock) Date: Mon, 2 Feb 2009 06:06:02 -0800 (PST) Subject: what IDE is the best to write python? References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> Message-ID: <703974cb-5ef4-4ec9-9bb5-02fda4f70251@w39g2000prb.googlegroups.com> I am personally a fan of vim and ipython. But most of my development is done on a remote system with ssh access. I have used many IDE's over the years and personally I feel like they try to hard to do everything for you that they end up doing very little the way I would like. There are MANY text editors out there and all you need to do is find the one that fits your development style. There are not so many IDE's and I found they wanted me to fit their styles. Why I like Vim: 1. Light and fast 2. Goes over ssh very well 3. Simple configuration 4. Lots of flexibility 5. Can your text editor do this? Vim search and replace, with increment :let i=1 | g/foo/s//\=i."morestuff"/ | let i=i+1 http://gdwarner.blogspot.com 6. Fast editing (once you have paid the price to learn it) I think the reality is productity, I would not be productive trying to write code on my computer then moving it to a server, it would be difficult to duplicate the enviroment without leaving my PC a garbage dump of packages I don't need. But that is not the case for many people. I also like Kate, it has server me well in my quest to learn vim. Thanks, Robert Comstock Lenovo T61 2.2Ghz/3GB Ram, Arch Linux x86_64, KDE 4.2 On Feb 2, 5:07?am, Christof Donat wrote: > Hi, > > >> > Just to register a contrary opinion: I *hate* syntax highlighting > > >> With vim you simply don't turn it on. Would that be OK for you? > > > No. Even the /possibility/ of having syntax highlighting would indicate > > wimpness and thus humiliate me. > > Ah, I guess you are using butterflies then:http://xkcd.com/378/ > > Christof From kdawg44 at gmail.com Mon Feb 2 09:14:26 2009 From: kdawg44 at gmail.com (K-Dawg) Date: Mon, 2 Feb 2009 09:14:26 -0500 Subject: Refreshing an IE Webpage Message-ID: <5caea3690902020614h2665690cpb6e5839e26615fd7@mail.gmail.com> Hi, I am trying to get and then refresh a page in IE with a Python script. I just want to get a page, then refresh it every 5 minutes. Below is the code I am attempting. It is erroring out on the id=ie.Document.Script._oleobj_.GetIDsOfNames('window.location.reload()') #tried with and without parens - reload & reload() line. This is mostly a borrowed script I found. The script was trying to call a written function on the page. I just want to call the build in reload function to refresh the page. Thanks for any help. Kevin import win32com.client, pythoncom from time import sleep ie=win32com.client.Dispatch('internetexplorer.application') ie.Visible=1 ie.Navigate('URL') sleep(5) id=ie.Document.Script._oleobj_.GetIDsOfNames('window.location.reload()') while True: res=ie.Document.Script._oleobj_.Invoke(id, 0, pythoncom.DISPATCH_METHOD, True) sleep(300) -------------- next part -------------- An HTML attachment was scrubbed... URL: From aahz at pythoncraft.com Mon Feb 2 09:30:00 2009 From: aahz at pythoncraft.com (Aahz) Date: 2 Feb 2009 06:30:00 -0800 Subject: what IDE is the best to write python? References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> <874ozd3cr3.fsf@benfinney.id.au> Message-ID: In article <874ozd3cr3.fsf at benfinney.id.au>, Ben Finney wrote: >aahz at pythoncraft.com (Aahz) writes: >> >> Just to register a contrary opinion: I *hate* syntax highlighting > >On what basis? It makes my eyes bleed -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From grflanagan at gmail.com Mon Feb 2 09:37:36 2009 From: grflanagan at gmail.com (Gerard Flanagan) Date: Mon, 02 Feb 2009 14:37:36 +0000 Subject: ElementTree and clone element toot In-Reply-To: <4986bfd7$0$9385$ba4acef3@news.orange.fr> References: <4986bfd7$0$9385$ba4acef3@news.orange.fr> Message-ID: m.banaouas wrote: > Hi all, > Working with the ElementTree module, I looked for clone element function but not > found such tool: > > def CloneElment(fromElem, destRoot = None) > fromElem is the element to clone > destRoot is the parent element of the new element ; if None so the new element > will be child of fromElem parent. The clone operation is recursive to make it > process all subtree of the element to clone. > > here is my first implementation: > > def CloneElement(fromElem, destRoot = None): > if destRoot == None: > fromRoot = ET.ElementTree(fromElem).getroot() > destRoot = fromRoot > destElem = destRoot.makeelement(fromElem.tag, fromElem.attrib) > destRoot.append(destElem) > destElem.text = fromElem.text > for e in fromElem.findall('*'): > CloneElement(e, destElem) > # > this function works fine only if destRoot parameter is defined by the caller > context. The problem is about retreiving parent element: I didn't found any way > to determine the parent element of an element "elem" by asking elem itself! > and ET.ElementTree(fromElem).getroot() is wrong because it returns fromElem > itself, not its parent. > > Thanks for any help. > -- > http://mail.python.org/mailman/listinfo/python-list > Maybe `dest = ET.fromstring(ET.tostring(src))` would do? Or as follows: from xml.etree import ElementTree as ET s = '''
text BBtext EEText ''' e = ET.fromstring(s) def clone(elem): ret = elem.makeelement(elem.tag, elem.attrib) ret.text = elem.text for child in elem: ret.append(clone(child)) return ret f = clone(e) assert ''.join(ET.tostring(e).split()) == ''.join(ET.tostring(f).split()) assert f[0].get('name') == e[0].get('name') f[0].set('name', 'NEWNAME') assert f[0].get('name') == 'NEWNAME' assert f[0].get('name') != e[0].get('name') From gagsl-py2 at yahoo.com.ar Mon Feb 2 09:59:44 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 02 Feb 2009 12:59:44 -0200 Subject: Config files editor References: Message-ID: En Sun, 01 Feb 2009 15:17:34 -0200, Tim Michelsen escribi?: > Hello Python, > does anyone know of a Python based project that has a GUI based > functionality to edit > config files read/written by ConfigParser? I think that people likes the ConfigParser format in part because it can be edited using *any* kind of editor. If you provide useful comments for all settings, most users should be able to modify it by themselves -- at least *my* type of users, perhaps your environment is different. -- Gabriel Genellina From alejandro.weinstein at gmail.com Mon Feb 2 10:00:43 2009 From: alejandro.weinstein at gmail.com (Alejandro) Date: Mon, 2 Feb 2009 07:00:43 -0800 (PST) Subject: Get thread pid References: <1f4ff371-447d-4eca-8c51-e73eb10ed8c5@a12g2000pro.googlegroups.com> <31508b6d-bebb-45e6-b57c-525d370e22c0@r37g2000prr.googlegroups.com> <9g8wopuphz.fsf@overberg.jeppesensystems.com> Message-ID: <5a2414d1-128e-4a02-bb81-d981429bf8b8@p2g2000prf.googlegroups.com> On Feb 2, 3:01?am, Ove Svensson wrote: > If you find a way to get to the real TID, that will be specific to > your architecture. > > If htop (or any other application) returns a TID, that is either > artificial or architecture specific. Right know I only need the TID for debugging under Linux. I will keep this information in mind though. Alejandro. From sjmachin at lexicon.net Mon Feb 2 10:14:48 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 2 Feb 2009 07:14:48 -0800 (PST) Subject: Comparing dates? References: <87bptl1a4l.fsf@benfinney.id.au> <5tkdo4l21dkm9kgv4ra4pftker89odebfu@4ax.com> Message-ID: <65bde456-45cb-434d-a60f-b2c0648155a7@g39g2000pri.googlegroups.com> On Feb 2, 10:07?pm, Gilles Ganault wrote: > On Mon, 02 Feb 2009 20:06:02 +1100, Ben Finney > > wrote: > >The Python data types for date and time are in the ?datetime? module > >. Create a > >?datetime? object for each value you want, then compare them. > > Thanks guys. For those interested, here's how to perform the > conversion from DD/MM/YYYY to YYYY-MM-DD: > > ===== > import datetime > > connection = datetime.datetime.strptime("21/02/2008", > "%d/%m/%Y").strftime("%Y-%m-%d") > print connection Gilles, that's certainly one way of doing it in Python. Here's another: >>> '-'.join(reversed('21/02/2008'.split('/'))) '2008-02-21' Please consider the following: If in fact the database has a text-type column (VARCHAR or similar) that contains dates formatted as DD/MM/YYYY: (1) somebody should be talking rather bluntly to the database designer, and that column should be fixed if possible without breaking other code (2) doing the comparison on the client side (i.e. in Python) instead of on the server side (i.e. in SQL) means that there will be unnecessary data transmitted to the client side -- hence this should only be considered if the volume of data is small. Imagine trying to do a relational join using that column and another (normal) date column by sucking both tables down to the client! (3) it's quite possible to do the comparison in SQL: e.g. if the column is named "d": WHERE SUBSTR(d, 7, 4) || SUBSTR(d, 4, 2) || SUBSTR(d, 1, 2) < '20090201' -- insert '-' if preferred or something similar should be doable in any SQL implementation. Most will have functions like str[pf]time that could be used to similar effect. Cheers, John From gagsl-py2 at yahoo.com.ar Mon Feb 2 10:18:08 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 02 Feb 2009 13:18:08 -0200 Subject: ElementTree and clone element toot References: <4986bfd7$0$9385$ba4acef3@news.orange.fr> Message-ID: En Mon, 02 Feb 2009 12:37:36 -0200, Gerard Flanagan escribi?: > e = ET.fromstring(s) > > def clone(elem): > ret = elem.makeelement(elem.tag, elem.attrib) > ret.text = elem.text > for child in elem: > ret.append(clone(child)) > return ret > > f = clone(e) You forget the tail attribute, and you also should use the SubElement factory instead of makeelement as documented; doing that fixes the "parent" issue too. -- Gabriel Genellina From drkjam at gmail.com Mon Feb 2 10:18:39 2009 From: drkjam at gmail.com (David Moss) Date: Mon, 2 Feb 2009 07:18:39 -0800 (PST) Subject: the 'right way' to distribute and access data files in a packaged Python module Message-ID: <715dabdd-618d-4451-a0db-ba6cf59847fc@x6g2000pre.googlegroups.com> Hi, I'm the author of netaddr :- http://pypi.python.org/pypi/netaddr/0.6 For release 0.6 I've added setuptools support so it can be distributed as a Python egg package using the easy_install tool. In 0.6, I've started bundling some data files from IEEE and IANA with the code below the site-packages install path (lib/site-packages/ netaddr/...). netaddr accesses and parses these files on module load to provide various IP and MAC address related information via its API. This mechanism works for the setuptools based packages because on install they extract to the filesystem and can be accessed using something like :- >>> index = open(os.path.join(__file__, 'oui.idx')) However, setuptools seems to perform some magic for module imports which prevents me from accessing these files directly as they are bundled inside an egg (zip) file :-( Two questions arise out of this situation :- 1) is there a better way to distribute the files, i.e. should I be using a different more correct path instead of site-packages for data? If so, where is this and how do I add it to my setup scripts and code? 2) is there an easy (and portable) way for me to dive inside an egg file to access the data I required (ugly but workable). I'm assuming I'd need to check for the presence of setuptools available with the Python interpreter etc. My users and I would be grateful for and help and advice. Many thanks, Dave M. From mail at microcorp.co.za Mon Feb 2 10:20:01 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Mon, 2 Feb 2009 17:20:01 +0200 Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com><0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com><6ul2ieFg1sraU1@mid.uni-berlin.de><73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com><018801c9850e$3e019fe0$0d00a8c0@hendrik><7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com> <6uo5koFg8q28U1@mid.uni-berlin.de> Message-ID: <005301c98549$d4934d60$0d00a8c0@hendrik> Hendrik: > > I wonder why the designers of processors do such silly things as having > > user and supervisor modes in the hardware - according to your > > arguments a code review would solve the problem, and then they > > could use the silicon saved to do other usefull stuff. - then any process > > could use any instruction, and it would be all right. - easy to manage > > out of the project - you just have to scan the object code for op codes > > that you have decided are dangerous (for whatever stupid reason). > Diez: > This is comparing apples to oranges. Forced data encapsulation or not take > place *inside one process*. So this whole argument is a straw-man. I do not agree with this, but then I won't will I? The reason is that I see a level of abstraction that makes it kind of irrelevant whether something is run as a process, a thread, a time multiplexed mainloop, on one or more processors, wherever or whatever - almost like a fractal structure spread across the total addressable space - and I would like to use the same rules everywhere. And if there are reasons for forced encapsulation *somewhere*, then it is more elegant (to my taste) to allow it *everywhere*. - and conversely, of course. Hence the rather *an der Haare herbeigezogen* (see ** below) argument based on the forced restrictions in processors. I see almost any piece of code that "does something" as a black box that has inputs and outputs - and I like to string them together in a style that resembles a systolic array - closer to unix piping , based on true queueing and message passing, where it becomes at all practical. Given this approach, there is no reason whatever for anything to mess with any other thing's innards - in fact the less you know about it, the more robust and predictable the system becomes. And in embedded processes, there exist things that are time critical, that are designed to be used in one way, and no other, and that can have serious consequences if messed with- when I have started moving the 100 tonne mass, then I *cannot* tolerate other code changing my timeouts or speeds or feeds in an arbitrary fashion - EXPENSIVE noises will result. > I've seen a lot of programs segfault that are written in C++ with data > encapsulation. And also a lot of them that overcame the restrictions the > compiler or even runtime in java imposed on them, either by pointer-magic, > or through some available backdoors that have been put in place for good > reasons. I think that segfaulting is basically caused by programming error - By the inability of the programmer actually to understand the limitations of the compiler to "do what I mean". Encapsulation or data hiding will never "cure" that, because at best it could move some of the errors from runtime to compile time. I doubt the "good reasons for backdoors" part - I think that comes from a design that has either not been done, or used, at the correct level of granularity. > So far I haven't seen any argument for forced data encapsulation that went > beyond a matter of personal taste. That's fine, but also just that. This could be true, and if it is, we are just beating our heads one against the other, trying to win non existent prizes for pig-headedness. I could also turn that argument around, as well as stating it stronger: So far I have not seen any argument in favour of free access to the internals of another piece of code that is based on ANY necessity, (beside a handwaving "good reasons" ) or that goes beyond a matter of personal taste based on a hacker's glee in meddling in somebody else's code. :-) - Hendrik ** -*an der Haare herbeigezogen* German, literally "drawn closer by the hair" expression denoting either a specious argument or a forced analogy. Sorry, but I could think of no English equivalent. From kyosohma at gmail.com Mon Feb 2 10:30:54 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Mon, 2 Feb 2009 07:30:54 -0800 (PST) Subject: Monitor Internet connections in XP/Vista References: Message-ID: <0e7db74f-091a-4948-a330-bd57599deecf@v5g2000pre.googlegroups.com> On Feb 2, 3:05?am, pranav wrote: > Hi Folks, > > I am designing a project for Windows XP/Vista, one part of which is a > background process that monitors internet connections. If the user > tries to connect to any particular site, say myDummySite.com in then > some actions are taken, based on fixed policies. > This can be thought of a mini firewall. > > I am sure there must be some good libraries for this purpose. I need > the names of those libraries. > > Thanks, > > Pranav Prakash You could try urllib2, socket or just call ping with subprocess. Mike From goon12 at gmail.com Mon Feb 2 10:36:52 2009 From: goon12 at gmail.com (Joe Riopel) Date: Mon, 2 Feb 2009 10:36:52 -0500 Subject: what IDE is the best to write python? In-Reply-To: References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> <874ozd3cr3.fsf@benfinney.id.au> Message-ID: <6a2ccd190902020736l3ddb1332ued49bc528bc87121@mail.gmail.com> I typically use vim/vi, because it's usually already installed on the OS's I work with and vim for Windows works the same. Also, using the same editor across these different OS's, I don't have to worry too much soft/hard tabs. The contents of rc files on both Windows and UNIX/Linux are the same too, so I can just maintain one run control file for all OS's. I have played around with some IDE's for python, and found that Komodo Edit is pretty good. It's also free: http://www.activestate.com/komodo_edit/ From gagsl-py2 at yahoo.com.ar Mon Feb 2 10:39:50 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 02 Feb 2009 13:39:50 -0200 Subject: Extreme Yaro weirdness References: Message-ID: En Mon, 02 Feb 2009 06:59:16 -0200, Ron Garret escribi?: > I'm running the following WSGI app under Yaro: > > def error(req): > try: > req.non_existent_key > except: > try: > return cgitb.html(sys.exc_info()) > except: > return 'foo' > > The result of running this is 'foo'. In other words, the reference to > the non-existent key generates an exception as expected, but then the > generation of the traceback generates ANOTHER exception, which I would > not have expected. If I add another TRY/EXCEPT block to capture this > exception, the result is attached at the bottom of this message. Unqualified excepts are evil -- see this recent post (mine) http://groups.google.com/group/comp.lang.python/msg/05e822f694b6421c But in this case you hit a known bug in cgitb - see http://bugs.python.org/issue4643 for a solution. -- Gabriel Genellina From grflanagan at gmail.com Mon Feb 2 10:52:59 2009 From: grflanagan at gmail.com (Gerard Flanagan) Date: Mon, 02 Feb 2009 15:52:59 +0000 Subject: ElementTree and clone element toot In-Reply-To: References: <4986bfd7$0$9385$ba4acef3@news.orange.fr> Message-ID: Gabriel Genellina wrote: > En Mon, 02 Feb 2009 12:37:36 -0200, Gerard Flanagan > escribi?: > >> e = ET.fromstring(s) >> >> def clone(elem): >> ret = elem.makeelement(elem.tag, elem.attrib) >> ret.text = elem.text >> for child in elem: >> ret.append(clone(child)) >> return ret >> >> f = clone(e) > > You forget the tail attribute, I did, thanks. and you also should use the SubElement > factory instead of makeelement as documented; doing that fixes the > "parent" issue too. > I suppose I would have just used the Element factory if the OP hadn't otherwise: def clone(elem): ret = ET.Element(elem.tag, elem.attrib) ret.text = elem.text ret.tail = elem.tail for child in elem: ret.append(clone(child)) return ret Not sure what SubElement gains you, in the context of the above function? From ppearson at nowhere.invalid Mon Feb 2 10:58:43 2009 From: ppearson at nowhere.invalid (Peter Pearson) Date: 2 Feb 2009 15:58:43 GMT Subject: Membership of multiple items to a list References: Message-ID: <6uojhjFgavaqU1@mid.individual.net> Sorry to whine, but here's how this looks on slrn: On Mon, 2 Feb 2009 00:24:19 -0800 (PST), Stephen Hansen wrote: > This is an OpenPGP/MIME signed message (RFC 2440 and 3156) > -------firegpg072eqfqovlg25y5x7pu7mz3 > Content-Type: text/plain; format=flowed; charset=UTF-8 > Content-Transfer-Encoding: base64 > > T24gU3VuLCBGZWIgMSwgMjAwOSBhdCA3OjQ3IFBNLCBCZW4gRmlubmV5IDxiaWdub3NlK2hhdGVz [many similarly informative lines omitted] > cnJ5IGZvciB0aGUgaW5jb252ZW5pZW5jZS4gDQoNCi0tU3RlcGhlbg== > -------firegpg072eqfqovlg25y5x7pu7mz3 > Content-Type: application/pgp-signature; name="signature.asc" > Content-Description: OpenPGP digital signature > Content-Disposition: attachment; filename="signature.asc" > > > -------firegpg072eqfqovlg25y5x7pu7mz3-- -- To email me, substitute nowhere->spamcop, invalid->net. From rNOSPAMon at flownet.com Mon Feb 2 11:10:19 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Mon, 02 Feb 2009 08:10:19 -0800 Subject: Extreme Yaro weirdness References: Message-ID: In article , "Gabriel Genellina" wrote: > En Mon, 02 Feb 2009 06:59:16 -0200, Ron Garret > escribi?: > > > I'm running the following WSGI app under Yaro: > > > > def error(req): > > try: > > req.non_existent_key > > except: > > try: > > return cgitb.html(sys.exc_info()) > > except: > > return 'foo' > > > > The result of running this is 'foo'. In other words, the reference to > > the non-existent key generates an exception as expected, but then the > > generation of the traceback generates ANOTHER exception, which I would > > not have expected. If I add another TRY/EXCEPT block to capture this > > exception, the result is attached at the bottom of this message. > > Unqualified excepts are evil -- see this recent post (mine) > http://groups.google.com/group/comp.lang.python/msg/05e822f694b6421c > > But in this case you hit a known bug in cgitb - see > http://bugs.python.org/issue4643 for a solution. Aha! Thank you! That explains everything, except this: why does the problem go away when I run under wsgiref and capture the request in a global variable? Feel free to treat that as a rhetorical question :) rg From sjmachin at lexicon.net Mon Feb 2 11:11:40 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 2 Feb 2009 08:11:40 -0800 (PST) Subject: Import without executing module References: <7a9c25c20902012319i2d217644k12bc926400f630c2@mail.gmail.com> Message-ID: <14edd870-74d4-4d7a-a363-a4bc3515a071@s9g2000prg.googlegroups.com> On Feb 2, 11:51?pm, pyt... at bdurham.com wrote: > If the output is coming from a print command, couldn't the OP > temporarily redirect STDIO to a file to prevent the output from being > displayed? He could, but that'd be a kludge on top of a stuff-up. He should put the script-only statements inside if __name__ == '__main__': and send the result back to the original author, who may in fact appreciate being enlightened :-) Cheers, John From james at agentultra.com Mon Feb 2 11:17:06 2009 From: james at agentultra.com (J Kenneth King) Date: Mon, 02 Feb 2009 16:17:06 +0000 Subject: What is wrong in my list comprehension? References: <44116a3e-0f4a-418f-9ada-dc917ec592d5@j35g2000yqh.googlegroups.com> Message-ID: <873aew24ql.fsf@agentultra.com> Chris Rebert writes: > Python 2.6 (r26:66714, Nov 18 2008, 21:48:52) > [GCC 4.0.1 (Apple Inc. build 5484)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> bool(-1) > True > > str.find() returns -1 on failure (i.e. if the substring is not in the > given string). > -1 is considered boolean true by Python. That's an odd little quirk... never noticed that before. I just use regular expressions myself. Wouldn't this be something worth cleaning up? It's a little confusing for failure to evaluate to boolean true even if the relationship isn't direct. From banaouas.medialog at wanadoo.fr Mon Feb 2 11:21:29 2009 From: banaouas.medialog at wanadoo.fr (m.banaouas) Date: Mon, 02 Feb 2009 17:21:29 +0100 Subject: ElementTree and clone element toot In-Reply-To: References: <4986bfd7$0$9385$ba4acef3@news.orange.fr> Message-ID: <49871c5b$0$4087$ba4acef3@news.orange.fr> My python version is 2.4.4 def SubElement(parent, tag, attrib={}, **extra): Can you tell me how does "parent" issue could be solved by SubElement ? I'm looking for how to determine element parent just by asking element it self. It seems like element doesn't know witch is its parent, while any parent knows well witch are its childs. My goal is to clone an element and attach it to a specified parent or to parant of original element to clone. may be better implementation of CloneElement is to let the caller context make the attachement between the clone and its parent. Gabriel Genellina a ?crit : > En Mon, 02 Feb 2009 12:37:36 -0200, Gerard Flanagan > escribi?: > >> e = ET.fromstring(s) >> >> def clone(elem): >> ret = elem.makeelement(elem.tag, elem.attrib) >> ret.text = elem.text >> for child in elem: >> ret.append(clone(child)) >> return ret >> >> f = clone(e) > > You forget the tail attribute, and you also should use the SubElement > factory instead of makeelement as documented; doing that fixes the > "parent" issue too. > From james at agentultra.com Mon Feb 2 11:30:54 2009 From: james at agentultra.com (J Kenneth King) Date: Mon, 02 Feb 2009 16:30:54 +0000 Subject: What is wrong in my list comprehension? References: <44116a3e-0f4a-418f-9ada-dc917ec592d5@j35g2000yqh.googlegroups.com> Message-ID: <871vug243l.fsf@agentultra.com> Chris Rebert writes: > Python 2.6 (r26:66714, Nov 18 2008, 21:48:52) > [GCC 4.0.1 (Apple Inc. build 5484)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> bool(-1) > True > > str.find() returns -1 on failure (i.e. if the substring is not in the > given string). > -1 is considered boolean true by Python. That's an odd little quirk... never noticed that before. I just use regular expressions myself. Wouldn't this be something worth cleaning up? It's a little confusing for failure to evaluate to boolean true even if the relationship isn't direct. From james at agentultra.com Mon Feb 2 11:33:02 2009 From: james at agentultra.com (J Kenneth King) Date: Mon, 02 Feb 2009 16:33:02 +0000 Subject: What is wrong in my list comprehension? References: <44116a3e-0f4a-418f-9ada-dc917ec592d5@j35g2000yqh.googlegroups.com> Message-ID: <87wsc8ztmp.fsf@agentultra.com> Chris Rebert writes: > Python 2.6 (r26:66714, Nov 18 2008, 21:48:52) > [GCC 4.0.1 (Apple Inc. build 5484)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> bool(-1) > True > > str.find() returns -1 on failure (i.e. if the substring is not in the > given string). > -1 is considered boolean true by Python. That's an odd little quirk... never noticed that before. I just use regular expressions myself. Wouldn't this be something worth cleaning up? It's a little confusing for failure to evaluate to boolean true even if the relationship isn't direct. From james at agentultra.com Mon Feb 2 11:38:34 2009 From: james at agentultra.com (J Kenneth King) Date: Mon, 02 Feb 2009 16:38:34 +0000 Subject: What is wrong in my list comprehension? References: <44116a3e-0f4a-418f-9ada-dc917ec592d5@j35g2000yqh.googlegroups.com> Message-ID: <87vdrsztdh.fsf@agentultra.com> Chris Rebert writes: > Python 2.6 (r26:66714, Nov 18 2008, 21:48:52) > [GCC 4.0.1 (Apple Inc. build 5484)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> bool(-1) > True > > str.find() returns -1 on failure (i.e. if the substring is not in the > given string). > -1 is considered boolean true by Python. That's an odd little quirk... never noticed that before. I just use regular expressions myself. Wouldn't this be something worth cleaning up? It's a little confusing for failure to evaluate to boolean true even if the relationship isn't direct. From gnewsg at gmail.com Mon Feb 2 12:01:10 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Mon, 2 Feb 2009 09:01:10 -0800 (PST) Subject: Monitor Internet connections in XP/Vista References: Message-ID: On 2 Feb, 10:05, pranav wrote: > Hi Folks, > > I am designing a project for Windows XP/Vista, one part of which is a > background process that monitors internet connections. If the user > tries to connect to any particular site, say myDummySite.com in then > some actions are taken, based on fixed policies. > This can be thought of a mini firewall. > > I am sure there must be some good libraries for this purpose. I need > the names of those libraries. > > Thanks, > > Pranav Prakash I doubt there's something so low-level and platform specific for Python. You could eventually observe what happens on the wire by using libpcap/ Winpcap ("pcapy" and "pypcap" are some python bindings I heard of) but forget about applying policies like "allow/deny this or that traffic" natively. --- Giampaolo http://code.google.com/p/pyftpdlib From thmpsn.m.k at gmail.com Mon Feb 2 12:02:13 2009 From: thmpsn.m.k at gmail.com (thmpsn.m.k at gmail.com) Date: Mon, 2 Feb 2009 09:02:13 -0800 (PST) Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> Message-ID: <67d8a4d2-0b3d-4b41-84e2-698f17cb8e88@35g2000pry.googlegroups.com> On Feb 2, 2:55?am, Stephen Hansen wrote: > > This is proven > > by your statement above, whereby you are driving a user away, > > simply because the language, in one small aspect, does not > > give him what he wants, and the tenor of this thread has been > > very much: "That's how it is - like it or lump it", and no amount > > of careful explanation of why people want the feature has cut > > any ice - > > I'm missing the careful explanation. What I've heard is that the lack > of enforced encapsulation is "a danger". What I've heard is that > people want it because they've been told they should want it and > believe that. Why? Who has said the latter? Are you just trying to spread FUD? > There have been no "careful explanations" to answer that, in my mind. > And thus my response is: the practical possibility of needing access > vastly outweights the theoretical situation that might go bad if > encapsulation wasn't there. Why? Because in any real situation, IMHO, > *forced* encapsulation is pointless. I think you've gotten too subjective on this matter. You might as well say that we don't need no stinkin' OOP, we could all just be programming with goto's. Sure, hey, let's do OOP in C, using structs, POD STRUCTS (!!!!), and PLAIN FUNCTIONS (!!!!) !!!! Heck, why do we even need OOP?? Long live procedural!! We don't even need no stinkin programming languages, we could just program using 1's and 0's!!!!!!!!! What's with this luddite attitude, Python community? > > It has all the time been countered with statements > > about how the proponents of private attributes "don't need it", > > (as if they are plain dumb), > > They don't need it. No one has shown a *real* reason why. The only > reasons provided are "its a DANGER" that someone "MIGHT DO BAD". > That's not a real reason. If its your project that someone is doing > bad in, this is a situation which can be *clearly* specified in a > projects policy and coding standards and can be *trivially* tested for > with simple static analysis in nearly all cases. The problem is the > person and not the code then. There's *countless* other ways that > person can do bad if you're allowing them to commit blindly anything > into your project. Aha! I see this attitude quite often among C/C++ people, regarding buffer overflows and uninitialized pointer dereferences: someone will say "C and C++ are unsafe languages because they allow you to overrun buffers", then a C/C++ zealot will respond "Hire some good programmers". SAME ATTITUDE. From __peter__ at web.de Mon Feb 2 12:05:09 2009 From: __peter__ at web.de (Peter Otten) Date: Mon, 02 Feb 2009 18:05:09 +0100 Subject: What is wrong in my list comprehension? References: <44116a3e-0f4a-418f-9ada-dc917ec592d5@j35g2000yqh.googlegroups.com> <87wsc8ztmp.fsf@agentultra.com> Message-ID: J Kenneth King wrote: > Chris Rebert writes: > >> Python 2.6 (r26:66714, Nov 18 2008, 21:48:52) >> [GCC 4.0.1 (Apple Inc. build 5484)] on darwin >> Type "help", "copyright", "credits" or "license" for more information. >>>>> bool(-1) >> True >> >> str.find() returns -1 on failure (i.e. if the substring is not in the >> given string). >> -1 is considered boolean true by Python. > > That's an odd little quirk... never noticed that before. > > I just use regular expressions myself. > > Wouldn't this be something worth cleaning up? It's a little confusing > for failure to evaluate to boolean true even if the relationship isn't > direct. Well, what is your suggested return value when the substring starts at position 0? >>> "abcde".find("abc") 0 By the way, there already is a method with a cleaner (I think) interface: >>> "abcde".index("abc") 0 >>> "abcde".index("cde") 2 >>> "abcde".index("xyz") Traceback (most recent call last): File "", line 1, in ValueError: substring not found Peter From thorsten at thorstenkampe.de Mon Feb 2 12:05:38 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Mon, 2 Feb 2009 18:05:38 +0100 Subject: what IDE is the best to write python? References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> <703974cb-5ef4-4ec9-9bb5-02fda4f70251@w39g2000prb.googlegroups.com> Message-ID: * Robert Comstock (Mon, 2 Feb 2009 06:06:02 -0800 (PST)) > Why I like Vim: > [...] > 5. Can your text editor do this? > Vim search and replace, with increment > :let i=1 | g/foo/s//\=i."morestuff"/ | let i=i+1 I hope my editor wouldn't let me do this... Thorsten From kdawg44 at gmail.com Mon Feb 2 12:05:39 2009 From: kdawg44 at gmail.com (K-Dawg) Date: Mon, 2 Feb 2009 12:05:39 -0500 Subject: Refreshing an IE Webpage In-Reply-To: <5caea3690902020614h2665690cpb6e5839e26615fd7@mail.gmail.com> References: <5caea3690902020614h2665690cpb6e5839e26615fd7@mail.gmail.com> Message-ID: <5caea3690902020905q7cbdcf5am2e1093674dd1a178@mail.gmail.com> I have also tried to do this with mechanize: import mechanize import time br = mechanize.Browser() br.open("URL") while True: br.reload() time.sleep(300) After a bunch of time, I get the following error: C:\>SDE_KeepAlive-v2.py Traceback (most recent call last): File "C:\SDE_KeepAlive-v2.py", line 1 1, in File "C:\Python25\lib\site-packages\mechanize-0.1.9-py2.5.egg\mechanize\_mecha nize.py", line 345, in reload File "C:\Python25\lib\site-packages\mechanize-0.1.9-py2.5.egg\mechanize\_mecha nize.py", line 257, in _mech_open mechanize._response.httperror_seek_wrapper: HTTP Error 302: The HTTP server retu rned a redirect error that would lead to an infinite loop. The last 30x error message was: Found And on my first code, trying to use the Win32 api, I get the following error: C:\> SDE_Keep_Alive.py Traceback (most recent call last): File "C:\SDE_Keep_Alive.py", line 8, in id=ie.Document.Script._oleobj_.GetIDsOfNames('window.location.reload') pywintypes.com_error: (-2147352570, 'Unknown name.', None, None) All I want to do is grab a page and refresh it every 5 minutes. Thanks. -- Kevin On Mon, Feb 2, 2009 at 9:14 AM, K-Dawg wrote: > Hi, > > I am trying to get and then refresh a page in IE with a Python script. I > just want to get a page, then refresh it every 5 minutes. Below is the code > I am attempting. It is erroring out on the > id=ie.Document.Script._oleobj_.GetIDsOfNames('window.location.reload()') > #tried with and without parens - reload & reload() > line. This is mostly a borrowed script I found. The script was trying to > call a written function on the page. I just want to call the build in > reload function to refresh the page. > > Thanks for any help. > > Kevin > > > import win32com.client, pythoncom > from time import sleep > > ie=win32com.client.Dispatch('internetexplorer.application') > ie.Visible=1 > ie.Navigate('URL') > sleep(5) > > id=ie.Document.Script._oleobj_.GetIDsOfNames('window.location.reload()') > while True: > res=ie.Document.Script._oleobj_.Invoke(id, 0, > pythoncom.DISPATCH_METHOD, True) > sleep(300) > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From thorsten at thorstenkampe.de Mon Feb 2 12:06:38 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Mon, 2 Feb 2009 18:06:38 +0100 Subject: what IDE is the best to write python? References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> <874ozd3cr3.fsf@benfinney.id.au> Message-ID: * Aahz (2 Feb 2009 06:30:00 -0800) > In article <874ozd3cr3.fsf at benfinney.id.au>, > Ben Finney wrote: > >aahz at pythoncraft.com (Aahz) writes: > >> > >> Just to register a contrary opinion: I *hate* syntax highlighting > > > >On what basis? > > It makes my eyes bleed Ever tried sunglasses? Thorsten From apt.shansen at gmail.com Mon Feb 2 12:07:57 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 2 Feb 2009 09:07:57 -0800 Subject: What is wrong in my list comprehension? In-Reply-To: <873aew24ql.fsf@agentultra.com> References: <44116a3e-0f4a-418f-9ada-dc917ec592d5@j35g2000yqh.googlegroups.com> <873aew24ql.fsf@agentultra.com> Message-ID: <7a9c25c20902020907h63c3f146y6db6268e4c761bd6@mail.gmail.com> >> str.find() returns -1 on failure (i.e. if the substring is not in the >> given string). >> -1 is considered boolean true by Python. > > That's an odd little quirk... never noticed that before. > > I just use regular expressions myself. > > Wouldn't this be something worth cleaning up? It's a little confusing > for failure to evaluate to boolean true even if the relationship isn't > direct. But what would you clean it up to? str.find can return 0 ... which is a *true* result as that means it finds what you're looking for at position 0... but which evaluates to boolean False. The fact that it can also return -1 which is the *false* result which evaluates to boolean True is just another side of that coin. What's the options to clean it up? It can return None when it doesn't match and you can then test str.find("a") is None... but while that kinda works it also goes a bit against the point of having boolean truth/falsehood not representing success/failure of the function. 0 (boolean false) still is a success. Raising an exception would be a bad idea in many cases, too. You can use str.index if that's what you want. So there's not really a great solution to "cleaning it up" . I remember there was some talk in py-dev of removing str.find entirely because there was no really c, but I have absolutely no idea if they ended up doing it or not. --S From bruno.42.desthuilliers at websiteburo.invalid Mon Feb 2 12:09:49 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 02 Feb 2009 18:09:49 +0100 Subject: is python Object oriented?? In-Reply-To: <67d8a4d2-0b3d-4b41-84e2-698f17cb8e88@35g2000pry.googlegroups.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <67d8a4d2-0b3d-4b41-84e2-698f17cb8e88@35g2000pry.googlegroups.com> Message-ID: <498728db$0$27521$426a74cc@news.free.fr> thmpsn.m.k at gmail.com a ?crit : > On Feb 2, 2:55 am, Stephen Hansen wrote: >>> This is proven >>> by your statement above, whereby you are driving a user away, >>> simply because the language, in one small aspect, does not >>> give him what he wants, and the tenor of this thread has been >>> very much: "That's how it is - like it or lump it", and no amount >>> of careful explanation of why people want the feature has cut >>> any ice - >> I'm missing the careful explanation. What I've heard is that the lack >> of enforced encapsulation is "a danger". What I've heard is that >> people want it because they've been told they should want it and >> believe that. Why? > > Who has said the latter? Are you just trying to spread FUD? > >> There have been no "careful explanations" to answer that, in my mind. >> And thus my response is: the practical possibility of needing access >> vastly outweights the theoretical situation that might go bad if >> encapsulation wasn't there. Why? Because in any real situation, IMHO, >> *forced* encapsulation is pointless. > > I think you've gotten too subjective on this matter. > > You might as well > say that we don't need no stinkin' OOP, we could all just be > programming with goto's. > > Sure, hey, let's do OOP in C, using structs, POD STRUCTS (!!!!), and > PLAIN FUNCTIONS (!!!!) !!!! Aren't you going a bit over the board here ? No need to go mad nor scream at us. (snip usual stuff about lack of access restriction perceived as dangerous or whatever - cargo cult, really...). From google at mrabarnett.plus.com Mon Feb 2 12:19:38 2009 From: google at mrabarnett.plus.com (MRAB) Date: Mon, 02 Feb 2009 17:19:38 +0000 Subject: What is wrong in my list comprehension? In-Reply-To: <873aew24ql.fsf@agentultra.com> References: <44116a3e-0f4a-418f-9ada-dc917ec592d5@j35g2000yqh.googlegroups.com> <873aew24ql.fsf@agentultra.com> Message-ID: <49872B2A.1070204@mrabarnett.plus.com> J Kenneth King wrote: > Chris Rebert writes: > >> Python 2.6 (r26:66714, Nov 18 2008, 21:48:52) >> [GCC 4.0.1 (Apple Inc. build 5484)] on darwin >> Type "help", "copyright", "credits" or "license" for more information. >>>>> bool(-1) >> True >> >> str.find() returns -1 on failure (i.e. if the substring is not in the >> given string). >> -1 is considered boolean true by Python. > > That's an odd little quirk... never noticed that before. > > I just use regular expressions myself. > > Wouldn't this be something worth cleaning up? It's a little confusing > for failure to evaluate to boolean true even if the relationship isn't > direct. > str.find() returns the index (position) where the substring was found. Because string indexes start at 0 the returned value is -1 if it's not found. In those languages where string indexes start at 1 the returned value is 0 if not found. From aahz at pythoncraft.com Mon Feb 2 12:29:43 2009 From: aahz at pythoncraft.com (Aahz) Date: 2 Feb 2009 09:29:43 -0800 Subject: what IDE is the best to write python? References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> <874ozd3cr3.fsf@benfinney.id.au> Message-ID: In article , Thorsten Kampe wrote: >* Aahz (2 Feb 2009 06:30:00 -0800) >> In article <874ozd3cr3.fsf at benfinney.id.au>, >> Ben Finney wrote: >>>aahz at pythoncraft.com (Aahz) writes: >>>> >>>> Just to register a contrary opinion: I *hate* syntax highlighting >>> >>>On what basis? >> >> It makes my eyes bleed > >Ever tried sunglasses? Polarized sunglasses don't work too well with LCD monitors -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From deets at nospam.web.de Mon Feb 2 12:42:07 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 02 Feb 2009 18:42:07 +0100 Subject: the 'right way' to distribute and access data files in a packaged Python module References: <715dabdd-618d-4451-a0db-ba6cf59847fc@x6g2000pre.googlegroups.com> Message-ID: <6uopjfFgd5gdU1@mid.uni-berlin.de> David Moss wrote: > Hi, > > I'm the author of netaddr :- > > http://pypi.python.org/pypi/netaddr/0.6 > > For release 0.6 I've added setuptools support so it can be distributed > as a Python egg package using the easy_install tool. > > In 0.6, I've started bundling some data files from IEEE and IANA with > the code below the site-packages install path (lib/site-packages/ > netaddr/...). netaddr accesses and parses these files on module load > to provide various IP and MAC address related information via its API. > > This mechanism works for the setuptools based packages because on > install they extract to the filesystem and can be accessed using > something like :- > > >>> index = open(os.path.join(__file__, 'oui.idx')) > > However, setuptools seems to perform some magic for module imports > which prevents me from accessing these files directly as they are > bundled inside an egg (zip) file :-( > > Two questions arise out of this situation :- > > 1) is there a better way to distribute the files, i.e. should I be > using a different more correct path instead of site-packages for data? > If so, where is this and how do I add it to my setup scripts and code? > > 2) is there an easy (and portable) way for me to dive inside an egg > file to access the data I required (ugly but workable). I'm assuming > I'd need to check for the presence of setuptools available with the > Python interpreter etc. > > My users and I would be grateful for and help and advice. There is a zip-safe flag that you can specify that tells setuptools that installing your egg only works if it is unarchived. However, there is also the pkg_resources-package that allows you to access streams from within a package, even if it is zipped. You should investigate these two options. Diez From james at agentultra.com Mon Feb 2 12:43:39 2009 From: james at agentultra.com (J Kenneth King) Date: Mon, 02 Feb 2009 17:43:39 +0000 Subject: What is wrong in my list comprehension? References: <44116a3e-0f4a-418f-9ada-dc917ec592d5@j35g2000yqh.googlegroups.com> <873aew24ql.fsf@agentultra.com> Message-ID: <87r62gzqd0.fsf@agentultra.com> Stephen Hansen writes: >>> str.find() returns -1 on failure (i.e. if the substring is not in the >>> given string). >>> -1 is considered boolean true by Python. >> >> That's an odd little quirk... never noticed that before. >> >> I just use regular expressions myself. >> >> Wouldn't this be something worth cleaning up? It's a little confusing >> for failure to evaluate to boolean true even if the relationship isn't >> direct. > > But what would you clean it up to? > > str.find can return 0 ... which is a *true* result as that means it > finds what you're looking for at position 0... but which evaluates to > boolean False. The fact that it can also return -1 which is the > *false* result which evaluates to boolean True is just another side of > that coin. > > What's the options to clean it up? It can return None when it doesn't > match and you can then test str.find("a") is None... but while that > kinda works it also goes a bit against the point of having boolean > truth/falsehood not representing success/failure of the function. 0 > (boolean false) still is a success. > > Raising an exception would be a bad idea in many cases, too. You can > use str.index if that's what you want. > > So there's not really a great solution to "cleaning it up" . I > remember there was some talk in py-dev of removing str.find entirely > because there was no really c, but I have absolutely no idea if they > ended up doing it or not. > > --S (Sorry all for the multiple post... my gnus fudged a bit there) That's the funny thing about integers having boolean contexts I guess. Here's a case where 0 actually isn't "False." Any returned value should be considered "True" and "None" should evaluate to "False." Then the method can be used in both contexts of logic and procedure. (I guess that's how I'd solve it, but I can see that implementing it is highly improbable) I'm only curious if it's worth cleaning up because the OP's case is one where there is more than one way to do it. However, that's not the way the world is and I suppose smarter people have discussed this before. If there's a link to the discussion, I'd like to read it. It's pedantic but fascinating no less. From tim.arnold at sas.com Mon Feb 2 12:45:25 2009 From: tim.arnold at sas.com (Tim Arnold) Date: Mon, 2 Feb 2009 12:45:25 -0500 Subject: Using lxml to screen scrap a site, problem with charset References: Message-ID: "?????? ???????????" wrote in message news:ciqh56-ses.ln1 at archaeopteryx.softver.org.mk... > So, I'm using lxml to screen scrap a site that uses the cyrillic > alphabet (windows-1251 encoding). The sites HTML doesn't have the ..content-type.. charset=..> header, but does have a HTTP header that > specifies the charset... so they are standards compliant enough. > > Now when I run this code: > > from lxml import html > doc = html.parse('http://a1.com.mk/') > root = doc.getroot() > title = root.cssselect(('head title'))[0] > print title.text > > the title.text is ? unicode string, but it has been wrongly decoded as > latin1 -> unicode > > So.. is this a deficiency/bug in lxml or I'm doing something wrong. > Also, what are my other options here? > > > I'm running Python 2.6.1 and python-lxml 2.1.4 on Linux if matters. > > -- > ?????? ( http://softver.org.mk/damjan/ ) > > "Debugging is twice as hard as writing the code in the first place. > Therefore, if you write the code as cleverly as possible, you are, > by definition, not smart enough to debug it." - Brian W. Kernighan > The way I do that is to open the file with codecs, encoding=cp1251, read it into variable and feed that to the parser. --Tim From eric.shain at gmail.com Mon Feb 2 12:48:53 2009 From: eric.shain at gmail.com (Eric) Date: Mon, 2 Feb 2009 09:48:53 -0800 (PST) Subject: Combining several text files Message-ID: This is my first post, so please advise if I'm not using proper etiquette. I've actually searched around a bit and while I think I can do this, I can't think of a clean elegant way. I'm pretty new to Python, but from what I've learned so far is that there is almost always an easier way. I have to parse several log files. I've already written a working parser. The log files are simple text files that when they get to a certain size are renamed to append a number. So, you might end up with: filename.log.2 filename.log.1 filename.log The higher the number, the older the file. I want to search for all the files in a directory with "filename.log" as part of their name. Then I can do one of two things. First I could combine them so that the resulting file ends up with the oldest on top and newest on the bottom. Otherwise, I could just iterate over the multiple files within my parser. I don't need working code (that makes things too easy), just clear suggestions to a Python newcomer to speed me on my way. Thanks From mensanator at aol.com Mon Feb 2 12:49:48 2009 From: mensanator at aol.com (Mensanator) Date: Mon, 2 Feb 2009 09:49:48 -0800 (PST) Subject: nth root References: <1AE19A80523D5F40BE0044A1447A53FF0ADB972E@UNIMAIL.staff.ad.cqu.edu.au> <44029925-ae8f-484e-8fcd-0d5ec484c184@z28g2000prd.googlegroups.com> <9ae987f6-d7f8-4d81-a740-7bb838e328da@v5g2000pre.googlegroups.com> <81c042d3-39a6-42c3-a529-7acc06d484b1@u14g2000yqg.googlegroups.com> <68b1337a-1938-4765-b28a-dc526dd8e8c1@x6g2000pre.googlegroups.com> Message-ID: <65936f1b-fd67-4234-b119-aff78babfb7d@t39g2000prh.googlegroups.com> On Feb 2, 1:01?am, casevh wrote: > On Feb 1, 10:02?pm, Mensanator wrote: > > > > > > > On Feb 1, 8:20 pm, casevh wrote: > > > > On Feb 1, 1:04 pm, Mensanator wrote: > > > > > On Feb 1, 2:27 am, casevh wrote: > > > > > > On Jan 31, 9:36 pm, "Tim Roberts" wrote: > > > > > > > Actually, all I'm interested in is whether the 100 digit numbers have an exact integral root, or not. At the moment, because of accuracy concerns, I'm doing something like > > > > > > > for root in powersp: > > > > > > nroot = round(bignum**(1.0/root)) > > > > > > if bignum==long(nroot)**root: > > > > > > ......... > > > > > > which is probably very inefficient, but I can't see anything better..... > > > > > > > Tim > > > > > > Take a look at gmpy and the is_power function. I think it will do > > > > > exactly what you want. > > > > > And the root function will give you the root AND tell you whether > > > > it was an integral root: > > > > > >>> gmpy.root(a,13) > > > > > (mpz(3221), 0) > > > > > In this case, it wasn't. > > > > I think the original poster wants to know if a large number has an > > > exact integral root for any exponent. is_power will give you an answer > > > to that question but won't tell you what the root or exponent is. Once > > > you know that the number is a perfect power, you can root to find the > > > root. > > > But how do you know what exponent to use? > > That's the gotcha. :) You still need to test all prime exponents until > you find the correct one. But it is much faster to use is_power to > check whether or not a number has representation as a**b and then try > all the possible exponents than to just try all the possible exponents > on all the numbers. Ok. I was under the impression that the OP was only interested in the 13th root, so that is_power wouldn't necessarily be of any use to him. If is_power returned true, you would still have to do root(a,13) to see if it's actually a 13th power. That's executing two gmpy functions and takes twice as much time as doing root(a,13) alone. > > > > > > > > > >http://code.google.com/p/gmpy/ > > > > > > casevh From gagsl-py2 at yahoo.com.ar Mon Feb 2 12:54:27 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 02 Feb 2009 15:54:27 -0200 Subject: Extreme Yaro weirdness References: Message-ID: En Mon, 02 Feb 2009 14:10:19 -0200, Ron Garret escribi?: > In article , > "Gabriel Genellina" wrote: >> >> [...] you hit a known bug in cgitb - see >> http://bugs.python.org/issue4643 for a solution. > > Aha! Thank you! That explains everything, except this: why does the > problem go away when I run under wsgiref and capture the request in a > global variable? NLMPI (If you don't understand the acronym -very likely- ... well, you don't miss anything) -- Gabriel Genellina From kdawg44 at gmail.com Mon Feb 2 12:59:27 2009 From: kdawg44 at gmail.com (K-Dawg) Date: Mon, 2 Feb 2009 12:59:27 -0500 Subject: Refreshing an IE Webpage In-Reply-To: <5caea3690902020905q7cbdcf5am2e1093674dd1a178@mail.gmail.com> References: <5caea3690902020614h2665690cpb6e5839e26615fd7@mail.gmail.com> <5caea3690902020905q7cbdcf5am2e1093674dd1a178@mail.gmail.com> Message-ID: <5caea3690902020959g2483f1d5oe4c3b8bbf0020823@mail.gmail.com> Please disregard... I was making it harder than it had to be I think. The following seems to be running fine. Whether its doing what I want I will know in a little bit if the page in my browser times out.... import win32com.client, pythoncom from time import sleep ie=win32com.client.Dispatch('internetexplorer.application') > ie.Visible=0 > ie.Navigate('URL') > sleep(5) > > while True: > sleep(240) ie.Refresh() Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From philip at semanchuk.com Mon Feb 2 13:03:20 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 2 Feb 2009 13:03:20 -0500 Subject: Calling into Python from a C thread Message-ID: <52119CC5-1716-40EF-A0E0-570C05BEE4F1@semanchuk.com> Hi all, I'm trying call Python from inside of a C thread that's running in a Python extension I've written and I am not having much luck. My C thread function consists of simply this, and I get a segmentation fault from Python: void start_routine(union sigval foo) { PyGILState_STATE gstate; gstate = PyGILState_Ensure(); // Calls to Python code will go here... PyGILState_Release(gstate); }; I added a printf() and can see that the fault happens *after* the call to PyGILState_Release(). Apparently I'm monkeying up something fundamental in Python, and this is really simple so I must be missing something big. The context is that I'm adding support for mq_notify() to my posix_ipc extension. A process can register via mq_notify() to have a new thread started when a message appears in a message queue. I've got this working when my thread code is pure C, now I'm trying to add a call to a user-specified Python function. Thanks Philip From deets at nospam.web.de Mon Feb 2 13:05:46 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 02 Feb 2009 19:05:46 +0100 Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com><0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com><6ul2ieFg1sraU1@mid.uni-berlin.de><73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com><018801c9850e$3e019fe0$0d00a8c0@hendrik><7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com> <6uo5koFg8q28U1@mid.uni-berlin.de> Message-ID: <6uoqvrFgh5oeU1@mid.uni-berlin.de> > The reason is that I see a level of abstraction that makes it kind of > irrelevant whether something is run as a process, a thread, a time > multiplexed mainloop, on one or more processors, wherever or > whatever - almost like a fractal structure spread across the total > addressable space - and I would like to use the same rules > everywhere. And if there are reasons for forced encapsulation > *somewhere*, then it is more elegant (to my taste) to allow it > *everywhere*. - and conversely, of course. Hence the rather > *an der Haare herbeigezogen* (see ** below) argument > based on the forced restrictions in processors. Your argument would be valid if *any* of the *languages* implementing encapsulation would offer that real isolation. None does. So where from comes the feeling that this must be something a *language* should offer? Sure one could envision a system where each object is running in it's micro-process. So far, this hasn't been implemented (to the best of my knowledge) - so making assertions about the feasibility & robustness for running as well as for developing are somewhat "airy", don't you think? > Given this approach, there is no reason whatever for anything > to mess with any other thing's innards - in fact the less you know > about it, the more robust and predictable the system becomes. For a certain, very limited definition of robustness & predictability. As much as I like my OS not to go down, it's nothing that helps me to accomplish my actual goal using it if the software running on top of it crashes. From this POV, a chain is always only as strong as it's weakest member. And that might well be one of your encapsulated components. > And in embedded processes, there exist things that are time > critical, that are designed to be used in one way, and no other, > and that can have serious consequences if messed with- when > I have started moving the 100 tonne mass, then I *cannot* tolerate > other code changing my timeouts or speeds or feeds in an arbitrary > fashion - EXPENSIVE noises will result. Embedded programming most often even offers the memory protection one needs to make the "real" encapsulation, due to hardware restrictions. And even if it did, it won't help you with memory corruption that occurs in process. Which is of course a re-iteration of my argument. Again: the expensive noises haven't been avoided because of encapsulation. They might be the product of expensive testruns, either by trial-and-error, or by review. Not by encapsulation. >> I've seen a lot of programs segfault that are written in C++ with data >> encapsulation. And also a lot of them that overcame the restrictions the >> compiler or even runtime in java imposed on them, either by >> pointer-magic, or through some available backdoors that have been put in >> place for good reasons. > > I think that segfaulting is basically caused by programming error - > By the inability of the programmer actually to understand the > limitations of the compiler to "do what I mean". > > Encapsulation or data hiding will never "cure" that, because > at best it could move some of the errors from runtime to > compile time. > > I doubt the "good reasons for backdoors" part - I think that comes > from a design that has either not been done, or used, at the correct > level of granularity. > >> So far I haven't seen any argument for forced data encapsulation that >> went beyond a matter of personal taste. That's fine, but also just that. > > This could be true, and if it is, we are just beating our heads one > against the other, trying to win non existent prizes for pig-headedness. > > I could also turn that argument around, as well as stating it stronger: > > So far I have not seen any argument in favour of free access to > the internals of another piece of code that is based on ANY necessity, > (beside a handwaving "good reasons" ) or that goes beyond a matter > of personal taste based on a hacker's glee in meddling in somebody > else's code. The argument as apparent in Python: ducktyping is used everyday, to all our benefit. And every piece of code that only works precisely because it was possible to access the innards of some other piece of code is an example and a reason to allow it. You might say that these things are showing a lack of proper design - but the point is that design is a question of perspective, and a otherwise useful piece of code is rendered useless because of encapsulation if that prevents the usage from a new perspective the original author didn't think of. That's my stance on this, and as a coder, I want to (re)use code, not work around it. Diez From vincent at vincentdavis.net Mon Feb 2 13:08:50 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Mon, 2 Feb 2009 11:08:50 -0700 Subject: faster scipy.percentileofscore ? Message-ID: <77e831100902021008v17408ea5u5f5467e8f0c1d5e8@mail.gmail.com> Currently I am using the following: pgrades = [scipy.percentileofscore(grades,x) for x in grades] I need the percentile of each number in grades. The problem is that it takes a long time (a few minutes) because there are 15,000 items in the list. does anyone know is there is a faster way? Thanks Vincent Davis 720-301-3003 From google at mrabarnett.plus.com Mon Feb 2 13:11:21 2009 From: google at mrabarnett.plus.com (MRAB) Date: Mon, 02 Feb 2009 18:11:21 +0000 Subject: Combining several text files In-Reply-To: References: Message-ID: <49873749.9070806@mrabarnett.plus.com> Eric wrote: > This is my first post, so please advise if I'm not using proper > etiquette. I've actually searched around a bit and while I think I can > do this, I can't think of a clean elegant way. I'm pretty new to > Python, but from what I've learned so far is that there is almost > always an easier way. > > I have to parse several log files. I've already written a working > parser. The log files are simple text files that when they get to a > certain size are renamed to append a number. So, you might end up > with: > > filename.log.2 > filename.log.1 > filename.log > > The higher the number, the older the file. I want to search for all > the files in a directory with "filename.log" as part of their name. > Then I can do one of two things. First I could combine them so that > the resulting file ends up with the oldest on top and newest on the > bottom. Otherwise, I could just iterate over the multiple files within > my parser. > > I don't need working code (that makes things too easy), just clear > suggestions to a Python newcomer to speed me on my way. > My suggestion is to list the filenames, sort them into descending order by the suffix (converted to an int) (treat an unnumbered filename as one having the suffix ".0"), and then parse them in the resulting order. From apt.shansen at gmail.com Mon Feb 2 13:12:33 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 2 Feb 2009 10:12:33 -0800 Subject: is python Object oriented?? In-Reply-To: <003d01c98527$d9ea4ec0$0d00a8c0@hendrik> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com> <003d01c98527$d9ea4ec0$0d00a8c0@hendrik> Message-ID: <7a9c25c20902021012s2bd6bd71lf82310a07a3f194b@mail.gmail.com> > > > > that an underscore convention is > > > "just as good", (It isn't), > > > > Why isn't it? > > Because it needs human intervention. > Not necessarily at all: that's something that could be checked very readily with static analysis. Why isn't that a good enough tool if policy isn't sufficient? If you scan the code for "._" and target is not "self", and is not a magic method, then I think that is an encapsulation error. I don't know that Pylint or the various other flavors of analysis tools have an option to check for that, but wouldn't adding one be better then changing the language? That way those who want it get the certainty that encapsulation is never broken, and those who don't care don't have to worry about it. > > > > that you could crack it if you really > > > tried, (so what?), > > > > Exactly.. so what? WHY is the convention not enough? What REAL > > situation is there that the lack of *forced* encapsulation but policy > > based encapsulation not enough? > > > > See human intervention above - and as for > "real, forced data hiding" - have you ever > coded anything that produced a segmentation fault? > [ snip discussion of processor memory protection ] That's apples to... potatoes. I'm not opposed to memory protection :) Segmentation faults and memoy protection are an utterly different thing. One protects against a programmer accidentally going in and overwriting something that he shouldn't, when he doesn't even know he's doing it. The other protects against a programmer *intentionally* and *explicitly* going into source code and finding an undocumented internal detail to *intentionally* change it for some specific purpose. One stops someone from making a mistake. The other stops someone from doing something they /intend/ on doing. (Both may have an impact on someone with malicious intent, but that's a whole other subject) --S P.S. Aiee, this discussion is getting overwhelmingly long. :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Mon Feb 2 13:17:43 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 2 Feb 2009 10:17:43 -0800 Subject: Combining several text files In-Reply-To: References: Message-ID: <50697b2c0902021017t398b9e1fn42e5ac27fdc17da8@mail.gmail.com> On Mon, Feb 2, 2009 at 9:48 AM, Eric wrote: > This is my first post, so please advise if I'm not using proper > etiquette. I've actually searched around a bit and while I think I can > do this, I can't think of a clean elegant way. I'm pretty new to > Python, but from what I've learned so far is that there is almost > always an easier way. > > I have to parse several log files. I've already written a working > parser. The log files are simple text files that when they get to a > certain size are renamed to append a number. So, you might end up > with: > > filename.log.2 > filename.log.1 > filename.log > > The higher the number, the older the file. I want to search for all > the files in a directory with "filename.log" as part of their name. > Then I can do one of two things. First I could combine them so that > the resulting file ends up with the oldest on top and newest on the > bottom. Otherwise, I could just iterate over the multiple files within > my parser. > > I don't need working code (that makes things too easy), just clear > suggestions to a Python newcomer to speed me on my way. For listing the filenames, you'll want to use os.listdir: http://docs.python.org/library/os.html#os.listdir or possibly the `glob` module depending on your needs: http://docs.python.org/library/glob.html Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From apt.shansen at gmail.com Mon Feb 2 13:18:39 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 2 Feb 2009 10:18:39 -0800 Subject: What is wrong in my list comprehension? In-Reply-To: <87r62gzqd0.fsf@agentultra.com> References: <44116a3e-0f4a-418f-9ada-dc917ec592d5@j35g2000yqh.googlegroups.com> <873aew24ql.fsf@agentultra.com> <87r62gzqd0.fsf@agentultra.com> Message-ID: <7a9c25c20902021018m7a4112edv3a282d9b0ba187a5@mail.gmail.com> > > I'm only curious if it's worth cleaning up because the OP's case is one > where there is more than one way to do it. I just think at this point ".find" is just not the right method to use; "substring" in "string" is the way to determine what he wants is all. ".find" is useful for when you want the actual position, not when you just want to determine if there's a match at all. The way I'd clean it is to remove .find, personally :) I don't remember the outcome of their discussion on py-dev, and haven't gotten around to loading up Py3 to test it out :) I s'pose in certain contexts where catching .index's ValueError is too expensive and just checking vs -1 is faster and speed is important, .find() can still be useful. I don't do that much text parsing generally, so don't know. > However, that's not the way the world is and I suppose smarter people > have discussed this before. If there's a link to the discussion, I'd > like to read it. It's pedantic but fascinating no less. The thread I remember reading was: http://mail.python.org/pipermail/python-dev/2005-August/055704.html It sorta digressed at a certain point :) --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From duncan.booth at invalid.invalid Mon Feb 2 13:21:24 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 2 Feb 2009 18:21:24 GMT Subject: Membership of multiple items to a list References: Message-ID: Stephen Hansen wrote: > I'm re-sending this same message as the OpenPGP S/MIME attachment > format -- just so test if its actually readable by news clients in > general. I have absolutely no idea. Not touched a news client in years > and years, as I said. It is readable in XNews, but only displays in a fixed pitch font and without colours to distinguish the quoted content. From robert.kern at gmail.com Mon Feb 2 13:28:37 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 02 Feb 2009 12:28:37 -0600 Subject: faster scipy.percentileofscore ? In-Reply-To: <77e831100902021008v17408ea5u5f5467e8f0c1d5e8@mail.gmail.com> References: <77e831100902021008v17408ea5u5f5467e8f0c1d5e8@mail.gmail.com> Message-ID: On 2009-02-02 12:08, Vincent Davis wrote: > Currently I am using the following: > pgrades = [scipy.percentileofscore(grades,x) for x in grades] > > I need the percentile of each number in grades. The problem is that it > takes a long time (a few minutes) because there are 15,000 items in > the list. > does anyone know is there is a faster way? from scipy import stats pgrades = (stats.rankdata(grades)-1) / (len(grades)-1) * 100 You will probably want to ask further scipy questions on the scipy mailing list. http://www.scipy.org/Mailing_Lists -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From Scott.Daniels at Acm.Org Mon Feb 2 13:30:42 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 02 Feb 2009 10:30:42 -0800 Subject: Combining several text files In-Reply-To: References: Message-ID: Eric wrote: > I have to parse several log files.... > Then I can do one of two things. First I could combine them so that > the resulting file ends up with the oldest on top and newest on the > bottom. Otherwise, I could just iterate over the multiple files within > my parser. > > I don't need working code (that makes things too easy), just clear > suggestions to a Python newcomer to speed me on my way. Look into the "glob" module to get your name list, and sort the resulting list appropriately, then you can loop over that list. Then you can use an iterator (similar to below) to produce lines: def source_lines(chronological_filenames): for name in chronological_filenames: with open(name) as source: for line in source: yield line Note this uses the with statement to do file closing, so if you are using an older Python, you may need to write it differently. You can use this as a source of lines for your parser. --Scott David Daniels Scott.Daniels at Acm.Org From apt.shansen at gmail.com Mon Feb 2 13:35:28 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 2 Feb 2009 10:35:28 -0800 Subject: Membership of multiple items to a list In-Reply-To: References: Message-ID: <7a9c25c20902021035t3377b8di579c540f8a11f9b@mail.gmail.com> On Mon, Feb 2, 2009 at 10:21 AM, Duncan Booth wrote: > Stephen Hansen wrote: > > > I'm re-sending this same message as the OpenPGP S/MIME attachment > > format -- just so test if its actually readable by news clients in > > general. I have absolutely no idea. Not touched a news client in years > > and years, as I said. > > It is readable in XNews, but only displays in a fixed pitch font and > without colours to distinguish the quoted content. Yeah, I gave up. I was hoping to find one common set of settings that worked in all contexts I use this email account for, but failed :) Oh well. Sorry for sending junk. :) And going off-topic here. Ahem. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From vincent at vincentdavis.net Mon Feb 2 13:36:18 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Mon, 2 Feb 2009 11:36:18 -0700 Subject: faster scipy.percentileofscore ? In-Reply-To: References: <77e831100902021008v17408ea5u5f5467e8f0c1d5e8@mail.gmail.com> Message-ID: <77e831100902021036k38e14d85l5c57e250e973a79b@mail.gmail.com> Did not know about http://www.scipy.org/Mailing_Lists but did not look, Thanks for the help Vincent Davis On Mon, Feb 2, 2009 at 11:28 AM, Robert Kern wrote: > On 2009-02-02 12:08, Vincent Davis wrote: >> >> Currently I am using the following: >> pgrades = [scipy.percentileofscore(grades,x) for x in grades] >> >> I need the percentile of each number in grades. The problem is that it >> takes a long time (a few minutes) because there are 15,000 items in >> the list. >> does anyone know is there is a faster way? > > from scipy import stats > pgrades = (stats.rankdata(grades)-1) / (len(grades)-1) * 100 > > You will probably want to ask further scipy questions on the scipy mailing > list. > > http://www.scipy.org/Mailing_Lists > > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless enigma > that is made terrible by our own mad attempt to interpret it as though it > had > an underlying truth." > -- Umberto Eco > > -- > http://mail.python.org/mailman/listinfo/python-list > From lionel.keene at gmail.com Mon Feb 2 13:36:31 2009 From: lionel.keene at gmail.com (Lionel) Date: Mon, 2 Feb 2009 10:36:31 -0800 (PST) Subject: Reading text file with wierd file extension? Message-ID: Hi Folks, Python newbie here. I'm trying to open (for reading) a text file with the following filenaming convension: "MyTextFile.slc.rsc" My code is as follows: Filepath = "C:\\MyTextFile.slc.rsc" FileH = open(Filepath) The above throws an IOError exception. On a hunch I changed the filename (only the filename) and tried again: Filepath = "C:\\MyTextFile.txt" FileH = open(Filepath) The above works well. I am able to open the file and read it's contents. I assume to read a file in text file "mode" the parameter is scanned for a ".txt" extension, otherwise the Python runtime doesn't know what version of "open(...)" to invoke. How do I pass the original filename (MyTextFile.slc.rsc) and get Python to open it as a text file? Thanks in advance everyone! From stef.mientki at gmail.com Mon Feb 2 13:40:01 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Mon, 02 Feb 2009 19:40:01 +0100 Subject: database wrapper ? In-Reply-To: <50697b2c0902011543w7c022fel7c32e8e1ea7a920e@mail.gmail.com> References: <4986289C.3030205@gmail.com> <50697b2c0902011543w7c022fel7c32e8e1ea7a920e@mail.gmail.com> Message-ID: <49873E01.5060802@gmail.com> Chris Rebert wrote: > On Sun, Feb 1, 2009 at 2:56 PM, Stef Mientki wrote: > >> hello, >> >> Until now I used a simple wrapper around pysqlite and pyodbc to manage my >> databases. >> Now I'm looking for a better solution, >> because I've to support a (for this moment) unknown database, >> and I'm not the one who will choose the database. >> >> Googling, I found SQLalchemy, >> which looks quit good. >> >> But as I only want to choose once, >> I googled for "SQLalchemy alternatives", >> but it didn't find many answers. >> (Storm / Grok are of no interest, because manipulating the structure of the >> database is a key issue). >> >> Is SQLalchemy the best / most popular database wrapper ? >> Are there any alternatives ? >> > > SQLObject is also probably worth looking at -- http://www.sqlobject.org/ > > Cheers, > Chris > > I took a brief look at the alternatives, but I guess it's difficult to judge, without trying them all, most information is quit fragmented. For now, I've the "feeling" the following arguments are valid: (If I'm telling something completely wrong, someone will correct me ;-) positive for SQLAlchemy - SQLObject is obsolete. Turbo Gears has replaced SQLObject with SQLAlchemy. - SQLAlchemy is better / faster supported than SQLObject. - SQLAlchemy is faster positive for SQLObject - supports Sybase (which is also obsolete, but still used in my environment) equal for both - SQLObject is much easier, but if you put Elixer on top of SQLAlchemy, you've about the same easy interface. As we've planned to replace Sybase in the not too far future, the choice for me seems clear. thanks you al, cheers, Stef From kyosohma at gmail.com Mon Feb 2 13:41:21 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Mon, 2 Feb 2009 10:41:21 -0800 (PST) Subject: Reading text file with wierd file extension? References: Message-ID: <887b7e96-b0cc-4dea-8c1a-76c60ebffad3@t26g2000prh.googlegroups.com> On Feb 2, 12:36?pm, Lionel wrote: > Hi Folks, Python newbie here. > > I'm trying to open (for reading) a text file with the following > filenaming convension: > > "MyTextFile.slc.rsc" > > My code is as follows: > > Filepath = "C:\\MyTextFile.slc.rsc" > FileH = open(Filepath) > > The above throws an IOError exception. On a hunch I changed the > filename (only the filename) and tried again: > > Filepath = "C:\\MyTextFile.txt" > FileH = open(Filepath) > > The above works well. I am able to open the file and read it's > contents. I assume to read a file in text file "mode" the parameter is > scanned for a ".txt" extension, otherwise the Python runtime doesn't > know what version of "open(...)" to invoke. How do I pass the original > filename (MyTextFile.slc.rsc) and get Python to open it as a text > file? Thanks in advance everyone! The extension shouldn't matter. I tried creating a file with the same extension as yours and Python 2.5.2 opened it and read it no problem. I tried it in IDLE and with Wing on Windows XP. What are you using? What's the complete traceback? Mike From simon at brunningonline.net Mon Feb 2 13:52:05 2009 From: simon at brunningonline.net (Simon Brunning) Date: Mon, 2 Feb 2009 18:52:05 +0000 Subject: Reading text file with wierd file extension? In-Reply-To: References: Message-ID: <8c7f10c60902021052t2bb57cd1n5907c22de270e30c@mail.gmail.com> 2009/2/2 Lionel : > Hi Folks, Python newbie here. > > I'm trying to open (for reading) a text file with the following > filenaming convension: > > "MyTextFile.slc.rsc" Some kind of a resource fork, perhaps? Where did the file come from? Python doesn't do anything magic with filenames, so this must be some sort of a fileysytem oddity, I think. -- Cheers, Simon B. From apt.shansen at gmail.com Mon Feb 2 13:55:26 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 2 Feb 2009 10:55:26 -0800 Subject: Reading text file with wierd file extension? In-Reply-To: References: Message-ID: <7a9c25c20902021055t6f3af7a9leca5b58d4e2ca3c2@mail.gmail.com> > > The above works well. I am able to open the file and read it's > contents. I assume to read a file in text file "mode" the parameter is > scanned for a ".txt" extension, otherwise the Python runtime doesn't > know what version of "open(...)" to invoke. How do I pass the original > filename (MyTextFile.slc.rsc) and get Python to open it as a text > file? Thanks in advance everyone! Python doesn't care what extension you use: it doesn't even look at it. The full file name is passed blindly to the base OS. To open a file in text mode, do open(filename, "r"); it opens in binary if you do open(filename, "rb"). The filename has no impact on if its text or binary mode. There's something else going on here, I think, and you got misdirected from it. Are you sure you didn't typo the Filepath slightly? Perhaps left off a \ or had a comma instead of a period -- etc? Or that the filename didn't have some odd character in it that looked like a regular ascii character? --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From mjbuchan at gmail.com Mon Feb 2 13:55:50 2009 From: mjbuchan at gmail.com (Power Button) Date: Mon, 2 Feb 2009 10:55:50 -0800 (PST) Subject: Threading / Queue management Message-ID: hi there, I wonder if anyone can help with the following. I have written a script which polls a server and if it finds and pending orders, it instantiates an new object (foo) - in a new thread and processes some data. In the new object (foo), there are also some long running processes so I am trying to create a thread pool/queue and to push items onto the queue in the instantiated object (foo). Currently I am creating the Queue in foo but this means I am starting up 5 new threads every time I instantiate foo. What I want to be able to do is create the Queue and start 5 (n) threads when my program starts and then push items onto the queue in foo. My question is, how can I create the Queue in my main object and set the target function for the Thread Constructor to be a function in foo? Below is a code snippet if it will help explain more - as I am fairly new to Python. Thanks. M import os, threading, time import Queue class Foo(threading.Thread): def __init__(self, record): self.mRecord = record self.mQueue = None threading.Thread.__init__(self) def run(self): files = self.getFiles() self.sendFiles(files) #snip def getFiles(self): #snip pass def sendFiles(self, files): self.mQueue = Queue.Queue() for i in range(5): t = threading.Thread(target=self.doSend) t.setDaemon(False) t.start() for f in files: self.mQueue.put(['ok', f]) self.mQueue.join() def doSend(self): flag = 'ok' while flag != 'stop': flag,item = self.mQueue.get() if flag == 'ok': self.sendIt(item) self.mQueue.task_done() def sendIt(self, item): #snip pass import sys, traceback, time from modules.foo import Foo from modules.bar import Bar class Server(object): def startPolling(self): while True: bar = Bar(accessKey) pending = None pending = bar.getPending() if pending != None: self. processRecord(bar) time.sleep(10) def processRecord(self, record): Foo(record).start() def main(): server = Server() server.startPolling() if __name__ == '__main__': main() From Scott.Daniels at Acm.Org Mon Feb 2 14:13:32 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 02 Feb 2009 11:13:32 -0800 Subject: Python package Management GUI - New Project on Sourceforge In-Reply-To: References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> <497FAFE4.4040602@gmail.com> <83900549676010b8244969ece9319a78@preisshare.net> Message-ID: Gabriel Rossetti wrote: > ... > Well, isn't tkinter being removed? > (http://www.python.org/dev/peps/pep-3108/) To quote the referenced PEP: Rejected Ideas Modules that were originally suggested for removal ... * Tkinter o Would prevent IDLE from existing. o No GUI toolkit would be available out of the box. --Scott David Daniels Scott.Daniels at Acm.Org From lionel.keene at gmail.com Mon Feb 2 14:20:17 2009 From: lionel.keene at gmail.com (Lionel) Date: Mon, 2 Feb 2009 11:20:17 -0800 (PST) Subject: Reading text file with wierd file extension? References: <887b7e96-b0cc-4dea-8c1a-76c60ebffad3@t26g2000prh.googlegroups.com> Message-ID: On Feb 2, 10:41?am, Mike Driscoll wrote: > On Feb 2, 12:36?pm, Lionel wrote: > > > > > > > Hi Folks, Python newbie here. > > > I'm trying to open (for reading) a text file with the following > > filenaming convension: > > > "MyTextFile.slc.rsc" > > > My code is as follows: > > > Filepath = "C:\\MyTextFile.slc.rsc" > > FileH = open(Filepath) > > > The above throws an IOError exception. On a hunch I changed the > > filename (only the filename) and tried again: > > > Filepath = "C:\\MyTextFile.txt" > > FileH = open(Filepath) > > > The above works well. I am able to open the file and read it's > > contents. I assume to read a file in text file "mode" the parameter is > > scanned for a ".txt" extension, otherwise the Python runtime doesn't > > know what version of "open(...)" to invoke. How do I pass the original > > filename (MyTextFile.slc.rsc) and get Python to open it as a text > > file? Thanks in advance everyone! > > The extension shouldn't matter. I tried creating a file with the same > extension as yours and Python 2.5.2 opened it and read it no problem. > I tried it in IDLE and with Wing on Windows XP. What are you using? > What's the complete traceback? > > Mike- Hide quoted text - > > - Show quoted text - Hi Mike, maybe it's not a "true" text file? Opening it in Microsoft Notepad gives an unformatted view of the file (text with no line wrapping, just the end-of-line square box character followed by more text, end- of-line character, etc). Wordpad opens it properly i.e. respects the end-of-line wrapping. I'm unsure of how these files are being generated, I was just given them and told they wanted to be able to read them. How do I collect the traceback to post it? From lionel.keene at gmail.com Mon Feb 2 14:21:54 2009 From: lionel.keene at gmail.com (Lionel) Date: Mon, 2 Feb 2009 11:21:54 -0800 (PST) Subject: Reading text file with wierd file extension? References: <887b7e96-b0cc-4dea-8c1a-76c60ebffad3@t26g2000prh.googlegroups.com> Message-ID: <56eb8d9c-893a-45fc-8961-9296dea287f7@g1g2000pra.googlegroups.com> On Feb 2, 11:20?am, Lionel wrote: > On Feb 2, 10:41?am, Mike Driscoll wrote: > > > > > > > On Feb 2, 12:36?pm, Lionel wrote: > > > > Hi Folks, Python newbie here. > > > > I'm trying to open (for reading) a text file with the following > > > filenaming convension: > > > > "MyTextFile.slc.rsc" > > > > My code is as follows: > > > > Filepath = "C:\\MyTextFile.slc.rsc" > > > FileH = open(Filepath) > > > > The above throws an IOError exception. On a hunch I changed the > > > filename (only the filename) and tried again: > > > > Filepath = "C:\\MyTextFile.txt" > > > FileH = open(Filepath) > > > > The above works well. I am able to open the file and read it's > > > contents. I assume to read a file in text file "mode" the parameter is > > > scanned for a ".txt" extension, otherwise the Python runtime doesn't > > > know what version of "open(...)" to invoke. How do I pass the original > > > filename (MyTextFile.slc.rsc) and get Python to open it as a text > > > file? Thanks in advance everyone! > > > The extension shouldn't matter. I tried creating a file with the same > > extension as yours and Python 2.5.2 opened it and read it no problem. > > I tried it in IDLE and with Wing on Windows XP. What are you using? > > What's the complete traceback? > > > Mike- Hide quoted text - > > > - Show quoted text - > > Hi Mike, > > maybe it's not a "true" text file? Opening it in Microsoft Notepad > gives an unformatted view of the file (text with no line wrapping, > just the end-of-line square box character followed by more text, end- > of-line character, etc). Wordpad opens it properly i.e. respects the > end-of-line wrapping. I'm unsure of how these files are being > generated, I was just given them and told they wanted to be able to > read them. > > How do I collect the traceback to post it?- Hide quoted text - > > - Show quoted text - Sorry, I forgot to mention I'm using Python 2.5 and the Python IDLE. From dmp1991 at gmail.com Mon Feb 2 14:24:38 2009 From: dmp1991 at gmail.com (Dave Peterson) Date: Mon, 2 Feb 2009 11:24:38 -0800 (PST) Subject: Python package Management GUI - New Project on Sourceforge References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> <497FAFE4.4040602@gmail.com> <83900549676010b8244969ece9319a78@preisshare.net> Message-ID: <014ede68-a0e8-4e4b-876d-98edef3059ec@i20g2000prf.googlegroups.com> On Feb 1, 10:57?pm, David Lyon wrote: > > What's wrong with Enstaller from Enthought ? > > for a start.... > > onhttps://svn.enthought.com/enthought/wiki/Enstaller > > it claims to be depracated... Hello, Actually it was version 2.x and earlier that was deprecated and we just hadn't updated that wiki page in a long time. Thanks for pointing that out! I've now updated it with a bit of news at the top. In short Enstaller 3.x is alive and well and available from PyPi. We had the downtime for exactly the reason pointed out on this thread -- which is that we found the old code to be extremely unstable as users updated any of the dependencies on which Enstaller depended -- things such as wxPython, Traits, etc. As of now, Enstaller 3.x is a command-line only tool but it does provide a lot of benefits over standard setuptools -- uninstall, update/upgrade command, found eggs aren't pre-pended to the full sys.path but instead inserted before the containing directory, etc. Our vision for re-implementing the GUI is to provide it via a web- based frontend as (a) the basic libraries for that ARE included in the standard lib and (b) we figure more people have a working web browser than have the Python bindings to any one of various widget libraries installed. We'd welcome others to the project if anyone would like to help out! Just contact us at info at enthought.com for procedures on getting repo privileges. From deets at nospam.web.de Mon Feb 2 14:28:07 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 02 Feb 2009 20:28:07 +0100 Subject: Reading text file with wierd file extension? In-Reply-To: References: <887b7e96-b0cc-4dea-8c1a-76c60ebffad3@t26g2000prh.googlegroups.com> Message-ID: <6uovq7FghiorU1@mid.uni-berlin.de> > Hi Mike, > > maybe it's not a "true" text file? Opening it in Microsoft Notepad > gives an unformatted view of the file (text with no line wrapping, > just the end-of-line square box character followed by more text, end- > of-line character, etc). Wordpad opens it properly i.e. respects the > end-of-line wrapping. I'm unsure of how these files are being > generated, I was just given them and told they wanted to be able to > read them. Sounds like a unix-line-ended textfile. Python has no problems reading these, and frankly I'm a bit wondering why you have that IOError -but then, on windows *anything* is possible. You can try to open the file using the "rb" flag, which opens it in binary. However, Python doesn't care about any extensions, that must be something else you did different. > How do I collect the traceback to post it? Copy and paste from the console or wherever you run the script? Diez From tcp at mac.com Mon Feb 2 14:28:19 2009 From: tcp at mac.com (Ted Pollari) Date: Mon, 02 Feb 2009 11:28:19 -0800 Subject: Financial aid for PyCon 2009 is now available Message-ID: I'm happy to announce that the Python Software Foundation has allocated some funds to help people attend PyCon 2009! If you would like to come to PyCon but can't afford it, the PSF may be able to help you pay for registration, lodging/hotel costs and transportation (flight etc.). Please see http://us.pycon.org/2009/registration/financial-aid/ for full details, or email pycon-aid at python.org with questions. From tpollari at gmail.com Mon Feb 2 14:28:41 2009 From: tpollari at gmail.com (ted) Date: Mon, 2 Feb 2009 11:28:41 -0800 (PST) Subject: Financial aid for PyCon 2009 is now available Message-ID: <73639627-b579-4d0c-a6e3-68442fa16414@p36g2000prp.googlegroups.com> I'm happy to announce that the Python Software Foundation has allocated some funds to help people attend PyCon 2009! If you would like to come to PyCon but can't afford it, the PSF may be able to help you pay for registration, lodging/hotel costs and transportation (flight etc.). Please see http://us.pycon.org/2009/registration/financial-aid/ for full details, or email pycon-aid at python.org with any questions. From aahz at pythoncraft.com Mon Feb 2 14:42:10 2009 From: aahz at pythoncraft.com (Aahz) Date: 2 Feb 2009 11:42:10 -0800 Subject: Where to put configuration/data files References: Message-ID: In article , Jay Bloodworth wrote: > >Is there a nice cross-platform way to figure out the Right (tm) place to >store configuration files and other data? For what purpose? Global program config, user config, what? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From eric.shain at gmail.com Mon Feb 2 14:45:20 2009 From: eric.shain at gmail.com (Eric) Date: Mon, 2 Feb 2009 11:45:20 -0800 (PST) Subject: Combining several text files References: Message-ID: <5e8c1433-f1d5-4242-bc64-24d02725a79b@z28g2000prd.googlegroups.com> On Feb 2, 12:17?pm, Chris Rebert wrote: > On Mon, Feb 2, 2009 at 9:48 AM, Eric wrote: > > This is my first post, so please advise if I'm not using proper > > etiquette. I've actually searched around a bit and while I think I can > > do this, I can't think of a clean elegant way. I'm pretty new to > > Python, but from what I've learned so far is that there is almost > > always an easier way. > > > I have to parse several log files. I've already written a working > > parser. The log files are simple text files that when they get to a > > certain size are renamed to append a number. So, you might end up > > with: > > > filename.log.2 > > filename.log.1 > > filename.log > > > The higher the number, the older the file. I want to search for all > > the files in a directory with "filename.log" as part of their name. > > Then I can do one of two things. First I could combine them so that > > the resulting file ends up with the oldest on top and newest on the > > bottom. Otherwise, I could just iterate over the multiple files within > > my parser. > > > I don't need working code (that makes things too easy), just clear > > suggestions to a Python newcomer to speed me on my way. > > For listing the filenames, you'll want to use os.listdir:http://docs.python.org/library/os.html#os.listdir > > or possibly the `glob` module depending on your needs:http://docs.python.org/library/glob.html > > Cheers, > Chris > > -- > Follow the path of the Iguana...http://rebertia.com That wasn't too hard at all. I even found the construct: logfile = [elem for elem in files if elem.find(ln) >= 0] For my own interest, is there an easy way once I have the file names to create a single concatenated file? Thanks, Eric From mdw at distorted.org.uk Mon Feb 2 14:50:33 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Mon, 02 Feb 2009 19:50:33 +0000 Subject: Number of bits/sizeof int References: Message-ID: <877i48obxy.fsf.mdw@metalzone.distorted.org.uk> Jon Clements writes: > "The int() type gained a bit_length method that returns the number of > bits necessary to represent its argument in binary:" > > Any tips on how to get this in 2.5.2 as that's the production version > I'm stuck with. def nbits(x): ## Special cases. if x == 0: return 0 elif x < 0: x = -x ## Find upper bound of the form 2^(2^n) >= x. n = 1 while True: y = x >> n if y == 0: break x = y n <<= 1 ## Now binary search until we're done. a = n while n > 0: n >>= 1 y = x >> n if y > 0: x = y a += n return a -- [mdw] From rdmurray at bitdance.com Mon Feb 2 14:55:37 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Mon, 2 Feb 2009 19:55:37 +0000 (UTC) Subject: What is wrong in my list comprehension? References: <44116a3e-0f4a-418f-9ada-dc917ec592d5@j35g2000yqh.googlegroups.com> <873aew24ql.fsf@agentultra.com> <87r62gzqd0.fsf@agentultra.com> <7a9c25c20902021018m7a4112edv3a282d9b0ba187a5@mail.gmail.com> Message-ID: Quoth Stephen Hansen : > I just think at this point ".find" is just not the right method to use; > "substring" in "string" is the way to determine what he wants is all. > ".find" is useful for when you want the actual position, not when you just > want to determine if there's a match at all. The way I'd clean it is to > remove .find, personally :) I don't remember the outcome of their discussion > on py-dev, and haven't gotten around to loading up Py3 to test it out :) Python 3.0 (r30:67503, Dec 18 2008, 19:09:30) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> help(''.find) Help on built-in function find: find(...) S.find(sub[, start[, end]]) -> int Return the lowest index in S where substring sub is found, such that sub is contained within s[start:end]. Optional arguments start and end are interpreted as in slice notation. Return -1 on failure. From kyosohma at gmail.com Mon Feb 2 15:10:17 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Mon, 2 Feb 2009 12:10:17 -0800 (PST) Subject: Reading text file with wierd file extension? References: <887b7e96-b0cc-4dea-8c1a-76c60ebffad3@t26g2000prh.googlegroups.com> Message-ID: <1e517f65-816e-4317-bb8c-0d9ee06041dd@r15g2000prd.googlegroups.com> On Feb 2, 1:20?pm, Lionel wrote: > On Feb 2, 10:41?am, Mike Driscoll wrote: > > > > > On Feb 2, 12:36?pm, Lionel wrote: > > > > Hi Folks, Python newbie here. > > > > I'm trying to open (for reading) a text file with the following > > > filenaming convension: > > > > "MyTextFile.slc.rsc" > > > > My code is as follows: > > > > Filepath = "C:\\MyTextFile.slc.rsc" > > > FileH = open(Filepath) > > > > The above throws an IOError exception. On a hunch I changed the > > > filename (only the filename) and tried again: > > > > Filepath = "C:\\MyTextFile.txt" > > > FileH = open(Filepath) > > > > The above works well. I am able to open the file and read it's > > > contents. I assume to read a file in text file "mode" the parameter is > > > scanned for a ".txt" extension, otherwise the Python runtime doesn't > > > know what version of "open(...)" to invoke. How do I pass the original > > > filename (MyTextFile.slc.rsc) and get Python to open it as a text > > > file? Thanks in advance everyone! > > > The extension shouldn't matter. I tried creating a file with the same > > extension as yours and Python 2.5.2 opened it and read it no problem. > > I tried it in IDLE and with Wing on Windows XP. What are you using? > > What's the complete traceback? > > > Mike- Hide quoted text - > > > - Show quoted text - > > Hi Mike, > > maybe it's not a "true" text file? Opening it in Microsoft Notepad > gives an unformatted view of the file (text with no line wrapping, > just the end-of-line square box character followed by more text, end- > of-line character, etc). Wordpad opens it properly i.e. respects the > end-of-line wrapping. I'm unsure of how these files are being > generated, I was just given them and told they wanted to be able to > read them. > > How do I collect the traceback to post it? The traceback should look something like this fake one: Traceback (most recent call last): File "", line 1, in raise IOError IOError Just copy and paste it in your next message. The other guys are probably right in that it is a line ending issue, but as they and I have said, Python shouldn't care (and doesn't on my machine). Mike From rdmurray at bitdance.com Mon Feb 2 15:18:30 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Mon, 2 Feb 2009 20:18:30 +0000 (UTC) Subject: Combining several text files References: Message-ID: Quoth Eric : > This is my first post, so please advise if I'm not using proper > etiquette. I've actually searched around a bit and while I think I can > do this, I can't think of a clean elegant way. I'm pretty new to > Python, but from what I've learned so far is that there is almost > always an easier way. > > I have to parse several log files. I've already written a working > parser. The log files are simple text files that when they get to a > certain size are renamed to append a number. So, you might end up > with: > > filename.log.2 > filename.log.1 > filename.log > > The higher the number, the older the file. I want to search for all > the files in a directory with "filename.log" as part of their name. > Then I can do one of two things. First I could combine them so that > the resulting file ends up with the oldest on top and newest on the > bottom. Otherwise, I could just iterate over the multiple files within > my parser. > > I don't need working code (that makes things too easy), just clear > suggestions to a Python newcomer to speed me on my way. My first thought would be to do something like this (assuming you are on a unix variant): yourscript `ls -tr filename.log*` and then in 'yourscript' do: import fileinput for line in fileinput.input(): #process the lines This has the nice advantage of giving you access to the source filename and line number within its source file of each line, in case that is useful. This is an example of why Python is referred to as "Batteries Included" :) --RDM From callen314 at gmail.com Mon Feb 2 15:21:07 2009 From: callen314 at gmail.com (Craig Allen) Date: Mon, 2 Feb 2009 12:21:07 -0800 (PST) Subject: Does the Python community really follow the philospy of "Community Matters?" References: <15bc25c2-4fa7-4efa-aa66-7c403acb3cc5@f29g2000vbf.googlegroups.com> <2d459946-2216-42f7-87f8-9f0cde1fd060@l16g2000yqo.googlegroups.com> Message-ID: <1580d92d-602b-4eb2-acce-3c33a3ee2301@b38g2000prf.googlegroups.com> I think what you have found is a remarkable characteristic of this language. Somehow, perhaps something to do with guido or python itself, python has a very strong non-dogmatic streak. It's a relief really. If I were to pose a "is python or its community really xyz?" I would wonder about the "one best way to do something". One of my first posts here was about three different ways I had built singletons. As a result of that I was given a better way, but no one said any of the other ways were "non-pythonic", it was more, "if you use option one, make sure of this, if you use option two, don't forget that"... As such, python programmers are not there for you to feel superior. If you want a language for a feeling of community, then it hardly matters what language you choose, and if you want a good language, it's secondary if the community gives you that feeling (you should get it from the language itself). And since there IS a python community to go to for help, python has that covered without worrying about it or making it a language feature. It may seems cold, instead of giving warm fuzzies, people will help you with tangible problems, but we are not starting a commune. "Uses a langague with sense of community that advocates for their language over others" is never in a spec. -craig From jervisau at gmail.com Mon Feb 2 15:30:52 2009 From: jervisau at gmail.com (Jervis Whitley) Date: Tue, 3 Feb 2009 07:30:52 +1100 Subject: Comparing dates? In-Reply-To: <65bde456-45cb-434d-a60f-b2c0648155a7@g39g2000pri.googlegroups.com> References: <87bptl1a4l.fsf@benfinney.id.au> <5tkdo4l21dkm9kgv4ra4pftker89odebfu@4ax.com> <65bde456-45cb-434d-a60f-b2c0648155a7@g39g2000pri.googlegroups.com> Message-ID: <8e63a5ce0902021230y74718b71rb8b33b784534d92b@mail.gmail.com> > Most > will have functions like str[pf]time that could be used to similar > effect. In mysql this is: str_to_date( '21/02/2008', '%d/%m/%Y') and oracle: to_date( '21/02/2008', 'dd-mm-yyyy') Cheers, From lionel.keene at gmail.com Mon Feb 2 15:33:36 2009 From: lionel.keene at gmail.com (Lionel) Date: Mon, 2 Feb 2009 12:33:36 -0800 (PST) Subject: Reading text file with wierd file extension? References: <887b7e96-b0cc-4dea-8c1a-76c60ebffad3@t26g2000prh.googlegroups.com> <1e517f65-816e-4317-bb8c-0d9ee06041dd@r15g2000prd.googlegroups.com> Message-ID: On Feb 2, 12:10?pm, Mike Driscoll wrote: > On Feb 2, 1:20?pm, Lionel wrote: > > > > > > > On Feb 2, 10:41?am, Mike Driscoll wrote: > > > > On Feb 2, 12:36?pm, Lionel wrote: > > > > > Hi Folks, Python newbie here. > > > > > I'm trying to open (for reading) a text file with the following > > > > filenaming convension: > > > > > "MyTextFile.slc.rsc" > > > > > My code is as follows: > > > > > Filepath = "C:\\MyTextFile.slc.rsc" > > > > FileH = open(Filepath) > > > > > The above throws an IOError exception. On a hunch I changed the > > > > filename (only the filename) and tried again: > > > > > Filepath = "C:\\MyTextFile.txt" > > > > FileH = open(Filepath) > > > > > The above works well. I am able to open the file and read it's > > > > contents. I assume to read a file in text file "mode" the parameter is > > > > scanned for a ".txt" extension, otherwise the Python runtime doesn't > > > > know what version of "open(...)" to invoke. How do I pass the original > > > > filename (MyTextFile.slc.rsc) and get Python to open it as a text > > > > file? Thanks in advance everyone! > > > > The extension shouldn't matter. I tried creating a file with the same > > > extension as yours and Python 2.5.2 opened it and read it no problem. > > > I tried it in IDLE and with Wing on Windows XP. What are you using? > > > What's the complete traceback? > > > > Mike- Hide quoted text - > > > > - Show quoted text - > > > Hi Mike, > > > maybe it's not a "true" text file? Opening it in Microsoft Notepad > > gives an unformatted view of the file (text with no line wrapping, > > just the end-of-line square box character followed by more text, end- > > of-line character, etc). Wordpad opens it properly i.e. respects the > > end-of-line wrapping. I'm unsure of how these files are being > > generated, I was just given them and told they wanted to be able to > > read them. > > > How do I collect the traceback to post it? > > The traceback should look something like this fake one: > > Traceback (most recent call last): > ? File "", line 1, in > ? ? raise IOError > IOError > > Just copy and paste it in your next message. The other guys are > probably right in that it is a line ending issue, but as they and I > have said, Python shouldn't care (and doesn't on my machine). > > Mike- Hide quoted text - > > - Show quoted text - Okay, I think I see what's going on. My class takes a single parameter when it is instantiated...the file path of the data file the user wants to open. This is of the form "someFile.slc". In the same directory of "someFile.slc" is a resource file that (like a file header) contains a host of parameters associated with the data file. The resource file is of the form "someFile.slc.rsc". So, when the user creates an instance of my class which, it invokes the __init__ method where I add the ".rsc" extension to the original filename/path parameter that was passed to the class "constructor". For example: Note: try-catch blocks ommitted. class MyUtilityClass: def __init__(self, DataFilepath): Resourcepath = DataFilepath + ".rsc" DataFileH = open(DataFilepath) ResourceFileH = open(Resourcepath) Invoking this from the Python shell explicitly is no problem i.e. "TestH = open("C:\\TestResourceFile.slc.rsc") works. BUT...something is lost when I append the ".rsc" extension to the DataFilePath parameter as above. When the __init__ method is invoked, Python will open the data file but generates the exception with the "open (Resourcepath)" instruction. I think it is somehow related to the backslashes but I'm not entirely sure of this. Any ideas? Thanks for the help folks. From vicente.soler at gmail.com Mon Feb 2 15:46:34 2009 From: vicente.soler at gmail.com (vsoler) Date: Mon, 2 Feb 2009 12:46:34 -0800 (PST) Subject: Source code for csv module Message-ID: <62a2e93e-3b86-44bc-9286-56333edd97f6@t26g2000prh.googlegroups.com> Hi you all, I just discovered the csv module here in the comp.lang.python group. I have found its manual, which is publicly available, but since I am still a newby, learning techniques, I was wondering if the source code for this module is available. Is it possible to have a look at it? Thanks From joncle at googlemail.com Mon Feb 2 15:51:13 2009 From: joncle at googlemail.com (Jon Clements) Date: Mon, 2 Feb 2009 12:51:13 -0800 (PST) Subject: Source code for csv module References: <62a2e93e-3b86-44bc-9286-56333edd97f6@t26g2000prh.googlegroups.com> Message-ID: <55c2db4e-8c89-4443-897b-b7ef92e263f1@l33g2000pri.googlegroups.com> On 2 Feb, 20:46, vsoler wrote: > Hi you all, > > I just discovered the csv module here in the comp.lang.python group. > > I have found its manual, which is publicly available, but since I am > still a newby, learning techniques, I was wondering if the source code > for this module is available. > > Is it possible to have a look at it? > > Thanks The csv module is a wrapper around a C extension. If you're happy reading C code then downloading the Python sources will let you take a goosey. Jon. From andrew at acooke.org Mon Feb 2 15:53:00 2009 From: andrew at acooke.org (andrew cooke) Date: Mon, 2 Feb 2009 12:53:00 -0800 (PST) Subject: Where to host a (Python) project? References: <387f23cd-90e2-46fc-8c91-1c2f6b31c89e@u13g2000yqg.googlegroups.com> Message-ID: <6dcb8ce5-c93e-458c-9047-e5db60f27d90@v18g2000pro.googlegroups.com> On Feb 1, 8:45?pm, a... at pythoncraft.com (Aahz) wrote: > [...]?I for one won't participate in any list hosted on > Google because of the need for a Google login. hi, just fyi, i investigated this and you can join any publicly readable group by sending an email to the "-subscribe" address. you do not need a google login for this and, as far as i can tell, it then operates for you like a normal mailing list. for example, to subscribe to the group foo, you would send an email to foo-subscribe at googlegroups.com. to unsubscribe, use foo- unsubscribe at googlegroups.com. this isn't exactly well-publicised, but i tested it and it does work. andrew From dickinsm at gmail.com Mon Feb 2 15:57:13 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Mon, 2 Feb 2009 12:57:13 -0800 (PST) Subject: Number of bits/sizeof int References: Message-ID: <8375c702-75f7-4bcc-85bb-068828af6a6d@f40g2000pri.googlegroups.com> On Jan 31, 7:03?am, Jon Clements wrote: > Any tips on how to get this in 2.5.2 as that's the production version > I'm stuck with. It's a bit cheeky, but: from decimal import _nbits as nbits should also work in 2.5.2 (but not in 2.5.1)! Mark From vicente.soler at gmail.com Mon Feb 2 15:57:39 2009 From: vicente.soler at gmail.com (vsoler) Date: Mon, 2 Feb 2009 12:57:39 -0800 (PST) Subject: Source code for csv module References: <62a2e93e-3b86-44bc-9286-56333edd97f6@t26g2000prh.googlegroups.com> <55c2db4e-8c89-4443-897b-b7ef92e263f1@l33g2000pri.googlegroups.com> Message-ID: <598543ea-2340-41dd-bc76-b787d12148ba@v5g2000prm.googlegroups.com> On 2 feb, 21:51, Jon Clements wrote: > On 2 Feb, 20:46, vsoler wrote: > > > Hi you all, > > > I just discovered the csv module here in the comp.lang.python group. > > > I have found its manual, which is publicly available, but since I am > > still a newby, learning techniques, I was wondering if the source code > > for this module is available. > > > Is it possible to have a look at it? > > > Thanks > > The csv module is a wrapper around a C extension. If you're happy > reading C code then downloading the Python sources will let you take a > goosey. > > Jon. I'm still interested in learning python techniques. Are there any other modules (standard or complementary) that I can use in my education? From python.list at tim.thechases.com Mon Feb 2 15:58:15 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 02 Feb 2009 14:58:15 -0600 Subject: Source code for csv module In-Reply-To: <62a2e93e-3b86-44bc-9286-56333edd97f6@t26g2000prh.googlegroups.com> References: <62a2e93e-3b86-44bc-9286-56333edd97f6@t26g2000prh.googlegroups.com> Message-ID: <49875E67.2090703@tim.thechases.com> > I just discovered the csv module here in the comp.lang.python > group. It certainly makes life easier. > I have found its manual, which is publicly available, but > since I am still a newby, learning techniques, I was wondering > if the source code for this module is available. > > Is it possible to have a look at it? Yep...the source csv.py is likely already on your computer: >>> import csv >>> csv.__file__ '/usr/lib/python2.5/csv.pyc' tchase at asgix2:~$ ls /usr/lib/python2.5/csv.* /usr/lib/python2.5/csv.py /usr/lib/python2.5/csv.pyc Same idea in Windows: >>> import csv >>> csv.__file__ 'C:\\Program Files\\Python24\\lib\\csv.pyc' c:\> dir "\Program Files\Python24\lib\csv.*" ... Just about all the modules in the standard library have python source in this same directory, so you can spelunk within. -tkc From david.lyon at preisshare.net Mon Feb 2 15:58:22 2009 From: david.lyon at preisshare.net (David Lyon) Date: Mon, 02 Feb 2009 15:58:22 -0500 Subject: Python package Management GUI - New Project on Sourceforge In-Reply-To: <014ede68-a0e8-4e4b-876d-98edef3059ec@i20g2000prf.googlegroups.com> References: <0f1ee3b4-e4c1-4ae4-9d6d-1184c6e20ce3@i24g2000prf.googlegroups.com> <497FAFE4.4040602@gmail.com> <83900549676010b8244969ece9319a78@preisshare.net> <014ede68-a0e8-4e4b-876d-98edef3059ec@i20g2000prf.googlegroups.com> Message-ID: <38eb2cc708c7252ef55aca51a4b74edb@preisshare.net> Hi Dave, > As of now, Enstaller 3.x is a command-line only tool but it does > provide a lot of benefits over standard setuptools -- uninstall, > update/upgrade command, found eggs aren't pre-pended to the full > sys.path but instead inserted before the containing directory, etc. Sounds extremely powerful. Maye I should be looking at offering support for driving Enstaller to the GUI tool. I think I will... Regards David From martin at marcher.name Mon Feb 2 16:00:53 2009 From: martin at marcher.name (Martin) Date: Mon, 2 Feb 2009 22:00:53 +0100 Subject: [2.5.1] Comparing dates? In-Reply-To: <5tkdo4l21dkm9kgv4ra4pftker89odebfu@4ax.com> References: <87bptl1a4l.fsf@benfinney.id.au> <5tkdo4l21dkm9kgv4ra4pftker89odebfu@4ax.com> Message-ID: <5fa6c12e0902021300u6e2d774egd8ab5c297c47bb59@mail.gmail.com> Hi, 2009/2/2 Gilles Ganault : > Thanks guys. For those interested, here's how to perform the > conversion from DD/MM/YYYY to YYYY-MM-DD: as suggested, the DBA should seriously think about defining the correct type of the column here, for intermediate use and getting stuff to work you could use a view and define some stored procedures on it so that inserting properly works... ---snip plain psql--- test=# CREATE table date_test( id serial primary key, the_date timestamp with time zone, stuff Text ); NOTICE: CREATE TABLE will create implicit sequence "date_test_id_seq" for serial column "date_test.id" NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "date_test_pkey" for table "date_test" CREATE TABLE test=# INSERT INTO date_test (the_date) VALUES ('20091231'); INSERT 0 1 test=# INSERT INTO date_test (the_date) VALUES ('20081231'); INSERT 0 1 test=# INSERT INTO date_test (the_date) VALUES ('20071231'); INSERT 0 1 test=# SELECT * from date_test; id | the_date | stuff ----+------------------------+------- 1 | 2009-12-31 00:00:00+01 | 2 | 2008-12-31 00:00:00+01 | 3 | 2007-12-31 00:00:00+01 | (3 rows) ---snap plain psql--- ---snip now in python--- from datetime import datetime d = datetime(day=21, month=21, year=2008) # use a real datetime without string fiddling import psycopg2 db = psycopg2.connect(host='localhost', user='test', password='test', database='test') cursor = db.cursor() cursor.execute("select * from date_test where the_date < '20080221'") # OK simple SELECT for row in cursor: print row # (3, datetime.datetime(2007, 12, 31, 0, 0, tzinfo=), None) ## kill SQL injection stuff, also personally I find this more convenient that fiddling with strings... cursor.execute("select * from date_test where the_date < %s", (d, )) for row in cursor: print row (3, datetime.datetime(2007, 12, 31, 0, 0, tzinfo=), None) ---snap now in python--- -- http://soup.alt.delete.co.at http://www.xing.com/profile/Martin_Marcher http://www.linkedin.com/in/martinmarcher You are not free to read this message, by doing so, you have violated my licence and are required to urinate publicly. Thank you. Please avoid sending me Word or PowerPoint attachments. See http://www.gnu.org/philosophy/no-word-attachments.html From deets at nospam.web.de Mon Feb 2 16:07:23 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 02 Feb 2009 22:07:23 +0100 Subject: Reading text file with wierd file extension? In-Reply-To: References: <887b7e96-b0cc-4dea-8c1a-76c60ebffad3@t26g2000prh.googlegroups.com> <1e517f65-816e-4317-bb8c-0d9ee06041dd@r15g2000prd.googlegroups.com> Message-ID: <6up5kbFglf13U1@mid.uni-berlin.de> Lionel schrieb: > On Feb 2, 12:10 pm, Mike Driscoll wrote: >> On Feb 2, 1:20 pm, Lionel wrote: >> >> >> >> >> >>> On Feb 2, 10:41 am, Mike Driscoll wrote: >>>> On Feb 2, 12:36 pm, Lionel wrote: >>>>> Hi Folks, Python newbie here. >>>>> I'm trying to open (for reading) a text file with the following >>>>> filenaming convension: >>>>> "MyTextFile.slc.rsc" >>>>> My code is as follows: >>>>> Filepath = "C:\\MyTextFile.slc.rsc" >>>>> FileH = open(Filepath) >>>>> The above throws an IOError exception. On a hunch I changed the >>>>> filename (only the filename) and tried again: >>>>> Filepath = "C:\\MyTextFile.txt" >>>>> FileH = open(Filepath) >>>>> The above works well. I am able to open the file and read it's >>>>> contents. I assume to read a file in text file "mode" the parameter is >>>>> scanned for a ".txt" extension, otherwise the Python runtime doesn't >>>>> know what version of "open(...)" to invoke. How do I pass the original >>>>> filename (MyTextFile.slc.rsc) and get Python to open it as a text >>>>> file? Thanks in advance everyone! >>>> The extension shouldn't matter. I tried creating a file with the same >>>> extension as yours and Python 2.5.2 opened it and read it no problem. >>>> I tried it in IDLE and with Wing on Windows XP. What are you using? >>>> What's the complete traceback? >>>> Mike- Hide quoted text - >>>> - Show quoted text - >>> Hi Mike, >>> maybe it's not a "true" text file? Opening it in Microsoft Notepad >>> gives an unformatted view of the file (text with no line wrapping, >>> just the end-of-line square box character followed by more text, end- >>> of-line character, etc). Wordpad opens it properly i.e. respects the >>> end-of-line wrapping. I'm unsure of how these files are being >>> generated, I was just given them and told they wanted to be able to >>> read them. >>> How do I collect the traceback to post it? >> The traceback should look something like this fake one: >> >> Traceback (most recent call last): >> File "", line 1, in >> raise IOError >> IOError >> >> Just copy and paste it in your next message. The other guys are >> probably right in that it is a line ending issue, but as they and I >> have said, Python shouldn't care (and doesn't on my machine). >> >> Mike- Hide quoted text - >> >> - Show quoted text - > > Okay, I think I see what's going on. My class takes a single parameter > when it is instantiated...the file path of the data file the user > wants to open. This is of the form "someFile.slc". In the same > directory of "someFile.slc" is a resource file that (like a file > header) contains a host of parameters associated with the data file. > The resource file is of the form "someFile.slc.rsc". So, when the user > creates an instance of my class which, it invokes the __init__ method > where I add the ".rsc" extension to the original filename/path > parameter that was passed to the class "constructor". For example: > > Note: try-catch blocks ommitted. > > class MyUtilityClass: > def __init__(self, DataFilepath): > Resourcepath = DataFilepath + ".rsc" > DataFileH = open(DataFilepath) > ResourceFileH = open(Resourcepath) > > > Invoking this from the Python shell explicitly is no problem i.e. > "TestH = open("C:\\TestResourceFile.slc.rsc") works. BUT...something > is lost when I append the ".rsc" extension to the DataFilePath > parameter as above. When the __init__ method is invoked, Python will > open the data file but generates the exception with the "open > (Resourcepath)" instruction. I think it is somehow related to the > backslashes but I'm not entirely sure of this. Any ideas? This is written very slowly, so you can read it better: Please post the traceback. Diez From martin at marcher.name Mon Feb 2 16:09:18 2009 From: martin at marcher.name (Martin) Date: Mon, 2 Feb 2009 22:09:18 +0100 Subject: database wrapper ? In-Reply-To: <4986289C.3030205@gmail.com> References: <4986289C.3030205@gmail.com> Message-ID: <5fa6c12e0902021309v8743e59v6413ce9bd7894dcd@mail.gmail.com> Hi, 2009/2/1 Stef Mientki : > Googling, I found SQLalchemy, > which looks quit good. sqlalchemy was always enough for my needs, I recently found elixir which is yet another wrapper around sqlalchemy. I haven't played too much with it but it seems there are a couple of nice things, that is elixir makes using sqlalchemy even easier. hth martin -- http://soup.alt.delete.co.at http://www.xing.com/profile/Martin_Marcher http://www.linkedin.com/in/martinmarcher You are not free to read this message, by doing so, you have violated my licence and are required to urinate publicly. Thank you. Please avoid sending me Word or PowerPoint attachments. See http://www.gnu.org/philosophy/no-word-attachments.html From steve at holdenweb.com Mon Feb 2 16:18:22 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 02 Feb 2009 16:18:22 -0500 Subject: Threading / Queue management In-Reply-To: References: Message-ID: Power Button wrote: > hi there, > > I wonder if anyone can help with the following. I have written a > script which polls a server and if it finds and pending orders, it > instantiates an new object (foo) - in a new thread and processes some > data. In the new object (foo), there are also some long running > processes so I am trying to create a thread pool/queue and to push > items onto the queue in the instantiated object (foo). Currently I am > creating the Queue in foo but this means I am starting up 5 new > threads every time I instantiate foo. What I want to be able to do is > create the Queue and start 5 (n) threads when my program starts and > then push items onto the queue in foo. > > My question is, how can I create the Queue in my main object and set > the target function for the Thread Constructor to be a function in > foo? > This might help. http://www.chrisarndt.de/projects/threadpool/ If not, Google around for "Python threadpool". If that doesn't help either, come back to the list. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From apt.shansen at gmail.com Mon Feb 2 16:29:55 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 2 Feb 2009 13:29:55 -0800 Subject: Reading text file with wierd file extension? In-Reply-To: References: <887b7e96-b0cc-4dea-8c1a-76c60ebffad3@t26g2000prh.googlegroups.com> <1e517f65-816e-4317-bb8c-0d9ee06041dd@r15g2000prd.googlegroups.com> Message-ID: <7a9c25c20902021329y4d25d597v652410b4a185f728@mail.gmail.com> > class MyUtilityClass: > def __init__(self, DataFilepath): > Resourcepath = DataFilepath + ".rsc" > DataFileH = open(DataFilepath) > ResourceFileH = open(Resourcepath) There's nothing wrong with this code. You have to look elsewhere in your program-- perhaps what calls it. Perhaps in the filesystem to ensure there really happens to be a rsc for this data file (maybe it got accidentally deleted?) Before you do any openings, try printing like: print repr(DataFilepath) print repr(Resourcepath) print os.path.exists(Resourcepath) print os.listdir(os.dirname(Resourcepath)) Something must jump out at that point to be obviously the problem. If not and you still get a traceback, try mailing the list the output and the actual traceback. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From sjmachin at lexicon.net Mon Feb 2 16:36:22 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 2 Feb 2009 13:36:22 -0800 (PST) Subject: Number of bits/sizeof int References: <877i48obxy.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <7d8c7677-e1e1-4d6a-9615-58144f776a59@t26g2000prh.googlegroups.com> On Feb 3, 6:50?am, Mark Wooding wrote: > Jon Clements writes: > > "The int() type gained a bit_length method that returns the number of > > bits necessary to represent its argument in binary:" > > > Any tips on how to get this in 2.5.2 as that's the production version > > I'm stuck with. > > def nbits(x): > > ? ## Special cases. > ? if x == 0: return 0 > ? elif x < 0: x = -x 3 can be represented in 2 bits and at the same time -3 can be represented in 2 bits?? But 2 bits can support only 2 ** 2 == 4 different possibilities, and -3 .. 3 is 7 different integers. > ? ## Find upper bound of the form 2^(2^n) >= x. Possibly you mean 2 ** ( 2 ** n) >= x From jason.scheirer at gmail.com Mon Feb 2 16:41:33 2009 From: jason.scheirer at gmail.com (Jason Scheirer) Date: Mon, 2 Feb 2009 13:41:33 -0800 (PST) Subject: What is wrong in my list comprehension? References: <44116a3e-0f4a-418f-9ada-dc917ec592d5@j35g2000yqh.googlegroups.com> Message-ID: <8454f0fd-ce56-47aa-a450-8a01fb72d0b0@x6g2000pre.googlegroups.com> On Feb 1, 3:37?am, Peter Otten <__pete... at web.de> wrote: > Hussein B wrote: > > Hey, > > I have a log file that doesn't contain the word "Haskell" at all, I'm > > just trying to do a little performance comparison: > > ++++++++++++++ > > from datetime import time, timedelta, datetime > > start = datetime.now() > > print start > > lines = [line for line in file('/media/sda4/Servers/Apache/ > > Tomcat-6.0.14/logs/catalina.out') if line.find('Haskell')] > > print 'Number of lines contains "Haskell" = ' + ?str(len(lines)) > > end = datetime.now() > > print end > > ++++++++++++++ > > Well, the script is returning the whole file's lines number !! > > What is wrong in my logic? > > Thanks. > > """ > find(...) > ? ? S.find(sub [,start [,end]]) -> int > > ? ? Return the lowest index in S where substring sub is found, > ? ? such that sub is contained within s[start:end]. ?Optional > ? ? arguments start and end are interpreted as in slice notation. > > ? ? Return -1 on failure. > """ > > a.find(b) returns -1 if b is no found. -1 evaluates to True in a boolean > context. > > Use > > [line for line in open(...) if line.find("Haskell") != -1] > > or, better > > [line for line in open(...) if "Haskell" in line] > > to get the expected result. > > Peter Or better, group them together in a generator: sum(line for line in open(...) if "Haskell" in line) and avoid allocating a new list with every line that contains Haskell in it. http://www.python.org/dev/peps/pep-0289/ From lionel.keene at gmail.com Mon Feb 2 16:43:26 2009 From: lionel.keene at gmail.com (Lionel) Date: Mon, 2 Feb 2009 13:43:26 -0800 (PST) Subject: Reading text file with wierd file extension? References: <887b7e96-b0cc-4dea-8c1a-76c60ebffad3@t26g2000prh.googlegroups.com> <1e517f65-816e-4317-bb8c-0d9ee06041dd@r15g2000prd.googlegroups.com> <6up5kbFglf13U1@mid.uni-berlin.de> Message-ID: On Feb 2, 1:07?pm, "Diez B. Roggisch" wrote: This is written very slowly, so you can read it better: Please post without sarcasm. This is the output from my Python shell: >>> DatafilePath = "C:\\C8Example1.slc" >>> ResourcefilePath = DatafilePath + ".rsc" >>> DatafileFH = open(DatafilePath) >>> ResourceFh = open(ResourcefilePath) >>> DatafilePath 'C:\\C8Example1.slc' >>> ResourcefilePath 'C:\\C8Example1.slc.rsc' It seems to run without trouble. However, here is the offending code in my class (followed by console output): class C8DataType: def __init__(self, DataFilepath): try: DataFH = open(DataFilepath, "rb") except IOError, message: # Error opening file. print(message) return None ResourceFilepath = DataFilepath + ".src" print(DataFilepath) print(ResourceFilepath) # Try to open resource file, catch exception: try: ResourceFH = open(ResourceFilepath) except IOError, message: # Error opening file. print(message) print("Error opening " + ResourceFilepath) DataFH.close() return None Console output when invoking as "someObject = C8DataType("C:\ \C8Example1.slc")" : C:\C8Example1.slc C:\C8Example1.slc.src [Errno 2] No such file or directory: 'C:\\C8Example1.slc.src' Error opening C:\C8Example1.slc.src Thank you > Lionel schrieb: > > > > > > > On Feb 2, 12:10 pm, Mike Driscoll wrote: > >> On Feb 2, 1:20 pm, Lionel wrote: > > >>> On Feb 2, 10:41 am, Mike Driscoll wrote: > >>>> On Feb 2, 12:36 pm, Lionel wrote: > >>>>> Hi Folks, Python newbie here. > >>>>> I'm trying to open (for reading) a text file with the following > >>>>> filenaming convension: > >>>>> "MyTextFile.slc.rsc" > >>>>> My code is as follows: > >>>>> Filepath = "C:\\MyTextFile.slc.rsc" > >>>>> FileH = open(Filepath) > >>>>> The above throws an IOError exception. On a hunch I changed the > >>>>> filename (only the filename) and tried again: > >>>>> Filepath = "C:\\MyTextFile.txt" > >>>>> FileH = open(Filepath) > >>>>> The above works well. I am able to open the file and read it's > >>>>> contents. I assume to read a file in text file "mode" the parameter is > >>>>> scanned for a ".txt" extension, otherwise the Python runtime doesn't > >>>>> know what version of "open(...)" to invoke. How do I pass the original > >>>>> filename (MyTextFile.slc.rsc) and get Python to open it as a text > >>>>> file? Thanks in advance everyone! > >>>> The extension shouldn't matter. I tried creating a file with the same > >>>> extension as yours and Python 2.5.2 opened it and read it no problem. > >>>> I tried it in IDLE and with Wing on Windows XP. What are you using? > >>>> What's the complete traceback? > >>>> Mike- Hide quoted text - > >>>> - Show quoted text - > >>> Hi Mike, > >>> maybe it's not a "true" text file? Opening it in Microsoft Notepad > >>> gives an unformatted view of the file (text with no line wrapping, > >>> just the end-of-line square box character followed by more text, end- > >>> of-line character, etc). Wordpad opens it properly i.e. respects the > >>> end-of-line wrapping. I'm unsure of how these files are being > >>> generated, I was just given them and told they wanted to be able to > >>> read them. > >>> How do I collect the traceback to post it? > >> The traceback should look something like this fake one: > > >> Traceback (most recent call last): > >> ? File "", line 1, in > >> ? ? raise IOError > >> IOError > > >> Just copy and paste it in your next message. The other guys are > >> probably right in that it is a line ending issue, but as they and I > >> have said, Python shouldn't care (and doesn't on my machine). > > >> Mike- Hide quoted text - > > >> - Show quoted text - > > > Okay, I think I see what's going on. My class takes a single parameter > > when it is instantiated...the file path of the data file the user > > wants to open. This is of the form "someFile.slc". In the same > > directory of "someFile.slc" is a resource file that (like a file > > header) contains a host of parameters associated with the data file. > > The resource file is of the form "someFile.slc.rsc". So, when the user > > creates an instance of my class which, it invokes the __init__ method > > where I add the ".rsc" extension to the original filename/path > > parameter that was passed to the class "constructor". For example: > > > Note: try-catch blocks ommitted. > > > class MyUtilityClass: > > ? ? def __init__(self, DataFilepath): > > ? ? ? ? Resourcepath ?= DataFilepath + ".rsc" > > ? ? ? ? DataFileH ? ? = open(DataFilepath) > > ? ? ? ? ResourceFileH = open(Resourcepath) > > > Invoking this from the Python shell explicitly is no problem i.e. > > "TestH = open("C:\\TestResourceFile.slc.rsc") works. BUT...something > > is lost when I append the ".rsc" extension to the DataFilePath > > parameter as above. When the __init__ method is invoked, Python will > > open the data file but generates the exception with the "open > > (Resourcepath)" instruction. I think it is somehow related to the > > backslashes but I'm not entirely sure of this. Any ideas? > > This is written very slowly, so you can read it better: > > Please post the traceback. > > Diez- Hide quoted text - > > - Show quoted text - From drkjam at gmail.com Mon Feb 2 16:48:14 2009 From: drkjam at gmail.com (David Moss) Date: Mon, 2 Feb 2009 13:48:14 -0800 (PST) Subject: the 'right way' to distribute and access data files in a packaged Python module References: <715dabdd-618d-4451-a0db-ba6cf59847fc@x6g2000pre.googlegroups.com> <6uopjfFgd5gdU1@mid.uni-berlin.de> Message-ID: > There is a zip-safe flag that you can specify that tells setuptools that > installing your egg only works if it is unarchived. However, there is also > the pkg_resources-package that allows you to access streams from within a > package, even if it is zipped. You should investigate these two options. > > Diez Exactly what I was looking for. Thanks Diez! From sjmachin at lexicon.net Mon Feb 2 16:50:28 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 2 Feb 2009 13:50:28 -0800 (PST) Subject: Reading text file with wierd file extension? References: <887b7e96-b0cc-4dea-8c1a-76c60ebffad3@t26g2000prh.googlegroups.com> <1e517f65-816e-4317-bb8c-0d9ee06041dd@r15g2000prd.googlegroups.com> <6up5kbFglf13U1@mid.uni-berlin.de> Message-ID: <3577795b-f031-400e-bb82-693ef2b3e639@q30g2000prq.googlegroups.com> On Feb 3, 8:07?am, "Diez B. Roggisch" wrote: > > This is written very slowly, so you can read it better: > > Please post the traceback. *AND* please post the text of the IOError message *AND* please do yourself a favour and move your files out of the root directory into a directory with a meaningful name From Russ.Paielli at gmail.com Mon Feb 2 16:51:11 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Mon, 2 Feb 2009 13:51:11 -0800 (PST) Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <67d8a4d2-0b3d-4b41-84e2-698f17cb8e88@35g2000pry.googlegroups.com> Message-ID: <26a3c05c-253d-4134-bcb9-aed8505f250e@e1g2000pra.googlegroups.com> On Feb 2, 9:02 am, thmpsn.... at gmail.com wrote: > On Feb 2, 2:55 am, Stephen Hansen wrote: > > > > This is proven > > > by your statement above, whereby you are driving a user away, > > > simply because the language, in one small aspect, does not > > > give him what he wants, and the tenor of this thread has been > > > very much: "That's how it is - like it or lump it", and no amount > > > of careful explanation of why people want the feature has cut > > > any ice - > > > I'm missing the careful explanation. What I've heard is that the lack > > of enforced encapsulation is "a danger". What I've heard is that > > people want it because they've been told they should want it and > > believe that. Why? > > Who has said the latter? Are you just trying to spread FUD? > > > There have been no "careful explanations" to answer that, in my mind. > > And thus my response is: the practical possibility of needing access > > vastly outweights the theoretical situation that might go bad if > > encapsulation wasn't there. Why? Because in any real situation, IMHO, > > *forced* encapsulation is pointless. > > I think you've gotten too subjective on this matter. You might as well > say that we don't need no stinkin' OOP, we could all just be > programming with goto's. > > Sure, hey, let's do OOP in C, using structs, POD STRUCTS (!!!!), and > PLAIN FUNCTIONS (!!!!) !!!! > > Heck, why do we even need OOP?? Long live procedural!! > > We don't even need no stinkin programming languages, we could just > program using 1's and 0's!!!!!!!!! > > What's with this luddite attitude, Python community? > > > > It has all the time been countered with statements > > > about how the proponents of private attributes "don't need it", > > > (as if they are plain dumb), > > > They don't need it. No one has shown a *real* reason why. The only > > reasons provided are "its a DANGER" that someone "MIGHT DO BAD". > > That's not a real reason. If its your project that someone is doing > > bad in, this is a situation which can be *clearly* specified in a > > projects policy and coding standards and can be *trivially* tested for > > with simple static analysis in nearly all cases. The problem is the > > person and not the code then. There's *countless* other ways that > > person can do bad if you're allowing them to commit blindly anything > > into your project. > > Aha! I see this attitude quite often among C/C++ people, regarding > buffer overflows and uninitialized pointer dereferences: someone will > say "C and C++ are unsafe languages because they allow you to overrun > buffers", then a C/C++ zealot will respond "Hire some good > programmers". > > SAME ATTITUDE. I couldn't agree more. As I said before, as an aeronautical engineer I don't know if enforced access restriction can be added to Python without compromising or unduly complicating the language. Maybe it can't. If that's the case, then people should make that argument. But just saying that enforced access restriction is useless in general is nonsense. Are we supposed to believe that the designers of C++, Java, Ada, and Scala are all idiots? Several participants here keep repeating that the leading-underscore convention is perfectly adequate. Aside from the aesthetic problem of littering code with leading underscores, let me try to explain the problem with leading underscores. Suppose a library developer (or a module developer on a large team) uses leading underscores. Now suppose that, for whatever reason (pressure from the users, perhaps), the library developer decides to change a "private" attribute to public. Now all occurrences of the identifier need to be changed. If an assignment to the previously "private" attribute is missed, no warning will be issued (because Python allows new attributes to be added anywhere, even completely outside the class definition itself). And if the library is widely used, the probability of such bugs occurring is very high. If a "private" keyword (or equivalent) were available, then the change would need to be made in only one location rather than at every occurrence off the identifier. That is much less error prone. Sure, you can argue (as I'm sure someone will) that the users of the library should be more careful. Yes they should, but why not let the language help with such low-level details. That's what high-level languages are for. Several people have argued that an advantage of the leading-underscore convention is that it tells you at every occurrence of the identifier that it is private. Of course, the leading-underscore convention could still be used even in combination with enforced access restriction. But the larger point is this: that is like saying that global parameters should be repeated as literal numbers at every occurrence so the user can see the value instantly. Sure, that saves you the trouble of looking up the value when you need to know it, but it also requres that any change must be carefully made at every location. No competent programmer would argue in favor of that. From __peter__ at web.de Mon Feb 2 16:55:05 2009 From: __peter__ at web.de (Peter Otten) Date: Mon, 02 Feb 2009 22:55:05 +0100 Subject: What is wrong in my list comprehension? References: <44116a3e-0f4a-418f-9ada-dc917ec592d5@j35g2000yqh.googlegroups.com> <8454f0fd-ce56-47aa-a450-8a01fb72d0b0@x6g2000pre.googlegroups.com> Message-ID: Jason Scheirer wrote: > On Feb 1, 3:37?am, Peter Otten <__pete... at web.de> wrote: >> Hussein B wrote: >> > Hey, >> > I have a log file that doesn't contain the word "Haskell" at all, I'm >> > just trying to do a little performance comparison: >> > ++++++++++++++ >> > from datetime import time, timedelta, datetime >> > start = datetime.now() >> > print start >> > lines = [line for line in file('/media/sda4/Servers/Apache/ >> > Tomcat-6.0.14/logs/catalina.out') if line.find('Haskell')] >> > print 'Number of lines contains "Haskell" = ' + ?str(len(lines)) >> > end = datetime.now() >> > print end >> > ++++++++++++++ >> > Well, the script is returning the whole file's lines number !! >> > What is wrong in my logic? >> > Thanks. >> >> """ >> find(...) >> S.find(sub [,start [,end]]) -> int >> >> Return the lowest index in S where substring sub is found, >> such that sub is contained within s[start:end]. ?Optional >> arguments start and end are interpreted as in slice notation. >> >> Return -1 on failure. >> """ >> >> a.find(b) returns -1 if b is no found. -1 evaluates to True in a boolean >> context. >> >> Use >> >> [line for line in open(...) if line.find("Haskell") != -1] >> >> or, better >> >> [line for line in open(...) if "Haskell" in line] >> >> to get the expected result. >> >> Peter > > Or better, group them together in a generator: > > sum(line for line in open(...) if "Haskell" in line) You probably mean sum(1 for line in open(...) if "Haskell" in line) if you want to count the lines containing "Haskell", or sum(line.count("Haskell") for line in open(...) if "Haskell" in line) if you want to count the occurences of "Haskell" (where the if clause is logically superfluous, but may improve performance). > and avoid allocating a new list with every line that contains Haskell > in it. But note that the OP stated that there were no such lines. Peter From python.list at tim.thechases.com Mon Feb 2 16:58:32 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 02 Feb 2009 15:58:32 -0600 Subject: Where to put configuration/data files In-Reply-To: References: Message-ID: <49876C88.6070508@tim.thechases.com> >> Is there a nice cross-platform way to figure out the Right >> (tm) place to store configuration files and other data? > > For what purpose? Global program config, user config, what? I've found three main categories of settings like Aahz describes (of which I've used all in a single application): global settings: I usually keep these in the shared data-store (database or web-site/service). This can include both global application settings such as the name of the institution running the app, or certain business-rules; and global user settings such as name, general preferences, colorschemes, etc. machine-specific settings: this relates to things like particular hardware configurations (path to the CD drive, resource-names/configurations for things like barcode/mag-stripe scanners, etc), or which server to connect to. I usually store these in my application directory on Win32, or in /etc on *nix boxes. User-specific per-machine settings: This can include things like preferred window-layout (which may change depending on screen-size), stored passwords/authentication, cache-locations, local document stores, etc. There's one other odd-ball category I've seen but not used: portable storage on a USB drive. It sorta crosses these boundaries being a bit of each (it's USB-drive specific, but can be moved from machine to machine). Choose your best storage location by thinking what a user/admin would want for each setting. Is it a global setting that all users need? put it in a network store. Is it something that pertains to a particular machine? store it in either a machine-global repository or a user-specific repository accordingly. -tkc From kyosohma at gmail.com Mon Feb 2 17:01:42 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Mon, 2 Feb 2009 14:01:42 -0800 (PST) Subject: Reading text file with wierd file extension? References: <887b7e96-b0cc-4dea-8c1a-76c60ebffad3@t26g2000prh.googlegroups.com> <1e517f65-816e-4317-bb8c-0d9ee06041dd@r15g2000prd.googlegroups.com> <6up5kbFglf13U1@mid.uni-berlin.de> Message-ID: <4eaab3c6-c721-4ee6-bd93-346f3ffd57f6@p36g2000prp.googlegroups.com> On Feb 2, 3:43?pm, Lionel wrote: > On Feb 2, 1:07?pm, "Diez B. Roggisch" wrote: > > This is written very slowly, so you can read it better: > > Please post without sarcasm. > > This is the output from my Python shell: > > >>> DatafilePath = "C:\\C8Example1.slc" > >>> ResourcefilePath = DatafilePath + ".rsc" > >>> DatafileFH = open(DatafilePath) > >>> ResourceFh = open(ResourcefilePath) > >>> DatafilePath > > 'C:\\C8Example1.slc'>>> ResourcefilePath > > 'C:\\C8Example1.slc.rsc' > > It seems to run without trouble. However, here is the offending code > in my class (followed by console output): > > class C8DataType: > > ? ? def __init__(self, DataFilepath): > > ? ? ? ? try: > ? ? ? ? ? ? DataFH = open(DataFilepath, "rb") > > ? ? ? ? except IOError, message: > ? ? ? ? ? ? # Error opening file. > ? ? ? ? ? ? print(message) > ? ? ? ? ? ? return None > > ? ? ? ? ResourceFilepath = DataFilepath + ".src" > > ? ? ? ? print(DataFilepath) > ? ? ? ? print(ResourceFilepath) > > ? ? ? ? # Try to open resource file, catch exception: > ? ? ? ? try: > ? ? ? ? ? ? ResourceFH = open(ResourceFilepath) > > ? ? ? ? except IOError, message: > ? ? ? ? ? ? # Error opening file. > ? ? ? ? ? ? print(message) > ? ? ? ? ? ? print("Error opening " + ResourceFilepath) > ? ? ? ? ? ? DataFH.close() > ? ? ? ? ? ? return None > > Console output when invoking as "someObject = C8DataType("C:\ > \C8Example1.slc")" : > > C:\C8Example1.slc > C:\C8Example1.slc.src > [Errno 2] No such file or directory: 'C:\\C8Example1.slc.src' > Error opening C:\C8Example1.slc.src > > Thank you > > > Lionel schrieb: > > > > On Feb 2, 12:10 pm, Mike Driscoll wrote: > > >> On Feb 2, 1:20 pm, Lionel wrote: > > > >>> On Feb 2, 10:41 am, Mike Driscoll wrote: > > >>>> On Feb 2, 12:36 pm, Lionel wrote: > > >>>>> Hi Folks, Python newbie here. > > >>>>> I'm trying to open (for reading) a text file with the following > > >>>>> filenaming convension: > > >>>>> "MyTextFile.slc.rsc" > > >>>>> My code is as follows: > > >>>>> Filepath = "C:\\MyTextFile.slc.rsc" > > >>>>> FileH = open(Filepath) > > >>>>> The above throws an IOError exception. On a hunch I changed the > > >>>>> filename (only the filename) and tried again: > > >>>>> Filepath = "C:\\MyTextFile.txt" > > >>>>> FileH = open(Filepath) > > >>>>> The above works well. I am able to open the file and read it's > > >>>>> contents. I assume to read a file in text file "mode" the parameter is > > >>>>> scanned for a ".txt" extension, otherwise the Python runtime doesn't > > >>>>> know what version of "open(...)" to invoke. How do I pass the original > > >>>>> filename (MyTextFile.slc.rsc) and get Python to open it as a text > > >>>>> file? Thanks in advance everyone! > > >>>> The extension shouldn't matter. I tried creating a file with the same > > >>>> extension as yours and Python 2.5.2 opened it and read it no problem. > > >>>> I tried it in IDLE and with Wing on Windows XP. What are you using? > > >>>> What's the complete traceback? > > >>>> Mike- Hide quoted text - > > >>>> - Show quoted text - > > >>> Hi Mike, > > >>> maybe it's not a "true" text file? Opening it in Microsoft Notepad > > >>> gives an unformatted view of the file (text with no line wrapping, > > >>> just the end-of-line square box character followed by more text, end- > > >>> of-line character, etc). Wordpad opens it properly i.e. respects the > > >>> end-of-line wrapping. I'm unsure of how these files are being > > >>> generated, I was just given them and told they wanted to be able to > > >>> read them. > > >>> How do I collect the traceback to post it? > > >> The traceback should look something like this fake one: > > > >> Traceback (most recent call last): > > >> ? File "", line 1, in > > >> ? ? raise IOError > > >> IOError > > > >> Just copy and paste it in your next message. The other guys are > > >> probably right in that it is a line ending issue, but as they and I > > >> have said, Python shouldn't care (and doesn't on my machine). > > > >> Mike- Hide quoted text - > > > >> - Show quoted text - > > > > Okay, I think I see what's going on. My class takes a single parameter > > > when it is instantiated...the file path of the data file the user > > > wants to open. This is of the form "someFile.slc". In the same > > > directory of "someFile.slc" is a resource file that (like a file > > > header) contains a host of parameters associated with the data file. > > > The resource file is of the form "someFile.slc.rsc". So, when the user > > > creates an instance of my class which, it invokes the __init__ method > > > where I add the ".rsc" extension to the original filename/path > > > parameter that was passed to the class "constructor". For example: > > > > Note: try-catch blocks ommitted. > > > > class MyUtilityClass: > > > ? ? def __init__(self, DataFilepath): > > > ? ? ? ? Resourcepath ?= DataFilepath + ".rsc" > > > ? ? ? ? DataFileH ? ? = open(DataFilepath) > > > ? ? ? ? ResourceFileH = open(Resourcepath) > > > > Invoking this from the Python shell explicitly is no problem i.e. > > > "TestH = open("C:\\TestResourceFile.slc.rsc") works. BUT...something > > > is lost when I append the ".rsc" extension to the DataFilePath > > > parameter as above. When the __init__ method is invoked, Python will > > > open the data file but generates the exception with the "open > > > (Resourcepath)" instruction. I think it is somehow related to the > > > backslashes but I'm not entirely sure of this. Any ideas? > > > This is written very slowly, so you can read it better: > > > Please post the traceback. > > > Diez- Hide quoted text - > > > - Show quoted text - Well, if I understand your code correctly, you pass in a filename that exists, then you append an extension to it and expect that to change the file's name. This doesn't work, as you only changed the string, not the filename in the file system itself. You can probably use os.rename() to do it. Then it should be able to open it. Mike From sjmachin at lexicon.net Mon Feb 2 17:07:50 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 2 Feb 2009 14:07:50 -0800 (PST) Subject: Reading text file with wierd file extension? References: <887b7e96-b0cc-4dea-8c1a-76c60ebffad3@t26g2000prh.googlegroups.com> <1e517f65-816e-4317-bb8c-0d9ee06041dd@r15g2000prd.googlegroups.com> <6up5kbFglf13U1@mid.uni-berlin.de> Message-ID: <0fbf8005-b609-44fb-9911-0ae9972df9c0@v5g2000pre.googlegroups.com> On Feb 3, 8:43?am, Lionel wrote: > ? ? ? ? ResourceFilepath = DataFilepath + ".src" Don't you mean ".rsc"? From steve at holdenweb.com Mon Feb 2 17:25:41 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 02 Feb 2009 17:25:41 -0500 Subject: Import without executing module In-Reply-To: <79153a2e0902020042k6a8db234id906ff5a773d131f@mail.gmail.com> References: <7a9c25c20902012336w1efeae6dre2de690943cf085b@mail.gmail.com> <79153a2e0902012343t338dd85di9132d0c14f1b964b@mail.gmail.com> <7a9c25c20902012358u60a5d594hef6c81fcdc437f4@mail.gmail.com> <79153a2e0902020042k6a8db234id906ff5a773d131f@mail.gmail.com> Message-ID: Taskinoor Hasan wrote: [...] > It make sense :-). So my reasoning......let A is imported in B, i.e. > name A is put in B's namespace. When we call something like A.a then the > interpreter first resolve A in B's namespace, then to get a, it need to > look up A's namespace. And there is no way to populate A's namespace > without executing A, and as all statements, including 'def', 'class' > etc., are treated in the same way, whole script need to be executed. > > So whether a script can be imported as module or not is mainly dependent > on how the script is written and largely on the intention of the coder. > That's right! regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From lionel.keene at gmail.com Mon Feb 2 17:33:50 2009 From: lionel.keene at gmail.com (Lionel) Date: Mon, 2 Feb 2009 14:33:50 -0800 (PST) Subject: Reading text file with wierd file extension? References: <887b7e96-b0cc-4dea-8c1a-76c60ebffad3@t26g2000prh.googlegroups.com> <1e517f65-816e-4317-bb8c-0d9ee06041dd@r15g2000prd.googlegroups.com> <6up5kbFglf13U1@mid.uni-berlin.de> <4eaab3c6-c721-4ee6-bd93-346f3ffd57f6@p36g2000prp.googlegroups.com> Message-ID: On Feb 2, 2:01?pm, Mike Driscoll wrote: > On Feb 2, 3:43?pm, Lionel wrote: > > > > > > > On Feb 2, 1:07?pm, "Diez B. Roggisch" wrote: > > > This is written very slowly, so you can read it better: > > > Please post without sarcasm. > > > This is the output from my Python shell: > > > >>> DatafilePath = "C:\\C8Example1.slc" > > >>> ResourcefilePath = DatafilePath + ".rsc" > > >>> DatafileFH = open(DatafilePath) > > >>> ResourceFh = open(ResourcefilePath) > > >>> DatafilePath > > > 'C:\\C8Example1.slc'>>> ResourcefilePath > > > 'C:\\C8Example1.slc.rsc' > > > It seems to run without trouble. However, here is the offending code > > in my class (followed by console output): > > > class C8DataType: > > > ? ? def __init__(self, DataFilepath): > > > ? ? ? ? try: > > ? ? ? ? ? ? DataFH = open(DataFilepath, "rb") > > > ? ? ? ? except IOError, message: > > ? ? ? ? ? ? # Error opening file. > > ? ? ? ? ? ? print(message) > > ? ? ? ? ? ? return None > > > ? ? ? ? ResourceFilepath = DataFilepath + ".src" > > > ? ? ? ? print(DataFilepath) > > ? ? ? ? print(ResourceFilepath) > > > ? ? ? ? # Try to open resource file, catch exception: > > ? ? ? ? try: > > ? ? ? ? ? ? ResourceFH = open(ResourceFilepath) > > > ? ? ? ? except IOError, message: > > ? ? ? ? ? ? # Error opening file. > > ? ? ? ? ? ? print(message) > > ? ? ? ? ? ? print("Error opening " + ResourceFilepath) > > ? ? ? ? ? ? DataFH.close() > > ? ? ? ? ? ? return None > > > Console output when invoking as "someObject = C8DataType("C:\ > > \C8Example1.slc")" : > > > C:\C8Example1.slc > > C:\C8Example1.slc.src > > [Errno 2] No such file or directory: 'C:\\C8Example1.slc.src' > > Error opening C:\C8Example1.slc.src > > > Thank you > > > > Lionel schrieb: > > > > > On Feb 2, 12:10 pm, Mike Driscoll wrote: > > > >> On Feb 2, 1:20 pm, Lionel wrote: > > > > >>> On Feb 2, 10:41 am, Mike Driscoll wrote: > > > >>>> On Feb 2, 12:36 pm, Lionel wrote: > > > >>>>> Hi Folks, Python newbie here. > > > >>>>> I'm trying to open (for reading) a text file with the following > > > >>>>> filenaming convension: > > > >>>>> "MyTextFile.slc.rsc" > > > >>>>> My code is as follows: > > > >>>>> Filepath = "C:\\MyTextFile.slc.rsc" > > > >>>>> FileH = open(Filepath) > > > >>>>> The above throws an IOError exception. On a hunch I changed the > > > >>>>> filename (only the filename) and tried again: > > > >>>>> Filepath = "C:\\MyTextFile.txt" > > > >>>>> FileH = open(Filepath) > > > >>>>> The above works well. I am able to open the file and read it's > > > >>>>> contents. I assume to read a file in text file "mode" the parameter is > > > >>>>> scanned for a ".txt" extension, otherwise the Python runtime doesn't > > > >>>>> know what version of "open(...)" to invoke. How do I pass the original > > > >>>>> filename (MyTextFile.slc.rsc) and get Python to open it as a text > > > >>>>> file? Thanks in advance everyone! > > > >>>> The extension shouldn't matter. I tried creating a file with the same > > > >>>> extension as yours and Python 2.5.2 opened it and read it no problem. > > > >>>> I tried it in IDLE and with Wing on Windows XP. What are you using? > > > >>>> What's the complete traceback? > > > >>>> Mike- Hide quoted text - > > > >>>> - Show quoted text - > > > >>> Hi Mike, > > > >>> maybe it's not a "true" text file? Opening it in Microsoft Notepad > > > >>> gives an unformatted view of the file (text with no line wrapping, > > > >>> just the end-of-line square box character followed by more text, end- > > > >>> of-line character, etc). Wordpad opens it properly i.e. respects the > > > >>> end-of-line wrapping. I'm unsure of how these files are being > > > >>> generated, I was just given them and told they wanted to be able to > > > >>> read them. > > > >>> How do I collect the traceback to post it? > > > >> The traceback should look something like this fake one: > > > > >> Traceback (most recent call last): > > > >> ? File "", line 1, in > > > >> ? ? raise IOError > > > >> IOError > > > > >> Just copy and paste it in your next message. The other guys are > > > >> probably right in that it is a line ending issue, but as they and I > > > >> have said, Python shouldn't care (and doesn't on my machine). > > > > >> Mike- Hide quoted text - > > > > >> - Show quoted text - > > > > > Okay, I think I see what's going on. My class takes a single parameter > > > > when it is instantiated...the file path of the data file the user > > > > wants to open. This is of the form "someFile.slc". In the same > > > > directory of "someFile.slc" is a resource file that (like a file > > > > header) contains a host of parameters associated with the data file. > > > > The resource file is of the form "someFile.slc.rsc". So, when the user > > > > creates an instance of my class which, it invokes the __init__ method > > > > where I add the ".rsc" extension to the original filename/path > > > > parameter that was passed to the class "constructor". For example: > > > > > Note: try-catch blocks ommitted. > > > > > class MyUtilityClass: > > > > ? ? def __init__(self, DataFilepath): > > > > ? ? ? ? Resourcepath ?= DataFilepath + ".rsc" > > > > ? ? ? ? DataFileH ? ? = open(DataFilepath) > > > > ? ? ? ? ResourceFileH = open(Resourcepath) > > > > > Invoking this from the Python shell explicitly is no problem i.e. > > > > "TestH = open("C:\\TestResourceFile.slc.rsc") works. BUT...something > > > > is lost when I append the ".rsc" extension to the DataFilePath > > > > parameter as above. When the __init__ method is invoked, Python will > > > > open the data file but generates the exception with the "open > > > > (Resourcepath)" instruction. I think it is somehow related to the > > > > backslashes but I'm not entirely sure of this. Any ideas? > > > > This is written very slowly, so you can read it better: > > > > Please post the traceback. > > > > Diez- Hide quoted text - > > > > - Show quoted text - > > Well, if I understand your code correctly, you pass in a filename that > exists, then you append an extension to it and expect that to change > the file's name. This doesn't work, as you only changed the string, > not the filename in the file system itself. You can probably use > os.rename() to do it. Then it should be able to open it. > > Mike- Hide quoted text - > > - Show quoted text - Hello Mike, I'm sorry, I'm not making myself clear. I have two files in my root directory: "C8Example1.slc" and "C8Example1.slc.rsc". (They are just in the root directory for testing for the time being). The ".slc" file contains the data and the ".slc.rsc" file contains the info necessary to extract it (datatype, width, height, etc). I know a priori that the header file will always be in the same directory and have the same name as the data file with the exception that it will have ".rsc" appended to its name. Therefore, when the user passes the data file name and path as a string to the class, I check the parameter by seeing if I can read to that filepath. If so, I simply add ".rsc" to the end of the parameter string and try to read to that new filepath/ name in order to acquire the header information. This works when typing it directly into the shell script (see above), but not when coded in my class. The IOError is printed above, but being a newbie I'm unsure of how to see the traceback. I've only been using these tools for a couple of days. From steve at holdenweb.com Mon Feb 2 17:34:51 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 02 Feb 2009 17:34:51 -0500 Subject: Membership of multiple items to a list In-Reply-To: References: <87myd51ouw.fsf@benfinney.id.au> Message-ID: Stephen Hansen wrote: > On Sun, Feb 1, 2009 at 7:47 PM, Ben Finney > wrote: >> rdmurray at bitdance.com writes: >> >>> I don't even see Stephen Hansen's posts. My newsreader just shows >>> the header and says "[HTML part not displayed]". >> >> Likewise. > > Yeah, I know HTML is bad on newsgroups. I didn't realize that when I > installed FireGPG to sign messages while in Gmail that it started > handling my html/plain text content differently. > > Oops. > > That said: Is S/MIME / OpenPGP readable on these various clients? > There's no HTML, the text body is just encoded in base64. > > I haven't actually subscribed to a usenet newsgroup in eons upon eons. > If its not readable as S/MIME then I'll switch to inline PGP... that's > just a slightly terrible solution for other places I have to talk and > I'll have to take extra care to remember to manually check the settings > based upon where I'm talking. > Or configure multiple personalities with the same email address but different settings, so all you have to do is switch personalities appropriately. > I'm re-sending this same message as the OpenPGP S/MIME attachment format > -- just so test if its actually readable by news clients in general. I > have absolutely no idea. Not touched a news client in years and years, > as I said. > > Sorry for the inconvenience. I run Thunderbird with the OpenPGP add-on, and I hadn't noticed anything at all strange about your posts :). regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From kurt.forrester.fec at googlemail.com Mon Feb 2 17:35:48 2009 From: kurt.forrester.fec at googlemail.com (Kurt Forrester) Date: Mon, 02 Feb 2009 22:35:48 +0000 Subject: MySQLdb and MySQL stored functions Message-ID: <1233614148.14298.4.camel@macbook> Hello All, I am running - Ubuntu 8.10 - Python 2.5.2 - MySQLdb (1, 2, 2, 'final', 0) - MySQL Server/Client 5.0.67 I am trying to write an authentication script for a python application that connects to a MySQL database. The database has a table named `user` which has the fields `id`, `alias` and `password` as well as a stored function `authenticate` as detailed below: CREATE DEFINER=`root`@`localhost` FUNCTION `authenticate`(a TEXT, p TEXT) RETURNS int(11) BEGIN DECLARE STATUS INT DEFAULT -1; SELECT id INTO STATUS FROM user WHERE alias = a AND password = p; RETURN STATUS; END table: `user` `id` = 1 `alias` = 'captain' `password' = 'a' I have been executing the following query from various connections: `SELECT authenticate('captain', 'a')` (this is what is in the table and should return 1) and `SELECT authenticate('captain', 'aa')` (this is a incorrect version of the password and should return -1) I have tried running this query from the MySQL Query Browser and it returns results as expected. I have also tried query from python using the _mysql module and this also returns results as expected. However, when I try to use the MySQLdb module it returns an incorrect value (it returns 1). I wish to use the DB API 2.0 compliant module for flexibility. Therefore I am trying to work out why the MySQLdb does not return the value as expected (that is as it is returned by the Query Browser). Any help would be greatly appreciated. Kurt -------------- next part -------------- An HTML attachment was scrubbed... URL: From lionel.keene at gmail.com Mon Feb 2 17:37:10 2009 From: lionel.keene at gmail.com (Lionel) Date: Mon, 2 Feb 2009 14:37:10 -0800 (PST) Subject: Reading text file with wierd file extension? References: <887b7e96-b0cc-4dea-8c1a-76c60ebffad3@t26g2000prh.googlegroups.com> <1e517f65-816e-4317-bb8c-0d9ee06041dd@r15g2000prd.googlegroups.com> <6up5kbFglf13U1@mid.uni-berlin.de> <0fbf8005-b609-44fb-9911-0ae9972df9c0@v5g2000pre.googlegroups.com> Message-ID: <1f06f9ce-e3e4-4f62-8eca-5db11e73237d@v39g2000pro.googlegroups.com> On Feb 2, 2:07?pm, John Machin wrote: > On Feb 3, 8:43?am, Lionel wrote: > > > ? ? ? ? ResourceFilepath = DataFilepath + ".src" > > Don't you mean ".rsc"? Good Grief!!! That's It!! I've been staring at it all day and I didn't see it. I'm sorry I've wasted everyone's time. This is bloody embarassing. Amateur night. Thank you for the help everyone. -L From minesh at gmail.com Mon Feb 2 17:39:39 2009 From: minesh at gmail.com (Minesh Patel) Date: Mon, 2 Feb 2009 14:39:39 -0800 Subject: Python patch module Message-ID: Hi, I was wondering if there is any patch management module for Python. Basically I am looking to only apply a hunk from a patch if the file exists. -- Thanks, Minesh From darcy at druid.net Mon Feb 2 17:40:26 2009 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Mon, 2 Feb 2009 17:40:26 -0500 Subject: Membership of multiple items to a list In-Reply-To: References: <87myd51ouw.fsf@benfinney.id.au> Message-ID: <20090202174026.16629f0f.darcy@druid.net> On Mon, 02 Feb 2009 17:34:51 -0500 Steve Holden wrote: > Or configure multiple personalities with the same email address but > different settings, so all you have to do is switch personalities > appropriately. They have pills for that now. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From digitig at gmail.com Mon Feb 2 17:46:43 2009 From: digitig at gmail.com (Tim Rowe) Date: Mon, 2 Feb 2009 22:46:43 +0000 Subject: is python Object oriented?? In-Reply-To: <26a3c05c-253d-4134-bcb9-aed8505f250e@e1g2000pra.googlegroups.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <67d8a4d2-0b3d-4b41-84e2-698f17cb8e88@35g2000pry.googlegroups.com> <26a3c05c-253d-4134-bcb9-aed8505f250e@e1g2000pra.googlegroups.com> Message-ID: 2009/2/2 Russ P. : > Are we supposed > to believe that the designers of C++, Java, Ada, and Scala are all > idiots? No, we're supposed to believe that the designers of C++, Java, Ada, and Scala are all designers of languages that are not Python. If all languages had the same philosophy what would be the point of different languages? Is it worth mentioning (again) that Python is not Java? -- Tim Rowe From casevh at gmail.com Mon Feb 2 17:47:47 2009 From: casevh at gmail.com (casevh) Date: Mon, 2 Feb 2009 14:47:47 -0800 (PST) Subject: Number of bits/sizeof int References: Message-ID: <6508f883-9d87-4583-b086-12429a714a96@g1g2000pra.googlegroups.com> On Jan 30, 11:03?pm, Jon Clements wrote: > Hi Group, > > This has a certain amount of irony (as this is what I'm pretty much > after):- > Fromhttp://docs.python.org/dev/3.0/whatsnew/3.1.html: > "The int() type gained a bit_length method that returns the number of > bits necessary to represent its argument in binary:" > > Any tips on how to get this in 2.5.2 as that's the production version > I'm stuck with. > > Cheers, > > Jon. If performance does become an issue, the newly released gmpy 1.04 includes bit_length(). casevh From kyrie at uh.cu Mon Feb 2 17:48:58 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Mon, 2 Feb 2009 17:48:58 -0500 Subject: is python Object oriented?? In-Reply-To: <26a3c05c-253d-4134-bcb9-aed8505f250e@e1g2000pra.googlegroups.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <67d8a4d2-0b3d-4b41-84e2-698f17cb8e88@35g2000pry.googlegroups.com> <26a3c05c-253d-4134-bcb9-aed8505f250e@e1g2000pra.googlegroups.com> Message-ID: <200902021748.59161.kyrie@uh.cu> On Monday 02 February 2009 04:51:11 pm Russ P. wrote: > As I said before, as an aeronautical engineer I don't know if enforced > access restriction can be added to Python without compromising or > unduly complicating the language. Maybe it can't. If that's the case, > then people should make that argument. But just saying that enforced > access restriction is useless in general is nonsense. Are we supposed > to believe that the designers of C++, Java, Ada, and Scala are all > idiots? I'm amazed at how quickly this thread degenerated into another 'enforced data hiding' thread. I think the previous one ran long enough for me to actually say that 'access restriction is nonsense', when my point had been '_enforced_ access restrictions in python is worthless in all the examples provided so far' (except perhaps the extensions modules, but those are not python). You are an aeronautical engineer. You, and I understand that, don't want, shouldn't want, and will not want to run anything you cannot trust. You want the most assurances you can get. You are well within your right to want that - to disallow in your systems, and in the systems that you build, anything that you even suspect that may threaten the integrity of the system, and let's face it, breaking the encapsulation, intentional or not, is pretty suspicious. So, in current python, _you_ have the _choice_ of preventing it. As the checks are static, of course, you can break them in runtime, just like you would in C, C++ and Java. But somehow, it is not enough for you that you have the choice, because that also gives _me_ the choice of _not_ doing it in my own systems. And you still haven't said why it bothers you that I have the choice. Now, if you were arguing for [truly optional - as in, the user decides] dynamic checks, you may see a very different position. That RExec and Bastion even existed should tell you that there is interest on implementing some kind of trusted execution (as in 'I trust this code to do whatever it wants, but not this other code'). That both projects failed should tell you that either it is impossible to achieve in python (which would be bad), or that there is just not enough interest on keeping them (which would not amaze me). But, if you are arguing for dynamic checks, those are not present in C++ either, and thus, it isn't really what you mean with enforced data hiding. > If an assignment to the previously > "private" attribute is missed, no warning will be issued (because > Python allows new attributes to be added anywhere, even completely > outside the class definition itself). And if the library is widely > used, the probability of such bugs occurring is very high. Good coding standards would prevent that. And by good coding standards, I mean "treat pylint and similar tools as a requirement before executing any code", and it will catch that sort of bugs. Again, _you_ have the choice. Use it if you wish. Now, I'm with you in that accidental variable creation is a nasty side effect of python dynamism (and that you may be forfeiting it if you go the pylint route). But that particular complaint has nothing to do with enforced vs not-enforced data hiding, and everything to do with static typing. And mind you, must of us who use python, do so _because_ of the dynamism and not in spite of it. Funny thing is, you have the choice, _now, today_, of having your precious static checks, both of them, for your projects. But you keep complaining because I also have the choice, and I may chose not to have them. -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From fredbasset1000 at gmail.com Mon Feb 2 18:03:18 2009 From: fredbasset1000 at gmail.com (fredbasset1000 at gmail.com) Date: Mon, 2 Feb 2009 15:03:18 -0800 (PST) Subject: Where & how to deallocate resources in Python C extension Message-ID: <8fe56d94-1d33-44d9-980f-a92c077a30d1@k36g2000pri.googlegroups.com> Hi, I've written a C extension, see code below, to provide a Python interface to a hardware watchdog timer. As part of the initialization it makes some calls to mmap, I am wondering should I be making balanced calls to munmap in some kind of de-init function? Do Python extensions have d'tors? Thanks for any help, Fred ---------------------------------------------------------------------------------------------- #include #include #include #include #include #include #include static const uint8_t WD_PAT_VALUE = 0x05; // hard coded value to indicate a pat to the watchdog static uint8_t* wdt_control = NULL; static uint8_t* wdt_feed = NULL; /*! \brief Initialize the watchdog timer and start it. \param[in] int timeout_period, value to pass to timeout register 0x00 - 0x07, see table above. \return void */ static PyObject* init(PyObject *self, PyObject *args) { int period; int fd; if (!PyArg_Parse(args, "(i)", &period)) { PyErr_SetString(PyExc_TypeError, "single integer argument expected"); return NULL; } if (period <= 0x00 || period >= 0x07) { PyErr_SetString(PyExc_ValueError, "watchdog reg. value out of range (0x00 to 0x07 only)"); return NULL; } fd = open("/dev/mem", O_RDWR | O_SYNC); if (fd == -1) { PyErr_SetString(PyExc_SystemError, strerror(errno)); return NULL; } wdt_control = mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x23800000); if (wdt_control == MAP_FAILED) { PyErr_SetString(PyExc_SystemError, strerror(errno)); return NULL; } wdt_feed = mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x23C00000); if (wdt_feed == MAP_FAILED) { PyErr_SetString(PyExc_SystemError, strerror(errno)); return NULL; } *wdt_feed = WD_PAT_VALUE; // must first pat the w.d. before setting period *wdt_control = period; Py_INCREF(Py_None); return Py_None; } /*! \brief Pat the watchdog timer once. Always call init() before calling this function. \return void */ static PyObject* pat(PyObject *self, PyObject *args) { if (!PyArg_Parse(args, "( )")) { // verify no args passed return NULL; } if (wdt_feed != NULL) { *wdt_feed = WD_PAT_VALUE; } Py_INCREF(Py_None); return Py_None; } // method registration table static struct PyMethodDef wdt_methods[] = { {"init", init, METH_VARARGS}, {"pat", pat, METH_VARARGS}, {NULL, NULL} }; // module initializer, called on first import void initwdtmodule() { (void) Py_InitModule("wdtmodule", wdt_methods); } From robert.kern at gmail.com Mon Feb 2 18:05:40 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 02 Feb 2009 17:05:40 -0600 Subject: Python patch module In-Reply-To: References: Message-ID: On 2009-02-02 16:39, Minesh Patel wrote: > Hi, > I was wondering if there is any patch management module for Python. > Basically I am looking to only apply a hunk from a patch if the file > exists. Google's diff-match-patch library might be up your alley. http://code.google.com/p/google-diff-match-patch/ -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From Russ.Paielli at gmail.com Mon Feb 2 18:20:52 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Mon, 2 Feb 2009 15:20:52 -0800 (PST) Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <67d8a4d2-0b3d-4b41-84e2-698f17cb8e88@35g2000pry.googlegroups.com> <26a3c05c-253d-4134-bcb9-aed8505f250e@e1g2000pra.googlegroups.com> Message-ID: On Feb 2, 2:46 pm, Tim Rowe wrote: > 2009/2/2 Russ P. : > > > Are we supposed > > to believe that the designers of C++, Java, Ada, and Scala are all > > idiots? > > No, we're supposed to believe that the designers of C++, Java, Ada, > and Scala are all designers of languages that are not Python. If all > languages had the same philosophy what would be the point of different > languages? Is it worth mentioning (again) that Python is not Java? > > -- > Tim Rowe I am not sure why people keep "mentioning" that "Python is not Java." As a slogan, it is rather misleading. Python is not C++, Ada, or Scala either. All of those languages have enforced access restriction. Why only mention Java? For the record, I have never used Java, nor do I have any desire to ever use it. That is why I am intrigued by the apparent obsession with it here. I suspect that many programmers are forced to use against their wishes. If that's the case, you have my sympathies, but let's not pretend that Java is the only popular OO language with enforced access restrictions. From google at mrabarnett.plus.com Mon Feb 2 18:25:13 2009 From: google at mrabarnett.plus.com (MRAB) Date: Mon, 02 Feb 2009 23:25:13 +0000 Subject: Reading text file with wierd file extension? In-Reply-To: References: <887b7e96-b0cc-4dea-8c1a-76c60ebffad3@t26g2000prh.googlegroups.com> <1e517f65-816e-4317-bb8c-0d9ee06041dd@r15g2000prd.googlegroups.com> <6up5kbFglf13U1@mid.uni-berlin.de> Message-ID: <498780D9.40603@mrabarnett.plus.com> Lionel wrote: > On Feb 2, 1:07 pm, "Diez B. Roggisch" wrote: > > This is written very slowly, so you can read it better: > > Please post without sarcasm. > > > This is the output from my Python shell: > >>>> DatafilePath = "C:\\C8Example1.slc" >>>> ResourcefilePath = DatafilePath + ".rsc" >>>> DatafileFH = open(DatafilePath) >>>> ResourceFh = open(ResourcefilePath) >>>> DatafilePath > 'C:\\C8Example1.slc' >>>> ResourcefilePath > 'C:\\C8Example1.slc.rsc' > Here the extension is '.rsc' ... > It seems to run without trouble. However, here is the offending code > in my class (followed by console output): > > class C8DataType: > > def __init__(self, DataFilepath): > > try: > DataFH = open(DataFilepath, "rb") > > except IOError, message: > # Error opening file. > print(message) > return None > > ResourceFilepath = DataFilepath + ".src" > ... but here the extension is '.src'. Is that the problem. > print(DataFilepath) > print(ResourceFilepath) > > # Try to open resource file, catch exception: > try: > ResourceFH = open(ResourceFilepath) > > except IOError, message: > # Error opening file. > print(message) > print("Error opening " + ResourceFilepath) > DataFH.close() > return None > > Console output when invoking as "someObject = C8DataType("C:\ > \C8Example1.slc")" : > > C:\C8Example1.slc > C:\C8Example1.slc.src > [Errno 2] No such file or directory: 'C:\\C8Example1.slc.src' > Error opening C:\C8Example1.slc.src > [snip] It can't find "C:\C8Example1.slc.src", but I think you intended "C:\C8Example1.slc.rsc". From tutufan at gmail.com Mon Feb 2 18:27:33 2009 From: tutufan at gmail.com (Mike) Date: Mon, 2 Feb 2009 15:27:33 -0800 (PST) Subject: handy way to spot-profile a python program (watch+pstat+tac) Message-ID: <87a8941c-233c-4790-9578-9d2660eafa9c@i18g2000prf.googlegroups.com> Someone (forget who) mentioned recently that you could get some "poor man's" profiling info by attaching to a running python with gdb, and periodically grabbing a stack trace. I figured out that there's a handy way to do this with this command: watch -n 1 'pstack 30154 | tac' which will show a full-screen stack dump once per second on the python with pid 30154. (It works with non-Python, too--the 'p' is apparently for "process", not "python".) If the interesting part runs off the bottom of your screen, you can always leave off the tac, though that makes it a bit jumpier. (pstack uses the ptrace interface, which may annoy the parents of this process if they're paying attention (which is not usually the case).) Have fun, Mike From demirbaris at gmail.com Mon Feb 2 18:40:22 2009 From: demirbaris at gmail.com (Baris Demir) Date: Tue, 03 Feb 2009 00:40:22 +0100 Subject: function scope Message-ID: <49878466.9010503@gmail.com> Hi everybody, I am quite new to python and using it for my thesis. Luckily I found out some kind of behavior surprising to me and so unwanted in my code. I could not find any explanation, so solution for the code. It is simply like this: /*li = another_module.global_variable f=simpleCut(li) def simpleCut(d=dict()): temp=d for i in temp.keys(): if (temp[i] == .......) : temp[i]=new_value return temp */ here /*simpleCut(d=dict())*/ is a function that changes the value of the key in the d if it satisfies conditions and returns the new dictionary. what i do not understand is, when i checked the original dictionary /*li,*/ i also found out that, the value of that key(operated in the if statement) had also been changed. so, simply, the simpleCut function also changes the variables of its own argument, even there is a 'temp' variable. That is a scandal for my code:) please tell me, if this is not possible and i am missing another thing in my code, or if this kind of behavior is possible, what is the philosophy of it, and how can i change it??? cheers B.D. From benjamin.kaplan at case.edu Mon Feb 2 18:58:05 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 2 Feb 2009 18:58:05 -0500 Subject: is python Object oriented?? In-Reply-To: <26a3c05c-253d-4134-bcb9-aed8505f250e@e1g2000pra.googlegroups.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <67d8a4d2-0b3d-4b41-84e2-698f17cb8e88@35g2000pry.googlegroups.com> <26a3c05c-253d-4134-bcb9-aed8505f250e@e1g2000pra.googlegroups.com> Message-ID: On Mon, Feb 2, 2009 at 4:51 PM, Russ P. wrote: > On Feb 2, 9:02 am, thmpsn.... at gmail.com wrote: > > On Feb 2, 2:55 am, Stephen Hansen wrote: > > > > > > This is proven > > > > by your statement above, whereby you are driving a user away, > > > > simply because the language, in one small aspect, does not > > > > give him what he wants, and the tenor of this thread has been > > > > very much: "That's how it is - like it or lump it", and no amount > > > > of careful explanation of why people want the feature has cut > > > > any ice - > > > > > I'm missing the careful explanation. What I've heard is that the lack > > > of enforced encapsulation is "a danger". What I've heard is that > > > people want it because they've been told they should want it and > > > believe that. Why? > > > > Who has said the latter? Are you just trying to spread FUD? > > > > > There have been no "careful explanations" to answer that, in my mind. > > > And thus my response is: the practical possibility of needing access > > > vastly outweights the theoretical situation that might go bad if > > > encapsulation wasn't there. Why? Because in any real situation, IMHO, > > > *forced* encapsulation is pointless. > > > > I think you've gotten too subjective on this matter. You might as well > > say that we don't need no stinkin' OOP, we could all just be > > programming with goto's. > > > > Sure, hey, let's do OOP in C, using structs, POD STRUCTS (!!!!), and > > PLAIN FUNCTIONS (!!!!) !!!! > > > > Heck, why do we even need OOP?? Long live procedural!! > > > > We don't even need no stinkin programming languages, we could just > > program using 1's and 0's!!!!!!!!! > > > > What's with this luddite attitude, Python community? > > > > > > It has all the time been countered with statements > > > > about how the proponents of private attributes "don't need it", > > > > (as if they are plain dumb), > > > > > They don't need it. No one has shown a *real* reason why. The only > > > reasons provided are "its a DANGER" that someone "MIGHT DO BAD". > > > That's not a real reason. If its your project that someone is doing > > > bad in, this is a situation which can be *clearly* specified in a > > > projects policy and coding standards and can be *trivially* tested for > > > with simple static analysis in nearly all cases. The problem is the > > > person and not the code then. There's *countless* other ways that > > > person can do bad if you're allowing them to commit blindly anything > > > into your project. > > > > Aha! I see this attitude quite often among C/C++ people, regarding > > buffer overflows and uninitialized pointer dereferences: someone will > > say "C and C++ are unsafe languages because they allow you to overrun > > buffers", then a C/C++ zealot will respond "Hire some good > > programmers". > > > > SAME ATTITUDE. > > I couldn't agree more. > > As I said before, as an aeronautical engineer I don't know if enforced > access restriction can be added to Python without compromising or > unduly complicating the language. Maybe it can't. If that's the case, > then people should make that argument. But just saying that enforced > access restriction is useless in general is nonsense. Are we supposed > to believe that the designers of C++, Java, Ada, and Scala are all > idiots? > > Several participants here keep repeating that the leading-underscore > convention is perfectly adequate. Aside from the aesthetic problem of > littering code with leading underscores, let me try to explain the > problem with leading underscores. > > Suppose a library developer (or a module developer on a large team) > uses leading underscores. Now suppose that, for whatever reason > (pressure from the users, perhaps), the library developer decides to > change a "private" attribute to public. Now all occurrences of the > identifier need to be changed. If an assignment to the previously > "private" attribute is missed, no warning will be issued (because > Python allows new attributes to be added anywhere, even completely > outside the class definition itself). And if the library is widely > used, the probability of such bugs occurring is very high. 1. This would be a great spot to use a property. Problem solved. 2. Unit tests. Lots of unit tests. 3. Pylint will check for uninitialized fields. It won't stop you from running the code obviously, but it will notify you if you forgot to change something. 4. Find/Replace. Takes the effort out of looking for the places to change the name. [long argument for private keyword] > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rhodri at wildebst.demon.co.uk Mon Feb 2 18:59:47 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Mon, 02 Feb 2009 23:59:47 -0000 Subject: Question about wx folder browser widget In-Reply-To: References: <2d570f6a-4e97-4ab0-8fd2-eb5cddc5e363@z27g2000prd.googlegroups.com> Message-ID: On Mon, 02 Feb 2009 02:58:07 -0000, Steve Holden wrote: > Sam Price wrote: >> Is there any good wx widgets that provide the same feel as folder/file >> browser. >> I want to be notified when a user tries to drag and drop a file/folder >> on the widget, and then copy that file/folder to a new folder an do >> operations on it. >> >> Wanted to check first to see if something exists, and not reinvent the >> wheel. >> > There's TreeCtrl, and CustomTreeCtrl. I don't know whether they can be > used with drag and drop, Yes they can, at least after a fashion. See http://wiki.wxpython.org/TreeControls -- Rhodri James *-* Wildebeeste Herder to the Masses From google at mrabarnett.plus.com Mon Feb 2 19:13:27 2009 From: google at mrabarnett.plus.com (MRAB) Date: Tue, 03 Feb 2009 00:13:27 +0000 Subject: function scope In-Reply-To: <49878466.9010503@gmail.com> References: <49878466.9010503@gmail.com> Message-ID: <49878C27.6010204@mrabarnett.plus.com> Baris Demir wrote: > Hi everybody, > > I am quite new to python and using it for my thesis. Luckily I found > out some kind of behavior surprising to me and so unwanted in my code. I > could not find any explanation, so solution for the code. > It is simply like this: > > /*li = another_module.global_variable > f=simpleCut(li) > > def simpleCut(d=dict()): > temp=d > for i in temp.keys(): > if (temp[i] == .......) : > temp[i]=new_value > return temp > */ > here /*simpleCut(d=dict())*/ is a function that changes the value of the > key in the d if it satisfies conditions and returns the new dictionary. > what i do not understand is, when i checked the original dictionary > /*li,*/ i also found out that, the value of that key(operated in the if > statement) had also been changed. so, simply, the simpleCut function > also changes the variables of its own argument, even there is a 'temp' > variable. That is a scandal for my code:) > > please tell me, if this is not possible and i am missing another thing > in my code, or if this kind of behavior is possible, what is the > philosophy of it, and how can i change it??? > It's called "Reference Semantics". "d" refers to a dict. When you say "temp=d" it makes "temp" also refer to that dict; it doesn't copy the dict. If you want a copy when you have to do so explicitly with "temp=d.copy()". When you pass "li" into simpleCut() you're not making a copy either! From apt.shansen at gmail.com Mon Feb 2 19:15:45 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 2 Feb 2009 16:15:45 -0800 Subject: function scope In-Reply-To: <49878466.9010503@gmail.com> References: <49878466.9010503@gmail.com> Message-ID: <7a9c25c20902021615q77ca48dbtc165f65ac5f69664@mail.gmail.com> On Mon, Feb 2, 2009 at 3:40 PM, Baris Demir wrote: > Hi everybody, > > I am quite new to python and using it for my thesis. Luckily I found out > some kind of behavior surprising to me and so unwanted in my code. I could > not find any explanation, so solution for the code. > It is simply like this: > > /*li = another_module.global_variable > f=simpleCut(li) > > def simpleCut(d=dict()): > temp=d > for i in temp.keys(): > if (temp[i] == .......) : > temp[i]=new_value > return temp > */ > here /*simpleCut(d=dict())*/ is a function that changes the value of the > key in the d if it satisfies conditions and returns the new dictionary. > what i do not understand is, when i checked the original dictionary /*li,*/ > i also found out that, the value of that key(operated in the if statement) > had also been changed. so, simply, the simpleCut function also changes the > variables of its own argument, even there is a 'temp' variable. That is a > scandal for my code:) In Python, assignment statements simply bind an existing object to a name: and when you call a function and pass that name in you're not passing the name but the object itself-- which will now be bound to a new name. So, if you have: li = {"hello": 5} A dictionary is created, and is bound to the name "li". If you then call: f=simpleCut(li) The dictionary, previously created, will be bound to a new name within simpleCut, that of "d". Within simpleCut, you do: temp = d That's simply binding the same dictionary to a new name. Its also the same dictionary which is known as "li" somewhere else. You then later do: return temp That's returning the same dictionary-- as its returning from the function the object currently bound to the name 'temp'. That dictionary will end up being assigned to "f" from earlier. In all of this you have one single dictionary, known by many names. You have to take care when passing around mutable objects for this reason (and there's another gotcha you're very near to by assigning a default value to a mutable object: that default dict() will be the exact same default dict every time you call the simpleCut() function with no arguments, instead of it being a new dictionary everytime). If you want to duplicate a dictionary, you import the copy module and call copy.copy(d) (or copy.deepcopy(d) depending on the contents). You can also pass the old dict to the dict() object to get a copy. I -believe- that's a shallow copy. E.g, return dict(temp) will make a shallow copy. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From apt.shansen at gmail.com Mon Feb 2 19:17:50 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 2 Feb 2009 16:17:50 -0800 Subject: function scope In-Reply-To: <49878C27.6010204@mrabarnett.plus.com> References: <49878466.9010503@gmail.com> <49878C27.6010204@mrabarnett.plus.com> Message-ID: <7a9c25c20902021617p270f563dy71b606301624ddd8@mail.gmail.com> > If you want a copy when you have > to do so explicitly with "temp=d.copy()". Or that! I forgot about that method. :) Curiously, in 160k lines of code, I haven't explicitly copied a dictionary once. I find that odd. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From digitig at gmail.com Mon Feb 2 19:28:01 2009 From: digitig at gmail.com (Tim Rowe) Date: Tue, 3 Feb 2009 00:28:01 +0000 Subject: is python Object oriented?? In-Reply-To: References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <67d8a4d2-0b3d-4b41-84e2-698f17cb8e88@35g2000pry.googlegroups.com> <26a3c05c-253d-4134-bcb9-aed8505f250e@e1g2000pra.googlegroups.com> Message-ID: 2009/2/2 Russ P. : > On Feb 2, 2:46 pm, Tim Rowe wrote: >> No, we're supposed to believe that the designers of C++, Java, Ada, >> and Scala are all designers of languages that are not Python. If all >> languages had the same philosophy what would be the point of different >> languages? Is it worth mentioning (again) that Python is not Java? >> >> -- >> Tim Rowe > > I am not sure why people keep "mentioning" that "Python is not Java." Because Java is the language that folks most offen insist Python become like. > As a slogan, it is rather misleading. Python is not C++, Ada, or Scala > either. All of those languages have enforced access restriction. Why > only mention Java? You might notice that I also mentioned C++, Ada and Scala. > their wishes. If that's the case, you have my sympathies, but let's > not pretend that Java is the only popular OO language with enforced > access restrictions. You might notice (again) that I also mentioned C++, Ada and Scala. -- Tim Rowe From rhodri at wildebst.demon.co.uk Mon Feb 2 19:35:28 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 03 Feb 2009 00:35:28 -0000 Subject: is python Object oriented?? In-Reply-To: <005201c98549$d3eb74a0$0d00a8c0@hendrik> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com> <003d01c98527$d9ea4ec0$0d00a8c0@hendrik> <005201c98549$d3eb74a0$0d00a8c0@hendrik> Message-ID: On Mon, 02 Feb 2009 13:54:08 -0000, Hendrik van Rooyen wrote: > wrote: >> PS: More accurately, Python _embodies_ a philosophy, and to advocate >> changes that go against that philosophy is to advocate changing >> Python into something that would no longer be Python. You can do >> that, but you aren't likely to get the community to follow you. > > *sits on his hands to try to avoid the tangent, with the gaping hole of > religion > looming beneath the spiderweb of philosophy, and the language spec > gathering > dust in the corner, forgotten and forlorn* This really, really, *really* isn't a tangent. It's the heart of the matter. You are advocating a change that doesn't fit with Python's "consenting adults" approach to programming. It's trivial to enforce hiding using static checking tools if you really feel the need to not trust yourself; it's much harder (though by no means impossible) to break language-enforced hiding when (not if) an interface turns out to be inadequate. -- Rhodri James *-* Wildebeeste Herder to the Masses From mrmakent at cox.net Mon Feb 2 19:37:07 2009 From: mrmakent at cox.net (Mike Kent) Date: Mon, 2 Feb 2009 16:37:07 -0800 (PST) Subject: function scope References: Message-ID: On Feb 2, 6:40?pm, Baris Demir wrote: > def simpleCut(d=dict()): > ? ? ? ?temp=d > ? ? ? ?for i in temp.keys(): > ? ? ? ? ? ?if ? ?(temp[i] == .......) : > ? ? ? ? ? ? ? temp[i]=new_value > return temp You have been bitten by the shared default parameter noobie trap: http://www.python.org/doc/faq/general/#why-are-default-values-shared-between-objects From denis.kasak at gmail.com Mon Feb 2 19:50:34 2009 From: denis.kasak at gmail.com (Denis Kasak) Date: Tue, 3 Feb 2009 01:50:34 +0100 Subject: Reading text file with wierd file extension? In-Reply-To: References: <887b7e96-b0cc-4dea-8c1a-76c60ebffad3@t26g2000prh.googlegroups.com> <1e517f65-816e-4317-bb8c-0d9ee06041dd@r15g2000prd.googlegroups.com> <6up5kbFglf13U1@mid.uni-berlin.de> Message-ID: <39e19a010902021650v2a03a293le1e9b67fabd3fac7@mail.gmail.com> On Mon, Feb 2, 2009 at 10:43 PM, Lionel wrote: > >>> ResourcefilePath > 'C:\\C8Example1.slc.rsc' > C:\C8Example1.slc.src The extension you used in the interactive shell differs from the one you used in the class code (i.e. "rsc" vs "src"). -- Denis Kasak From bignose+hates-spam at benfinney.id.au Mon Feb 2 20:00:18 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Tue, 03 Feb 2009 12:00:18 +1100 Subject: what IDE is the best to write python? References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> <874ozd3cr3.fsf@benfinney.id.au> Message-ID: <87y6woz659.fsf@benfinney.id.au> aahz at pythoncraft.com (Aahz) writes: > In article <874ozd3cr3.fsf at benfinney.id.au>, > Ben Finney wrote: > >aahz at pythoncraft.com (Aahz) writes: > >> > >> Just to register a contrary opinion: I *hate* syntax highlighting > > > >On what basis? > > It makes my eyes bleed Okay. I'll tick the ?irrational objection? box and move on, then. -- \ Q: ?I've heard that Linux causes cancer...? Torvalds: ?That's a | `\ filthy lie. Besides, it was only in rats and has not been | _o__) reproduced in humans.? ?Linus Torvalds | Ben Finney From lionel.keene at gmail.com Mon Feb 2 20:01:53 2009 From: lionel.keene at gmail.com (Lionel) Date: Mon, 2 Feb 2009 17:01:53 -0800 (PST) Subject: Reading text file with wierd file extension? References: <887b7e96-b0cc-4dea-8c1a-76c60ebffad3@t26g2000prh.googlegroups.com> <1e517f65-816e-4317-bb8c-0d9ee06041dd@r15g2000prd.googlegroups.com> <6up5kbFglf13U1@mid.uni-berlin.de> Message-ID: <1f19d002-5a2e-45ab-9401-caf9ac967fea@g3g2000pre.googlegroups.com> On Feb 2, 4:50?pm, Denis Kasak wrote: > On Mon, Feb 2, 2009 at 10:43 PM, Lionel wrote: > > > > > >>> ResourcefilePath > > 'C:\\C8Example1.slc.rsc' > > > > > C:\C8Example1.slc.src > > The extension you used in the interactive shell differs from the one > you used in the class code (i.e. "rsc" vs "src"). > > -- > Denis Kasak Yes, I see the problem now. Thank you everyone! -L From psteiger at dcc.ufba.br Mon Feb 2 20:16:50 2009 From: psteiger at dcc.ufba.br (Patrick Steiger) Date: Mon, 2 Feb 2009 22:16:50 -0300 Subject: what IDE is the best to write python? In-Reply-To: <6a2ccd190902020736l3ddb1332ued49bc528bc87121@mail.gmail.com> References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> <874ozd3cr3.fsf@benfinney.id.au> <6a2ccd190902020736l3ddb1332ued49bc528bc87121@mail.gmail.com> Message-ID: <909ef3300902021716s2b4d2177o9954e349abd82402@mail.gmail.com> 2009/2/2 Joe Riopel > I typically use vim/vi, because it's usually already installed on the > OS's I work with and vim for Windows works the same. Also, using the > same editor across these different OS's, I don't have to worry too > much soft/hard tabs. You shouldn't even think about hard tabs, and you should default all your editors to soft tabs. -- "I May Be the Walrus." -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Mon Feb 2 20:17:19 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 02 Feb 2009 23:17:19 -0200 Subject: ElementTree and clone element toot References: <4986bfd7$0$9385$ba4acef3@news.orange.fr> <49871c5b$0$4087$ba4acef3@news.orange.fr> Message-ID: En Mon, 02 Feb 2009 14:21:29 -0200, m.banaouas escribi?: > My python version is 2.4.4 > > def SubElement(parent, tag, attrib={}, **extra): > > Can you tell me how does "parent" issue could be solved by SubElement ? Simply because you *have* to pass a parent to the function... > I'm looking for how to determine element parent just by asking element > it self. There isn't a way -- and there are good reasons. One is memory management (it would create reference cycles, and they aren't efficiently removed). Another one is that it prevents an element to be shared between containers. > My goal is to clone an element and attach it to a specified parent or to > parant of original element to clone. Then pass the desired parent as the "parent" argument. En Mon, 02 Feb 2009 13:52:59 -0200, Gerard Flanagan escribi?: > Not sure what SubElement gains you, in the context of the above function? Just because Element and SubElement are documented as the recommended way to create Element instances. Also, I was under the impression that makeelement did not make a copy of its "attrib" argument, so it would end being shared by other instances too -- but it isn't the case actually. -- Gabriel Genellina From mdw at distorted.org.uk Mon Feb 2 20:19:21 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 03 Feb 2009 01:19:21 +0000 Subject: Number of bits/sizeof int References: <877i48obxy.fsf.mdw@metalzone.distorted.org.uk> <7d8c7677-e1e1-4d6a-9615-58144f776a59@t26g2000prh.googlegroups.com> Message-ID: <87wsc8mi5i.fsf.mdw@metalzone.distorted.org.uk> John Machin writes: > 3 can be represented in 2 bits and at the same time -3 can be > represented in 2 bits?? But 2 bits can support only 2 ** 2 == 4 > different possibilities, and -3 .. 3 is 7 different integers. Yeah, I made some arbitrary choices about what to do with non-positive inputs. If you prefer other answers, use 'em. My ones work well with signed-magnitude representations where the sign is stored separately. >> ? ## Find upper bound of the form 2^(2^n) >= x. > > Possibly you mean 2 ** ( 2 ** n) >= x I write maths in comments, not Python. Feel lucky I didn't write it in LaTeX. -- [mdw] From jervisau at gmail.com Mon Feb 2 20:35:32 2009 From: jervisau at gmail.com (Jervis Whitley) Date: Tue, 3 Feb 2009 12:35:32 +1100 Subject: what IDE is the best to write python? In-Reply-To: <20090202034654.GD30237@turki.gavron.org> References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> <874ozd3cr3.fsf@benfinney.id.au> <20090202034654.GD30237@turki.gavron.org> Message-ID: <8e63a5ce0902021735x45bea672tc4a655023ba11d5a@mail.gmail.com> On Mon, Feb 2, 2009 at 2:46 PM, Chris Jones wrote: > On Sun, Feb 01, 2009 at 07:26:24PM EST, Ben Finney wrote: >> aahz at pythoncraft.com (Aahz) writes: >> >> > Just to register a contrary opinion: I *hate* syntax highlighting >> >> On what basis? > > Real men hate syntax highlighting. > -- > http://mail.python.org/mailman/listinfo/python-list > real programmers use ed. http://www.gnu.org/fun/jokes/ed.msg.html From rhodri at wildebst.demon.co.uk Mon Feb 2 20:40:37 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 03 Feb 2009 01:40:37 -0000 Subject: Reading text file with wierd file extension? In-Reply-To: References: <887b7e96-b0cc-4dea-8c1a-76c60ebffad3@t26g2000prh.googlegroups.com> <1e517f65-816e-4317-bb8c-0d9ee06041dd@r15g2000prd.googlegroups.com> <6up5kbFglf13U1@mid.uni-berlin.de> <4eaab3c6-c721-4ee6-bd93-346f3ffd57f6@p36g2000prp.googlegroups.com> Message-ID: [Quoting restored for reduced On Mon, 02 Feb 2009 22:33:50 -0000, Lionel wrote: > On Feb 2, 2:01?pm, Mike Driscoll wrote: >> On Feb 2, 3:43?pm, Lionel wrote: >> > On Feb 2, 1:07?pm, "Diez B. Roggisch" wrote: >> >> >> This is written very slowly, so you can read it better: >> >> > Please post without sarcasm. On Usenet? You'll be wanting single unequivocal answers next! Seriously though, you had been asked several times for the traceback, so that we could stop guessing and tell you for sure what was going on, and you hadn't provided it. Diez's mild sarcasm was not uncalled- for. The fact that you didn't have a traceback partially excuses you, but it would have helped if you'd said so. >> >> > This is the output from my Python shell: >> >> > >>> DatafilePath = "C:\\C8Example1.slc" >> > >>> ResourcefilePath = DatafilePath + ".rsc" >> > >>> DatafileFH = open(DatafilePath) >> > >>> ResourceFh = open(ResourcefilePath) >> > >>> DatafilePath >> >> > 'C:\\C8Example1.slc'>>> ResourcefilePath >> >> > 'C:\\C8Example1.slc.rsc' >> >> > It seems to run without trouble. However, here is the offending code >> > in my class (followed by console output): >> >> > class C8DataType: >> >> > ? ? def __init__(self, DataFilepath): >> >> > ? ? ? ? try: >> > ? ? ? ? ? ? DataFH = open(DataFilepath, "rb") >> >> > ? ? ? ? except IOError, message: >> > ? ? ? ? ? ? # Error opening file. >> > ? ? ? ? ? ? print(message) >> > ? ? ? ? ? ? return None You're catching the IOError, presumably so that you can fail gracefully elsewhere. This may not be a particularly good idea, and in any case it stops the exception reaching the console where it would cause the traceback to be displayed. More on this later. >> > ? ? ? ? ResourceFilepath = DataFilepath + ".src" As other people have pointed out, you've got a typo here. >> > ? ? ? ? print(DataFilepath) >> > ? ? ? ? print(ResourceFilepath) >> >> > ? ? ? ? # Try to open resource file, catch exception: >> > ? ? ? ? try: >> > ? ? ? ? ? ? ResourceFH = open(ResourceFilepath) >> >> > ? ? ? ? except IOError, message: >> > ? ? ? ? ? ? # Error opening file. >> > ? ? ? ? ? ? print(message) >> > ? ? ? ? ? ? print("Error opening " + ResourceFilepath) >> > ? ? ? ? ? ? DataFH.close() >> > ? ? ? ? ? ? return None [Huge amounts of text trimmed] Fair enough, you're catching the IOError so that you can ensure that DataFH is closed. Unfortunately this concealed the traceback information, which would have made it more obvious to you what people were talking about. Given that this has rather stuffed your C8DataType instance, you might want to think about re-raising the exception after you've closed DataFH and letting the outer layers deal with it in a more appropriate fashion. Incidentally, this code isn't going to do anything useful for you anyway even after you've fixed the typo. DataFH and ResourceFH are both local variables to __init__ and will be tossed away when it finishes executing. If you want to use them later, make them self.data_fh and self.resource_fh respectively. (PEP 8 recommends that you use lower_case_with_underscores for variable or attribute names, and leave MixedCase for class names.) -- Rhodri James *-* Wildebeeste Herder to the Masses From rhodri at wildebst.demon.co.uk Mon Feb 2 20:47:28 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 03 Feb 2009 01:47:28 -0000 Subject: key capture In-Reply-To: <4986CEC1.6060209@wildenhain.de> References: <72218f020902012244g75593286x83f3157c0379a8e0@mail.gmail.com> <4986CEC1.6060209@wildenhain.de> Message-ID: On Mon, 02 Feb 2009 10:45:21 -0000, Tino Wildenhain wrote: > Hi, > > swamynathan wrote: >> hello, >> im making a virtual piano in python where on key stroke a wav is played >> from a location >> now to implement a fully functional piano i need to have multiple key >> stroke captures ie if 2 or 3 keys pressed then the function which >> playes the wav is called with 3 parameters > > >> how to implement this or any other suggestion(i was asked to try multi >> threading which dint seem optimal) > > Are you trying to do this with a computer keyboard or with an > attached midi or usb music keybord? If the former, you are probably > w/o luck because afaik there is no way to track the event > of having random keys pressed the same time. Yes there is. You need to use one of the GUIs (Tkinter, wxPython, PyGame, etc), all of which will give you Key Down/Key Up events. -- Rhodri James *-* Wildebeeste Herder to the Masses From gotbyrd at gmail.com Mon Feb 2 21:02:46 2009 From: gotbyrd at gmail.com (gotbyrd) Date: Mon, 2 Feb 2009 18:02:46 -0800 (PST) Subject: Searching a file for multiple strings References: <7b0df317-c3cb-4013-9b68-42d0ee9869df@f24g2000vbf.googlegroups.com> Message-ID: On Jan 31, 2:45?pm, Tim Chase wrote: > > I'm fairly new with python and am trying to build a fairly simple > > search script. ?Ultimately, I'm wanting to search a directory of files > > for multiple user inputted keywords. ?I've already written a script > > that can search for a single string through multiple files, now I just > > need to adapt it to multiple strings. > > > I found a bit of code that's a good start: > > > import re > > test = open('something.txt', 'r').read() > > > list = ['a', 'b', 'c'] > > > foundit = re.compile('|'.join(re.escape(target) for target in list)) > > if foundit.findall(test): > > ? ? print 'yes!' > > > The only trouble with this is it returns yes! if it finds any of the > > search items, and I only want a return when it finds all of them. ?Is > > there a bit of code that's similar that I can use? > > [insert standard admonition about using "list" as a variable > name, masking the built-in "list"] > Unless there's a reason to use regular expressions, you could > simply use > > ? ?test = open("something.txt").read() > ? ?items = ['a', 'b', 'c'] > ? ?if all(s in test for s in items): > ? ? ?print "Yes!" > ? ?else: > ? ? ?print "Sorry, bub" > > This presumes python2.5 in which the "all()" function was added. > ? Otherwise in pre-2.5, you could do > > ? ?for s in items: > ? ? ?if s not in test: > ? ? ? ?print "Sorry, bub" > ? ? ? ?break > ? ?else: > ? ? ?print "Yeparoo" > > (note that the "else" goes with the "for", not the "if") > > -tkc Thanks, Tim. What you suggested worked perfectly! Jason From gotbyrd at gmail.com Mon Feb 2 21:05:37 2009 From: gotbyrd at gmail.com (gotbyrd) Date: Mon, 2 Feb 2009 18:05:37 -0800 (PST) Subject: Searching a file for multiple strings (PS) References: <7b0df317-c3cb-4013-9b68-42d0ee9869df@f24g2000vbf.googlegroups.com> <4984AA57.3050106@tim.thechases.com> <4984ADDB.2070509@tim.thechases.com> Message-ID: <26622f01-2418-442d-91c2-0f026d571edd@35g2000pry.googlegroups.com> On Jan 31, 11:39?pm, Shawn Milochik wrote: > On Sat, Jan 31, 2009 at 3:00 PM, Tim Chase > > wrote: > >>> I'm fairly new with python and am trying to build a fairly simple > >>> search script. ?Ultimately, I'm wanting to search a directory of files > >>> for multiple user inputted keywords. ?I've already written a script > >>> that can search for a single string through multiple files, now I just > >>> need to adapt it to multiple strings. > > Not to discourage the use of Python, but it seems that fgrep with the > -f flag already does exactly what you want. If you're on Windows, you > can get the Windows version of fgrep here:http://unxutils.sourceforge.net/ > > Shawn Shawn, Thanks for your suggestion, but the office I work in has python 2.4 on its workstations and we're prohibited from installing outside software. Learning to use python was quicker than getting the IT staff to approve adding new software :) Jason From lionel.keene at gmail.com Mon Feb 2 21:08:49 2009 From: lionel.keene at gmail.com (Lionel) Date: Mon, 2 Feb 2009 18:08:49 -0800 (PST) Subject: Reading text file with wierd file extension? References: <887b7e96-b0cc-4dea-8c1a-76c60ebffad3@t26g2000prh.googlegroups.com> <1e517f65-816e-4317-bb8c-0d9ee06041dd@r15g2000prd.googlegroups.com> <6up5kbFglf13U1@mid.uni-berlin.de> <4eaab3c6-c721-4ee6-bd93-346f3ffd57f6@p36g2000prp.googlegroups.com> Message-ID: <22b823cc-c707-4673-9ba1-03ff68a67bba@d36g2000prf.googlegroups.com> On Feb 2, 5:40?pm, "Rhodri James" wrote: > [Quoting restored for reduced > > On Mon, 02 Feb 2009 22:33:50 -0000, Lionel wrote: > > On Feb 2, 2:01?pm, Mike Driscoll wrote: > >> On Feb 2, 3:43?pm, Lionel wrote: > >> > On Feb 2, 1:07?pm, "Diez B. Roggisch" wrote: > > >> >> This is written very slowly, so you can read it better: > > >> > Please post without sarcasm. > > On Usenet? ?You'll be wanting single unequivocal answers next! > > Seriously though, you had been asked several times for the traceback, > so that we could stop guessing and tell you for sure what was going > on, and you hadn't provided it. ?Diez's mild sarcasm was not uncalled- > for. ?The fact that you didn't have a traceback partially excuses you, > but it would have helped if you'd said so. > > > > > > > > >> > This is the output from my Python shell: > > >> > >>> DatafilePath = "C:\\C8Example1.slc" > >> > >>> ResourcefilePath = DatafilePath + ".rsc" > >> > >>> DatafileFH = open(DatafilePath) > >> > >>> ResourceFh = open(ResourcefilePath) > >> > >>> DatafilePath > > >> > 'C:\\C8Example1.slc'>>> ResourcefilePath > > >> > 'C:\\C8Example1.slc.rsc' > > >> > It seems to run without trouble. However, here is the offending code > >> > in my class (followed by console output): > > >> > class C8DataType: > > >> > ? ? def __init__(self, DataFilepath): > > >> > ? ? ? ? try: > >> > ? ? ? ? ? ? DataFH = open(DataFilepath, "rb") > > >> > ? ? ? ? except IOError, message: > >> > ? ? ? ? ? ? # Error opening file. > >> > ? ? ? ? ? ? print(message) > >> > ? ? ? ? ? ? return None > > You're catching the IOError, presumably so that you can fail > gracefully elsewhere. ?This may not be a particularly good > idea, and in any case it stops the exception reaching the > console where it would cause the traceback to be displayed. > More on this later. > > >> > ? ? ? ? ResourceFilepath = DataFilepath + ".src" > > As other people have pointed out, you've got a typo here. > > >> > ? ? ? ? print(DataFilepath) > >> > ? ? ? ? print(ResourceFilepath) > > >> > ? ? ? ? # Try to open resource file, catch exception: > >> > ? ? ? ? try: > >> > ? ? ? ? ? ? ResourceFH = open(ResourceFilepath) > > >> > ? ? ? ? except IOError, message: > >> > ? ? ? ? ? ? # Error opening file. > >> > ? ? ? ? ? ? print(message) > >> > ? ? ? ? ? ? print("Error opening " + ResourceFilepath) > >> > ? ? ? ? ? ? DataFH.close() > >> > ? ? ? ? ? ? return None > > [Huge amounts of text trimmed] > > Fair enough, you're catching the IOError so that you can > ensure that DataFH is closed. ?Unfortunately this concealed > the traceback information, which would have made it more > obvious to you what people were talking about. ?Given that > this has rather stuffed your C8DataType instance, you > might want to think about re-raising the exception after > you've closed DataFH and letting the outer layers deal > with it in a more appropriate fashion. > > Incidentally, this code isn't going to do anything useful > for you anyway even after you've fixed the typo. ?DataFH > and ResourceFH are both local variables to __init__ and > will be tossed away when it finishes executing. ?If you > want to use them later, make them self.data_fh and > self.resource_fh respectively. > > (PEP 8 recommends that you use lower_case_with_underscores > for variable or attribute names, and leave MixedCase for > class names.) > > -- > Rhodri James *-* Wildebeeste Herder to the Masses- Hide quoted text - > > - Show quoted text - Very good comments. I'll be implementing some of your suggestions, to be sure. Thanks Rhodri. From mdw at distorted.org.uk Mon Feb 2 21:14:49 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 03 Feb 2009 02:14:49 +0000 Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <67d8a4d2-0b3d-4b41-84e2-698f17cb8e88@35g2000pry.googlegroups.com> <26a3c05c-253d-4134-bcb9-aed8505f250e@e1g2000pra.googlegroups.com> Message-ID: <87skmwmfl2.fsf.mdw@metalzone.distorted.org.uk> "Russ P." writes: > I am not sure why people keep "mentioning" that "Python is not Java." > As a slogan, it is rather misleading. Python is not C++, Ada, or Scala > either. All of those languages have enforced access restriction. Why > only mention Java? Because Java is a well-known member of a family of object-oriented languages (or at least languages supporting object-oriented programming). `Python is not Java' is somewhat of a slogan, intended to convey the message that Python, quite intentionally, does not behave in the same way as other languages you may be familiar with. Smalltalk's visibility features are very different from C++ and Java: a method can mess with its own object's (i.e., the recipient of the message which caused the method to be invoked) instance variables but no others -- a restriction enforced syntactically, since there is simply no way of referring to a different instance's variables. There is no restriction whatever on sending messages to other objects. Self abandons the concept of instance variable (and of class, for that matter), and access controls with it. The Common Lisp Object System provides no access control features (though one could probably implement some using the MOP, were one sufficiently motivated); however, CL's package system is better placed for this job anyway. Other object systems for Lisp-family languages tend to be similar. The Lisp Machine's Flavors -- the first object system with multiple inheritance -- relied on the package system for access control; CLOS-like systems for Scheme, which lacks packages, tend not to bother at all. (The package system controls the mapping from tokens read from, say, files to symbols; packages can export some of their symbols, so you can refer to, say, MDW:FOO if package MDW exports symbol FOO, or you can `use' package MDW in your own package to make FOO refer to MDW:FOO. The package system tries to keep you honest rather than acting as an enforcement mechanism: even if MDW doesn't export BAR, you can still talk about MDW::BAR -- note the double-colon -- as much as you like. Working at the name-to-symbol level allows the package system to operate uniformly on all the various namespaces in Lisp.) Perl's object system provides no access controls. Ruby does, following Simula, though it uses C++-ish `private' for Simula's `hidden'. > If that's the case, you have my sympathies, but let's not pretend that > Java is the only popular OO language with enforced access > restrictions. No, but let's not pretend either that such features are essential to object orientation, or that they are even typical of object systems outside of a particular (admittedly popular) subfamily. -- [mdw] From Russ.Paielli at gmail.com Mon Feb 2 21:16:01 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Mon, 2 Feb 2009 18:16:01 -0800 (PST) Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com> <003d01c98527$d9ea4ec0$0d00a8c0@hendrik> <005201c98549$d3eb74a0$0d00a8c0@hendrik> Message-ID: <2ed10ddd-63ac-4507-b046-0404cc85c97a@s1g2000prg.googlegroups.com> On Feb 2, 4:35 pm, "Rhodri James" wrote: > This really, really, *really* isn't a tangent. It's the heart of > the matter. You are advocating a change that doesn't fit with > Python's "consenting adults" approach to programming. It's trivial > to enforce hiding using static checking tools if you really feel the > need to not trust yourself; it's much harder (though by no means > impossible) to break language-enforced hiding when (not if) an > interface turns out to be inadequate. Here we go again. If you have access to the source code (as you nearly always do with Python code), then "breaking the language-enforced data hiding" is a trivial matter of deleting the word "private" (or equivalent). I know ... changing one word constitutes a "fork." Yeah, right. You can't be bothered to change one word, but the library developer should be required to litter his code with leading underscores everywhere, and large development teams should depend on labor intensive code reviews for checks that could be automated by the language. (And, please ... I am not suggesting that enforced access restrictions would render code reviews unnecessary, but it could certainly simplify them.) From ianand0204 at gmail.com Mon Feb 2 21:25:37 2009 From: ianand0204 at gmail.com (flagg) Date: Mon, 2 Feb 2009 18:25:37 -0800 (PST) Subject: Code critique xmlrpclib Message-ID: <4c54d31a-6b8e-40ba-9124-850abff6c69e@g3g2000pre.googlegroups.com> This xmlrpc server is designed to parse dns zone files and then perform various actions on said files. \ It uses dnspython, and xmlrpclib I'd like to know what some of the more experienced python users think. Where I could improve code, make it more efficient, whatever. All suggestions are welcome. This is my first functional python program, and I have tons of questions to go along with whatever suggestions. How could I do sanity checking; right now nothing checks the input to these functions, error-handling in this program is almost non-existant how do you integrate decent error handling into a piece of software......ill shut up now. Thanks import dns.zone from time import localtime, strftime, time import os, sys from dns.rdataclass import * from dns.rdatatype import * from string import Template import xmlrpclib from SimpleXMLRPCServer import SimpleXMLRPCServer from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler zoneDir = "/dns" def openZoneFile(zoneFile): """ Opens a zone file. Then reads in zone file to dnspython zone object. """ global zone global host global domain domain = ".".join(zoneFile.split('.')[1:]) host = ".".join(zoneFile.split('.')[:1]) try: zone = dns.zone.from_file(zoneDir + domain + '.zone', domain) except dns.exception, e: print e.__class__, e class DNSFunctions: # Not exposed to xml-rpc calls, used internally only. def _writeToZoneFile(self, record): """ Checks if zone file exists, if it does it write values to zone file """ for (name, ttl, rdata) in zone.iterate_rdatas(SOA): new_serial = int(strftime('%Y%m%d00', localtime(time()))) if new_serial <= rdata.serial: new_serial = rdata.serial + 1 rdata.serial = new_serial if os.path.exists(zoneDir + str(zone.origin) + "zone"): f = open(zoneDir + str(zone.origin) + "zone", "w") zone.to_file(f) f.close() else: print "Zone: " + zone.origin + " does not exist, please add first" def showRecord(self, record): """ Shows a record for a given zone. Prints out TTL, IN, Record Type, IP """ openZoneFile(record) try: rdataset = zone.get_node(host) for rdata in rdataset: return str(rdata) except: raise Exception("Record not found") def changeRecord(self, record, type, target): """ Changes a dns entry. @param record: which record to chance @param type: what type of record, A, MX, NS, CNAME @target: if CNAME target points to HOSTNAME, if A record points to IP """ openZoneFile(record) try: rdataset = zone.find_rdataset(host, rdtype=type) except: raise Exception("You must enter a valid record and type. See --usage for examples") for rdata in rdataset: if rdata.rdtype == CNAME: rdata.target = dns.name.Name((target,)) elif rdata.rdtype == A: rdata.address = target else: assert False self._writeToZoneFile(host) def deleteRecord(self, record): """ Delete Entry from zone file """ openZoneFile(record) zone.delete_node(host) self._writeToZoneFile(record) def addRecord(self, record, type, target): """ Adds a new record to zone file """ openZoneFile(record) rdataset = zone.find_rdataset(host, rdtype=type, create=True) if rdataset.rdtype == A: rdata = dns.rdtypes.IN.A.A(IN, A, address = target) rdataset.add(rdata, ttl=300) elif rdataset.rdtype == CNAME: rdata = dns.rdtypes.ANY.CNAME.CNAME(IN, CNAME, dns.name.Name((target,))) rdataset.add(rdata, ttl=300) else: assert False self._writeToZoneFile(host) def addZoneFile(self, file): """ Function to create a new empty zone file, if none exists. If exists function will terminate. """ newZoneSerial = strftime("%Y%m%d00", localtime()) zoneTemplate = Template('''$$TTL ${ttltime} $$ORIGIN ${domain}. @ 5M IN SOA nsrepo1.foobar.priv. dnsadmin.foobar.priv. ( ; did you update reverse?! ${serial} ; Serial CCYYMMDDxx where xx is todays edit 1H 10M 1D 60M )''') if not os.path.exists(zoneDir + file + ".zone"): f = open(zoneDir + file + ".zone", "w") f.write(zoneTemplate.substitute({'ttltime':'300', 'domain': file, 'serial': newZoneSerial})) f.close() else: print "Zone: " + file + " already exists" class RequestHandler(SimpleXMLRPCRequestHandler): # rpc_paths = ('/RPC2',), pass server = SimpleXMLRPCServer(("localhost", 8080), requestHandler = RequestHandler, allow_none=True) print "Listening on port 8080..." server.register_introspection_functions() server.register_instance(DNSFunctions()) server.register_multicall_functions() server.serve_forever() ### Client Script ### ## I will probably use a mix of multicalls and singlecalls for client activity. Muticalls will primarily be used for showing a record, applying a change, then showing the same record again to verify changes went through. import xmlrpclib proxy = xmlrpclib.ServerProxy('http://localhost:8080') multicall = xmlrpclib.MultiCall(proxy) print proxy.showRecord('host11.lab0.foobar.priv') print proxy.showRecord('host12.lab0.foobar.priv') multicall.showRecord('host11.lab0.foobar.priv') multicall.changeRecord('host11.lab0.foorbar.priv', 'A', '127.0.0.1') multicall.showRecord('host11.lab0.foobar.priv') print proxy.system.listMethods result = multicall() print result[1], result[2] From raykyoto at gmail.com Mon Feb 2 21:37:55 2009 From: raykyoto at gmail.com (Ray) Date: Mon, 2 Feb 2009 18:37:55 -0800 (PST) Subject: Import without executing module References: <7a9c25c20902012319i2d217644k12bc926400f630c2@mail.gmail.com> <14edd870-74d4-4d7a-a363-a4bc3515a071@s9g2000prg.googlegroups.com> Message-ID: <0ad1a5c0-0605-49fe-8a97-1159fc274d30@a39g2000prl.googlegroups.com> Hi all, On Feb 3, 1:11?am, John Machin wrote: > On Feb 2, 11:51?pm, pyt... at bdurham.com wrote: > > > If the output is coming from a print command, couldn't the OP > > temporarily redirect STDIO to a file to prevent the output from being > > displayed? > > He could, but that'd be a kludge on top of a stuff-up. He should put > the script-only statements inside > ? ? if __name__ == '__main__': > and send the result back to the original author, who may in fact > appreciate being enlightened :-) > > Cheers, > John Thanks John and Malcolm! In my case the first solution would not work. Sorry, that my simple "test" example was only a minimal one which did not reflect the true problem. The module that I do not want to edit not only runs on the command line and does some processing, but also expects arguments. So, when reading it through importing, it exits with an error (because no arguments were supplied). I'll enclose the top-level commands with the if statement above...its just a minor change, but it seems unavoidable. Thanks again! Ray From john at john-a-harper.com Mon Feb 2 21:59:29 2009 From: john at john-a-harper.com (John Harper) Date: Tue, 03 Feb 2009 02:59:29 -0000 Subject: Cross platform compilation? Message-ID: I am trying to build Python to use in an embedded system which uses a ppc_440 CPU. The only information I've found is something written by Klaus Reimer a few years ago, which was based on Python 2.2. So far I seem to have successfully built Python itself, but building the extensions fails miserably with complaints about library format. It insists on referring to "i686" which is indeed the platform it is actually running on. Before I try to reverse engineer completely setup.py, is there something obvious that needs to be done to get it to use the right tool chain? More generally, it seems like this would be something that lots of people would want to do. I'm surprised there isn't support for it built into the distributed version of Python, without having to hack all the setup files...? Thanks, John From grante at visi.com Mon Feb 2 22:27:21 2009 From: grante at visi.com (Grant Edwards) Date: Mon, 02 Feb 2009 21:27:21 -0600 Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <67d8a4d2-0b3d-4b41-84e2-698f17cb8e88@35g2000pry.googlegroups.com> <26a3c05c-253d-4134-bcb9-aed8505f250e@e1g2000pra.googlegroups.com> Message-ID: On 2009-02-02, Russ P. wrote: > I am not sure why people keep "mentioning" that "Python is not > Java." As a slogan, it is rather misleading. Because other people keep insisting that it ought to be. > Python is not C++, Ada, or Scala either. All of those > languages have enforced access restriction. Why only mention > Java? It's often mentioned that Python is not C++ as well. People who know Ada or Scala presumably have a varied enough background that they find no need insist that all languages must do things the same way as language X does. -- Grant From grante at visi.com Mon Feb 2 22:30:01 2009 From: grante at visi.com (Grant Edwards) Date: Mon, 02 Feb 2009 21:30:01 -0600 Subject: Reading text file with wierd file extension? References: <887b7e96-b0cc-4dea-8c1a-76c60ebffad3@t26g2000prh.googlegroups.com> <1e517f65-816e-4317-bb8c-0d9ee06041dd@r15g2000prd.googlegroups.com> <6up5kbFglf13U1@mid.uni-berlin.de> <4eaab3c6-c721-4ee6-bd93-346f3ffd57f6@p36g2000prp.googlegroups.com> Message-ID: On 2009-02-03, Rhodri James wrote: > [Quoting restored for reduced > > On Mon, 02 Feb 2009 22:33:50 -0000, Lionel wrote: > >> On Feb 2, 2:01?pm, Mike Driscoll wrote: >>> On Feb 2, 3:43?pm, Lionel wrote: >>> > On Feb 2, 1:07?pm, "Diez B. Roggisch" wrote: >>> >>> >> This is written very slowly, so you can read it better: >>> >>> > Please post without sarcasm. > > On Usenet? You'll be wanting single unequivocal answers next! ROFL! > Seriously though, you had been asked several times for the > traceback, so that we could stop guessing and tell you for > sure what was going on, and you hadn't provided it. Diez's > mild sarcasm was not uncalled- for. The fact that you didn't > have a traceback partially excuses you, but it would have > helped if you'd said so. The OP might be well served by a careful reading of http://www.catb.org/~esr/faqs/smart-questions.html -- Grant From rhodri at wildebst.demon.co.uk Mon Feb 2 22:48:58 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 03 Feb 2009 03:48:58 -0000 Subject: is python Object oriented?? In-Reply-To: <2ed10ddd-63ac-4507-b046-0404cc85c97a@s1g2000prg.googlegroups.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com> <003d01c98527$d9ea4ec0$0d00a8c0@hendrik> <005201c98549$d3eb74a0$0d00a8c0@hendrik> <2ed10ddd-63ac-4507-b046-0404cc85c97a@s1g2000prg.googlegroups.com> Message-ID: On Tue, 03 Feb 2009 02:16:01 -0000, Russ P. wrote: > Here we go again. If you have access to the source code (as you nearly > always do with Python code), then "breaking the language-enforced data > hiding" is a trivial matter of deleting the word "private" (or > equivalent). If it's that trivial to defeat something that its proponents appear to want to be close to an iron-clad guarantee, what on earth is the point of using "private" in the first place? -- Rhodri James *-* Wildebeeste Herder to the Masses From kyosohma at gmail.com Mon Feb 2 22:57:24 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Mon, 2 Feb 2009 19:57:24 -0800 (PST) Subject: Reading text file with wierd file extension? References: <887b7e96-b0cc-4dea-8c1a-76c60ebffad3@t26g2000prh.googlegroups.com> <1e517f65-816e-4317-bb8c-0d9ee06041dd@r15g2000prd.googlegroups.com> <6up5kbFglf13U1@mid.uni-berlin.de> <4eaab3c6-c721-4ee6-bd93-346f3ffd57f6@p36g2000prp.googlegroups.com> <22b823cc-c707-4673-9ba1-03ff68a67bba@d36g2000prf.googlegroups.com> Message-ID: <3f280744-c393-4709-98d7-bf00366178c9@v39g2000pro.googlegroups.com> On Feb 2, 8:08?pm, Lionel wrote: > On Feb 2, 5:40?pm, "Rhodri James" wrote: > > > > > [Quoting restored for reduced > > > On Mon, 02 Feb 2009 22:33:50 -0000, Lionel wrote: > > > On Feb 2, 2:01?pm, Mike Driscoll wrote: > > >> On Feb 2, 3:43?pm, Lionel wrote: > > >> > On Feb 2, 1:07?pm, "Diez B. Roggisch" wrote: > > > >> >> This is written very slowly, so you can read it better: > > > >> > Please post without sarcasm. > > > On Usenet? ?You'll be wanting single unequivocal answers next! > > > Seriously though, you had been asked several times for the traceback, > > so that we could stop guessing and tell you for sure what was going > > on, and you hadn't provided it. ?Diez's mild sarcasm was not uncalled- > > for. ?The fact that you didn't have a traceback partially excuses you, > > but it would have helped if you'd said so. > > > >> > This is the output from my Python shell: > > > >> > >>> DatafilePath = "C:\\C8Example1.slc" > > >> > >>> ResourcefilePath = DatafilePath + ".rsc" > > >> > >>> DatafileFH = open(DatafilePath) > > >> > >>> ResourceFh = open(ResourcefilePath) > > >> > >>> DatafilePath > > > >> > 'C:\\C8Example1.slc'>>> ResourcefilePath > > > >> > 'C:\\C8Example1.slc.rsc' > > > >> > It seems to run without trouble. However, here is the offending code > > >> > in my class (followed by console output): > > > >> > class C8DataType: > > > >> > ? ? def __init__(self, DataFilepath): > > > >> > ? ? ? ? try: > > >> > ? ? ? ? ? ? DataFH = open(DataFilepath, "rb") > > > >> > ? ? ? ? except IOError, message: > > >> > ? ? ? ? ? ? # Error opening file. > > >> > ? ? ? ? ? ? print(message) > > >> > ? ? ? ? ? ? return None > > > You're catching the IOError, presumably so that you can fail > > gracefully elsewhere. ?This may not be a particularly good > > idea, and in any case it stops the exception reaching the > > console where it would cause the traceback to be displayed. > > More on this later. > > > >> > ? ? ? ? ResourceFilepath = DataFilepath + ".src" > > > As other people have pointed out, you've got a typo here. > > > >> > ? ? ? ? print(DataFilepath) > > >> > ? ? ? ? print(ResourceFilepath) > > > >> > ? ? ? ? # Try to open resource file, catch exception: > > >> > ? ? ? ? try: > > >> > ? ? ? ? ? ? ResourceFH = open(ResourceFilepath) > > > >> > ? ? ? ? except IOError, message: > > >> > ? ? ? ? ? ? # Error opening file. > > >> > ? ? ? ? ? ? print(message) > > >> > ? ? ? ? ? ? print("Error opening " + ResourceFilepath) > > >> > ? ? ? ? ? ? DataFH.close() > > >> > ? ? ? ? ? ? return None > > > [Huge amounts of text trimmed] > > > Fair enough, you're catching the IOError so that you can > > ensure that DataFH is closed. ?Unfortunately this concealed > > the traceback information, which would have made it more > > obvious to you what people were talking about. ?Given that > > this has rather stuffed your C8DataType instance, you > > might want to think about re-raising the exception after > > you've closed DataFH and letting the outer layers deal > > with it in a more appropriate fashion. > > > Incidentally, this code isn't going to do anything useful > > for you anyway even after you've fixed the typo. ?DataFH > > and ResourceFH are both local variables to __init__ and > > will be tossed away when it finishes executing. ?If you > > want to use them later, make them self.data_fh and > > self.resource_fh respectively. > > > (PEP 8 recommends that you use lower_case_with_underscores > > for variable or attribute names, and leave MixedCase for > > class names.) > > > -- > > Rhodri James *-* Wildebeeste Herder to the Masses- Hide quoted text - > > > - Show quoted text - > > Very good comments. I'll be implementing some of your suggestions, to > be sure. Thanks Rhodri. You could check to see if the file actually exists using os.path.exists (). I've found that if I use that in combination with printing the path variable, I sometimes discover that either my file doesn't exist or that my path is slightly wrong and thus Python doesn't think my file exists... Mike From steven at REMOVE.THIS.cybersource.com.au Mon Feb 2 23:25:53 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 03 Feb 2009 04:25:53 GMT Subject: function scope References: Message-ID: On Mon, 02 Feb 2009 16:37:07 -0800, Mike Kent wrote: > On Feb 2, 6:40?pm, Baris Demir wrote: > >> def simpleCut(d=dict()): >> ? ? ? ?temp=d >> ? ? ? ?for i in temp.keys(): >> ? ? ? ? ? ?if ? ?(temp[i] == .......) : >> ? ? ? ? ? ? ? temp[i]=new_value >> return temp > > You have been bitten by the shared default parameter noobie trap: No, he has tripped over the assignment-doesn't-make-copies feature. Ignore the default value, and consider passing in a dict: def simpleCut(d=dict()): ? ? temp=d # ... That doesn't make a temporary copy of d, it makes a new name that refers to the same dictionary as d. So if you do this: li = {'x': 1} f = simpleCut(li) then assert f is li will pass, and he will be surprised and dismayed to discover that simpleCut() has side-effects. Solution: make a copy of the input. def simpleCut(d=dict()): temp = d.copy() for i in temp: # don't need to call keys() if (temp[i] == ...): temp[i] = new_value return temp -- Steven From timr at probo.com Mon Feb 2 23:27:03 2009 From: timr at probo.com (Tim Roberts) Date: Tue, 03 Feb 2009 04:27:03 GMT Subject: Source code for csv module References: <62a2e93e-3b86-44bc-9286-56333edd97f6@t26g2000prh.googlegroups.com> <55c2db4e-8c89-4443-897b-b7ef92e263f1@l33g2000pri.googlegroups.com> <598543ea-2340-41dd-bc76-b787d12148ba@v5g2000prm.googlegroups.com> Message-ID: vsoler wrote: > >I'm still interested in learning python techniques. Are there any >other modules (standard or complementary) that I can use in my >education? Are you serious about this? Are you not aware that virtually ALL of the Python standard modules are written in Python, and are included in their full, readable source form in every Python installation? \Python25\lib in Windows, /usr/lib/python25 in Linux. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Mon Feb 2 23:29:01 2009 From: timr at probo.com (Tim Roberts) Date: Tue, 03 Feb 2009 04:29:01 GMT Subject: function scope References: Message-ID: <0vhfo4p2fsmogbjgs87jhfcbvl1ir7pi9n@4ax.com> Mike Kent wrote: > >On Feb 2, 6:40?pm, Baris Demir wrote: > >> def simpleCut(d=dict()): >> ? ? ? ?temp=d >> ? ? ? ?for i in temp.keys(): >> ? ? ? ? ? ?if ? ?(temp[i] == .......) : >> ? ? ? ? ? ? ? temp[i]=new_value >> return temp > >You have been bitten by the shared default parameter noobie trap: >http://www.python.org/doc/faq/general/#why-are-default-values-shared-between-objects Actually, he hasn't. His problem is more fundamental. However, this is still a good thing for you to point out now and then. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From kyrie at uh.cu Mon Feb 2 23:41:23 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Mon, 02 Feb 2009 23:41:23 -0500 Subject: is python Object oriented?? In-Reply-To: <2ed10ddd-63ac-4507-b046-0404cc85c97a@s1g2000prg.googlegroups.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com> <003d01c98527$d9ea4ec0$0d00a8c0@hendrik> <005201c98549$d3eb74a0$0d00a8c0@hendrik> <2ed10ddd-63ac-4507-b046-0404cc85c97a@s1g2000prg.googlegroups.com> Message-ID: <1233636083.4987caf3011e2@mail.uh.cu> Quoting "Russ P." : > I know ... changing one word constitutes a "fork." Yeah, right. Yeah, right. > You can't be bothered to change one word, but the library developer should > be required to litter his code with leading underscores everywhere, No, instead they will have to litter his code with "private" keywords. (So now this is about laziness and not wanting to type "_"? The argument gets weirder and weirder) > and large development teams should depend on labor intensive code > reviews for checks that could be automated by the language. Or, by already existing third party tools that you insist on ignoring. > (And, please ... I am not suggesting that enforced access restrictions > would render code reviews unnecessary, but it could certainly simplify > them.) Please, tell, how does it having the checks on the interpreter will simplify them more than having the checks on an external tool? -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie From aahz at pythoncraft.com Tue Feb 3 00:09:58 2009 From: aahz at pythoncraft.com (Aahz) Date: 2 Feb 2009 21:09:58 -0800 Subject: what IDE is the best to write python? References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> <874ozd3cr3.fsf@benfinney.id.au> <87y6woz659.fsf@benfinney.id.au> Message-ID: In article <87y6woz659.fsf at benfinney.id.au>, Ben Finney wrote: >aahz at pythoncraft.com (Aahz) writes: >> In article <874ozd3cr3.fsf at benfinney.id.au>, >> Ben Finney wrote: >>>aahz at pythoncraft.com (Aahz) writes: >>>> >>>> Just to register a contrary opinion: I *hate* syntax highlighting >>> >>>On what basis? >> >> It makes my eyes bleed > >Okay. I'll tick the ???irrational objection??? box and move on, then. You favor bleeding eyes? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From Russ.Paielli at gmail.com Tue Feb 3 00:37:57 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Mon, 2 Feb 2009 21:37:57 -0800 (PST) Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com> <003d01c98527$d9ea4ec0$0d00a8c0@hendrik> <005201c98549$d3eb74a0$0d00a8c0@hendrik> <2ed10ddd-63ac-4507-b046-0404cc85c97a@s1g2000prg.googlegroups.com> Message-ID: <3acf1429-9aec-4e0d-b617-21cbcdf76087@w1g2000prk.googlegroups.com> On Feb 2, 7:48?pm, "Rhodri James" wrote: > On Tue, 03 Feb 2009 02:16:01 -0000, Russ P. wrote: > > Here we go again. If you have access to the source code (as you nearly > > always do with Python code), then "breaking the language-enforced data > > hiding" is a trivial matter of deleting the word "private" (or > > equivalent). > > If it's that trivial to defeat something that its proponents appear to > want to be close to an iron-clad guarantee, what on earth is the point > of using "private" in the first place? > > -- > Rhodri James *-* Wildebeeste Herder to the Masses If a library developer releases the source code of a library, any user can trivially "defeat" the access restrictions. But if a team of developers is checking in code for a project, the leader(s) of the project can insist that the access restrictions be respected to simplify the management of interfaces. The larger the team, the more useful that can be. That's why Java, C++, Ada, Scala, and other languages have a "private" keyword. From peter.anderson at internode.on.net Tue Feb 3 00:40:00 2009 From: peter.anderson at internode.on.net (Peter Anderson) Date: Tue, 03 Feb 2009 16:40:00 +1100 Subject: what IDE is the best to write python? In-Reply-To: References: Message-ID: <4987D8B0.4030904@internode.on.net> I have a "thing" about editors; a good editor is my tool of trade! I have tried many editors over the years mainly in the MS Windows, Linux and IBM mainframe environments. After all this I really like EditPlus (and the a slightly lesser extent Textpad). What both have in common is their "Clip Library" or "Clip Text" (I think its called in Textpad). A Clip Library is a simple text file that appears in a side panel next to the main edit panel. Double click on a Clip Library element and it is automatically pasted into the edit panel at the current cursor position. The Clip Library content can also be pased around highlighted text in the edit panel. Here is a simple of an EditPlus Clip Library for what I call a "short script": #T=Short script ^# ^!.py ^# The purpose of this script is def main(): {code here} main() #T=Next Clip Library element #T= defines the name of the Clip Library element ^# the "^" character must proceed a character that is normally a Clip Library syntax character but which you want to use in another context (a Python line comment in this case) ^! is the cursor positin after the Clip Library element has been inserted, in this case the cursor is positioned to alloy the name of the script to be typed The Clip Library element ends when the Clip Library "parser" finds either another element definition or the end of the file. Clip Libraries are stored in simple text files. This is such a simple concept but is so very productive. Who needs an IDE?. I would love to have a Linux text editor (like Scite or GEdit) that could do this. Regards, Peter -- *Peter Anderson* There is nothing more difficult to take in hand, more perilous to conduct, or more uncertain in its success, than to take the lead in the introduction of a new order of things?Niccolo Machiavelli, /The Prince/, ch. 6 From ferdinandsousa at gmail.com Tue Feb 3 01:02:55 2009 From: ferdinandsousa at gmail.com (Ferdinand Sousa) Date: Tue, 3 Feb 2009 11:32:55 +0530 Subject: Varibles -- copies and references Message-ID: Hi Some weeks back I had been following the thread "Why can't assign to function call". Today, I saw the "function scope" thread, and decided I should ask about the behaviour below: >>> # Simple variables >>>p=55 >>> q=p >>> q 55 >>> q=44 >>> p 55 >>> >>> # In a function >>> def dd(d): del d['key'] return d >>> adict={'pramod':'goodboy', 'ferdi':'badboy', 'key':'to be deleted'} >>> dd(adict) {'ferdi': 'badboy', 'pramod': 'goodboy'} >>> adict {'ferdi': 'badboy', 'pramod': 'goodboy'} # undesirable? >>> >>> # In a class >>>class AA: a=111 >>> x=AA() >>> x.a 111 >>> y=x >>> y.a 111 >>> y.a=222 >>> x.a 222 # undesirable? >>> z=copy.deepcopy(x) >>> z.a 222 >>> z.a=444 >>> x.a 222 >>> y.a 222 >>> Guess the simple types show the expected behaviour (even though they are technically instances of existing classes). The user defined classes seem to be references/shallow copies. The "function scope" thread refers to http://www.python.org/doc/faq/general/#why-are-default-values-shared-between-objectsto explain why default parameters should not be modified. But, in the function example above, the dictionary passed as a variable *in the calling scope* gets modified. How can you avoid the dictionary being changed? Assigning one object to another always creates references? Can you modify anything in the class def to get a copy? [I have a tingling feeling this is how the default types (integers, strings etc) are defined] Thanks and best regards, Ferdi -------------- next part -------------- An HTML attachment was scrubbed... URL: From Russ.Paielli at gmail.com Tue Feb 3 01:18:20 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Mon, 2 Feb 2009 22:18:20 -0800 (PST) Subject: what IDE is the best to write python? References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> <874ozd3cr3.fsf@benfinney.id.au> <87y6woz659.fsf@benfinney.id.au> Message-ID: On Feb 2, 9:09?pm, a... at pythoncraft.com (Aahz) wrote: > You favor bleeding eyes? If I am going to bleed anywhere, I'd actually prefer it be somewhere other than the eyes. Well, maybe not the gonads either. That's a tough call. In any case, I use xemacs, and I've always liked color highlighting. Not that it really helps much, but it "spices up" the code and stimulates the eyes and brain. When I see the same code without color highlighting, it just seems bland, like something is missing. It seems like just "text" rather than "code." From aahz at pythoncraft.com Tue Feb 3 01:20:55 2009 From: aahz at pythoncraft.com (Aahz) Date: 2 Feb 2009 22:20:55 -0800 Subject: socket.unbind or socket.unlisten? - socket.error: (48, 'Address already in use') References: <20090127134145.24460.1190938528.divmod.quotient.2653@henry.divmod.com> <49855129.9070901@shopzeus.com> Message-ID: In article , Grant Edwards wrote: >On 2009-02-01, Steve Holden wrote: > >> I believe this is because Microsoft failed to understand the >> original meaning of ___________________, and persisted with >> this ghastly error in the name of backwards compatibility, >> justifying it by suggesting that _________________________. > >Somebody should have cards printed up... +1 QOTW -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From robert.dm.smith at gmail.com Tue Feb 3 01:25:41 2009 From: robert.dm.smith at gmail.com (Robert D.M. Smith) Date: Mon, 2 Feb 2009 22:25:41 -0800 Subject: global variable confusion Message-ID: I have a question on global variables and how to use them. I have 2 files; a.py & b.py # a.py ----- myvar = { 'test' : '123' } # ------- # b.py ----- from a import myvar def test(): a.myvar = { 'blah' : '456' } # ----- If I *'import a*' & type *'a.myvar'* it prints 'test' & '123'. Now, if I *'import b'* & type *'b.test()'* ... does this actually change the contents of myvar? It seems I have to do *'print b.myvar'* to see the change but really I want to just simply do* 'print myvar'*. I want to be able to change myvar anywhere. Please help me grasp this concept. Thanks in advance. -- Rob -------------- next part -------------- An HTML attachment was scrubbed... URL: From banibrata.dutta at gmail.com Tue Feb 3 01:31:44 2009 From: banibrata.dutta at gmail.com (Banibrata Dutta) Date: Tue, 3 Feb 2009 12:01:44 +0530 Subject: rfi : bestpractises for implementing secure policies in python Message-ID: <3de8e1f70902022231v1c2e39f9va75417781ac16b07@mail.gmail.com> Hi, Wondering if it is at-all possible to implement "secure" (s.a. not viewable / tunable / tweakable) "Policies" in python ? Use-cases: 1) License enforcement -- Same application, licensed at differential price levels, based on various feature-sets. 2) "Parental-Control" enforcement. Application usable, with *all* features only if adult (a particular user-id) is using, and *restricted* feature set if a child is using it. 3) Enterprise Policy enforecement -- People from Dept-X shouldn't be able to use the application feature-set A, but only set B. However, people from Dept-Y should be able to feature-set A & B. The question is for what could be a desktop (standalone) python application, or a hosted (SaaS) application. The target user group includes "Programmers" and "hackers", so while application need not be Fort Knox (no national secrets or mission-critical), it need to deter basic-to-moderate hacker attempts at bypassing policy. Seeking best-practise advice, including alternatives s.a. mixed-Language usage (but ideally, multi-platform / portable approaches). -- regards, Banibrata http://www.linkedin.com/in/bdutta -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Tue Feb 3 01:47:21 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 2 Feb 2009 22:47:21 -0800 Subject: global variable confusion In-Reply-To: References: Message-ID: <50697b2c0902022247i5987f199n3f0b5d3e077379ad@mail.gmail.com> On Mon, Feb 2, 2009 at 10:25 PM, Robert D.M. Smith wrote: > I have a question on global variables and how to use them. I have 2 files; > a.py & b.py > > # a.py ----- > > myvar = { 'test' : '123' } > > # ------- > # b.py ----- > > from a import myvar > > def test(): > a.myvar = { 'blah' : '456' } test() will fail at runtime with a NameError. You imported only 'myvar' from 'a', not 'a' itself (i.e. there is no variable 'a' defined with 'b', only the variable 'myvar'). Assuming you changed the import to `import a`, then yes, a.myvar (both within 'a' itself and when accessed from 'b') would have its value changed by test(). Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From apt.shansen at gmail.com Tue Feb 3 01:47:41 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 2 Feb 2009 22:47:41 -0800 Subject: Varibles -- copies and references In-Reply-To: References: Message-ID: <7a9c25c20902022247y13b96c34q95de08644b24293c@mail.gmail.com> > > Guess the simple types show the expected behaviour (even though they are > technically instances of existing classes). The user defined classes seem to > be references/shallow copies. I prefer to avoid the term "reference" when talking about Python semantics, because it tends to make a lot of people get very opinionated on "call-by-value", "call-by-preference", and such, and how they work in other languages and it doesn't quite match up to how things work in Python. In Python every assignment (be it x = y, def foo(): pass, and varieties) are bindings of Objects to Names. That's all: there's no copying going on ever. The only time Python copies an object is if you explicitly copy it. In this code: >>> p=55 >>> q=p An int object, 55, is bound to the name 'p' in the first line. In the second line, the object bound to 'p' (the int object 55) is bound to the name 'q' There's no copying going on. At the end of this, you have two names pointing to the same object. When you next execute the code: >>> q=44 You're binding a different object (the int 44) to the name 'q'. As you show, 'p' is not modified because p and q are not /variables/ really: they're names that point to objects. That you changed where one name points doesn't change where another name points. Things get interesting because Python has two kinds of types: immutable and mutable types. The code: >>> p = p + 5 Results in the object that 'p' points to being added to the object int 5, which results in an entirely new object being created (int 60), which is then bound to the name 'p' again. What looks like changing an int is not changing the actual int at all, but instead creating new objects and binding them to the name 'p'. That's because ints (like strings and tuples) are immutable. Any operation which might appear to change it /does not/ change it: it returns an entirely new object instead. >>> s = "Hello" >>> t = s.replace("o", "a") >>> s 'Hello' >>> t 'Hella' The str.replace operation doesn't change s, it returns a new string object that has the replace operation performed on it. You can bind the new object to the same name as the previous one (thus making the previous one be destroyed if no other names point to them) by >>> s = s.replace("o", "a") For immutable types, when you pass the objects into functions (thus binding the object to the name specified in the def() line), any changes to the binding within the def don't propagate outside the function context: because every change to the names inside the def are not changing the objects pointed to by the names outside: they're just rebinding the internal names. People get a confused because if you pass a mutable object inside a def function and mutate that object the changes /are/ propagated outside-- because now you have a name inside the function and a name outside the object both pointing to the same object. If you want a function to work on a copy of a mutable object passed to it, and not the real object itself, you must explicitly make a copy of it. This code: >>>class AA: a=111 >>> x=AA() >>> x.a 111 >>> y=x >>> y.a 111 >>> y.a=222 >>> x.a 222 is demonstrating something else entirely. A class is made with a name bound to the classes namespace, called 'a'. Then you're trying to access an instance's namespace to fetch the object pointed to by its 'a' name: but with instances, if they do not have a name of their own they will access their classes bindings instead. If you set an "a" onto an instance, it won't be seen on another instance because that instance's 'a' will shadow/override the classes binding. The reason you see the "undesirable" behavior of a change to y.a showing the same result of x.a... is because those are the *exact* same instance. You didn't make a copy of the instance, you just made a new name and bound it to the same instance. If you want to copy in Python you have to explicitly do so, via the 'copy' module or any copy methods an object provides. -breathe- Hope that helps. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From gnujohn at gmail.com Tue Feb 3 01:49:53 2009 From: gnujohn at gmail.com (john) Date: Mon, 2 Feb 2009 22:49:53 -0800 (PST) Subject: Reading text file with wierd file extension? References: <887b7e96-b0cc-4dea-8c1a-76c60ebffad3@t26g2000prh.googlegroups.com> <1e517f65-816e-4317-bb8c-0d9ee06041dd@r15g2000prd.googlegroups.com> <6up5kbFglf13U1@mid.uni-berlin.de> <4eaab3c6-c721-4ee6-bd93-346f3ffd57f6@p36g2000prp.googlegroups.com> <22b823cc-c707-4673-9ba1-03ff68a67bba@d36g2000prf.googlegroups.com> <3f280744-c393-4709-98d7-bf00366178c9@v39g2000pro.googlegroups.com> Message-ID: <82c91293-32ff-44b5-b6a2-33054f03943d@v5g2000prm.googlegroups.com> On Feb 2, 7:57?pm, Mike Driscoll wrote: > On Feb 2, 8:08?pm, Lionel wrote: > > > > > On Feb 2, 5:40?pm, "Rhodri James" wrote: > > > > [Quoting restored for reduced > > > > On Mon, 02 Feb 2009 22:33:50 -0000, Lionel wrote: > > > > On Feb 2, 2:01?pm, Mike Driscoll wrote: > > > >> On Feb 2, 3:43?pm, Lionel wrote: > > > >> > On Feb 2, 1:07?pm, "Diez B. Roggisch" wrote: > > > > >> >> This is written very slowly, so you can read it better: > > > > >> > Please post without sarcasm. > > > > On Usenet? ?You'll be wanting single unequivocal answers next! > > > > Seriously though, you had been asked several times for the traceback, > > > so that we could stop guessing and tell you for sure what was going > > > on, and you hadn't provided it. ?Diez's mild sarcasm was not uncalled- > > > for. ?The fact that you didn't have a traceback partially excuses you, > > > but it would have helped if you'd said so. > > > > >> > This is the output from my Python shell: > > > > >> > >>> DatafilePath = "C:\\C8Example1.slc" > > > >> > >>> ResourcefilePath = DatafilePath + ".rsc" > > > >> > >>> DatafileFH = open(DatafilePath) > > > >> > >>> ResourceFh = open(ResourcefilePath) > > > >> > >>> DatafilePath > > > > >> > 'C:\\C8Example1.slc'>>> ResourcefilePath > > > > >> > 'C:\\C8Example1.slc.rsc' > > > > >> > It seems to run without trouble. However, here is the offending code > > > >> > in my class (followed by console output): > > > > >> > class C8DataType: > > > > >> > ? ? def __init__(self, DataFilepath): > > > > >> > ? ? ? ? try: > > > >> > ? ? ? ? ? ? DataFH = open(DataFilepath, "rb") > > > > >> > ? ? ? ? except IOError, message: > > > >> > ? ? ? ? ? ? # Error opening file. > > > >> > ? ? ? ? ? ? print(message) > > > >> > ? ? ? ? ? ? return None > > > > You're catching the IOError, presumably so that you can fail > > > gracefully elsewhere. ?This may not be a particularly good > > > idea, and in any case it stops the exception reaching the > > > console where it would cause the traceback to be displayed. > > > More on this later. > > > > >> > ? ? ? ? ResourceFilepath = DataFilepath + ".src" > > > > As other people have pointed out, you've got a typo here. > > > > >> > ? ? ? ? print(DataFilepath) > > > >> > ? ? ? ? print(ResourceFilepath) > > > > >> > ? ? ? ? # Try to open resource file, catch exception: > > > >> > ? ? ? ? try: > > > >> > ? ? ? ? ? ? ResourceFH = open(ResourceFilepath) > > > > >> > ? ? ? ? except IOError, message: > > > >> > ? ? ? ? ? ? # Error opening file. > > > >> > ? ? ? ? ? ? print(message) > > > >> > ? ? ? ? ? ? print("Error opening " + ResourceFilepath) > > > >> > ? ? ? ? ? ? DataFH.close() > > > >> > ? ? ? ? ? ? return None > > > > [Huge amounts of text trimmed] > > > > Fair enough, you're catching the IOError so that you can > > > ensure that DataFH is closed. ?Unfortunately this concealed > > > the traceback information, which would have made it more > > > obvious to you what people were talking about. ?Given that > > > this has rather stuffed your C8DataType instance, you > > > might want to think about re-raising the exception after > > > you've closed DataFH and letting the outer layers deal > > > with it in a more appropriate fashion. > > > > Incidentally, this code isn't going to do anything useful > > > for you anyway even after you've fixed the typo. ?DataFH > > > and ResourceFH are both local variables to __init__ and > > > will be tossed away when it finishes executing. ?If you > > > want to use them later, make them self.data_fh and > > > self.resource_fh respectively. > > > > (PEP 8 recommends that you use lower_case_with_underscores > > > for variable or attribute names, and leave MixedCase for > > > class names.) > > > > -- > > > Rhodri James *-* Wildebeeste Herder to the Masses- Hide quoted text - > > > > - Show quoted text - > > > Very good comments. I'll be implementing some of your suggestions, to > > be sure. Thanks Rhodri. > > You could check to see if the file actually exists using os.path.exists > (). I've found that if I use that in combination with printing the > path variable, I sometimes discover that either my file doesn't exist > or that my path is slightly wrong and thus Python doesn't think my > file exists... > > Mike It's weird, right? But thanks to Grant and Rhodri, from another newbie (me) and to everyone else who helps us out. John (the "how to ask questions" text is priceless) From clp2 at rebertia.com Tue Feb 3 01:53:59 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 2 Feb 2009 22:53:59 -0800 Subject: Varibles -- copies and references In-Reply-To: References: Message-ID: <50697b2c0902022253p7d9f1dd6i8e0a3cdcd9364ee8@mail.gmail.com> On Mon, Feb 2, 2009 at 10:02 PM, Ferdinand Sousa wrote: > Hi > > Some weeks back I had been following the thread "Why can't assign to > function call". Today, I saw the "function scope" thread, and decided I > should ask about the behaviour below: > >>>> # >>>> Simple variables >>>>p=55 >>>> q=p >>>> q > 55 >>>> q=44 >>>> p > 55 >>>> >>>> # >>>> In a function >>>> def dd(d): > del d['key'] > return d > >>>> adict={'pramod':'goodboy', 'ferdi':'badboy', 'key':'to be deleted'} >>>> dd(adict) > {'ferdi': 'badboy', 'pramod': 'goodboy'} >>>> adict > {'ferdi': 'badboy', 'pramod': 'goodboy'} # > undesirable? >>>> >>>> # >>>> In a class >>>>class AA: > a=111 > > >>>> x=AA() >>>> x.a > 111 >>>> y=x >>>> y.a > 111 >>>> y.a=222 >>>> x.a > 222 # > undesirable? >>>> z=copy.deepcopy(x) >>>> z.a > 222 >>>> z.a=444 >>>> x.a > 222 >>>> y.a > 222 >>>> > > Guess the simple types show the expected behaviour (even though they are > technically instances of existing classes). The user defined classes seem to > be references/shallow copies. The "function scope" thread refers to > http://www.python.org/doc/faq/general/#why-are-default-values-shared-between-objects > to explain why default parameters should not be modified. But, in the > function example above, the dictionary passed as a variable *in the calling > scope* gets modified. > > How can you avoid the dictionary being changed? > Assigning one object to another always creates references? Can you modify > anything in the class def to get a copy? [I have a tingling feeling this is > how the default types (integers, strings etc) are defined] Stephen gave a great summary of the issue; here's another popular write-up about it: http://effbot.org/zone/call-by-object.htm Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From apt.shansen at gmail.com Tue Feb 3 02:04:54 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 2 Feb 2009 23:04:54 -0800 Subject: rfi : bestpractises for implementing secure policies in python In-Reply-To: <3de8e1f70902022231v1c2e39f9va75417781ac16b07@mail.gmail.com> References: <3de8e1f70902022231v1c2e39f9va75417781ac16b07@mail.gmail.com> Message-ID: <7a9c25c20902022304v154dd3a1xd4756dd454ddc7bf@mail.gmail.com> > Wondering if it is at-all possible to implement "secure" (s.a. not viewable > / tunable / tweakable) "Policies" in python ? > Use-cases: > 1) License enforcement -- Same application, licensed at differential price > levels, based on various feature-sets. > 2) "Parental-Control" enforcement. Application usable, with *all* features > only if adult (a particular user-id) is using, and *restricted* feature set > if a child is using it. > 3) Enterprise Policy enforecement -- People from Dept-X shouldn't be able > to use the application feature-set A, but only set B. However, people from > Dept-Y should be able to feature-set A & B. > > The question is for what could be a desktop (standalone) python > application, or a hosted (SaaS) application. The target user group includes > "Programmers" and "hackers", so while application need not be Fort Knox (no > national secrets or mission-critical), it need to deter basic-to-moderate > hacker attempts at bypassing policy. > 2 and 3 are very... domain-specific. You just need to implement some sort of login procedure where users connect with a credential, and you test those credential vs rights defined in some configuration. Exactly what the login mechanism is depends too much on just what you're doing with your app, and how you define users and roles and privileges as well. As for 1, what we do is that we distribute our main application code as a .zip file with PYC's only and no PY's. That's more then sufficient as far as I'm concerned. If someone knows Python and knows what's going on they can dig into a pYC and disassemble its bytecode and fiddle.. but I don't care at that point. Someone's going to get through if they're that determined. As for determining license enforcement, we provide a system file which includes several fields that define what the system is capable of doing according to the given contract/license, then a license file which is just a checksum of the file with a simple encryption applied to it. When the app starts it computes a checksum of the system file, decrypts the license and compares the checksums. If it matches, we continue on. Its not even close to perfect: someone could find which PYC had the checking routine and disassemble it to get the key, but... its more then good enough IMHO. I could get more cryptic and do the decryption in a C module (perhaps written in Cython) and try to go through more effort obfuscating it... then they'd have to disassemble an object file and know assembly to get the key. But that's just "harder". I'm only interested in the casual protection. But we have a solid relationship with our customers and they all have maintenance contracts: we keep them loyal and not interested in doing anything like that primarily by providing continued updates and enhancements overtime. So we're only really worried about casual tweaking bypassing the security. HTH, --Stephen -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at microcorp.co.za Tue Feb 3 02:10:45 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Tue, 3 Feb 2009 09:10:45 +0200 Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com><0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com><6ul2ieFg1sraU1@mid.uni-berlin.de><73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com><018801c9850e$3e019fe0$0d00a8c0@hendrik><7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com><6uo5koFg8q28U1@mid.uni-berlin.de> <6uoqvrFgh5oeU1@mid.uni-berlin.de> Message-ID: <015a01c985d5$038efac0$0d00a8c0@hendrik> "Diez B. Roggisch" > Your argument would be valid if *any* of the *languages* implementing > encapsulation would offer that real isolation. None does. So where from > comes the feeling that this must be something a *language* should offer? > > Sure one could envision a system where each object is running in it's > micro-process. So far, this hasn't been implemented (to the best of my > knowledge) - so making assertions about the feasibility & robustness for > running as well as for developing are somewhat "airy", don't you think? No. Not airy. Hairy, yes. I suppose the language is a kind of wish list on my part - I have spent the last twenty years or so writing stuff like this on small processors, in assembler, and I would have loved a language that supported it, as well as an operating system (and I do not mean stuff like tiny os and others of that ilk), but one that really supported fast task switching to make the micro tasks less expensive on cheap little processors with scarce resources. (8031) I have written various flavours of my own, (pre emptive, round robin, cooperative) and they all suffer from the speed troubles associated with task switching on that architecture, but in all cases the performance was good enough to get the job done. Most of the stuff really did follow a dataflow model as I have described, but its all so inextricably intertwined with the hardware and the requirements of the different jobs that it feels kind of hopeless to try to extract general principles from it, except for obvious stuff like that it works better if your queues are formal and robust, and that the messages must contain everything that is required to get the job done. If you do this, then there is really no reason to worry about how some other thing is doing it's job. In fact if you find yourself peeking at the other task's innards, then it means you have to rethink the dataflow, because you are on the wrong track - that is what I meant when I talk of "granularity" I have find that code re use, between different projects, has in my case been limited to some parts of: - Task switching code - The ticker structure to interface to hardware - Queues, buffers and memory management. - Utility functions like some simple math and string handling. Anyway this is getting a bit far away from the python way, which does not strictly enforce the 'Pure Path' (Tm) of: - have loose objects as threads/processes - send messages between them using clever queueing So we are extremely unlikely to agree on the importance of enforced data hiding. :-) - Hendrik From cournape at gmail.com Tue Feb 3 02:14:47 2009 From: cournape at gmail.com (David Cournapeau) Date: Tue, 3 Feb 2009 16:14:47 +0900 Subject: is python Object oriented?? In-Reply-To: <3acf1429-9aec-4e0d-b617-21cbcdf76087@w1g2000prk.googlegroups.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com> <003d01c98527$d9ea4ec0$0d00a8c0@hendrik> <005201c98549$d3eb74a0$0d00a8c0@hendrik> <2ed10ddd-63ac-4507-b046-0404cc85c97a@s1g2000prg.googlegroups.com> <3acf1429-9aec-4e0d-b617-21cbcdf76087@w1g2000prk.googlegroups.com> Message-ID: <5b8d13220902022314s7aeab97fx91610bdf89ae73a9@mail.gmail.com> On Tue, Feb 3, 2009 at 2:37 PM, Russ P. wrote: > On Feb 2, 7:48 pm, "Rhodri James" wrote: >> On Tue, 03 Feb 2009 02:16:01 -0000, Russ P. wrote: >> > Here we go again. If you have access to the source code (as you nearly >> > always do with Python code), then "breaking the language-enforced data >> > hiding" is a trivial matter of deleting the word "private" (or >> > equivalent). >> >> If it's that trivial to defeat something that its proponents appear to >> want to be close to an iron-clad guarantee, what on earth is the point >> of using "private" in the first place? >> >> -- >> Rhodri James *-* Wildebeeste Herder to the Masses > > If a library developer releases the source code of a library, any user > can trivially "defeat" the access restrictions. But if a team of > developers is checking in code for a project, the leader(s) of the > project can insist that the access restrictions be respected to > simplify the management of interfaces. The larger the team, the more > useful that can be. That's why Java, C++, Ada, Scala, and other > languages have a "private" keyword. I think a lof of this "discussion" is caused by different usages of private. My understanding is that you think private is missing in python because there is no clear different between a member which is published (part of the API) and one which is not (e.g. whose behavior may change between different revisions, even minor). I agree the underscore is not an ideal solution - it is certainly not followed by all python code out there (not even in python itself - see distutils for example). But I think you are overstating the advantage of private for that usage, at least for C++. In C++, if you have a public class in a header: class Foo { private: int f; }; It means f is private (cannot be accessed outside Foo instances), but it is declared in the public header. Actually, when people means this kind of 'data-hiding', C++ does not bring anything to C itself - after all, we have used FILE* for years and I have no idea about the FILE structure. Maybe I still lack experience, but I find neither _ prefixing nor private/public/protected a satisfaying way to make clear what is public API and what is not. In particular, if I have a python package which does not use _ at all, shall I assume everything is public ? cheers, David From mail at microcorp.co.za Tue Feb 3 02:19:06 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Tue, 3 Feb 2009 09:19:06 +0200 Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com><0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com><6ul2ieFg1sraU1@mid.uni-berlin.de><73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik><7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com><003d01c98527$d9ea4ec0$0d00a8c0@hendrik> <7a9c25c20902021012s2bd6bd71lf82310a07a3f194b@mail.gmail.com> Message-ID: <015b01c985d5$047255e0$0d00a8c0@hendrik> Stephen Hansen wrote: 8< --------- arguments I don't agree with ------------- >P.S. Aiee, this discussion is getting overwhelmingly long. :) It is indeed and I do actually have other stuff to do so I shall try to retreat with defiant dignity. Been fun though, to see the other viewpoints when it started getting serious. :-) - Hendrik From kurt.forrester.fec at googlemail.com Tue Feb 3 02:28:05 2009 From: kurt.forrester.fec at googlemail.com (kurt.forrester.fec at googlemail.com) Date: Mon, 2 Feb 2009 23:28:05 -0800 (PST) Subject: MySQLdb and MySQL stored functions Message-ID: Hello All, I am running - Ubuntu 8.10 - Python 2.5.2 - MySQLdb (1, 2, 2, 'final', 0) - MySQL Server/Client 5.0.67 I am trying to write an authentication script for a python application that connects to a MySQL database. The database has a table named `user` which has the fields `id`, `alias` and `password` as well as a stored function `authenticate` as detailed below: CREATE DEFINER=`root`@`localhost` FUNCTION `authenticate`(a TEXT, p TEXT) RETURNS int(11) BEGIN DECLARE STATUS INT DEFAULT -1; SELECT id INTO STATUS FROM user WHERE alias = a AND password = p; RETURN STATUS; END table: `user` `id` = 1 `alias` = 'captain' `password' = 'a' I have been executing the following query from various connections: `SELECT authenticate('captain', 'a')` (this is what is in the table and should return 1) and `SELECT authenticate('captain', 'aa')` (this is a incorrect version of the password and should return -1) I have tried running this query from the MySQL Query Browser and it returns results as expected. I have also tried query from python using the _mysql module and this also returns results as expected. However, when I try to use the MySQLdb module it returns an incorrect value (it returns 1). I wish to use the DB API 2.0 compliant module for flexibility. Therefore I am trying to work out why the MySQLdb does not return the value as expected (that is as it is returned by the Query Browser). Any help would be greatly appreciated. Kurt From btaylordesign at gmail.com Tue Feb 3 02:31:24 2009 From: btaylordesign at gmail.com (Brandon Taylor) Date: Mon, 2 Feb 2009 23:31:24 -0800 (PST) Subject: Extracting file from zip archive in Python 2.6.1 Message-ID: <7676f73d-2ee9-4151-8a09-b11a3eea2045@p37g2000yqd.googlegroups.com> Hello everyone, I'm having an issue specifying the path for extracting files from a .zip archive. In my method, I have: zip_file.extract(zip_name + '/' + thumbnail_image, thumbnail_path) What is happening is that the extract method is creating a folder with the name of 'zip_name' and extracting the files to it. Example: if 'thumbnail_path' is 'images/inventory/thumbnails/' extract is creating: 'images/inventory/thumbnails/test1/' and saving the files out. How can I set the path to be exactly: 'images/inventory/thumbnails' ? TIA, Brandon From mail at microcorp.co.za Tue Feb 3 02:31:37 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Tue, 3 Feb 2009 09:31:37 +0200 Subject: Threading / Queue management References: Message-ID: <015c01c985d5$051106e0$0d00a8c0@hendrik> "Power Button" > My question is, how can I create the Queue in my main object and set > the target function for the Thread Constructor to be a function in > foo? Just create it, giving it some name. Then start the static long running stuff, and pass the name you gave it. Pass the name to the thing that starts the per transaction thread, so that it can pass it to the new thread, and away you go. You may even need an output queue, so that the static long running stuff knows what to do with the results, and a thread to handle the final output. - Hendrik From apt.shansen at gmail.com Tue Feb 3 02:53:06 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 2 Feb 2009 23:53:06 -0800 Subject: Problem using compileall Message-ID: <7a9c25c20902022353o6ecafe89m32ece2e8cdeff001@mail.gmail.com> I'm having a slight problem with pre-compiling some files for distribution that I'm not sure where to even look for. An excerpt from an output: C:\mother\Python24\core\application\sysconfig>python -m compileall . Listing . ... Compiling .\BulkListClass.py ... Sorry: TypeError: ('compile() expected string without null bytes',) Compiling .\BulkUserImporter.py ... The BulkListClass is then not creating a PYC. Yet, if I: C:\mother\Python24\core\application\sysconfig>python Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import BulkListClass It imports the module fine and made the PYC file. I'm not sure why compileall is failing to compile that file, yet Python can import it to do so. Any suggestions for how to debug this? This is Python 2.4.3 on Windows Vista. Thanks. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From thorsten at thorstenkampe.de Tue Feb 3 03:38:32 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Tue, 3 Feb 2009 09:38:32 +0100 Subject: what IDE is the best to write python? References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> <874ozd3cr3.fsf@benfinney.id.au> Message-ID: * Aahz (2 Feb 2009 09:29:43 -0800) > In article , > Thorsten Kampe wrote: > >* Aahz (2 Feb 2009 06:30:00 -0800) > >> In article <874ozd3cr3.fsf at benfinney.id.au>, > >> Ben Finney wrote: > >>>aahz at pythoncraft.com (Aahz) writes: > >>>> > >>>> Just to register a contrary opinion: I *hate* syntax highlighting > >>> > >>>On what basis? > >> > >> It makes my eyes bleed > > > >Ever tried sunglasses? > > Polarized sunglasses don't work too well with LCD monitors Well, the answer to your issue with syntax highlighting is to use a /decent/ highlighting colour scheme. Don't use that all purple/red/green/yellow/blue one. That's for psychedelic trips. Use a decent colour scheme for adults and you will see that you will benefit from syntax highlighting. Thorsten From steven at REMOVE.THIS.cybersource.com.au Tue Feb 3 03:45:23 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 03 Feb 2009 08:45:23 GMT Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com> <003d01c98527$d9ea4ec0$0d00a8c0@hendrik> <005201c98549$d3eb74a0$0d00a8c0@hendrik> <2ed10ddd-63ac-4507-b046-0404cc85c97a@s1g2000prg.googlegroups.com> Message-ID: On Tue, 03 Feb 2009 03:48:58 +0000, Rhodri James wrote: > On Tue, 03 Feb 2009 02:16:01 -0000, Russ P. > wrote: > >> Here we go again. If you have access to the source code (as you nearly >> always do with Python code), then "breaking the language-enforced data >> hiding" is a trivial matter of deleting the word "private" (or >> equivalent). > > If it's that trivial to defeat something that its proponents appear to > want to be close to an iron-clad guarantee, what on earth is the point > of using "private" in the first place? Well, that is a good question. Since it is even more trivial to defeat Python's private-by-convention data hiding, why even bother? Just make everything public. What on earth is the point of prefixing an attribute with an underscore? I think this debate has a lot to do with people's attitudes towards "No User Serviceable Parts". Some people are comfortable using black-boxes, and if (enforced) data hiding makes it easier for others to build safe, efficient black-boxes, then they're willing to give up that a little bit of flexibility/freedom for the benefit of safe, efficient black-boxes. Others prefer white-boxes, and are willing to give up some safety and efficiency, and live with increased risk and lower performance, just in case some day they might want to open up the white-box and replace the widget with a gadget. Some of us consider that a black-box sealed with regular Phillips head screws is still be an effective black-box. It's not hard to find a screw driver and open the box, but it's still an effective barrier against casual and accidental tinkering while allowing deliberate tinkering. Others take the attitude that anything short of resistance to oxy torches and diamond-tipped drills might as well be in a paper bag, and therefore there's no point to black-boxes at all. I find this extreme position is rather incoherent. If I may paraphrase the argument as I see it: "Enforced data hiding is useless, because it is utterly trivial to bypass it, AND it's wicked, because it makes it unbelievably painful and difficult to bypass it when you need to." If it is trivial to bypass, surely it can't be that painful to bypass? Another extreme position is that enforced data hiding is useless, that there is *never* any need for it *at all*, and therefore Python doesn't need it, there's no reason except stupid PHB's belief in cargo-cult coding why Python couldn't be used for controlling nuclear reactors or the Space Shuttle. There's been some claims remarkably close to that in this or the previous thread. I trust that nobody really believes this extreme position -- it's not that far off claiming that procedures and functions are pointless and stupid because we have GOTO. (The restrictions on GOTOs is analogous to enforced data hiding. We give up the freedom and flexibility to jump into the middle of arbitrary pieces of code in order to write safer and more maintainable code.) But as I wrote once before, it is very liberating to program in Python, and put responsibility for dealing with errors onto the caller. Let them call your methods with invalid arguments, let them mess with your internals, if it breaks, it's their responsibility! Except when it isn't. And that's when I'd like to be able to lock my classes down and enforce data hiding. Not all the time, because I do like white-boxes, but sometimes a black-box is the right choice, or the necessary choice, and if that makes development harder, then that's a cost I'm willing to pay. If I'm not willing to pay it, then I'll leave it as a nice, open, transparent white-box with easily messed-with internals and let the caller deal with the consequences of messing with the internals. Whether you agree with that choice or not is irrelevant. *My* code, *my* choice: it's my decision to write code as a black-box or a white-box, just like it's my choice to use a BSD license or the GPL or a closed- source proprietary license, or to make the class mutable or immutable. If other people don't like my choices, well, you have lots of options: you can sub-class, you can delegate, you can use somebody else's class, you can write your own class, you can do without, you can fork the source code, you can make do with it the way it is, or you can complain to the Salvation Army[1] about how I'm ruining your programming experience by being too strict/not strict enough. I love Python, and I'm greedy and want it all: I want a dynamic, easy-to- use language *and* a compiler that can protect me from myself and bad data. I'm envious of Haskell's type-inference. I want the option to have the compiler warn me when some function is messing with my classes' internals as soon as I hit Enter, and not to have to remember to run some third-party tool. I'm not going to *demand* the choice of white-box or black-box classes. I don't have the right to demand anything. But I can ask, I can try to make my case (to those who will listen), and I refuse to be brow-beaten by those who think Python is Just About Perfect Just The Way It Is into feeling *ashamed* for wanting that choice. [1] They give a damn. -- Steven From thorsten at thorstenkampe.de Tue Feb 3 03:53:34 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Tue, 3 Feb 2009 09:53:34 +0100 Subject: what IDE is the best to write python? References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> <874ozd3cr3.fsf@benfinney.id.au> <87y6woz659.fsf@benfinney.id.au> Message-ID: * Russ P. (Mon, 2 Feb 2009 22:18:20 -0800 (PST)) > On Feb 2, 9:09?pm, a... at pythoncraft.com (Aahz) wrote: > > You favor bleeding eyes? > > If I am going to bleed anywhere, I'd actually prefer it be somewhere > other than the eyes. Well, maybe not the gonads either. That's a tough > call. In any case, I use xemacs, and I've always liked color > highlighting. Not that it really helps much, but it "spices up" the > code and stimulates the eyes and brain. When I see the same code > without color highlighting, it just seems bland, like something is > missing. It seems like just "text" rather than "code." Absolutely correct and probably 99% of all programmers see it like that. The trick here is to use colour sparingly. This is not only true for syntax highlighting but for any kind of highlighting like in prompts and ls/dircolors: use it right and your ability to grasp and categorize the provided information will improve, use too much colour and you will go blind...( ;-) ) Thorsten From kurt.forrester.fec at googlemail.com Tue Feb 3 03:55:34 2009 From: kurt.forrester.fec at googlemail.com (kurt.forrester.fec at googlemail.com) Date: Tue, 3 Feb 2009 00:55:34 -0800 (PST) Subject: MySQLdb and MySQL stored functions References: Message-ID: <0fef1833-2dae-44d2-a719-9a036ca0907c@l37g2000vba.googlegroups.com> On Feb 3, 8:28?am, Dennis Lee Bieber wrote: > On Mon, 2 Feb 2009 23:28:05 -0800 (PST), > kurt.forrester.... at googlemail.com declaimed the following in > comp.lang.python: > > > However, when I try to use the MySQLdb module it returns an incorrect > > value (it returns 1). > > > I wish to use the DB API 2.0 compliant module for flexibility. > > Therefore I am trying to work out why the MySQLdb does not return the > > value as expected (that is as it is returned by the Query Browser). > > > Any help would be greatly appreciated. > > ? ? ? ? Show the code! > > ? ? ? ? At a rough guess, given the lack of details... > > ? ? ? ? You forgot to .fetch() the result and are looking at the status code > from the .execute() > -- > ? ? ? ? Wulfraed ? ? ? ?Dennis Lee Bieber ? ? ? ? ? ? ? KD6MOG > ? ? ? ? wlfr... at ix.netcom.com ? ? ? ? ? ? ?wulfr... at bestiaria.com > ? ? ? ? ? ? ? ? HTTP://wlfraed.home.netcom.com/ > ? ? ? ? (Bestiaria Support Staff: ? ? ? ? ? ? ? web-a... at bestiaria.com) > ? ? ? ? ? ? ? ? HTTP://www.bestiaria.com/ Correct diagnosis. Thanks. Any ideas on how to suppress the warning output: __main__:1: Warning: No data - zero rows fetched, selected, or processed From hongyuan1306 at gmail.com Tue Feb 3 03:56:15 2009 From: hongyuan1306 at gmail.com (Yuan HOng) Date: Tue, 3 Feb 2009 16:56:15 +0800 Subject: urllib2.open always send 'Accept-Encoding: gzip, deflate' under Windows Message-ID: <91320d220902030056h49db6a10pe4000ef934a95a6a@mail.gmail.com> Hi, I wish to send a request without 'Accept-Encoding: gzip, deflate' in the request header. Under Linux, this is not a problem, I got 'Accept-Encoding: identity' by default. However, under Windows (XP SP3 with Python 2.5), no matter what I try, I always got 'Accept-Encoding: gzip, deflate' in the request header. There is no method in urllib2 to remove or disable the sending of a header. So what I can do is try to override the miraculously added header, like: >>> opener = urllib2.build_opener() >>> opener.addheaders = [('Accept-encoding', 'identity;q=1.0, gzip;q=0')] >>> opener.open('some test url') or >>> request = urllib2.Request('http://www.homemaster.cn', headers={'Accept-encoding': 'identity'}) >>> urllib2.urlopen(request) But I always still get the annoying 'gzip, deflate' in the header (captured by Wireshark). And in the latter case, it seems my 'Accept-encoding': 'identity' is changed into '---------------: --------', presumably because it clashes with the system generated header of 'gzip, deflate': GET / HTTP/1.1 Accept-Encoding: gzip, deflate Host: www.homemaster.cn User-Agent: Python-urllib/2.5 Connection: close ---------------: -------- Strangely I neither find the string 'gzip, deflate' in urllib2.py nor in httplib.py. Where does it come and how can I remove it or replace it with 'identity'? -- Hong Yuan ????????? ??????????? http://www.homemaster.cn -------------- next part -------------- An HTML attachment was scrubbed... URL: From ferdinandsousa at gmail.com Tue Feb 3 03:57:30 2009 From: ferdinandsousa at gmail.com (Ferdinand Sousa) Date: Tue, 3 Feb 2009 14:27:30 +0530 Subject: Varibles -- copies and references Message-ID: People get a confused because if you pass a mutable object inside a def function and mutate that object the changes /are/ propagated outside-- because now you have a name inside the function and a name outside the object both pointing to the same object. Since tuples are immutable, I guess passing tuples to functions would achieve the result desired by me: result = func ( (anobject) ) If you want a function to work on a copy of a mutable object passed to it, and not the real object itself, you must explicitly make a copy of it. Or using deepcopy within the function definition. This would be better as I could simply pass an object to the function. I don't think there is another way to make an object mutable by something in the class definition. Is there? >>>class AA: a=111 >>> x=AA() >>> x.a 111 >>> y=x >>> y.a 111 >>> y.a=222 >>> x.a 222 # undesirable? >>> z=copy.deepcopy(x) >>> z.a 222 >>> z.a=444 >>> x.a 222 >>> y.a 222 The reason you see the "undesirable" behavior of a change to y.a showing the same result of x.a... is because those are the *exact* same instance. You didn't make a copy of the instance, you just made a new name and bound it to the same instance. If you want to copy in Python you have to explicitly do so, via the 'copy' module or any copy methods an object provides. Could someone please give me an example of how to implement this copy method for the AA class. Going the other way: >>> a=555 >>> d=copy.copy(a) # Supposed to be a shallow copy >>> d 555 >>> d=444 >>> a # But, it doesn't change the original 555 Is there any way to get ints/strings to refer to the same object? Thanks and Regards, Ferdi -------------- next part -------------- An HTML attachment was scrubbed... URL: From Russ.Paielli at gmail.com Tue Feb 3 04:11:14 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 3 Feb 2009 01:11:14 -0800 (PST) Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com> <003d01c98527$d9ea4ec0$0d00a8c0@hendrik> <005201c98549$d3eb74a0$0d00a8c0@hendrik> <2ed10ddd-63ac-4507-b046-0404cc85c97a@s1g2000prg.googlegroups.com> Message-ID: On Feb 3, 12:45?am, Steven D'Aprano wrote: > Another extreme position is that enforced data hiding is useless, that > there is *never* any need for it *at all*, and therefore Python doesn't > need it, there's no reason except stupid PHB's belief in cargo-cult > coding why Python couldn't be used for controlling nuclear reactors or > the Space Shuttle. There's been some claims remarkably close to that in > this or the previous thread. My recollection is that several people have said exactly that in no uncertain terms, if not in this thread then in the one a few days ago. > I trust that nobody really believes this > extreme position -- it's not that far off claiming that procedures and > functions are pointless and stupid because we have GOTO. If nobody believes it, several participants here could have fooled me. From thorsten at thorstenkampe.de Tue Feb 3 04:20:28 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Tue, 3 Feb 2009 10:20:28 +0100 Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <67d8a4d2-0b3d-4b41-84e2-698f17cb8e88@35g2000pry.googlegroups.com> <26a3c05c-253d-4134-bcb9-aed8505f250e@e1g2000pra.googlegroups.com> Message-ID: * Russ P. (Mon, 2 Feb 2009 13:51:11 -0800 (PST)) > On Feb 2, 9:02 am, thmpsn.... at gmail.com wrote: > Several participants here keep repeating that the leading-underscore > convention is perfectly adequate. Aside from the aesthetic problem of > littering code with leading underscores, let me try to explain the > problem with leading underscores. A leading underscore is not an aesthetic problem - while I would agree that /multiple/ leading or trailing underscores are. > Suppose a library developer (or a module developer on a large team) > uses leading underscores. Now suppose that, for whatever reason > (pressure from the users, perhaps), the library developer decides to > change a "private" attribute to public. Now all occurrences of the > identifier need to be changed. If an assignment to the previously > "private" attribute is missed, no warning will be issued (because > Python allows new attributes to be added anywhere, even completely > outside the class definition itself). And if the library is widely > used, the probability of such bugs occurring is very high. > > If a "private" keyword (or equivalent) were available, then the change > would need to be made in only one location rather than at every > occurrence off the identifier. That is much less error prone. Sure, > you can argue (as I'm sure someone will) that the users of the library > should be more careful. Yes they should, but why not let the language > help with such low-level details. That's what high-level languages are > for. This scenario is highly "supposing" and doesn't look like a real-world- case to me. But anyway: the obvious solution in my humble opinion would be to do something like "public_attribute = _private_attribute". But that would be too simple, too "unjavaesque", right?! Thorsten From thorsten at thorstenkampe.de Tue Feb 3 04:29:29 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Tue, 3 Feb 2009 10:29:29 +0100 Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <67d8a4d2-0b3d-4b41-84e2-698f17cb8e88@35g2000pry.googlegroups.com> Message-ID: * thmpsn.m.k at gmail.com (Mon, 2 Feb 2009 09:02:13 -0800 (PST)) > On Feb 2, 2:55?am, Stephen Hansen wrote: > > > This is proven > > > by your statement above, whereby you are driving a user away, > > > simply because the language, in one small aspect, does not > > > give him what he wants, and the tenor of this thread has been > > > very much: "That's how it is - like it or lump it", and no amount > > > of careful explanation of why people want the feature has cut > > > any ice - > > > > I'm missing the careful explanation. What I've heard is that the lack > > of enforced encapsulation is "a danger". What I've heard is that > > people want it because they've been told they should want it and > > believe that. Why? > > Who has said the latter? Are you just trying to spread FUD? No, he's not. He's giving his and other people's impression of the pro- private group's arguments. They construct cases that do not exist in reality or can more-than-easily be avoided. > > There have been no "careful explanations" to answer that, in my mind. > > And thus my response is: the practical possibility of needing access > > vastly outweights the theoretical situation that might go bad if > > encapsulation wasn't there. Why? Because in any real situation, IMHO, > > *forced* encapsulation is pointless. > > I think you've gotten too subjective on this matter. You might as well > say that we don't need no stinkin' OOP, we could all just be > programming with goto's. It's even simpler: "don't use other people's underscores". It couldn't get more simple than that. > > > It has all the time been countered with statements > > > about how the proponents of private attributes "don't need it", > > > (as if they are plain dumb), > > > > They don't need it. No one has shown a *real* reason why. The only > > reasons provided are "its a DANGER" that someone "MIGHT DO BAD". > > That's not a real reason. If its your project that someone is doing > > bad in, this is a situation which can be *clearly* specified in a > > projects policy and coding standards and can be *trivially* tested for > > with simple static analysis in nearly all cases. The problem is the > > person and not the code then. There's *countless* other ways that > > person can do bad if you're allowing them to commit blindly anything > > into your project. > > Aha! I see this attitude quite often among C/C++ people, regarding > buffer overflows and uninitialized pointer dereferences: someone will > say "C and C++ are unsafe languages because they allow you to overrun > buffers", then a C/C++ zealot will respond "Hire some good > programmers". > > SAME ATTITUDE. Not at all. Buffer overflows cannot be easily avoided in C/C++ like languages. On the contrary you can easily avoid other people's privates by simply not using their underscores. It's really that simple. Even I got that - and I'm a really simple guy. Thorsten From tjreedy at udel.edu Tue Feb 3 04:34:30 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 03 Feb 2009 04:34:30 -0500 Subject: Varibles -- copies and references In-Reply-To: References: Message-ID: Ferdinand Sousa wrote: > Hi > > Some weeks back I had been following the thread "Why can't assign to > function call". Today, I saw the "function scope" thread, and decided I > should ask about the behaviour below: > > >>> > # Simple variables > >>>p=55 > >>> q=p > >>> q > 55 > >>> q=44 > >>> p > 55 > >>> > >>> > # In a function > >>> def dd(d): > del d['key'] > return d You both mutated and returned the input object. This is undesirable. All built-in functions and methods that mutate an object have a verb for a name and return nothing. (Ok, find an exception if you can, but that is the intented convention.) Statements, of course, also have no 'return'. So either def strip_key(d): del d['key'] # or def stripped_of_key(d): newd = dict(d) del newd['key'] return newd tjr From marco at sferacarta.com Tue Feb 3 04:42:06 2009 From: marco at sferacarta.com (Marco Mariani) Date: Tue, 03 Feb 2009 10:42:06 +0100 Subject: is python Object oriented?? In-Reply-To: References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <67d8a4d2-0b3d-4b41-84e2-698f17cb8e88@35g2000pry.googlegroups.com> <26a3c05c-253d-4134-bcb9-aed8505f250e@e1g2000pra.googlegroups.com> Message-ID: Thorsten Kampe wrote: > This scenario is highly "supposing" and doesn't look like a real-world- > case to me. But anyway: the obvious solution in my humble opinion would > be to do something like "public_attribute = _private_attribute". But > that would be too simple, too "unjavaesque", right?! Yes, the use of @property is.. cheating!! Shame on you! :) From hongyuan1306 at gmail.com Tue Feb 3 04:48:40 2009 From: hongyuan1306 at gmail.com (Yuan HOng) Date: Tue, 3 Feb 2009 17:48:40 +0800 Subject: urllib2.open always send 'Accept-Encoding: gzip, deflate' under Windows In-Reply-To: <91320d220902030056h49db6a10pe4000ef934a95a6a@mail.gmail.com> References: <91320d220902030056h49db6a10pe4000ef934a95a6a@mail.gmail.com> Message-ID: <91320d220902030148u5ff6e5awd6fe9728d70da9e7@mail.gmail.com> Hi, I got the reason. It has nothing to do with Python and its libraries. I have Symantec Client Security installed on the test machine, and it is modifying the content encoding header for outgoing http request, which is a strange thing. Disable the firewall and the problem goes away. -- Hong Yuan ????????? ??????????? http://www.homemaster.cn -------------- next part -------------- An HTML attachment was scrubbed... URL: From thorsten at thorstenkampe.de Tue Feb 3 05:11:04 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Tue, 3 Feb 2009 11:11:04 +0100 Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <67d8a4d2-0b3d-4b41-84e2-698f17cb8e88@35g2000pry.googlegroups.com> <26a3c05c-253d-4134-bcb9-aed8505f250e@e1g2000pra.googlegroups.com> Message-ID: * Marco Mariani (Tue, 03 Feb 2009 10:42:06 +0100) > Thorsten Kampe wrote: > > This scenario is highly "supposing" and doesn't look like a > > real-world- case to me. But anyway: the obvious solution in my > > humble opinion would be to do something like "public_attribute = > > _private_attribute". But that would be too simple, too > > "unjavaesque", right?! > > Yes, the use of @property is.. cheating!! Shame on you! :) "Decorators", right? Never used that, but I read about it... Thorsten From dickinsm at gmail.com Tue Feb 3 05:19:21 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Tue, 3 Feb 2009 02:19:21 -0800 (PST) Subject: Number of bits/sizeof int References: <877i48obxy.fsf.mdw@metalzone.distorted.org.uk> <7d8c7677-e1e1-4d6a-9615-58144f776a59@t26g2000prh.googlegroups.com> <87wsc8mi5i.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <282bf012-2191-4178-8cc1-adfd4fa55431@u18g2000pro.googlegroups.com> On Feb 3, 1:19?am, Mark Wooding wrote: > Yeah, I made some arbitrary choices about what to do with non-positive > inputs. ?If you prefer other answers, use 'em. ?My ones work well with > signed-magnitude representations where the sign is stored separately. Not *that* arbitrary: they're the same choices that were made (after some discussion) for the int.bit_length method, which is what the OP was looking to replace. They're also identical to the choices that Mathematica made for its BitLength function... As Mark says, this seems a natural choice for sign-magnitude representation, which is what almost every bignum library seems to use under the hood. Mark From Lie.1296 at gmail.com Tue Feb 3 05:21:56 2009 From: Lie.1296 at gmail.com (Lie) Date: Tue, 3 Feb 2009 02:21:56 -0800 (PST) Subject: Import without executing module References: <7a9c25c20902012319i2d217644k12bc926400f630c2@mail.gmail.com> <14edd870-74d4-4d7a-a363-a4bc3515a071@s9g2000prg.googlegroups.com> <0ad1a5c0-0605-49fe-8a97-1159fc274d30@a39g2000prl.googlegroups.com> Message-ID: <45e5daf1-108c-499e-82a9-10e67eac33e2@z27g2000prd.googlegroups.com> On Feb 3, 1:37?pm, Ray wrote: > I'll enclose the top-level commands with the if statement above...its > just a minor change, but it seems unavoidable. > > Thanks again! > > Ray If you really don't want the file to be changed, you could (depends on the module) use the module as a subprocess. The ideal solution is for the module to have an if __name__ == '__main__': to determine whether it is being used as a module or a standalone program though. From marco at sferacarta.com Tue Feb 3 05:25:35 2009 From: marco at sferacarta.com (Marco Mariani) Date: Tue, 03 Feb 2009 11:25:35 +0100 Subject: what IDE is the best to write python? In-Reply-To: References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> <874ozd3cr3.fsf@benfinney.id.au> <87y6woz659.fsf@benfinney.id.au> Message-ID: Russ P. wrote: > highlighting. Not that it really helps much, but it "spices up" the > code and stimulates the eyes and brain. When I see the same code > without color highlighting, it just seems bland, like something is > missing. It seems like just "text" rather than "code." Plus, it can be configured to induce seizures when the programmer tries to write private methods ;) From stef.mientki at gmail.com Tue Feb 3 05:38:25 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Tue, 3 Feb 2009 11:38:25 +0100 Subject: what IDE is the best to write python? In-Reply-To: <4987D8B0.4030904@internode.on.net> References: <4987D8B0.4030904@internode.on.net> Message-ID: <3dfd60f20902030238i609a1a25w1296c4bb5ff17cd0@mail.gmail.com> > > > Clip Libraries are stored in simple text files. > > This is such a simple concept but is so very productive. Who needs an IDE?. > I would love to have a Linux text editor (like Scite or GEdit) that could do > this. > The code snippet manager, part of a huge IDE, but can be used as a standalone tool on any OS, might be what your looking for http://mientki.ruhosting.nl/data_www/pylab_works/pw_code_editor.html you can find the code here http://code.google.com/p/pylab-works cheers, Stef -------------- next part -------------- An HTML attachment was scrubbed... URL: From cd at okunah.de Tue Feb 3 05:51:40 2009 From: cd at okunah.de (Christof Donat) Date: Tue, 03 Feb 2009 11:51:40 +0100 Subject: Bitwise 2009 ($5000 prize money) References: Message-ID: Hi, > http://www.bitwise.iitkgp.ernet.in/ I'm having quite some fun reading the questions since I got this Post in comp.lang.c++ before. Here it is of topic and this crosspostings will definatelly not be a good advertisement for your contest. Christof From bruno.42.desthuilliers at websiteburo.invalid Tue Feb 3 06:09:46 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 03 Feb 2009 12:09:46 +0100 Subject: is python Object oriented?? In-Reply-To: References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com> <003d01c98527$d9ea4ec0$0d00a8c0@hendrik> <005201c98549$d3eb74a0$0d00a8c0@hendrik> <2ed10ddd-63ac-4507-b046-0404cc85c97a@s1g2000prg.googlegroups.com> Message-ID: <498825f3$0$3303$426a74cc@news.free.fr> Steven D'Aprano a ?crit : > On Tue, 03 Feb 2009 03:48:58 +0000, Rhodri James wrote: > >> On Tue, 03 Feb 2009 02:16:01 -0000, Russ P. >> wrote: >> >>> Here we go again. If you have access to the source code (as you nearly >>> always do with Python code), then "breaking the language-enforced data >>> hiding" is a trivial matter of deleting the word "private" (or >>> equivalent). >> If it's that trivial to defeat something that its proponents appear to >> want to be close to an iron-clad guarantee, what on earth is the point >> of using "private" in the first place? > > Well, that is a good question. > > Since it is even more trivial to defeat Python's private-by-convention > data hiding, why even bother? Just make everything public. What on earth > is the point of prefixing an attribute with an underscore? To make clear it is *not* part of the API. The point is about enforced access restriction, not encapsulation. > > I think this debate has a lot to do with people's attitudes towards "No > User Serviceable Parts". Some people are comfortable using black-boxes, > and if (enforced) data hiding makes it easier for others to build safe, > efficient black-boxes, then they're willing to give up that a little bit > of flexibility/freedom for the benefit of safe, efficient black-boxes. > > Others prefer white-boxes, and are willing to give up some safety and > efficiency, and live with increased risk and lower performance, just in > case some day they might want to open up the white-box and replace the > widget with a gadget. I don't see how this relates to efficiency. > Some of us consider that a black-box sealed with regular Phillips head > screws is still be an effective black-box. And most of us here go as far as considering that something as simple as a "warranty broke if unsealed" label is enough. > It's not hard to find a screw > driver and open the box, but it's still an effective barrier against > casual and accidental tinkering while allowing deliberate tinkering. Idem for a label. You *see* it, don't you ? So you cannot pretend you "accidentaly" opened the box. > Others take the attitude that anything short of resistance to oxy torches > and diamond-tipped drills might as well be in a paper bag, and therefore > there's no point to black-boxes at all. straw-man argument once again. No one here says taht there's no point to black-box - just that there's no point having to resort to any special screw-driver if and when we want to treat it as a white box. > I find this extreme position is rather incoherent. It's *your* oversimplification of the point against *enforced* access restriction that makes it incoherent. (snip) > Another extreme position is that enforced data hiding is useless, that > there is *never* any need for it *at all*, and therefore Python doesn't > need it, there's no reason except stupid PHB's belief in cargo-cult > coding why Python couldn't be used for controlling nuclear reactors or > the Space Shuttle. There may be quite a lot of reasons to think (rightly or not) that Python is not suited for such tasks. Anyway, I personnaly don't care whether Python would be the right tool for such cases, because - like probably more than 99.99% of Python users - that's not what I'm using it for, and I don't see any reason to add such useless arbitrary restrictions just because 2 or 3 persons claims that it's "how it should be". FWIW, since anything dynamic would be considered unsafe in the mentioned use cases, the next point would be to make Python as static as Java. Yeah, great. > There's been some claims remarkably close to that in > this or the previous thread. I trust that nobody really believes this > extreme position -- it's not that far off claiming that procedures and > functions are pointless and stupid because we have GOTO. yet another straw man argument. > I love Python, and I'm greedy and want it all: I want a dynamic, easy-to- > use language *and* a compiler that can protect me from myself That's not what compilers are for. > and bad > data. I definitly fail to see how a compiler could protect you from *runtime* issues ??? > I'm envious of Haskell's type-inference. I want the option to have > the compiler warn me when some function is messing with my classes' > internals as soon as I hit Enter, May I remind you that "def" and "class" are executable statements ? > > I'm not going to *demand* the choice of white-box or black-box classes. I > don't have the right to demand anything. But I can ask, I can try to make > my case (to those who will listen), and I refuse to be brow-beaten by > those who think Python is Just About Perfect Just The Way It Is into > feeling *ashamed* for wanting that choice. It's not about Python being "Just About Perfect Just The Way It", it's about deciding whether enforced access restriction is of any use (at least for a very large majority of it's users), and if it's worth imposing design changes so fundamuntal they would just turn Python into a totally different language just because a couple guys ask for it. Anyway: the choice is neither yours nor mine, so all this discussion is more than pointless. If you really want such drastic changes in Python's design and implementation, submit a PEP. From mohana2004 at gmail.com Tue Feb 3 06:53:20 2009 From: mohana2004 at gmail.com (mohana2004 at gmail.com) Date: Tue, 3 Feb 2009 03:53:20 -0800 (PST) Subject: Date Comparison Message-ID: <2806523d-bba6-48e4-b23f-c27e069f00b8@o40g2000yqb.googlegroups.com> Hi, I need to compare two dates and find the number of days between those two dates.This can be done with datetime module in python as below, but this is not supported in Jython. example from datetime import date a=datetime.date(2009,2,1) b=datetime.date(2008,10,10) c= a-b c.days 114 Is there any other function to do the same(should be supported by Jython) Regards, Monyl From crculver at christopherculver.com Tue Feb 3 08:07:09 2009 From: crculver at christopherculver.com (Christopher Culver) Date: Tue, 03 Feb 2009 15:07:09 +0200 Subject: Unzipping a .zip properly, and from a remote URL Message-ID: <874ozbhdoi.fsf@christopherculver.com> Returning to Python after several years away, I'm working on a little script that will download a ZIP archive from a website and unzip it to a mounted filesystem. The code is below, and it works so far, but I'm unsure of a couple of things. The first is, is there a way to read the .zip into memory without the use of a temporary file? If I do archive = zipfile.ZipFile(remotedata.read()) directly without creating a temporary file, the zipfile module complains that the data is in the wrong string type. The second issue is that I don't know if this is the correct way to unpack a file onto the filesystem. It's strange that the zipfile module has no one simple function to unpack a zip onto the disk. Does this code seem especially liable to break? try: remotedata = urllib2.urlopen(theurl) except IOError: print("Network down.") sys.exit() data = os.tmpfile() data.write(remotedata.read()) archive = zipfile.ZipFile(data) if archive.testzip() != None: print "Invalid zipfile" sys.exit() contents = archive.namelist() for item in contents: try: os.makedirs(os.path.join(mountpoint, os.path.dirname(item))) except OSError: # OSError means that the dir already exists, but no matter. pass if item[-1] != "/": outputfile = open(os.path.join(mountpoint, item), 'w') outputfile.write(archive.read(item)) outputfile.close() From sk8in_zombi at yahoo.com.au Tue Feb 3 08:22:01 2009 From: sk8in_zombi at yahoo.com.au (Mr SZ) Date: Tue, 3 Feb 2009 05:22:01 -0800 (PST) Subject: imaplib thread method anomaly Message-ID: <113545.23852.qm@web54507.mail.re2.yahoo.com> Hi, I was looking at the thread functionality of IMAP4rev1 servers with the threading extension. Here is my output with debug=8 : 02:23.02 > GDJB3 UID THREAD references UTF-8 (SEEN) 02:23.02 < * THREAD (3)(2)(4)(1) 02:23.02 matched r'\* (?P[A-Z-]+)( (?P.*))?' => ('THREAD', ' (3)(2)(4)(1)', '(3)(2)(4)(1)') 02:23.03 untagged_responses[THREAD] 0 += ["(3)(2)(4)(1)"] 02:23.03 < GDJB3 OK Thread completed. 02:23.03 matched r'(?PGDJB\d+) (?P[A-Z]+) (?P.*)' => ('GDJB3', 'OK', 'Thread completed.') [None] ... 02:59.22 > CNCF3 THREAD references UTF-8 (SEEN) 02:59.23 < * THREAD (3)(2)(4)(1) 02:59.23 matched r'\* (?P[A-Z-]+)( (?P.*))?' => ('THREAD', ' (3)(2)(4)(1)', '(3)(2)(4)(1)') 02:59.23 untagged_responses[THREAD] 0 += ["(3)(2)(4)(1)"] 02:59.23 < CNCF3 OK Thread completed. 02:59.23 matched r'(?PCNCF\d+) (?P[A-Z]+) (?P.*)' => ('CNCF3', 'OK', 'Thread completed.') 02:59.23 untagged_responses[THREAD] => ['(3)(2)(4)(1)'] ['(3)(2)(4)(1)'] As you can see, the first is a UID command and the second is calling the thread method. Also, the server responses are the same for both. So why is one returning None and the other returning the correct response? I'm using python2.4 and I'm stuck with it as I'm using it in a zope environment. Regards, SZ " life isn't heavy enough,it flies away and floats far above action" Make Yahoo!7 your homepage and win a trip to the Quiksilver Pro. Find out more From tino at wildenhain.de Tue Feb 3 08:32:55 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Tue, 03 Feb 2009 14:32:55 +0100 Subject: Unzipping a .zip properly, and from a remote URL In-Reply-To: <874ozbhdoi.fsf@christopherculver.com> References: <874ozbhdoi.fsf@christopherculver.com> Message-ID: <49884787.9010805@wildenhain.de> Hi, Christopher Culver wrote: > Returning to Python after several years away, I'm working on a little > script that will download a ZIP archive from a website and unzip it to > a mounted filesystem. The code is below, and it works so far, but I'm > unsure of a couple of things. > > The first is, is there a way to read the .zip into memory without the > use of a temporary file? If I do archive = zipfile.ZipFile(remotedata.read()) > directly without creating a temporary file, the zipfile module > complains that the data is in the wrong string type. Which makes sense given the documentation (note you can either browse the HTML online/offline or just use help() within the interpreter/ide: Help on class ZipFile in module zipfile: class ZipFile | Class with methods to open, read, write, close, list zip files. | | z = ZipFile(file, mode="r", compression=ZIP_STORED, allowZip64=True) | | file: Either the path to the file, or a file-like object. | If it is a path, the file will be opened and closed by ZipFile. | mode: The mode can be either read "r", write "w" or append "a". | compression: ZIP_STORED (no compression) or ZIP_DEFLATED (requires zlib). | allowZip64: if True ZipFile will create files with ZIP64 extensions when | needed, otherwise it will raise an exception when this would | be necessary. | ... so instead you would use archive = zipfile.ZipFile(remotedata) > The second issue is that I don't know if this is the correct way to > unpack a file onto the filesystem. It's strange that the zipfile > module has no one simple function to unpack a zip onto the disk. Does > this code seem especially liable to break? > > try: > remotedata = urllib2.urlopen(theurl) > except IOError: > print("Network down.") > sys.exit() > data = os.tmpfile() > data.write(remotedata.read()) > > archive = zipfile.ZipFile(data) > if archive.testzip() != None: > print "Invalid zipfile" > sys.exit() > contents = archive.namelist() > > for item in contents: ... here you should check the zipinfo entry and normalize and clean the path just in case to avoid unpacking a zipfile with special crafted paths (like /etc/passwd and such) Maybe also checking for the various encodings (like utf8) in pathnames makes sense. The dir-creation could be put into a class with caching of already existing subdirectories created and recursive creation of missing subdirectories as well es to make sure you do not ascend out of your target directory by accident (or crafted zip, see above). Regards Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From deets at nospam.web.de Tue Feb 3 08:34:09 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 03 Feb 2009 14:34:09 +0100 Subject: Date Comparison References: <2806523d-bba6-48e4-b23f-c27e069f00b8@o40g2000yqb.googlegroups.com> Message-ID: <6uqvehFgpaciU1@mid.uni-berlin.de> mohana2004 at gmail.com wrote: > Hi, > I need to compare two dates and find the number of days between those > two dates.This can be done with datetime module in python as below, > but this is not supported in Jython. > > example > from datetime import date > a=datetime.date(2009,2,1) > b=datetime.date(2008,10,10) > c= a-b > c.days > 114 > > Is there any other function to do the same(should be supported by > Jython) Use the java API of java.util. That methods like before and after on date-objects. Diez From crculver at christopherculver.com Tue Feb 3 08:38:09 2009 From: crculver at christopherculver.com (Christopher Culver) Date: Tue, 03 Feb 2009 15:38:09 +0200 Subject: Unzipping a .zip properly, and from a remote URL References: <874ozbhdoi.fsf@christopherculver.com> Message-ID: <87y6wnfxoe.fsf@christopherculver.com> Tino Wildenhain writes: > so instead you would use archive = zipfile.ZipFile(remotedata) That produces the following error if I try that in the Python interpreter (URL edited for privacy): >>> import zipfile >>> import urllib2 >>> remotedata = urllib2.urlopen("http://...file.zip") >>> archive = zipfile.ZipFile(remotedata) Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.5/zipfile.py", line 346, in __init__ self._GetContents() File "/usr/lib/python2.5/zipfile.py", line 366, in _GetContents self._RealGetContents() File "/usr/lib/python2.5/zipfile.py", line 376, in _RealGetContents endrec = _EndRecData(fp) File "/usr/lib/python2.5/zipfile.py", line 133, in _EndRecData fpin.seek(-22, 2) # Assume no archive comment. AttributeError: addinfourl instance has no attribute 'seek' From alan.isaac at gmail.com Tue Feb 3 08:49:36 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Tue, 03 Feb 2009 13:49:36 GMT Subject: what IDE is the best to write python? In-Reply-To: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> Message-ID: On 2/1/2009 2:42 AM mcheung63 at hotmail.com apparently wrote: > Hi all > what IDE is the best to write python? http://blog.sontek.net/2008/05/11/python-with-a-modular-ide-vim/ Alan Isaac PS Also maybe see: http://vim.sourceforge.net/scripts/script.php?script_id=30 http://www.builderau.com.au/program/python/soa/Extending-Vim-with-Python/0,2000064084,339283181,00.htm http://www.vim.org/scripts/script.php?script_id=790 http://www.vim.org/scripts/script.php?script_id=2527 http://www.tummy.com/Community/Presentations/vimpython-20070225/vim.html From simon at mullis.co.uk Tue Feb 3 08:52:07 2009 From: simon at mullis.co.uk (Simon Mullis) Date: Tue, 3 Feb 2009 14:52:07 +0100 Subject: parse date/time from a log entry with only strftime (and no regexen) Message-ID: <23d7e1bb0902030552j6a12dcbcy428c9ede8419fb7b@mail.gmail.com> Hi All I'm writing a script to help with analyzing log files timestamps and have a very specific question on which I'm momentarily stumped.... I'd like the script to support multiple log file types, so allow a strftime format to be passed in as a cli switch (default is %Y-%m-%d %H:%M:%S). When it comes to actually doing the analysis I want to store or discard the log entry based on certain criteria. In fact, I only need the log line timestamp. I'd like to do this in one step and therefore not require the user to supply a regex aswell as a strftime format: >>> import datetime >>> p = datetime.datetime.strptime("2008-07-23 12:18:28 this is the remainder of the log line that I do not care about", "%Y-%m-%d %H:%M:%S") Traceback (most recent call last): File "", line 1, in File "/opt/local/lib/python2.5/_strptime.py", line 333, in strptime data_string[found.end():]) ValueError: unconverted data remains: this is the remainder of the log line that I do not care about >>> repr(p) NameError: name 'p' is not defined Clearly the strptime method above can grab the right bits of data but the string "p" is not created due to the error. So, my options are: 1 - Only support one log format. 2 - Support any log format but require a regex as well as a strftime format so I can extract the "timestamp" portion. 3 - Create another class/method with a lookup table for the strftime options that automagically creates the correct regex to extract the right string from the log entry... (or is this overly complicated) 4 - Override the method above (strptime) to allow what I'm trying to do). 4 - Some other very clever and elegant solution that I would not ever manage to think of myself.... Am I making any sense whatsoever? Thanks SM (P.S The reason I don't want the end user to supply a regex for the timestamin he log-entry is that we're already using 2 other regexes as cli switches to select the file glob and log line to match....) -------------- next part -------------- An HTML attachment was scrubbed... URL: From wmcclain at watershade.net Tue Feb 3 08:56:09 2009 From: wmcclain at watershade.net (Bill McClain) Date: 3 Feb 2009 13:56:09 GMT Subject: Date Comparison References: <2806523d-bba6-48e4-b23f-c27e069f00b8@o40g2000yqb.googlegroups.com> Message-ID: On 2009-02-03, mohana2004 at gmail.com wrote: > Hi, > I need to compare two dates and find the number of days between those > two dates.This can be done with datetime module in python as below, > but this is not supported in Jython. There are julian day routines in this astronomy package: http://astrolabe.sourceforge.net/ -Bill -- Sattre Press In the Quarter http://sattre-press.com/ by Robert W. Chambers info at sattre-press.com http://sattre-press.com/itq.html From simon at brunningonline.net Tue Feb 3 09:00:34 2009 From: simon at brunningonline.net (Simon Brunning) Date: Tue, 3 Feb 2009 14:00:34 +0000 Subject: Date Comparison In-Reply-To: <6uqvehFgpaciU1@mid.uni-berlin.de> References: <2806523d-bba6-48e4-b23f-c27e069f00b8@o40g2000yqb.googlegroups.com> <6uqvehFgpaciU1@mid.uni-berlin.de> Message-ID: <8c7f10c60902030600qd6d0db3tb4e9f02914a8f093@mail.gmail.com> 2009/2/3 Diez B. Roggisch : > Use the java API of java.util. Or better still, use Joda. -- Cheers, Simon B. From tino at wildenhain.de Tue Feb 3 09:32:26 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Tue, 03 Feb 2009 15:32:26 +0100 Subject: Unzipping a .zip properly, and from a remote URL In-Reply-To: <87y6wnfxoe.fsf@christopherculver.com> References: <874ozbhdoi.fsf@christopherculver.com> <87y6wnfxoe.fsf@christopherculver.com> Message-ID: <4988557A.5020407@wildenhain.de> Christopher Culver wrote: > Tino Wildenhain writes: >> so instead you would use archive = zipfile.ZipFile(remotedata) > > That produces the following error if I try that in the Python > interpreter (URL edited for privacy): > >>>> import zipfile >>>> import urllib2 >>>> remotedata = urllib2.urlopen("http://...file.zip") >>>> archive = zipfile.ZipFile(remotedata) > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python2.5/zipfile.py", line 346, in __init__ > self._GetContents() > File "/usr/lib/python2.5/zipfile.py", line 366, in _GetContents > self._RealGetContents() > File "/usr/lib/python2.5/zipfile.py", line 376, in _RealGetContents > endrec = _EndRecData(fp) > File "/usr/lib/python2.5/zipfile.py", line 133, in _EndRecData > fpin.seek(-22, 2) # Assume no archive comment. > AttributeError: addinfourl instance has no attribute 'seek' Oh thats annoying. In this case short of providing a buffered wrapper (which is possible) you would stick to the temp file for an easy solution. Sorry about that. Regards Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From jcd at sdf.lonestar.org Tue Feb 3 09:54:16 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Tue, 03 Feb 2009 09:54:16 -0500 Subject: English-like Python In-Reply-To: <497899D0.5030706@strout.net> References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> <497899D0.5030706@strout.net> Message-ID: <1233672856.7189.7.camel@aalcdl07.lib.unc.edu> On Thu, 2009-01-22 at 09:07 -0700, Joe Strout wrote: > >> Beep > >> > >> Doesn't get much more readable and syntax-free than that. > > > > readable doesn't mean smallest amount of syntax possible sometimes > syntax > > increases the readability of a text as you would see if we for > example > > dropped all punctuation but you probably already knew that but > perhaps > > you didnt draw the connection with programming language wink > > Cute. But I stand by my contention that "Beep" is about the most > readable way imaginable to express the "make a beep sound now please" > command, and any additional punctuation (parentheses, semicolons, > etc.) > only get in the way. > But what if your language allows functions to be used as first class objects? (Mine does :)) x = Beep Does that assign the name x to the Beep object or does it assign the result of a Beep call to x? There's no virtue in making ridiculously simple things even simpler if it makes the interesting things impossible. def tone_sequence(sound): sequence = DialTone.followed_by(sound) sequence() for x in Beep, Buzz, Warble: tone_sequence(x) Cheers, Cliff From nick at craig-wood.com Tue Feb 3 10:32:00 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Tue, 03 Feb 2009 09:32:00 -0600 Subject: Code critique xmlrpclib References: <4c54d31a-6b8e-40ba-9124-850abff6c69e@g3g2000pre.googlegroups.com> Message-ID: flagg wrote: > This xmlrpc server is designed to parse dns zone files and then > perform various actions on said files. \ > It uses dnspython, and xmlrpclib > I'd like to know what some of the more experienced python users > think. Where I could improve code, make it more efficient, whatever. > All suggestions are welcome. This is my first functional python > program, and I have tons of questions to go along with whatever > suggestions. How could I do sanity checking; right now nothing > checks the input to these functions, error-handling in this program is > almost non-existant how do you integrate decent error handling into a > piece of software......ill shut up now. I made a few comments, some about error handling! See below > import dns.zone > from time import localtime, strftime, time > import os, sys > from dns.rdataclass import * > from dns.rdatatype import * > from string import Template > import xmlrpclib > from SimpleXMLRPCServer import SimpleXMLRPCServer > from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler > > > zoneDir = "/dns" > > def openZoneFile(zoneFile): > """ > Opens a zone file. Then reads in zone file to dnspython zone > object. > """ > global zone > global host > global domain > domain = ".".join(zoneFile.split('.')[1:]) > host = ".".join(zoneFile.split('.')[:1]) > > try: > zone = dns.zone.from_file(zoneDir + domain + '.zone', > domain) > except dns.exception, e: > print e.__class__, e Don't use global variables! This function should probably return 3 things return zone, host, domain And whenever you use it, say zone, host, domain = openZoneFile(xxx) It should probably be a method of DNSFunctions. I'd avoid setting self.zone etc as that is making a different sort of global data which I'd avoid too. Also if the dns.zone.from_file didn't work (raises dns.exception) you set the host and domain but the zone is left at its previous value which probably isn't what you wanted. I'd let the error propagate which I think will do something sensible for the xmlrpc. > class DNSFunctions: > > # Not exposed to xml-rpc calls, used internally only. > def _writeToZoneFile(self, record): > """ > Checks if zone file exists, if it does it write values to zone > file > """ > > for (name, ttl, rdata) in zone.iterate_rdatas(SOA): > new_serial = int(strftime('%Y%m%d00', localtime(time()))) > if new_serial <= rdata.serial: > new_serial = rdata.serial + 1 > rdata.serial = new_serial > > if os.path.exists(zoneDir + str(zone.origin) + "zone"): > f = open(zoneDir + str(zone.origin) + "zone", "w") > zone.to_file(f) > f.close() > else: > print "Zone: " + zone.origin + " does not exist, please > add first" This should probably be raising an exception to be caught or propagated back to the client via xmlrpc. > > def showRecord(self, record): > """ > Shows a record for a given zone. Prints out > TTL, IN, Record Type, IP > """ > > openZoneFile(record) > > try: > rdataset = zone.get_node(host) > for rdata in rdataset: > return str(rdata) > except: > raise Exception("Record not found") > > > def changeRecord(self, record, type, target): > """ > Changes a dns entry. > @param record: which record to chance > @param type: what type of record, A, MX, NS, CNAME > @target: if CNAME target points to HOSTNAME, if A record > points to IP > """ > openZoneFile(record) > try: > rdataset = zone.find_rdataset(host, rdtype=type) > except: > raise Exception("You must enter a valid record and type. > See --usage for examples") Don't catch all exceptions - find out which exceptions are thrown. Consider just letting it propagate - hopefully the find_rdataset error is descriptive enough. -- Nick Craig-Wood -- http://www.craig-wood.com/nick From jldunn2000 at googlemail.com Tue Feb 3 10:38:38 2009 From: jldunn2000 at googlemail.com (loial) Date: Tue, 3 Feb 2009 07:38:38 -0800 (PST) Subject: Python ssh with SSH Tectia server Message-ID: Has anyone any experiencing with ssh between a python client and the SSH Tectia server from SSH (ssh.com) ? Does it work? From tino at wildenhain.de Tue Feb 3 10:45:13 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Tue, 03 Feb 2009 16:45:13 +0100 Subject: Python ssh with SSH Tectia server In-Reply-To: References: Message-ID: <49886689.6050409@wildenhain.de> Hi, loial wrote: > Has anyone any experiencing with ssh between a python client and the > SSH Tectia server from SSH (ssh.com) ? this might well be. ;) > > Does it work? Did you try? (It should however since at least openssh client worked) Cheers Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From gagsl-py2 at yahoo.com.ar Tue Feb 3 10:45:27 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 03 Feb 2009 13:45:27 -0200 Subject: Extracting file from zip archive in Python 2.6.1 References: <7676f73d-2ee9-4151-8a09-b11a3eea2045@p37g2000yqd.googlegroups.com> Message-ID: En Tue, 03 Feb 2009 05:31:24 -0200, Brandon Taylor escribi?: > I'm having an issue specifying the path for extracting files from > a .zip archive. In my method, I have: > > zip_file.extract(zip_name + '/' + thumbnail_image, thumbnail_path) > > What is happening is that the extract method is creating a folder with > the name of 'zip_name' and extracting the files to it. Example: extract will create all directories in member name. Use open instead: with zip_file.open(zip_name + '/' + thumbnail_image) as source: with open(os.path.join(thumbnail_path, thumbnail_image), "wb") as target: shutil.copyfileobj(source, target) (untested) -- Gabriel Genellina From deets at nospam.web.de Tue Feb 3 10:48:53 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 03 Feb 2009 16:48:53 +0100 Subject: Date Comparison References: <2806523d-bba6-48e4-b23f-c27e069f00b8@o40g2000yqb.googlegroups.com> <6uqvehFgpaciU1@mid.uni-berlin.de> Message-ID: <6ur7b5Fgq8s0U1@mid.uni-berlin.de> Simon Brunning wrote: > 2009/2/3 Diez B. Roggisch : >> Use the java API of java.util. > > Or better still, use Joda. > "dates compare you must?" SCNR. Didn't know of this incarnation of him... Diez From erobererunc at gmail.com Tue Feb 3 10:58:49 2009 From: erobererunc at gmail.com (er) Date: Tue, 3 Feb 2009 10:58:49 -0500 Subject: Python Global State Message-ID: <775033410902030758pa44e7ccl251fc82e6bb90229@mail.gmail.com> Simple question, I think: Is there a way to make a completely global variable across a slew of modules? If not, what is the canonical way to keep a global state? The purpose of this is to try to prevent circular module imports, which just sort of seems nasty. Thank you! -------------- next part -------------- An HTML attachment was scrubbed... URL: From google at mrabarnett.plus.com Tue Feb 3 11:00:40 2009 From: google at mrabarnett.plus.com (MRAB) Date: Tue, 03 Feb 2009 16:00:40 +0000 Subject: parse date/time from a log entry with only strftime (and no regexen) In-Reply-To: <23d7e1bb0902030552j6a12dcbcy428c9ede8419fb7b@mail.gmail.com> References: <23d7e1bb0902030552j6a12dcbcy428c9ede8419fb7b@mail.gmail.com> Message-ID: <49886A28.2080204@mrabarnett.plus.com> Simon Mullis wrote: > Hi All > > I'm writing a script to help with analyzing log files timestamps and > have a very specific question on which I'm momentarily stumped.... > > I'd like the script to support multiple log file types, so allow a > strftime format to be passed in as a cli switch (default is %Y-%m-%d > %H:%M:%S). > > When it comes to actually doing the analysis I want to store or discard > the log entry based on certain criteria. In fact, I only need the log > line timestamp. > > I'd like to do this in one step and therefore not require the user to > supply a regex aswell as a strftime format: > > >>> import datetime > >>> p = datetime.datetime.strptime("2008-07-23 12:18:28 this is the > remainder of the log line that I do not care about", "%Y-%m-%d %H:%M:%S") > Traceback (most recent call last): > File "", line 1, in > File "/opt/local/lib/python2.5/_strptime.py", line 333, in strptime > data_string[found.end():]) > ValueError: unconverted data remains: this is the remainder of the log > line that I do not care about > > >>> repr(p) > NameError: name 'p' is not defined > > Clearly the strptime method above can grab the right bits of data but > the string "p" is not created due to the error. > > So, my options are: > > 1 - Only support one log format. > > 2 - Support any log format but require a regex as well as a strftime > format so I can extract the "timestamp" portion. > > 3 - Create another class/method with a lookup table for the strftime > options that automagically creates the correct regex to extract the > right string from the log entry... (or is this overly complicated) > > 4 - Override the method above (strptime) to allow what I'm trying to do). > > 4 - Some other very clever and elegant solution that I would not ever > manage to think of myself.... > > > Am I making any sense whatsoever? > > Thanks > > SM > > (P.S The reason I don't want the end user to supply a regex for the > timestamin he log-entry is that we're already using 2 other regexes as > cli switches to select the file glob and log line to match....) > If the timestamp is always at the start of the line (and I expect it is) and is always the same length then you could calculate how long the timestamp is from the format (eg "%Y" matches 4 characters) and use string slicing. If the timestamp isn't a fixed length then a generating a regex might be needed. From ianand0204 at gmail.com Tue Feb 3 11:03:01 2009 From: ianand0204 at gmail.com (flagg) Date: Tue, 3 Feb 2009 08:03:01 -0800 (PST) Subject: Code critique xmlrpclib References: <4c54d31a-6b8e-40ba-9124-850abff6c69e@g3g2000pre.googlegroups.com> Message-ID: <106ff6e6-1c23-4adb-8d89-b59d852db458@q30g2000prq.googlegroups.com> On Feb 3, 7:32?am, Nick Craig-Wood wrote: > flagg wrote: > > ?This xmlrpc server is designed to parse dns zone files and then > > ?perform various actions on said files. \ > > ?It uses dnspython, and xmlrpclib > > ? I'd like to know what some of the more experienced python users > > ?think. Where I could improve code, make it more efficient, whatever. > > ?All suggestions are welcome. ?This is my first functional python > > ?program, ?and I have tons of questions to go along with whatever > > ?suggestions. ? How could I do sanity checking; right now nothing > > ?checks the input to these functions, error-handling in this program is > > ?almost non-existant how do you integrate decent error handling into a > > ?piece of software......ill shut up now. > > I made a few comments, some about error handling! ?See below > > > > > ?import dns.zone > > ?from time import localtime, strftime, time > > ?import os, sys > > ?from dns.rdataclass import * > > ?from dns.rdatatype import * > > ?from string import Template > > ?import xmlrpclib > > ?from SimpleXMLRPCServer import SimpleXMLRPCServer > > ?from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler > > > ?zoneDir = "/dns" > > > ?def openZoneFile(zoneFile): > > ? ? ?""" > > ? ? ?Opens a zone file. ?Then reads in zone file to dnspython zone > > ?object. > > ? ? ?""" > > ? ? ?global zone > > ? ? ?global host > > ? ? ?global domain > > ? ? ?domain = ".".join(zoneFile.split('.')[1:]) > > ? ? ?host = ".".join(zoneFile.split('.')[:1]) > > > ? ? ?try: > > ? ? ? ? ? ? ?zone = dns.zone.from_file(zoneDir + domain + '.zone', > > ?domain) > > ? ? ?except dns.exception, e: > > ? ? ? ? ? ? ?print e.__class__, e > > Don't use global variables! > > This function should probably return 3 things > > ? ? return zone, host, domain > > And whenever you use it, say > > ? ? zone, host, domain = openZoneFile(xxx) > > It should probably be a method of DNSFunctions. ?I'd avoid setting > self.zone etc as that is making a different sort of global data which > I'd avoid too. > > Also if the dns.zone.from_file didn't work (raises dns.exception) you > set the host and domain but the zone is left at its previous value > which probably isn't what you wanted. ?I'd let the error propagate > which I think will do something sensible for the xmlrpc. > > > > > ?class DNSFunctions: > > > ? ? ? # Not exposed to xml-rpc calls, used internally only. > > ? ? ?def _writeToZoneFile(self, record): > > ? ? ? ? ?""" > > ? ? ? ? ?Checks if zone file exists, if it does it write values to zone > > ?file > > ? ? ? ? ?""" > > > ? ? ? ? ?for (name, ttl, rdata) in zone.iterate_rdatas(SOA): > > ? ? ? ? ? ? ?new_serial = int(strftime('%Y%m%d00', localtime(time()))) > > ? ? ? ? ? ? ?if new_serial <= rdata.serial: > > ? ? ? ? ? ? ? ? ?new_serial = rdata.serial + 1 > > ? ? ? ? ? ? ?rdata.serial = new_serial > > > ? ? ? ? ?if os.path.exists(zoneDir + str(zone.origin) + "zone"): > > ? ? ? ? ? ? ?f = open(zoneDir + str(zone.origin) + "zone", "w") > > ? ? ? ? ? ? ?zone.to_file(f) > > ? ? ? ? ? ? ?f.close() > > ? ? ? ? ?else: > > ? ? ? ? ? ? ?print "Zone: " + zone.origin + " does not exist, please > > ?add first" > > This should probably be raising an exception to be caught or > propagated back to the client via xmlrpc. > > > > > > > ? ? ?def showRecord(self, record): > > ? ? ? ? ?""" > > ? ? ? ? ?Shows a record for a given zone. Prints out > > ? ? ? ? ?TTL, IN, Record Type, IP > > ? ? ? ? ?""" > > > ? ? ? ? ?openZoneFile(record) > > > ? ? ? ? ?try: > > ? ? ? ? ? ? ?rdataset = zone.get_node(host) > > ? ? ? ? ? ? ?for rdata in rdataset: > > ? ? ? ? ? ? ? ? ?return str(rdata) > > ? ? ? ? ?except: > > ? ? ? ? ? ? ?raise Exception("Record not found") > > > ? ? ?def changeRecord(self, record, type, target): > > ? ? ? ? ?""" > > ? ? ? ? ?Changes a dns entry. > > ? ? ? ? ?@param record: which record to chance > > ? ? ? ? ?@param type: ?what type of record, A, MX, NS, CNAME > > ? ? ? ? ?@target: if CNAME target points to HOSTNAME, if A record > > ?points to IP > > ? ? ? ? ?""" > > ? ? ? ? ?openZoneFile(record) > > ? ? ? ? ?try: > > ? ? ? ? ? ? ?rdataset = zone.find_rdataset(host, rdtype=type) > > ? ? ? ? ?except: > > ? ? ? ? ? ? ?raise Exception("You must enter a valid record and type. > > ?See --usage for examples") > > Don't catch all exceptions - find out which exceptions are thrown. > Consider just letting it propagate - hopefully the find_rdataset error > is descriptive enough. > > -- > Nick Craig-Wood --http://www.craig-wood.com/nick Thanks for taking the time to reply I appreciate it. Are global variables "bad"? Or just inefficient? Also when you say: "Also if the dns.zone.from_file didn't work (raises dns.exception) you set the host and domain but the zone is left at its previous value which probably isn't what you wanted. I'd let the error propagate which I think will do something sensible for the xmlrpc." Could you elaborate on that. Im not following what you mean by "propagate" Thanks again for the suggestions I'll remove the global variables and use the method you described for assigning "host,domain and zone" From Scott.Daniels at Acm.Org Tue Feb 3 11:05:20 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 03 Feb 2009 08:05:20 -0800 Subject: Unzipping a .zip properly, and from a remote URL In-Reply-To: <87y6wnfxoe.fsf@christopherculver.com> References: <874ozbhdoi.fsf@christopherculver.com> <87y6wnfxoe.fsf@christopherculver.com> Message-ID: Christopher Culver wrote: > Tino Wildenhain writes: >> so instead you would use archive = zipfile.ZipFile(remotedata) > That produces the following error if I try that in the Python > interpreter (URL edited for privacy): .... >>>> remotedata = urllib2.urlopen("http://...file.zip") >>>> archive = zipfile.ZipFile(remotedata) No, he means you need to pull down the remote data. Zip file reading is not done in a single pass; it needs to seek to find the directory, then again to get to the data for any particular file. Seeking around a file does not work so well across the net. Try something like: >>> import zipfile >>> import urllib2 >>> import StringIO # or cStringIO as StringIO >>> remotehandle = urllib2.urlopen("http://...file.zip") >>> zipdata = StringIO.StringIO(remotehandle.read()) >>> remotehandle.close() >>> archive = zipfile.ZipFile(zipdata) or: >>> with urllib2.urlopen("http://...file.zip") as remotehandle: ... zipdata = StringIO.StringIO(remotehandle.read()) ... archive = zipfile.ZipFile(zipdata) --Scott David Daniels Scott.Daniels at Acm.Org From google at mrabarnett.plus.com Tue Feb 3 11:10:32 2009 From: google at mrabarnett.plus.com (MRAB) Date: Tue, 03 Feb 2009 16:10:32 +0000 Subject: Python Global State In-Reply-To: <775033410902030758pa44e7ccl251fc82e6bb90229@mail.gmail.com> References: <775033410902030758pa44e7ccl251fc82e6bb90229@mail.gmail.com> Message-ID: <49886C78.5020406@mrabarnett.plus.com> er wrote: > Simple question, I think: Is there a way to make a completely global > variable across a slew of modules? If not, what is the canonical > way to keep a global state? The purpose of this is to try to prevent > circular module imports, which just sort of seems nasty. Thank you! > Simple answer: no. You can put your global state into a module which is imported wherever it's needed: my_globals.py ------------- foo = "" module_1.py ----------- import my_globals ... my_globals.foo = "FOO" ... module_2.py ----------- import my_globals ... print my_globals.foo ... From mdw at distorted.org.uk Tue Feb 3 11:10:59 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 03 Feb 2009 16:10:59 +0000 Subject: Date Comparison References: <2806523d-bba6-48e4-b23f-c27e069f00b8@o40g2000yqb.googlegroups.com> Message-ID: <87hc3bmrfw.fsf.mdw@metalzone.distorted.org.uk> mohana2004 at gmail.com writes: > I need to compare two dates and find the number of days between those > two dates.This can be done with datetime module in python as below, > but this is not supported in Jython. > > example > from datetime import date > a=datetime.date(2009,2,1) > b=datetime.date(2008,10,10) > c= a-b > c.days > 114 I don't understand your problem. Jython 2.2.1 on java1.6.0_0 Type "copyright", "credits" or "license" for more information. >>> from datetime import date >>> a=datetime.date(2009,2,1) >>> b=datetime.date(2008,10,10) >>> c = a - b >>> c.days 114 -- [mdw] From gherron at islandtraining.com Tue Feb 3 11:11:17 2009 From: gherron at islandtraining.com (Gary Herron) Date: Tue, 03 Feb 2009 08:11:17 -0800 Subject: Python Global State In-Reply-To: <775033410902030758pa44e7ccl251fc82e6bb90229@mail.gmail.com> References: <775033410902030758pa44e7ccl251fc82e6bb90229@mail.gmail.com> Message-ID: <49886CA5.9090605@islandtraining.com> er wrote: > Simple question, I think: Is there a way to make a completely global > variable across a slew of modules? No. > If not, what is the canonical way to keep a global state? But this might satisfy: Create a module called, perhaps, global.py which contains your variables. global.py VarA = None VarB = None Then any module can import it and read/write the values. import global global.VarA = ... print global.VarB # and so forth > The purpose of this is to try to prevent circular module imports, > which just sort of seems nasty. Thank you! I'm not sure how that will work. Gary Herron From Scott.Daniels at Acm.Org Tue Feb 3 11:12:29 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 03 Feb 2009 08:12:29 -0800 Subject: is python Object oriented?? In-Reply-To: References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com><0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com><6ul2ieFg1sraU1@mid.uni-berlin.de><73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com><018801c9850e$3e019fe0$0d00a8c0@hendrik><7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com><6uo5koFg8q28U1@mid.uni-berlin.de> <6uoqvrFgh5oeU1@mid.uni-berlin.de> Message-ID: Hendrik van Rooyen wrote: > "Diez B. Roggisch" >> ...Sure one could envision a system where each object is running in it's >> micro-process. > ... I would have loved a > language that supported it, as well as an operating system > (and I do not mean stuff like tiny os and others of that ilk), > but one that really supported fast task switching to make > the micro tasks less expensive on cheap little processors > with scarce resources.... You might enjoy looking at QNX, since I think it is built along the lines you are describing here. I have an ancient copy of their OS, but haven't followed for more than couple of decades. --Scott David Daniels Scott.Daniels at Acm.Org From steve at holdenweb.com Tue Feb 3 11:17:17 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 03 Feb 2009 11:17:17 -0500 Subject: MySQLdb and MySQL stored functions In-Reply-To: <0fef1833-2dae-44d2-a719-9a036ca0907c@l37g2000vba.googlegroups.com> References: <0fef1833-2dae-44d2-a719-9a036ca0907c@l37g2000vba.googlegroups.com> Message-ID: kurt.forrester.fec at googlemail.com wrote: > On Feb 3, 8:28 am, Dennis Lee Bieber wrote: >> On Mon, 2 Feb 2009 23:28:05 -0800 (PST), >> kurt.forrester.... at googlemail.com declaimed the following in >> comp.lang.python: >> >>> However, when I try to use the MySQLdb module it returns an incorrect >>> value (it returns 1). >>> I wish to use the DB API 2.0 compliant module for flexibility. >>> Therefore I am trying to work out why the MySQLdb does not return the >>> value as expected (that is as it is returned by the Query Browser). >>> Any help would be greatly appreciated. >> Show the code! >> >> At a rough guess, given the lack of details... >> >> You forgot to .fetch() the result and are looking at the status code >> from the .execute() >> -- >> Wulfraed Dennis Lee Bieber KD6MOG >> wlfr... at ix.netcom.com wulfr... at bestiaria.com >> HTTP://wlfraed.home.netcom.com/ >> (Bestiaria Support Staff: web-a... at bestiaria.com) >> HTTP://www.bestiaria.com/ > > Correct diagnosis. > > Thanks. > > Any ideas on how to suppress the warning output: > __main__:1: Warning: No data - zero rows fetched, selected, or > processed > -- try: ... except MySQLdb.Warning: pass There is probably some setting you can establish with MySQL so it doesn't raise these warnings: I have never seen one, and zero rows is a perfectly valid retrieval result. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From exarkun at divmod.com Tue Feb 3 11:23:43 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Tue, 3 Feb 2009 11:23:43 -0500 Subject: persistent TCP connection in python using socketserver In-Reply-To: <80bc0bfa-f505-49f9-8d5a-f6574e6f8608@z28g2000prd.googlegroups.com> Message-ID: <20090203162343.12853.1844552571.divmod.quotient.2903@henry.divmod.com> On Sat, 31 Jan 2009 09:31:52 -0800 (PST), markobrien85 at gmail.com wrote: > [snip] > >Cheers mate I had a look into twisted but was put off by the FAQ >stating 1.0+ modules may or may not be stable, and only the 'core' is. >I don't wanna be messing around with a potentially buggy server, so im >gonna roll my own using the sockets module. > For what it's worth, that FAQ entry was grossly out of date. I just deleted it and replaced it with an entry which says the exact opposite. Jean-Paul From gagsl-py2 at yahoo.com.ar Tue Feb 3 11:48:28 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 03 Feb 2009 14:48:28 -0200 Subject: parse date/time from a log entry with only strftime (and no regexen) References: <23d7e1bb0902030552j6a12dcbcy428c9ede8419fb7b@mail.gmail.com> Message-ID: En Tue, 03 Feb 2009 11:52:07 -0200, Simon Mullis escribi?: > I'm writing a script to help with analyzing log files timestamps and > have a > very specific question on which I'm momentarily stumped.... > > I'd like the script to support multiple log file types, so allow a > strftime > format to be passed in as a cli switch (default is %Y-%m-%d %H:%M:%S). >>>> import datetime >>>> p = datetime.datetime.strptime("2008-07-23 12:18:28 this is the > remainder of the log line that I do not care about", "%Y-%m-%d %H:%M:%S") > Traceback (most recent call last): > File "", line 1, in > File "/opt/local/lib/python2.5/_strptime.py", line 333, in strptime > data_string[found.end():]) > ValueError: unconverted data remains: this is the remainder of the log > line > that I do not care about If the logfile has fixed width fields, you may ask the user a column range to extract the date/time information. -- Gabriel Genellina From gdamjan at gmail.com Tue Feb 3 11:51:06 2009 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Tue, 03 Feb 2009 17:51:06 +0100 Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> Message-ID: > Why? - Python is object oriented, but I can write whole systems > without defining a single class. > By analogy, if data hiding is added to language, I could write a > whole system without hiding a single item. I guess the problem is that you would not be able to use some libraries because their author thought that it would be wise to hide everything (a behavior fairly popular in the Java world). Let take some http library as an example, the author would certainly think that hiding the socket object is the only sane thing to do. But what if you just *have* to call that special ioctl on the socket object before it can work in your scenario... In python you can easily go under the hood if you need to do it. -- ?????? ( http://softver.org.mk/damjan/ ) "We think it's a great consumer win, and it's a great industry win, to be able to ensure that with good copy protection, you can have so much functionality for the user", Jordi Rivas, Microsoft Director of Technology From djames.suhanko at gmail.com Tue Feb 3 11:58:27 2009 From: djames.suhanko at gmail.com (Djames Suhanko) Date: Tue, 3 Feb 2009 14:58:27 -0200 Subject: Window (tkinter) with no decoration Message-ID: Hello, programmers! I would like to do a menu bar like kicker or windows menu. is possible? -- Djames Suhanko LinuxUser 158.760 From gagsl-py2 at yahoo.com.ar Tue Feb 3 11:59:07 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 03 Feb 2009 14:59:07 -0200 Subject: Problem using compileall References: <7a9c25c20902022353o6ecafe89m32ece2e8cdeff001@mail.gmail.com> Message-ID: En Tue, 03 Feb 2009 05:53:06 -0200, Stephen Hansen escribi?: > I'm having a slight problem with pre-compiling some files for > distribution > that I'm not sure where to even look for. > > An excerpt from an output: > > C:\mother\Python24\core\application\sysconfig>python -m compileall . > Listing . ... > Compiling .\BulkListClass.py ... > Sorry: TypeError: ('compile() expected string without null bytes',) > Compiling .\BulkUserImporter.py ... > > The BulkListClass is then not creating a PYC. Try this to discover whether the file actually contains a NUL byte or not: f = open("BulkListClass.py","rb") src = f.read() i = src.index('\0') print "found NUL at index", i print repr(src[i-20:i+20]) -- Gabriel Genellina From aahz at pythoncraft.com Tue Feb 3 12:02:18 2009 From: aahz at pythoncraft.com (Aahz) Date: 3 Feb 2009 09:02:18 -0800 Subject: what IDE is the best to write python? References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> Message-ID: In article , Thorsten Kampe wrote: >* Aahz (2 Feb 2009 09:29:43 -0800) >> In article , >> Thorsten Kampe wrote: >>>* Aahz (2 Feb 2009 06:30:00 -0800) >>>> In article <874ozd3cr3.fsf at benfinney.id.au>, >>>> Ben Finney wrote: >>>>>aahz at pythoncraft.com (Aahz) writes: >>>>>> >>>>>> Just to register a contrary opinion: I *hate* syntax highlighting >>>>> >>>>>On what basis? >>>> >>>> It makes my eyes bleed >>> >>>Ever tried sunglasses? >> >> Polarized sunglasses don't work too well with LCD monitors > >Well, the answer to your issue with syntax highlighting is to use a >/decent/ highlighting colour scheme. Don't use that all >purple/red/green/yellow/blue one. That's for psychedelic trips. > >Use a decent colour scheme for adults and you will see that you will >benefit from syntax highlighting. Then I have the problem of copying around the syntax highlighting configuration to every computer I use. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From apt.shansen at gmail.com Tue Feb 3 12:12:53 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 3 Feb 2009 09:12:53 -0800 Subject: Problem using compileall In-Reply-To: References: <7a9c25c20902022353o6ecafe89m32ece2e8cdeff001@mail.gmail.com> Message-ID: <7a9c25c20902030912x15397ae6k97da3d5d661f152c@mail.gmail.com> > Try this to discover whether the file actually contains a NUL byte or not: > > f = open("BulkListClass.py","rb") > src = f.read() > i = src.index('\0') > print "found NUL at index", i > print repr(src[i-20:i+20]) Doh. It did. How the heck did that get there! I hadn't thought to actually look -- which seems terribly dense in retrospect -- because I just assumed whatever regular-Python did to compile the same file, compileall'd duplicate. Doh. :) Thanks. --S From joncle at googlemail.com Tue Feb 3 12:14:14 2009 From: joncle at googlemail.com (Jon Clements) Date: Tue, 3 Feb 2009 09:14:14 -0800 (PST) Subject: Source code for csv module References: <62a2e93e-3b86-44bc-9286-56333edd97f6@t26g2000prh.googlegroups.com> <55c2db4e-8c89-4443-897b-b7ef92e263f1@l33g2000pri.googlegroups.com> <598543ea-2340-41dd-bc76-b787d12148ba@v5g2000prm.googlegroups.com> Message-ID: <7e91345b-1fed-442c-8c4a-aa4f7b580df4@b38g2000prf.googlegroups.com> On 3 Feb, 04:27, Tim Roberts wrote: > vsoler wrote: > > >I'm still interested in learning python techniques. Are there any > >other modules (standard or complementary) that I can use in my > >education? > > Are you serious about this? ?Are you not aware that virtually ALL of the > Python standard modules are written in Python, and are included in their > full, readable source form in every Python installation? ?\Python25\lib in > Windows, /usr/lib/python25 in Linux. > -- > Tim Roberts, t... at probo.com > Providenza & Boekelheide, Inc. Okies, so the sniffer is there as readable python, but the most interesting bit (which fair enough I made the assumption the OP was interested in) is the reader/writer functionality -- which is implemented as a shared library and thus, unless you have a source install of python somewhere, there is no readable code. Jon. From gagsl-py2 at yahoo.com.ar Tue Feb 3 12:16:30 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 03 Feb 2009 15:16:30 -0200 Subject: Where & how to deallocate resources in Python C extension References: <8fe56d94-1d33-44d9-980f-a92c077a30d1@k36g2000pri.googlegroups.com> Message-ID: En Mon, 02 Feb 2009 21:03:18 -0200, escribi?: > I've written a C extension, see code below, to provide a Python > interface to a hardware watchdog timer. As part of the initialization > it makes some calls to mmap, I am wondering should I be making > balanced calls to munmap in some kind of de-init function? Do Python > extensions have d'tors? No, there is no way to de-initialize an extension module. That's a big deficiency. In some cases you may provide your own function (and hope the users call it when needed), or use Py_AtExit. -- Gabriel Genellina From antoniosacchi85 at gmail.com Tue Feb 3 12:22:12 2009 From: antoniosacchi85 at gmail.com (antoniosacchi85 at gmail.com) Date: Tue, 3 Feb 2009 09:22:12 -0800 (PST) Subject: Find the critical points Message-ID: <1b1b6f12-c910-4a13-902d-3523bfe8e3f5@u18g2000pro.googlegroups.com> someone can help me?? I am new to programing, but I need to make some script like this: http://blogs.nyu.edu/blogs/agc282/zia/2008/11/using_python_to_solve_optimiza.html so th equestion is : is possible to open it than it ask something and it tell me the result?? thank you!! p.s. this is my hessiana.py: import sympy as S x,y=S.symbols('xy') f=x**4+x**2-6*x*y+3*y**2 a=S.diff(f,x) S.pprint(a) b=S.diff(f,y) S.pprint(b) S.solve_system([a,b],[x,y]) H=S.hessian(f,[x,y]) M1=S.Matrix([14,-6],[-6,6]) M2=S.Matrix([2,-6],[-6,6]) S.Matrix.berkowitz_minors(M2) S.Matrix.berkowitz_minors(M1) From Scott.Daniels at Acm.Org Tue Feb 3 12:25:27 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 03 Feb 2009 09:25:27 -0800 Subject: Python Global State In-Reply-To: References: <775033410902030758pa44e7ccl251fc82e6bb90229@mail.gmail.com> Message-ID: <1uGdnW8nBLsK4BXUnZ2dnUVZ_ovinZ2d@pdx.net> Gary Herron wrote: > er wrote: >> Simple question, I think: Is there a way to make a completely global >> variable across a slew of modules? > ... > > Create a module called, perhaps, global.py which contains your variables. Bad choice of names (a reserved word). Use globals, or data or global_. Otherwise, the advice is spot-on. --Scott David Daniels Scott.Daniels at Acm.Org From no at spam.thanks Tue Feb 3 12:31:21 2009 From: no at spam.thanks (Keith) Date: Tue, 3 Feb 2009 17:31:21 +0000 (UTC) Subject: Safe to get address of va_list function parameter? References: Message-ID: Is it safe to get the address of a va_list function parameter? Keith From robin at reportlab.com Tue Feb 3 12:36:05 2009 From: robin at reportlab.com (Robin Becker) Date: Tue, 03 Feb 2009 17:36:05 +0000 Subject: x64 speed Message-ID: <49888085.3020709@chamonix.reportlab.co.uk> Whilst doing some portability testing with reportlab I noticed a strange speedup for our unittest suite with python2.5 host win32 xp3 unittest time=42.2 seconds vmware RHEL x64 unittest time=30.9 seconds so it looks like the vmware emulated system is much faster. Is it the x64 working faster at its design sizes or perhaps the compiler or could it be the vmware system caching all writes etc etc? For the red hat x64 build the only special configuration was to use ucs2 I know that the VT bit stuff has made virtualization much better, but this seems a bit weird. -- Robin Becker From thmpsn.m.k at gmail.com Tue Feb 3 12:36:54 2009 From: thmpsn.m.k at gmail.com (thmpsn.m.k at gmail.com) Date: Tue, 3 Feb 2009 09:36:54 -0800 (PST) Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com> <003d01c98527$d9ea4ec0$0d00a8c0@hendrik> <005201c98549$d3eb74a0$0d00a8c0@hendrik> <2ed10ddd-63ac-4507-b046-0404cc85c97a@s1g2000prg.googlegroups.com> <3acf1429-9aec-4e0d-b617-21cbcdf76087@w1g2000prk.googlegroups.com> Message-ID: <22440895-ed68-4643-b833-0befe83d571c@f40g2000pri.googlegroups.com> On Feb 3, 1:14?am, David Cournapeau wrote: > On Tue, Feb 3, 2009 at 2:37 PM, Russ P. wrote: > > On Feb 2, 7:48 pm, "Rhodri James" wrote: > >> On Tue, 03 Feb 2009 02:16:01 -0000, Russ P. wrote: > >> > Here we go again. If you have access to the source code (as you nearly > >> > always do with Python code), then "breaking the language-enforced data > >> > hiding" is a trivial matter of deleting the word "private" (or > >> > equivalent). > > >> If it's that trivial to defeat something that its proponents appear to > >> want to be close to an iron-clad guarantee, what on earth is the point > >> of using "private" in the first place? > > >> -- > >> Rhodri James *-* Wildebeeste Herder to the Masses > > > If a library developer releases the source code of a library, any user > > can trivially "defeat" the access restrictions. But if a team of > > developers is checking in code for a project, the leader(s) of the > > project can insist that the access restrictions be respected to > > simplify the management of interfaces. The larger the team, the more > > useful that can be. That's why Java, C++, Ada, Scala, and other > > languages have a "private" keyword. > > I think a lof of this "discussion" is caused by different usages of > private. My understanding is that you think private is missing in > python because there is no clear different between a member which is > published (part of the API) and one which is not (e.g. whose behavior > may change between different revisions, even minor). I agree the > underscore is not an ideal solution - it is certainly not followed by > all python code out there (not even in python itself - see distutils > for example). > > But I think you are overstating the advantage of private for that > usage, at least for C++. In C++, if you have a public class in a > header: > > class Foo { > ? ? private: > ? ? ? ? int f; > > }; > > It means f is private (cannot be accessed outside Foo instances), but > it is declared in the public header. Actually, when people means this > kind of 'data-hiding', C++ does not bring anything to C itself - after > all, we have used FILE* for years and I have no idea about the FILE > structure. Your lack of knowledge about it doesn't mean that it has somehow magically "private" members. The only reason that most of us don't know what a FILE is is that it's definition is implementation-defined (i.e., every compiler may define it differently). That doesn't have anything to do with private members. For example, on my system, defines FILE as: struct _iobuf { char *_ptr; int _cnt; char *_base; int _flag; int _file; int _charbuf; int _bufsiz; char *_tmpfname; }; typedef struct _iobuf FILE; Given this information, nothing prevents me from writing things like: FILE* fp = fopen("file.txt", "r"); if (!fp) { /* do something */ } printf("fp->_cnt = %d\n", fp->cnt); printf("fp->_flag = %d\n", fp->_flag); printf("fp->_file = %d\n", fp->_file); fp->_flag = 0x20; // OOPS!! > Maybe I still lack experience, but I find neither _ prefixing nor > private/public/protected a satisfaying way to make clear what is > public API and what is not. In particular, if I have a python package > which does not use _ at all, shall I assume everything is public ? Pretty much, unless maybe the code documents what you're not supposed to access: class IOBuf: def __init__(self): self.ptr = "" # <- this is private! self.cnt = 0 # <- this is private! self.base = "" # <- this is private! self.flag = 0 # <- this is private! self.file = 0 # <- this is private! self.charbuf = 0 # <- this is private! self.bufsiz = 0 # <- this is private! self.tmpfname = "" # <- this is private! Nope, not a good idea either... From tundra at tundraware.com Tue Feb 3 12:48:35 2009 From: tundra at tundraware.com (Tim Daneliuk) Date: Tue, 03 Feb 2009 11:48:35 -0600 Subject: x64 speed In-Reply-To: References: Message-ID: Robin Becker wrote: > Whilst doing some portability testing with reportlab I noticed a strange > speedup for our unittest suite with python2.5 > > host win32 xp3 unittest time=42.2 seconds > vmware RHEL x64 unittest time=30.9 seconds > > so it looks like the vmware emulated system is much faster. Is it the > x64 working faster at its design sizes or perhaps the compiler or could > it be the vmware system caching all writes etc etc? For the red hat x64 > build the only special configuration was to use ucs2 > > I know that the VT bit stuff has made virtualization much better, but > this seems a bit weird. Which vmware product? -- ---------------------------------------------------------------------------- Tim Daneliuk tundra at tundraware.com PGP Key: http://www.tundraware.com/PGP/ From Bornstub at gmail.com Tue Feb 3 12:51:36 2009 From: Bornstub at gmail.com (Victor Lin) Date: Tue, 3 Feb 2009 09:51:36 -0800 (PST) Subject: How to call python from a foreign language thread (C++) Message-ID: Hi, I am developing a program that use DirectShow to grab audio data from media files. DirectShow use thread to pass audio data to the callback function in my program, and I let that callback function call another function in Python. I use Boost.Python to wrapper my library, the callback function : class PythonCallback { private: object m_Function; public: PythonCallback(object obj) : m_Function(obj) {} void operator() (double time, const AudioData &data) { // Call the callback function in python m_Function(time, data); } }; Here comes the problem, a thread of DirectShow calls my PythonCallback, namely, call the function in Python. Once it calls, my program just crash. I found this should be threading problem. Then I found this document: http://docs.python.org/c-api/init.html It seems that my program can't call to Python's function from thread directly, because there is Global Interpreter Lock. The python's GIL is so complex, I have no idea how it works. I'm sorry, what I can do is to ask. My question is. What should I do before and after I call a Python function from threads? It may looks like this. void operator() (double time, const AudioData &data) { // acquire lock m_Function(time, data); // release lock } Thanks. Victor Lin. From steve at holdenweb.com Tue Feb 3 12:56:24 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 03 Feb 2009 12:56:24 -0500 Subject: Bitwise 2009 ($5000 prize money) In-Reply-To: References: Message-ID: Christof Donat wrote: > Hi, > >> http://www.bitwise.iitkgp.ernet.in/ > > I'm having quite some fun reading the questions since I got this Post in > comp.lang.c++ before. Here it is of topic and this crosspostings will > definatelly not be a good advertisement for your contest. > Thanks you so much, Christof. The spam filters successfully kept this URL out of c.l.py until you took the trouble to re-publish it. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From f.guerrieri at gmail.com Tue Feb 3 13:01:31 2009 From: f.guerrieri at gmail.com (Francesco Guerrieri) Date: Tue, 3 Feb 2009 19:01:31 +0100 Subject: New filters? was: Re: Bitwise 2009 ($5000 prize money) Message-ID: <79b79e730902031001r6180b531j57c2b1247ba1865c@mail.gmail.com> On Tue, Feb 3, 2009 at 6:56 PM, Steve Holden wrote: > Thanks you so much, Christof. The spam filters successfully kept this > URL out of c.l.py until you took the trouble to re-publish it. > > regards > Steve > Speaking of which: it seems to me that the amount of spam that I receive from clpy has greatly reduced in the last month or so. So it seems that the spam filters are doing a great job. Thanks are due to the people managing them :-) Francesco -------------- next part -------------- An HTML attachment was scrubbed... URL: From cournape at gmail.com Tue Feb 3 13:05:27 2009 From: cournape at gmail.com (David Cournapeau) Date: Wed, 4 Feb 2009 03:05:27 +0900 Subject: is python Object oriented?? In-Reply-To: <22440895-ed68-4643-b833-0befe83d571c@f40g2000pri.googlegroups.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <003d01c98527$d9ea4ec0$0d00a8c0@hendrik> <005201c98549$d3eb74a0$0d00a8c0@hendrik> <2ed10ddd-63ac-4507-b046-0404cc85c97a@s1g2000prg.googlegroups.com> <3acf1429-9aec-4e0d-b617-21cbcdf76087@w1g2000prk.googlegroups.com> <22440895-ed68-4643-b833-0befe83d571c@f40g2000pri.googlegroups.com> Message-ID: <5b8d13220902031005k538c1d12ufb8bede897f43a7c@mail.gmail.com> On Wed, Feb 4, 2009 at 2:36 AM, wrote: > On Feb 3, 1:14 am, David Cournapeau wrote: >> On Tue, Feb 3, 2009 at 2:37 PM, Russ P. wrote: >> > On Feb 2, 7:48 pm, "Rhodri James" wrote: >> >> On Tue, 03 Feb 2009 02:16:01 -0000, Russ P. wrote: >> >> > Here we go again. If you have access to the source code (as you nearly >> >> > always do with Python code), then "breaking the language-enforced data >> >> > hiding" is a trivial matter of deleting the word "private" (or >> >> > equivalent). >> >> >> If it's that trivial to defeat something that its proponents appear to >> >> want to be close to an iron-clad guarantee, what on earth is the point >> >> of using "private" in the first place? >> >> >> -- >> >> Rhodri James *-* Wildebeeste Herder to the Masses >> >> > If a library developer releases the source code of a library, any user >> > can trivially "defeat" the access restrictions. But if a team of >> > developers is checking in code for a project, the leader(s) of the >> > project can insist that the access restrictions be respected to >> > simplify the management of interfaces. The larger the team, the more >> > useful that can be. That's why Java, C++, Ada, Scala, and other >> > languages have a "private" keyword. >> >> I think a lof of this "discussion" is caused by different usages of >> private. My understanding is that you think private is missing in >> python because there is no clear different between a member which is >> published (part of the API) and one which is not (e.g. whose behavior >> may change between different revisions, even minor). I agree the >> underscore is not an ideal solution - it is certainly not followed by >> all python code out there (not even in python itself - see distutils >> for example). >> >> But I think you are overstating the advantage of private for that >> usage, at least for C++. In C++, if you have a public class in a >> header: >> >> class Foo { >> private: >> int f; >> >> }; >> >> It means f is private (cannot be accessed outside Foo instances), but >> it is declared in the public header. Actually, when people means this >> kind of 'data-hiding', C++ does not bring anything to C itself - after >> all, we have used FILE* for years and I have no idea about the FILE >> structure. > > Your lack of knowledge about it doesn't mean that it has somehow > magically "private" members. The only reason that most of us don't > know what a FILE is is that it's definition is implementation-defined > (i.e., every compiler may define it differently). > > That doesn't have anything to do with private members. For example, on > my system, defines FILE as: > > struct _iobuf { > char *_ptr; > int _cnt; > char *_base; > int _flag; > int _file; > int _charbuf; > int _bufsiz; > char *_tmpfname; > }; > typedef struct _iobuf FILE; Hm, I guess it depends on the implementation, but it is at least possible in C to completely hide the structure, by declaring only a pointer, and defining the structure outside any public header file. Then, you cannot accidentally access any member - it would result in a compiler error. This method is also used in C++, that's the pimpl pattern. It is used for various purposes (avoid long compilation times when changing some private implementation, actual data hiding), but the underlying idea is that you hide the implementation from the public headers. That's used for example by QT, and many other C++ libraries. This shows quite strongly the limitations of the whole private/public business in C++. > > Pretty much, unless maybe the code documents what you're not supposed > to access: But that's my point: that's just not true for many packages I have used - some packages do follow the _ convention, some don't. For example, to take an example I am somewhat familiar with: distutils does not follow this at all. There is no documentation, and it is almost impossible to know what's the API from implementation details, the interface is leaking everywhere. Now, distutils is an "old" package, but my experience at least showed me that this is relatively common. There are some relatively well known packages which use a different mechanism to clearly separate the intended API, without using the _ convention, or more exactly in supplement of it. David From cournape at gmail.com Tue Feb 3 13:12:55 2009 From: cournape at gmail.com (David Cournapeau) Date: Wed, 4 Feb 2009 03:12:55 +0900 Subject: x64 speed In-Reply-To: <49888085.3020709@chamonix.reportlab.co.uk> References: <49888085.3020709@chamonix.reportlab.co.uk> Message-ID: <5b8d13220902031012oeef1b9fga08573629a83e34b@mail.gmail.com> On Wed, Feb 4, 2009 at 2:36 AM, Robin Becker wrote: > Whilst doing some portability testing with reportlab I noticed a strange > speedup for our unittest suite with python2.5 > > host win32 xp3 unittest time=42.2 seconds > vmware RHEL x64 unittest time=30.9 seconds > > so it looks like the vmware emulated system is much faster. Is it the x64 > working faster at its design sizes or perhaps the compiler or could it be > the vmware system caching all writes etc etc? For the red hat x64 build the > only special configuration was to use ucs2 > > I know that the VT bit stuff has made virtualization much better, but this > seems a bit weird. It can be many things of course depending on your configuration and what you are doing in your unit tests, but I don't find it weird at all. I often see faster results when IO is involed in my Ubuntu in vmware fusion than on mac os X - again, can be that the vm is not loaded (less python packages, faster import times), Linux better IO handling (I don't know whether this is true or not, but I could at least imagine that linux FS generally being faster than windows or mac os X ones, this could influence IO) It can also be compilers differences, 32 vs 64 bits as you say, etc... If you want to be sure, you should try a window VM :) David From digitig at gmail.com Tue Feb 3 13:14:58 2009 From: digitig at gmail.com (Tim Rowe) Date: Tue, 3 Feb 2009 18:14:58 +0000 Subject: what IDE is the best to write python? In-Reply-To: <8e63a5ce0902021735x45bea672tc4a655023ba11d5a@mail.gmail.com> References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> <874ozd3cr3.fsf@benfinney.id.au> <20090202034654.GD30237@turki.gavron.org> <8e63a5ce0902021735x45bea672tc4a655023ba11d5a@mail.gmail.com> Message-ID: 2009/2/3 Jervis Whitley : > real programmers use ed. Ed? Eee, tha' were lucky. We had to make holes in Hollerith cards wi' our bare teeth... -- Tim Rowe From catherine.heathcote at gmail.com Tue Feb 3 13:19:57 2009 From: catherine.heathcote at gmail.com (Catherine Heathcote) Date: Tue, 03 Feb 2009 18:19:57 GMT Subject: what IDE is the best to write python? In-Reply-To: References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> <874ozd3cr3.fsf@benfinney.id.au> <20090202034654.GD30237@turki.gavron.org> <8e63a5ce0902021735x45bea672tc4a655023ba11d5a@mail.gmail.com> Message-ID: Tim Rowe wrote: > 2009/2/3 Jervis Whitley : > >> real programmers use ed. > > Ed? Eee, tha' were lucky. We had to make holes in Hollerith cards wi' > our bare teeth... > You had teeth!?! Oh and hi, I shall be a new face in the crowd ;) From rdmurray at bitdance.com Tue Feb 3 13:27:33 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Tue, 3 Feb 2009 18:27:33 +0000 (UTC) Subject: Python Global State References: <775033410902030758pa44e7ccl251fc82e6bb90229@mail.gmail.com> <49886C78.5020406@mrabarnett.plus.com> Message-ID: Quoth MRAB : > er wrote: > > Simple question, I think: Is there a way to make a completely global > > variable across a slew of modules? If not, what is the canonical > > way to keep a global state? The purpose of this is to try to prevent > > circular module imports, which just sort of seems nasty. Thank you! > > > Simple answer: no. I'm wondering a little about posting this, but...well, the answer actually isn't "no". It's just that it's not something you should _ever_ do. The trick is to assign the value to the __builtins__ module... --RDM PS: I know this because Zope used to do it. Fortunately they wised up and refactored that code to be more sane. From kmcbrearty at yahoo.com Tue Feb 3 13:30:45 2009 From: kmcbrearty at yahoo.com (KMCB) Date: Tue, 3 Feb 2009 10:30:45 -0800 (PST) Subject: JDBC in CPYTHON Message-ID: <3e9865ac-ce12-492f-83db-74bd78ed3ee2@i18g2000prf.googlegroups.com> I was wondering if anyone was aware of a JDBC DBAPI module for cpython. I have looked at PYJDBC and was interested in avoiding using that extra level of ICE. I was thinking maybe someone would have back ported zxJDBC from Jython. Or used that as a starting point, to create a module and had a C based wrapper for the driver. This type of activity was talked about back in 2004 on this forum, but I was wondering if anyone had newer information. Regards, kmcb From rdmurray at bitdance.com Tue Feb 3 13:38:41 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Tue, 3 Feb 2009 18:38:41 +0000 (UTC) Subject: what IDE is the best to write python? References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> Message-ID: Quoth aahz at pythoncraft.com (Aahz): > In article , > Thorsten Kampe wrote: > >* Aahz (2 Feb 2009 09:29:43 -0800) > >> In article , > >> Thorsten Kampe wrote: > >>>* Aahz (2 Feb 2009 06:30:00 -0800) > >>>> In article <874ozd3cr3.fsf at benfinney.id.au>, > >>>> Ben Finney wrote: > >>>>>aahz at pythoncraft.com (Aahz) writes: > >>>>>> > >>>>>> Just to register a contrary opinion: I *hate* syntax highlighting > >>>>> > >>>>>On what basis? > >>>> > >>>> It makes my eyes bleed > >>> > >>>Ever tried sunglasses? > >> > >> Polarized sunglasses don't work too well with LCD monitors > > > >Well, the answer to your issue with syntax highlighting is to use a > >/decent/ highlighting colour scheme. Don't use that all > >purple/red/green/yellow/blue one. That's for psychedelic trips. > > > >Use a decent colour scheme for adults and you will see that you will > >benefit from syntax highlighting. > > Then I have the problem of copying around the syntax highlighting > configuration to every computer I use. Well, _that's_ easy to fix. I have a little bash script called 'synchome' that uses rsync to update the home directory on any of the remote machines on which I work. I've had to install rsync on one or two of the boxes, but that's a useful thing to do anyway. (Granted, I still have a couple bugs to work out, where I haven't taken the time to conditionalize things properly for some of the more exotic machine configurations, but hey, if I spend more time on those machines I'll get around to it...) Now, if you are a Windows user, then I sympathise...a little :) --RDM From philip at semanchuk.com Tue Feb 3 13:44:07 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 3 Feb 2009 13:44:07 -0500 Subject: How to call python from a foreign language thread (C++) In-Reply-To: References: Message-ID: On Feb 3, 2009, at 12:51 PM, Victor Lin wrote: > > It seems that my program can't call to Python's function from thread > directly, because there is Global Interpreter Lock. The python's GIL > is so complex, I have no idea how it works. I'm sorry, what I can do > is to ask. My question is. What should I do before and after I call a > Python function from threads? Hi Victor, I asked a similar question yesterday and have gotten no response yet -- I hope you'll have better luck. I'm writing a C extension that wants to implement a callback in a new thread. Here's what I think I've learned from reading the threads API doc. Please note that this is a classic case of the blind leading the blind! I'm sure some (most? all?) of the ideas below are wrong, but I'm hoping that thinking through some of this "out loud" will help both of us. Or maybe some more knowledgeable person will take pity on/be appalled by my ignorance and come to our rescue. =) Python's infamous GIL doesn't exist when a program is single-threaded. Before a new thread is created, the main thread must call PyEval_InitThreads() to create the GIL. However, "It is not safe to call this function when it is unknown which thread (if any) currently has the global interpreter lock." Therefore my extension must do this: i_have_the_gil = 0; if (!PyEval_ThreadsInitialized()) { PyEval_InitThreads(); /* "...when this function initializes the lock, it also acquires it." */ i_have_the_gil = 1; } That ensures that the GIL is created. My extension will be calling from a newly-created C thread. The *Python* thread doesn't exist yet; so next I have to create it. Therefore -- if (!i_have_the_gil) PyEval_AcquireLock(); // Might not actually be the main thread but conceptually // it is OK to assume so here. main_thread = PyThreadState_Get(); callback_thread = PyThreadState_New(main_thread->interp); PyThreadState_Swap(callback_thread); gstate = PyGILState_Ensure(); call_callback_function(); // Now unwind the above PyGILState_Release(gstate); PyThreadState_Swap(main_thread); PyThreadState_Clear(callback_thread); PyThreadState_Delete(callback_thread); PyEval_ReleaseLock(); I haven't yet tested this! But hopefully it is the right idea and just needs a little fine tuning. I found this discussion useful: http://mail.python.org/pipermail/python-list/2006-November/413088.html It includes the quote, "The current thread state API doc, as you read it from top to bottom now, is in fact totally confusing for anyone who didn't develop Python himself" I like! =) Cheers Philip From geert.discussions at gmail.com Tue Feb 3 13:47:29 2009 From: geert.discussions at gmail.com (Geert Vancompernolle) Date: Tue, 03 Feb 2009 19:47:29 +0100 Subject: Path question Message-ID: <49889141.6000202@gmail.com> Hi, I have the following path construction: ./src/__init__.py /main.py /modules/__init__.py /application.py /ui/__init__.py /mainwindow/__init__.py /mainwindow.py Now I want to call the method 'MainWindow' in the module 'mainwindow', from the module 'application'. I'm having the following import statement in 'applications.py': from .. ui.mainwindow.mainwindow import MainWindow That doesn't work. I've also tried many other combinations like from ..ui.mainwindow... but none of them work. I always get the following error: "Attempted relative import beyond toplevel package" How can I import the method 'MainWindow' from 'mainwindow' into 'application', using the explicit relative import rules? Or is there a better way to do this? -- Best rgds, Geert ________________________________________________ *Use EcoCho : environmentally friendly search the internet!* From erobererunc at gmail.com Tue Feb 3 14:10:18 2009 From: erobererunc at gmail.com (er) Date: Tue, 3 Feb 2009 14:10:18 -0500 Subject: Python Global State In-Reply-To: References: <775033410902030758pa44e7ccl251fc82e6bb90229@mail.gmail.com> <49886C78.5020406@mrabarnett.plus.com> Message-ID: <775033410902031110m2437f858n4affa3a0a92dd90a@mail.gmail.com> That was my hack for one other app, but I did it because I'd only been studying Python for a month or two. Glad to see others did it once as well, but that we all wised up. =P It might be nice if Python could provide a global dictionary, perhaps _G{}, where you can throw things. This is actually the solution provided by the Lua scripting language. Thanks for the global_ module solution, I was just making sure that was the canonical way. On Tue, Feb 3, 2009 at 1:27 PM, wrote: > Quoth MRAB : > > er wrote: > > > Simple question, I think: Is there a way to make a completely global > > > variable across a slew of modules? If not, what is the canonical > > > way to keep a global state? The purpose of this is to try to prevent > > > circular module imports, which just sort of seems nasty. Thank you! > > > > > Simple answer: no. > > I'm wondering a little about posting this, but...well, the answer actually > isn't "no". It's just that it's not something you should _ever_ do. > The trick is to assign the value to the __builtins__ module... > > --RDM > > PS: I know this because Zope used to do it. Fortunately they wised > up and refactored that code to be more sane. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From thmpsn.m.k at gmail.com Tue Feb 3 14:10:19 2009 From: thmpsn.m.k at gmail.com (thmpsn.m.k at gmail.com) Date: Tue, 3 Feb 2009 11:10:19 -0800 (PST) Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <003d01c98527$d9ea4ec0$0d00a8c0@hendrik> <005201c98549$d3eb74a0$0d00a8c0@hendrik> <2ed10ddd-63ac-4507-b046-0404cc85c97a@s1g2000prg.googlegroups.com> <3acf1429-9aec-4e0d-b617-21cbcdf76087@w1g2000prk.googlegroups.com> <22440895-ed68-4643-b833-0befe83d571c@f40g2000pri.googlegroups.com> Message-ID: On Feb 3, 12:05?pm, David Cournapeau wrote: > On Wed, Feb 4, 2009 at 2:36 AM, ? wrote: > > On Feb 3, 1:14 am, David Cournapeau wrote: > >> On Tue, Feb 3, 2009 at 2:37 PM, Russ P. wrote: > >> > On Feb 2, 7:48 pm, "Rhodri James" wrote: > >> >> On Tue, 03 Feb 2009 02:16:01 -0000, Russ P. wrote: > >> >> > Here we go again. If you have access to the source code (as you nearly > >> >> > always do with Python code), then "breaking the language-enforced data > >> >> > hiding" is a trivial matter of deleting the word "private" (or > >> >> > equivalent). > > >> >> If it's that trivial to defeat something that its proponents appear to > >> >> want to be close to an iron-clad guarantee, what on earth is the point > >> >> of using "private" in the first place? > > >> >> -- > >> >> Rhodri James *-* Wildebeeste Herder to the Masses > > >> > If a library developer releases the source code of a library, any user > >> > can trivially "defeat" the access restrictions. But if a team of > >> > developers is checking in code for a project, the leader(s) of the > >> > project can insist that the access restrictions be respected to > >> > simplify the management of interfaces. The larger the team, the more > >> > useful that can be. That's why Java, C++, Ada, Scala, and other > >> > languages have a "private" keyword. > > >> I think a lof of this "discussion" is caused by different usages of > >> private. My understanding is that you think private is missing in > >> python because there is no clear different between a member which is > >> published (part of the API) and one which is not (e.g. whose behavior > >> may change between different revisions, even minor). I agree the > >> underscore is not an ideal solution - it is certainly not followed by > >> all python code out there (not even in python itself - see distutils > >> for example). > > >> But I think you are overstating the advantage of private for that > >> usage, at least for C++. In C++, if you have a public class in a > >> header: > > >> class Foo { > >> ? ? private: > >> ? ? ? ? int f; > > >> }; > > >> It means f is private (cannot be accessed outside Foo instances), but > >> it is declared in the public header. Actually, when people means this > >> kind of 'data-hiding', C++ does not bring anything to C itself - after > >> all, we have used FILE* for years and I have no idea about the FILE > >> structure. > > > Your lack of knowledge about it doesn't mean that it has somehow > > magically "private" members. The only reason that most of us don't > > know what a FILE is is that it's definition is implementation-defined > > (i.e., every compiler may define it differently). > > > That doesn't have anything to do with private members. For example, on > > my system, defines FILE as: > > > struct _iobuf { > > ? ? ? ?char *_ptr; > > ? ? ? ?int ? _cnt; > > ? ? ? ?char *_base; > > ? ? ? ?int ? _flag; > > ? ? ? ?int ? _file; > > ? ? ? ?int ? _charbuf; > > ? ? ? ?int ? _bufsiz; > > ? ? ? ?char *_tmpfname; > > ? ? ? ?}; > > typedef struct _iobuf FILE; > > Hm, I guess it depends on the implementation, but it is at least > possible in C to completely hide the structure, by declaring only a > pointer, and defining the structure outside any public header file. > Then, you cannot accidentally access any member - it would result in a > compiler error. I've done that to implement ADTs (abstract data types, also known as opaque types), but it's far from optimal, mainly because: - The compiler doesn't know the size of the class/struct (since it hasn't seen its definition), so you have to provide some sort of "constructor" function that's defined in the same file in which the class/struct is defined. This function will allocate memory for the object using malloc()/new and return a pointer to it. Of course, since memory allocated using malloc()/new has to be released using free()/ delete, you also have to provide a "destructor" function that does this, and the user *always* has to call both the constructor function and the destructor function *explicitly*, which is VERY cumbersome (as opposed to C++ constructors/destructors, which are called automatically at object creation/deletion, and which you don't always need to provide unless you have to do some initialization/cleanup). - Memory allocated with malloc()/new is allocated on the heap (as opposed to variables that you simply declare locally, which are allocated on the stack), and heap memory allocation is slower than stack memory allocation (not that you have to worry about this overhead except in really high-performance applications). In short, you pay too high a price for using an object whose size isn't known at compile time. > This method is also used in C++, that's the pimpl pattern. It is used > for various purposes (avoid long compilation times when changing some > private implementation, actual data hiding), but the underlying idea > is that you hide the implementation from the public headers. That's > used for example by QT, and many other C++ libraries. > > This shows quite strongly the limitations of the whole private/public > business in C++. What limitations? The only limitations I see are the ones associated with opaque types (what you mentioned above). From giles.thomas at resolversystems.com Tue Feb 3 14:12:45 2009 From: giles.thomas at resolversystems.com (Giles Thomas) Date: Tue, 3 Feb 2009 11:12:45 -0800 (PST) Subject: Resolver One 1.4 beta - with IronPython 2.0 and numpy Message-ID: Hi all, Version 1.4 of Resolver One, our Pythonic spreadsheet, uses the Ironclad project to provide (alpha-level) support for numpy in a IronPython application. You can put numpy matrices in spreadsheet cells and manipulate them like any other data - there's a 4-minute screencast here: We're releasing the beta tomorrow: this has a few performance problems but is otherwise functionally complete. If you're interested in trying it out, drop me a line. Best regards, Giles -- Giles Thomas MD & CTO, Resolver Systems Ltd. giles.thomas at resolversystems.com +44 (0) 20 7253 6372 Win up to $17,000 for a spreadsheet: 17a Clerkenwell Road, London EC1M 5RD, UK VAT No.: GB 893 5643 79 Registered in England and Wales as company number 5467329. Registered address: 843 Finchley Road, London NW11 8NA, UK From btaylordesign at gmail.com Tue Feb 3 14:16:25 2009 From: btaylordesign at gmail.com (Brandon Taylor) Date: Tue, 3 Feb 2009 11:16:25 -0800 (PST) Subject: Extracting file from zip archive in Python 2.6.1 References: <7676f73d-2ee9-4151-8a09-b11a3eea2045@p37g2000yqd.googlegroups.com> Message-ID: <4d2b4207-e14a-4b4d-b518-1b7eb6322ce5@n33g2000pri.googlegroups.com> On Feb 3, 9:45?am, "Gabriel Genellina" wrote: > En Tue, 03 Feb 2009 05:31:24 -0200, Brandon Taylor ? > escribi?: > > > I'm having an issue specifying the path for extracting files from > > a .zip archive. In my method, I have: > > > zip_file.extract(zip_name + '/' + thumbnail_image, thumbnail_path) > > > What is happening is that the extract method is creating a folder with > > the name of 'zip_name' and extracting the files to it. Example: > > extract will create all directories in member name. Use open instead: > > with zip_file.open(zip_name + '/' + thumbnail_image) as source: > ? ?with open(os.path.join(thumbnail_path, thumbnail_image), "wb") as target: > ? ? ?shutil.copyfileobj(source, target) > > (untested) > > -- > Gabriel Genellina Hi Gabriel, Thank you for the code sample. I figured I was going to have to use 'open', but I completely forgot about the 'with' statement. I was trying to figure out how to get access to the file object in the zip without having to loop over all of the items, and 'with' will allow me to do just that. I'll give it a shot when I get home this evening and post my results. Kind regards, Brandon From deets at nospam.web.de Tue Feb 3 14:22:25 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 03 Feb 2009 20:22:25 +0100 Subject: Path question In-Reply-To: References: Message-ID: <6urjrhFgvif8U1@mid.uni-berlin.de> Geert Vancompernolle schrieb: > Hi, > > I have the following path construction: > > ./src/__init__.py > /main.py > /modules/__init__.py > /application.py > /ui/__init__.py > /mainwindow/__init__.py > /mainwindow.py > > Now I want to call the method 'MainWindow' in the module 'mainwindow', > from the module 'application'. > > I'm having the following import statement in 'applications.py': > > from .. ui.mainwindow.mainwindow import MainWindow > > That doesn't work. I've also tried many other combinations like from > ..ui.mainwindow... but none of them work. > > I always get the following error: > > "Attempted relative import beyond toplevel package" > > How can I import the method 'MainWindow' from 'mainwindow' into > 'application', using the explicit relative import rules? > > Or is there a better way to do this? > Rename "src" to "myapp", and start main.py from above that. That should work. Diez From rdmurray at bitdance.com Tue Feb 3 14:25:16 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Tue, 3 Feb 2009 19:25:16 +0000 (UTC) Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <003d01c98527$d9ea4ec0$0d00a8c0@hendrik> <005201c98549$d3eb74a0$0d00a8c0@hendrik> <2ed10ddd-63ac-4507-b046-0404cc85c97a@s1g2000prg.googlegroups.com> <3acf1429-9aec-4e0d-b617-21cbcdf76087@w1g2000prk.googlegroups.com> <22440895-ed68-4643-b833-0befe83d571c@f40g2000pri.googlegroups.com> <5b8d13220902031005k538c1d12ufb8bede897f43a7c@mail.gmail.com> Message-ID: Quoth David Cournapeau : > On Wed, Feb 4, 2009 at 2:36 AM, wrote: > > > > Pretty much, unless maybe the code documents what you're not supposed > > to access: > > But that's my point: that's just not true for many packages I have > used - some packages do follow the _ convention, some don't. For > example, to take an example I am somewhat familiar with: distutils > does not follow this at all. There is no documentation, and it is > almost impossible to know what's the API from implementation details, > the interface is leaking everywhere. Now, distutils is an "old" > package, but my experience at least showed me that this is relatively > common. > > There are some relatively well known packages which use a different > mechanism to clearly separate the intended API, without using the _ > convention, or more exactly in supplement of it. This whole issue gets more complicated, I think, when you consider that what is "public" versus "private" in an API depends on the consumer. That is, you might have a group of modules that use a package-internal interface, while what the "outside world" is supposed to use is a more restricted API. The package-internal interface isn't _private_ in the sense of hiding things from anybody outside the class or its subclasses, but neither is it public. I won't be surprised to hear that languages with data hiding have some provision for this, but to my mind this is a "one, two, many" situation. That is, if you have one case, things are trivially simple. If you have two cases, you can differentiate them. But once you have three cases, you almost certainly have _more_ than three cases...in other words a problem in generalization. In my code I generally use _ for stuff that is class-private, and document the "outside" or "stable" API, and everything else is...whatever it needs to be. Perhaps the packages you are thinking of do something similar? --RDM From gandalf at shopzeus.com Tue Feb 3 14:32:51 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 03 Feb 2009 20:32:51 +0100 Subject: kinterbasdb + firebird 1.5 with python 2.6 ? Message-ID: <49889BE3.7030206@shopzeus.com> Does anyone know how to get firebird 1.5 driver (kinterbasdb) for FireBird 1.5? My problem: * python 2.6 already installed on a server * there is a firebird 1.5 database on the same server * I need to access it from python 2.6 Any thoughts? From steve at holdenweb.com Tue Feb 3 14:37:08 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 03 Feb 2009 14:37:08 -0500 Subject: what IDE is the best to write python? In-Reply-To: References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> <874ozd3cr3.fsf@benfinney.id.au> <20090202034654.GD30237@turki.gavron.org> <8e63a5ce0902021735x45bea672tc4a655023ba11d5a@mail.gmail.com> Message-ID: Tim Rowe wrote: > 2009/2/3 Jervis Whitley : > >> real programmers use ed. > > Ed? Eee, tha' were lucky. We had to make holes in Hollerith cards wi' > our bare teeth... > Cards? Teeth? You were lucky! We 'ad ter stare at t'paper tape until the intensity of our gaze burned holes in it. If yer got one wrong yer 'ad ter tear it up and start all over again. And yer tell these young folk and they just don't believe yer. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From martin at v.loewis.de Tue Feb 3 14:58:41 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 03 Feb 2009 20:58:41 +0100 Subject: x64 speed In-Reply-To: References: Message-ID: <4988a1f1$0$3390$9b622d9e@news.freenet.de> Robin Becker wrote: > Whilst doing some portability testing with reportlab I noticed a strange > speedup for our unittest suite with python2.5 > > host win32 xp3 unittest time=42.2 seconds > vmware RHEL x64 unittest time=30.9 seconds > > so it looks like the vmware emulated system is much faster. Is it the > x64 working faster at its design sizes or perhaps the compiler or could > it be the vmware system caching all writes etc etc? I follow David's guess that Linux does better IO than Windows (not knowing anything about the benchmark, of course) Regards, Martin From jcd at sdf.lonestar.org Tue Feb 3 15:01:17 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Tue, 03 Feb 2009 15:01:17 -0500 Subject: English-like Python In-Reply-To: <498863CF.7010402@strout.net> References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> <497899D0.5030706@strout.net> <1233672856.7189.7.camel@aalcdl07.lib.unc.edu> <498863CF.7010402@strout.net> Message-ID: <1233691277.9141.6.camel@aalcdl07.lib.unc.edu> On Tue, 2009-02-03 at 08:33 -0700, Joe Strout wrote: > J. Cliff Dyer wrote: > > > But what if your language allows functions to be used as first class > > objects? (Mine does :)) > > > > x = Beep > > > > Does that assign the name x to the Beep object or does it assign the > > result of a Beep call to x? > > It assigns the result. To assign the name to the Beep object requires a > bit of additional syntax; in RB, this would be > > x = AddressOf Beep > > > There's no virtue in making ridiculously simple things even simpler if > > it makes the interesting things impossible. > > Of course. The goal is (or should be) to make the common things > ridiculously simple, and make the uncommon things only somewhat less so. > Even in Python, it is far more common to invoke a function than to > need a reference to it. So invoking a function should be the thing that > requires no extra syntax (even including "()"). Getting a reference to > it, which is less common, should be the thing that requires more syntax. > Except that now you have introduced an inconsistency into python. What does the following mean? my_object = MyObject() x = my_object What if MyObject defines a method named __call__? Now some objects are passed around using x = my_object while others require x = AddressOf my_object and the only way to tell which is which is to check the object for the presence of a __call__ method. This seems like a serious inconsistency to me. > Cheers, > - Joe > Cliff From mccredie at gmail.com Tue Feb 3 15:03:17 2009 From: mccredie at gmail.com (Matimus) Date: Tue, 3 Feb 2009 12:03:17 -0800 (PST) Subject: Window (tkinter) with no decoration References: Message-ID: <28e2c428-8fe3-4162-b490-39c883f12683@l33g2000pri.googlegroups.com> On Feb 3, 8:58?am, Djames Suhanko wrote: > Hello, programmers! > ?I would like to do a menu bar like kicker or windows menu. is possible? > > -- > Djames Suhanko > LinuxUser 158.760 Maybe you are looking for this? import Tkinter rt = Tkinter.Tk() rt.overrideredirect(True) # do stuff Matt From robert.kern at gmail.com Tue Feb 3 15:18:37 2009 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 03 Feb 2009 14:18:37 -0600 Subject: what IDE is the best to write python? In-Reply-To: References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> <874ozd3cr3.fsf@benfinney.id.au> <20090202034654.GD30237@turki.gavron.org> <8e63a5ce0902021735x45bea672tc4a655023ba11d5a@mail.gmail.com> Message-ID: On 2009-02-03 12:19, Catherine Heathcote wrote: > Tim Rowe wrote: >> 2009/2/3 Jervis Whitley : >> >>> real programmers use ed. >> >> Ed? Eee, tha' were lucky. We had to make holes in Hollerith cards wi' >> our bare teeth... > > You had teeth!?! > > Oh and hi, I shall be a new face in the crowd ;) Welcome! -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From djames.suhanko at gmail.com Tue Feb 3 15:18:38 2009 From: djames.suhanko at gmail.com (Djames Suhanko) Date: Tue, 3 Feb 2009 18:18:38 -0200 Subject: Window (tkinter) with no decoration In-Reply-To: <28e2c428-8fe3-4162-b490-39c883f12683@l33g2000pri.googlegroups.com> References: <28e2c428-8fe3-4162-b490-39c883f12683@l33g2000pri.googlegroups.com> Message-ID: Exactly ! I thank you very much, Matimus !!! >> I would like to do a menu bar like kicker or windows menu. is possible? > Maybe you are looking for this? > rt = Tkinter.Tk() > rt.overrideredirect(True) -- Djames Suhanko LinuxUser 158.760 From deets at nospam.web.de Tue Feb 3 15:27:48 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 03 Feb 2009 21:27:48 +0100 Subject: x64 speed In-Reply-To: References: Message-ID: <6urnm4Fgv092U1@mid.uni-berlin.de> Robin Becker schrieb: > Whilst doing some portability testing with reportlab I noticed a strange > speedup for our unittest suite with python2.5 > > host win32 xp3 unittest time=42.2 seconds > vmware RHEL x64 unittest time=30.9 seconds > > so it looks like the vmware emulated system is much faster. Is it the > x64 working faster at its design sizes or perhaps the compiler or could > it be the vmware system caching all writes etc etc? For the red hat x64 > build the only special configuration was to use ucs2 > > I know that the VT bit stuff has made virtualization much better, but > this seems a bit weird. AFAIK some VMs have difficulties with timers. For example, my virtualized KDE has that jumping icon when starting a program - and that's *much* faster jumping inside VBox :) So - are you sure it *is* faster? Diez From gagsl-py2 at yahoo.com.ar Tue Feb 3 15:28:54 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 03 Feb 2009 18:28:54 -0200 Subject: Safe to get address of va_list function parameter? References: Message-ID: En Tue, 03 Feb 2009 15:31:21 -0200, Keith escribi?: > Is it safe to get the address of a va_list function parameter? Wrong group... -- Gabriel Genellina From istvan.albert at gmail.com Tue Feb 3 15:34:00 2009 From: istvan.albert at gmail.com (Istvan Albert) Date: Tue, 3 Feb 2009 12:34:00 -0800 (PST) Subject: what IDE is the best to write python? References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> <874ozd3cr3.fsf@benfinney.id.au> Message-ID: On Feb 2, 12:06?pm, Thorsten Kampe wrote: > > It makes my eyes bleed > > Ever tried sunglasses? Sunglasses for bleeding eyes? For pete's sake try bandages. From dunmer at dreams.sk Tue Feb 3 15:47:22 2009 From: dunmer at dreams.sk (Gabriel) Date: Tue, 03 Feb 2009 21:47:22 +0100 Subject: python libpcap equivalent Message-ID: <4988AD5A.1030706@dreams.sk> Hello I need to write a software router [yes, software equivalent to a hardware box that is routing packets .)]. It's a school work.. Question is: is possible write this kind of application in python? and if it's, what module should i use? I tried search for some libpcap equivalent in python and found pylibpcap, but can't find documentation and tutorial. From dunmer at dreams.sk Tue Feb 3 15:47:22 2009 From: dunmer at dreams.sk (Gabriel) Date: Tue, 03 Feb 2009 21:47:22 +0100 Subject: python libpcap equivalent Message-ID: <4988AD5A.1030706@dreams.sk> Hello I need to write a software router [yes, software equivalent to a hardware box that is routing packets .)]. It's a school work.. Question is: is possible write this kind of application in python? and if it's, what module should i use? I tried search for some libpcap equivalent in python and found pylibpcap, but can't find documentation and tutorial. From steve at holdenweb.com Tue Feb 3 15:53:00 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 03 Feb 2009 15:53:00 -0500 Subject: English-like Python In-Reply-To: <1233691277.9141.6.camel@aalcdl07.lib.unc.edu> References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> <497899D0.5030706@strout.net> <1233672856.7189.7.camel@aalcdl07.lib.unc.edu> <498863CF.7010402@strout.net> <1233691277.9141.6.camel@aalcdl07.lib.unc.edu> Message-ID: J. Cliff Dyer wrote: > On Tue, 2009-02-03 at 08:33 -0700, Joe Strout wrote: >> J. Cliff Dyer wrote: >> >>> But what if your language allows functions to be used as first class >>> objects? (Mine does :)) >>> >>> x = Beep >>> >>> Does that assign the name x to the Beep object or does it assign the >>> result of a Beep call to x? >> It assigns the result. To assign the name to the Beep object requires a >> bit of additional syntax; in RB, this would be >> >> x = AddressOf Beep >> >>> There's no virtue in making ridiculously simple things even simpler if >>> it makes the interesting things impossible. >> Of course. The goal is (or should be) to make the common things >> ridiculously simple, and make the uncommon things only somewhat less so. >> Even in Python, it is far more common to invoke a function than to >> need a reference to it. So invoking a function should be the thing that >> requires no extra syntax (even including "()"). Getting a reference to >> it, which is less common, should be the thing that requires more syntax. >> > > Except that now you have introduced an inconsistency into python. What > does the following mean? > > my_object = MyObject() > x = my_object > > What if MyObject defines a method named __call__? > > Now some objects are passed around using > > x = my_object > > while others require > > x = AddressOf my_object > > and the only way to tell which is which is to check the object for the > presence of a __call__ method. > > This seems like a serious inconsistency to me. > Time for my annual comment on the apparent requirement for DWIM-mode Python. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From gagsl-py2 at yahoo.com.ar Tue Feb 3 15:57:29 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 03 Feb 2009 18:57:29 -0200 Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <67d8a4d2-0b3d-4b41-84e2-698f17cb8e88@35g2000pry.googlegroups.com> <26a3c05c-253d-4134-bcb9-aed8505f250e@e1g2000pra.googlegroups.com> Message-ID: En Mon, 02 Feb 2009 19:51:11 -0200, Russ P. escribi?: > Suppose a library developer (or a module developer on a large team) > uses leading underscores. Now suppose that, for whatever reason > (pressure from the users, perhaps), the library developer decides to > change a "private" attribute to public. Now all occurrences of the > identifier need to be changed. If an assignment to the previously > "private" attribute is missed, no warning will be issued (because > Python allows new attributes to be added anywhere, even completely > outside the class definition itself). And if the library is widely > used, the probability of such bugs occurring is very high. So _foo becomes foo. Then: class X(object): def get_foo(self): return self._foo def set_foo(self, value): self._foo = value foo = property(get_foo, set_foo) You have the public name "foo", for new usage outside the library, and the private name "_foo", for internal use only. And we're all happy. If it weren't for your "historical" reasons, using those trivial get/set functions is rather silly. -- Gabriel Genellina From imageguy1206 at gmail.com Tue Feb 3 16:01:53 2009 From: imageguy1206 at gmail.com (imageguy) Date: Tue, 3 Feb 2009 13:01:53 -0800 (PST) Subject: kinterbasdb + firebird 1.5 with python 2.6 ? References: Message-ID: On Feb 3, 2:32?pm, Laszlo Nagy wrote: > Does anyone know how to get firebird 1.5 driver (kinterbasdb) for > FireBird 1.5? > > My problem: > > ? ? * python 2.6 already installed on a server > ? ? * there is a firebird 1.5 database on the same server > ? ? * I need to access it from python 2.6 > > Any thoughts? Have you asked on the Firebird list ? The original maintainer of kinterbasedb passed away and maintenance was taken over by the Firebird project. See this link. http://www.firebirdsql.org/index.php?op=devel&sub=python Sorry, but that is the best I can do. g. From http Tue Feb 3 16:05:01 2009 From: http (Paul Rubin) Date: 03 Feb 2009 13:05:01 -0800 Subject: x64 speed References: Message-ID: <7xy6wn1bb6.fsf@ruckus.brouhaha.com> Robin Becker writes: > so it looks like the vmware emulated system is much faster. Is it the > x64 working faster at its design sizes or perhaps the compiler or > could it be the vmware system caching all writes etc etc? For the red > hat x64 build the only special configuration was to use ucs2 You have to control all these variables separately in order to know. But, 64 bit code is in general faster than 32 bit code when properly compiled: more cpu registers, wider moves when copying large blocks of data, floating point registers instead of the legacy stack-oriented FPU, etc. From robin at NOSPAMreportlab.com Tue Feb 3 16:20:23 2009 From: robin at NOSPAMreportlab.com (Robin Becker) Date: Tue, 03 Feb 2009 21:20:23 +0000 Subject: x64 speed In-Reply-To: <6urnm4Fgv092U1@mid.uni-berlin.de> References: <6urnm4Fgv092U1@mid.uni-berlin.de> Message-ID: <4988B517.1090108@jessikat.plus.net> Diez B. Roggisch wrote: > Robin Becker schrieb: >> Whilst doing some portability testing with reportlab I noticed a >> strange speedup for our unittest suite with python2.5 >> >> host win32 xp3 unittest time=42.2 seconds >> vmware RHEL x64 unittest time=30.9 seconds >> >> so it looks like the vmware emulated system is much faster. Is it the >> x64 working faster at its design sizes or perhaps the compiler or >> could it be the vmware system caching all writes etc etc? For the red >> hat x64 build the only special configuration was to use ucs2 >> >> I know that the VT bit stuff has made virtualization much better, but >> this seems a bit weird. > > > AFAIK some VMs have difficulties with timers. For example, my > virtualized KDE has that jumping icon when starting a program - and > that's *much* faster jumping inside VBox :) > ...... > Diez I started both in terminals and the host never wins :) -- Robin Becker From robin at NOSPAMreportlab.com Tue Feb 3 16:21:47 2009 From: robin at NOSPAMreportlab.com (Robin Becker) Date: Tue, 03 Feb 2009 21:21:47 +0000 Subject: x64 speed In-Reply-To: <7xy6wn1bb6.fsf@ruckus.brouhaha.com> References: <7xy6wn1bb6.fsf@ruckus.brouhaha.com> Message-ID: <4988B56B.9040203@jessikat.plus.net> Paul Rubin wrote: > Robin Becker writes: >> so it looks like the vmware emulated system is much faster. Is it the >> x64 working faster at its design sizes or perhaps the compiler or >> could it be the vmware system caching all writes etc etc? For the red >> hat x64 build the only special configuration was to use ucs2 > > You have to control all these variables separately in order to know. > But, 64 bit code is in general faster than 32 bit code when properly > compiled: more cpu registers, wider moves when copying large blocks of > data, floating point registers instead of the legacy stack-oriented > FPU, etc. I tried looking at the cpu usage whilst running these and by eye it seemed that the host system was running more parallel stuff than the vmware vm. -- Robin Becker From robin at NOSPAMreportlab.com Tue Feb 3 16:22:13 2009 From: robin at NOSPAMreportlab.com (Robin Becker) Date: Tue, 03 Feb 2009 21:22:13 +0000 Subject: x64 speed In-Reply-To: References: Message-ID: <4988B585.5080909@jessikat.plus.net> Tim Daneliuk wrote: ...... > > Which vmware product? > vmware server -- Robin Becker From sevillad at gmail.com Tue Feb 3 16:24:17 2009 From: sevillad at gmail.com (David Sevilla) Date: Tue, 3 Feb 2009 13:24:17 -0800 (PST) Subject: Locating python Message-ID: Hi, Apologies if this was answered somewhere else, I have not found anything similar anywhere. I have SUSE 11.0 and I am trying to install a program called mnemosyne. I need easy_install for this, for which I installed setuptools through yast2. But when I run easy_install for the final installation, I get an error like this: [...] [Errno 2] No such file or directory: '/usr/local/lib/python2.5/site- packages/test-easy-install-3728.pth' The installation directory you specified (via --install-dir, --prefix, or the distutils default setting) was: /usr/local/lib/python2.5/site-packages/ This directory does not currently exist. [...] >From what I have gathered by reading here and there, it seems that the actual path for site-packages is not the place where it is being looked for. Sure enough, I have /usr/local/lib/python2.5/site- packages/ . What worries me is that there is no file called test* there, and I am not even able to find the site.py file mentioned in site-packages/README. I suspect that I have two concurrent installations or something like that (I do have python and python2.5 inside /usr/lib). How do I untangle this? Or at least how do I get easy_install to find the right place? Thanks a lot, David From robin at NOSPAMreportlab.com Tue Feb 3 16:24:37 2009 From: robin at NOSPAMreportlab.com (Robin Becker) Date: Tue, 03 Feb 2009 21:24:37 +0000 Subject: x64 speed In-Reply-To: <4988a1f1$0$3390$9b622d9e@news.freenet.de> References: <4988a1f1$0$3390$9b622d9e@news.freenet.de> Message-ID: <4988B615.4060206@jessikat.plus.net> Martin v. L?wis wrote: ..... > I follow David's guess that Linux does better IO than Windows (not > knowing anything about the benchmark, of course) > > Regards, > Martin I originally thought it must be the vmware host stuff offloading IO to the second core, but watching with sysinternals didn't show a lot of extra stuff going on with the vm compared to just running on the host. -- Robin Becker From gagsl-py2 at yahoo.com.ar Tue Feb 3 16:42:02 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 03 Feb 2009 19:42:02 -0200 Subject: Python Global State References: <775033410902030758pa44e7ccl251fc82e6bb90229@mail.gmail.com> <49886C78.5020406@mrabarnett.plus.com> <775033410902031110m2437f858n4affa3a0a92dd90a@mail.gmail.com> Message-ID: En Tue, 03 Feb 2009 17:10:18 -0200, er escribi?: > It might be nice if Python could provide a global dictionary, perhaps > _G{}, > where you can throw things. This is actually the solution provided by > the > Lua scripting language. Thanks for the global_ module solution, I was > just > making sure that was the canonical way. You *could* do that now, just inject a dictionary into the builtin module. sitecustomize.py would be the place to do that (it's executed before the main script). import __builtin__ __builtin__.globalvars = {} Then you can use globalvars[...] everywhere. But your code won't run in other locations, nor can you distribute it, you'll have to repeat the same steps when you upgrade your Python version, and people will wonder *where* such variable name comes from... Too much trouble, only to avoid typing a single line: from config import globalvars and it doesn't have any of the drawbacks listed above. I'd use import. -- Gabriel Genellina From martin at v.loewis.de Tue Feb 3 16:45:12 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 03 Feb 2009 22:45:12 +0100 Subject: x64 speed In-Reply-To: <4988B615.4060206@jessikat.plus.net> References: <4988a1f1$0$3390$9b622d9e@news.freenet.de> <4988B615.4060206@jessikat.plus.net> Message-ID: <4988BAE8.2060204@v.loewis.de> >> I follow David's guess that Linux does better IO than Windows (not >> knowing anything about the benchmark, of course) >> > I originally thought it must be the vmware host stuff offloading IO to > the second core, but watching with sysinternals didn't show a lot of > extra stuff going on with the vm compared to just running on the host. I'm not talking about vmware. I'm suggesting that Linux ext3, and the Linux buffer handling, is just more efficient than NTFS, and the Windows buffer handling. If you split the total runtime into system time and user time, how do the 30s split up? Regards, Martin From aahz at pythoncraft.com Tue Feb 3 16:53:39 2009 From: aahz at pythoncraft.com (Aahz) Date: 3 Feb 2009 13:53:39 -0800 Subject: what IDE is the best to write python? References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> <8e63a5ce0902021735x45bea672tc4a655023ba11d5a@mail.gmail.com> Message-ID: In article , Catherine Heathcote wrote: >Tim Rowe wrote: >> 2009/2/3 Jervis Whitley : >>> >>> real programmers use ed. >> >> Ed? Eee, tha' were lucky. We had to make holes in Hollerith cards wi' >> our bare teeth... > >You had teeth!?! > >Oh and hi, I shall be a new face in the crowd ;) Welcome! Looks like you'll fit right ni. (Yes, that's a typo but it's such a lovely one...) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From castironpi at gmail.com Tue Feb 3 16:59:53 2009 From: castironpi at gmail.com (Aaron Brady) Date: Tue, 3 Feb 2009 13:59:53 -0800 (PST) Subject: English-like Python References: <1232067775.15931.25.camel@localhost> <8436acc6-953f-4fa5-a894-123de4254a25@r15g2000prh.googlegroups.com> <497899D0.5030706@strout.net> <1233672856.7189.7.camel@aalcdl07.lib.unc.edu> <498863CF.7010402@strout.net> Message-ID: <356f70e4-abd6-4fdd-9c4c-c802fbb4f67b@r41g2000prr.googlegroups.com> On Feb 3, 2:01?pm, "J. Cliff Dyer" wrote: > On Tue, 2009-02-03 at 08:33 -0700, Joe Strout wrote: > > J. Cliff Dyer wrote: > > > > But what if your language allows functions to be used as first class > > > objects? ?(Mine does :)) ? > > > > x = Beep > > > > Does that assign the name x to the Beep object or does it assign the > > > result of a Beep call to x? > > > It assigns the result. ?To assign the name to the Beep object requires a > > bit of additional syntax; in RB, this would be > > > ? x = AddressOf Beep > > > > There's no virtue in making ridiculously simple things even simpler if > > > it makes the interesting things impossible. > > > Of course. ?The goal is (or should be) to make the common things > > ridiculously simple, and make the uncommon things only somewhat less so. > > ? Even in Python, it is far more common to invoke a function than to > > need a reference to it. ?So invoking a function should be the thing that > > requires no extra syntax (even including "()"). ?Getting a reference to > > it, which is less common, should be the thing that requires more syntax. > > Except that now you have introduced an inconsistency into python. ?What > does the following mean? > > my_object = MyObject() > x = my_object > > What if MyObject defines a method named __call__? > > Now some objects are passed around using > > x = my_object > > while others require > > x = AddressOf my_object > > and the only way to tell which is which is to check the object for the > presence of a __call__ method. ? > > This seems like a serious inconsistency to me. > > > Cheers, > > - Joe > > Cliff Well, just return to the natural language we're trying to model. x= going to the store x= go to the store Imperatives don't usually return values. x= the process of going to the store x= the result of going to the store I'm starting to think that PLs and NLs are quite dissimilar. What do return values are denoting phrases: x= the man in the corner x= the man in the corner talking to the woman Once you've established the subject, you usually make declarations about him/er/it. was_at_the_mall_today( x ) talked_to_me_earlier( x ) Usually you expect your audience to have reasoning capacities, and giving them declarative knowledge is preemptive to the need to give them orders later on. Ideally, interactions could take place entirely in the declarative: introduce yourself and wait-style. From piers at it.usyd.edu.au Tue Feb 3 17:07:06 2009 From: piers at it.usyd.edu.au (Piers Lauder) Date: Wed, 04 Feb 2009 09:07:06 +1100 Subject: imaplib thread method anomaly References: <113545.23852.qm@web54507.mail.re2.yahoo.com> Message-ID: <1233698829.49.72156511@it.usyd.edu.au> On Tue, 3 Feb 2009 05:22:01 -0800 (PST), Mr SZ wrote: > > I was looking at the thread functionality of IMAP4rev1 servers with the > threading extension. Here is my output with debug=8 : > > > > 02:23.02 > GDJB3 UID THREAD references UTF-8 (SEEN) > 02:23.02 < * THREAD (3)(2)(4)(1) > 02:23.02 matched r'\* (?P[A-Z-]+)( (?P.*))?' => ('THREAD', ' (3)(2)(4)(1)', '(3)(2)(4)(1)') > 02:23.03 untagged_responses[THREAD] 0 += ["(3)(2)(4)(1)"] > 02:23.03 < GDJB3 OK Thread completed. > 02:23.03 matched r'(?PGDJB\d+) (?P[A-Z]+) (?P.*)' => ('GDJB3', 'OK', 'Thread completed.') > [None] > > ... > > > 02:59.22 > CNCF3 THREAD references UTF-8 (SEEN) > 02:59.23 < * THREAD (3)(2)(4)(1) > 02:59.23 matched r'\* (?P[A-Z-]+)( (?P.*))?' => ('THREAD', ' (3)(2)(4)(1)', '(3)(2)(4)(1)') > 02:59.23 untagged_responses[THREAD] 0 += ["(3)(2)(4)(1)"] > 02:59.23 < CNCF3 OK Thread completed. > 02:59.23 matched r'(?PCNCF\d+) (?P[A-Z]+) (?P.*)' => ('CNCF3', 'OK', 'Thread completed.') > 02:59.23 untagged_responses[THREAD] => ['(3)(2)(4)(1)'] > ['(3)(2)(4)(1)'] > > > As you can see, the first is a UID command and the second is calling the > thread method. Also, the server responses are the same for both. So why is > one returning None and the other returning the correct response? I'm using > python2.4 and I'm stuck with it as I'm using it in a zope environment. In one of life's weird coincidences - someone else just created bugs.python.org issue5146 on this. The fix is a change in the method 'uid' to read: ... if command in ('SEARCH', 'SORT', 'THREAD'): name = command else: name = 'FETCH' ... (Thanks to ) Piers Lauder From lists at cheimes.de Tue Feb 3 17:19:26 2009 From: lists at cheimes.de (Christian Heimes) Date: Tue, 03 Feb 2009 23:19:26 +0100 Subject: kinterbasdb + firebird 1.5 with python 2.6 ? In-Reply-To: <49889BE3.7030206@shopzeus.com> References: <49889BE3.7030206@shopzeus.com> Message-ID: Laszlo Nagy schrieb: > Does anyone know how to get firebird 1.5 driver (kinterbasdb) for > FireBird 1.5? > > My problem: > > * python 2.6 already installed on a server > * there is a firebird 1.5 database on the same server > * I need to access it from python 2.6 > > Any thoughts? kinterbasdb 3.2.2 and 3.3.0 are working perfectly fine with Python 2.6. You can install it in less than 2 minutes with the usual tar -xzf && python2.6 setup.py install dance. I don't know if the latest versions of kinterbasdb still support 1.5. Christian From simon at brunningonline.net Tue Feb 3 17:20:44 2009 From: simon at brunningonline.net (Simon Brunning) Date: Tue, 3 Feb 2009 22:20:44 +0000 Subject: JDBC in CPYTHON In-Reply-To: <3e9865ac-ce12-492f-83db-74bd78ed3ee2@i18g2000prf.googlegroups.com> References: <3e9865ac-ce12-492f-83db-74bd78ed3ee2@i18g2000prf.googlegroups.com> Message-ID: <8c7f10c60902031420y1cc5647flcbde2aedd9e66c92@mail.gmail.com> 2009/2/3 KMCB : > I was wondering if anyone was aware of a JDBC DBAPI module for > cpython. I have looked at PYJDBC and was interested in avoiding using > that extra level of ICE. I was thinking maybe someone would have back > ported zxJDBC from Jython. Or used that as a starting point, to > create a module and had a C based wrapper for the driver. This type > of activity was talked about back in 2004 on this forum, but I was > wondering if anyone had newer information. I don't know if or might be of help. -- Cheers, Simon B. From kyosohma at gmail.com Tue Feb 3 17:24:48 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Tue, 3 Feb 2009 14:24:48 -0800 (PST) Subject: Locating python References: Message-ID: On Feb 3, 3:24?pm, David Sevilla wrote: > Hi, > > Apologies if this was answered somewhere else, I have not found > anything similar anywhere. > > I have SUSE 11.0 and I am trying to install a program called > mnemosyne. I need easy_install for this, for which I installed > setuptools through yast2. But when I run easy_install for the final > installation, I get an error like this: > > [...] > [Errno 2] No such file or directory: '/usr/local/lib/python2.5/site- > packages/test-easy-install-3728.pth' > > The installation directory you specified (via --install-dir, --prefix, > or the distutils default setting) was: > > ? ? /usr/local/lib/python2.5/site-packages/ > > This directory does not currently exist. [...] > > From what I have gathered by reading here and there, it seems that the > actual path for site-packages is not the place where it is being > looked for. Sure enough, I have /usr/local/lib/python2.5/site- > packages/ . What worries me is that there is no file called test* > there, and I am not even able to find the site.py file mentioned in > site-packages/README. I suspect that I have two concurrent > installations or something like that (I do have python and python2.5 > inside /usr/lib). How do I untangle this? Or at least how do I get > easy_install to find the right place? > > Thanks a lot, > > David I would get setuptools from the official source: http://peak.telecommunity.com/DevCenter/setuptools http://pypi.python.org/pypi/setuptools Install it using the python of your choice. You may have to pass a full path to the python "binary" to make sure you're using the right one. So, after downloading and decompressing the setuptools package, change directory into it. Then run something like this: /path/to/python setup.py install I think that will work...of course, your mileage may vary. I haven't used SUSE. Doesn't SUSE have a package manager like Ubuntu's apt-get? You might be able to just use that too.. Mike From steve at holdenweb.com Tue Feb 3 17:27:47 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 03 Feb 2009 17:27:47 -0500 Subject: Reading text file with wierd file extension? In-Reply-To: <3577795b-f031-400e-bb82-693ef2b3e639@q30g2000prq.googlegroups.com> References: <887b7e96-b0cc-4dea-8c1a-76c60ebffad3@t26g2000prh.googlegroups.com> <1e517f65-816e-4317-bb8c-0d9ee06041dd@r15g2000prd.googlegroups.com> <6up5kbFglf13U1@mid.uni-berlin.de> <3577795b-f031-400e-bb82-693ef2b3e639@q30g2000prq.googlegroups.com> Message-ID: John Machin wrote: > On Feb 3, 8:07 am, "Diez B. Roggisch" wrote: > >> This is written very slowly, so you can read it better: >> >> Please post the traceback. > > *AND* please post the text of the IOError message > > *AND* please do yourself a favour and move your files out of the root > directory into a directory with a meaningful name *AND* please don't take offense, as all this gratuitous advice is meant to allow us to better help you! regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From andrew at acooke.org Tue Feb 3 17:30:26 2009 From: andrew at acooke.org (andrew cooke) Date: Tue, 3 Feb 2009 14:30:26 -0800 (PST) Subject: Locating python References: Message-ID: <3eb685e5-dc80-41d0-acc2-2cafe0cb65c5@e18g2000yqo.googlegroups.com> the exact details of what you are reporting seem a bit odd, but i have seen a similar error because i have tried to use my own account to install the package, instead of using root. what i believe happens is that easy_install first tries to create the "test" file, and then checks it is there. if it is not there, you get an error. normally the error explains that you need to run as root, but i assume in your case it doesn't - that seems odd, but it seemed worth mentioning anyway. so if you have not done so, instead of python setup.py install do sudo python setup.py install more generally, i have used opensuse 11.0 and 11.1, and generally things work just fine, so i would check you are following all the instructions correctly. good luck, andrew On Feb 3, 6:24?pm, David Sevilla wrote: > [...] > [Errno 2] No such file or directory: '/usr/local/lib/python2.5/site- > packages/test-easy-install-3728.pth' > > The installation directory you specified (via --install-dir, --prefix, > or the distutils default setting) was: > > ? ? /usr/local/lib/python2.5/site-packages/ > > This directory does not currently exist. [...] > > From what I have gathered by reading here and there, it seems that the > actual path for site-packages is not the place where it is being > looked for. Sure enough, I have /usr/local/lib/python2.5/site- > packages/ . What worries me is that there is no file called test* From invalid at invalid Tue Feb 3 17:30:34 2009 From: invalid at invalid (Grant Edwards) Date: Tue, 03 Feb 2009 16:30:34 -0600 Subject: python libpcap equivalent References: Message-ID: On 2009-02-03, Gabriel wrote: > I need to write a software router [yes, software equivalent to > hardware box that is routing packets .)]. It's a school work.. > Question is: is possible write this kind of application in > python? Hmm. It's going to be rather difficult, but you might be able to. > and if it's, what module should i use? I tried search for some > libpcap equivalent in python and found pylibpcap, but can't > find documentation and tutorial. You can use pylibpcap to capture packets, and then use a raw socket to send them out again on whatever interface you want. You'll have to make sure that the host's OS's network stack isn't going to process the packets at all. I'm not sure how you go about that. The documentation for pylibpcap is built into the module. See doc.i in the tarball. -- Grant Edwards grante Yow! I'd like some JUNK at FOOD ... and then I want to visi.com be ALONE -- From sevillad at gmail.com Tue Feb 3 17:34:07 2009 From: sevillad at gmail.com (David Sevilla) Date: Tue, 3 Feb 2009 14:34:07 -0800 (PST) Subject: Locating python References: Message-ID: <3c83a573-3170-4cf1-9b2d-88e4b639f9a1@p2g2000prf.googlegroups.com> On Feb 3, 11:24?pm, Mike Driscoll wrote: > On Feb 3, 3:24?pm, David Sevilla wrote: > > > > > Hi, > > > Apologies if this was answered somewhere else, I have not found > > anything similar anywhere. > > > I have SUSE 11.0 and I am trying to install a program called > > mnemosyne. I need easy_install for this, for which I installed > > setuptools through yast2. But when I run easy_install for the final > > installation, I get an error like this: > > > [...] > > [Errno 2] No such file or directory: '/usr/local/lib/python2.5/site- > > packages/test-easy-install-3728.pth' > > > The installation directory you specified (via --install-dir, --prefix, > > or the distutils default setting) was: > > > ? ? /usr/local/lib/python2.5/site-packages/ > > > This directory does not currently exist. [...] > > > From what I have gathered by reading here and there, it seems that the > > actual path for site-packages is not the place where it is being > > looked for. Sure enough, I have /usr/local/lib/python2.5/site- > > packages/ . What worries me is that there is no file called test* > > there, and I am not even able to find the site.py file mentioned in > > site-packages/README. I suspect that I have two concurrent > > installations or something like that (I do have python and python2.5 > > inside /usr/lib). How do I untangle this? Or at least how do I get > > easy_install to find the right place? > > > Thanks a lot, > > > David > > I would get setuptools from the official source: > > http://peak.telecommunity.com/DevCenter/setuptoolshttp://pypi.python.org/pypi/setuptools > > Install it using the python of your choice. You may have to pass a > full path to the python "binary" to make sure you're using the right > one. So, after downloading and decompressing the setuptools package, > change directory into it. Then run something like this: > > /path/to/python setup.py install > > I think that will work...of course, your mileage may vary. I haven't > used SUSE. Doesn't SUSE have a package manager like Ubuntu's apt-get? > You might be able to just use that too.. > > Mike Actually, a manual installation is probably the best thing to do, since I did use the SUSE package manager (yast2) to install setuptools and never had a chance to choose installation paths. Thanks, David From sevillad at gmail.com Tue Feb 3 17:35:31 2009 From: sevillad at gmail.com (David Sevilla) Date: Tue, 3 Feb 2009 14:35:31 -0800 (PST) Subject: Locating python References: <3eb685e5-dc80-41d0-acc2-2cafe0cb65c5@e18g2000yqo.googlegroups.com> Message-ID: <6827582d-26ce-4245-88dd-d24955dc9f3a@x16g2000prn.googlegroups.com> On Feb 3, 11:30?pm, andrew cooke wrote: > the exact details of what you are reporting seem a bit odd, but i have > seen a similar error because i have tried to use my own account to > install the package, instead of using root. > > what i believe happens is that easy_install first tries to create the > "test" file, and then checks it is there. ?if it is not there, you get > an error. ?normally the error explains that you need to run as root, > but i assume in your case it doesn't - that seems odd, but it seemed > worth mentioning anyway. > > so if you have not done so, instead of > > ? python setup.py install > > do > > ? sudo python setup.py install > > more generally, i have used opensuse 11.0 and 11.1, and generally > things work just fine, so i would check you are following all the > instructions correctly. > > good luck, > andrew > > On Feb 3, 6:24?pm, David Sevilla wrote: > > > [...] > > [Errno 2] No such file or directory: '/usr/local/lib/python2.5/site- > > packages/test-easy-install-3728.pth' > > > The installation directory you specified (via --install-dir, --prefix, > > or the distutils default setting) was: > > > ? ? /usr/local/lib/python2.5/site-packages/ > > > This directory does not currently exist. [...] > > > From what I have gathered by reading here and there, it seems that the > > actual path for site-packages is not the place where it is being > > looked for. Sure enough, I have /usr/local/lib/python2.5/site- > > packages/ . What worries me is that there is no file called test* > > I am quite new to Linux, and thought that by using yast2 there would be no user problems (I am asked for the root password). I will sudo it to see if it solves the problem. Thanks, David From andrew at acooke.org Tue Feb 3 17:36:36 2009 From: andrew at acooke.org (andrew cooke) Date: Tue, 3 Feb 2009 14:36:36 -0800 (PST) Subject: Locating python References: <3eb685e5-dc80-41d0-acc2-2cafe0cb65c5@e18g2000yqo.googlegroups.com> Message-ID: sorry, you are using easy_install, so sudo easy_install .... instead of what i said a moment ago. the important thing is to use "sudo". andrew On Feb 3, 7:30?pm, andrew cooke wrote: > the exact details of what you are reporting seem a bit odd, but i have > seen a similar error because i have tried to use my own account to > install the package, instead of using root. > > what i believe happens is that easy_install first tries to create the > "test" file, and then checks it is there. ?if it is not there, you get > an error. ?normally the error explains that you need to run as root, > but i assume in your case it doesn't - that seems odd, but it seemed > worth mentioning anyway. > > so if you have not done so, instead of > > ? python setup.py install > > do > > ? sudo python setup.py install > > more generally, i have used opensuse 11.0 and 11.1, and generally > things work just fine, so i would check you are following all the > instructions correctly. > > good luck, > andrew > > On Feb 3, 6:24?pm, David Sevilla wrote: > > > [...] > > [Errno 2] No such file or directory: '/usr/local/lib/python2.5/site- > > packages/test-easy-install-3728.pth' > > > The installation directory you specified (via --install-dir, --prefix, > > or the distutils default setting) was: > > > ? ? /usr/local/lib/python2.5/site-packages/ > > > This directory does not currently exist. [...] > > > From what I have gathered by reading here and there, it seems that the > > actual path for site-packages is not the place where it is being > > looked for. Sure enough, I have /usr/local/lib/python2.5/site- > > packages/ . What worries me is that there is no file called test* > > From steve at holdenweb.com Tue Feb 3 17:38:02 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 03 Feb 2009 17:38:02 -0500 Subject: python libpcap equivalent In-Reply-To: References: Message-ID: Unknown wrote: > On 2009-02-03, Gabriel wrote: > >> I need to write a software router [yes, software equivalent to >> hardware box that is routing packets .)]. It's a school work.. > >> Question is: is possible write this kind of application in >> python? > > Hmm. It's going to be rather difficult, but you might be able > to. > >> and if it's, what module should i use? I tried search for some >> libpcap equivalent in python and found pylibpcap, but can't >> find documentation and tutorial. > > You can use pylibpcap to capture packets, and then use a raw > socket to send them out again on whatever interface you want. > You'll have to make sure that the host's OS's network stack > isn't going to process the packets at all. I'm not sure how > you go about that. > > The documentation for pylibpcap is built into the module. See > doc.i in the tarball. > > And note that this won't work on Vista, where the raw socket interface is no longer available to standard applications. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Tue Feb 3 17:41:01 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 03 Feb 2009 17:41:01 -0500 Subject: Locating python In-Reply-To: References: Message-ID: Mike Driscoll wrote: > On Feb 3, 3:24 pm, David Sevilla wrote: >> Hi, >> >> Apologies if this was answered somewhere else, I have not found >> anything similar anywhere. >> >> I have SUSE 11.0 and I am trying to install a program called >> mnemosyne. I need easy_install for this, for which I installed >> setuptools through yast2. But when I run easy_install for the final >> installation, I get an error like this: >> >> [...] >> [Errno 2] No such file or directory: '/usr/local/lib/python2.5/site- >> packages/test-easy-install-3728.pth' >> >> The installation directory you specified (via --install-dir, --prefix, >> or the distutils default setting) was: >> >> /usr/local/lib/python2.5/site-packages/ >> >> This directory does not currently exist. [...] >> >> From what I have gathered by reading here and there, it seems that the >> actual path for site-packages is not the place where it is being >> looked for. Sure enough, I have /usr/local/lib/python2.5/site- >> packages/ . What worries me is that there is no file called test* >> there, and I am not even able to find the site.py file mentioned in >> site-packages/README. I suspect that I have two concurrent >> installations or something like that (I do have python and python2.5 >> inside /usr/lib). How do I untangle this? Or at least how do I get >> easy_install to find the right place? >> >> Thanks a lot, >> >> David > > I would get setuptools from the official source: > > http://peak.telecommunity.com/DevCenter/setuptools > http://pypi.python.org/pypi/setuptools > > Install it using the python of your choice. You may have to pass a > full path to the python "binary" to make sure you're using the right > one. So, after downloading and decompressing the setuptools package, > change directory into it. Then run something like this: > > /path/to/python setup.py install > > I think that will work...of course, your mileage may vary. I haven't > used SUSE. Doesn't SUSE have a package manager like Ubuntu's apt-get? > You might be able to just use that too.. Easier still: wget http://peak.telecommunity.com/dist/ez_setup.py /path/to/python ez_setup.py rm ez_setup.py regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From lists at cheimes.de Tue Feb 3 17:42:02 2009 From: lists at cheimes.de (Christian Heimes) Date: Tue, 03 Feb 2009 23:42:02 +0100 Subject: Cross platform compilation? In-Reply-To: References: Message-ID: John Harper schrieb: > I am trying to build Python to use in an embedded system which uses a > ppc_440 CPU. The only information I've found is something written by > Klaus Reimer a few years ago, which was based on Python 2.2. So far I > seem to have successfully built Python itself, but building the > extensions fails miserably with complaints about library format. It > insists on referring to "i686" which is indeed the platform it is > actually running on. > > Before I try to reverse engineer completely setup.py, is there > something obvious that needs to be done to get it to use the right tool > chain? > > More generally, it seems like this would be something that lots of > people would want to do. I'm surprised there isn't support for it built > into the distributed version of Python, without having to hack all the > setup files...? I'm sorry to inform you that Python doesn't support cross platform compilation. Python eats its own dog food and uses Python to compile optional extension modules. Some guys were working on a patch. You may find something in the bug tracker at http://bugs.python.org Christian From spammers at rot.in.hell Tue Feb 3 17:46:21 2009 From: spammers at rot.in.hell (Eddie Watson) Date: Tue, 3 Feb 2009 22:46:21 +0000 (UTC) Subject: function call overhead Message-ID: What's the Python function call overhead like? Eddie Watson "CLC plonkers in a state of panic!!!" From andrew at acooke.org Tue Feb 3 17:47:40 2009 From: andrew at acooke.org (andrew cooke) Date: Tue, 3 Feb 2009 14:47:40 -0800 (PST) Subject: parse date/time from a log entry with only strftime (and no regexen) References: <23d7e1bb0902030552j6a12dcbcy428c9ede8419fb7b@mail.gmail.com> Message-ID: <7e3602b0-57c0-4d9e-8c8d-fb0a5b00108d@d36g2000prf.googlegroups.com> > > ValueError: unconverted data remains: ?this is the remainder of the log ? > > line > > that I do not care about you could catch the ValueError and split at the ':' in the .args attribute to find the extra data. you could then find the extra data in the original string, use the index to remove it, and re-parse the time. ugly, but should work. andrew From lists at cheimes.de Tue Feb 3 17:54:32 2009 From: lists at cheimes.de (Christian Heimes) Date: Tue, 03 Feb 2009 23:54:32 +0100 Subject: function call overhead In-Reply-To: References: Message-ID: Eddie Watson schrieb: > What's the Python function call overhead like? Like 6, maybe 7 *scnr* From dunmer at dreams.sk Tue Feb 3 17:55:04 2009 From: dunmer at dreams.sk (Gabriel) Date: Tue, 03 Feb 2009 23:55:04 +0100 Subject: python libpcap equivalent In-Reply-To: References: Message-ID: <4988CB48.9000304@dreams.sk> Steve Holden wrote: > Unknown wrote: >> On 2009-02-03, Gabriel wrote: >> >>> I need to write a software router [yes, software equivalent to >>> hardware box that is routing packets .)]. It's a school work.. >>> Question is: is possible write this kind of application in >>> python? >> Hmm. It's going to be rather difficult, but you might be able >> to. >> >>> and if it's, what module should i use? I tried search for some >>> libpcap equivalent in python and found pylibpcap, but can't >>> find documentation and tutorial. >> You can use pylibpcap to capture packets, and then use a raw >> socket to send them out again on whatever interface you want. >> You'll have to make sure that the host's OS's network stack >> isn't going to process the packets at all. I'm not sure how >> you go about that. >> >> The documentation for pylibpcap is built into the module. See >> doc.i in the tarball. >> >> > And note that this won't work on Vista, where the raw socket interface > is no longer available to standard applications. > > regards > Steve > Thanks guys I don't care about Vista. What i will (i hope only) need is a linux system with two net devices running router, XP hosts connected (not only two.. hubs, switches) and these hosts have to ping via router. From dunmer at dreams.sk Tue Feb 3 17:57:02 2009 From: dunmer at dreams.sk (Gabriel) Date: Tue, 03 Feb 2009 23:57:02 +0100 Subject: python libpcap equivalent In-Reply-To: References: Message-ID: <4988CBBE.7000408@dreams.sk> Steve Holden wrote: > Unknown wrote: >> On 2009-02-03, Gabriel wrote: >> >>> I need to write a software router [yes, software equivalent to >>> hardware box that is routing packets .)]. It's a school work.. >>> Question is: is possible write this kind of application in >>> python? >> Hmm. It's going to be rather difficult, but you might be able >> to. >> >>> and if it's, what module should i use? I tried search for some >>> libpcap equivalent in python and found pylibpcap, but can't >>> find documentation and tutorial. >> You can use pylibpcap to capture packets, and then use a raw >> socket to send them out again on whatever interface you want. >> You'll have to make sure that the host's OS's network stack >> isn't going to process the packets at all. I'm not sure how >> you go about that. >> >> The documentation for pylibpcap is built into the module. See >> doc.i in the tarball. >> >> > And note that this won't work on Vista, where the raw socket interface > is no longer available to standard applications. > > regards > Steve > Thanks guys I don't care about Vista. What i will (i hope only) need is a linux system with two net devices running router, XP hosts connected (not only two.. hubs, switches) and these hosts have to ping via router. From Scott.Daniels at Acm.Org Tue Feb 3 18:42:21 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 03 Feb 2009 15:42:21 -0800 Subject: Path question In-Reply-To: References: Message-ID: <37WdnbcVOrtzSBXUnZ2dnUVZ_vninZ2d@pdx.net> Geert Vancompernolle wrote: > I have the following path construction: ... > ./src/__init__.py > /main.py > /modules/__init__.py > /application.py > /ui/__init__.py > /mainwindow/__init__.py > /mainwindow.py > I want to call ... 'MainWindow' in module 'mainwindow', from 'application'. > I'm having the following import statement in 'applications.py': > from .. ui.mainwindow.mainwindow import MainWindow If you run the application with the command: python -m src.modules.application ... rather than python src/modules/application.py ... your import should work. You need to make the package layering to application explicit. Similarly, you can start Idle with: python -m idlelib.idle ... --Scott David Daniels Scott.Daniels at Acm.Org From rhodri at wildebst.demon.co.uk Tue Feb 3 19:05:24 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 04 Feb 2009 00:05:24 -0000 Subject: is python Object oriented?? In-Reply-To: References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com> <003d01c98527$d9ea4ec0$0d00a8c0@hendrik> <005201c98549$d3eb74a0$0d00a8c0@hendrik> <2ed10ddd-63ac-4507-b046-0404cc85c97a@s1g2000prg.googlegroups.com> Message-ID: On Tue, 03 Feb 2009 08:45:23 -0000, Steven D'Aprano wrote: > I find this extreme position is rather incoherent. If I may paraphrase > the argument as I see it: > "Enforced data hiding is useless, because it is utterly trivial to bypass > it, AND it's wicked, because it makes it unbelievably painful and > difficult to bypass it when you need to." > If it is trivial to bypass, surely it can't be that painful to bypass? I think you haven't noticed which of the parties is shifting their ground. I'm very much of the second opinion; it was Russ who did the sudden volte face and declared that it was trivial to circumvent. -- Rhodri James *-* Wildebeeste Herder to the Masses From rhodri at wildebst.demon.co.uk Tue Feb 3 19:14:23 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 04 Feb 2009 00:14:23 -0000 Subject: is python Object oriented?? In-Reply-To: <3acf1429-9aec-4e0d-b617-21cbcdf76087@w1g2000prk.googlegroups.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com> <003d01c98527$d9ea4ec0$0d00a8c0@hendrik> <005201c98549$d3eb74a0$0d00a8c0@hendrik> <2ed10ddd-63ac-4507-b046-0404cc85c97a@s1g2000prg.googlegroups.com> <3acf1429-9aec-4e0d-b617-21cbcdf76087@w1g2000prk.googlegroups.com> Message-ID: On Tue, 03 Feb 2009 05:37:57 -0000, Russ P. wrote: > On Feb 2, 7:48?pm, "Rhodri James" wrote: >> On Tue, 03 Feb 2009 02:16:01 -0000, Russ P. >> wrote: >> > Here we go again. If you have access to the source code (as you nearly >> > always do with Python code), then "breaking the language-enforced data >> > hiding" is a trivial matter of deleting the word "private" (or >> > equivalent). >> >> If it's that trivial to defeat something that its proponents appear to >> want to be close to an iron-clad guarantee, what on earth is the point >> of using "private" in the first place? > > If a library developer releases the source code of a library, any user > can trivially "defeat" the access restrictions. But if a team of > developers is checking in code for a project, the leader(s) of the > project can insist that the access restrictions be respected to > simplify the management of interfaces. The larger the team, the more > useful that can be. That's why Java, C++, Ada, Scala, and other > languages have a "private" keyword. Indeed he can. He can even do that in Python; it just requires a little self-discipline from the team, or a validation script on the code repository if he really doesn't trust them. Not only can this be done without forcing the rest of the world to play, it makes things a little less daunting when those nice clean interfaces turn out to be incomplete/too slow/not what you thought. -- Rhodri James *-* Wildebeeste Herder to the Masses From defaultuserbr at yahoo.com Tue Feb 3 19:23:00 2009 From: defaultuserbr at yahoo.com (Default User) Date: 4 Feb 2009 00:23:00 GMT Subject: function call overhead References: Message-ID: <6us5f4Fh659sU1@mid.individual.net> The original message in this thread was posted with the intent to disrupt comp.lang.c by setting follow-ups there. Please either ignore this thread or change the distribution. Thanks, and sorry our troll has caused problems in your group. Brian From steven at REMOVE.THIS.cybersource.com.au Tue Feb 3 19:51:46 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 04 Feb 2009 00:51:46 GMT Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <67d8a4d2-0b3d-4b41-84e2-698f17cb8e88@35g2000pry.googlegroups.com> <26a3c05c-253d-4134-bcb9-aed8505f250e@e1g2000pra.googlegroups.com> Message-ID: On Tue, 03 Feb 2009 10:20:28 +0100, Thorsten Kampe wrote: >> If a "private" keyword (or equivalent) were available, then the change >> would need to be made in only one location rather than at every >> occurrence off the identifier. That is much less error prone. Sure, you >> can argue (as I'm sure someone will) that the users of the library >> should be more careful. Yes they should, but why not let the language >> help with such low-level details. That's what high-level languages are >> for. > > This scenario is highly "supposing" and doesn't look like a real-world- > case to me. You think that private attributes never become public? Encoding a "private" flag in the name is a violation of Once And Only Once. Although the OAOO principle is generally referred to when discussing code, it is more generic and applies to other things as well. You should be able to state an attribute is private *once*, not every time you use it. http://c2.com/cgi/wiki?OnceAndOnlyOnce On the other hand, encoding that private flag in the name is a variation of *sensible* Hungarian Notation, as used by the Microsoft Apps team, not the stupid version used by the Windows team. http://www.joelonsoftware.com/articles/Wrong.html So that's a point in its favour. > But anyway: the obvious solution in my humble opinion would > be to do something like "public_attribute = _private_attribute". But > that would be too simple, too "unjavaesque", right?! No, it would be too *faulty*. It simply doesn't work. Consider: class Parrot(object): _count = 0 def foo(self): print 'foo' self._count += 1 def bar(self): print "You have called foo %d times" % self._count This works as expected: >>> p = Parrot() >>> p.foo() foo >>> p.foo() foo >>> p.bar() You have called foo 2 times Now you promote count from private to public, using your "obvious solution", and try to use it: class Parrot(object): _count = 0 count = _count def foo(self): print 'foo' self._count += 1 def bar(self): print "You have called foo %d times" % self._count >>> p = Parrot() >>> p.foo() foo >>> p.count = 99 >>> p.bar() You have called foo 1 times Clearly the "obvious" solution simply isn't sufficient to get the result that you need. One solution is to just refactor the source code, so that the attribute identifier "_count" becomes "count", but beware of all the usual issues with source code refactoring. Another solution is to leave _count as it is, and create a *property* called count, not a simple attribute: count = property( lambda self: self._count, lambda self, x: setattr(self, '_count', x), None, "Public interface to private attribute _count" ) but this adds complexity to the class and will be a maintenance headache as the class' methods diverge into those that manipulate self._count directly and other methods which manipulate self.count. -- Steven From demirbaris at gmail.com Tue Feb 3 19:57:37 2009 From: demirbaris at gmail.com (Baris Demir) Date: Wed, 04 Feb 2009 01:57:37 +0100 Subject: function scope In-Reply-To: <0vhfo4p2fsmogbjgs87jhfcbvl1ir7pi9n@4ax.com> References: <0vhfo4p2fsmogbjgs87jhfcbvl1ir7pi9n@4ax.com> Message-ID: <4988E801.7050705@gmail.com> Tim Roberts wrote: > Mike Kent wrote: > >> On Feb 2, 6:40 pm, Baris Demir wrote: >> >> >>> def simpleCut(d=dict()): >>> temp=d >>> for i in temp.keys(): >>> if (temp[i] == .......) : >>> temp[i]=new_value >>> return temp >>> >> You have been bitten by the shared default parameter noobie trap: >> http://www.python.org/doc/faq/general/#why-are-default-values-shared-between-objects >> > > Actually, he hasn't. His problem is more fundamental. > > However, this is still a good thing for you to point out now and then. > Thanks a lot for the replies guys. They all helped a lot. And, I guess, I should read a lot more about python, it is not as simple as it seems at the beginning, or for the beginners:) cheers BD From cournape at gmail.com Tue Feb 3 20:03:57 2009 From: cournape at gmail.com (David Cournapeau) Date: Wed, 4 Feb 2009 10:03:57 +0900 Subject: is python Object oriented?? In-Reply-To: References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <005201c98549$d3eb74a0$0d00a8c0@hendrik> <2ed10ddd-63ac-4507-b046-0404cc85c97a@s1g2000prg.googlegroups.com> <3acf1429-9aec-4e0d-b617-21cbcdf76087@w1g2000prk.googlegroups.com> <22440895-ed68-4643-b833-0befe83d571c@f40g2000pri.googlegroups.com> Message-ID: <5b8d13220902031703r15a32435j27f90fabde147e25@mail.gmail.com> On Wed, Feb 4, 2009 at 4:10 AM, wrote: > > What limitations? The only limitations I see are the ones associated > with opaque types (what you mentioned above). Opaque type are used in C++ as well, for data hiding - if private/public were that great for data hiding, the PIMPL idiom would not be used. That's the limitation I am talking about. Granted, it is relatively specific to C++, which use the C headers mechanism for API declaration. David From Russ.Paielli at gmail.com Tue Feb 3 20:13:32 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 3 Feb 2009 17:13:32 -0800 (PST) Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com> <003d01c98527$d9ea4ec0$0d00a8c0@hendrik> <005201c98549$d3eb74a0$0d00a8c0@hendrik> <2ed10ddd-63ac-4507-b046-0404cc85c97a@s1g2000prg.googlegroups.com> Message-ID: <4ec8770b-631f-492b-be7a-27bb8ac47afc@i20g2000prf.googlegroups.com> On Feb 3, 4:05 pm, "Rhodri James" wrote: > On Tue, 03 Feb 2009 08:45:23 -0000, Steven D'Aprano > > wrote: > > I find this extreme position is rather incoherent. If I may paraphrase > > the argument as I see it: > > "Enforced data hiding is useless, because it is utterly trivial to bypass > > it, AND it's wicked, because it makes it unbelievably painful and > > difficult to bypass it when you need to." > > If it is trivial to bypass, surely it can't be that painful to bypass? > > I think you haven't noticed which of the parties is shifting their ground. > I'm very much of the second opinion; it was Russ who did the sudden volte > face and declared that it was trivial to circumvent. Whoa! Hold on a minute here. Your failure to understand a simple idea does not constitute a "sudden volte" (whatever that is) on my part. Let me try to explain again what should be fairly obvious. If the user of the library has the source code (and the right to modify it), disabling access restrictions is trivial. You simply delete the "private" keyword (or equivalent) wherever necessary. If you are working with a team, however, you cannot just do that unilaterally unless you have the authority to do so. In other words, you may be required to conform to the APIs established by the team. In that case, disabling access restrictions may not be impossible (or even difficult), but it is no longer trivial. From rdmurray at bitdance.com Tue Feb 3 20:25:05 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Wed, 4 Feb 2009 01:25:05 +0000 (UTC) Subject: global variable confusion References: Message-ID: "Robert D.M. Smith" wrote: > I have a question on global variables and how to use them. I have 2 files; > a.py & b.py > > # a.py ----- > > myvar = { 'test' : '123' } > > # ------- > # b.py ----- > > from a import myvar > > def test(): > a.myvar = { 'blah' : '456' } > > # ----- > > If I *'import a*' & type *'a.myvar'* it prints 'test' & '123'. > > Now, if I *'import b'* & type *'b.test()'* ... does this actually change the > contents of myvar? It seems I have to do *'print b.myvar'* to see the change > but really I want to just simply do* 'print myvar'*. I want to be able to > change myvar anywhere. Please help me grasp this concept. As someone else told you the code above won't work, because you haven't imported the 'a' that your 'test' function references. But let's ignore that issue. I'm guessing the confusion you are experiencing is arising from the concept of name spaces (a very powerful and ubiquitous concept in Python). A namespace maps an identifier to a object. A given identifier exists in exactly one namespace, but many identifiers can refer to the same object. When you do 'from a import myvar', you are setting the identifier 'myvar' _in the current model's global namespace_ to point to the same object that 'myvar' does in module a. If, in the current module, you then do, say, 'myvar = 1', what you've done is _rebound_ the identifier 'myvar' in the current module's global namespace to the integer 1 (an integer object). You haven't affected anything in module 'a'. If, on the other hand, you do 'import a', what you've done is bound the global namespace of module 'a' (an object) to the identifier 'a' in the current module's global namespace. If you were to do 'a = 1' in the current module, then you'd rebind the identifier 'a' to the integer 1. After that a.myvar would be an error. If, however, you say 'a.myvar = 1', what you've done is rebound the identifier 'myvar' _in module a's global namespace_ to the integer 1. Anything that subsequently references a.myvar is going to get '1' as the result. Now, to take your brain around the final bend, think about what happens if one module does 'from a import myvar', and module imported later does 'import a; a.myvar = 1'. The first module bound its global identifier 'myvar' to the object a.myvar originally pointed to (a little dictionary in your example above). The second module rebinds the identifier myvar in module a's global namespace to the integer 1. But that doesn't affect the first module's global namespace. There, the identifier 'myvar' is still bound _to the original dictionary_. A modification of your example should make what is going on clearer: --------------------------- # a.py myvar = {'test': '123'} --------------------------- # b.py from a import myvar myvar['test'] = '456' --------------------------- Python 2.6.1 (r261:67515, Jan 7 2009, 17:09:13) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from a import myvar >>> print myvar {'test': '123'} >>> import b >>> print myvar {'test': '456'} The difference between the above and doing 'myvar = 1' is that in the above code the statement 'myvar['test'] = '456' modifies _the object that myvar points to_, while 'myvar = 1' modifies _what_ myvar points to. Study that last sentence until you understand it, and a lot of things that happen in Python will be much clearer to you (such as what happens when you pass arguments to a function or method!) If what I have written doesn't make sense, feel free to ask more questions. --RDM From Russ.Paielli at gmail.com Tue Feb 3 20:28:58 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 3 Feb 2009 17:28:58 -0800 (PST) Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com> <003d01c98527$d9ea4ec0$0d00a8c0@hendrik> <005201c98549$d3eb74a0$0d00a8c0@hendrik> <2ed10ddd-63ac-4507-b046-0404cc85c97a@s1g2000prg.googlegroups.com> <3acf1429-9aec-4e0d-b617-21cbcdf76087@w1g2000prk.googlegroups.com> Message-ID: On Feb 3, 4:14 pm, "Rhodri James" wrote: > On Tue, 03 Feb 2009 05:37:57 -0000, Russ P. wrote: > > On Feb 2, 7:48 pm, "Rhodri James" wrote: > >> On Tue, 03 Feb 2009 02:16:01 -0000, Russ P. > >> wrote: > >> > Here we go again. If you have access to the source code (as you nearly > >> > always do with Python code), then "breaking the language-enforced data > >> > hiding" is a trivial matter of deleting the word "private" (or > >> > equivalent). > > >> If it's that trivial to defeat something that its proponents appear to > >> want to be close to an iron-clad guarantee, what on earth is the point > >> of using "private" in the first place? > > > If a library developer releases the source code of a library, any user > > can trivially "defeat" the access restrictions. But if a team of > > developers is checking in code for a project, the leader(s) of the > > project can insist that the access restrictions be respected to > > simplify the management of interfaces. The larger the team, the more > > useful that can be. That's why Java, C++, Ada, Scala, and other > > languages have a "private" keyword. > > Indeed he can. He can even do that in Python; it just requires a little > self-discipline from the team, or a validation script on the code > repository if he really doesn't trust them. Not only can this be done > without forcing the rest of the world to play, it makes things a little > less daunting when those nice clean interfaces turn out to be > incomplete/too slow/not what you thought. This has already been refuted several times on this thread alone, so I will not bother doing it again. From davidgould at davidgould.com Tue Feb 3 20:46:57 2009 From: davidgould at davidgould.com (davidgould at davidgould.com) Date: Tue, 3 Feb 2009 17:46:57 -0800 (PST) Subject: Passing environment variable to "subprocess" causes failure Message-ID: <13842319-2d1a-4012-aa55-977b79574288@l33g2000pri.googlegroups.com> I'm attempting to run subprocess and passing in an environment variable. When I do this the child process fails with an error. When I don't pass an environement variable it runs fine. BTW Running this code under Windows XP with Python 2.6.1 Code A: p = subprocess.Popen( ['python', '-V'], env={ 'PYTHONPATH': 'C:/ Documents and Settings/David Gould/workspace/DgTools/Common/Trunk/ Source' } ) print p.communicate()[0] print p.returncode Output: None -1072365564 Code B: p = subprocess.Popen( ['python', '-V'] ) print p.communicate()[0] print p.returncode Output: Python 2.6.1 0 Any idea why passing an environment variable causes it to fail? Thanks. From johnforse at talktalk.net Tue Feb 3 20:58:43 2009 From: johnforse at talktalk.net (John Forse) Date: Wed, 4 Feb 2009 01:58:43 +0000 Subject: v 3.0 mpkg Message-ID: <2E75ECDE-6B15-471F-8747-ED4616EF4847@talktalk.net> Does anyone know if Python v3.0 is available as an .mpkg installer for Mac 10.5.6. I have used 2.5 & updated to 2.6.1 this way, but can't find any reference to one on the Python.org download site. I've downloaded the Python 3.0 folder but can't follow how to install it without a .mpkg file. Any help would be really appreciated. Regards John From btaylordesign at gmail.com Tue Feb 3 21:36:40 2009 From: btaylordesign at gmail.com (Brandon Taylor) Date: Tue, 3 Feb 2009 18:36:40 -0800 (PST) Subject: Extracting file from zip archive in Python 2.6.1 References: <7676f73d-2ee9-4151-8a09-b11a3eea2045@p37g2000yqd.googlegroups.com> <4d2b4207-e14a-4b4d-b518-1b7eb6322ce5@n33g2000pri.googlegroups.com> Message-ID: On Feb 3, 1:16?pm, Brandon Taylor wrote: > On Feb 3, 9:45?am, "Gabriel Genellina" wrote: > > > > > En Tue, 03 Feb 2009 05:31:24 -0200, Brandon Taylor ? > > escribi?: > > > > I'm having an issue specifying the path for extracting files from > > > a .zip archive. In my method, I have: > > > > zip_file.extract(zip_name + '/' + thumbnail_image, thumbnail_path) > > > > What is happening is that the extract method is creating a folder with > > > the name of 'zip_name' and extracting the files to it. Example: > > > extract will create all directories in member name. Use open instead: > > > with zip_file.open(zip_name + '/' + thumbnail_image) as source: > > ? ?with open(os.path.join(thumbnail_path, thumbnail_image), "wb") as target: > > ? ? ?shutil.copyfileobj(source, target) > > > (untested) > > > -- > > Gabriel Genellina > > Hi Gabriel, > > Thank you for the code sample. I figured I was going to have to use > 'open', but I completely forgot about the 'with' statement. I was > trying to figure out how to get access to the file object in the zip > without having to loop over all of the items, and 'with' will allow me > to do just that. > > I'll give it a shot when I get home this evening and post my results. > > Kind regards, > Brandon Ok, the first thing I needed to do was add: from __future__ import with_statement at the beginning of my file but: with zip_file.open(zip_name + '/' + thumbnail_image) as source: with open(os.path.join(thumbnail_path, thumbnail_image), 'wb') as target: shutil.copyfileobj(source, target) Returns an error on the first line: ZipExtFile instance has no attribute '__exit__' Googling this error message is turning up nothing, and there's no mention of the exception in the docs. Any thoughts? TIA, Brandon From google at mrabarnett.plus.com Tue Feb 3 21:44:27 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 04 Feb 2009 02:44:27 +0000 Subject: Passing environment variable to "subprocess" causes failure In-Reply-To: <13842319-2d1a-4012-aa55-977b79574288@l33g2000pri.googlegroups.com> References: <13842319-2d1a-4012-aa55-977b79574288@l33g2000pri.googlegroups.com> Message-ID: <4989010B.2050104@mrabarnett.plus.com> davidgould at davidgould.com wrote: > I'm attempting to run subprocess and passing in an environment > variable. When I do this the child process fails with an error. When I > don't pass an environement variable it runs fine. > > BTW Running this code under Windows XP with Python 2.6.1 > > Code A: > > p = subprocess.Popen( ['python', '-V'], env={ 'PYTHONPATH': 'C:/ > Documents and Settings/David Gould/workspace/DgTools/Common/Trunk/ > Source' } ) > print p.communicate()[0] > print p.returncode > > Output: > > None > -1072365564 > > Code B: > > p = subprocess.Popen( ['python', '-V'] ) > print p.communicate()[0] > print p.returncode > > Output: > > Python 2.6.1 > 0 > > Any idea why passing an environment variable causes it to fail? > Thanks. > Are you sure it's not the path within the dict you're passing that's wrong? From google at mrabarnett.plus.com Tue Feb 3 21:53:30 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 04 Feb 2009 02:53:30 +0000 Subject: Extracting file from zip archive in Python 2.6.1 In-Reply-To: References: <7676f73d-2ee9-4151-8a09-b11a3eea2045@p37g2000yqd.googlegroups.com> <4d2b4207-e14a-4b4d-b518-1b7eb6322ce5@n33g2000pri.googlegroups.com> Message-ID: <4989032A.1010200@mrabarnett.plus.com> Brandon Taylor wrote: > On Feb 3, 1:16 pm, Brandon Taylor wrote: >> On Feb 3, 9:45 am, "Gabriel Genellina" wrote: >> >> >> >>> En Tue, 03 Feb 2009 05:31:24 -0200, Brandon Taylor >>> escribi?: >>>> I'm having an issue specifying the path for extracting files from >>>> a .zip archive. In my method, I have: >>>> zip_file.extract(zip_name + '/' + thumbnail_image, thumbnail_path) >>>> What is happening is that the extract method is creating a folder with >>>> the name of 'zip_name' and extracting the files to it. Example: >>> extract will create all directories in member name. Use open instead: >>> with zip_file.open(zip_name + '/' + thumbnail_image) as source: >>> with open(os.path.join(thumbnail_path, thumbnail_image), "wb") as target: >>> shutil.copyfileobj(source, target) >>> (untested) >>> -- >>> Gabriel Genellina >> Hi Gabriel, >> >> Thank you for the code sample. I figured I was going to have to use >> 'open', but I completely forgot about the 'with' statement. I was >> trying to figure out how to get access to the file object in the zip >> without having to loop over all of the items, and 'with' will allow me >> to do just that. >> >> I'll give it a shot when I get home this evening and post my results. >> >> Kind regards, >> Brandon > > Ok, the first thing I needed to do was add: > > from __future__ import with_statement at the beginning of my file > > but: > > with zip_file.open(zip_name + '/' + thumbnail_image) as source: > with open(os.path.join(thumbnail_path, > thumbnail_image), 'wb') as target: > shutil.copyfileobj(source, target) > > Returns an error on the first line: > > ZipExtFile instance has no attribute '__exit__' > > Googling this error message is turning up nothing, and there's no > mention of the exception in the docs. Any thoughts? > The 'with' statement relies on the object having __enter__ and __exit__ methods. It looks like the object returned by zip_file.open() doesn't have them. From raykyoto at gmail.com Tue Feb 3 21:53:53 2009 From: raykyoto at gmail.com (Ray) Date: Tue, 3 Feb 2009 18:53:53 -0800 (PST) Subject: Import without executing module References: <7a9c25c20902012319i2d217644k12bc926400f630c2@mail.gmail.com> <14edd870-74d4-4d7a-a363-a4bc3515a071@s9g2000prg.googlegroups.com> <0ad1a5c0-0605-49fe-8a97-1159fc274d30@a39g2000prl.googlegroups.com> <45e5daf1-108c-499e-82a9-10e67eac33e2@z27g2000prd.googlegroups.com> Message-ID: <5a64441e-bee9-4466-b613-3e83fce2e8fb@r15g2000prd.googlegroups.com> Hi Lie, On Feb 3, 7:21?pm, Lie wrote: > On Feb 3, 1:37?pm, Ray wrote: > > > I'll enclose the top-level commands with the if statement above...its > > just a minor change, but it seems unavoidable. > > > Thanks again! > > > Ray > > If you really don't want the file to be changed, you could (depends on > the module) use the module as a subprocess. The ideal solution is for > the module to have an if __name__ == '__main__': to determine whether > it is being used as a module or a standalone program though. Thank you for this! I've done the "if __name__ ..." as you and others suggested. It isn't what I would have liked, but I'm ok with it...especially after finding out that top-level code has to be run while importing. As I'm new to python, I didn't know about that, but I now see there's no way around it. So, is inserting the above if statement common practice for python programmers? As a C programmer, it seems that people put a "#ifndef XXX...#define XXX...[all of the code]...#endif" almost as a habit. I wonder if its the same thing? Thank you! Ray From rdmurray at bitdance.com Tue Feb 3 22:08:31 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Wed, 4 Feb 2009 03:08:31 +0000 (UTC) Subject: Passing environment variable to "subprocess" causes failure References: <13842319-2d1a-4012-aa55-977b79574288@l33g2000pri.googlegroups.com> <4989010B.2050104@mrabarnett.plus.com> Message-ID: Quoth MRAB : > davidgould at davidgould.com wrote: > > I'm attempting to run subprocess and passing in an environment > > variable. When I do this the child process fails with an error. When I > > don't pass an environement variable it runs fine. > > > > BTW Running this code under Windows XP with Python 2.6.1 > > > > Code A: > > > > p = subprocess.Popen( ['python', '-V'], env={ 'PYTHONPATH': 'C:/ > > Documents and Settings/David Gould/workspace/DgTools/Common/Trunk/ > > Source' } ) > > print p.communicate()[0] > > print p.returncode > > > > Output: > > > > None > > -1072365564 > > > > Code B: > > > > p = subprocess.Popen( ['python', '-V'] ) > > print p.communicate()[0] > > print p.returncode > > > > Output: > > > > Python 2.6.1 > > 0 > > > > Any idea why passing an environment variable causes it to fail? > > Thanks. > > > Are you sure it's not the path within the dict you're passing that's wrong? Or there's something missing from the environment that python needs, causing a non-zero return code when it is missing. (That seems odd, though.) You ought to print communiicate()[1] to see if there is an accompanying error message that would shed light on the problem. --RDM From rdmurray at bitdance.com Tue Feb 3 22:15:18 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Wed, 4 Feb 2009 03:15:18 +0000 (UTC) Subject: Extracting file from zip archive in Python 2.6.1 References: <7676f73d-2ee9-4151-8a09-b11a3eea2045@p37g2000yqd.googlegroups.com> <4d2b4207-e14a-4b4d-b518-1b7eb6322ce5@n33g2000pri.googlegroups.com> Message-ID: Quoth Brandon Taylor : > Ok, the first thing I needed to do was add: > > from __future__ import with_statement at the beginning of my file > > but: > > with zip_file.open(zip_name + '/' + thumbnail_image) as source: > with open(os.path.join(thumbnail_path, > thumbnail_image), 'wb') as target: > shutil.copyfileobj(source, target) > > Returns an error on the first line: > > ZipExtFile instance has no attribute '__exit__' > > Googling this error message is turning up nothing, and there's no > mention of the exception in the docs. Any thoughts? Yeah, that means the ZipExtFile object hasn't been extended to handle the context management protocol. It would be pretty simple to roll your own for it. Take a look at the contextlib module. --RDM From miki.tebeka at gmail.com Tue Feb 3 22:34:15 2009 From: miki.tebeka at gmail.com (Miki) Date: Tue, 3 Feb 2009 19:34:15 -0800 (PST) Subject: Passing environment variable to "subprocess" causes failure References: <13842319-2d1a-4012-aa55-977b79574288@l33g2000pri.googlegroups.com> Message-ID: > Code A: > > p = subprocess.Popen( ['python', '-V'], env={ 'PYTHONPATH': 'C:/ > Documents and Settings/David Gould/workspace/DgTools/Common/Trunk/ > Source' } ) > print p.communicate()[0] > print p.returncode > > Output: > > None > -1072365564 My *guess* is that since PATH is not in the environment you're passing, the shell can't find the python interpreter. Try: from os import environ from subprocess import Popen, PIPE env = environ.copy() # Warning: override existing PYTHONPATH env["PYTHONPATH"] = "C:/Documents and Settings/David Gould/workspace/ DgTools/Common/Trunk/Source" p = = subprocess.Popen(['python', '-V'], env=env, stdout=PIPE) print p.communicate() print p.returncode HTH, -- Miki http://pythonwise.blogspot.com From miki.tebeka at gmail.com Tue Feb 3 22:39:29 2009 From: miki.tebeka at gmail.com (Miki) Date: Tue, 3 Feb 2009 19:39:29 -0800 (PST) Subject: Cross platform compilation? References: Message-ID: <4a4b0708-9502-4c49-8612-98ab8b6417e3@r15g2000prh.googlegroups.com> On Feb 2, 6:59?pm, "John Harper" wrote: > I am trying to build Python to use in an embedded system which uses a > ppc_440 CPU. The only information I've found is something written by > Klaus Reimer a few years ago, which was based on Python 2.2. So far I > seem to have successfully built Python itself, but building the > extensions fails miserably with complaints about library format. It > insists on referring to "i686" which is indeed the platform it is > actually running on. > > Before I try to reverse engineer completely setup.py, is there > something obvious that needs to be done to get it to use the right tool > chain? > > More generally, it seems like this would be something that lots of > people would want to do. I'm surprised there isn't support for it built > into the distributed version of Python, without having to hack all the > setup files...? Maybe http://www.ailis.de/~k/archives/19-ARM-cross-compiling-howto.html could help? HTH, -- Miki http://pythonwise.blogspot.com From rhodri at wildebst.demon.co.uk Tue Feb 3 22:49:08 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 04 Feb 2009 03:49:08 -0000 Subject: is python Object oriented?? In-Reply-To: <4ec8770b-631f-492b-be7a-27bb8ac47afc@i20g2000prf.googlegroups.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com> <003d01c98527$d9ea4ec0$0d00a8c0@hendrik> <005201c98549$d3eb74a0$0d00a8c0@hendrik> <2ed10ddd-63ac-4507-b046-0404cc85c97a@s1g2000prg.googlegroups.com> <4ec8770b-631f-492b-be7a-27bb8ac47afc@i20g2000prf.googlegroups.com> Message-ID: On Wed, 04 Feb 2009 01:13:32 -0000, Russ P. wrote: > On Feb 3, 4:05 pm, "Rhodri James" wrote: >> I'm very much of the second opinion; it was Russ who did the sudden >> volte >> face and declared that it was trivial to circumvent. > > Whoa! Hold on a minute here. Your failure to understand a simple idea > does not constitute a "sudden volte" (whatever that is) on my part. My apologies. "Volte-face" should have had a hyphen in it. > Let me try to explain again what should be fairly obvious. I understood you just fine. It was how what you described was consistent with your previous position that "private" was needed for enforcement purposes, while the leading underscore convention relied on team discipline and was therefore insufficient. Since you've clarified that "private" enforces privacy through... er... team discipline, I'm now just very confused as to what you think it buys you. -- Rhodri James *-* Wildebeeste Herder to the Masses From btaylordesign at gmail.com Tue Feb 3 22:56:32 2009 From: btaylordesign at gmail.com (Brandon Taylor) Date: Tue, 3 Feb 2009 19:56:32 -0800 (PST) Subject: Extracting file from zip archive in Python 2.6.1 References: <7676f73d-2ee9-4151-8a09-b11a3eea2045@p37g2000yqd.googlegroups.com> <4d2b4207-e14a-4b4d-b518-1b7eb6322ce5@n33g2000pri.googlegroups.com> Message-ID: <4b188330-0328-48c3-a072-041273055fb8@r24g2000vbp.googlegroups.com> On Feb 3, 9:15?pm, rdmur... at bitdance.com wrote: > Quoth Brandon Taylor : > > > > > Ok, the first thing I needed to do was add: > > > from __future__ import with_statement at the beginning of my file > > > but: > > > with zip_file.open(zip_name + '/' + thumbnail_image) as source: > > ? ? ? ? ? ? ? ? ? ? with open(os.path.join(thumbnail_path, > > thumbnail_image), 'wb') as target: > > ? ? ? ? ? ? ? ? ? ? ? ? shutil.copyfileobj(source, target) > > > Returns an error on the first line: > > > ZipExtFile instance has no attribute '__exit__' > > > Googling this error message is turning up nothing, and there's no > > mention of the exception in the docs. Any thoughts? > > Yeah, that means the ZipExtFile object hasn't been extended to > handle the context management protocol. ?It would be pretty > simple to roll your own for it. ?Take a look at the contextlib > module. > > --RDM Cool. Thanks for the pointers. In the meantime, I just used extract and os.rename to move the files where I need them, but I'll see if I can save that extra step if possible. From haag at lsu.edu Tue Feb 3 23:02:13 2009 From: haag at lsu.edu (Alaric Haag) Date: Tue, 03 Feb 2009 22:02:13 -0600 Subject: Good or bad use of __repr__? Message-ID: Hello, Is the use of __repr__ below a "really bad idea"? class Dimension(): def __init__(self, setp, name): ptr = setp.contents.dim while ptr.contents.name != name: ptr = ptr.contents.next self.name = ptr.contents.name self.size = ptr.contents.size self.unlimited = bool(ptr.contents.unlimited) self.coord = ptr.contents.coord def __repr__(self): return '%g' % (self.size) As written, if a program references a Dimension instance without an attribute, it gets the size attrbute "by default". If it wants the other attributes, they have to be spec'd. In the context of the code being developed, the "size" attribute is the "logical" representation of the dimension. I'm just wondering if this sort of design should be avoided. Many thanks! Alaric From apt.shansen at gmail.com Tue Feb 3 23:08:34 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 3 Feb 2009 20:08:34 -0800 Subject: Import without executing module In-Reply-To: <5a64441e-bee9-4466-b613-3e83fce2e8fb@r15g2000prd.googlegroups.com> References: <7a9c25c20902012319i2d217644k12bc926400f630c2@mail.gmail.com> <14edd870-74d4-4d7a-a363-a4bc3515a071@s9g2000prg.googlegroups.com> <0ad1a5c0-0605-49fe-8a97-1159fc274d30@a39g2000prl.googlegroups.com> <45e5daf1-108c-499e-82a9-10e67eac33e2@z27g2000prd.googlegroups.com> <5a64441e-bee9-4466-b613-3e83fce2e8fb@r15g2000prd.googlegroups.com> Message-ID: <7a9c25c20902032008u1e745eb0x2d30b45844a74c5d@mail.gmail.com> On Tue, Feb 3, 2009 > So, is inserting the above if statement common practice for python > programmers? As a C programmer, it seems that people put a "#ifndef > XXX...#define XXX...[all of the code]...#endif" almost as a habit. I > wonder if its the same thing? That statement is very common in Python. If a module is only ever going to be run as the main script its not needed but as you saw with this thread, sometimes you want to import what would be main into other places. More commonly I've found, is the use of that statement in other modules that are never -really- meant to be main but sometimes you want to run on their for testing or other purposes. For me, I use it all the time in my GUI modules that are never in the normal course of events run directly, but when developing them its useful to quickly start up a fake app / frame and load what I'm working on into a test display. That said, its use is fairly unique and idiomatic just as the 'main entry point' of a module. 75%(a number I'm pulling outta my arse!) of its uses are things like: if __name__ == "__main__": main() Or whatever other minimal scaffolding is required to jumpstart the script's driver functions. Its unlikely you'll see anything like it elsewhere -- and it serves a very different purpose from what you describe seeing in C. There is no need to try to make sure something is executed/compiled only once in Python like you may want to do in C. Every module is only ever compiled once: if you import it ten times in ten different places only the first will compile and execute the code, the rest of the calls will return that original module again. You're only likely to see "if" statements around definitions and larger blocks of top-level code if someone is doing something... complicated. Or if they're doing a big procedural script that's not really ever meant to be re-used (especially one that grows overtime and takes a life of its own). It happens but its really rare, from my experience at least. --S From apt.shansen at gmail.com Tue Feb 3 23:23:40 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 3 Feb 2009 20:23:40 -0800 Subject: Good or bad use of __repr__? In-Reply-To: References: Message-ID: <7a9c25c20902032023j37e719d7j6246e54cd50af37a@mail.gmail.com> > > As written, if a program references a Dimension instance without an > attribute, it gets the size attrbute "by default". If it wants the other > attributes, they have to be spec'd. In the context of the code being > developed, the "size" attribute is the "logical" representation of the > dimension. I'm just wondering if this sort of design should be avoided. Well the question is: does that repr give you sufficient information to identify at least and possibly recreate that instance? If you repr an int and it comes up as 50.. and repr a Dimension and it comes up as 50, does that allow you to differentiate between them? If you need to. I primarily use repr for a debugging tool, and in that context I'd always for instances at least make it something like as the repr output. But I personally like to err on the side of 'more is better' when it comes to repr output, and would probably have put in the name/unlimited/coord even if they may not always be present. So that if you're checking something after the fact and all you have to go on is a repr of an object involved you have more details to work with. But there's no hard and fast rules. Generally, repr output should be whatever you need to clearly reflect The Specific Object as a string. --S From Bornstub at gmail.com Tue Feb 3 23:37:02 2009 From: Bornstub at gmail.com (Victor Lin) Date: Tue, 3 Feb 2009 20:37:02 -0800 (PST) Subject: How to call python from a foreign language thread (C++) References: Message-ID: On 2?4?, ??2?44?, Philip Semanchuk wrote: > On Feb 3, 2009, at 12:51 PM, Victor Lin wrote: > > > > > It seems that my program can't call to Python's function from thread > > directly, because there is Global Interpreter Lock. The python's GIL > > is so complex, I have no idea how it works. I'm sorry, what I can do > > is to ask. My question is. What should I do before and after I call a > > Python function from threads? > > Hi Victor, > I asked a similar question yesterday and have gotten no response yet > -- I hope you'll have better luck. I'm writing a C extension that > wants to implement a callback in a new thread. Here's what I think > I've learned from reading the threads API doc. Please note that this > is a classic case of the blind leading the blind! I'm sure some (most? > all?) of the ideas below are wrong, but I'm hoping that thinking > through some of this "out loud" will help both of us. Or maybe some > more knowledgeable person will take pity on/be appalled by my > ignorance and come to our rescue. =) > > Python's infamous GIL doesn't exist when a program is single-threaded. > Before a new thread is created, the main thread must call > PyEval_InitThreads() to create the GIL. However, "It is not safe to > call this function when it is unknown which thread (if any) currently > has the global interpreter lock." Therefore my extension must do this: > > i_have_the_gil = 0; > if (!PyEval_ThreadsInitialized()) { > PyEval_InitThreads(); > /* "...when this function initializes the lock, it also acquires > it." */ > i_have_the_gil = 1; > > } > > That ensures that the GIL is created. > > My extension will be calling from a newly-created C thread. The > *Python* thread doesn't exist yet; so next I have to create it. > Therefore -- > > if (!i_have_the_gil) > PyEval_AcquireLock(); > > // Might not actually be the main thread but conceptually > // it is OK to assume so here. > main_thread = PyThreadState_Get(); > > callback_thread = PyThreadState_New(main_thread->interp); > > PyThreadState_Swap(callback_thread); > > gstate = PyGILState_Ensure(); > > call_callback_function(); > > // Now unwind the above > > PyGILState_Release(gstate); > > PyThreadState_Swap(main_thread); > > PyThreadState_Clear(callback_thread); > > PyThreadState_Delete(callback_thread); > > PyEval_ReleaseLock(); > > I haven't yet tested this! But hopefully it is the right idea and just > needs a little fine tuning. > > I found this discussion useful:http://mail.python.org/pipermail/python-list/2006-November/413088.html > > It includes the quote, "The current thread state API doc, as you read > it from top to bottom now, is in fact totally confusing for anyone who > didn't develop Python himself" > > I like! =) > > Cheers > Philip Hi Philip, It does not work. But however, thanks your help. I have tired so many methods to do. But it crash...crash..deadlock...deadlock..crash...crash... I have no any tried success. I am going crazy. Could someone help me, thanks. From Russ.Paielli at gmail.com Wed Feb 4 00:04:30 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Tue, 3 Feb 2009 21:04:30 -0800 (PST) Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com> <003d01c98527$d9ea4ec0$0d00a8c0@hendrik> <005201c98549$d3eb74a0$0d00a8c0@hendrik> <2ed10ddd-63ac-4507-b046-0404cc85c97a@s1g2000prg.googlegroups.com> <4ec8770b-631f-492b-be7a-27bb8ac47afc@i20g2000prf.googlegroups.com> Message-ID: <11ee7ba4-12f2-4744-80af-315dbea78cd9@r41g2000prr.googlegroups.com> On Feb 3, 7:49?pm, "Rhodri James" wrote: > On Wed, 04 Feb 2009 01:13:32 -0000, Russ P. wrote: > > On Feb 3, 4:05 pm, "Rhodri James" wrote: > >> I'm very much of the second opinion; it was Russ who did the sudden ? > >> volte > >> face and declared that it was trivial to circumvent. > > > Whoa! Hold on a minute here. Your failure to understand a simple idea > > does not constitute a "sudden volte" (whatever that is) on my part. > > My apologies. ?"Volte-face" should have had a hyphen in it. > > > Let me try to explain again what should be fairly obvious. > > I understood you just fine. ?It was how what you described was > consistent with your previous position that "private" was needed > for enforcement purposes, while the leading underscore convention > relied on team discipline and was therefore insufficient. ?Since > you've clarified that "private" enforces privacy through... er... > team discipline, I'm now just very confused as to what you think > it buys you. > > -- > Rhodri James *-* Wildebeeste Herder to the Masses You need team discipline either way. The question here is to what extent the language supports the discipline. If you are going to check for access violations anyway with third-party tools or code reviews, why not let the language do the job for you automatically (or at least take a first cut at it)? Imagine you own a company, and you decide to lease an office building. Would you expect the office doors to have locks on them? Oh, you would? Why? You mean you don't "trust" your co-workers? What are locks but enforced access restriction? What people like you are saying is that you don't need no stinkin' locks because your co-workers are all "consenting adults" whom you trust. Actually, you're saying even more than that. You're saying that office doors never need locks, because everyone should trust their co- workers. All you need is a "keep-out" sign on the door (leading underscores). And you are presenting as evidence for your position the fact that people occasionally get locked out of an office that they need to get into. I'm saying, fine, if you trust your co-workers, then keep the doors unlocked, but please don't insist that office doors come without locks. Yes, locks occasionally cause inconvenience, but they serve a very useful purpose if used properly. From steven at REMOVE.THIS.cybersource.com.au Wed Feb 4 00:18:29 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 04 Feb 2009 05:18:29 GMT Subject: Good or bad use of __repr__? References: Message-ID: On Tue, 03 Feb 2009 22:02:13 -0600, Alaric Haag wrote: > Hello, > > Is the use of __repr__ below a "really bad idea"? > > class Dimension(): > def __init__(self, setp, name): > ptr = setp.contents.dim > while ptr.contents.name != name: > ptr = ptr.contents.next > self.name = ptr.contents.name > self.size = ptr.contents.size > self.unlimited = bool(ptr.contents.unlimited) > self.coord = ptr.contents.coord > def __repr__(self): > return '%g' % (self.size) As a rule of thumb, you should aim for: eval( repr(obj) ) to recreate the obj. That's not always possible, but when possible, it is an ideal to aspire to. Given that, I'd recommend: def __repr__(self): return '%s(%s, %s)' % ( self.__class__.__name__, self.ptr, self.name) def __str__(self): return "" % self.size except of course your class doesn't store ptr. But looking at the code shown, I'm guessing you have bigger design problems than just what __repr__ should look like. I suggest you read this: http://www.surfscranton.com/architecture/LawOfDemeter.htm -- Steven From steven at REMOVE.THIS.cybersource.com.au Wed Feb 4 00:29:01 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 04 Feb 2009 05:29:01 GMT Subject: Good or bad use of __repr__? References: Message-ID: On Wed, 04 Feb 2009 05:18:29 +0000, Steven D'Aprano wrote: > ... I'd recommend: > > def __repr__(self): > return '%s(%s, %s)' % ( > self.__class__.__name__, self.ptr, self.name) > def __str__(self): > return "" % self.size > > > except of course your class doesn't store ptr. Ah crap, sorry, I meant setp not ptr. Sorry for the confusion. -- Steven From tjreedy at udel.edu Wed Feb 4 00:54:19 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 04 Feb 2009 00:54:19 -0500 Subject: Good or bad use of __repr__? In-Reply-To: References: Message-ID: Alaric Haag wrote: > Hello, > > Is the use of __repr__ below a "really bad idea"? > > class Dimension(): > def __init__(self, setp, name): > ptr = setp.contents.dim > while ptr.contents.name != name: > ptr = ptr.contents.next > self.name = ptr.contents.name > self.size = ptr.contents.size > self.unlimited = bool(ptr.contents.unlimited) > self.coord = ptr.contents.coord > def __repr__(self): > return '%g' % (self.size) > > As written, if a program references a Dimension instance without an > attribute, it gets the size attrbute "by default". No it does not. It gets a string representation of the size. Not the same thing. From raykyoto at gmail.com Wed Feb 4 00:56:04 2009 From: raykyoto at gmail.com (Ray) Date: Tue, 3 Feb 2009 21:56:04 -0800 (PST) Subject: Import without executing module References: <7a9c25c20902012319i2d217644k12bc926400f630c2@mail.gmail.com> <14edd870-74d4-4d7a-a363-a4bc3515a071@s9g2000prg.googlegroups.com> <0ad1a5c0-0605-49fe-8a97-1159fc274d30@a39g2000prl.googlegroups.com> <45e5daf1-108c-499e-82a9-10e67eac33e2@z27g2000prd.googlegroups.com> <5a64441e-bee9-4466-b613-3e83fce2e8fb@r15g2000prd.googlegroups.com> Message-ID: <877a81a9-4f69-42d2-ab39-09ad7ca73c96@p2g2000prn.googlegroups.com> Hi Stephen, On Feb 4, 1:08?pm, Stephen Hansen wrote: > On Tue, Feb 3, 2009 > > > So, is inserting the above if statement common practice for python > > programmers? ?As a C programmer, it seems that people put a "#ifndef > > XXX...#define XXX...[all of the code]...#endif" almost as a habit. ?I > > wonder if its the same thing? > > That statement is very common in Python. If a module is only ever > going to be run as the main script its not needed but as you saw with > this thread, sometimes you want to import what would be main into > other places. More commonly I've found, is the use of that statement > in other modules that are never -really- meant to be main but > sometimes you want to run on their for testing or other purposes. For ... Oh, I see...I never thought of module testing as one possible uses of it -- but yes, I see that now. Makes sense to test each module individually and (in C, at least) to write a separate main() driver in another file each time... > That said, its use is fairly unique and idiomatic just as the 'main > entry point' of a module. 75%(a number I'm pulling outta my arse!) of > its uses are things like: > ? ? if __name__ == "__main__": > ? ? ? ? main() > > Or whatever other minimal scaffolding is required to jumpstart the > script's driver functions. Its unlikely you'll see anything like it > elsewhere -- and it serves a very different purpose from what you > describe seeing in C. There is no need to try to make sure something ... Ah, ok! I'm still trying to get use to how Python does things from languages such as C...old habits [from other languages] are harder to break. :) If the above "if" statement is fairly common, then I think I'll start using it just to get into the habit of it. Thank you very much for your detailed explanation! Ray From gagsl-py2 at yahoo.com.ar Wed Feb 4 01:16:06 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 04 Feb 2009 04:16:06 -0200 Subject: Extracting file from zip archive in Python 2.6.1 References: <7676f73d-2ee9-4151-8a09-b11a3eea2045@p37g2000yqd.googlegroups.com> <4d2b4207-e14a-4b4d-b518-1b7eb6322ce5@n33g2000pri.googlegroups.com> Message-ID: En Wed, 04 Feb 2009 00:36:40 -0200, Brandon Taylor escribi?: > On Feb 3, 1:16?pm, Brandon Taylor wrote: >> On Feb 3, 9:45?am, "Gabriel Genellina" wrote: >> > En Tue, 03 Feb 2009 05:31:24 -0200, Brandon Taylor ? >> > escribi?: >> > > zip_file.extract(zip_name + '/' + thumbnail_image, thumbnail_path) >> > > What is happening is that the extract method is creating a folder > >> > with >> > > the name of 'zip_name' and extracting the files to it. Example: >> > extract will create all directories in member name. Use open instead: >> > with zip_file.open(zip_name + '/' + thumbnail_image) as source: >> > ? ?with open(os.path.join(thumbnail_path, thumbnail_image), "wb") as >> > target: >> > ? ? ?shutil.copyfileobj(source, target) > Ok, the first thing I needed to do was add: > > from __future__ import with_statement at the beginning of my file That should not be necesary with your Python version (2.6.1 isn't it?) > with zip_file.open(zip_name + '/' + thumbnail_image) as source: > with open(os.path.join(thumbnail_path, > thumbnail_image), 'wb') as target: > shutil.copyfileobj(source, target) > > Returns an error on the first line: > > ZipExtFile instance has no attribute '__exit__' Ouch, sorry, this new feature will appear in the not-yet-released 2.7 version... Try this instead: source = zip_file.open(zip_name + '/' + thumbnail_image) try: with open(os.path.join(thumbnail_path, thumbnail_image), 'wb') as target: shutil.copyfileobj(source, target) finally: source.close() -- Gabriel Genellina From grante at visi.com Wed Feb 4 01:30:37 2009 From: grante at visi.com (Grant Edwards) Date: Wed, 04 Feb 2009 00:30:37 -0600 Subject: python libpcap equivalent References: Message-ID: On 2009-02-03, Steve Holden wrote: >> You can use pylibpcap to capture packets, and then use a raw >> socket to send them out again on whatever interface you want. FWIW, under Linux you can also capture packets using a raw-mode socket, but the only times I've done it I was only capturing packets for a single Ethertype (an Ethertype that I knew the OS network stack was discarding). I'm not sure if you can configure a raw socket to intercept any and all packets such that they don't get passed on to the network stack. >> You'll have to make sure that the host's OS's network stack >> isn't going to process the packets at all. I'm not sure how >> you go about that. >> >> The documentation for pylibpcap is built into the module. See >> doc.i in the tarball. > > And note that this won't work on Vista, where the raw socket > interface is no longer available to standard applications. [I've few clues when it comes to Windows, but based on what I overhear from the guys at work who do work on Windows networking stuff, I suspect doing something like this on is going to be an order of magnitude harder on Windows than on Linux or BSD.] Under Unices (and prehaps Windows), there are the tun/tap interfaces, but they do pretty much the inverse of what the OP wants to do. TUN/TAP interfaces are an API between a user-space app and the OSes network stack that allows the user-space app to "pretend" to be an Ethernet interface in the eyes of the OS. What the OP want's is a corresponding API between user-space and an Ethernet card's driver such that the user-space app can pretend to be -- Grant From sri_annauni at yahoo.co.in Wed Feb 4 01:48:26 2009 From: sri_annauni at yahoo.co.in (srinivasan srinivas) Date: Wed, 4 Feb 2009 12:18:26 +0530 (IST) Subject: How do i add body to email.mime.multipart.MIMEMultipart instance? Message-ID: <460283.85034.qm@web7904.mail.in.yahoo.com> Hi, Could someone tell me the way to add body to the instance email.mime.multipart.MIMEMultipart instance which has attachments? Thanks, Srini Bollywood news, movie reviews, film trailers and more! Go to http://in.movies.yahoo.com/ From sri_annauni at yahoo.co.in Wed Feb 4 01:50:43 2009 From: sri_annauni at yahoo.co.in (srinivasan srinivas) Date: Wed, 4 Feb 2009 12:20:43 +0530 (IST) Subject: How do i add body to 'email.mime.multipart.MIMEMultipart' instance? Message-ID: <944076.49060.qm@web7906.mail.in.yahoo.com> Hi, Could someone tell me the way to add body content to 'email.mime.multipart.MIMEMultipart' instance? Thanks, Srini Add more friends to your messenger and enjoy! Go to http://messenger.yahoo.com/invite/ From mail at microcorp.co.za Wed Feb 4 01:54:35 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Wed, 4 Feb 2009 08:54:35 +0200 Subject: Python Global State References: <775033410902030758pa44e7ccl251fc82e6bb90229@mail.gmail.com> Message-ID: <009b01c98695$712b9320$0d00a8c0@hendrik> er wrote: >Simple question, I think: Is there a way to make a >completely global variable across a slew of modules? >If not, what is the canonical way to keep a global state? >The purpose of this is to try to prevent circular module >imports, which just sort of seems nasty. Thank you! Take a leaf out of COBOL's data division book, and make a module that has all the globals in it. Just refrain from calling it globals, that is the path to insanity. Then whenever you need the stuff, just import system_globals, and you are done. This has another hidden advantage, in that the system_globals.py can be used to keep all sorts of system wide configuration information. - Hendrik From mail at microcorp.co.za Wed Feb 4 02:09:04 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Wed, 4 Feb 2009 09:09:04 +0200 Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com><0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com><6ul2ieFg1sraU1@mid.uni-berlin.de><73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com><018801c9850e$3e019fe0$0d00a8c0@hendrik><7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com><6uo5koFg8q28U1@mid.uni-berlin.de> <6uoqvrFgh5oeU1@mid.uni-berlin.de> Message-ID: <01a901c9869c$628e8fa0$0d00a8c0@hendrik> "Scott David Daniels" wrote: > You might enjoy looking at QNX, since I think it is built along the > lines you are describing here. I have an ancient copy of their OS, > but haven't followed for more than couple of decades. I vaguely know about it, and I know they claim to be hot on real time stuff. I have never pursued it in any depth because of the real tiny nature of the processors I have been working with (8031). When I had a cursory look at it a long time ago, it seemed to be almost unix like in its make up, and I doubted that I could persuade it to run on of them. (I may be dead wrong of course - I don't know) I will put it on my list of stuff to try to get done. Thanks for the reminder. - Hendrik From steven at REMOVE.THIS.cybersource.com.au Wed Feb 4 02:10:26 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 04 Feb 2009 07:10:26 GMT Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com> <003d01c98527$d9ea4ec0$0d00a8c0@hendrik> <005201c98549$d3eb74a0$0d00a8c0@hendrik> <2ed10ddd-63ac-4507-b046-0404cc85c97a@s1g2000prg.googlegroups.com> <498825f3$0$3303$426a74cc@news.free.fr> Message-ID: On Tue, 03 Feb 2009 12:09:46 +0100, Bruno Desthuilliers wrote: >> I love Python, and I'm greedy and want it all: I want a dynamic, >> easy-to- use language *and* a compiler that can protect me from myself > > That's not what compilers are for. So you say. >> and bad data. > > I definitly fail to see how a compiler could protect you from *runtime* > issues ??? I'm surprised you can't. Any time a compiler prevents an error by detecting it at compile-time (say, attempting to store a 96-bit float into the memory space allocated for a 32-bit int), it has prevented a runtime error. Perhaps what you are thinking is that I meant compilers can protect you from "all" runtime issues. That would be silly. Although, in principle, we can get close, for some definition of "close". Here's a toy function, and a specification: def inverse(x): return 1.0/x Specification: input must be a float, output must be a float. Is that function correct? No, because it will raise an exception if x==0.0. Python's compiler is dumb and will allow you to write incorrect functions, but a smart compiler could look at that function and see that it was incorrect. The fix would then be to change the code, or the specification, or both. Smart compilers turn some runtime errors into compile-time errors. The earlier you catch the error, the easier it is to fix it. Now, that's a toy example. Languages like Ada make correctness proofs, well, perhaps not easy, but merely difficult compared to impossible for languages like Python. To bring it back to private/public attributes, side-effects make correctness proofs difficult. Modifications of attributes are side- effects. When attributes are subject to being modified by arbitrary code, it is harder to reason about the correctness of the code: class Inverter(object): def __init__(self, x): # Pre-condition: x is always a float if x: self.x = x else: raise ValueError("x must not be zero") # Post-condition: if self.x exists, it is a non-zero float def invert(self): return 1.0/self.x Is method invert correct? No, it is not, because the invariant that self.x is non-zero may have been broken by some arbitrary piece of code elsewhere. Our ability to reason about the correctness of the code is weakened significantly. Sticking an underscore in front of x does not help: there's nothing to stop some arbitrary function elsewhere changing _x to zero. There are two usual approaches to dealing with that problem which are available to Python programmers: (1) Paranoia. Make the developer responsible for checking everything all the time: def invert(self): x = self.x if isinstance(x, float) and x: return 1.0/self.x else: raise MyError('post-condition x a non-zero float violated') You can use decorators to decrease the amount of boilerplate, but you have to remember to use the decorators; or you can use a metaclass to automatically apply decorators, but that's hard and not very flexible. Whichever way you do it, you're still responsible, and whatever way, you still have to pay the performance penalty. This also turns an unexpected exception into an expected exception, but is otherwise rather useless. It doesn't tell you when the post-condition was violated, or by what function, and that's the information you need in order to fix the bug. (2) Hope the error never occurs, and if it does, let the caller deal with it. Hopefully you aren't your own caller. That's often the Python approach. I've already written about the glorious freedom such an approach gives the developer. I'm not being sarcastic: even if you are your own caller, you get to put off worrying about a bug which might never happen. This is a great strategy when the worst thing that a bug will do is display an icon in the wrong position. Fix it in the next release. But that's not a viable strategy when the consequences of a bug might include giving the patient 20,000 rads of radiation instead of 200: http://www.ccnr.org/fatal_dose.html There is a third strategy, sadly not available to Python programmers: prevention by catching potential errors at compile-time. (Python does catch some errors at compile-time, but only syntax errors.) If x can only be modified in a few places, (that is, it is effectively hidden or private) then it is much easier to reason about program correctness, avoid bugs, and debug those bugs which do occur. No, this is not a panacea which will prevent every imaginable bug. Nor is it a replacement for unit-testing (which also does not prevent every imaginable bug). It is a compliment to unit-testing. Is it subject to over-use or misuse? Of course it is. So are properties, and decorators, and metaclasses, and OO, and Singletons, and, well, everything. Let's not close our eyes to *either* the costs or the benefits, and let's not limit what Python might become in the future. Python 3 has type annotations and Guido is encouraging people to experiment with type systems. This was unthinkable a year or two ago. What might Python 4000 bring? -- Steven From tpawley at gmail.com Wed Feb 4 02:29:47 2009 From: tpawley at gmail.com (Torabisu) Date: Tue, 3 Feb 2009 23:29:47 -0800 (PST) Subject: what IDE is the best to write python? References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> Message-ID: On Feb 1, 9:42?am, "mcheun... at hotmail.com" wrote: > Hi all > ? ?what IDE is the best to write python? > thanks > from Peter (mcheun... at hotmail.com) I use a combination of: 1. VI/VIM 2. Eclipse with PyDev extensions 3. NetBeans with Python Module installed When I'm working directly on development boxes, making quick changes, I'll use VI/VIM. When I'm only doing Python / Django backend development and working with Subversion I'll use Eclipse. If I'm on a project where I need to do Java ME work and Python / Django backend development, then I'll use NetBeans. My recommendation is try 3 or 4 and pick one that you feel comfortable with. Trav (",) T From bob.martin at excite.com Wed Feb 4 02:42:15 2009 From: bob.martin at excite.com (Bob Martin) Date: Wed, 04 Feb 2009 07:42:15 GMT Subject: what IDE is the best to write python? References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> <874ozd3cr3.fsf@benfinney.id.au> <20090202034654.GD30237@turki.gavron.org> <8e63a5ce0902021735x45bea672tc4a655023ba11d5a@mail.gmail.com> Message-ID: in 100686 20090203 181957 Catherine Heathcote wrote: >Tim Rowe wrote: >> 2009/2/3 Jervis Whitley : >> >>> real programmers use ed. >> >> Ed? Eee, tha' were lucky. We had to make holes in Hollerith cards wi' >> our bare teeth... >> > >You had teeth!?! > >Oh and hi, I shall be a new face in the crowd ;) Oh dear! You'd better tell them what they're in for ;-) From bruno.42.desthuilliers at websiteburo.invalid Wed Feb 4 03:51:25 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 04 Feb 2009 09:51:25 +0100 Subject: Good or bad use of __repr__? In-Reply-To: References: Message-ID: <49895700$0$20332$426a34cc@news.free.fr> Alaric Haag a ?crit : > Hello, > > Is the use of __repr__ below a "really bad idea"? I'd probably do the same as Stephen Hansen ("") or at least something quite similar. Now on a totally unrelated point (micro optimization anyone ?): > class Dimension(): > def __init__(self, setp, name): > ptr = setp.contents.dim > while ptr.contents.name != name: > ptr = ptr.contents.next > self.name = ptr.contents.name > self.size = ptr.contents.size > self.unlimited = bool(ptr.contents.unlimited) > self.coord = ptr.contents.coord In the above code, you're constantly refering to ptr.contents, and never use ptr directly. Attribute lookup is not free, so it's better to avoid them. Local bindings lookup, OTHO, is quite fast. IOW, this would better be written as: def __init__(self, setp, name): contents = setp.contents.dim while contents.name != name: contents = contents.next self.name = contents.name self.size = contents.size self.unlimited = bool(contents.unlimited) self.coord = contents.coord From bruno.42.desthuilliers at websiteburo.invalid Wed Feb 4 04:05:22 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 04 Feb 2009 10:05:22 +0100 Subject: is python Object oriented?? In-Reply-To: References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <67d8a4d2-0b3d-4b41-84e2-698f17cb8e88@35g2000pry.googlegroups.com> <26a3c05c-253d-4134-bcb9-aed8505f250e@e1g2000pra.googlegroups.com> Message-ID: <49895a45$0$16900$426a74cc@news.free.fr> Gabriel Genellina a ?crit : > En Mon, 02 Feb 2009 19:51:11 -0200, Russ P. > escribi?: > >> Suppose a library developer (or a module developer on a large team) >> uses leading underscores. Now suppose that, for whatever reason >> (pressure from the users, perhaps), the library developer decides to >> change a "private" attribute to public. Now all occurrences of the >> identifier need to be changed. If an assignment to the previously >> "private" attribute is missed, no warning will be issued (because >> Python allows new attributes to be added anywhere, even completely >> outside the class definition itself). And if the library is widely >> used, the probability of such bugs occurring is very high. > > So _foo becomes foo. Then: > > class X(object): > def get_foo(self): return self._foo > def set_foo(self, value): self._foo = value > foo = property(get_foo, set_foo) FWIW, if there's no other need for the property, I'd do it the other way round : directly make foo a plain attribute, and add a _foo property whose accessors would raise a deprecation warning. Then there's no chance I miss a an assignement to _foo !-) From bruno.42.desthuilliers at websiteburo.invalid Wed Feb 4 04:11:22 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 04 Feb 2009 10:11:22 +0100 Subject: is python Object oriented?? In-Reply-To: <22440895-ed68-4643-b833-0befe83d571c@f40g2000pri.googlegroups.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com> <003d01c98527$d9ea4ec0$0d00a8c0@hendrik> <005201c98549$d3eb74a0$0d00a8c0@hendrik> <2ed10ddd-63ac-4507-b046-0404cc85c97a@s1g2000prg.googlegroups.com> <3acf1429-9aec-4e0d-b617-21cbcdf76087@w1g2000prk.googlegroups.com> <22440895-ed68-4643-b833-0befe83d571c@f40g2000pri.googlegroups.com> Message-ID: <49895bad$0$28683$426a74cc@news.free.fr> thmpsn.m.k at gmail.com a ?crit : > On Feb 3, 1:14 am, David Cournapeau wrote: (snip) >> after all, we have used FILE* for years and I have no idea about the FILE >> structure. > > Your lack of knowledge about it doesn't mean that it has somehow > magically "private" members. The only reason that most of us don't > know what a FILE is is that it's definition is implementation-defined > (i.e., every compiler may define it differently). > > That doesn't have anything to do with private members. For example, on > my system, defines FILE as: > > struct _iobuf { > char *_ptr; > int _cnt; > char *_base; > int _flag; > int _file; > int _charbuf; > int _bufsiz; > char *_tmpfname; > }; Didn't you notice kind of a pattern here ? > typedef struct _iobuf FILE; > > Given this information, nothing prevents me from writing things like: > > FILE* fp = fopen("file.txt", "r"); > if (!fp) { /* do something */ } > > printf("fp->_cnt = %d\n", fp->cnt); > printf("fp->_flag = %d\n", fp->_flag); > printf("fp->_file = %d\n", fp->_file); > > fp->_flag = 0x20; // OOPS!! Indeed - and that's exactly the point : nothing prevents you from accessing the implementation, *and yet, you don't* - unless of course you have a very strong reason to do so for a very specific corner case *and* you pretty well know what you're doing *and* you accept the implications. From bruno.42.desthuilliers at websiteburo.invalid Wed Feb 4 04:14:30 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 04 Feb 2009 10:14:30 +0100 Subject: is python Object oriented?? In-Reply-To: References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com> <003d01c98527$d9ea4ec0$0d00a8c0@hendrik> <005201c98549$d3eb74a0$0d00a8c0@hendrik> <2ed10ddd-63ac-4507-b046-0404cc85c97a@s1g2000prg.googlegroups.com> <3acf1429-9aec-4e0d-b617-21cbcdf76087@w1g2000prk.googlegroups.com> Message-ID: <49895c69$0$28683$426a74cc@news.free.fr> Russ P. a ?crit : > On Feb 3, 4:14 pm, "Rhodri James" wrote: >> On Tue, 03 Feb 2009 05:37:57 -0000, Russ P. wrote: (snip) >>> If a library developer releases the source code of a library, any user >>> can trivially "defeat" the access restrictions. But if a team of >>> developers is checking in code for a project, the leader(s) of the >>> project can insist that the access restrictions be respected to >>> simplify the management of interfaces. The larger the team, the more >>> useful that can be. That's why Java, C++, Ada, Scala, and other >>> languages have a "private" keyword. >> Indeed he can. He can even do that in Python; it just requires a little >> self-discipline from the team, or a validation script on the code >> repository if he really doesn't trust them. Not only can this be done >> without forcing the rest of the world to play, it makes things a little >> less daunting when those nice clean interfaces turn out to be >> incomplete/too slow/not what you thought. > > This has already been refuted several times on this thread alone, s/refuted/debated/ From jarausch at skynet.be Wed Feb 4 04:22:13 2009 From: jarausch at skynet.be (Helmut Jarausch) Date: Wed, 04 Feb 2009 10:22:13 +0100 Subject: subprocess.Popen - file like object from stdout=PIPE Message-ID: <49895e45$0$2860$ba620e4c@news.skynet.be> Hi, using e.g. import subprocess Package='app-arch/lzma-utils' EQ=subprocess.Popen(['/usr/bin/equery','depends',Package],stdout=subprocess.PIPE) EQ_output= EQ.communicate()[0] EQ_output is a string containing multiple lines. I'd prefer a file-like object, e.g. EQ_OUT so that I can loop over the lines of it like for line in EQ_OUT : ... I could use StringIO.StringIO applied to EQ_output but this reads all of the command's output into a big string first. On Unix/Linux a pipe is a file-like object after all, so how to get hold of it. Many thanks for a hint, Helmut. -- Helmut Jarausch Lehrstuhl fuer Numerische Mathematik RWTH - Aachen University D 52056 Aachen, Germany From justin.mailinglists at gmail.com Wed Feb 4 04:27:22 2009 From: justin.mailinglists at gmail.com (Justin Ezequiel) Date: Wed, 4 Feb 2009 01:27:22 -0800 (PST) Subject: How do i add body to 'email.mime.multipart.MIMEMultipart' instance? References: Message-ID: <62e9fa5a-dff1-425d-b3fe-cb038b717ff5@i24g2000prf.googlegroups.com> On Feb 4, 2:50?pm, srinivasan srinivas wrote: > Hi, > Could someone tell me the way to add body content to 'email.mime.multipart.MIMEMultipart' instance? > > Thanks, > Srini excerpt from one of the modules I use: def build_body(html, text=''): text = text.strip() and text or html2text(html).encode('ascii', 'xmlcharrefreplace') body = MIMEMultipart('alternative') body.attach(MIMEText(text)) body.attach(MIMEText(html, 'html')) return body HTH Justin From mariusbutuc at gmail.com Wed Feb 4 04:30:16 2009 From: mariusbutuc at gmail.com (Marius Butuc) Date: Wed, 4 Feb 2009 01:30:16 -0800 (PST) Subject: Load / Reload module Message-ID: <73783af1-803d-4baf-b428-85682c476e2f@w24g2000prd.googlegroups.com> Hi, First I must state that I'm a beginner in Python, so all help would be more than welcomed. I want do declare some classes (classes.py) in an external editor, than import the file and use the classes. After I change the file, I want to reload the definitions w/o leaving the interactive interpreter. So far I have tried - import classes # doesn't import my classes - from classes import * # imports, but I can't reload - reload(classes) # I have the same class definition after this I've tried the documentation but I got lost, so please help. Thanks, Marius From nick at craig-wood.com Wed Feb 4 04:31:58 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Wed, 04 Feb 2009 03:31:58 -0600 Subject: Code critique xmlrpclib References: <4c54d31a-6b8e-40ba-9124-850abff6c69e@g3g2000pre.googlegroups.com> <106ff6e6-1c23-4adb-8d89-b59d852db458@q30g2000prq.googlegroups.com> Message-ID: flagg wrote: > On Feb 3, 7:32?am, Nick Craig-Wood wrote: > > flagg wrote: > > > ?This xmlrpc server is designed to parse dns zone files and then > > > ?perform various actions on said files. \ > > > ?It uses dnspython, and xmlrpclib > > > ? I'd like to know what some of the more experienced python users > > > ?think. Where I could improve code, make it more efficient, whatever. > > > ?All suggestions are welcome. ?This is my first functional python > > > ?program, ?and I have tons of questions to go along with whatever > > > ?suggestions. ? How could I do sanity checking; right now nothing > > > ?checks the input to these functions, error-handling in this program is > > > ?almost non-existant how do you integrate decent error handling into a > > > ?piece of software......ill shut up now. > > > > I made a few comments, some about error handling! ?See below > > > > > > > > > ?import dns.zone > > > ?from time import localtime, strftime, time > > > ?import os, sys > > > ?from dns.rdataclass import * > > > ?from dns.rdatatype import * > > > ?from string import Template > > > ?import xmlrpclib > > > ?from SimpleXMLRPCServer import SimpleXMLRPCServer > > > ?from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler > > > > > ?zoneDir = "/dns" > > > > > ?def openZoneFile(zoneFile): > > > ? ? ?""" > > > ? ? ?Opens a zone file. ?Then reads in zone file to dnspython zone > > > ?object. > > > ? ? ?""" > > > ? ? ?global zone > > > ? ? ?global host > > > ? ? ?global domain > > > ? ? ?domain = ".".join(zoneFile.split('.')[1:]) > > > ? ? ?host = ".".join(zoneFile.split('.')[:1]) > > > > > ? ? ?try: > > > ? ? ? ? ? ? ?zone = dns.zone.from_file(zoneDir + domain + '.zone', > > > ?domain) > > > ? ? ?except dns.exception, e: > > > ? ? ? ? ? ? ?print e.__class__, e > > > > Don't use global variables! > > > > This function should probably return 3 things > > > > ? ? return zone, host, domain > > > > And whenever you use it, say > > > > ? ? zone, host, domain = openZoneFile(xxx) > > > > It should probably be a method of DNSFunctions. ?I'd avoid setting > > self.zone etc as that is making a different sort of global data which > > I'd avoid too. > > > > Also if the dns.zone.from_file didn't work (raises dns.exception) you > > set the host and domain but the zone is left at its previous value > > which probably isn't what you wanted. ?I'd let the error propagate > > which I think will do something sensible for the xmlrpc. > > > > > > > > > ?class DNSFunctions: > > > > > ? ? ? # Not exposed to xml-rpc calls, used internally only. > > > ? ? ?def _writeToZoneFile(self, record): > > > ? ? ? ? ?""" > > > ? ? ? ? ?Checks if zone file exists, if it does it write values to zone > > > ?file > > > ? ? ? ? ?""" > > > > > ? ? ? ? ?for (name, ttl, rdata) in zone.iterate_rdatas(SOA): > > > ? ? ? ? ? ? ?new_serial = int(strftime('%Y%m%d00', localtime(time()))) > > > ? ? ? ? ? ? ?if new_serial <= rdata.serial: > > > ? ? ? ? ? ? ? ? ?new_serial = rdata.serial + 1 > > > ? ? ? ? ? ? ?rdata.serial = new_serial > > > > > ? ? ? ? ?if os.path.exists(zoneDir + str(zone.origin) + "zone"): > > > ? ? ? ? ? ? ?f = open(zoneDir + str(zone.origin) + "zone", "w") > > > ? ? ? ? ? ? ?zone.to_file(f) > > > ? ? ? ? ? ? ?f.close() > > > ? ? ? ? ?else: > > > ? ? ? ? ? ? ?print "Zone: " + zone.origin + " does not exist, please > > > ?add first" > > > > This should probably be raising an exception to be caught or > > propagated back to the client via xmlrpc. > > > > > > > > > > > > > ? ? ?def showRecord(self, record): > > > ? ? ? ? ?""" > > > ? ? ? ? ?Shows a record for a given zone. Prints out > > > ? ? ? ? ?TTL, IN, Record Type, IP > > > ? ? ? ? ?""" > > > > > ? ? ? ? ?openZoneFile(record) > > > > > ? ? ? ? ?try: > > > ? ? ? ? ? ? ?rdataset = zone.get_node(host) > > > ? ? ? ? ? ? ?for rdata in rdataset: > > > ? ? ? ? ? ? ? ? ?return str(rdata) > > > ? ? ? ? ?except: > > > ? ? ? ? ? ? ?raise Exception("Record not found") > > > > > ? ? ?def changeRecord(self, record, type, target): > > > ? ? ? ? ?""" > > > ? ? ? ? ?Changes a dns entry. > > > ? ? ? ? ?@param record: which record to chance > > > ? ? ? ? ?@param type: ?what type of record, A, MX, NS, CNAME > > > ? ? ? ? ?@target: if CNAME target points to HOSTNAME, if A record > > > ?points to IP > > > ? ? ? ? ?""" > > > ? ? ? ? ?openZoneFile(record) > > > ? ? ? ? ?try: > > > ? ? ? ? ? ? ?rdataset = zone.find_rdataset(host, rdtype=type) > > > ? ? ? ? ?except: > > > ? ? ? ? ? ? ?raise Exception("You must enter a valid record and type. > > > ?See --usage for examples") > > > > Don't catch all exceptions - find out which exceptions are thrown. > > Consider just letting it propagate - hopefully the find_rdataset error > > is descriptive enough. > > > > Thanks for taking the time to reply I appreciate it. No problems. > Are global variables "bad"? Or just inefficient? They make code a lot more difficult to follow because you have to wonder where the variable has been set. If you create multiple instances of DNSFunctions (more than likely in a multi-user server) you'll find that global variables will cause your program to go wrong quite badly! In general only ever use global variables in quick and dirty scripts. For static configuration which you might think globals are good for you can easily do that in a module namespace or in a Config object which you only have one of. > Also when you say: > > "Also if the dns.zone.from_file didn't work (raises dns.exception) you > set the host and domain but the zone is left at its previous value > which probably isn't what you wanted. I'd let the error propagate > which I think will do something sensible for the xmlrpc." > > Could you elaborate on that. Im not following what you mean by > "propagate" I mean don't catch the exception. If you raise an exception while in an RPC it will get propagated back to the client which is exactly what you want. Eg, run this in one window import SimpleXMLRPCServer class SimpleTest: def divide(self, x, y): """Does an integer divide""" print "About to divide %r by %r" % (x, y) return x // y server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8000)) server.register_instance(SimpleTest()) server.serve_forever() And this in another import xmlrpclib server = xmlrpclib.Server('http://localhost:8000') print server.divide(6, 3) print server.divide(6, 2) print server.divide(6, 0) The client will print 2 3 Traceback (most recent call last): File "xmlrpc_client.py", line 6, in print server.divide(6, 0) File "/usr/lib/python2.5/xmlrpclib.py", line 1147, in __call__ return self.__send(self.__name, args) File "/usr/lib/python2.5/xmlrpclib.py", line 1437, in __request verbose=self.__verbose File "/usr/lib/python2.5/xmlrpclib.py", line 1201, in request return self._parse_response(h.getfile(), sock) File "/usr/lib/python2.5/xmlrpclib.py", line 1340, in _parse_response return u.close() File "/usr/lib/python2.5/xmlrpclib.py", line 787, in close raise Fault(**self._stack[0]) xmlrpclib.Fault: :integer division or modulo by zero"> Whereas the server will keep running with About to divide 6 by 3 localhost - - [04/Feb/2009 09:01:56] "POST /RPC2 HTTP/1.0" 200 - About to divide 6 by 2 localhost - - [04/Feb/2009 09:01:56] "POST /RPC2 HTTP/1.0" 200 - About to divide 6 by 0 localhost - - [04/Feb/2009 09:01:56] "POST /RPC2 HTTP/1.0" 200 - So in general if the error is caused by the client, send it back to the client by not catching it in the server. The server will keep running and the client will know it has done something wrong. -- Nick Craig-Wood -- http://www.craig-wood.com/nick From nick at craig-wood.com Wed Feb 4 04:31:59 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Wed, 04 Feb 2009 03:31:59 -0600 Subject: Cross platform compilation? References: Message-ID: Christian Heimes wrote: > John Harper schrieb: > > I am trying to build Python to use in an embedded system which uses a > > ppc_440 CPU. The only information I've found is something written by > > Klaus Reimer a few years ago, which was based on Python 2.2. So far I > > seem to have successfully built Python itself, but building the > > extensions fails miserably with complaints about library format. It > > insists on referring to "i686" which is indeed the platform it is > > actually running on. > > > > Before I try to reverse engineer completely setup.py, is there > > something obvious that needs to be done to get it to use the right tool > > chain? I spent some time mucking about trying to do this for ARM. I almost got it to work using qemu but not quite! What I did in the end was to use a pre-compiled python (from debian) then copy the headers and library files into the cross compiling environment so we could embed python into our code and build our extensions. > > More generally, it seems like this would be something that lots of > > people would want to do. I'm surprised there isn't support for it built > > into the distributed version of Python, without having to hack all the > > setup files...? > > I'm sorry to inform you that Python doesn't support cross platform > compilation. Python eats its own dog food and uses Python to compile > optional extension modules. It isn't an impossible problem... If you've ever cross compiled gcc you'll find that it first uses the host compiler (possibly not gcc) to compile itself to make a gcc which runs on the host but makes code for the target. It then uses that new compiler to compile a gcc for the target architecture. I could imagine a similar scheme for python, but it would involve lots of fiddling about and some commitment from the python maintainers. -- Nick Craig-Wood -- http://www.craig-wood.com/nick From clp2 at rebertia.com Wed Feb 4 04:43:37 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 4 Feb 2009 01:43:37 -0800 Subject: subprocess.Popen - file like object from stdout=PIPE In-Reply-To: <49895e45$0$2860$ba620e4c@news.skynet.be> References: <49895e45$0$2860$ba620e4c@news.skynet.be> Message-ID: <50697b2c0902040143p66b4e2dfy7ba53e8a8397a020@mail.gmail.com> On Wed, Feb 4, 2009 at 1:22 AM, Helmut Jarausch wrote: > Hi, > > using e.g. > import subprocess > Package='app-arch/lzma-utils' > EQ=subprocess.Popen(['/usr/bin/equery','depends',Package],stdout=subprocess.PIPE) > EQ_output= EQ.communicate()[0] > > EQ_output is a string containing multiple lines. > > I'd prefer a file-like object, e.g. EQ_OUT > so that I can loop over the lines of it like > > for line in EQ_OUT : > ... Is there some reason that: for line in EQ_OUT.splitlines(): #... Does not meet your needs? Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From skippy.hammond at gmail.com Wed Feb 4 04:43:40 2009 From: skippy.hammond at gmail.com (Mark Hammond) Date: Wed, 04 Feb 2009 20:43:40 +1100 Subject: How to call python from a foreign language thread (C++) In-Reply-To: References: Message-ID: <4989634C.4020108@gmail.com> On 4/02/2009 4:51 AM, Victor Lin wrote: > It may looks like this. > > void operator() (double time, const AudioData&data) { > // acquire lock > m_Function(time, data); > // release lock > } You want something like: void operator() (double time, const AudioData&data) { PyGILState_STATE old = PyGILState_Acquire(); m_Function(time, data); PyGILState_Release(old); Note that Phillip is also correct; you will need to initialize threading if this is an app which embeds Python... HTH, Mark From Scott.Daniels at Acm.Org Wed Feb 4 04:43:58 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 04 Feb 2009 01:43:58 -0800 Subject: Load / Reload module In-Reply-To: <73783af1-803d-4baf-b428-85682c476e2f@w24g2000prd.googlegroups.com> References: <73783af1-803d-4baf-b428-85682c476e2f@w24g2000prd.googlegroups.com> Message-ID: Marius Butuc wrote: > I want do declare some classes (classes.py) in an external editor, > than import the file and use the classes. After I change the file, I > want to reload the definitions w/o leaving the interactive > interpreter. > > So far I have tried > - import classes # doesn't import my classes Use this and refer to the class from the imported module. import classes instance = classes.SomeClass() ... reload(classes) instance = classes.SomeClass() This is by far the best way, but if you _must_, from classes import * instance = SomeClass() ... reload(classes) from classes import * instance = SomeClass() --Scott David Daniels Scott.Daniels at Acm.Org From skippy.hammond at gmail.com Wed Feb 4 04:49:14 2009 From: skippy.hammond at gmail.com (Mark Hammond) Date: Wed, 04 Feb 2009 20:49:14 +1100 Subject: How to call python from a foreign language thread (C++) In-Reply-To: <4989634C.4020108@gmail.com> References: <4989634C.4020108@gmail.com> Message-ID: <4989649A.1000802@gmail.com> On 4/02/2009 8:43 PM, I wrote: > PyGILState_STATE old = PyGILState_Acquire(); Make that PyGILState_Ensure(); Mark From andrew at acooke.org Wed Feb 4 05:03:38 2009 From: andrew at acooke.org (andrew cooke) Date: Wed, 4 Feb 2009 02:03:38 -0800 (PST) Subject: Locating python References: <3eb685e5-dc80-41d0-acc2-2cafe0cb65c5@e18g2000yqo.googlegroups.com> <6827582d-26ce-4245-88dd-d24955dc9f3a@x16g2000prn.googlegroups.com> Message-ID: <1e7b7458-26f1-4ae6-b4d0-02dfbfc2cef3@l42g2000yqe.googlegroups.com> On Feb 3, 7:35?pm, David Sevilla wrote: > I am quite new to Linux, and thought that by using yast2 there would > be no user problems (I am asked for the root password). I will sudo it > to see if it solves the problem. yast asked you for the password so that easy_install could be installed correctly. you are now using "sudo easy_install" to install mnemosyne and sudo is asking for the root password. each time you install something you need to change public files on the system, and so each time you need to use root in some way. yast does this by logging in as root for you, but needs the password to do it. sudo does the same thing, but again needs the password to do it. hope that makes senses (and that this worked). andrew From bruno.42.desthuilliers at websiteburo.invalid Wed Feb 4 05:12:40 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 04 Feb 2009 11:12:40 +0100 Subject: is python Object oriented?? In-Reply-To: References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com> <003d01c98527$d9ea4ec0$0d00a8c0@hendrik> <005201c98549$d3eb74a0$0d00a8c0@hendrik> <2ed10ddd-63ac-4507-b046-0404cc85c97a@s1g2000prg.googlegroups.com> <498825f3$0$3303$426a74cc@news.free.fr> Message-ID: <49896a0b$0$3507$426a74cc@news.free.fr> Steven D'Aprano a ?crit : > On Tue, 03 Feb 2009 12:09:46 +0100, Bruno Desthuilliers wrote: > >>> I love Python, and I'm greedy and want it all: I want a dynamic, >>> easy-to- use language *and* a compiler that can protect me from myself >> That's not what compilers are for. > > So you say. While it's quite clear that a compiler for a statically typed language can catch at least some type errors, this is still not what a compiler is for. A compiler is here to compile you source code into a suitable representation for the execution environment. And FWIW, some compilers are rather weaker than Python when it comes to "protecting you from yourself". > >>> and bad data. >> I definitly fail to see how a compiler could protect you from *runtime* >> issues ??? > > I'm surprised you can't. Any time a compiler prevents an error by > detecting it at compile-time (say, attempting to store a 96-bit float > into the memory space allocated for a 32-bit int), Oh, you meant "type error". But this is a programming error, not "bad data". "bad data" is something you get (usually from the outside world) at runtime only. Well, the way I understand it, at least. > > Perhaps what you are thinking is that I meant compilers can protect you > from "all" runtime issues. That would be silly. Although, in principle, > we can get close, for some definition of "close". > > > Here's a toy function, and a specification: > > def inverse(x): > return 1.0/x > > Specification: input must be a float, output must be a float. > > Is that function correct? No, because it will raise an exception if > x==0.0. Python's compiler is dumb and will allow you to write incorrect > functions, but a smart compiler could look at that function and see that > it was incorrect. The fix would then be to change the code, or the > specification, or both. Ok, let's see. What happens if you pass 0.0 to the function as-is ? Yes, indeed, you get a runtime error. Now what happens if you add error handling to the function itself ? What will the error handler do ? Yes, raise a runtime error. So far, I don't see any gain here. No, no, don't answer yet. Sure, what you need here is a compiler that can inspect the whole code source using this function to make sure it is always properly invoked. Mmm, wait - will this work with shared libs ? I'm afraid not. Ok, so you have to change the specification to : "input must be a non-zero-float", and use the type system to define non-zero-float type. > Smart compilers turn some runtime errors into compile-time errors. Indeed. > The > earlier you catch the error, the easier it is to fix it. Indeed. > Now, that's a toy example. Languages like Ada make correctness proofs, > well, perhaps not easy, but merely difficult compared to impossible for > languages like Python. Indeed. And that's fine : if we want maximum type safety and as-possibly-proved code, we know which tool to use. Now good luck doing web development, system admin, app scripting and quite a lot of other things (well, perhaps more that 80% of ordinary application programming) in Ada. Can you understand that not everybody needs maximum type safety / correctness proof etc for all his code ? That all this "security" stuff comes with a price that may not be worth paying ? > To bring it back to private/public attributes, side-effects make > correctness proofs difficult. Modifications of attributes are side- > effects. Then use a functional language !-) > When attributes are subject to being modified by arbitrary code, > it is harder to reason about the correctness of the code: Indeed. Not the right tool, obviously. OTHO, it makes it way easier to use as glue between different, sometimes not highly compatible components. (snip) > There are two usual approaches to dealing with that problem which are > available to Python programmers: > > (1) Paranoia. Make the developer responsible for checking everything all > the time: Paranoiacs (also known as control-freaks) are not happy using Python. They usually prefer Ada or, at least, Java. > def invert(self): > x = self.x > if isinstance(x, float) and x: > return 1.0/self.x > else: > raise MyError('post-condition x a non-zero float violated') The correct solution is indeed to make x a property with a sanity check in the setter - in which case you'll have a useful traceback - or as a read-only property, or even better to just declare it as implementation (naming it _x). > > (2) Hope the error never occurs, and if it does, let the caller deal with > it. If the attribute is either a read-only property or an implementation attribute, then the guy that messed with it is responsible for the possible consequences. That's the contract, yes. > Hopefully you aren't your own caller. I'm usually the first user of my own libs, and my coworkers comes immediatly after. IOW, I eat my own dogfood, thanks. > That's often the Python approach. As I explained above, the "Python approach" is actually a bit different. In your example code, you explicitely declared x as a *public* attribute. Which is not wise - whatever the language - if you have to maintain invariants on this attribute. Make it either an implementation attribute or a read-only property. (snip usual stuff about nuclear disasters, x-ray-overdosed patients etc) > There is a third strategy, sadly not available to Python programmers: > prevention by catching potential errors at compile-time. (Python does > catch some errors at compile-time, but only syntax errors.) Yes. Because *everything* else happens at runtime. Remember, even "def" and "class" are executable statements. > If x can only > be modified in a few places, (that is, it is effectively hidden or > private) then it is much easier to reason about program correctness, > avoid bugs, and debug those bugs which do occur. Would you then say that Ruby has "real privates" attributes ? > No, this is not a panacea which will prevent every imaginable bug. Indeed. > Nor is > it a replacement for unit-testing (which also does not prevent every > imaginable bug). Neither. From thorsten at thorstenkampe.de Wed Feb 4 05:14:55 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Wed, 4 Feb 2009 11:14:55 +0100 Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com> <003d01c98527$d9ea4ec0$0d00a8c0@hendrik> <005201c98549$d3eb74a0$0d00a8c0@hendrik> <2ed10ddd-63ac-4507-b046-0404cc85c97a@s1g2000prg.googlegroups.com> <4ec8770b-631f-492b-be7a-27bb8ac47afc@i20g2000prf.googlegroups.com> <11ee7ba4-12f2-4744-80af-315dbea78cd9@r41g2000prr.googlegroups.com> Message-ID: * Russ P. (Tue, 3 Feb 2009 21:04:30 -0800 (PST)) > Imagine you own a company, and you decide to lease an office building. > Would you expect the office doors to have locks on them? Oh, you > would? Why? You mean you don't "trust" your co-workers? What are locks > but enforced access restriction? > > What people like you are saying is that you don't need no stinkin' > locks because your co-workers are all "consenting adults" whom you > trust. Actually, you're saying even more than that. You're saying that > office doors never need locks, because everyone should trust their co- > workers. All you need is a "keep-out" sign on the door (leading > underscores). And you are presenting as evidence for your position the > fact that people occasionally get locked out of an office that they > need to get into. > > I'm saying, fine, if you trust your co-workers, then keep the doors > unlocked, but please don't insist that office doors come without > locks. Yes, locks occasionally cause inconvenience, but they serve a > very useful purpose if used properly. This analogy is not adequate. If someone uses your library then it is his office and nothing can stop him. Someone else gave a better analogy with a device that says that the warranty is lost if you open it. And that's exactly the same with the underscore convention. Thorsten From robin at reportlab.com Wed Feb 4 05:14:56 2009 From: robin at reportlab.com (Robin Becker) Date: Wed, 04 Feb 2009 10:14:56 +0000 Subject: x64 speed In-Reply-To: <4988BAE8.2060204@v.loewis.de> References: <4988a1f1$0$3390$9b622d9e@news.freenet.de> <4988B615.4060206@jessikat.plus.net> <4988BAE8.2060204@v.loewis.de> Message-ID: <49896AA0.2050202@chamonix.reportlab.co.uk> Martin v. L?wis wrote: >>> I follow David's guess that Linux does better IO than Windows (not >>> knowing anything about the benchmark, of course) >>> >> I originally thought it must be the vmware host stuff offloading IO to >> the second core, but watching with sysinternals didn't show a lot of >> extra stuff going on with the vm compared to just running on the host. > > I'm not talking about vmware. I'm suggesting that Linux ext3, and the > Linux buffer handling, is just more efficient than NTFS, and the Windows > buffer handling. > > If you split the total runtime into system time and user time, how do > the 30s split up? ....... so here is one for the vm clock is bad theorists :) > [rptlab at localhost tests]$ time python25 runAll.py > ............................................................. ......................... > ---------------------------------------------------------------------- > Ran 193 tests in 27.841s > > OK > > real 0m28.150s > user 0m26.606s > sys 0m0.917s > [rptlab at localhost tests]$ magical how the total python time is less than the real time. -- Robin Becker From robin at reportlab.com Wed Feb 4 05:14:56 2009 From: robin at reportlab.com (Robin Becker) Date: Wed, 04 Feb 2009 10:14:56 +0000 Subject: x64 speed In-Reply-To: <4988BAE8.2060204@v.loewis.de> References: <4988a1f1$0$3390$9b622d9e@news.freenet.de> <4988B615.4060206@jessikat.plus.net> <4988BAE8.2060204@v.loewis.de> Message-ID: <49896AA0.2050202@chamonix.reportlab.co.uk> Martin v. L?wis wrote: >>> I follow David's guess that Linux does better IO than Windows (not >>> knowing anything about the benchmark, of course) >>> >> I originally thought it must be the vmware host stuff offloading IO to >> the second core, but watching with sysinternals didn't show a lot of >> extra stuff going on with the vm compared to just running on the host. > > I'm not talking about vmware. I'm suggesting that Linux ext3, and the > Linux buffer handling, is just more efficient than NTFS, and the Windows > buffer handling. > > If you split the total runtime into system time and user time, how do > the 30s split up? ....... so here is one for the vm clock is bad theorists :) > [rptlab at localhost tests]$ time python25 runAll.py > ............................................................. ......................... > ---------------------------------------------------------------------- > Ran 193 tests in 27.841s > > OK > > real 0m28.150s > user 0m26.606s > sys 0m0.917s > [rptlab at localhost tests]$ magical how the total python time is less than the real time. -- Robin Becker From nick at craig-wood.com Wed Feb 4 05:31:58 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Wed, 04 Feb 2009 04:31:58 -0600 Subject: MySQLdb and MySQL stored functions References: <0fef1833-2dae-44d2-a719-9a036ca0907c@l37g2000vba.googlegroups.com> Message-ID: kurt.forrester.fec at googlemail.com wrote: > Any ideas on how to suppress the warning output: > __main__:1: Warning: No data - zero rows fetched, selected, or > processed You can use the warnings module to suppress these I would have thought. -- Nick Craig-Wood -- http://www.craig-wood.com/nick From jarausch at skynet.be Wed Feb 4 05:48:42 2009 From: jarausch at skynet.be (Helmut Jarausch) Date: Wed, 04 Feb 2009 11:48:42 +0100 Subject: subprocess.Popen - file like object from stdout=PIPE In-Reply-To: References: <49895e45$0$2860$ba620e4c@news.skynet.be> Message-ID: <49897289$0$2855$ba620e4c@news.skynet.be> Chris Rebert wrote: > On Wed, Feb 4, 2009 at 1:22 AM, Helmut Jarausch wrote: >> Hi, >> >> using e.g. >> import subprocess >> Package='app-arch/lzma-utils' >> EQ=subprocess.Popen(['/usr/bin/equery','depends',Package],stdout=subprocess.PIPE) >> EQ_output= EQ.communicate()[0] >> >> EQ_output is a string containing multiple lines. >> >> I'd prefer a file-like object, e.g. EQ_OUT >> so that I can loop over the lines of it like >> >> for line in EQ_OUT : >> ... > > Is there some reason that: > > for line in EQ_OUT.splitlines(): > #... > > Does not meet your needs? > It works, but it still reads the complete output of the command executed by Popen at once. Helmut. -- Helmut Jarausch Lehrstuhl fuer Numerische Mathematik RWTH - Aachen University D 52056 Aachen, Germany From __peter__ at web.de Wed Feb 4 05:49:55 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 04 Feb 2009 11:49:55 +0100 Subject: Load / Reload module References: <73783af1-803d-4baf-b428-85682c476e2f@w24g2000prd.googlegroups.com> Message-ID: Scott David Daniels wrote: > Marius Butuc wrote: >> I want do declare some classes (classes.py) in an external editor, >> than import the file and use the classes. After I change the file, I >> want to reload the definitions w/o leaving the interactive >> interpreter. >> >> So far I have tried >> - import classes # doesn't import my classes > Use this and refer to the class from the imported module. > > import classes > instance = classes.SomeClass() > ... > reload(classes) > instance = classes.SomeClass() > > This is by far the best way, but if you _must_, > from classes import * > instance = SomeClass() > ... > reload(classes) > from classes import * > instance = SomeClass() Also note that only instances created after the reload will have the new layout: >>> import classes >>> a = classes.SomeClass() >>> print a old >>> open("classes.py", "w").write("""class SomeClass: ... def __str__(self): return 'new' ... """) >>> reload(classes) >>> b = classes.SomeClass() >>> print b new >>> print a old Sometimes you may be able to fix this manually by assigning to the __class__: >>> a.__class__ = classes.SomeClass >>> print a new but I recommend that you put all your code into a another script rather than resorting to such tricks $ cat main.py import classes a = classes.SomeClass() If you want to experiment with a in the interactive interpreter you can invoke main with the -i option: $ python -i main.py >>> print a new Peter From tino at wildenhain.de Wed Feb 4 06:31:33 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Wed, 04 Feb 2009 12:31:33 +0100 Subject: Locating python In-Reply-To: <1e7b7458-26f1-4ae6-b4d0-02dfbfc2cef3@l42g2000yqe.googlegroups.com> References: <3eb685e5-dc80-41d0-acc2-2cafe0cb65c5@e18g2000yqo.googlegroups.com> <6827582d-26ce-4245-88dd-d24955dc9f3a@x16g2000prn.googlegroups.com> <1e7b7458-26f1-4ae6-b4d0-02dfbfc2cef3@l42g2000yqe.googlegroups.com> Message-ID: <49897C95.1000301@wildenhain.de> andrew cooke wrote: > On Feb 3, 7:35 pm, David Sevilla wrote: >> I am quite new to Linux, and thought that by using yast2 there would >> be no user problems (I am asked for the root password). I will sudo it >> to see if it solves the problem. > > yast asked you for the password so that easy_install could be > installed correctly. > > you are now using "sudo easy_install" to install mnemosyne and sudo is > asking for the root password. > > each time you install something you need to change public files on the > system, and so each time you need to use root in some way. yast does > this by logging in as root for you, but needs the password to do it. > sudo does the same thing, but again needs the password to do it. > > hope that makes senses (and that this worked). actually "su" needs the root (or the target users') password and sudo needs _your_ (the current users) password. HTH Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From simon at brunningonline.net Wed Feb 4 06:37:26 2009 From: simon at brunningonline.net (Simon Brunning) Date: Wed, 4 Feb 2009 11:37:26 +0000 Subject: v 3.0 mpkg In-Reply-To: <2E75ECDE-6B15-471F-8747-ED4616EF4847@talktalk.net> References: <2E75ECDE-6B15-471F-8747-ED4616EF4847@talktalk.net> Message-ID: <8c7f10c60902040337q617a37bfr9ec937b38e433fa9@mail.gmail.com> 2009/2/4 John Forse : > Does anyone know if Python v3.0 is available as an .mpkg installer for Mac > 10.5.6. I have used 2.5 & updated to 2.6.1 this way, but can't find any > reference to one on the Python.org download site. I've downloaded the Python > 3.0 folder but can't follow how to install it without a .mpkg file. Any help > would be really appreciated. AFAIK there's no Python 3.0 installer for the Mac. You'll have to build it yourself - see . -- Cheers, Simon B. From noama at answers.com Wed Feb 4 06:40:59 2009 From: noama at answers.com (Noam Aigerman) Date: Wed, 4 Feb 2009 13:40:59 +0200 Subject: Kill a function while it's being executed In-Reply-To: <49897C95.1000301@wildenhain.de> References: <3eb685e5-dc80-41d0-acc2-2cafe0cb65c5@e18g2000yqo.googlegroups.com><6827582d-26ce-4245-88dd-d24955dc9f3a@x16g2000prn.googlegroups.com><1e7b7458-26f1-4ae6-b4d0-02dfbfc2cef3@l42g2000yqe.googlegroups.com> <49897C95.1000301@wildenhain.de> Message-ID: <749CACF29BDFB64E9F80189ECD77868804C00682@jermail1.atomant.net> Hi All, I have a script in which I receive a list of functions. I iterate over the list and run each function. This functions are created by some other user who is using the lib I wrote. Now, there are some cases in which the function I receive will never finish (stuck in infinite loop). Suppose I use a thread which times the amount of time passed since the function has started, Is there some way I can kill the function after a certain amount of time has passed (without asking the user who's giving me the list of functions to make them all have some way of notifying them to finish)? Thanks, Noam From nosklo at gmail.com Wed Feb 4 07:06:58 2009 From: nosklo at gmail.com (Clovis Fabricio) Date: Wed, 4 Feb 2009 10:06:58 -0200 Subject: subprocess.Popen - file like object from stdout=PIPE In-Reply-To: <49895e45$0$2860$ba620e4c@news.skynet.be> References: <49895e45$0$2860$ba620e4c@news.skynet.be> Message-ID: <9187a60d0902040406s7d1e5da1l44ee57abf0e6c8e@mail.gmail.com> 2009/2/4 Helmut Jarausch : > using e.g. > import subprocess > Package='app-arch/lzma-utils' > EQ=subprocess.Popen(['/usr/bin/equery','depends',Package],stdout=subprocess.PIPE) > EQ_output= EQ.communicate()[0] > EQ_output is a string containing multiple lines. > I'd prefer a file-like object, e.g. EQ_OUT > so that I can loop over the lines of it like EQ.stdout is the filelike object you're looking for. communicate() grabs entire output at once so don't use it. import subprocess Package = 'app-arch/lzma-utils' EQ = subprocess.Popen(['/usr/bin/equery', 'depends', Package], stdout=subprocess.PIPE) for line in EQ.stdout: do_stuff_with(line) From kareta at web.de Wed Feb 4 07:12:51 2009 From: kareta at web.de (Juergen Kareta) Date: Wed, 04 Feb 2009 13:12:51 +0100 Subject: python libpcap equivalent In-Reply-To: References: Message-ID: <6utf23Fh6fakU1@mid.individual.net> Gabriel schrieb: > Hello > > I need to write a software router [yes, software equivalent to a > hardware box that is routing packets .)]. It's a school > work.. > Question is: is possible write this kind of application in python? and > if it's, what module should i use? > I tried search for some libpcap equivalent in python and found > pylibpcap, but can't find documentation and tutorial. Hello Gabriel, you might look into scapy: http://www.secdev.org/projects/scapy/ which easily allows you to fetch, manipulate and send network packages. J?rgen From jarausch at skynet.be Wed Feb 4 07:13:03 2009 From: jarausch at skynet.be (Helmut Jarausch) Date: Wed, 04 Feb 2009 13:13:03 +0100 Subject: subprocess.Popen - file like object from stdout=PIPE In-Reply-To: References: <49895e45$0$2860$ba620e4c@news.skynet.be> Message-ID: <4989864F.50700@skynet.be> Clovis Fabricio wrote: > 2009/2/4 Helmut Jarausch : >> using e.g. >> import subprocess >> Package='app-arch/lzma-utils' >> EQ=subprocess.Popen(['/usr/bin/equery','depends',Package],stdout=subprocess.PIPE) >> EQ_output= EQ.communicate()[0] >> EQ_output is a string containing multiple lines. >> I'd prefer a file-like object, e.g. EQ_OUT >> so that I can loop over the lines of it like > > EQ.stdout is the filelike object you're looking for. > communicate() grabs entire output at once so don't use it. > > import subprocess > Package = 'app-arch/lzma-utils' > EQ = subprocess.Popen(['/usr/bin/equery', 'depends', Package], > stdout=subprocess.PIPE) > for line in EQ.stdout: > do_stuff_with(line) Thanks a lot, I haven't found that in the official documentation. Helmut. -- Helmut Jarausch Lehrstuhl fuer Numerische Mathematik RWTH - Aachen University D 52056 Aachen, Germany From jarausch at skynet.be Wed Feb 4 07:13:03 2009 From: jarausch at skynet.be (Helmut Jarausch) Date: Wed, 04 Feb 2009 13:13:03 +0100 Subject: subprocess.Popen - file like object from stdout=PIPE In-Reply-To: References: <49895e45$0$2860$ba620e4c@news.skynet.be> Message-ID: <4989864F.50700@skynet.be> Clovis Fabricio wrote: > 2009/2/4 Helmut Jarausch : >> using e.g. >> import subprocess >> Package='app-arch/lzma-utils' >> EQ=subprocess.Popen(['/usr/bin/equery','depends',Package],stdout=subprocess.PIPE) >> EQ_output= EQ.communicate()[0] >> EQ_output is a string containing multiple lines. >> I'd prefer a file-like object, e.g. EQ_OUT >> so that I can loop over the lines of it like > > EQ.stdout is the filelike object you're looking for. > communicate() grabs entire output at once so don't use it. > > import subprocess > Package = 'app-arch/lzma-utils' > EQ = subprocess.Popen(['/usr/bin/equery', 'depends', Package], > stdout=subprocess.PIPE) > for line in EQ.stdout: > do_stuff_with(line) Thanks a lot, I haven't found that in the official documentation. Helmut. -- Helmut Jarausch Lehrstuhl fuer Numerische Mathematik RWTH - Aachen University D 52056 Aachen, Germany From andrew at acooke.org Wed Feb 4 07:16:37 2009 From: andrew at acooke.org (andrew cooke) Date: Wed, 4 Feb 2009 04:16:37 -0800 (PST) Subject: Locating python References: <3eb685e5-dc80-41d0-acc2-2cafe0cb65c5@e18g2000yqo.googlegroups.com> <6827582d-26ce-4245-88dd-d24955dc9f3a@x16g2000prn.googlegroups.com> <1e7b7458-26f1-4ae6-b4d0-02dfbfc2cef3@l42g2000yqe.googlegroups.com> Message-ID: <86d1c582-650f-487c-a5bd-16ce94a0b03a@w1g2000prk.googlegroups.com> > actually "su" needs the root (or the target users') password > and sudo needs _your_ (the current users) password. argh, sorry for the confusion. From nosklo at gmail.com Wed Feb 4 07:19:33 2009 From: nosklo at gmail.com (Clovis Fabricio) Date: Wed, 4 Feb 2009 10:19:33 -0200 Subject: subprocess.Popen - file like object from stdout=PIPE In-Reply-To: <4989864F.50700@skynet.be> References: <49895e45$0$2860$ba620e4c@news.skynet.be> <4989864F.50700@skynet.be> Message-ID: <9187a60d0902040419h3eb27695v97e336c13b5d1e30@mail.gmail.com> 2009/2/4 Helmut Jarausch : >> EQ.stdout is the filelike object you're looking for. >> communicate() grabs entire output at once so don't use it. > Thanks a lot, I haven't found that in the official documentation. > Helmut. That would be a documentation bug. Fortunately it is not true. Here is it in the documentation: http://docs.python.org/library/subprocess.html#subprocess.Popen.stdout From andrew at acooke.org Wed Feb 4 07:29:12 2009 From: andrew at acooke.org (andrew cooke) Date: Wed, 4 Feb 2009 04:29:12 -0800 (PST) Subject: Locating python References: <3eb685e5-dc80-41d0-acc2-2cafe0cb65c5@e18g2000yqo.googlegroups.com> <6827582d-26ce-4245-88dd-d24955dc9f3a@x16g2000prn.googlegroups.com> <1e7b7458-26f1-4ae6-b4d0-02dfbfc2cef3@l42g2000yqe.googlegroups.com> <86d1c582-650f-487c-a5bd-16ce94a0b03a@w1g2000prk.googlegroups.com> Message-ID: <44486906-2212-4b38-8a2f-6a941eaddf0a@u14g2000yqg.googlegroups.com> On Feb 4, 9:16?am, andrew cooke wrote: > > actually "su" needs the root (or the target users') password > > and sudo needs _your_ (the current users) password. > > argh, sorry for the confusion. actually, no. sudo requires the root password. at least on opensuse 11.1 default config. i just tried it: > Python-2.5.4: sudo make install root's password: this is explained in the sudoers file: # In the default (unconfigured) configuration, sudo asks for the root password. # This allows use of an ordinary user account for administration of a freshly # installed system. When configuring sudo, delete the two # following lines: Defaults targetpw # ask for the password of the target user i.e. root ALL ALL=(ALL) ALL # WARNING! Only use this together with 'Defaults targetpw'! andrew From jarausch at skynet.be Wed Feb 4 08:00:53 2009 From: jarausch at skynet.be (Helmut Jarausch) Date: Wed, 04 Feb 2009 14:00:53 +0100 Subject: subprocess.Popen - file like object from stdout=PIPE In-Reply-To: References: <49895e45$0$2860$ba620e4c@news.skynet.be> <4989864F.50700@skynet.be> Message-ID: <49899185$0$2861$ba620e4c@news.skynet.be> Clovis Fabricio wrote: > 2009/2/4 Helmut Jarausch : >>> EQ.stdout is the filelike object you're looking for. >>> communicate() grabs entire output at once so don't use it. >> Thanks a lot, I haven't found that in the official documentation. >> Helmut. > > That would be a documentation bug. > Fortunately it is not true. Here is it in the documentation: > > http://docs.python.org/library/subprocess.html#subprocess.Popen.stdout Thanks! For people like me which don't always read until the end of a document it would be nice if just after the paragraph stdin, stdout and stderr specify the executed programs? standard input, standard output and standard error file handles, respectively. Valid values are PIPE, an existing file descriptor (a positive integer), an existing file object, and None. PIPE indicates that a new pipe to the child should be created. With None, no redirection will occur; the child?s file handles will be inherited from the parent. Additionally, stderr can be STDOUT, which indicates that the stderr data from the applications should be captured into the same file handle as for stdout. there would some lines like These pipes are exposed as file-like objects which can be accessed via the stdin, stdout or stderr (resp.) attributes of an object of class subprocess.Popen . Please be indulgent to people like me. Helmut. -- Helmut Jarausch Lehrstuhl fuer Numerische Mathematik RWTH - Aachen University D 52056 Aachen, Germany From kyrie at uh.cu Wed Feb 4 08:27:10 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Wed, 04 Feb 2009 08:27:10 -0500 Subject: is python Object oriented?? In-Reply-To: References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com> <003d01c98527$d9ea4ec0$0d00a8c0@hendrik> <005201c98549$d3eb74a0$0d00a8c0@hendrik> <2ed10ddd-63ac-4507-b046-0404cc85c97a@s1g2000prg.googlegroups.com> <3acf1429-9aec-4e0d-b617-21cbcdf76087@w1g2000prk.googlegroups.com> Message-ID: <1233754030.498997ae36410@mail.uh.cu> Quoting "Russ P." : > > Indeed he can. He can even do that in Python; it just requires a little > > self-discipline from the team, or a validation script on the code > > repository if he really doesn't trust them. Not only can this be done > > without forcing the rest of the world to play, it makes things a little > > less daunting when those nice clean interfaces turn out to be > > incomplete/too slow/not what you thought. > > This has already been refuted several times on this thread alone, so I > will not bother doing it again. > Please, point out where, because I don't recall you explaining why is not enough to use a "validation script" on the code if you wish to. I _do_ recall you saying that you didn't want the validation script unless it is integrated with python, but I'm yet to see the difference. -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie From kyrie at uh.cu Wed Feb 4 08:35:50 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Wed, 04 Feb 2009 08:35:50 -0500 Subject: is python Object oriented?? In-Reply-To: <11ee7ba4-12f2-4744-80af-315dbea78cd9@r41g2000prr.googlegroups.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com> <003d01c98527$d9ea4ec0$0d00a8c0@hendrik> <005201c98549$d3eb74a0$0d00a8c0@hendrik> <2ed10ddd-63ac-4507-b046-0404cc85c97a@s1g2000prg.googlegroups.com> <4ec8770b-631f-492b-be7a-27bb8ac47afc@i20g2000prf.googlegroups.com> <11ee7ba4-12f2-4744-80af-315dbea78cd9@r41g2000prr.googlegroups.com> Message-ID: <1233754550.498999b6356d9@mail.uh.cu> Quoting "Russ P." : > Imagine you own a company, and you decide to lease an office building. > Would you expect the office doors to have locks on them? Oh, you > would? Why? You mean you don't "trust" your co-workers? What are locks > but enforced access restriction? This analogy is nonsense. There is no way you will execute code on my system if I don't authorize it, regardless of how "public" are the variables declared in my code. No one will execute code on _your_ system either, without your authorization. That puts you in a different position: you can easily _check_ that everything is alright before executing, whereas in the office example, it cannot be done. Of course, if the analogy is flawed in such an essential aspect, I won't even humor it. I worry, though, that you obviously believe that it is not flawed. -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie From Pat at junk.net Wed Feb 4 09:38:04 2009 From: Pat at junk.net (Pat) Date: Wed, 04 Feb 2009 09:38:04 -0500 Subject: len() References: <20090131201648.201b6ed5@usenot.de> Message-ID: Andreas Waldenburger wrote: > On Sat, 31 Jan 2009 13:27:02 -0500 Pat wrote: > >> Tobiah wrote: >>> Just out of curiosity, why was len() made to >>> be it's own function? I often find myself >>> typing things like my_list.len before I >>> catch myself. >>> >>> Thanks, >>> >>> Toby >> I'm surprised that no one responded to that question. >> > Huh? Gabriel Genellina replied about 46 minutes after it was posted. > Might it be that your newsserver is a bit laggy? > > regards > /W > Might be laggy. Who knows. Why didn't you answer the len() question? From unews at nospam.onlinehome.de Wed Feb 4 09:46:53 2009 From: unews at nospam.onlinehome.de (Uwe Grauer) Date: Wed, 04 Feb 2009 15:46:53 +0100 Subject: kinterbasdb + firebird 1.5 with python 2.6 ? In-Reply-To: References: Message-ID: Laszlo Nagy wrote: > Does anyone know how to get firebird 1.5 driver (kinterbasdb) for > FireBird 1.5? > > My problem: > > * python 2.6 already installed on a server > * there is a firebird 1.5 database on the same server > * I need to access it from python 2.6 > > Any thoughts? > > Get it from here: http://www.firebirdsql.org/index.php?op=devel&sub=python You should have mentioned your OS to get better answers. Uwe From ljjediknight at gmail.com Wed Feb 4 10:01:23 2009 From: ljjediknight at gmail.com (Luke) Date: Wed, 4 Feb 2009 07:01:23 -0800 (PST) Subject: Tkinter Message-ID: <593b7e33-f0ef-434f-b967-a4a1a102aab1@z6g2000pre.googlegroups.com> Hello, I'm an inexperienced programmer and I'm trying to make a Tkinter window and have so far been unsuccessful in being able to delete widgets from the main window and then add new ones back into the window without closing the main window. The coding looks similar to this: from Tkinter import * def MainWin(): main=Tk() main.geometry('640x480') back_ground=Frame(main,width=640,height=480,bg='black') back_ground.pack_propagate(0) back_ground.pack(side=TOP,anchor=N) frame1=Frame(back_ground,width=213,height=480,bg='light gray') frame1.pack_propagate(0) frame1.pack(side=TOP,anchor=N) close_frame1=Button(frame1,text='close',bg='light gray', command=frame1.destroy) close_frame1.pack_propagate(0) close_frame1.pack(side=TOP, anchor=N,pady=25) if frame1.destroy==True: frame1=Frame(back_ground,width=213,height=480,bg='white') frame1.pack_propagate(0) frame1.pack(side=TOP,anchor=N) main.mainloop() MainWin() It may just be bad coding but either way I could use some help. Thanks From marco at sferacarta.com Wed Feb 4 10:02:08 2009 From: marco at sferacarta.com (Marco Mariani) Date: Wed, 04 Feb 2009 16:02:08 +0100 Subject: len() In-Reply-To: References: <20090131201648.201b6ed5@usenot.de> Message-ID: Pat wrote: > Why didn't you answer the len() question? It's a bit of a FAQ: len() cannot be a method of list objects because it works on any sequence or iterable. From floris.bruynooghe at gmail.com Wed Feb 4 10:08:32 2009 From: floris.bruynooghe at gmail.com (Floris Bruynooghe) Date: Wed, 4 Feb 2009 07:08:32 -0800 (PST) Subject: x64 speed References: <4988a1f1$0$3390$9b622d9e@news.freenet.de> <4988B615.4060206@jessikat.plus.net> <4988BAE8.2060204@v.loewis.de> Message-ID: On Feb 4, 10:14?am, Robin Becker wrote: > > [rptlab at localhost tests]$ time python25 runAll.py > > ............................................................. > > ......................... > > > ---------------------------------------------------------------------- > > Ran 193 tests in 27.841s > > > OK > > > real ? ?0m28.150s > > user ? ?0m26.606s > > sys ? ? 0m0.917s > > [rptlab at localhost tests]$ > > magical how the total python time is less than the real time. Not really. Python was still running at the time that it prints the time of the tests. So it's only natural that the wall time Python prints on just the tests is going to be smaller then the wall time time prints for the entire python process. Same for when it starts, some stuff is done in Python before it starts its timer. Regards Floris From tino at wildenhain.de Wed Feb 4 10:14:58 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Wed, 04 Feb 2009 16:14:58 +0100 Subject: Locating python In-Reply-To: <44486906-2212-4b38-8a2f-6a941eaddf0a@u14g2000yqg.googlegroups.com> References: <3eb685e5-dc80-41d0-acc2-2cafe0cb65c5@e18g2000yqo.googlegroups.com> <6827582d-26ce-4245-88dd-d24955dc9f3a@x16g2000prn.googlegroups.com> <1e7b7458-26f1-4ae6-b4d0-02dfbfc2cef3@l42g2000yqe.googlegroups.com> <86d1c582-650f-487c-a5bd-16ce94a0b03a@w1g2000prk.googlegroups.com> <44486906-2212-4b38-8a2f-6a941eaddf0a@u14g2000yqg.googlegroups.com> Message-ID: <4989B0F2.30107@wildenhain.de> andrew cooke wrote: > On Feb 4, 9:16 am, andrew cooke wrote: >>> actually "su" needs the root (or the target users') password >>> and sudo needs _your_ (the current users) password. >> argh, sorry for the confusion. > > actually, no. sudo requires the root password. at least on opensuse > 11.1 default config. i just tried it: > argh. This N?rnberg Windows ;-) But this shows that a sensible configuration of the system is usefull before you start installing services on it :-) Cheers Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From matt.dubins at sympatico.ca Wed Feb 4 10:21:14 2009 From: matt.dubins at sympatico.ca (inkhorn) Date: Wed, 4 Feb 2009 07:21:14 -0800 (PST) Subject: tkSimpleDialog window focus problem Message-ID: <238e1e3c-66aa-45de-9a67-2b91e15bc465@x6g2000pre.googlegroups.com> Hi all, As part of the program I've created and am maintaining, the user has to type in his/her username and password into tkinter simple dialog windows. What you'll see below is that I've nested an askstring dialog window within a call to use the ftp module to login to an FTP server. result = self.ftp.login(self.userid, tkSimpleDialog.askstring ("Password Entry", "Password:", show="*")) Annoyingly, every time this password entry window pops up, the focus does not go on it automatically. Anyone know what I can do to put the focus on it automatically, while *not* storing the user's password in my script for the remainder of its runtime? Thanks, Matt Dubins From marduk at letterboxes.org Wed Feb 4 10:25:52 2009 From: marduk at letterboxes.org (Albert Hopkins) Date: Wed, 04 Feb 2009 10:25:52 -0500 Subject: Kill a function while it's being executed In-Reply-To: <749CACF29BDFB64E9F80189ECD77868804C00682@jermail1.atomant.net> References: <3eb685e5-dc80-41d0-acc2-2cafe0cb65c5@e18g2000yqo.googlegroups.com> <6827582d-26ce-4245-88dd-d24955dc9f3a@x16g2000prn.googlegroups.com> <1e7b7458-26f1-4ae6-b4d0-02dfbfc2cef3@l42g2000yqe.googlegroups.com> <49897C95.1000301@wildenhain.de> <749CACF29BDFB64E9F80189ECD77868804C00682@jermail1.atomant.net> Message-ID: <1233761152.373.14.camel@localhost.localdomain> On Wed, 2009-02-04 at 13:40 +0200, Noam Aigerman wrote: > Hi All, > I have a script in which I receive a list of functions. I iterate over > the list and run each function. This functions are created by some other > user who is using the lib I wrote. Now, there are some cases in which > the function I receive will never finish (stuck in infinite loop). > Suppose I use a thread which times the amount of time passed since the > function has started, Is there some way I can kill the function after a > certain amount of time has passed (without asking the user who's giving > me the list of functions to make them all have some way of notifying > them to finish)? > Thanks, Noam Noam, did you hijack a thread? You could decorate the functions with a timeout function. Here's one that I either wrote or copied from a recipe (can't recall): class FunctionTimeOut(Exception): pass def function_timeout(seconds): """Function decorator to raise a timeout on a function call""" import signal def decorate(f): def timeout(signum, frame): raise FunctionTimeOut() def funct(*args, **kwargs): old = signal.signal(signal.SIGALRM, timeout) signal.alarm(seconds) try: result = f(*args, **kwargs) finally: signal.signal(signal.SIGALRM, old) signal.alarm(0) return result return funct return decorate Then func_dec = function_timeout(TIMEOUT_SECS) for func in function_list: timeout_function = func_dec(func) try: timeout_function(...) except FunctionTimeout: ... -a From Russ.Paielli at gmail.com Wed Feb 4 10:53:54 2009 From: Russ.Paielli at gmail.com (Russ P.) Date: Wed, 4 Feb 2009 07:53:54 -0800 (PST) Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com> <003d01c98527$d9ea4ec0$0d00a8c0@hendrik> <005201c98549$d3eb74a0$0d00a8c0@hendrik> <2ed10ddd-63ac-4507-b046-0404cc85c97a@s1g2000prg.googlegroups.com> <4ec8770b-631f-492b-be7a-27bb8ac47afc@i20g2000prf.googlegroups.com> <11ee7ba4-12f2-4744-80af-315dbea78cd9@r41g2000prr.googlegroups.com> Message-ID: On Feb 4, 5:35?am, Luis Zarrabeitia wrote: > Quoting "Russ P." : > > > Imagine you own a company, and you decide to lease an office building. > > Would you expect the office doors to have locks on them? Oh, you > > would? Why? You mean you don't "trust" your co-workers? What are locks > > but enforced access restriction? > > This analogy is nonsense. There is no way you will execute code on my system if > I don't authorize it, regardless of how "public" are the variables declared in > my code. No one will execute code on _your_ system either, without your > authorization. That puts you in a different position: you can easily _check_ > that everything is alright before executing, whereas in the office example, it > cannot be done. I don't follow your point, but I think you are reading too much into the analogy. Obviously, an office building cannot be "copied" in a few seconds as a software library can, so the analogy obviously cannot be taken too far. The locks on the doors are analogous to enforced access restrictions. When you lease the building, you are presumably given a complete set of keys, including master keys. The keys are analogous to the source code, which allows you to trivially disable the access restrictions. People like you are saying that keys are not enough. You don't want to be bothered with keys. You want the office doors to come with no locks on them at all, because you don't intend to lock them anyway, and someone could possibly get locked out someday. You are saying that locks are unnecessary because you trust your co-workers (aren't you lucky!), and you can just put "keep-out" signs on the doors (leading underscores). Well, that may be reasonable for a small group of developers working on a small, "cool" project. It is inappropriate, however, for a large, safety-critical project with dozens or hundreds of developers that are hired off the street in accordance with current labor laws. Now, if you concede that Python is just not intended for such projects, then fine, but please don't claim that access restrictions are useless for all applications and domains. That's just ridiculous. From noama at answers.com Wed Feb 4 10:54:09 2009 From: noama at answers.com (Noam Aigerman) Date: Wed, 4 Feb 2009 17:54:09 +0200 Subject: Kill a function while it's being executed In-Reply-To: <1233761152.373.14.camel@localhost.localdomain> References: <3eb685e5-dc80-41d0-acc2-2cafe0cb65c5@e18g2000yqo.googlegroups.com><6827582d-26ce-4245-88dd-d24955dc9f3a@x16g2000prn.googlegroups.com><1e7b7458-26f1-4ae6-b4d0-02dfbfc2cef3@l42g2000yqe.googlegroups.com><49897C95.1000301@wildenhain.de><749CACF29BDFB64E9F80189ECD77868804C00682@jermail1.atomant.net> <1233761152.373.14.camel@localhost.localdomain> Message-ID: <749CACF29BDFB64E9F80189ECD77868804C0072C@jermail1.atomant.net> About the hijacking - I *might* have done it without understanding what I did (replied to a previous message and then changed the subject), if that's what you mean... Sorry -----Original Message----- From: python-list-bounces+noama=answers.com at python.org [mailto:python-list-bounces+noama=answers.com at python.org] On Behalf Of Albert Hopkins Sent: Wednesday, February 04, 2009 5:26 PM To: python-list at python.org Subject: Re: Kill a function while it's being executed On Wed, 2009-02-04 at 13:40 +0200, Noam Aigerman wrote: > Hi All, > I have a script in which I receive a list of functions. I iterate over > the list and run each function. This functions are created by some other > user who is using the lib I wrote. Now, there are some cases in which > the function I receive will never finish (stuck in infinite loop). > Suppose I use a thread which times the amount of time passed since the > function has started, Is there some way I can kill the function after a > certain amount of time has passed (without asking the user who's giving > me the list of functions to make them all have some way of notifying > them to finish)? > Thanks, Noam Noam, did you hijack a thread? You could decorate the functions with a timeout function. Here's one that I either wrote or copied from a recipe (can't recall): class FunctionTimeOut(Exception): pass def function_timeout(seconds): """Function decorator to raise a timeout on a function call""" import signal def decorate(f): def timeout(signum, frame): raise FunctionTimeOut() def funct(*args, **kwargs): old = signal.signal(signal.SIGALRM, timeout) signal.alarm(seconds) try: result = f(*args, **kwargs) finally: signal.signal(signal.SIGALRM, old) signal.alarm(0) return result return funct return decorate Then func_dec = function_timeout(TIMEOUT_SECS) for func in function_list: timeout_function = func_dec(func) try: timeout_function(...) except FunctionTimeout: ... -a -- http://mail.python.org/mailman/listinfo/python-list From how at about.no.com Wed Feb 4 10:55:32 2009 From: how at about.no.com (eviljonny) Date: 04 Feb 2009 15:55:32 GMT Subject: wsdl2py/ZSI and complex types with arrays Message-ID: <4989ba74$0$24592$da0feed9@news.zen.co.uk> Hello all, I have been trying to write a web service using ZSI with wsdl2py. I have read 'The Zolera Soap Infrastructure User?s Guide Release 2.0.0' and some older guides (a guide by Nortel called Using ZSI with wsdl2py) and am unable to find any working examples of how to use arrays in complex types. I have a Request method which takes an array as an argument and responds with an array. Assume I am just trying to write a client at this point. I have tried a lot of variations on this and can get a call made but using a tracefile the element SOIID is always empty no matter what I do. Please excuse me if the code is not fantastic. I am very new to python. #--------------------------------------- from GraphingReporter_services import * from GraphingReporter_services_types import * loc = GraphingReporterLocator() fp = file("/tmp/PYTHON-TRACE","w") port = loc.getGraphingReporterPort(tracefile=fp) request = GraphRequestSOIID() graphRequest = request.new_soiid() graphRequest.Soiid = [123456,123457] request.set_element_soiid(graphRequest) response = port.GetGraphsForSOIID(request) fp.close() #--------------------------------------- The outgoing call in the trace shows #--------------------------------------- #--------------------------------------- Can anyone provide me an example (or a link to an example) of how to populate the arrays in complex types? Even pointing me in the right direction would be wonderful. -- EvilJonny From nospam at nospam.com Wed Feb 4 11:08:45 2009 From: nospam at nospam.com (Gilles Ganault) Date: Wed, 04 Feb 2009 17:08:45 +0100 Subject: [Web 2.0] Added-value of frameworks? Message-ID: Hello If I wanted to build some social web site such as Facebook, what do frameworks like Django or TurboGears provide over writing a site from scratch using Python? Thank you for your feedback. From nospam at nospam.com Wed Feb 4 11:11:07 2009 From: nospam at nospam.com (Gilles Ganault) Date: Wed, 04 Feb 2009 17:11:07 +0100 Subject: [2.5.1] Comparing dates? References: <87bptl1a4l.fsf@benfinney.id.au> <5tkdo4l21dkm9kgv4ra4pftker89odebfu@4ax.com> Message-ID: On Mon, 2 Feb 2009 22:00:53 +0100, Martin wrote: >as suggested, the DBA should seriously think about defining the >correct type of the column here, for intermediate use and getting >stuff to work you could use a view and define some stored procedures >on it so that inserting properly works... Right, but SQLite only has two types: Numeric or text, so I figured it'd be better to turn dates into the usual YYYY-MM-DD before saving data into an SQLite file. Thanks for the feedback. From tino at wildenhain.de Wed Feb 4 11:19:13 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Wed, 04 Feb 2009 17:19:13 +0100 Subject: len() In-Reply-To: References: <20090131201648.201b6ed5@usenot.de> Message-ID: <4989C001.5040102@wildenhain.de> Marco Mariani wrote: > Pat wrote: > >> Why didn't you answer the len() question? > > It's a bit of a FAQ: len() cannot be a method of list objects because it > works on any sequence or iterable. Thats only half of the truth :-) len() can use some internal optimizations on certain objects where sequences indeed have a len() method called __len__() Regards Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From vincent at vincentdavis.net Wed Feb 4 11:24:00 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Wed, 4 Feb 2009 09:24:00 -0700 Subject: Use list name as string Message-ID: <77e831100902040824q2a0b8465k4894f29ed4baba12@mail.gmail.com> Do to laking knowledge my google searches have not turned up an answer for me. I know this is wrong it uses the items in the list as the filename, how do I refer to the dataname and not the items in it. def savedata(dataname): filename = str(dataname) # this does not do what I would like it to ext1 = '\.csv' flex = filename + ext1 datawrite = csv.writer(open(flex, "wb")) datawrite.writerows(dataname) Thanks Vincent Davis From mccredie at gmail.com Wed Feb 4 11:30:38 2009 From: mccredie at gmail.com (Matimus) Date: Wed, 4 Feb 2009 08:30:38 -0800 (PST) Subject: Added-value of frameworks? References: Message-ID: <98d0397d-f707-4c09-94ad-11427d94930f@l33g2000pri.googlegroups.com> On Feb 4, 8:08?am, Gilles Ganault wrote: > Hello > > If I wanted to build some social web site such as Facebook, what do > frameworks like Django or TurboGears provide over writing a site from > scratch using Python? > > Thank you for your feedback. Why not just look at the frameworks themselves and see what they have to offer. Django and Turbogears both have pretty good tutorials. You can be up and running in 20 minutes with each one. You be the judge. The frameworks provide a lot of boilerplate code that I would rather not write. They are probably more secure and scalable than something I would come up with. You also get many extras for free. I think in both of the frameworks you mention you get an administrative back end for free. Other people have created apps/plugins that you can use with those frameworks. So, for example, you might be able to borrow the code to help you add a forum to your site. I'm not sure I know the advantage of not using a framework. Unless "I get to write more code" is an advantage. Creating your own framework might be fun, but if you really just want a website don't do more work than you need to. Matt From gherron at islandtraining.com Wed Feb 4 11:35:32 2009 From: gherron at islandtraining.com (Gary Herron) Date: Wed, 04 Feb 2009 08:35:32 -0800 Subject: Use list name as string In-Reply-To: <77e831100902040824q2a0b8465k4894f29ed4baba12@mail.gmail.com> References: <77e831100902040824q2a0b8465k4894f29ed4baba12@mail.gmail.com> Message-ID: <4989C3D4.4070303@islandtraining.com> Vincent Davis wrote: > Do to laking knowledge my google searches have not turned up an answer for me. > I know this is wrong it uses the items in the list as the filename, > how do I refer to the dataname and not the items in it. > > def savedata(dataname): > filename = str(dataname) # this does not do what I would like it to > ext1 = '\.csv' > flex = filename + ext1 > datawrite = csv.writer(open(flex, "wb")) > datawrite.writerows(dataname) > > I need more information to answer this question -- because I have no idea what the question means. SO: What is dataname? What would you like filename to be after that line. One example of dataname and the desired filename is probably enough to answer your question. > Thanks > Vincent Davis > -- > http://mail.python.org/mailman/listinfo/python-list > From catherine.heathcote at gmail.com Wed Feb 4 11:47:04 2009 From: catherine.heathcote at gmail.com (Catherine Heathcote) Date: Wed, 04 Feb 2009 16:47:04 GMT Subject: Couple of noobish question Message-ID: Firstly hi, I don't know any of you yet but am picking up Python and will be lurking here a lot lol. I am a hobbiest coder (did 3 out of 4 years of a comp tech degree, long story) and am learning Python, 'cos I saw some code and it just looks a really nice language to work with. I come from C++, so I am bound to trip up trying to do things the wrong way! I have been working with Project Euler to get the hang of Python, and all goes well. I have an idea for a small project, an overly simplistic interactive fiction engine (well more like those old choose your own adventure books, used to love those!) that uses XML for its map files. The main issues I see so far is the XML parsing (I should pick that up ok, I have a blackbelt in google-foo), but more importantly splitting code files. In C++ I would obviously split .cpp and .h files, pairing them up and using #include. How do I do this in Python? I see that you don't tend to split logic from defenition, but how do I keep different classes in different files? My google-fu fails me so far. From python.list at tim.thechases.com Wed Feb 4 11:48:16 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 04 Feb 2009 10:48:16 -0600 Subject: Use list name as string In-Reply-To: <77e831100902040824q2a0b8465k4894f29ed4baba12@mail.gmail.com> References: <77e831100902040824q2a0b8465k4894f29ed4baba12@mail.gmail.com> Message-ID: <4989C6D0.2000604@tim.thechases.com> > I know this is wrong it uses the items in the list as the filename, > how do I refer to the dataname and not the items in it. Without a sample value for "dataname", it's hard to tell what you're trying to do. Do you mean dataname = ['path', 'to', 'file'] ... filename = os.sep.join(dataname) Or you have a list of one value, and just want its first item? filename = dataname[0] > def savedata(dataname): > filename = str(dataname) # this does not do what I would like it to It would help if you detailed what you *would* like it to do... >>> from MindReading import answer Traceback (most recent call last): File "", line 6, in comp.lang.python ImportError: No module named MindReading Similar failure attempting >>> import dwim -tkc From manu3d at gmail.com Wed Feb 4 11:51:41 2009 From: manu3d at gmail.com (Emanuele D'Arrigo) Date: Wed, 4 Feb 2009 08:51:41 -0800 (PST) Subject: re.sub and named groups Message-ID: <4c7158d2-5663-46b9-b950-be81bd79964c@z6g2000pre.googlegroups.com> Hi everybody, I'm having a ball with the power of regular expression but I stumbled on something I don't quite understand: theOriginalString = "spam:(?P.*) ham:(?P.*)" aReplacementPattern = "\(\?P.*\)" aReplacementString= "foo" re.sub(aReplacementPattern , aReplacementString, theOriginalString) results in : "spam:foo" instead, I was expecting: "spam:foo ham:" Why is that? Thanks for your help! Manu From steve at holdenweb.com Wed Feb 4 11:54:45 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 04 Feb 2009 11:54:45 -0500 Subject: Kill a function while it's being executed In-Reply-To: <749CACF29BDFB64E9F80189ECD77868804C0072C@jermail1.atomant.net> References: <3eb685e5-dc80-41d0-acc2-2cafe0cb65c5@e18g2000yqo.googlegroups.com><6827582d-26ce-4245-88dd-d24955dc9f3a@x16g2000prn.googlegroups.com><1e7b7458-26f1-4ae6-b4d0-02dfbfc2cef3@l42g2000yqe.googlegroups.com><49897C95.1000301@wildenhain.de><749CACF29BDFB64E9F80189ECD77868804C00682@jermail1.atomant.net> <1233761152.373.14.camel@localhost.localdomain> <749CACF29BDFB64E9F80189ECD77868804C0072C@jermail1.atomant.net> Message-ID: Noam Aigerman wrote: > About the hijacking - I *might* have done it without understanding what > I did (replied to a previous message and then changed the subject), if > that's what you mean... > Sorry That's what he meant. A lot of news reading and email software uses In-Reply-To and various other message headers to determine how messages are threaded, so (for example) in my Thunderbird Window this appears to be a part of the thread that started out as "Locating Python". regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From vincent at vincentdavis.net Wed Feb 4 11:57:13 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Wed, 4 Feb 2009 09:57:13 -0700 Subject: Use list name as string In-Reply-To: <4989C6D0.2000604@tim.thechases.com> References: <77e831100902040824q2a0b8465k4894f29ed4baba12@mail.gmail.com> <4989C6D0.2000604@tim.thechases.com> Message-ID: <77e831100902040857q2379bf80hc05b5575cba85bdd@mail.gmail.com> Sorry for not being clearI would have something like this x = [1, 2, 3,5 ,6 ,9,234] Then def savedata(dataname): .......... savedata(x) this would save a to a file called x.csv This is my problem, getting the name to be x.csv which is the same as the name of the list. and the data in the file would be 1,2,3,5,6,9,234 this parts works Thanks Vincent Davis 720-301-3003 On Wed, Feb 4, 2009 at 9:48 AM, Tim Chase wrote: > I know this is wrong it uses the items in the list as the filename, >> how do I refer to the dataname and not the items in it. >> > > Without a sample value for "dataname", it's hard to tell what you're trying > to do. Do you mean > > dataname = ['path', 'to', 'file'] > ... > filename = os.sep.join(dataname) > > Or you have a list of one value, and just want its first item? > > filename = dataname[0] > > def savedata(dataname): >> filename = str(dataname) # this does not do what I would like it to >> > > It would help if you detailed what you *would* like it to do... > > >>> from MindReading import answer > Traceback (most recent call last): > File "", line 6, in comp.lang.python > ImportError: No module named MindReading > > Similar failure attempting > > >>> import dwim > > -tkc > > > > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kyosohma at gmail.com Wed Feb 4 12:05:16 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Wed, 4 Feb 2009 09:05:16 -0800 (PST) Subject: Couple of noobish question References: Message-ID: On Feb 4, 10:47?am, Catherine Heathcote wrote: > Firstly hi, I don't know any of you yet but am picking up Python and > will be lurking here a lot lol. I am a hobbiest coder (did 3 out of 4 > years of a comp tech degree, long story) and am learning Python, 'cos I > saw some code and it just looks a really nice language to work with. I > come from C++, so I am bound to trip up trying to do things the wrong way! > > I have been working with Project Euler to get the hang of Python, and > all goes well. I have an idea for a small project, an overly simplistic > interactive fiction engine (well more like those old choose your own > adventure books, used to love those!) that uses XML for its map files. > The main issues I see so far is the XML parsing (I should pick that up > ok, I have a blackbelt in google-foo), but more importantly splitting > code files. > > In C++ I would obviously split .cpp and .h files, pairing them up and > using #include. How do I do this in Python? I see that you don't tend to > split logic from defenition, but how do I keep different classes in > different files? My google-fu fails me so far. You just use the keyword "import". Here's a goofy example: 1) foo.py contains a class called Foo 2) bar.py contains a script that imports Foo: import foo # create an instance of the Foo class myFoo = foo.Foo() I hope that was clear. Mike From google at mrabarnett.plus.com Wed Feb 4 12:07:19 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 04 Feb 2009 17:07:19 +0000 Subject: Use list name as string In-Reply-To: <77e831100902040857q2379bf80hc05b5575cba85bdd@mail.gmail.com> References: <77e831100902040824q2a0b8465k4894f29ed4baba12@mail.gmail.com> <4989C6D0.2000604@tim.thechases.com> <77e831100902040857q2379bf80hc05b5575cba85bdd@mail.gmail.com> Message-ID: <4989CB47.3060806@mrabarnett.plus.com> Vincent Davis wrote: > Sorry for not being clear I would have something like this x = [1, 2, > 3,5 ,6 ,9,234] > > Then def savedata(dataname): .......... > > savedata(x) > > this would save a to a file called x.csv This is my problem, getting > the name to be x.csv which is the same as the name of the list. > > and the data in the file would be 1,2,3,5,6,9,234 this parts works > The list itself doesn't have a name. You need to pass in both the name and the list: def savedata(name, data): .......... savedata("x", x) From catherine.heathcote at gmail.com Wed Feb 4 12:09:54 2009 From: catherine.heathcote at gmail.com (Catherine Heathcote) Date: Wed, 04 Feb 2009 17:09:54 GMT Subject: Couple of noobish question In-Reply-To: References: Message-ID: Mike Driscoll wrote: > On Feb 4, 10:47 am, Catherine Heathcote > wrote: >> Firstly hi, I don't know any of you yet but am picking up Python and >> will be lurking here a lot lol. I am a hobbiest coder (did 3 out of 4 >> years of a comp tech degree, long story) and am learning Python, 'cos I >> saw some code and it just looks a really nice language to work with. I >> come from C++, so I am bound to trip up trying to do things the wrong way! >> >> I have been working with Project Euler to get the hang of Python, and >> all goes well. I have an idea for a small project, an overly simplistic >> interactive fiction engine (well more like those old choose your own >> adventure books, used to love those!) that uses XML for its map files. >> The main issues I see so far is the XML parsing (I should pick that up >> ok, I have a blackbelt in google-foo), but more importantly splitting >> code files. >> >> In C++ I would obviously split .cpp and .h files, pairing them up and >> using #include. How do I do this in Python? I see that you don't tend to >> split logic from defenition, but how do I keep different classes in >> different files? My google-fu fails me so far. > > You just use the keyword "import". Here's a goofy example: > > 1) foo.py contains a class called Foo > 2) bar.py contains a script that imports Foo: > > import foo > > # create an instance of the Foo class > myFoo = foo.Foo() > > > I hope that was clear. > > Mike Perfect, thanks ^^ From google at mrabarnett.plus.com Wed Feb 4 12:17:54 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 04 Feb 2009 17:17:54 +0000 Subject: re.sub and named groups In-Reply-To: <4c7158d2-5663-46b9-b950-be81bd79964c@z6g2000pre.googlegroups.com> References: <4c7158d2-5663-46b9-b950-be81bd79964c@z6g2000pre.googlegroups.com> Message-ID: <4989CDC2.7010001@mrabarnett.plus.com> Emanuele D'Arrigo wrote: > Hi everybody, > > I'm having a ball with the power of regular expression but I stumbled > on something I don't quite understand: > > theOriginalString = "spam:(?P.*) ham:(?P.*)" > aReplacementPattern = "\(\?P.*\)" > aReplacementString= "foo" > re.sub(aReplacementPattern , aReplacementString, theOriginalString) > > results in : > > "spam:foo" > > instead, I was expecting: > > "spam:foo ham:" > > Why is that? > > Thanks for your help! > The quantifiers eg "*" are normally greedy; they try to match as much as possible. Therefore ".*" matches: spam:(?P.*) ham:(?P.*) ^^^^^^^^^^^^^^^^^^^^^ You could use the lazy form "*?" which tries to match as little as possible, eg "\(\?P.*?\)" where the ".*?" matches: spam:(?P.*) ham:(?P.*) ^^ giving "spam:foo ham:(?P.*)". From vincent at vincentdavis.net Wed Feb 4 12:18:49 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Wed, 4 Feb 2009 10:18:49 -0700 Subject: Use list name as string In-Reply-To: <4989CB47.3060806@mrabarnett.plus.com> References: <77e831100902040824q2a0b8465k4894f29ed4baba12@mail.gmail.com> <4989C6D0.2000604@tim.thechases.com> <77e831100902040857q2379bf80hc05b5575cba85bdd@mail.gmail.com> <4989CB47.3060806@mrabarnett.plus.com> Message-ID: <77e831100902040918j4be325d3y760120c92f8a0d7f@mail.gmail.com> I know nothing but that sucks. I can think of a lot of times I would like to do something similar. There really is no way to do this, it seems like there would be some simple way kind of like str(listname) but backwards or different. Thanks Vincent Davis On Wed, Feb 4, 2009 at 10:07 AM, MRAB wrote: > Vincent Davis wrote: > > Sorry for not being clear I would have something like this x = [1, 2, > > 3,5 ,6 ,9,234] > > > > Then def savedata(dataname): .......... > > > > savedata(x) > > > > this would save a to a file called x.csv This is my problem, getting > > the name to be x.csv which is the same as the name of the list. > > > > and the data in the file would be 1,2,3,5,6,9,234 this parts works > > > The list itself doesn't have a name. You need to pass in both the name > and the list: > > def savedata(name, data): .......... > > savedata("x", x) > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From manu3d at gmail.com Wed Feb 4 12:23:45 2009 From: manu3d at gmail.com (Emanuele D'Arrigo) Date: Wed, 4 Feb 2009 09:23:45 -0800 (PST) Subject: re.sub and named groups References: <4c7158d2-5663-46b9-b950-be81bd79964c@z6g2000pre.googlegroups.com> Message-ID: <97ab8831-97ab-4d05-8fd3-90ac17f04bd1@x16g2000prn.googlegroups.com> On Feb 4, 5:17?pm, MRAB wrote: > You could use the lazy form "*?" which tries to match as little as > possible, eg "\(\?P.*?\)" where the ".*?" matches: > spam:(?P.*) ham:(?P.*) > giving "spam:foo ham:(?P.*)". A-ha! Of course! That makes perfect sense! Thank you! Problem solved! Ciao! Manu From vincent at vincentdavis.net Wed Feb 4 12:23:55 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Wed, 4 Feb 2009 10:23:55 -0700 Subject: Use list name as string In-Reply-To: <77e831100902040918j4be325d3y760120c92f8a0d7f@mail.gmail.com> References: <77e831100902040824q2a0b8465k4894f29ed4baba12@mail.gmail.com> <4989C6D0.2000604@tim.thechases.com> <77e831100902040857q2379bf80hc05b5575cba85bdd@mail.gmail.com> <4989CB47.3060806@mrabarnett.plus.com> <77e831100902040918j4be325d3y760120c92f8a0d7f@mail.gmail.com> Message-ID: <77e831100902040923k188e5df3q22423884f239e5a5@mail.gmail.com> I guess what I am saying is that it does not seem like I am adding any information that is not already there when I have to enter that list and list name after all they are the same. Thanks Vincent Davis On Wed, Feb 4, 2009 at 10:18 AM, Vincent Davis wrote: > I know nothing but that sucks. I can think of a lot of times I would like > to do something similar. There really is no way to do this, it seems like > there would be some simple way kind of like str(listname) but backwards or > different. > Thanks > Vincent Davis > > > > > On Wed, Feb 4, 2009 at 10:07 AM, MRAB wrote: > >> Vincent Davis wrote: >> > Sorry for not being clear I would have something like this x = [1, 2, >> > 3,5 ,6 ,9,234] >> > >> > Then def savedata(dataname): .......... >> > >> > savedata(x) >> > >> > this would save a to a file called x.csv This is my problem, getting >> > the name to be x.csv which is the same as the name of the list. >> > >> > and the data in the file would be 1,2,3,5,6,9,234 this parts works >> > >> The list itself doesn't have a name. You need to pass in both the name >> and the list: >> >> def savedata(name, data): .......... >> >> savedata("x", x) >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gherron at islandtraining.com Wed Feb 4 12:26:28 2009 From: gherron at islandtraining.com (Gary Herron) Date: Wed, 04 Feb 2009 09:26:28 -0800 Subject: Couple of noobish question In-Reply-To: References: Message-ID: <4989CFC4.6090305@islandtraining.com> Catherine Heathcote wrote: > Firstly hi, I don't know any of you yet but am picking up Python and > will be lurking here a lot lol. I am a hobbiest coder (did 3 out of 4 > years of a comp tech degree, long story) and am learning Python, 'cos > I saw some code and it just looks a really nice language to work with. > I come from C++, so I am bound to trip up trying to do things the > wrong way! Welcome. I suspect you'll enjoy Python. (Far more than C++ ). > > I have been working with Project Euler to get the hang of Python, and > all goes well. I have an idea for a small project, an overly > simplistic interactive fiction engine (well more like those old choose > your own adventure books, used to love those!) that uses XML for its > map files. The main issues I see so far is the XML parsing (I should > pick that up ok, I have a blackbelt in google-foo), but more > importantly splitting code files. Several modules exits to do the parsing of XML: elementtree, xml, and beautifulsoup come to mind immediately. > > In C++ I would obviously split .cpp and .h files, pairing them up and > using #include. How do I do this in Python? I see that you don't tend > to split logic from defenition, but how do I keep different classes in > different files? My google-fu fails me so far. Use the import statement for this. If file a.py defines some classes or functions a.py: class UsefulClass: ... def UsefulFn(...): ... Then your main Python file imports it and uses the things define in a.py like this: import a ob = UsefulClass(...) a.UsefulFn() Good luck, Gary Herron > -- > http://mail.python.org/mailman/listinfo/python-list From vincent at vincentdavis.net Wed Feb 4 12:31:38 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Wed, 4 Feb 2009 10:31:38 -0700 Subject: Use list name as string In-Reply-To: <77e831100902040923k188e5df3q22423884f239e5a5@mail.gmail.com> References: <77e831100902040824q2a0b8465k4894f29ed4baba12@mail.gmail.com> <4989C6D0.2000604@tim.thechases.com> <77e831100902040857q2379bf80hc05b5575cba85bdd@mail.gmail.com> <4989CB47.3060806@mrabarnett.plus.com> <77e831100902040918j4be325d3y760120c92f8a0d7f@mail.gmail.com> <77e831100902040923k188e5df3q22423884f239e5a5@mail.gmail.com> Message-ID: <77e831100902040931t76eb7d11la93fcd840c866b5e@mail.gmail.com> can I do it the otherway, that issavedata('nameoflist') Thanks Vincent Davis 720-301-3003 On Wed, Feb 4, 2009 at 10:23 AM, Vincent Davis wrote: > I guess what I am saying is that it does not seem like I am adding any > information that is not already there when I have to enter that list and > list name after all they are the same. > Thanks > Vincent Davis > > > > > On Wed, Feb 4, 2009 at 10:18 AM, Vincent Davis wrote: > >> I know nothing but that sucks. I can think of a lot of times I would like >> to do something similar. There really is no way to do this, it seems like >> there would be some simple way kind of like str(listname) but backwards or >> different. >> Thanks >> Vincent Davis >> >> >> >> >> On Wed, Feb 4, 2009 at 10:07 AM, MRAB wrote: >> >>> Vincent Davis wrote: >>> > Sorry for not being clear I would have something like this x = [1, 2, >>> > 3,5 ,6 ,9,234] >>> > >>> > Then def savedata(dataname): .......... >>> > >>> > savedata(x) >>> > >>> > this would save a to a file called x.csv This is my problem, getting >>> > the name to be x.csv which is the same as the name of the list. >>> > >>> > and the data in the file would be 1,2,3,5,6,9,234 this parts works >>> > >>> The list itself doesn't have a name. You need to pass in both the name >>> and the list: >>> >>> def savedata(name, data): .......... >>> >>> savedata("x", x) >>> >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >>> >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From cjw at ncf.ca Wed Feb 4 12:32:41 2009 From: cjw at ncf.ca (Colin J. Williams) Date: Wed, 04 Feb 2009 12:32:41 -0500 Subject: Date Comparison In-Reply-To: References: <2806523d-bba6-48e4-b23f-c27e069f00b8@o40g2000yqb.googlegroups.com> Message-ID: Bill McClain wrote: > On 2009-02-03, mohana2004 at gmail.com wrote: >> Hi, >> I need to compare two dates and find the number of days between those >> two dates.This can be done with datetime module in python as below, >> but this is not supported in Jython. > > There are julian day routines in this astronomy package: > > http://astrolabe.sourceforge.net/ and in Mark Lemburg's mxDate Colin W. > > -Bill From python.list at tim.thechases.com Wed Feb 4 12:35:29 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 04 Feb 2009 11:35:29 -0600 Subject: Use list name as string In-Reply-To: <77e831100902040918j4be325d3y760120c92f8a0d7f@mail.gmail.com> References: <77e831100902040824q2a0b8465k4894f29ed4baba12@mail.gmail.com> <4989C6D0.2000604@tim.thechases.com> <77e831100902040857q2379bf80hc05b5575cba85bdd@mail.gmail.com> <4989CB47.3060806@mrabarnett.plus.com> <77e831100902040918j4be325d3y760120c92f8a0d7f@mail.gmail.com> Message-ID: <4989D1E1.8090008@tim.thechases.com> > I know nothing but that sucks. I can think of a lot of times I would like to > do something similar. There really is no way to do this, it seems like there > would be some simple way kind of like str(listname) but backwards or > different. Python does the only reasonable thing: doesn't give you access to the "name". Consider the following situation: a = [1,2,3,4,5] b = a savedata(b) Do you want "a" or "b" as the variable-name? Both are valid names for the same list. If it matters, you can do something like this hack: def savedata(**kwargs): assert len(kwargs) == 1, "Just pass one parameter" filename, data = kwargs.iteritems().next() ext1 = '\.csv' flex = filename + ext1 datawrite = csv.writer(open(flex, "wb")) datawrite.writerows(data) which can then be called with something like savedata(foo=[1,2,3,4,5]) savedata(bar=a) savedata(name=name) to create "foo.csv" containing that data. Or you could just pass it explicitly which would make more sense and be easier to understand. -tkc From sebastien.yapo at free.fr Wed Feb 4 12:36:56 2009 From: sebastien.yapo at free.fr (=?ISO-8859-1?Q?Yapo_S=E9bastien?=) Date: Wed, 04 Feb 2009 18:36:56 +0100 Subject: re.sub and named groups In-Reply-To: <4c7158d2-5663-46b9-b950-be81bd79964c@z6g2000pre.googlegroups.com> References: <4c7158d2-5663-46b9-b950-be81bd79964c@z6g2000pre.googlegroups.com> Message-ID: <4989D238.6000702@free.fr> > Hi everybody, > > I'm having a ball with the power of regular expression but I stumbled > on something I don't quite understand: > > theOriginalString = "spam:(?P.*) ham:(?P.*)" > aReplacementPattern = "\(\?P.*\)" > aReplacementString= "foo" > re.sub(aReplacementPattern , aReplacementString, theOriginalString) > > results in : > > "spam:foo" > > instead, I was expecting: > > "spam:foo ham:" > > Why is that? > > Thanks for your help! > > Manu > > I think that .* in your replacement pattern matches ".*) ham:(?P.*" in your original string which seems correct for a regexp. Perhaps you should try aReplacementPattern = "\(\?P\.\*\)" or use replace() since your replacement pattern is not a regexp anymore. Sebastien From python.list at tim.thechases.com Wed Feb 4 12:46:13 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 04 Feb 2009 11:46:13 -0600 Subject: Use list name as string In-Reply-To: <77e831100902040931t76eb7d11la93fcd840c866b5e@mail.gmail.com> References: <77e831100902040824q2a0b8465k4894f29ed4baba12@mail.gmail.com> <4989C6D0.2000604@tim.thechases.com> <77e831100902040857q2379bf80hc05b5575cba85bdd@mail.gmail.com> <4989CB47.3060806@mrabarnett.plus.com> <77e831100902040918j4be325d3y760120c92f8a0d7f@mail.gmail.com> <77e831100902040923k188e5df3q22423884f239e5a5@mail.gmail.com> <77e831100902040931t76eb7d11la93fcd840c866b5e@mail.gmail.com> Message-ID: <4989D465.6070402@tim.thechases.com> > can I do it the otherway, that issavedata('nameoflist') for limited cases where your variable is defined globally, you can use: >>> a = [1,2,3,4] >>> def save(s): ... print globals().get(s, "UNDEFINED") ... >>> save("a") [1, 2, 3, 4] >>> save("b") UNDEFINED >>> b = (6,5,4,3) >>> save("b") (6, 5, 4, 3) However, it's a hideous hack, and fragile as demonstrated by >>> x = 7000 >>> def baz(): ... x = (7,8,9) # this isn't in save()'s globals() ... save("x") ... >>> baz() 7000 >>> x = 8000 >>> baz() 8000 and using locals() doesn't help either: print locals().get(s, globals().get(s, "UNDEFINED")) and has even weirder (but totally understandable) behavior: >>> save("s") # "s" hasn't been defined in globals() 's' Just pass the filename as a string, and skip trying to sniff internal variable-names. Or you'll experience a world of headaches. -tkc From google at mrabarnett.plus.com Wed Feb 4 12:49:57 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 04 Feb 2009 17:49:57 +0000 Subject: Use list name as string In-Reply-To: <77e831100902040923k188e5df3q22423884f239e5a5@mail.gmail.com> References: <77e831100902040824q2a0b8465k4894f29ed4baba12@mail.gmail.com> <4989C6D0.2000604@tim.thechases.com> <77e831100902040857q2379bf80hc05b5575cba85bdd@mail.gmail.com> <4989CB47.3060806@mrabarnett.plus.com> <77e831100902040918j4be325d3y760120c92f8a0d7f@mail.gmail.com> <77e831100902040923k188e5df3q22423884f239e5a5@mail.gmail.com> Message-ID: <4989D545.4030409@mrabarnett.plus.com> Vincent Davis wrote: > I guess what I am saying is that it does not seem like I am adding > any information that is not already there when I have to enter that > list and list name after all they are the same. > If you write: y = x then both x and y refer to the same list. The actual names of the variables and functions shouldn't matter to the outside world; the name of an output file shouldn't depend on the name of a variable. > On Wed, Feb 4, 2009 at 10:18 AM, Vincent Davis > > wrote: > > I know nothing but that sucks. I can think of a lot of times I > would like to do something similar. There really is no way to do > this, itseems like there would be some simple way kind of like > str(listname)but backwards or different. > > On Wed, Feb 4, 2009 at 10:07 AM, MRAB > wrote: > > Vincent Davis wrote: > > Sorry for not being clear I would have something like this > x = [1, 2, 3,5 ,6 ,9,234] > > > > Then def savedata(dataname): .......... > > > > savedata(x) > > > > this would save a to a file called x.csv This is my > > problem,getting the name to be x.csv which is the same as > > the name of the list. > > > > and the data in the file would be 1,2,3,5,6,9,234 this > > parts works > > > The list itself doesn't have a name. You need to pass in both > the name and the list: > > def savedata(name, data): .......... > > savedata("x", x) > From rdmurray at bitdance.com Wed Feb 4 13:12:48 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Wed, 4 Feb 2009 18:12:48 +0000 (UTC) Subject: Couple of noobish question References: Message-ID: Quoth Catherine Heathcote : > all goes well. I have an idea for a small project, an overly simplistic > interactive fiction engine (well more like those old choose your own > adventure books, used to love those!) that uses XML for its map files. > The main issues I see so far is the XML parsing (I should pick that up > ok, I have a blackbelt in google-foo), but more importantly splitting Others have answered your other question, but I thought I'd mention that you will probably want to take a look at the ElementTree module. --RDM From shiningsandy at gmail.com Wed Feb 4 13:27:26 2009 From: shiningsandy at gmail.com (sandeep) Date: Wed, 4 Feb 2009 10:27:26 -0800 (PST) Subject: Running CVSNT commands from python to Automate the job Message-ID: Hi All, i want to automate my task for of doing cvs checkout for different modules. I am on Windows XP and i am using Python 2.6. here is my attched python code. The thing is when i am running this nothing is happening. I am not sure at which end the problem is. am i giving wrong parameters or what? any help or pointers to write directions will be helpfull. CVS_PATH='C:\Program Files\CVSNT\cvs.exe' CVS_PATH=(os.sep).join(CVS_PATH.split('\\')) BRANCH_NAME='B_PKG14_01' ''' Filters the directories only from the list of files and directories excluding the directories starting with name '.' @param dirList=List of all the files and directories @param basePath=path where we are doing our filtering ''' def filterDir(dirList,basePath): import os temp=[] for data in dirList: #if(data[0]!='.'): mydir=os.path.join(basePath,data) flag=os.path.isdir(mydir) if(flag==True): temp.append(mydir) return temp def main(): import os curr_dir=os.getcwd()#current working directory curr_list=os.listdir(curr_dir)#list of all files and directories in current working directory global CVS_PATH,BRANCH_NAME temp=filterDir(curr_list,curr_dir) for mydir in temp: dir_name=os.path.split(mydir)[1] #os.rmdir(mydir) CVS_COMMAND='checkout -r '+BRANCH_NAME+' -P '+dir_name print '"'+CVS_PATH+'"'+' -q '+CVS_COMMAND main() thanks, sandeep From james at agentultra.com Wed Feb 4 13:36:12 2009 From: james at agentultra.com (J Kenneth King) Date: Wed, 04 Feb 2009 18:36:12 +0000 Subject: Added-value of frameworks? References: <98d0397d-f707-4c09-94ad-11427d94930f@l33g2000pri.googlegroups.com> Message-ID: <878wom6odf.fsf@agentultra.com> Matimus writes: > On Feb 4, 8:08?am, Gilles Ganault wrote: >> Hello >> >> If I wanted to build some social web site such as Facebook, what do >> frameworks like Django or TurboGears provide over writing a site from >> scratch using Python? >> >> Thank you for your feedback. > > Why not just look at the frameworks themselves and see what they have > to offer. Django and Turbogears both have pretty good tutorials. You > can be up and running in 20 minutes with each one. You be the judge. > > The frameworks provide a lot of boilerplate code that I would rather > not write. They are probably more secure and scalable than something I > would come up with. You also get many extras for free. I think in both > of the frameworks you mention you get an administrative back end for > free. Other people have created apps/plugins that you can use with > those frameworks. So, for example, you might be able to borrow the > code to help you add a forum to your site. > > I'm not sure I know the advantage of not using a framework. Unless "I > get to write more code" is an advantage. Creating your own framework > might be fun, but if you really just want a website don't do more work > than you need to. > > Matt In other words, it boils down to what you get paid to do. If you're being paid for a frob (the product, in this case a website) then you use a frob-maker (a framework). If you're being paid to make frobs, then you make the frob-maker. Most frob-makers are good at producing frobs of a certain kind. Just choose the frob-maker that makes the frobs you need. In rare circumstances you'll need a really customized frob. Call on me when you get there. ;) From gagsl-py2 at yahoo.com.ar Wed Feb 4 13:50:17 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 04 Feb 2009 16:50:17 -0200 Subject: len() References: <20090131201648.201b6ed5@usenot.de> Message-ID: En Wed, 04 Feb 2009 12:38:04 -0200, Pat escribi?: > Andreas Waldenburger wrote: >> On Sat, 31 Jan 2009 13:27:02 -0500 Pat wrote: >>> Tobiah wrote: >>>> Just out of curiosity, why was len() made to >>>> be it's own function? I often find myself >>>> typing things like my_list.len before I >>>> catch myself. >>> I'm surprised that no one responded to that question. >>> >> Huh? Gabriel Genellina replied about 46 minutes after it was posted. >> Might it be that your newsserver is a bit laggy? > > Might be laggy. Who knows. > Why didn't you answer the len() question? Why should he? Why didn't you look for the answer yourself, after being told that it existed? Why do you expect *us* to repeat ourselves again and again? Don't be so lazy... You can read all these posts using the mailing list (python-list at python.org), Usenet (comp.lang.python), Google Groups, and many other mirrors. See this same thread in 3 different ways: Google groups: http://groups.google.com/group/comp.lang.python/t/247ec641c289a326/ Gmane: http://permalink.gmane.org/gmane.comp.python.general/608346 Python.org: http://mail.python.org/pipermail/python-list/2009-January/526500.html and many others, like the "forum" look & feel provided by www.velocityreviews.com -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Wed Feb 4 13:57:55 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 04 Feb 2009 16:57:55 -0200 Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <67d8a4d2-0b3d-4b41-84e2-698f17cb8e88@35g2000pry.googlegroups.com> <26a3c05c-253d-4134-bcb9-aed8505f250e@e1g2000pra.googlegroups.com> <49895a45$0$16900$426a74cc@news.free.fr> Message-ID: En Wed, 04 Feb 2009 07:05:22 -0200, Bruno Desthuilliers escribi?: > Gabriel Genellina a ?crit : >> En Mon, 02 Feb 2009 19:51:11 -0200, Russ P. >> escribi?: >> >>> Suppose a library developer (or a module developer on a large team) >>> uses leading underscores. Now suppose that, for whatever reason >>> (pressure from the users, perhaps), the library developer decides to >>> change a "private" attribute to public. Now all occurrences of the >>> identifier need to be changed. If an assignment to the previously >>> "private" attribute is missed, no warning will be issued (because >>> Python allows new attributes to be added anywhere, even completely >>> outside the class definition itself). And if the library is widely >>> used, the probability of such bugs occurring is very high. >> So _foo becomes foo. Then: >> class X(object): >> def get_foo(self): return self._foo >> def set_foo(self, value): self._foo = value >> foo = property(get_foo, set_foo) > > > FWIW, if there's no other need for the property, I'd do it the other way > round : directly make foo a plain attribute, and add a _foo property > whose accessors would raise a deprecation warning. Then there's no > chance I miss a an assignement to _foo !-) Yes, that would be better. In any case, one has both static analysis tools (e.g. pylint) and dynamic warnings (like you said above) so I don't see a problem here. -- Gabriel Genellina From tjreedy at udel.edu Wed Feb 4 14:06:33 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 04 Feb 2009 14:06:33 -0500 Subject: is python Object oriented?? In-Reply-To: <01a901c9869c$628e8fa0$0d00a8c0@hendrik> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com><0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com><6ul2ieFg1sraU1@mid.uni-berlin.de><73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com><018801c9850e$3e019fe0$0d00a8c0@hendrik><7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com><6uo5koFg8q28U1@mid.uni-berlin.de> <6uoqvrFgh5oeU1@mid.uni-berlin.de> <01a901c9869c$628e8fa0$0d00a8c0@hendrik> Message-ID: Hendrik van Rooyen wrote: > "Scott David Daniels" wrote: > >> You might enjoy looking at QNX, since I think it is built along the >> lines you are describing here. I have an ancient copy of their OS, >> but haven't followed for more than couple of decades. > > I vaguely know about it, and I know they claim to be hot on > real time stuff. I have never pursued it in any depth because > of the real tiny nature of the processors I have been working > with (8031). > > When I had a cursory look at it a long time ago, it seemed > to be almost unix like in its make up, and I doubted that > I could persuade it to run on of them. (I may be dead > wrong of course - I don't know) > > I will put it on my list of stuff to try to get done. Slightly OT: QNX was open-sourced, at least for non-commercial use, a little more that a year ago. So it might be worth a new look. From tjreedy at udel.edu Wed Feb 4 14:11:20 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 04 Feb 2009 14:11:20 -0500 Subject: len() In-Reply-To: References: <20090131201648.201b6ed5@usenot.de> Message-ID: Pat wrote: > Andreas Waldenburger wrote: >> On Sat, 31 Jan 2009 13:27:02 -0500 Pat wrote: >> >>> Tobiah wrote: >>>> Just out of curiosity, why was len() made to >>>> be it's own function? I often find myself >>>> typing things like my_list.len before I >>>> catch myself. >>>> >>>> Thanks, >>>> >>>> Toby >>> I'm surprised that no one responded to that question. >>> >> Huh? Gabriel Genellina replied about 46 minutes after it was posted. >> Might it be that your newsserver is a bit laggy? >> >> regards >> /W >> > > Might be laggy. Who knows. > > Why didn't you answer the len() question? I didn't respond because it has been asked and answered before, so the answer can be found in the google archives or even maybe the FAQ. From digitig at gmail.com Wed Feb 4 14:18:25 2009 From: digitig at gmail.com (Tim Rowe) Date: Wed, 4 Feb 2009 19:18:25 +0000 Subject: sys.float_info.epsilon Message-ID: I'm reading Mark Summerfield's "Programming Python 3.0" at the moment, and I'm puzzled by some of his uses of sys.float_info.epsilon. I appreciate the issues of comparing floating point numbers, but I'm puzzled by code like: ... x = float(input(msg)) if abs(x) < sys.float_info.epsilon: ... What could the float() conversion return that would give different results for: if abs(x) < sys.float_info.epsilon and (to my mind, more obvious): if abs(x) == 0.0 I didn't realise that float() could return anything with an absolute value less than sys.float_value.epsilon other than 0.0 (which I think all representations can represent exactly). What am I missing here? -- Tim Rowe From bockman at virgilio.it Wed Feb 4 14:33:10 2009 From: bockman at virgilio.it (Francesco Bochicchio) Date: Wed, 04 Feb 2009 20:33:10 +0100 Subject: Tkinter In-Reply-To: <593b7e33-f0ef-434f-b967-a4a1a102aab1@z6g2000pre.googlegroups.com> References: <593b7e33-f0ef-434f-b967-a4a1a102aab1@z6g2000pre.googlegroups.com> Message-ID: <4989ed76$0$1117$4fafbaef@reader1.news.tin.it> Luke ha scritto: > Hello, I'm an inexperienced programmer and I'm trying to make a > Tkinter window and have so far been unsuccessful in being able to > delete widgets from the main window and then add new ones back into > the window without closing the main window. > > The coding looks similar to this: > ... > It may just be bad coding but either way I could use some help. > > Thanks I fixed your code to do what you want, although I have no idea why you want it... The main change is that you need to place the code to be executed when the button is clicked in a different function, and use the name of that function as value of the on_command property of the button. Then you need to give back the control to Tkinter, calling the mainloop function and when the button is clicked, your function is called. This sort of ping-pong is called event-driven programming, and it is how most GUI toolkit work. The functions called when a GUI event occurs are called callbacks. A secondary thing is that since both the main function and the callback read and change some 'variable' pointing to the widgets, you need to share them using python 'global' statement. Now, a better way to do it would be incapsulate all in a class, but I wanted to stay as much as possible close to your code. Finally, if you plan to to something that requires to dynamically create and destroy - or move arounds - graphical objects (not widgets), you might want to have a look to the 'Canvas' widget. Code follows after signature. Since the frame and the button are recreated just after having been destroyed, you just see them flicker. Ciao ---- FB -------------------------------------------- # # Module-level variables referring to widgets # used/changed by more than one function # back_ground = None frame1 = None def make_frame_and_button(): global frame1, back_ground print 'background', back_ground frame1=Frame(back_ground,width=213,height=480,bg='white') print 'Frame1', frame1 frame1.pack_propagate(0) frame1.pack(side=TOP,anchor=N) frame1.pack_propagate(0) frame1.pack(side=TOP,anchor=N) close_frame1=Button(frame1,text='close', bg='blue', command=on_close_button ) print 'close_frame1', close_frame1 close_frame1.pack_propagate(0) close_frame1.pack(side=TOP, anchor=N,pady=25) def on_close_button(): global frame1 frame1.destroy() make_frame_and_button() def MainWin(): global back_ground, frame1 main=Tk() main.geometry('640x480') back_ground=Frame(main,width=640,height=480,bg='black') back_ground.pack_propagate(0) back_ground.pack(side=TOP,anchor=N) make_frame_and_button() main.mainloop() MainWin() From martin at v.loewis.de Wed Feb 4 14:37:21 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 04 Feb 2009 20:37:21 +0100 Subject: x64 speed In-Reply-To: References: Message-ID: <4989ee71$0$3356$9b622d9e@news.freenet.de> > Is it the > x64 working faster at its design sizes Another guess (still from the darkness of not having received the slightest clue what the test actually does): if it creates integers in range(2**32, 2**64), then they fit into a Python int on AMD64-Linux, but require a Python long on 32-bit Windows; long operations are much slower than int operations. Regards, Martin From Scott.Daniels at Acm.Org Wed Feb 4 14:37:43 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 04 Feb 2009 11:37:43 -0800 Subject: Tkinter In-Reply-To: <593b7e33-f0ef-434f-b967-a4a1a102aab1@z6g2000pre.googlegroups.com> References: <593b7e33-f0ef-434f-b967-a4a1a102aab1@z6g2000pre.googlegroups.com> Message-ID: Luke wrote: > Hello, I'm an inexperienced programmer and I'm trying to make a > Tkinter window and have so far been unsuccessful in being able to > delete widgets from the main window and then add new ones back into > the window without closing the main window. > > The coding looks similar to this: > ... > from Tkinter import * > def MainWin(): > main=Tk() > ... > close_frame1=Button(frame1,text='close',bg='light gray', > command=frame1.destroy) > close_frame1.pack_propagate(0) > close_frame1.pack(side=TOP, anchor=N,pady=25) > if frame1.destroy==True: > frame1=Frame(back_ground,width=213,height=480,bg='white') > frame1.pack_propagate(0) > frame1.pack(side=TOP,anchor=N) > main.mainloop() > MainWin() > > It may just be bad coding but either way I could use some help. I'll tell you what I find helps me in exploring Tkinter: running Idle in the "no-subprocesses" mode. Now the resulting system _is_ less stable and may well require you to restart from time to time, but there is a compensation: you can see the effect of each operation as you do it by hand, as well as checking expressions: If in Windows: run cmd C:\> python -m idlelib.idle -n If in Linux / MacOSx: Start a terminal: $ python -m idlelib.idle -n & Once idle shows up, >>> import Tkinter >>> main = Tkinter.Tk() ... Following through your code, you'll see you start the frame, add the button, and, immediately after getting everything set up, you check: > if frame1.destroy==True: Which it will never be (frame1.destroy is a method, not data). Once you get the base set up, your code should runfrom events. So, to get a single step farther: At the top of the MainWin function, insert: global frame1, close_frame1 Replace your "close_frame1 =" line down to end-o-function with: def on_click(): global frame1, close_frame1 frame1.destroy() frame1 =Frame(back_ground,width=213,height=480,bg='white') frame1.pack_propagate(0) frame1.pack(side=TOP,anchor=N) close_frame1 = Button(frame1,text='retry', bg='light blue', command=on_click) close_frame1.pack_propagate(0) close_frame1.pack(side=TOP, anchor=N,pady=25) close_frame1 = Button(frame1,text='close',bg='light gray', command=on_click) close_frame1.pack_propagate(0) close_frame1.pack(side=TOP, anchor=N,pady=25) The "global" lines are needed so that on_click and MainWin (which both set the two names) are talking about the same objects. --Scott David Daniels Scott.Daniels at Acm.Org From thmpsn.m.k at gmail.com Wed Feb 4 14:49:32 2009 From: thmpsn.m.k at gmail.com (thmpsn.m.k at gmail.com) Date: Wed, 4 Feb 2009 11:49:32 -0800 (PST) Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com> <003d01c98527$d9ea4ec0$0d00a8c0@hendrik> <005201c98549$d3eb74a0$0d00a8c0@hendrik> <2ed10ddd-63ac-4507-b046-0404cc85c97a@s1g2000prg.googlegroups.com> <3acf1429-9aec-4e0d-b617-21cbcdf76087@w1g2000prk.googlegroups.com> <22440895-ed68-4643-b833-0befe83d571c@f40g2000pri.googlegroups.com> <49895bad$0$28683$426a74cc@news.free.fr> Message-ID: <5475ff03-2d41-4db1-a986-5124b166abfb@r15g2000prd.googlegroups.com> On Feb 4, 3:11?am, Bruno Desthuilliers wrote: > thmpsn.... at gmail.com a ?crit : > > > > > On Feb 3, 1:14 am, David Cournapeau wrote: > (snip) > >> after all, we have used FILE* for years and I have no idea about the FILE > >> structure. > > > Your lack of knowledge about it doesn't mean that it has somehow > > magically "private" members. The only reason that most of us don't > > know what a FILE is is that it's definition is implementation-defined > > (i.e., every compiler may define it differently). > > > That doesn't have anything to do with private members. For example, on > > my system, defines FILE as: > > > struct _iobuf { > > ? ? ? ? char *_ptr; > > ? ? ? ? int ? _cnt; > > ? ? ? ? char *_base; > > ? ? ? ? int ? _flag; > > ? ? ? ? int ? _file; > > ? ? ? ? int ? _charbuf; > > ? ? ? ? int ? _bufsiz; > > ? ? ? ? char *_tmpfname; > > ? ? ? ? }; > > Didn't you notice kind of a pattern here ? You mean the leading underscores? I don't think they're used for the same purpose as in Python. In C/C++, identifiers that begin with an underscore are reserved (at least at the outer level). Thus, if the member '_ptr' would instead be named 'ptr', something like this would break things: #define ptr // OOPS!! #include That shouldn't happen with '_ptr', since programs are not supposed to define those kinds of names (yeah, right). > > typedef struct _iobuf FILE; > > > Given this information, nothing prevents me from writing things like: > > > FILE* fp = fopen("file.txt", "r"); > > if (!fp) { /* do something */ } > > > printf("fp->_cnt = %d\n", fp->cnt); > > printf("fp->_flag = %d\n", fp->_flag); > > printf("fp->_file = %d\n", fp->_file); > > > fp->_flag = 0x20; // OOPS!! > > Indeed - and that's exactly the point : nothing prevents you from > accessing the implementation, *and yet, you don't* I sure don't, but I still *can*. CHAOS MAY ENSUE!! From Scott.Daniels at Acm.Org Wed Feb 4 14:52:11 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 04 Feb 2009 11:52:11 -0800 Subject: sys.float_info.epsilon In-Reply-To: References: Message-ID: Tim Rowe wrote: > I'm reading Mark Summerfield's "Programming Python 3.0" at the moment, > and I'm puzzled by some of his uses of sys.float_info.epsilon. I > appreciate the issues of comparing floating point numbers, but I'm > puzzled by code like: > ... > x = float(input(msg)) > if abs(x) < sys.float_info.epsilon: > ... > > What could the float() conversion return that would give different results for: > if abs(x) < sys.float_info.epsilon > and (to my mind, more obvious): > if abs(x) == 0.0 > > I didn't realise that float() could return anything with an absolute > value less than sys.float_value.epsilon other than 0.0 (which I think > all representations can represent exactly). What am I missing here? > You are missing the whole thing that mes floating point tricky. I _believe_ that the epsilon is the smallest positive x such that 1.0 != 1.0 + x That doesn't mean that x is the smallest representable. for example, .0125 + epsilon / 4 != .0125 To avoid using epsilon, do something like: if 1 + abs(x) != 1: To learn a bit more, look into numerical analysis -- there is a whole field dedicated to figuring out how to make floating point behave a little bit like real numbers. The reason it is tough is that addition is not associative in real numbers, and associativity is at the core of a lot of proofs in arithmetic (and group theory). --Scott David Daniels Scott.Daniels at Acm.Org From dickinsm at gmail.com Wed Feb 4 14:57:20 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Wed, 4 Feb 2009 11:57:20 -0800 (PST) Subject: sys.float_info.epsilon References: Message-ID: <42b8c80f-b53c-4ec0-a1eb-c66410c60197@i18g2000prf.googlegroups.com> On Feb 4, 7:18?pm, Tim Rowe wrote: > I didn't realise that float() could return anything with an absolute > value less than sys.float_value.epsilon other than 0.0 (which I think > all representations can represent exactly). ?What am I missing here? There are many positive floating-point values smaller than sys.float_info.epsilon. sys.float_info.epsilon is defined as the difference between 1.0 and the next largest representable floating-point number. On your system, the next largest float is almost certainly 1 + 2**-52, so sys.float_info.epsilon will be exactly 2**-52, which is around 2.2e-16. This number is a good guide to the relative error from rounding that you can expect from a basic floating-point operation. The smallest positive floating-point number is *much* smaller: again, unless you have a very unusual platform, it's going to be 2**-1074, or around 4.9e-324. In between 2**-1074 and 2**-52 there are approximately 4.4 million million million different floating-point numbers. Take your pick! If you want a specific example, how about float('6.626e-34'). Mark From stefan_ml at behnel.de Wed Feb 4 15:02:52 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 04 Feb 2009 21:02:52 +0100 Subject: Using lxml to screen scrap a site, problem with charset In-Reply-To: References: Message-ID: <4989f46c$0$31338$9b4e6d93@newsspool4.arcor-online.net> Tim Arnold wrote: > "?????? ???????????" wrote in message > news:ciqh56-ses.ln1 at archaeopteryx.softver.org.mk... >> So, I'm using lxml to screen scrap a site that uses the cyrillic >> alphabet (windows-1251 encoding). The sites HTML doesn't have the > ..content-type.. charset=..> header, but does have a HTTP header that >> specifies the charset... so they are standards compliant enough. >> >> Now when I run this code: >> >> from lxml import html >> doc = html.parse('http://a1.com.mk/') >> root = doc.getroot() >> title = root.cssselect(('head title'))[0] >> print title.text >> >> the title.text is ? unicode string, but it has been wrongly decoded as >> latin1 -> unicode > > The way I do that is to open the file with codecs, encoding=cp1251, read it > into variable and feed that to the parser. Yes, if you know the encoding through an external source (especially when parsing broken HTML), it's best to pass in either a decoded string or a decoding file-like object, as in tree = lxml.html.parse( codecs.open(..., encoding='...') ) You can also create a parser with an encoding override: parser = etree.HTMLParser(encoding='...', **other_options) Stefan From dickinsm at gmail.com Wed Feb 4 15:07:23 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Wed, 4 Feb 2009 12:07:23 -0800 (PST) Subject: sys.float_info.epsilon References: Message-ID: <8f6095b4-f316-4c64-a210-ab0d746659d7@s1g2000prg.googlegroups.com> On Feb 4, 7:52?pm, Scott David Daniels wrote: > You are missing the whole thing that mes floating point tricky. > I _believe_ that the epsilon is the smallest positive x such that > ? ? 1.0 != 1.0 + x Nitpick alert: this isn't quite the same thing, since that definition is affected by rounding. For example, if you're using IEEE 754 doubles but (somehow) you've got a round-half-up rounding mode then this makes epsilon 2**-53 rather than 2**-52, because 1 + 2**-53 rounds to 1 + 2**-52 != 1. (This confused the hell out of me many years ago when I was reading Numerical Recipes, and trying to figure out why on earth IEEE 754 and the VAX format had different epsilons even though both had 53-bit mantissas. The answer is that IEEE 754 uses round-half-even as standard, and VAX uses round-half-up. Oh, and the authors of Numerical Recipes used the 1 != 1+x definition...) Python's float_info.epsilon comes straight from C's DBL_EPSILON, which is defined very carefully in the C99 standard as: """the difference between 1 and the least value greater than 1 that is representable in the given floating point type""" (taking the 'given floating point type' to be double). Mark From mdw at distorted.org.uk Wed Feb 4 15:16:03 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 04 Feb 2009 20:16:03 +0000 Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com> <003d01c98527$d9ea4ec0$0d00a8c0@hendrik> <005201c98549$d3eb74a0$0d00a8c0@hendrik> <2ed10ddd-63ac-4507-b046-0404cc85c97a@s1g2000prg.googlegroups.com> <4ec8770b-631f-492b-be7a-27bb8ac47afc@i20g2000prf.googlegroups.com> <11ee7ba4-12f2-4744-80af-315dbea78cd9@r41g2000prr.googlegroups.com> Message-ID: <87d4dylzzw.fsf.mdw@metalzone.distorted.org.uk> "Russ P." writes: > Imagine you own a company, and you decide to lease an office building. > Would you expect the office doors to have locks on them? Oh, you > would? Why? You mean you don't "trust" your co-workers? What are locks > but enforced access restriction? Huh? The lock on the door isn't to keep the coworkers out. It's to let them /in/ while keeping everyone else out. So I don't really see the analogy. Or are you talking about the individual offices? If so, then I'd expect the locks to be /used/ only under rather unusual circumstances. If someone in the office has something to hide, I think that's rather suspicious, actually... -- [mdw] From pellegrinodj at gmail.com Wed Feb 4 15:18:28 2009 From: pellegrinodj at gmail.com (pellegrinodj at gmail.com) Date: Wed, 4 Feb 2009 12:18:28 -0800 (PST) Subject: how to compile in jython 2.5b1?? Message-ID: <6784ac72-0dbb-4904-b92b-3bee3418a233@r37g2000prr.googlegroups.com> I have to use jython 2.5b1 couse with the stable version it's not possible to use sympy library for mathematic operation but the "jythonc.bat" it's not included. I look to this link: http://www.jython.org/Project/jythonc.html "..jythonc is unmaintained and will not be present in its current form in Jython 2.5..." so what can I do?? thank you for the answer!! From steve at holdenweb.com Wed Feb 4 15:20:29 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 04 Feb 2009 15:20:29 -0500 Subject: sys.float_info.epsilon In-Reply-To: References: Message-ID: Tim Rowe wrote: > I'm reading Mark Summerfield's "Programming Python 3.0" at the moment, > and I'm puzzled by some of his uses of sys.float_info.epsilon. I > appreciate the issues of comparing floating point numbers, but I'm > puzzled by code like: > ... > x = float(input(msg)) > if abs(x) < sys.float_info.epsilon: > ... > > What could the float() conversion return that would give different results for: > if abs(x) < sys.float_info.epsilon > and (to my mind, more obvious): > if abs(x) == 0.0 > > I didn't realise that float() could return anything with an absolute > value less than sys.float_value.epsilon other than 0.0 (which I think > all representations can represent exactly). What am I missing here? > epsilon is the difference between *1.0* and the next smallest number in the representation. It seems pretty obvious that the smallest representable number will be way smaller than that. To me, at least. Think about the representation of 1. + epsilon - the mantissa will have a leading 1, then all zeros but for a trailing 1, and the exponent will effectively be 0. For numbers close to zero the exponent will have a large negative effective value (exponents are usually stored as biased positive numbers), and so the smallest value will be tiny compared with epsilon. Though it's a long time since I did my numerical analysis, and it isn't clear to me exactly what the test *is* supposed to do. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From nytrokiss at gmail.com Wed Feb 4 15:23:25 2009 From: nytrokiss at gmail.com (James Matthews) Date: Wed, 4 Feb 2009 22:23:25 +0200 Subject: [Web 2.0] Added-value of frameworks? In-Reply-To: References: Message-ID: <8a6b8e350902041223u68f4655bu728d49d25195672e@mail.gmail.com> They provide a nice framework that will handle most of the annoying things. With Django you don't need to write SQL (in a sense). etc.. On Wed, Feb 4, 2009 at 6:08 PM, Gilles Ganault wrote: > Hello > > If I wanted to build some social web site such as Facebook, what do > frameworks like Django or TurboGears provide over writing a site from > scratch using Python? > > Thank you for your feedback. > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://www.goldwatches.com/ http://www.jewelerslounge.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From joviyach at gmail.com Wed Feb 4 15:31:37 2009 From: joviyach at gmail.com (joviyach) Date: Wed, 4 Feb 2009 12:31:37 -0800 (PST) Subject: Upgrade 2.6 to 3.0 Message-ID: <669c42cc-4f4d-40be-b842-6f778959d391@f40g2000pri.googlegroups.com> I am fairly new to Python, the first version I loaded was 2.6. I have since downloaded 3.0 and I was wondering what the best practice for upgrading is? I am using Windows XP Pro for my OS. Thanks, Jim From Scott.Daniels at Acm.Org Wed Feb 4 15:43:02 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 04 Feb 2009 12:43:02 -0800 Subject: Upgrade 2.6 to 3.0 In-Reply-To: <669c42cc-4f4d-40be-b842-6f778959d391@f40g2000pri.googlegroups.com> References: <669c42cc-4f4d-40be-b842-6f778959d391@f40g2000pri.googlegroups.com> Message-ID: joviyach wrote: > I am fairly new to Python, the first version I loaded was 2.6. I have > since downloaded 3.0 and I was wondering what the best practice for > upgrading is? I am using Windows XP Pro for my OS. On Windows, X.Y.* all go in one directory (over-riding each other) So the whole 2.6.* family should work just fine alongside the 3.0.* family. In just a bit, 3.0.1 is coming soon, correcting some problems in 3.0, so if you do install 3.0, check in a few weeks for an update. The 2 -> 3 change was pretty substantial, so it will be a bit until the 3.0 line gets lots of outside packages. --Scott David Daniels Scott.Daniels at Acm.Org From mdw at distorted.org.uk Wed Feb 4 15:44:49 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 04 Feb 2009 20:44:49 +0000 Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <0ea1a7b8-7fa5-4d32-80c2-2614b82dde5e@f3g2000yqf.googlegroups.com> <6ul2ieFg1sraU1@mid.uni-berlin.de> <73df3c0e-425b-4d0d-a7ba-8c15970678ef@p37g2000yqd.googlegroups.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com> <003d01c98527$d9ea4ec0$0d00a8c0@hendrik> <005201c98549$d3eb74a0$0d00a8c0@hendrik> <2ed10ddd-63ac-4507-b046-0404cc85c97a@s1g2000prg.googlegroups.com> <498825f3$0$3303$426a74cc@news.free.fr> Message-ID: <878womlyny.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > Now, that's a toy example. Languages like Ada make correctness proofs, > well, perhaps not easy, but merely difficult compared to impossible for > languages like Python. Say `generally impractical' rather than `impossible' and I'll agree with you. But I'm not actually sure that the situation for Python with respect to correctness proofs is significantly harder than it is for C. Certainly Ada (or at least dialects of Ada) have features which make proof-supporting tools easier; I'm not aware of such proof support for other languages. Actually, if you're starting from a formal specification in Z, say, and implementing in Python, well, the Z checker will already have ensured that your specification is well typed; your proof that the implementation follows the specification will automatically contain a well-typed-ness proof of your implementation regardless of whether the compiler provides static verification. > To bring it back to private/public attributes, side-effects make > correctness proofs difficult. Modifications of attributes are side- > effects. When attributes are subject to being modified by arbitrary code, > it is harder to reason about the correctness of the code: > > class Inverter(object): > def __init__(self, x): > # Pre-condition: x is always a float > if x: > self.x = x > else: > raise ValueError("x must not be zero") > # Post-condition: if self.x exists, it is a non-zero float > def invert(self): > return 1.0/self.x > > > Is method invert correct? I'd argue that it isn't, and in fact that the specification is wrong. In particular, it ought to be a precondition that x is nonzero. At this point you can dump the explicit check at the cost of imposing a proof obligation on the caller. > No, it is not, because the invariant that self.x is non-zero may have > been broken by some arbitrary piece of code elsewhere. It's not stated as an invariant. It's stated as a post-condition, which is indeed true (almost[1]) regardless of the behaviour of other parts of the program. [1] A subclass may have already set self.x before invoking Inverter.__init__. If you explicitly `del self.x' before raising the exception, the subclass can still defeat you by passing the reference to the half-constructed object to another thread which mutates the object at an inconvenient time. I mention all of this merely to avoid pedantry in follow-ups. I'd also argue that maintaining the invariant about self.x is the responsibility of code that messes with self.x, and therefore it is /legitimate/ to modify self.x from external code which maintains the invariant. > Our ability to reason about the correctness of the code is weakened > significantly. Sticking an underscore in front of x does not help: > there's nothing to stop some arbitrary function elsewhere changing _x > to zero. Dichotomy for you. * EITHER the other code is written to the same high standards, in which case it will come with appropriate specifications, preconditions, postconditions, invariants and proofs for whatever it does, even -- especially -- if it involves grubbily messing about with your module's innards (so everything is fine); * OR the other code doesn't meet your high standards, in which case all bets are off anyway, from the point of view of formal-methods types at any rate (so you can wash your hands of the whole affair). > (1) Paranoia. Make the developer responsible for checking everything all > the time: [...] > (2) Hope the error never occurs, and if it does, let the caller deal with > it. [...] > There is a third strategy, sadly not available to Python programmers: > prevention by catching potential errors at compile-time. Four: Describe your interface clearly, specify the behaviour of functions and so on; and leave whoever messes with your module with the task of proving -- to whatever level of formality is required by their project -- that what they've done is sane and reasonable. In fact, since whatever one does in a project should be held to this standard, whether it involves grubbing about inside undocumented internals or not, there's nothing particularly special about this case. Good job, really, since Python doesn't distinguish either. ;-) -- [mdw] From mdw at distorted.org.uk Wed Feb 4 15:49:23 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 04 Feb 2009 20:49:23 +0000 Subject: Where & how to deallocate resources in Python C extension References: <8fe56d94-1d33-44d9-980f-a92c077a30d1@k36g2000pri.googlegroups.com> Message-ID: <874ozalygc.fsf.mdw@metalzone.distorted.org.uk> fredbasset1000 at gmail.com writes: > I've written a C extension, see code below, to provide a Python > interface to a hardware watchdog timer. As part of the initialization > it makes some calls to mmap, I am wondering should I be making > balanced calls to munmap in some kind of de-init function? The kernel should remove the mapping when your process exits anyway -- otherwise the world would be left in an inconsistent state if your process got killed by SIGKILL for example. > Do Python extensions have d'tors? No. But you can cheat: stash some object whose tp_del slot does your cleanup in your extension's module under some funny name. (And woe betide anyone who dels the funny name prematurely!) I'm not sure I'd bother. -- [mdw] From deets at nospam.web.de Wed Feb 4 15:56:59 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 04 Feb 2009 21:56:59 +0100 Subject: how to compile in jython 2.5b1?? In-Reply-To: <6784ac72-0dbb-4904-b92b-3bee3418a233@r37g2000prr.googlegroups.com> References: <6784ac72-0dbb-4904-b92b-3bee3418a233@r37g2000prr.googlegroups.com> Message-ID: <6uudorFh6dr4U1@mid.uni-berlin.de> pellegrinodj at gmail.com schrieb: > I have to use jython 2.5b1 couse with the stable version it's not > possible to use sympy library for mathematic operation but the > "jythonc.bat" it's not included. > I look to this link: http://www.jython.org/Project/jythonc.html > "..jythonc is unmaintained and will not be present in its current form > in Jython 2.5..." > so what can I do?? > thank you for the answer!! What do you need jythonc for? That's purely for a somewhat neater integration of *Java* with jython - nothing to do with sympy. Diez From kst-u at mib.org Wed Feb 4 16:06:30 2009 From: kst-u at mib.org (Keith Thompson) Date: Wed, 4 Feb 2009 21:06:30 +0000 (UTC) Subject: structs References: Message-ID: "Scott David Daniels" writes: > To avoid using epsilon, do something like: > if 1 + abs(x) != 1: An OK effort, but you're wrong. That's not how to do it at all. From pellegrinodj at gmail.com Wed Feb 4 16:08:05 2009 From: pellegrinodj at gmail.com (ruelle) Date: Wed, 4 Feb 2009 13:08:05 -0800 (PST) Subject: how to compile in jython 2.5b1?? References: <6784ac72-0dbb-4904-b92b-3bee3418a233@r37g2000prr.googlegroups.com> <6uudorFh6dr4U1@mid.uni-berlin.de> Message-ID: <1d4d9261-6d0d-4312-8967-0fa13dc98e09@r10g2000prf.googlegroups.com> > What do you need jythonc for? That's purely for a somewhat neater > integration of *Java* with jython - nothing to do with sympy. > > Diez I need jythonc to compile a simple script in java, this script import SymPy library. thank you ruelle From mal at egenix.com Wed Feb 4 16:16:31 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Wed, 04 Feb 2009 22:16:31 +0100 Subject: JDBC in CPYTHON In-Reply-To: <3e9865ac-ce12-492f-83db-74bd78ed3ee2@i18g2000prf.googlegroups.com> References: <3e9865ac-ce12-492f-83db-74bd78ed3ee2@i18g2000prf.googlegroups.com> Message-ID: <498A05AF.2070706@egenix.com> On 2009-02-03 19:30, KMCB wrote: > I was wondering if anyone was aware of a JDBC DBAPI module for > cpython. I have looked at PYJDBC and was interested in avoiding using > that extra level of ICE. I was thinking maybe someone would have back > ported zxJDBC from Jython. Or used that as a starting point, to > create a module and had a C based wrapper for the driver. This type > of activity was talked about back in 2004 on this forum, but I was > wondering if anyone had newer information. Why not use ODBC instead ? http://www.egenix.com/products/python/mxODBC/ (zxJDBC is based on and was inspired by mxODBC) Or, if you don't have ODBC drivers for your database, use an ODBC-JDBC bridge such as: http://www.easysoft.com/products/data_access/odbc_jdbc_gateway/ or http://odbcjdbc.sourceforge.net/ -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Feb 04 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From kst-u at mib.org Wed Feb 4 16:20:43 2009 From: kst-u at mib.org (Keith Thompson) Date: Wed, 4 Feb 2009 21:20:43 +0000 (UTC) Subject: structs References: Message-ID: "Gary Herron" writes: > Python *is* object-oriented I disagree. Care to provide proof of that statement? From mal at egenix.com Wed Feb 4 16:26:37 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Wed, 04 Feb 2009 22:26:37 +0100 Subject: x64 speed In-Reply-To: <49896AA0.2050202@chamonix.reportlab.co.uk> References: <4988a1f1$0$3390$9b622d9e@news.freenet.de> <4988B615.4060206@jessikat.plus.net> <4988BAE8.2060204@v.loewis.de> <49896AA0.2050202@chamonix.reportlab.co.uk> Message-ID: <498A080D.3000703@egenix.com> On 2009-02-04 11:14, Robin Becker wrote: > Martin v. L?wis wrote: >>>> I follow David's guess that Linux does better IO than Windows (not >>>> knowing anything about the benchmark, of course) >>>> >>> I originally thought it must be the vmware host stuff offloading IO to >>> the second core, but watching with sysinternals didn't show a lot of >>> extra stuff going on with the vm compared to just running on the host. >> >> I'm not talking about vmware. I'm suggesting that Linux ext3, and the >> Linux buffer handling, is just more efficient than NTFS, and the Windows >> buffer handling. >> >> If you split the total runtime into system time and user time, how do >> the 30s split up? > ....... > so here is one for the vm clock is bad theorists :) > > >> [rptlab at localhost tests]$ time python25 runAll.py >> ............................................................. > > ......................... >> ---------------------------------------------------------------------- >> Ran 193 tests in 27.841s >> >> OK >> >> real 0m28.150s >> user 0m26.606s >> sys 0m0.917s >> [rptlab at localhost tests]$ > > magical how the total python time is less than the real time. time(1) also measures the Python startup and shutdown time, so I don't quite see the magic :-( FWIW: VMware VMs need the VMware tools installed to make their clocks work more or less. With Linux, you need some extra tweaks as well, otherwise the clocks are just completely unreliable. See these notes: http://kb.vmware.com/selfservice/viewContent.do?language=en_US&externalId=1420 http://communities.vmware.com/message/782173 -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Feb 04 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From bignose+hates-spam at benfinney.id.au Wed Feb 4 16:28:43 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Thu, 05 Feb 2009 08:28:43 +1100 Subject: Kill a function while it's being executed References: <3eb685e5-dc80-41d0-acc2-2cafe0cb65c5@e18g2000yqo.googlegroups.com> <6827582d-26ce-4245-88dd-d24955dc9f3a@x16g2000prn.googlegroups.com> <1e7b7458-26f1-4ae6-b4d0-02dfbfc2cef3@l42g2000yqe.googlegroups.com> <49897C95.1000301@wildenhain.de> <749CACF29BDFB64E9F80189ECD77868804C00682@jermail1.atomant.net> <1233761152.373.14.camel@localhost.localdomain> Message-ID: <878wolzyb8.fsf@benfinney.id.au> "Noam Aigerman" writes: > About the hijacking - I *might* have done it without understanding > what I did (replied to a previous message and then changed the > subject), if that's what you mean... Right. The message still declares itself (via fields in the header) to be a reply to the original, regardless of the subject change. If your reply actually has no bearing on the original, then that's what is known as hijacking a thread. To start a new thread, you need to compose a new message to the forum. -- \ ?[Freedom of speech] isn't something somebody else gives you. | `\ That's something you give to yourself.? ?_Hocus Pocus_, Kurt | _o__) Vonnegut | Ben Finney From mal at egenix.com Wed Feb 4 16:43:04 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Wed, 04 Feb 2009 22:43:04 +0100 Subject: Unzipping a .zip properly, and from a remote URL In-Reply-To: <4988557A.5020407@wildenhain.de> References: <874ozbhdoi.fsf@christopherculver.com> <87y6wnfxoe.fsf@christopherculver.com> <4988557A.5020407@wildenhain.de> Message-ID: <498A0BE8.5080205@egenix.com> On 2009-02-03 15:32, Tino Wildenhain wrote: > Christopher Culver wrote: >> Tino Wildenhain writes: >>> so instead you would use archive = zipfile.ZipFile(remotedata) >> >> That produces the following error if I try that in the Python >> interpreter (URL edited for privacy): >> >>>>> import zipfile >>>>> import urllib2 >>>>> remotedata = urllib2.urlopen("http://...file.zip") >>>>> archive = zipfile.ZipFile(remotedata) >> Traceback (most recent call last): >> File "", line 1, in >> File "/usr/lib/python2.5/zipfile.py", line 346, in __init__ >> self._GetContents() >> File "/usr/lib/python2.5/zipfile.py", line 366, in _GetContents >> self._RealGetContents() >> File "/usr/lib/python2.5/zipfile.py", line 376, in _RealGetContents >> endrec = _EndRecData(fp) >> File "/usr/lib/python2.5/zipfile.py", line 133, in _EndRecData >> fpin.seek(-22, 2) # Assume no archive comment. >> AttributeError: addinfourl instance has no attribute 'seek' Try this: >>> import urllib, zipfile, cStringIO >>> zipwebfile = urllib.urlopen('http://downloads.egenix.com/python/locale-0.1.zip') >>> buffer = cStringIO.StringIO(zipwebfile.read()) >>> zfile = zipfile.ZipFile(buffer) >>> zfile.printdir() File Name Modified Size locale/Makefile.pre.in 1997-10-31 21:13:06 9818 locale/Setup.in 1997-10-31 21:14:04 74 locale/locale.c 1997-11-19 17:36:46 4698 locale/CommandLine.py 1997-11-19 15:50:02 2306 locale/probe.py 1997-11-19 15:51:18 1870 locale/__init__.py 1997-11-19 17:55:02 0 The trick is to use a StringIO buffer to provide the .seek() method. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Feb 04 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From digitig at gmail.com Wed Feb 4 16:44:49 2009 From: digitig at gmail.com (Tim Rowe) Date: Wed, 4 Feb 2009 21:44:49 +0000 Subject: sys.float_info.epsilon In-Reply-To: <42b8c80f-b53c-4ec0-a1eb-c66410c60197@i18g2000prf.googlegroups.com> References: <42b8c80f-b53c-4ec0-a1eb-c66410c60197@i18g2000prf.googlegroups.com> Message-ID: 2009/2/4 Mark Dickinson : > There are many positive floating-point values smaller than > sys.float_info.epsilon. > > sys.float_info.epsilon is defined as the difference between 1.0 and > the next largest representable floating-point number. On your system, > the next largest float is almost certainly 1 + 2**-52, so > sys.float_info.epsilon will be exactly 2**-52, which is around > 2.2e-16. This number is a good guide to the relative error > from rounding that you can expect from a basic floating-point > operation. > > The smallest positive floating-point number is *much* smaller: > again, unless you have a very unusual platform, it's going to > be 2**-1074, or around 4.9e-324. In between 2**-1074 and > 2**-52 there are approximately 4.4 million million million > different floating-point numbers. Take your pick! Ok, that makes a lot of sense, thanks. I was thinking in terms of Ada's floating point delta (rather than epsilon), which as I remember it, if specified, applies uniformly across the whole floating point range, not just to a particular point on the scale. That just leaves me puzzled as to why Mark Summerfield used it instead of a check against zero on user input. There's a later division by 2*x, so small values of x matter; there's no protection against overflow (the numerator could perfectly well be somewhere up near sys.float_info.max; a quick check in the shell tells me that Python3 will happily do sys.float_info.max/(2*sys.float_info.epsilon) and will give me the answer "inf") so presumably he's trying to protect against divide by zero. So my next question is whether there is any x that can be returned by float() such that x != 0 but some_number / (2 * x) raises a ZeroDivisionError? -- Tim Rowe From digitig at gmail.com Wed Feb 4 16:47:24 2009 From: digitig at gmail.com (Tim Rowe) Date: Wed, 4 Feb 2009 21:47:24 +0000 Subject: sys.float_info.epsilon In-Reply-To: References: Message-ID: 2009/2/4 Scott David Daniels : Thanks for that. It makes me feel guilty to point out that: > addition is not associative in real numbers should presumably be "addition is not associative in floating point numbers". -- Tim Rowe From bdesth.quelquechose at free.quelquepart.fr Wed Feb 4 16:49:53 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Wed, 04 Feb 2009 22:49:53 +0100 Subject: Couple of noobish question In-Reply-To: References: Message-ID: <498a1b1d$0$24204$426a74cc@news.free.fr> Catherine Heathcote a ?crit : > Firstly hi, I don't know any of you yet but am picking up Python and > will be lurking here a lot lol. I am a hobbiest coder (did 3 out of 4 > years of a comp tech degree, long story) and am learning Python, 'cos I > saw some code and it just looks a really nice language to work with. I > come from C++, so I am bound to trip up trying to do things the wrong way! > > I have been working with Project Euler to get the hang of Python, and > all goes well. I have an idea for a small project, an overly simplistic > interactive fiction engine (well more like those old choose your own > adventure books, used to love those!) that uses XML for its map files. You may have good reasons to choose this format, but FWIW, some (most ?) of us here tend to prefer "lighter" formats like json or yaml, or even just plain Python source. But, well, just so you know there are possible alternatives to XML !-) > The main issues I see so far is the XML parsing (I should pick that up > ok, I have a blackbelt in google-foo), but more importantly splitting > code files. ??? Oh, you mean, how to organize your source code ? > In C++ I would obviously split .cpp and .h files, pairing them up and > using #include. How do I do this in Python? I see that you don't tend to > split logic from defenition, Ok. First thing you must know: in Python, almost everything happens at runtime (the only error you might get at compile time is SyntaxError), and "import", "class" and "def" are actually executable statements. That is, when a module (or main program FWIW) is first loaded (directly for the main program, via an import statement for other modules), all the top-level code of the corresponding source file is executed sequentially. One of the implications is that there's no need for preprocessor directives - you just use Python code (at the module top-level) to have alternative versions of a function or conditional imports (which BTW are _not_ the same as #include directives ). Like: # somemodule.py import os if os.uname()[0] == "Linux": def somefunc(): return "this is the Linux version" else def somefunc(): return "this is not the Linux version" try: import some_module something = some_module.something else: # some_module not installed something = "default" # etc... To make a long story short: your notions of "definition" and "logic" don't really apply here. > but how do I keep different classes in > different files? You don't necessarily have to keep you class in "different files" - it really depends on the project's complexity. If you only have a couple classes, functions and (pseudo)constants, you just stick them either in the main program file (if it's a simple script) or in a module. If it gets a bit more complex, regroup classes and functions in distinct modules or packages trying to make each module (or package) as cohesive and decoupled as possible. Just have at look at the modules and packages in the stdlib to see what it may looks like. > My google-fu fails me so far. You were probably lokking for this: http://docs.python.org/tutorial/modules.html My two cents... From deets at nospam.web.de Wed Feb 4 16:55:48 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 04 Feb 2009 22:55:48 +0100 Subject: how to compile in jython 2.5b1?? In-Reply-To: <1d4d9261-6d0d-4312-8967-0fa13dc98e09@r10g2000prf.googlegroups.com> References: <6784ac72-0dbb-4904-b92b-3bee3418a233@r37g2000prr.googlegroups.com> <6uudorFh6dr4U1@mid.uni-berlin.de> <1d4d9261-6d0d-4312-8967-0fa13dc98e09@r10g2000prf.googlegroups.com> Message-ID: <6uuh74Fh26j9U1@mid.uni-berlin.de> ruelle schrieb: >> What do you need jythonc for? That's purely for a somewhat neater >> integration of *Java* with jython - nothing to do with sympy. >> >> Diez > > I need jythonc to compile a simple script in java, > this script import SymPy library. You need to find other ways. The usual approach to this is a factory-pattern with an embedded Jython-interpreter. There is the Jython-magazine that a couple of years ago brought a few examples of these techniques. They roughly work as this: - create a jython-file contains a jython-class subclassing/implementing some Java class or interface. - write a java-class that instantiates a jython interpreter - make that intepreter execute a small script (one-liner) to create one instance of that jython-class, and assigns it to a global variable. - fetch that variable's value from the interpreter-instance, and pass it to some java-code that works with it. This is working for nearly *all* use-cases, the exception only being rare casese where some Java-framework itself uses something like classForName to instantiate a class (e.g. struts for action-classes) But even then, you could simply create a java delegation class with the same recipe. There really is no need for the Jythonc, which is the reason it is discontinued I presume. Diez From aahz at pythoncraft.com Wed Feb 4 17:01:02 2009 From: aahz at pythoncraft.com (Aahz) Date: 4 Feb 2009 14:01:02 -0800 Subject: Understanding descriptors References: Message-ID: In article , Brian Allen Vanderburg II wrote: > > [...] > >When a lookup is done it uses this descriptor to make a bound or unbound >method: > >c=C() > >C.F # unbound method object, expects explicit instance when calling the >function >c.F # bound method object provides instance implicitly when calling the >function > >This is also done when adding to the classes: > >C.f1 = f1 > >f1 # function >C.f1 # unbound method >c.f1 # bound method > >To prevent this it has to be decorated so the descriptor doesn't cause >the binding: > >C.f2 = staticmethod(f1) >C.f2 # functon >c.f2 # function > >Here is a question, why don't instance attributes do the same thing? > >c.f3 = f1 >c.f3 # function, not bound method > >So it is not calling the __get__ method for c.f3 After it finds c.f3 in >c.__dict__, and since it has a getter, shouldn't it call the __get__ to >return the bound method. It is good that it doesn't I know, but I just >want to know why it doesn't from an implementation view. This is a bit beyond my expertise, but nobody else has responded, so I'll take a stab at it: Basically, this is part of the design philosphy that keeps everything working the same way. When an attribute is found on an instance, it gets returned unmodified. Period. In other words, the fact that f3 happens to return a function object gets ignored. You can force f3 to work like a bound method by defining it as one: def f3(self): pass If you use a new-style class or Python 3.0, the same design is evident when you try to use e.g. str() to call the __str__() special method: the instance gets ignored for looking up the method. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From bdesth.quelquechose at free.quelquepart.fr Wed Feb 4 17:01:14 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Wed, 04 Feb 2009 23:01:14 +0100 Subject: [Web 2.0] Added-value of frameworks? In-Reply-To: References: Message-ID: <498a1dc7$0$10675$426a74cc@news.free.fr> Gilles Ganault a ?crit : > Hello > > If I wanted to build some social web site such as Facebook, what do > frameworks like Django or TurboGears provide over writing a site from > scratch using Python? Quite a lot of abstractions and factorisation of the boilerplate code, a known way to organize your application, and possibly a good integration of the usual components (and wrt/ Django, a customizable yet fairly usable OOTB admin interface). For simple to mediumly complex applications, this can mean more than 80% of the grunt work. The counterpart is mostly learning and understanding the framework, which means you may not save that much time on a first project - but it can really pay off then. One of my coworker started this morning a (really simple...) project which acceptance tests are to begin on monday, and we are all quite confident he'll deliver on time, thanks to Django. From kyrie at uh.cu Wed Feb 4 17:13:31 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Wed, 4 Feb 2009 17:13:31 -0500 Subject: is python Object oriented?? In-Reply-To: References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> Message-ID: <200902041713.32118.kyrie@uh.cu> On Wednesday 04 February 2009 10:53:54 am Russ P. wrote: > On Feb 4, 5:35?am, Luis Zarrabeitia wrote: > > Quoting "Russ P." : > > This analogy is nonsense. There is no way you will execute code on my > > system if I don't authorize it, regardless of how "public" are the > > variables declared in my code. No one will execute code on _your_ system > > either, without your authorization. That puts you in a different > > position: you can easily _check_ that everything is alright before > > executing, whereas in the office example, it cannot be done. > > I don't follow your point, [...] > The locks on the doors are analogous to enforced access restrictions. And that is my point, nothing more, nothing less. They aren't analogous. I know a bit of python, and a bit of programming, and I think you do too. If you can't make your point without an analogy, isn't it perhaps that your point is not transferable from the analogy to the python context where you are trying to apply it?. You can control everything that happens in your systems, whatever those systems may be. There are no locks, no offices, no employees going unchecked. You can decide, at any time you want, if the code you are about to run meets your policies. The particular one you are talking about, the "data hiding", can be easily checked. By you, by the QA team, by a computer, by an automated system, by your own pseudo python interpreter that will run pylint against the code before trying to run it. Insert that into your office analogy, and maybe then situations will be a little more analogous. But keep in mind that the only difference between what you claim to want and what you currently have, is that _you_ (not me) can decide whether to use it or not. -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From joviyach at gmail.com Wed Feb 4 17:38:06 2009 From: joviyach at gmail.com (joviyach) Date: Wed, 4 Feb 2009 14:38:06 -0800 (PST) Subject: Upgrade 2.6 to 3.0 References: <669c42cc-4f4d-40be-b842-6f778959d391@f40g2000pri.googlegroups.com> Message-ID: <4bb62c09-d590-4065-90eb-f112aedd97df@d36g2000prf.googlegroups.com> On Feb 4, 2:43?pm, Scott David Daniels wrote: > joviyach wrote: > > I am fairly new to Python, the first version I loaded was 2.6. I have > > since downloaded 3.0 and I was wondering what the best practice for > > upgrading is? I am using Windows XP Pro for my OS. > > On Windows, X.Y.* all go in one directory (over-riding each other) > So the whole 2.6.* family should work just fine alongside the 3.0.* > family. ?In just a bit, 3.0.1 is coming soon, correcting some problems > in 3.0, so if you do install 3.0, check in a few weeks for an update. > The 2 -> 3 change was pretty substantial, so it will be a bit until the > 3.0 line gets lots of outside packages. > > --Scott David Daniels > Scott.Dani... at Acm.Org Thanks Scott, I will be lurking/hopefully contributing. From steve at holdenweb.com Wed Feb 4 17:38:23 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 04 Feb 2009 17:38:23 -0500 Subject: structs In-Reply-To: References: Message-ID: Keith Thompson wrote: > "Gary Herron" writes: >> Python *is* object-oriented > > I disagree. Care to provide proof of that statement? Disagree all you like. Just do it silently, please. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From andrew at acooke.org Wed Feb 4 17:49:51 2009 From: andrew at acooke.org (andrew cooke) Date: Wed, 4 Feb 2009 14:49:51 -0800 (PST) Subject: Structuring Modules with a Ubiquitous Base Class (Circular Dependencies) Message-ID: Is there a good solution to the following problem? I have a library whose components I would like to separate into distinct modules. These components inherit from a common base class that provides common functionality (the inheritance is important only for implementation; there's a separate ABC mechanism for typing). Now as that stands, there is no problem. Each module could import the common base class. Unfortunately the base class itself references many of the components (the reason for this is that supplies operator implementations (like __add__) which are shortcuts for the components themselves). This leads to a circular dependency - the base class wants to import the components, which in turn want to import the base class. Is there any standard solution to this? Thanks, Andrew From lionel.keene at gmail.com Wed Feb 4 17:51:17 2009 From: lionel.keene at gmail.com (Lionel) Date: Wed, 4 Feb 2009 14:51:17 -0800 (PST) Subject: Does array.read() move file pointer automatically? Message-ID: Hello everyone. Quick question: When using the "read()" method in the array module, must I redirect the current file pointer or will that occur automatically? For example, if I were to sequentially read data in chunks from a binary file as in: for currentChunk in range(numberOfChunksToRead): floatData = array.array('f') floatData.read(MyFileHandle, numberOfFloatsPerChunk) ...go to work on data... at each iteration of the "for" loop, will the next chunk of bytes be read into "floatData" or must I move the file pointer by calling "seek ()" or some function like that? Thanks everyone. L From Scott.Daniels at Acm.Org Wed Feb 4 17:53:07 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 04 Feb 2009 14:53:07 -0800 Subject: More on ancient pythons (before version 0.0?) Message-ID: <86udncDdhtd8hhfUnZ2dnUVZ_rHinZ2d@pdx.net> Apparently there is some fossil evidence of an early version of Python over 50 million years ago. Must have been some large negative version. It apparently suffered from serious code bloat, since the article says it was 13 meters long and over a megagram. http://news.bbc.co.uk/1/hi/sci/tech/7868588.stm I know, Titanoboa might not have actually been a python, but it may well have been a precursor to our Python. --Scott David Daniels Scott.Daniels at Acm.Org From lsumnler at gmail.com Wed Feb 4 18:06:00 2009 From: lsumnler at gmail.com (len) Date: Wed, 4 Feb 2009 15:06:00 -0800 (PST) Subject: How to find wxPython method documentation?? Message-ID: <10ead1a8-fc44-4392-b07d-54c00f0619f7@r36g2000prf.googlegroups.com> Hi I am going through the "wxPython in Action" book by Noel Rappin and Robin Dunn. I have been typing in the example programs as I go and play with modifing the code. Thought I should start trying to find my way around the documentation found on the wxPython web site. The problem I have been having is I can't find the methods or more specifically 'SetBackgroundColour' or 'AddSimpleTool' for example. How does one find the methods that are available in the classes. I tried looking at the wxWidgets web site and still had the same problem. Could someone give me a little direction in this? Thanks Len From google at mrabarnett.plus.com Wed Feb 4 18:10:39 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 04 Feb 2009 23:10:39 +0000 Subject: Does array.read() move file pointer automatically? In-Reply-To: References: Message-ID: <498A206F.7090501@mrabarnett.plus.com> Lionel wrote: > Hello everyone. Quick question: When using the "read()" method in the > array module, must I redirect the current file pointer or will that > occur automatically? > > For example, if I were to sequentially read data in chunks from a > binary file as in: > > > for currentChunk in range(numberOfChunksToRead): > > floatData = array.array('f') > floatData.read(MyFileHandle, numberOfFloatsPerChunk) > ...go to work on data... > > > at each iteration of the "for" loop, will the next chunk of bytes be > read into "floatData" or must I move the file pointer by calling "seek > ()" or some function like that? > The read() method has been deprecated since version Python 1.5.1. Use the fromfile() method instead. It will advance the file pointer. From andrew at acooke.org Wed Feb 4 18:12:58 2009 From: andrew at acooke.org (andrew cooke) Date: Wed, 4 Feb 2009 15:12:58 -0800 (PST) Subject: Structuring Modules with a Ubiquitous Base Class (Circular Dependencies) References: Message-ID: On Feb 4, 7:49?pm, andrew cooke wrote: > This leads to a circular dependency - the base class wants to import > the components, which in turn want to import the base class. > > Is there any standard solution to this? well, to partially answer my own question, this is certainly possible. in the general case it might get quite complex, but for the structure described it is quite simple. the 'trick' is to import the component in the *method* of the common base class. for example: class Base(object): def __init__(self): from first import First from second import Second self.first = lambda *args: First(*args) self.second = lambda *args: Second(*args) where First, defined in first, subclasses Base in the normal way. however, i suspect this will have a performance hit, since "linking" is being done at "run time" rather than "compile time". anyone have any guidance on how serious that would be? i guess it could be ameliorated by doing the work in the constructor (as above, which is just that way for a compact example - in "real life" the components are used in a more complex manner). and i still suspect there is a more efficient metaclass or similar approach. andrew From lionel.keene at gmail.com Wed Feb 4 18:37:11 2009 From: lionel.keene at gmail.com (Lionel) Date: Wed, 4 Feb 2009 15:37:11 -0800 (PST) Subject: Does array.read() move file pointer automatically? References: Message-ID: On Feb 4, 3:10?pm, MRAB wrote: > Lionel wrote: > > ?> Hello everyone. Quick question: When using the "read()" method in the > ?> array module, must I redirect the current file pointer or will that > ?> occur automatically? > ?> > ?> For example, if I were to sequentially read data in chunks from a > ?> binary file as in: > ?> > ?> > ?> for currentChunk in range(numberOfChunksToRead): > ?> > ?> ? ? ? ?floatData = array.array('f') > ?> ? ? ? ?floatData.read(MyFileHandle, numberOfFloatsPerChunk) > ?> ? ? ? ?...go to work on data... > ?> > ?> > ?> at each iteration of the "for" loop, will the next chunk of bytes be > ?> read into "floatData" or must I move the file pointer by calling "seek > ?> ()" or some function like that? > ?> > The read() method has been deprecated since version Python 1.5.1. Use > the fromfile() method instead. > > It will advance the file pointer. Thank you, I'll change it. On a related matter, I seem to be making a mistake somewhere in the way I'm importing and using modules (in particular the "array" module). The following code generates an error (traceback message follows code): import pdb import array from numpy import * class MyClass: def __init__(self, initialData): test = array.array('f') # Trigger error message The traceback message is: test = array.array('f') AttributeError: 'builtin_function_or_method' object has no attribute 'array' According to the Python 2.5 documentation for the "array" module it does have an "array" method. I'm closely following examples I've found online (here, for ex: http://www.python.org/search/hypermail/python-1993/0393.html) but don't see my error. This error goes away if I change the import statement to: import pdb from array import * from numpy import * and the instruction to test = array('f') but then I get another error (sorry I don't have it handy) that implies Python is interpreting the object returned from "array('f')" as a numpy.ndarray object. Something I'm doing is causing ambiguity it seems. Anyone? As always, thank you for the help. L From andrew at acooke.org Wed Feb 4 18:49:00 2009 From: andrew at acooke.org (andrew cooke) Date: Wed, 4 Feb 2009 15:49:00 -0800 (PST) Subject: How to find wxPython method documentation?? References: <10ead1a8-fc44-4392-b07d-54c00f0619f7@r36g2000prf.googlegroups.com> Message-ID: <5ef6e64b-1468-4ee2-8261-3ba027ca5370@p2g2000prf.googlegroups.com> On Feb 4, 8:06?pm, len wrote: > How does one find the methods that are available in the classes. heh. welcome to the wonderful world of wxpython :o( if you use eclipse to edit your code, then (providing the wind is in the right direction and the file you are editing doesn't have any syntax errors) pressing F3 when you are on a particular method will take you to the definition. or, at least, one of the definitions with that name. and if you want to see a list of available methods the simplest way is to use tab completion (or dir() in python itself). if you're not using eclipse (with pydev) check to see if the ide/ editor you are using has something similar. also, wxpython comes with some examples, all packaged in a demo program. that is your best source of documentation. go through all the examples in there and look at the code (the demo program will show you the code and even let you edit it and see the results of your changes). to be honest, wxpython is a bit of a nightmare (imho). but the results can be worth it. good luck, andrew From rhodri at wildebst.demon.co.uk Wed Feb 4 19:09:08 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 05 Feb 2009 00:09:08 -0000 Subject: Use list name as string In-Reply-To: <77e831100902040923k188e5df3q22423884f239e5a5@mail.gmail.com> References: <77e831100902040824q2a0b8465k4894f29ed4baba12@mail.gmail.com> <4989C6D0.2000604@tim.thechases.com> <77e831100902040857q2379bf80hc05b5575cba85bdd@mail.gmail.com> <4989CB47.3060806@mrabarnett.plus.com> <77e831100902040918j4be325d3y760120c92f8a0d7f@mail.gmail.com> <77e831100902040923k188e5df3q22423884f239e5a5@mail.gmail.com> Message-ID: On Wed, 04 Feb 2009 17:23:55 -0000, Vincent Davis wrote: > I guess what I am saying is that it does not seem like I am adding any > information that is not already there when I have to enter that list and > list name after all they are the same. > Thanks But you are. Consider just for a moment what happens when you execute savedata([1, 2, 3, 55]). Fundamentally, the concept of a single unique name for any object isn't something built into the language (or, indeed, most languages I can think of). An object can have no names (though it'll promptly get garbage collected if it isn't assigned to a name somehow), or just as easily one or many names. -- Rhodri James *-* Wildebeeste Herder to the Masses From digitig at gmail.com Wed Feb 4 19:14:22 2009 From: digitig at gmail.com (Tim Rowe) Date: Thu, 5 Feb 2009 00:14:22 +0000 Subject: Couple of noobish question In-Reply-To: <498a1b1d$0$24204$426a74cc@news.free.fr> References: <498a1b1d$0$24204$426a74cc@news.free.fr> Message-ID: 2009/2/4 Bruno Desthuilliers : > # somemodule.py > > import os > > if os.uname()[0] == "Linux": On an MS Windows system, os.uname()[0] raises an AttributeError -- sys doesn't seem to contain uname. Is that a Linux thing? Would os.name work on Linux? Or would one have to use exception handling and catch the Windows case? That's the trouble with using anything in os, of course -- it's os dependent, which is why it's there! :-) -- Tim Rowe From digitig at gmail.com Wed Feb 4 19:18:03 2009 From: digitig at gmail.com (Tim Rowe) Date: Thu, 5 Feb 2009 00:18:03 +0000 Subject: Upgrade 2.6 to 3.0 In-Reply-To: References: <669c42cc-4f4d-40be-b842-6f778959d391@f40g2000pri.googlegroups.com> Message-ID: 2009/2/4 Scott David Daniels : > joviyach wrote: >> >> I am fairly new to Python, the first version I loaded was 2.6. I have >> since downloaded 3.0 and I was wondering what the best practice for >> upgrading is? I am using Windows XP Pro for my OS. > > On Windows, X.Y.* all go in one directory (over-riding each other) > So the whole 2.6.* family should work just fine alongside the 3.0.* Just don't try to have a 2.6 version of Idle and a 3.0 version of Idle running at the same time! 2.6 WinPy and 3.0 Idle seem to coexist ok, which is handy when I'm trying to get to grips with the differences between versions.. -- Tim Rowe From Scott.Daniels at Acm.Org Wed Feb 4 19:29:37 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 04 Feb 2009 16:29:37 -0800 Subject: sys.float_info.epsilon In-Reply-To: References: Message-ID: I wrote: > You are missing the whole thing that mes floating point tricky.... > The reason it is tough is that addition is not associative in real > numbers, and associativity is at the core > of a lot of proofs in > arithmetic (and group theory). In response to which Tim Rowe wrote: > ... Thanks for that. It makes me feel guilty to point out that: > > addition is not associative in real numbers > should presumably be "addition is not associative in floating point numbers". And, of course he is right (and didn't even whomp on my typo of "makes" as "mes in the first line quoted above). --Scott David Daniels Scott.Daniels at Acm.Org From afriere at yahoo.co.uk Wed Feb 4 19:31:24 2009 From: afriere at yahoo.co.uk (afriere at yahoo.co.uk) Date: Wed, 4 Feb 2009 16:31:24 -0800 (PST) Subject: Couple of noobish question References: <498a1b1d$0$24204$426a74cc@news.free.fr> Message-ID: On Feb 5, 11:14?am, Tim Rowe wrote: ... > On an MS Windows system, os.uname()[0] raises an AttributeError -- sys > doesn't seem to contain uname. Is that a Linux thing? Would os.name > work on Linux? Or would one have to use exception handling and catch > the Windows case? It seems to be a Windows thing. My Linux box gives me 'Linux' the server gives me 'SunOS' and a Mac tells me 'Darwin'. I'm still running Python2.4 on the Windows box. At least in that version on the OS, the 'os' module has no attribute 'uname', On both Linux and SunOS, os.name returns 'posix'. From mdw at distorted.org.uk Wed Feb 4 19:35:45 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 05 Feb 2009 00:35:45 +0000 Subject: structs References: Message-ID: <87zlh1lnz2.fsf.mdw@metalzone.distorted.org.uk> Keith Thompson writes: > "Gary Herron" writes: >> Python *is* object-oriented > > I disagree. Care to provide proof of that statement? AWOOGA! The article I'm following up to (together with at least one other) is a forgery, and the Followup-To header is set to comp.lang.c as part of an effort to (a) disrupt that newsgroup, and (b) discredit Keith Thompson, who is a respected and capable contributor to that group. This is a request to other readers to take special care over responding to controversial articles, and particularly to watch for strange Followup-To headers. Thanks for listening. -- [mdw] From digitig at gmail.com Wed Feb 4 19:36:52 2009 From: digitig at gmail.com (Tim Rowe) Date: Thu, 5 Feb 2009 00:36:52 +0000 Subject: sys.float_info.epsilon In-Reply-To: References: Message-ID: 2009/2/5 Scott David Daniels : > And, of course he is right (and didn't even whomp on my typo of "makes" > as "mes in the first line quoted above). A typo for "makes" didn't bother me. Non-associativity of the real numbers under addition risked making my whole world fall apart :-) -- Tim Rowe From digitig at gmail.com Wed Feb 4 19:45:56 2009 From: digitig at gmail.com (Tim Rowe) Date: Thu, 5 Feb 2009 00:45:56 +0000 Subject: Couple of noobish question In-Reply-To: References: <498a1b1d$0$24204$426a74cc@news.free.fr> Message-ID: 2009/2/5 : > On Feb 5, 11:14 am, Tim Rowe wrote: > > ... > >> On an MS Windows system, os.uname()[0] raises an AttributeError -- sys >> doesn't seem to contain uname. Is that a Linux thing? Would os.name >> work on Linux? Or would one have to use exception handling and catch >> the Windows case? > > It seems to be a Windows thing. My Linux box gives me 'Linux' the > server gives me 'SunOS' and a Mac tells me 'Darwin'. I'm still > running Python2.4 on the Windows box. At least in that version on the > OS, the 'os' module has no attribute 'uname', On both Linux and > SunOS, os.name returns 'posix'. Python in a Nutshell states that os.uname "exists only on certain platforms", and in the code sample wraps it in a try statement. That seems to be the safe way to go -- except (and I don't know much about this) wouldn't code have to be digging into some pretty obscure corners to find a difference between different posix implementations? -- Tim Rowe From todpose at hotmail.com Wed Feb 4 20:02:48 2009 From: todpose at hotmail.com (todpose at hotmail.com) Date: Wed, 4 Feb 2009 17:02:48 -0800 Subject: Using while loop and if statement to tell if a binary has an odd or even number of 1's. Message-ID: Using while loop and if statement, I'm trying to get Python to tell me whether there are even or odd number of 1's in a binary representation. For example, if I give Python a 00000111, then I want it to say that the binary representation given has an odd number of 1's. If I give it 00010111, then it will tell me that there is an even number of 1's. I'd appreciate any suggestion. Thanks! _________________________________________________________________ So many new options, so little time. Windows Live Messenger. http://www.microsoft.com/windows/windowslive/messenger.aspx -------------- next part -------------- An HTML attachment was scrubbed... URL: From google at mrabarnett.plus.com Wed Feb 4 20:10:49 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 05 Feb 2009 01:10:49 +0000 Subject: Does array.read() move file pointer automatically? In-Reply-To: References: Message-ID: <498A3C99.5090208@mrabarnett.plus.com> Lionel wrote: > On Feb 4, 3:10 pm, MRAB wrote: >> Lionel wrote: >> >> > Hello everyone. Quick question: When using the "read()" method in the >> > array module, must I redirect the current file pointer or will that >> > occur automatically? >> > >> > For example, if I were to sequentially read data in chunks from a >> > binary file as in: >> > >> > >> > for currentChunk in range(numberOfChunksToRead): >> > >> > floatData = array.array('f') >> > floatData.read(MyFileHandle, numberOfFloatsPerChunk) >> > ...go to work on data... >> > >> > >> > at each iteration of the "for" loop, will the next chunk of bytes be >> > read into "floatData" or must I move the file pointer by calling "seek >> > ()" or some function like that? >> > >> The read() method has been deprecated since version Python 1.5.1. Use >> the fromfile() method instead. >> >> It will advance the file pointer. > > Thank you, I'll change it. On a related matter, I seem to be making a > mistake somewhere in the way I'm importing and using modules (in > particular the "array" module). > > The following code generates an error (traceback message follows > code): > > import pdb > import array > from numpy import * > [snip] I think that numpy has a class called "array", so the "import *" will result in the name "array" binding to that, thus hiding the module called "array" that you've only just imported! From cosmo_general at yahoo.com Wed Feb 4 20:16:00 2009 From: cosmo_general at yahoo.com (Muddy Coder) Date: Wed, 4 Feb 2009 17:16:00 -0800 (PST) Subject: How to trigger a smart link? Message-ID: <757efced-1082-43d8-8a39-5752e1b5bc4f@i20g2000prf.googlegroups.com> Hi All, Using urllib2 can trigger CGI script in server side. However, I encountered a problem of the so-called smart link. When a fairly large site, the server needs to track the identifier of each request from client, so it generated an ugly escape string attached on url. It seems that I must get this ugly escape string first then I can can fill the string into my url, and the CGI script on server side can be triggered. For example, http://whatever.com/submitreal.cgi?fp=3xD0TuGMp7C7gP1TRD displays a submit form. If I just copy http://whatever.com/submitreal.cgi to url address, without the escape string ?fp=3xD0TuGMp7C7gP1TRD, the browser will report error of 404 I found Python has a module of escape, but I don't know how to use this module to solve the problem above. Or, I just wonder does urllib2 has such a method to handle smart link? Thanks! Moddy Coder From clp2 at rebertia.com Wed Feb 4 20:18:25 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 4 Feb 2009 17:18:25 -0800 Subject: Using while loop and if statement to tell if a binary has an odd or even number of 1's. In-Reply-To: References: Message-ID: <50697b2c0902041718h5616c78p3420762fd546df3e@mail.gmail.com> On Wed, Feb 4, 2009 at 5:02 PM, todpose at hotmail.com wrote: > Using while loop and if statement, I'm trying to get Python to tell me > whether there are even or odd number of 1's in a binary representation. > For example, if I give Python a 00000111, then I want it to say that the > binary representation given has an odd number of 1's. > If I give it 00010111, then it will tell me that there is an even number of > 1's. > I'd appreciate any suggestion. Please define "binary representation". Do you mean a sequence of bytes, an integer, a string of 0s and 1s, or something else entirely? If it's a string of 0s and 1s, then: is_even = zerosones.count('1') % 2 == 0 For an integer: is_even = bin(the_int)[2:].count('1') % 2 == 0 For the others, I don't know offhand. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From matzke at berkeley.edu Wed Feb 4 20:20:06 2009 From: matzke at berkeley.edu (Nick Matzke) Date: Wed, 04 Feb 2009 17:20:06 -0800 Subject: Comparing two book chapters (text files) Message-ID: <498A3EC6.4040607@berkeley.edu> Hi all, So I have an interesting challenge. I want to compare two book chapters, which I have in plain text format, and find out (a) percentage similarity and (b) what has changed. Some features make this problem different than what seems to be the standard text-matching problem solvable with e.g. difflib. Here is what I mean: * there is no guarantee that single lines from each file will be directly comparable -- e.g., if a few words are inserted into a sentence, then a chunk of the sentence will be moved to the next line, then a chunk of that line moved to the next, etc. * Also, there are cases where paragraphs have been moved around, sections re-ordered, etc. So it can't just be a "linear" match. I imagine this kind of thing can't be all that hard in the grand scheme of things, but I couldn't find an easily applicable solution readily available. I have advanced beginner python skills but am not quite where I could do this kind of thing from scratch without some guidance about the likely functions, libraries etc. to use. PS: I am going to have to do this for multiple book chapters so various software packages, e.g. for windows, are not really usable. Any help is much appreciated!! Cheers, Nick -- ==================================================== Nicholas J. Matzke Ph.D. student, Graduate Student Researcher Huelsenbeck Lab Center for Theoretical Evolutionary Genomics 4151 VLSB (Valley Life Sciences Building) Department of Integrative Biology University of California, Berkeley Lab websites: http://ib.berkeley.edu/people/lab_detail.php?lab=54 http://fisher.berkeley.edu/cteg/hlab.html Dept. personal page: http://ib.berkeley.edu/people/students/person_detail.php?person=370 Lab personal page: http://fisher.berkeley.edu/cteg/members/matzke.html Lab phone: 510-643-6299 Dept. fax: 510-643-6264 Cell phone: 510-301-0179 Email: matzke at berkeley.edu Mailing address: Department of Integrative Biology 3060 VLSB #3140 Berkeley, CA 94720-3140 ----------------------------------------------------- "[W]hen people thought the earth was flat, they were wrong. When people thought the earth was spherical, they were wrong. But if you think that thinking the earth is spherical is just as wrong as thinking the earth is flat, then your view is wronger than both of them put together." Isaac Asimov (1989). "The Relativity of Wrong." The Skeptical Inquirer, 14(1), 35-44. Fall 1989. http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm ==================================================== From todpose at hotmail.com Wed Feb 4 20:23:46 2009 From: todpose at hotmail.com (todpose at hotmail.com) Date: Wed, 4 Feb 2009 17:23:46 -0800 Subject: Using while loop and if statement to tell if a binary has an odd or even number of 1's. In-Reply-To: <50697b2c0902041718h5616c78p3420762fd546df3e@mail.gmail.com> References: <50697b2c0902041718h5616c78p3420762fd546df3e@mail.gmail.com> Message-ID: By "binary representation", I mean a byte of 0s and 1s. Example: 00000101 Also, I'm interested in only using while loop and if statement to accomplish this task. Thanks.> Date: Wed, 4 Feb 2009 17:18:25 -0800> Subject: Re: Using while loop and if statement to tell if a binary has an odd or even number of 1's.> From: clp2 at rebertia.com> To: todpose at hotmail.com> CC: python-list at python.org> > On Wed, Feb 4, 2009 at 5:02 PM, todpose at hotmail.com wrote:> > Using while loop and if statement, I'm trying to get Python to tell me> > whether there are even or odd number of 1's in a binary representation.> > For example, if I give Python a 00000111, then I want it to say that the> > binary representation given has an odd number of 1's.> > If I give it 00010111, then it will tell me that there is an even number of> > 1's.> > I'd appreciate any suggestion.> > Please define "binary representation". Do you mean a sequence of> bytes, an integer, a string of 0s and 1s, or something else entirely?> > If it's a string of 0s and 1s, then:> is_even = zerosones.count('1') % 2 == 0> > For an integer:> is_even = bin(the_int)[2:].count('1') % 2 == 0> > For the others, I don't know offhand.> > Cheers,> Chris> > -- > Follow the path of the Iguana...> http://rebertia.com _________________________________________________________________ The new Windows Live Messenger. You don?t want to miss this. http://www.microsoft.com/windows/windowslive/messenger.aspx -------------- next part -------------- An HTML attachment was scrubbed... URL: From digitig at gmail.com Wed Feb 4 20:25:50 2009 From: digitig at gmail.com (Tim Rowe) Date: Thu, 5 Feb 2009 01:25:50 +0000 Subject: Using while loop and if statement to tell if a binary has an odd or even number of 1's. In-Reply-To: References: Message-ID: 2009/2/5 todpose at hotmail.com : > Using while loop and if statement, I'm trying to get Python to tell me > whether there are even or odd number of 1's in a binary representation. > For example, if I give Python a 00000111, then I want it to say that the > binary representation given has an odd number of 1's. > If I give it 00010111, then it will tell me that there is an even number of > 1's. > I'd appreciate any suggestion. > Thanks! Looks like homework to me, so I'll just give a couple of suggestions. If you're going to prompt the user for the number, you'll get a string back, and that might be easier to work with than a number. So you need to set a boolean value for the result, something like: even = True (because so far you've seen zero 1's, and zero is even). Then you need to loop over each character in the string -- there's your loop -- and if (there's your if) it's a "1" change the truth value of even: even = !even. If it is a number rather than a string, you want to do much the same thing but you'll need the >> and & operators. Chris has already shown you how this would actually be done in Python, but that doesn't match your assignment description. -- Tim Rowe From clp2 at rebertia.com Wed Feb 4 20:27:38 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 4 Feb 2009 17:27:38 -0800 Subject: How to trigger a smart link? In-Reply-To: <757efced-1082-43d8-8a39-5752e1b5bc4f@i20g2000prf.googlegroups.com> References: <757efced-1082-43d8-8a39-5752e1b5bc4f@i20g2000prf.googlegroups.com> Message-ID: <50697b2c0902041727l463235c9pe1fdc55d1ee02942@mail.gmail.com> On Wed, Feb 4, 2009 at 5:16 PM, Muddy Coder wrote: > Hi All, > > Using urllib2 can trigger CGI script in server side. However, I > encountered a problem of the so-called smart link. When a fairly large > site, the server needs to track the identifier of each request from > client, so it generated an ugly escape string attached on url. It > seems that I must get this ugly escape string first then I can can > fill the string into my url, and the CGI script on server side can be > triggered. For example, > > http://whatever.com/submitreal.cgi?fp=3xD0TuGMp7C7gP1TRD > > displays a submit form. If I just copy > > http://whatever.com/submitreal.cgi > > to url address, without the escape string ?fp=3xD0TuGMp7C7gP1TRD, the > browser will report error of 404 > > I found Python has a module of escape, but I don't know how to use > this module to solve the problem above. Or, I just wonder does urllib2 > has such a method to handle smart link? Thanks! I think you'll need to fetch whatever webpage contains the link with the magic URL, and then use an HTML parser (e.g. BeautifulSoup or lxml) to parse the URL out of the page. Then just fetch the URL you obtained. I doubt you can just generate the escape string yourself, you need the cooperation of the CGI script on the other end; hence the need to fetch the known page. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From david at boddie.org.uk Wed Feb 4 20:27:49 2009 From: david at boddie.org.uk (David Boddie) Date: Thu, 05 Feb 2009 02:27:49 +0100 Subject: Cross platform compilation? References: Message-ID: On Tuesday 03 February 2009 03:59, John Harper wrote: > Before I try to reverse engineer completely setup.py, is there > something obvious that needs to be done to get it to use the right tool > chain? I think it's more complicated than that, though in an ideal world it wouldn't have to be that way. I created some patches for Python 2.4.4 a while ago to make it slightly easier to cross-compile it: http://chaos.troll.no/~dboddie/Python/Greenphone/ There were patches to solve similar issues with the build system floating around in the Python bug tracker. I had intended to help push those along a bit, but lack of time prevented me from doing so. The magic incantation that worked for me was this: export HOST_PLATFORM=i386 export TARGET_TOOLS=$SOME_DIR/gcc-4.1.1-glibc-2.3.6/arm-linux/bin export TARGET_PLATFORM=arm-linux CC=$TARGET_TOOLS/$TARGET_PLATFORM-gcc \ CXX=$TARGET_TOOLS/$TARGET_PLATFORM-g++ \ ./configure --prefix=$TARGETDIR --enable-shared --enable-unicode=ucs4 \ --build=$TARGET_PLATFORM --host=$HOST_PLATFORM where SOME_DIR and TARGETDIR are appropriately set, of course. I did experience issues with some extension modules, though. > More generally, it seems like this would be something that lots of > people would want to do. I'm surprised there isn't support for it built > into the distributed version of Python, without having to hack all the > setup files...? I suppose people don't explicitly configure projects for cross-compilation anymore, especially now that things like Scratchbox are used to fake the build environment: http://www.scratchbox.org/ That might also be worth looking at, but you really have to buy in to its way of working to use it fully, in my experience. David From todpose at hotmail.com Wed Feb 4 20:28:06 2009 From: todpose at hotmail.com (todpose at hotmail.com) Date: Wed, 4 Feb 2009 17:28:06 -0800 Subject: Feet and inches Message-ID: I'm trying to get Python to say: Enter the height (in metres): and convert whatever value to feet and inches. I've done this part as you can see below, but how can I terminate the program when user inputs a height less than 1/2 inch? How can I also take into account all the cases that need an exception? metres = float(raw_input("Enter the height (in metres): "))total_inches = 39.37 * metresfeet = int(total_inches/12)inches = int(round(total_inches - feet*12))if feet>=1: print "It is " + str(feet) + " feet " + str(inches) + ' inches high.'if feet<1 and inches<0.5: print "Error." _________________________________________________________________ Windows Live Messenger. Multitasking at its finest. http://www.microsoft.com/windows/windowslive/messenger.aspx -------------- next part -------------- An HTML attachment was scrubbed... URL: From gnewsg at gmail.com Wed Feb 4 20:36:01 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Wed, 4 Feb 2009 17:36:01 -0800 (PST) Subject: Upgrade 2.6 to 3.0 References: <669c42cc-4f4d-40be-b842-6f778959d391@f40g2000pri.googlegroups.com> Message-ID: <2ba4f763-79fa-423e-b082-f9de829ae964@i20g2000prf.googlegroups.com> On 5 Feb, 01:18, Tim Rowe wrote: > 2009/2/4 Scott David Daniels : > > > joviyach wrote: > > >> I am fairly new to Python, the first version I loaded was 2.6. I have > >> since downloaded 3.0 and I was wondering what the best practice for > >> upgrading is? I am using Windows XP Pro for my OS. > > > On Windows, X.Y.* all go in one directory (over-riding each other) > > So the whole 2.6.* family should work just fine alongside the 3.0.* > > Just don't try to have a 2.6 version of Idle and a 3.0 version of Idle > running at the same time! 2.6 WinPy and 3.0 Idle seem to coexist ok, > which is handy when I'm trying to get to grips with the differences > between versions.. > > -- > Tim Rowe Just out of curiosity, am I the only one who think that switching to 3.x right now is not a good idea? --- Giampaolo http://code.google.com/p/pyftpdlib From vincent at vincentdavis.net Wed Feb 4 20:36:17 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Wed, 4 Feb 2009 18:36:17 -0700 Subject: Use list name as string In-Reply-To: References: <77e831100902040824q2a0b8465k4894f29ed4baba12@mail.gmail.com> <4989C6D0.2000604@tim.thechases.com> <77e831100902040857q2379bf80hc05b5575cba85bdd@mail.gmail.com> <4989CB47.3060806@mrabarnett.plus.com> <77e831100902040918j4be325d3y760120c92f8a0d7f@mail.gmail.com> <77e831100902040923k188e5df3q22423884f239e5a5@mail.gmail.com> Message-ID: <77e831100902041736w5194b59dubdd922c80dd82ece@mail.gmail.com> if I start with M = [1,3,5,7] M is [1,3,5,7] This seems one way, as [1,3,5,7] is not M in the sense that there is no operation I can preform on [1,3,5,7] and get M back. Other than asking/testing M==[1,3,5,7] This seems fine to me. but when I savedata(M) it seems I should be able to refer to both [1,3,5,7] and "M", "I mean I did just type it why type it again) My argument comes down to; we use M so we don't have to type [1,3,5,7], I realize that this is in part because we might not no what M will be. This is starting to sound like double talk on my part, I have only been programing in python for 2 weeks so my credibility is only that of an outside that MAY have a reasonable way of thinking of this or at least a feature I would like. Thanks for the comments by the way what is "**kwargs" I can't find any documentation on this? Thanks Vincent Davis On Wed, Feb 4, 2009 at 5:09 PM, Rhodri James wrote: > On Wed, 04 Feb 2009 17:23:55 -0000, Vincent Davis > wrote: > >> I guess what I am saying is that it does not seem like I am adding any >> information that is not already there when I have to enter that list and >> list name after all they are the same. >> Thanks > > But you are. Consider just for a moment what happens when you execute > savedata([1, 2, 3, 55]). > > Fundamentally, the concept of a single unique name for any object isn't > something built into the language (or, indeed, most languages I can think > of). An object can have no names (though it'll promptly get garbage > collected if it isn't assigned to a name somehow), or just as easily > one or many names. > > -- > Rhodri James *-* Wildebeeste Herder to the Masses > -- > http://mail.python.org/mailman/listinfo/python-list > From lionel.keene at gmail.com Wed Feb 4 20:39:01 2009 From: lionel.keene at gmail.com (Lionel) Date: Wed, 4 Feb 2009 17:39:01 -0800 (PST) Subject: Does array.read() move file pointer automatically? References: Message-ID: On Feb 4, 5:10?pm, MRAB wrote: > Lionel wrote: > > ?> On Feb 4, 3:10 pm, MRAB wrote:?>> Lionel wrote: > > ?>> > ?>> ?> Hello everyone. Quick question: When using the "read()" method in the > ?>> ?> array module, must I redirect the current file pointer or will that > ?>> ?> occur automatically? > ?>> ?> > ?>> ?> For example, if I were to sequentially read data in chunks from a > ?>> ?> binary file as in: > ?>> ?> > ?>> ?> > ?>> ?> for currentChunk in range(numberOfChunksToRead): > ?>> ?> > ?>> ?> ? ? ? ?floatData = array.array('f') > ?>> ?> ? ? ? ?floatData.read(MyFileHandle, numberOfFloatsPerChunk) > ?>> ?> ? ? ? ?...go to work on data... > ?>> ?> > ?>> ?> > ?>> ?> at each iteration of the "for" loop, will the next chunk of bytes be > ?>> ?> read into "floatData" or must I move the file pointer by calling > "seek > ?>> ?> ()" or some function like that? > ?>> ?> > ?>> The read() method has been deprecated since version Python 1.5.1. Use > ?>> the fromfile() method instead. > ?>> > ?>> It will advance the file pointer. > ?> > ?> Thank you, I'll change it. On a related matter, I seem to be making a > ?> mistake somewhere in the way I'm importing and using modules (in > ?> particular the "array" module). > ?> > ?> The following code generates an error (traceback message follows > ?> code): > ?> > ?> import pdb > ?> import array > ?> from numpy import * > ?> > [snip] > I think that numpy has a class called "array", so the "import *" will > result in the name "array" binding to that, thus hiding the module > called "array" that you've only just imported! I believe that's correct. I've gotten it to work by changing the import statements to: import pdb import array import numpy and then I qualify the module specific attributes as either "numpy.SomeAttribute" or "array.SomeAttribute" to avoid this namespace ambiguity. Thanks for the input! L From clp2 at rebertia.com Wed Feb 4 20:39:28 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 4 Feb 2009 17:39:28 -0800 Subject: Using while loop and if statement to tell if a binary has an odd or even number of 1's. In-Reply-To: References: <50697b2c0902041718h5616c78p3420762fd546df3e@mail.gmail.com> Message-ID: <50697b2c0902041739m726936f2w33138add2ffd1f14@mail.gmail.com> A "byte" is *not* a Python type. My question was what *Python type* (i.e. bytes (which is distinctly different from the abstract notion of a byte), str/unicode, int, etc...) you were using for you "binary representation", which you still haven't answered. Also, please don't reply by top-posting (http://en.wikipedia.org/wiki/Top_post#Top-posting), it's bad netiquette. I'm only doing it in this message for consistency. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com On Wed, Feb 4, 2009 at 5:23 PM, todpose at hotmail.com wrote: > By "binary representation", I mean a byte of 0s and 1s. Example: 00000101 > Also, I'm interested in only using while loop and if statement to accomplish > this task. > Thanks. > >> Date: Wed, 4 Feb 2009 17:18:25 -0800 >> Subject: Re: Using while loop and if statement to tell if a binary has an >> odd or even number of 1's. >> From: clp2 at rebertia.com >> To: todpose at hotmail.com >> CC: python-list at python.org >> >> On Wed, Feb 4, 2009 at 5:02 PM, todpose at hotmail.com >> wrote: >> > Using while loop and if statement, I'm trying to get Python to tell me >> > whether there are even or odd number of 1's in a binary representation. >> > For example, if I give Python a 00000111, then I want it to say that the >> > binary representation given has an odd number of 1's. >> > If I give it 00010111, then it will tell me that there is an even number >> > of >> > 1's. >> > I'd appreciate any suggestion. >> >> Please define "binary representation". Do you mean a sequence of >> bytes, an integer, a string of 0s and 1s, or something else entirely? >> >> If it's a string of 0s and 1s, then: >> is_even = zerosones.count('1') % 2 == 0 >> >> For an integer: >> is_even = bin(the_int)[2:].count('1') % 2 == 0 >> >> For the others, I don't know offhand. >> >> Cheers, >> Chris >> >> -- >> Follow the path of the Iguana... >> http://rebertia.com > > > ________________________________ > The new Windows Live Messenger. You don't want to miss this. > -- > http://mail.python.org/mailman/listinfo/python-list > > From crebert at ucsd.edu Wed Feb 4 20:41:41 2009 From: crebert at ucsd.edu (Chris Rebert) Date: Wed, 4 Feb 2009 17:41:41 -0800 Subject: Comparing two book chapters (text files) In-Reply-To: <498A3EC6.4040607@berkeley.edu> References: <498A3EC6.4040607@berkeley.edu> Message-ID: <50697b2c0902041741w3ad7365ay8dbcab7b9cc3216e@mail.gmail.com> On Wed, Feb 4, 2009 at 5:20 PM, Nick Matzke wrote: > Hi all, > > So I have an interesting challenge. I want to compare two book chapters, > which I have in plain text format, and find out (a) percentage similarity > and (b) what has changed. > > Some features make this problem different than what seems to be the standard > text-matching problem solvable with e.g. difflib. Here is what I mean: > > * there is no guarantee that single lines from each file will be directly > comparable -- e.g., if a few words are inserted into a sentence, then a > chunk of the sentence will be moved to the next line, then a chunk of that > line moved to the next, etc. > > * Also, there are cases where paragraphs have been moved around, sections > re-ordered, etc. So it can't just be a "linear" match. > > I imagine this kind of thing can't be all that hard in the grand scheme of > things, but I couldn't find an easily applicable solution readily available. > I have advanced beginner python skills but am not quite where I could do > this kind of thing from scratch without some guidance about the likely > functions, libraries etc. to use. > > PS: I am going to have to do this for multiple book chapters so various > software packages, e.g. for windows, are not really usable. Though not written in Python, wdiff (http://www.gnu.org/software/wdiff/wdiff.html) might be a good starting point. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From python.list at tim.thechases.com Wed Feb 4 20:43:15 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 04 Feb 2009 19:43:15 -0600 Subject: Using while loop and if statement to tell if a binary has an odd or even number of 1's. In-Reply-To: References: Message-ID: <498A4433.7070600@tim.thechases.com> > Using while loop and if statement, I'm trying to get Python to > tell me whether there are even or odd number of 1's in a > binary representation. For example, if I give Python a > 00000111, then I want it to say that the binary representation > given has an odd number of 1's. If I give it 00010111, then it > will tell me that there is an even number of 1's. I'd > appreciate any suggestion. A couple come to mind. First, start by counting the bits. If it's a string, this is easy: b = "00010111" result = b.count('1') If it's an integer datatype instead of as string, as long as you know the number of bits to expect, you can use x = 0xf7 result = sum((x >> i) & 1 for i in range(8)) where 8 is the number of bits you expect. If you don't know the number of bits to expect, you'd have to do it in a more open-ended loop: x = 0xDEADBEEF result = 0 while x: result += x & 1 x >>= 1 Once you have the resulting count, you can then check if it's even or odd: if result & 1: print "Odd" else: print "Even" Hope this helps, -tkc From afriere at yahoo.co.uk Wed Feb 4 20:44:41 2009 From: afriere at yahoo.co.uk (afriere at yahoo.co.uk) Date: Wed, 4 Feb 2009 17:44:41 -0800 (PST) Subject: Couple of noobish question References: <498a1b1d$0$24204$426a74cc@news.free.fr> Message-ID: <6ff716b0-6111-4b20-b060-b52dea45cf14@w1g2000prm.googlegroups.com> On Feb 5, 11:45?am, Tim Rowe wrote: [snip] > Python in a Nutshell states that os.uname "exists only on certain > platforms", and in the code sample wraps it in a try statement. That > seems to be the safe way to go -- except (and I don't know much about > this) wouldn't code have to be digging into some pretty obscure > corners to find a difference between different posix implementations? Perhaps not, if the particular posix implementation is Mac OSX. I would think that trying os.uname() first and then os.name if it throws will give you the clearest picture of which OS you are facing. Alternatively you could query os.name and if that says 'posix' proceed to call os.uname(). From digitig at gmail.com Wed Feb 4 20:58:24 2009 From: digitig at gmail.com (Tim Rowe) Date: Thu, 5 Feb 2009 01:58:24 +0000 Subject: Upgrade 2.6 to 3.0 In-Reply-To: <2ba4f763-79fa-423e-b082-f9de829ae964@i20g2000prf.googlegroups.com> References: <669c42cc-4f4d-40be-b842-6f778959d391@f40g2000pri.googlegroups.com> <2ba4f763-79fa-423e-b082-f9de829ae964@i20g2000prf.googlegroups.com> Message-ID: 2009/2/5 Giampaolo Rodola' : > Just out of curiosity, am I the only one who think that switching to > 3.x right now is not a good idea? I'm looking at making the switch, but I'm put off by the lack of 3rd party stuff such as PyWin (and I can't see a NumPy build for Python 2.6 yet, never mind 3.0). Unless all you want is in the standard library, I think it's worth the general user holding back for a while whilst the tool providers catch up. -- Tim Rowe From rhodri at wildebst.demon.co.uk Wed Feb 4 21:01:12 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 05 Feb 2009 02:01:12 -0000 Subject: Feet and inches In-Reply-To: References: Message-ID: On Thu, 05 Feb 2009 01:28:06 -0000, todpose at hotmail.com wrote: > I'm trying to get Python to say: > Enter the height (in metres): > and convert whatever value to feet and inches. I've done this part as > you can see below, but [...] Holy homework, you are busy tonight. Hang on while I put the line breaks back in your code. > metres = float(raw_input("Enter the height (in metres): ")) > total_inches = 39.37 * metres > feet = int(total_inches/12) > inches = int(round(total_inches - feet*12)) > if feet>=1: > print "It is " + str(feet) + " feet " + str(inches) + ' inches high.' > if feet<1 and inches<0.5: > print "Error." First things first: that line printing the result is making life harder on yourself than you really need to, given that Python's print statement (in 2.x -- it's a function from 3.0 onwards) will put spaces between items for you, and will happily print out integers without needing to str() them. print "It is", feet, "feet", inches, "inches high." Since the rest of this smells like homework, I'll answer your question with questions. > [...] how can I terminate the program when user inputs a height less > than 1/2 inch? First you have to make your program repeat itself, otherwise this question is meaningless. How would you do that? Then, what methods do you have for stopping a loop in Python? How would you decide to make one of them happen? What condition is "a height less than 1/2 inch" in terms of your program? (Hint: the condition isn't what I think you think it is -- remember that "inches" is an int!) > How can I also take into account all the cases that need an exception? How do you take care of any exception? -- Rhodri James *-* Wildebeeste Herder to the Masses From python.list at tim.thechases.com Wed Feb 4 21:15:47 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 04 Feb 2009 20:15:47 -0600 Subject: Feet and inches In-Reply-To: References: Message-ID: <498A4BD3.3080906@tim.thechases.com> > Enter the height (in metres): > > and convert whatever value to feet and inches. I've done this > part as you can see below, but how can I terminate the program > when user inputs a height less than 1/2 inch? Dang...I got suckered into answering a homework problem for the last one. My apologies to the professor if they eavesdrop on the mailing list. However, given the demonstrated skill level of the programmer, if you suspect your student got the answer from my reply, a fairly simple tweak of the problem would separate the wheat from the chaff. For this one, 1) you're using the int() function, so fractional inches coming from the user don't really matter anyways. 2) read up on the "%" (modulo) operator, or check out the divmod() function in Python. -tkc From digitig at gmail.com Wed Feb 4 21:17:08 2009 From: digitig at gmail.com (Tim Rowe) Date: Thu, 5 Feb 2009 02:17:08 +0000 Subject: Feet and inches In-Reply-To: References: Message-ID: 2009/2/5 todpose at hotmail.com : > I'm trying to get Python to say: > > Enter the height (in metres): > > and convert whatever value to feet and inches. This looks like another homework assignment. You'll probably get more help (on *any* language forum) if you admit that up front. However, at least this time you've shown us that you've made a good first attempt, so here are a few hints. > I've done this part as you > can see below, but how can I terminate the program when user inputs a height > less than 1/2 inch? The program already terminates when the user inputs any height. If you want it to *keep* asking you need to wrap it in some sort of loop. Look up "while" and "break". > How can I also take into account all the cases that need an exception? I think your code already takes into account all the cases that need an exception -- you just need to handle the exceptions. Try entering some silly values for the height (try something like "one point three" for example) and look at the exception you get. Then look up "try" and "catch" to see what you might do about it. You might like to think about what should happen if a user enters a negative value, but the present behaviour -- when fixed -- may be what you need. -- Tim Rowe From python.list at tim.thechases.com Wed Feb 4 21:31:49 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 04 Feb 2009 20:31:49 -0600 Subject: Use list name as string In-Reply-To: <77e831100902041736w5194b59dubdd922c80dd82ece@mail.gmail.com> References: <77e831100902040824q2a0b8465k4894f29ed4baba12@mail.gmail.com> <4989C6D0.2000604@tim.thechases.com> <77e831100902040857q2379bf80hc05b5575cba85bdd@mail.gmail.com> <4989CB47.3060806@mrabarnett.plus.com> <77e831100902040918j4be325d3y760120c92f8a0d7f@mail.gmail.com> <77e831100902040923k188e5df3q22423884f239e5a5@mail.gmail.com> <77e831100902041736w5194b59dubdd922c80dd82ece@mail.gmail.com> Message-ID: <498A4F95.8050302@tim.thechases.com> > My argument comes down to; we use M so we don't have to type > [1,3,5,7], I realize that this is in part because we might not no what > M will be. > This is starting to sound like double talk on my part, I have only > been programing in python for 2 weeks so my credibility is only that > of an outside that MAY have a reasonable way of thinking of this or at > least a feature I would like. The problem (as pointed out elsewhere on the list), an argument to a function may have zero or more names at the time the function is called. There *is* *no* canonical name for an object. If you want to name an object, pass it as a function-argument. Or use its ID. However, since Python has the flexibility to handle any of the following: a = [1,2,3] b = [5,6,7] c = b foo([8,9,10]) foo(a) foo(b) foo(c) While for the b/c name conflict (both refer to the same object), might be hackable by sniffing the call-stack, the anonymous [8,9,10] argument has *no* name, and thus your function is stuck. > by the way what is "**kwargs" I can't find any documentation on this? There's a quick example here: http://mail.python.org/pipermail/python-list/2007-June/443934.html -tkc From dchandran1 at tinkercell.com Wed Feb 4 21:41:47 2009 From: dchandran1 at tinkercell.com (Deepak Chandran) Date: Wed, 4 Feb 2009 18:41:47 -0800 Subject: Embedded python output capture Message-ID: <5dfe78f40902041841j1424bcacke4239991207507b8@mail.gmail.com> I have a program with embedded Python. If the python code has print statements, how do I retrieve those values (which normally go to stdout)? The output from Py_RunString is just NULL Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From sjmachin at lexicon.net Wed Feb 4 21:45:51 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 4 Feb 2009 18:45:51 -0800 (PST) Subject: Does array.read() move file pointer automatically? References: Message-ID: <283e98d0-8e0d-44eb-b170-43afb70c616f@r15g2000prd.googlegroups.com> On Feb 5, 9:51?am, Lionel wrote: > Hello everyone. Quick question: When using the "read()" method in the > array module, must I redirect the current file pointer or will that > occur automatically? > > For example, if I were to sequentially read data in chunks from a > binary file as in: > > for currentChunk in range(numberOfChunksToRead): > > ? ? ? ?floatData = array.array('f') > ? ? ? ?floatData.read(MyFileHandle, numberOfFloatsPerChunk) > ? ? ? ?...go to work on data... > > at each iteration of the "for" loop, will the next chunk of bytes be > read into "floatData" or must I move the file pointer by calling "seek > ()" or some function like that? Suggestions for the the next time you have a question like that: (1) Consider which outcome is more plausible, write your code accordingly and see what happens (2) If it blows up, or if you like looking before you leap anyway, try inserting temporarily some code -- in this case print MyFileHandle.tell() that will tell you the answer to your question. In this game you are allowed to experiment to get an answer, and it's often faster than phone-a-friend :-) From kmcbrearty at yahoo.com Wed Feb 4 21:49:21 2009 From: kmcbrearty at yahoo.com (KMCB) Date: Wed, 4 Feb 2009 18:49:21 -0800 (PST) Subject: JDBC in CPYTHON References: <3e9865ac-ce12-492f-83db-74bd78ed3ee2@i18g2000prf.googlegroups.com> Message-ID: <63dfd3f1-ce70-4b40-b375-82c0ee03d1c3@u14g2000yqg.googlegroups.com> Thanks Simon and Marc, I currently have an app on OSX that I wanted to migrate to NIX, it uses a ODBC DBAPI interface to communicate with Filemaker. Unfortunately, FMP does not support linux drivers. They do have a JDBC driver that looks like it may work. My preference was to run that app on one machine. I may not be understand your suggestion Marc, can the app and bridge run on the same machine. Can I specify the ODBC to a localhost, being the bridge? Then have the JDBC driver installed. Also, your second link does not seam to have a download or anything in the CVS. Thanks, KMCB From rhodri at wildebst.demon.co.uk Wed Feb 4 21:55:04 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 05 Feb 2009 02:55:04 -0000 Subject: Use list name as string In-Reply-To: <77e831100902041736w5194b59dubdd922c80dd82ece@mail.gmail.com> References: <77e831100902040824q2a0b8465k4894f29ed4baba12@mail.gmail.com> <4989C6D0.2000604@tim.thechases.com> <77e831100902040857q2379bf80hc05b5575cba85bdd@mail.gmail.com> <4989CB47.3060806@mrabarnett.plus.com> <77e831100902040918j4be325d3y760120c92f8a0d7f@mail.gmail.com> <77e831100902040923k188e5df3q22423884f239e5a5@mail.gmail.com> <77e831100902041736w5194b59dubdd922c80dd82ece@mail.gmail.com> Message-ID: On Thu, 05 Feb 2009 01:36:17 -0000, Vincent Davis wrote: > if I start with > M = [1,3,5,7] > M is [1,3,5,7] > This seems one way, as [1,3,5,7] is not M in the sense that there is > no operation I can preform on [1,3,5,7] and get M back. Other than > asking/testing M==[1,3,5,7] Correct. If you actually try that, you get this: Python 2.5.2 (r252:60911, May 7 2008, 15:21:12) [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> M = [1,3,5,7] >>> M is [1,3,5,7] False This isn't just me being funny with your suggested syntax, it's making an important point: the second [1,3,5,7] is an entirely different object to the list we named M, it just happens to contain the same data. > This seems fine to me. but when I savedata(M) it seems I should be > able to refer to both [1,3,5,7] and "M", "I mean I did just type it > why type it again) > My argument comes down to; we use M so we don't have to type > [1,3,5,7], I realize that this is in part because we might not no what > M will be. That's an oversimplification, and you're battering away well past the point where it works. In any language, not just Python. > This is starting to sound like double talk on my part, I have only > been programing in python for 2 weeks so my credibility is only that > of an outside that MAY have a reasonable way of thinking of this or at > least a feature I would like. The problem is you seem to be thinking in terms of objects having names. They don't. Names have objects. What I mean by that is that when you type "M = [1,3,5,7]", you are saying "when I say 'M', substitute in this list (not just one that looks like it, this exact list". When you type "N = M", similarly you get the name N bound to the same exact list; if you then type "N[1] = 2" and print out M, it'll show up as [1,2,5,7] -- it's still the same list under both names. In effect (to oversimplify more than a bit), Python looks up the name in a dictionary to get the object it represents. The reverse lookup doesn't exist, largely because it isn't unique. Our [1,3,5,7] list has no idea what names, if any, refer to it, and in all but the most trivial cases the information isn't really meaningful. Suppose that we did have a "getvariablename" function, what would you expect the following code to do? def f(thing): print getvariablename(thing) m = [1,3,5,7] for n in m: f(n) Should it say "n" for all of them? Or "['n', 'thing']", since 'thing' is after all a perfectly valid name for it? Then what about this: for i in range(len(m)): f(m[i]) Should it say "m[i]" for all of them, or "m[0]" "m[1]" and so on, or what? > by the way what is "**kwargs" I can't find any documentation on this? http://docs.python.org/tutorial/controlflow.html#keyword-arguments In a function definition, "**name" mops up all the keyword arguments to the function that aren't explicit formal parameters into a dictionary called "name", indexed by keyword. "kwargs" seems to be the traditional name to use. So: >>> def demo(action, **kwargs): ... print kwargs ... >>> demo(action="dummy", text="wombats are go") {'text': 'wombats are go'} You can also use it the other way round to expand a dictionary into keyword parameters to a function call: >>> myargs = { 'action': 'avoid', 'where': 'Camelot', 'because': 'it is a >>> silly place' } >>> demo(**myargs) {'because': 'it is a silly place', 'where': 'Camelot'} -- Rhodri James *-* Wildebeeste Herder to the Masses From steve at holdenweb.com Wed Feb 4 21:58:44 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 04 Feb 2009 21:58:44 -0500 Subject: Using while loop and if statement to tell if a binary has an odd or even number of 1's. In-Reply-To: References: <50697b2c0902041718h5616c78p3420762fd546df3e@mail.gmail.com> Message-ID: todpose at hotmail.com wrote: > By "binary representation", I mean a byte of 0s and 1s. Example: 00000101 > Also, I'm interested in only using while loop and if statement > to accomplish this task. > Thanks. > I smell homework. Do it yourself! -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Wed Feb 4 22:15:11 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 04 Feb 2009 22:15:11 -0500 Subject: Upgrade 2.6 to 3.0 In-Reply-To: References: <669c42cc-4f4d-40be-b842-6f778959d391@f40g2000pri.googlegroups.com> <2ba4f763-79fa-423e-b082-f9de829ae964@i20g2000prf.googlegroups.com> Message-ID: <498A59BF.1030101@holdenweb.com> Tim Rowe wrote: > 2009/2/5 Giampaolo Rodola' : > >> Just out of curiosity, am I the only one who think that switching to >> 3.x right now is not a good idea? > > I'm looking at making the switch, but I'm put off by the lack of 3rd > party stuff such as PyWin (and I can't see a NumPy build for Python > 2.6 yet, never mind 3.0). Unless all you want is in the standard > library, I think it's worth the general user holding back for a while > whilst the tool providers catch up. > > Take a look at the recent threads on the topic of the 3.0.1 release on the python-dev list. There is some feeling that the 3.0 release was unsatisfactory in certain ways. Some of the issues (including removal of some obscure features that should have been removed in 3.0) will be taken care of in 3.0.1. In addition to that expect a 3.1 release before too long (say, within the next six months) that will address some performance issues not addressed in 3.0.1 and provide other optimizations and perhaps a small list of new features. 3.0 is of remarkably good quality for a ".0" release. Expect even better things in the future. If you want to write portable code you can put into production now and move to 3.0 when appropriate then write for 2.6, and 2.7 when and if it comes out. Compile it with the -3 option and rewrite until it stops raising warnings. It will then be relatively easy to move to 3.x when the third-party library support you need is available. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From jervisau at gmail.com Wed Feb 4 22:24:48 2009 From: jervisau at gmail.com (Jervis Whitley) Date: Thu, 5 Feb 2009 14:24:48 +1100 Subject: Use list name as string In-Reply-To: <77e831100902040857q2379bf80hc05b5575cba85bdd@mail.gmail.com> References: <77e831100902040824q2a0b8465k4894f29ed4baba12@mail.gmail.com> <4989C6D0.2000604@tim.thechases.com> <77e831100902040857q2379bf80hc05b5575cba85bdd@mail.gmail.com> Message-ID: <8e63a5ce0902041924h55c7964di3b6a415a0a4dff2d@mail.gmail.com> On Thu, Feb 5, 2009 at 3:57 AM, Vincent Davis wrote: > Sorry for not being clear > I would have something like this > x = [1, 2, 3,5 ,6 ,9,234] > Then > def savedata(dataname): .......... > > savedata(x) > this would save a to a file called x.csv This is my problem, getting the > name to be x.csv which is the same as the name of the list. > and the data in the file would be > 1,2,3,5,6,9,234 this parts works It sounds like you would _really_ like to attach a name to this list of data. How about this terrible example to solve your problem. x = dict(x=[1,2,3,5,6,9,234]) then def savedata(dataname): # extract the first key(name) and value(data) from the dataname data type. try: name, data = dataname.items()[0] except AttributeError: raise TypeError("Expecting a datatype that declares method 'items' :).") # we could catch other exceptions here but I wont (like empty items). now you have your name and your data variable. This way you don't declare your variable name when calling savedata but when you create your variable. Although you should really solve your problem by thinking about it from a completely different angle, maybe subclassing your datatype and adding a 'name' attribute ? I'm sure some of the others here have suggested that already. Cheers, From vincent at vincentdavis.net Wed Feb 4 22:32:59 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Wed, 4 Feb 2009 20:32:59 -0700 Subject: Use list name as string In-Reply-To: References: <77e831100902040824q2a0b8465k4894f29ed4baba12@mail.gmail.com> <4989C6D0.2000604@tim.thechases.com> <77e831100902040857q2379bf80hc05b5575cba85bdd@mail.gmail.com> <4989CB47.3060806@mrabarnett.plus.com> <77e831100902040918j4be325d3y760120c92f8a0d7f@mail.gmail.com> <77e831100902040923k188e5df3q22423884f239e5a5@mail.gmail.com> <77e831100902041736w5194b59dubdd922c80dd82ece@mail.gmail.com> Message-ID: <77e831100902041932h502dea32s66a4aacaf247790a@mail.gmail.com> "The problem is you seem to be thinking in terms of objects having names. They don't. Names have objects."I agree this is my problem. This is not correct terminology then? The name of the object is anobject Let me give another example and let me know if I am just beating a dead horse. In my current script I have may print statements to verify I am manipulating my list as I hope. I have many lines like; print 'alist', alist I need to print the names so I know what I am looking at on the output. It would be nice if I could define fuction that did this def lp(thelist): "magic occurs" Then I could just type lp(alist) note I am entering the name which has an object that is a list. I am not entering [1,3,5,7] and it would print 'alist' alist Does it not seem reasonable to what to do this. Vincent Davis 720-301-3003 On Wed, Feb 4, 2009 at 7:55 PM, Rhodri James wrote: > On Thu, 05 Feb 2009 01:36:17 -0000, Vincent Davis < > vincent at vincentdavis.net> wrote: > > if I start with >> M = [1,3,5,7] >> M is [1,3,5,7] >> This seems one way, as [1,3,5,7] is not M in the sense that there is >> no operation I can preform on [1,3,5,7] and get M back. Other than >> asking/testing M==[1,3,5,7] >> > > Correct. If you actually try that, you get this: > > Python 2.5.2 (r252:60911, May 7 2008, 15:21:12) > [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >> M = [1,3,5,7] >>>> M is [1,3,5,7] >>>> >>> False > > This isn't just me being funny with your suggested syntax, it's > making an important point: the second [1,3,5,7] is an entirely > different object to the list we named M, it just happens to > contain the same data. > > This seems fine to me. but when I savedata(M) it seems I should be >> able to refer to both [1,3,5,7] and "M", "I mean I did just type it >> why type it again) >> My argument comes down to; we use M so we don't have to type >> [1,3,5,7], I realize that this is in part because we might not no what >> M will be. >> > > That's an oversimplification, and you're battering away well past the > point where it works. In any language, not just Python. > > This is starting to sound like double talk on my part, I have only >> been programing in python for 2 weeks so my credibility is only that >> of an outside that MAY have a reasonable way of thinking of this or at >> least a feature I would like. >> > > The problem is you seem to be thinking in terms of objects having names. > They don't. Names have objects. > > What I mean by that is that when you type "M = [1,3,5,7]", you are saying > "when I say 'M', substitute in this list (not just one that looks like it, > this exact list". When you type "N = M", similarly you get the name N > bound to the same exact list; if you then type "N[1] = 2" and print out > M, it'll show up as [1,2,5,7] -- it's still the same list under both names. > In effect (to oversimplify more than a bit), Python looks up the name > in a dictionary to get the object it represents. > > The reverse lookup doesn't exist, largely because it isn't unique. Our > [1,3,5,7] list has no idea what names, if any, refer to it, and in all > but the most trivial cases the information isn't really meaningful. > Suppose that we did have a "getvariablename" function, what would you > expect the following code to do? > > def f(thing): > print getvariablename(thing) > > m = [1,3,5,7] > for n in m: > f(n) > > > Should it say "n" for all of them? Or "['n', 'thing']", since 'thing' > is after all a perfectly valid name for it? > > Then what about this: > > for i in range(len(m)): > f(m[i]) > > > Should it say "m[i]" for all of them, or "m[0]" "m[1]" and so on, or > what? > > by the way what is "**kwargs" I can't find any documentation on this? >> > > http://docs.python.org/tutorial/controlflow.html#keyword-arguments > > In a function definition, "**name" mops up all the keyword arguments > to the function that aren't explicit formal parameters into a > dictionary called "name", indexed by keyword. "kwargs" seems to be > the traditional name to use. So: > > def demo(action, **kwargs): >>>> >>> ... print kwargs > ... > >> demo(action="dummy", text="wombats are go") >>>> >>> {'text': 'wombats are go'} > > > You can also use it the other way round to expand a dictionary into > keyword parameters to a function call: > > myargs = { 'action': 'avoid', 'where': 'Camelot', 'because': 'it is a >>>> silly place' } >>>> demo(**myargs) >>>> >>> {'because': 'it is a silly place', 'where': 'Camelot'} > > -- > Rhodri James *-* Wildebeeste Herder to the Masses > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From vincent at vincentdavis.net Wed Feb 4 22:37:04 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Wed, 4 Feb 2009 20:37:04 -0700 Subject: Use list name as string In-Reply-To: <8e63a5ce0902041924h55c7964di3b6a415a0a4dff2d@mail.gmail.com> References: <77e831100902040824q2a0b8465k4894f29ed4baba12@mail.gmail.com> <4989C6D0.2000604@tim.thechases.com> <77e831100902040857q2379bf80hc05b5575cba85bdd@mail.gmail.com> <8e63a5ce0902041924h55c7964di3b6a415a0a4dff2d@mail.gmail.com> Message-ID: <77e831100902041937i2668897dm733747201429f9d6@mail.gmail.com> Jervis Whitley wrote "Although you should really solve your problem by thinking about it from a completely different angle, maybe subclassing your datatype and adding a 'name' attribute ? I'm sure some of the others here have suggested that already." That is beyond my current knowledge. Any suggestions for reading about this? Thanks Vincent Davis On Wed, Feb 4, 2009 at 8:24 PM, Jervis Whitley wrote: > On Thu, Feb 5, 2009 at 3:57 AM, Vincent Davis > wrote: > > Sorry for not being clear > > I would have something like this > > x = [1, 2, 3,5 ,6 ,9,234] > > Then > > def savedata(dataname): .......... > > > > savedata(x) > > this would save a to a file called x.csv This is my problem, getting the > > name to be x.csv which is the same as the name of the list. > > and the data in the file would be > > 1,2,3,5,6,9,234 this parts works > > It sounds like you would _really_ like to attach a name to this list of > data. > > How about this terrible example to solve your problem. > > x = dict(x=[1,2,3,5,6,9,234]) > > then > def savedata(dataname): > # extract the first key(name) and value(data) from the dataname data > type. > try: > name, data = dataname.items()[0] > except AttributeError: > raise TypeError("Expecting a datatype that declares method 'items' > :).") > # we could catch other exceptions here but I wont (like empty items). > > > now you have your name and your data variable. > This way you don't declare your variable name when calling savedata > but when you > create your variable. > > Although you should really solve your problem by thinking about it > from a completely > different angle, maybe subclassing your datatype and adding a 'name' > attribute ? I'm > sure some of the others here have suggested that already. > > Cheers, > -------------- next part -------------- An HTML attachment was scrubbed... URL: From matzke at berkeley.edu Wed Feb 4 22:38:57 2009 From: matzke at berkeley.edu (Nick Matzke) Date: Wed, 04 Feb 2009 19:38:57 -0800 Subject: Comparing two book chapters (text files) In-Reply-To: <50697b2c0902041741w3ad7365ay8dbcab7b9cc3216e@mail.gmail.com> References: <498A3EC6.4040607@berkeley.edu> <50697b2c0902041741w3ad7365ay8dbcab7b9cc3216e@mail.gmail.com> Message-ID: <498A5F51.4030900@berkeley.edu> Chris Rebert wrote: > On Wed, Feb 4, 2009 at 5:20 PM, Nick Matzke wrote: >> Hi all, >> >> So I have an interesting challenge. I want to compare two book chapters, >> which I have in plain text format, and find out (a) percentage similarity >> and (b) what has changed. >> >> Some features make this problem different than what seems to be the standard >> text-matching problem solvable with e.g. difflib. Here is what I mean: >> >> * there is no guarantee that single lines from each file will be directly >> comparable -- e.g., if a few words are inserted into a sentence, then a >> chunk of the sentence will be moved to the next line, then a chunk of that >> line moved to the next, etc. >> >> * Also, there are cases where paragraphs have been moved around, sections >> re-ordered, etc. So it can't just be a "linear" match. >> >> I imagine this kind of thing can't be all that hard in the grand scheme of >> things, but I couldn't find an easily applicable solution readily available. >> I have advanced beginner python skills but am not quite where I could do >> this kind of thing from scratch without some guidance about the likely >> functions, libraries etc. to use. >> >> PS: I am going to have to do this for multiple book chapters so various >> software packages, e.g. for windows, are not really usable. > > Though not written in Python, wdiff > (http://www.gnu.org/software/wdiff/wdiff.html) might be a good > starting point. Wow -- this is actually amazingly effective. And fast! Simple to run from python & then use python to parse the output. Thanks! Nick > > Cheers, > Chris > -- ==================================================== Nicholas J. Matzke Ph.D. student, Graduate Student Researcher Huelsenbeck Lab Center for Theoretical Evolutionary Genomics 4151 VLSB (Valley Life Sciences Building) Department of Integrative Biology University of California, Berkeley Lab websites: http://ib.berkeley.edu/people/lab_detail.php?lab=54 http://fisher.berkeley.edu/cteg/hlab.html Dept. personal page: http://ib.berkeley.edu/people/students/person_detail.php?person=370 Lab personal page: http://fisher.berkeley.edu/cteg/members/matzke.html Lab phone: 510-643-6299 Dept. fax: 510-643-6264 Cell phone: 510-301-0179 Email: matzke at berkeley.edu Mailing address: Department of Integrative Biology 3060 VLSB #3140 Berkeley, CA 94720-3140 ----------------------------------------------------- "[W]hen people thought the earth was flat, they were wrong. When people thought the earth was spherical, they were wrong. But if you think that thinking the earth is spherical is just as wrong as thinking the earth is flat, then your view is wronger than both of them put together." Isaac Asimov (1989). "The Relativity of Wrong." The Skeptical Inquirer, 14(1), 35-44. Fall 1989. http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm ==================================================== From jervisau at gmail.com Wed Feb 4 22:53:28 2009 From: jervisau at gmail.com (Jervis Whitley) Date: Thu, 5 Feb 2009 14:53:28 +1100 Subject: Use list name as string In-Reply-To: <77e831100902041937i2668897dm733747201429f9d6@mail.gmail.com> References: <77e831100902040824q2a0b8465k4894f29ed4baba12@mail.gmail.com> <4989C6D0.2000604@tim.thechases.com> <77e831100902040857q2379bf80hc05b5575cba85bdd@mail.gmail.com> <8e63a5ce0902041924h55c7964di3b6a415a0a4dff2d@mail.gmail.com> <77e831100902041937i2668897dm733747201429f9d6@mail.gmail.com> Message-ID: <8e63a5ce0902041953r300ddf75h87760d0752a7f8e7@mail.gmail.com> On Thu, Feb 5, 2009 at 2:37 PM, Vincent Davis wrote: > Jervis Whitley wrote "Although you should really solve your problem by > thinking about it > from a completely different angle, maybe subclassing your datatype and > adding a 'name' > attribute ? I'm sure some of the others here have suggested that already." > That is beyond my current knowledge. Any suggestions for reading about this? > Thanks > Vincent Davis Here is a short example, more information on 'Inheritance' can be obtained from http://docs.python.org/tutorial/classes.html class NamedList(list): """A List with a 'name' attribute.""" def __init__(self, name, *args, **keyword_arguments): list.__init__(self, *args, **keyword_arguments) self.name = name you can now do this x = NamedList('x', [1,2,3,4]) >>> x.name 'x' In this example I have inherited all the features of the original built-in list, and added my own initialisation method. of course this is only a minimal example and there are other approaches (such as adding an attribute at runtime) but this one is self documenting to some extent. Cheers, From aahz at pythoncraft.com Thu Feb 5 00:09:58 2009 From: aahz at pythoncraft.com (Aahz) Date: 4 Feb 2009 21:09:58 -0800 Subject: Use list name as string References: <77e831100902040824q2a0b8465k4894f29ed4baba12@mail.gmail.com> <77e831100902040918j4be325d3y760120c92f8a0d7f@mail.gmail.com> <77e831100902040923k188e5df3q22423884f239e5a5@mail.gmail.com> Message-ID: In article , Rhodri James wrote: > >Fundamentally, the concept of a single unique name for any object isn't >something built into the language (or, indeed, most languages I can think >of). An object can have no names (though it'll promptly get garbage >collected if it isn't assigned to a name somehow), or just as easily >one or many names. Slight tangent: I prefer to use "binding target" ("target" for short) for the generic term describing the left-hand side of an assignment statement. Consider L[1] = C() (where L is a list and C is a class) It seems to me that while L and C are properly described as names, L[1] is not really a name, it's an expression describing the location to be used for binding. (The Python docs also use this terminology, at least some parts of them.) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From timr at probo.com Thu Feb 5 00:35:30 2009 From: timr at probo.com (Tim Roberts) Date: Thu, 05 Feb 2009 05:35:30 GMT Subject: Find the critical points References: <1b1b6f12-c910-4a13-902d-3523bfe8e3f5@u18g2000pro.googlegroups.com> Message-ID: <3huko41tkcr916ijv7eimuev6baapbod6i@4ax.com> antoniosacchi85 at gmail.com wrote: > >someone can help me?? >I am new to programing, >but I need to make some script like this: >http://blogs.nyu.edu/blogs/agc282/zia/2008/11/using_python_to_solve_optimiza.html >so th equestion is : >is possible to open it than it ask something and it tell me the >result?? I'm not exactly sure what you're asking. The script as you wrote it works, but it was designed to be entered from the interactive interpreter, so if you run it in a script it won't print anything. Basically, just add "print" in front of the expressions that you want printed: >import sympy as S >x,y=S.symbols('xy') >f=x**4+x**2-6*x*y+3*y**2 >a=S.diff(f,x) >S.pprint(a) >b=S.diff(f,y) >S.pprint(b) >S.solve_system([a,b],[x,y]) print S.solve_system([a,b],[x,y]) >H=S.hessian(f,[x,y]) >M1=S.Matrix([14,-6],[-6,6]) >M2=S.Matrix([2,-6],[-6,6]) >S.Matrix.berkowitz_minors(M2) >S.Matrix.berkowitz_minors(M1) print S.Matrix.berkowitz_minors(M2) print S.Matrix.berkowitz_minors(M1) -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From tim--at-- at frontier--dot--.net Thu Feb 5 01:35:13 2009 From: tim--at-- at frontier--dot--.net (Tim H) Date: Wed, 04 Feb 2009 23:35:13 -0700 Subject: time: Daylight savings confusion Message-ID: On Win XP 64bit, Python 2.6.1 64bit I am trying to rename files by their creation time. It seems the time module is too smart for its own good here. time.localtime(os.path.getctime(f)) returns a value one hour off from what windows reports for files that were created when Daylight savings time was in effect (ie when the tm_isdst field is one). I can kludge it, but am I missing the "right" way to do it? Tim full code: import os, time filetypes = (".avi") skipped = [] for f in os.listdir("."): root, ext = os.path.splitext(f) if ext in filetypes: creation_time = time.localtime(os.path.getctime(f)) newname = time.strftime("%Y-%m-%d_%H%M" + ext, creation_time) if os.path.exists(newname): skipped.append(newname) else: os.rename(f, newname) print f, "->", newname else: skipped.append(f) print print "These files were skipped:" for sf in skipped: print sf From spacebar265 at gmail.com Thu Feb 5 01:48:13 2009 From: spacebar265 at gmail.com (Spacebar265) Date: Wed, 4 Feb 2009 22:48:13 -0800 (PST) Subject: Scanning a file character by character Message-ID: Hi. Does anyone know how to scan a file character by character and have each character so I can put it into a variable. I am attempting to make a chatbot and need this to read the saved input to look for spelling mistakes and further analysis of user input. Thanks Spacebar265 From mail at microcorp.co.za Thu Feb 5 02:03:03 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Thu, 5 Feb 2009 09:03:03 +0200 Subject: Use list name as string References: <77e831100902040824q2a0b8465k4894f29ed4baba12@mail.gmail.com> <4989C6D0.2000604@tim.thechases.com> <77e831100902040857q2379bf80hc05b5575cba85bdd@mail.gmail.com> <4989CB47.3060806@mrabarnett.plus.com> <77e831100902040918j4be325d3y760120c92f8a0d7f@mail.gmail.com><77e831100902040923k188e5df3q22423884f239e5a5@mail.gmail.com> <4989D545.4030409@mrabarnett.plus.com> Message-ID: <012101c98765$78df0c20$0d00a8c0@hendrik> "MRAB" wrote: > The actual names of the variables and functions shouldn't matter to the > outside world; the name of an output file shouldn't depend on the name > of a variable. That is a matter of opinion. It is however, an interesting problem, namely: How does one get hold of the actual name by which some parameter is passed? you may want to print, as a debug thingy: print "the name passed in was: ", ImpossibleThingYieldingName print "and it evaluates to:" , ArgumentPassed to help you see from where your function was called, and you can't, as far as I know, do this, because there is no backwards link from the object to all of its various names. And while the OP can solve his problem by passing in the name explicitly, as doStuff("banana",banana) it will do him no good if he gets the list returned from something else: doStuff(WhatMustGoHere?,getlist()) Because in such a situation there is no backwards link to a name. So to the OP : Sorry - you can't get there from here. - Hendrik From elzapp at gmail.com Thu Feb 5 02:03:06 2009 From: elzapp at gmail.com (Bard Aase) Date: Wed, 4 Feb 2009 23:03:06 -0800 (PST) Subject: Scanning a file character by character References: Message-ID: On 5 Feb, 07:48, Spacebar265 wrote: > Hi. Does anyone know how to scan a file character by character and > have each character so I can put it into a variable. I am attempting > to make a chatbot and need this to read the saved input to look for > spelling mistakes and further analysis of user input. > Thanks > Spacebar265 You can read one byte at the time using the read() method on the file- object. http://docs.python.org/library/stdtypes.html#file.read e.g.: f=open("myfile.txt") byte=f.read(1) From xahlee at gmail.com Thu Feb 5 03:47:56 2009 From: xahlee at gmail.com (Xah Lee) Date: Thu, 5 Feb 2009 00:47:56 -0800 (PST) Subject: programming by evolution? References: <42a2e3fc-ec2e-4c09-b456-95a5fc4ce5a2@g39g2000pri.googlegroups.com> <6uuc4eFhc1u1U1@mid.individual.net> <11809792-676f-4d95-87c1-26666cc46b3b@w24g2000prd.googlegroups.com> Message-ID: <03db1c69-828a-4961-914d-62fe10ed88fb@w39g2000prb.googlegroups.com> looking at the eXtreme Programing fuckheads's traffic history: http://groups.google.com/group/comp.software.extreme-programming/about for those who are not aware, it was one of the snake oil wildly popular in around 2001. Xah ? http://xahlee.org/ ? Jason wrote: I just started reading OnLisp and hit this quote: Why wait for hindsight? As Montaigne found, nothing clarifies your ideas like trying to write them down. Once you?re freed from the worry that you?ll paint yourself into a corner, you can take full advantage of this possibility. The ability to plan programs as you write them has two momentous consequences: programs take less time to write, because when you plan and write at the same time, you have a real program to focus your attention; and they turn out better, because the final design is always a product of evolution. So long as you maintain a certain discipline while searching for your program?s destiny?so long as you always rewrite mistaken parts as soon as it becomes clear that they?re mistaken?the final product will be a program more elegant than if you had spent weeks planning it beforehand. I've always heard "design is 90% of the job. You have to have a good design in place before writing anything." This quote from OnLisp is a radical paradigm for me (being an engineer who designs things). My question to you is does this apply in practice? In the real world when the rubber hits the road, can you program this way and develop good software used by lots of people? ----------------- On Feb 4, 10:36 pm, Xah Lee wrote: yes and no. The problem is that such opinion is not a scientific opinion. It can't be verified or denied. Any dynamic lang, such as Python, PHP, Ruby, Mathematica can be said the same thing. And, prob more so for functional langs. The langs that this cannot be done, is C, Java, where the lang is inflexible, low level, or requires big structure that's hard to change. if you want software engineering books, i suggest try some books that are based on statistical survey, as opposed to some dignitary's ?opinion? or current fashion & trends that comes with a jargon. These type of books are a dime a dozen, every year, they come and go. The stastical survey approach takes major understaking and cost. The opinion type any motherfucking ?guru? can write. e.g. Paul Graham has you buy into certain concept of ?hackers? fucker and claim they are like ?painters?. Certain Gabriel wants you to believe in poetry and C is the last language. (see Book Review: Patterns of Softwarehttp://xahlee.org/PageTwo_dir/Personal_dir/bookReviewRichardGabriel.html ) et al. Certain Gosling wants you to believe Java is the last lang on earth that'll wipe out Microsoft (circa 1998). Pascal Constanza wrote: > Yes. There are actually complete software development methodologies > built around these ideas. Google for "extreme programming" and "agile > software methodologies". Pascal Constanza is a Common Lisp fanatic. Note here, that eXtreme Programing is one of the snake oil, that ran like rampant wild fire in the industry around 2002, with many books published on it on the supposed motherfucking hip Software Engineering practices, but today you don't hear much of it. I haven't looked at ?Agile programing? agile my ass, but it is probably a waste of time. ... what society overwhelmingly asks for is snake oil. Of course, the snake oil has the most impressive names ?otherwise you would be selling nothing? like ?Structured Analysis and Design?, ?Software Engineering?, ?Maturity Models?, ?Management Information Systems?, ?Integrated Project Support Environments? ?Object Orientation? and ?Business Process Re-engineering? (the latter three being known as IPSE, OO and BPR, respectively).? ? Edsger W Dijkstra (1930-2002), in EWD 1175: The strengths of the academic enterprise. you want to be a good programer? Study math, the math of programing, and master the langs and protocols and tools you use. You want to climb the tech industry ladder? get better at people, learn politics. You want to be rich? Study business. Chances are, you are a coding geek, and at heart you dna is not geared to be interested in politics or business, and you'll never be rich or big ceo just because of that. See also: ? Why Software Suck http://xahlee.org/UnixResource_dir/writ/why_software_suck.html Xah ? http://xahlee.org/ ? From bruno.42.desthuilliers at websiteburo.invalid Thu Feb 5 04:00:24 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 05 Feb 2009 10:00:24 +0100 Subject: is python Object oriented?? In-Reply-To: <5475ff03-2d41-4db1-a986-5124b166abfb@r15g2000prd.googlegroups.com> References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <018801c9850e$3e019fe0$0d00a8c0@hendrik> <7a9c25c20902020055p7b2b449ek9faf789a5d6e1452@mail.gmail.com> <003d01c98527$d9ea4ec0$0d00a8c0@hendrik> <005201c98549$d3eb74a0$0d00a8c0@hendrik> <2ed10ddd-63ac-4507-b046-0404cc85c97a@s1g2000prg.googlegroups.com> <3acf1429-9aec-4e0d-b617-21cbcdf76087@w1g2000prk.googlegroups.com> <22440895-ed68-4643-b833-0befe83d571c@f40g2000pri.googlegroups.com> <49895bad$0$28683$426a74cc@news.free.fr> <5475ff03-2d41-4db1-a986-5124b166abfb@r15g2000prd.googlegroups.com> Message-ID: <498aaa94$0$14156$426a74cc@news.free.fr> thmpsn.m.k at gmail.com a ?crit : > On Feb 4, 3:11 am, Bruno Desthuilliers 42.desthuilli... at websiteburo.invalid> wrote: >> thmpsn.... at gmail.com a ?crit : >> >> >> >>> On Feb 3, 1:14 am, David Cournapeau wrote: >> (snip) >>>> after all, we have used FILE* for years and I have no idea about the FILE >>>> structure. >>> Your lack of knowledge about it doesn't mean that it has somehow >>> magically "private" members. The only reason that most of us don't >>> know what a FILE is is that it's definition is implementation-defined >>> (i.e., every compiler may define it differently). >>> That doesn't have anything to do with private members. For example, on >>> my system, defines FILE as: >>> struct _iobuf { >>> char *_ptr; >>> int _cnt; >>> char *_base; >>> int _flag; >>> int _file; >>> int _charbuf; >>> int _bufsiz; >>> char *_tmpfname; >>> }; >> Didn't you notice kind of a pattern here ? > > You mean the leading underscores? I don't think they're used for the > same purpose as in Python. Not exactly the same purpose, indeed, but there's still something close: mark the names as "special". > In C/C++, identifiers that begin with an > underscore are reserved (at least at the outer level). Thus, if the > member '_ptr' would instead be named 'ptr', something like this would > break things: > > #define ptr // OOPS!! > #include > > That shouldn't happen with '_ptr', since programs are not supposed to > define those kinds of names (yeah, right). And here again : "would break", "shouldn't", "supposed". Convention over enforcement. >>> typedef struct _iobuf FILE; >>> Given this information, nothing prevents me from writing things like: >>> FILE* fp = fopen("file.txt", "r"); >>> if (!fp) { /* do something */ } >>> printf("fp->_cnt = %d\n", fp->cnt); >>> printf("fp->_flag = %d\n", fp->_flag); >>> printf("fp->_file = %d\n", fp->_file); >>> fp->_flag = 0x20; // OOPS!! >> >> Indeed - and that's exactly the point : nothing prevents you from >> accessing the implementation, *and yet, you don't* > > I sure don't, but I still *can*. So what ? > CHAOS MAY ENSUE!! C is not really a new technology, and has been the basis for most systems for years and years. Looks like nothing that bad as "CHAOS" really happened so far... From dickinsm at gmail.com Thu Feb 5 04:04:57 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Thu, 5 Feb 2009 01:04:57 -0800 (PST) Subject: Using while loop and if statement to tell if a binary has an odd or even number of 1's. References: mailman.8817.1233796709.3487.python-list@python.org Message-ID: <6c1875c3-8283-4764-a481-ebfa135868bc@v5g2000pre.googlegroups.com> On Feb 5, 1:18?am, Chris Rebert wrote: > For an integer: > is_even = bin(the_int)[2:].count('1') % 2 == 0 But the OP has to use if and while. How about: while 2+2 != 5: if 'wkw' in 'just being awkward': is_even = bin(the_int)[2:].count('1') % 2 == 0 break or (Python 2.5 compatible): def count_set_bits(n): # make sure we include an if, to # satisfy OP's requirements: if n < 0: raise ValueError count = 0 while n: count += 1 n &= n-1 return count is_even = count_set_bits(the_int) % 2 == 0 ...but anyone submitting this as a homework solution had better be prepared to explain why it works. Mark From matzke at berkeley.edu Thu Feb 5 04:08:25 2009 From: matzke at berkeley.edu (Nick Matzke) Date: Thu, 05 Feb 2009 01:08:25 -0800 Subject: global name 'sqrt' is not defined Message-ID: <498AAC89.5080002@berkeley.edu> Hi all, So, I can run this in the ipython shell just fine: =========== a = ["12", "15", "16", "38.2"] dim = int(sqrt(size(a))) dim >2 =========== But if I move these commands to a function in another file, it freaks out: ================================= a = distances_matrix.split('\t') from LR_run_functions_v2 import make_half_square_array d = make_half_square_array(a) > --------------------------------------------------------------------------- NameError Traceback (most recent call last) /bioinformatics/phylocom/ in () /bioinformatics/phylocom/_scripts/LR_run_functions_v2.py in make_half_square_array(linear_version_of_square_array) 1548 1549 a = linear_version_of_square_array -> 1550 dim = int(sqrt(size(a))) 1551 1552 NameError: global name 'sqrt' is not defined ================================= Here's the function in LR_run_functions_v2.py ========================== def make_half_square_array(linear_version_of_square_array): a = linear_version_of_square_array dim = int(sqrt(size(a))) ========================== Any ideas? If I do something like "import math" in the subfunction, then the error changes to "global name 'math' is not defined". Thanks! Nick -- ==================================================== Nicholas J. Matzke Ph.D. student, Graduate Student Researcher Huelsenbeck Lab Center for Theoretical Evolutionary Genomics 4151 VLSB (Valley Life Sciences Building) Department of Integrative Biology University of California, Berkeley Lab websites: http://ib.berkeley.edu/people/lab_detail.php?lab=54 http://fisher.berkeley.edu/cteg/hlab.html Dept. personal page: http://ib.berkeley.edu/people/students/person_detail.php?person=370 Lab personal page: http://fisher.berkeley.edu/cteg/members/matzke.html Lab phone: 510-643-6299 Dept. fax: 510-643-6264 Cell phone: 510-301-0179 Email: matzke at berkeley.edu Mailing address: Department of Integrative Biology 3060 VLSB #3140 Berkeley, CA 94720-3140 ----------------------------------------------------- "[W]hen people thought the earth was flat, they were wrong. When people thought the earth was spherical, they were wrong. But if you think that thinking the earth is spherical is just as wrong as thinking the earth is flat, then your view is wronger than both of them put together." Isaac Asimov (1989). "The Relativity of Wrong." The Skeptical Inquirer, 14(1), 35-44. Fall 1989. http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm ==================================================== From tino at wildenhain.de Thu Feb 5 04:13:24 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Thu, 05 Feb 2009 10:13:24 +0100 Subject: Use list name as string In-Reply-To: <77e831100902040857q2379bf80hc05b5575cba85bdd@mail.gmail.com> References: <77e831100902040824q2a0b8465k4894f29ed4baba12@mail.gmail.com> <4989C6D0.2000604@tim.thechases.com> <77e831100902040857q2379bf80hc05b5575cba85bdd@mail.gmail.com> Message-ID: <498AADB4.3060704@wildenhain.de> Hi, Vincent Davis wrote: > Sorry for not being clear > I would have something like this > x = [1, 2, 3,5 ,6 ,9,234] > > Then > def savedata(dataname): .......... > > savedata(x) > > this would save a to a file called x.csv This is my problem, getting the > name to be x.csv which is the same as the name of the list. > > and the data in the file would be > 1,2,3,5,6,9,234 this parts works the problem you are facing comes from a little misunderstanding. To clarify: python objects are nameless. You can bind them to any number of names (aka variables) >>> 1 # unnamed integer object with value 1 1 >>> a=1 # bind the integer object to name 'a' >>> b=a # bind the same integer object referred to by name a to name b therefore in your above example, which "name" should your savedata pick up for the filename? the 'x' of the first assignment or the 'dataname' of the assignment in the function call? The only solution I see would be to add a property to your datastore to give it its own unique name. (By subclassing and providing a name attribute or property) - and while you are at it, maybe you want to put the 'write to file' part into the class as well. Regards Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From crebert at ucsd.edu Thu Feb 5 04:19:44 2009 From: crebert at ucsd.edu (Chris Rebert) Date: Thu, 5 Feb 2009 01:19:44 -0800 Subject: global name 'sqrt' is not defined In-Reply-To: <498AAC89.5080002@berkeley.edu> References: <498AAC89.5080002@berkeley.edu> Message-ID: <50697b2c0902050119p65b0df7ei9cef4af4cc724986@mail.gmail.com> On Thu, Feb 5, 2009 at 1:08 AM, Nick Matzke wrote: > Hi all, > > So, I can run this in the ipython shell just fine: > > =========== > a = ["12", "15", "16", "38.2"] > dim = int(sqrt(size(a))) sqrt() is not a builtin function, it's located in the 'math' module. You must have imported it at some point. Or it could be be getting imported without your direct knowledge through ~/.pythonrc.py, $PYTHONSTARTUP, and/or by doing 'import user' For that matter, size() is not built into Python either, so you're definitely importing these things somewhere. Adding explicit imports of the modules/functions in question to the top of the file(s) in question should fix the problem. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From Ron.Barak at lsi.com Thu Feb 5 04:27:38 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Thu, 5 Feb 2009 09:27:38 +0000 Subject: How to find wxPython method documentation?? In-Reply-To: <10ead1a8-fc44-4392-b07d-54c00f0619f7@r36g2000prf.googlegroups.com> References: <10ead1a8-fc44-4392-b07d-54c00f0619f7@r36g2000prf.googlegroups.com> Message-ID: <7F0503CD69378F49BE0DC30661C6CCF60E6875B3@enbmail01.lsi.com> Hi Len, First off, there's the wxPython mailing list (To subscribe or unsubscribe via the World Wide Web, visit http://lists.wxwidgets.org/mailman/listinfo/wxpython-users or, via email, send a message with subject or body 'help' to wxpython-users-request at lists.wxwidgets.org) I also find Google invaluable in searching for wxPython knowledge, e.g., try http://www.google.com/search?q=wxpython+dialog. Bye, Ron. From egon.frerich at nord-com.net Thu Feb 5 04:30:19 2009 From: egon.frerich at nord-com.net (Egon Frerich) Date: Thu, 05 Feb 2009 10:30:19 +0100 Subject: How to find wxPython method documentation?? In-Reply-To: <10ead1a8-fc44-4392-b07d-54c00f0619f7@r36g2000prf.googlegroups.com> References: <10ead1a8-fc44-4392-b07d-54c00f0619f7@r36g2000prf.googlegroups.com> Message-ID: <498AB1AB.3030307@nord-com.net> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 The documentation is here: http://www.wxpython.org/onlinedocs.php In "Alphabetical class reference" you can find for example wxButton with its methods. Yes - there is no function 'SetBackgroundColour'. But there is a list with classes from which wxButton is derived. 'SetBackgroundColour' is a method for all widgets so it is described in ~ class wxWindow. Egon len schrieb: | Hi | | I am going through the "wxPython in Action" book by Noel Rappin and | Robin Dunn. | | I have been typing in the example programs as I go and play with | modifing the code. | Thought I should start trying to find my way around the documentation | found on the wxPython web site. | | The problem I have been having is I can't find the methods or more | specifically | | 'SetBackgroundColour' or 'AddSimpleTool' for example. | | How does one find the methods that are available in the classes. | | I tried looking at the wxWidgets web site and still had the same | problem. | | Could someone give me a little direction in this? | | Thanks | Len | -- | http://mail.python.org/mailman/listinfo/python-list -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFJirGrZRiDo9Iq4qIRAoReAJ49ojnUSI9tlCLXn3ynrUDqERykywCePuYB FOFMykSlCTgON4Ta3eGLPCM= =0Xq3 -----END PGP SIGNATURE----- From tino at wildenhain.de Thu Feb 5 04:39:24 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Thu, 05 Feb 2009 10:39:24 +0100 Subject: Use list name as string In-Reply-To: <012101c98765$78df0c20$0d00a8c0@hendrik> References: <77e831100902040824q2a0b8465k4894f29ed4baba12@mail.gmail.com> <4989C6D0.2000604@tim.thechases.com> <77e831100902040857q2379bf80hc05b5575cba85bdd@mail.gmail.com> <4989CB47.3060806@mrabarnett.plus.com> <77e831100902040918j4be325d3y760120c92f8a0d7f@mail.gmail.com><77e831100902040923k188e5df3q22423884f239e5a5@mail.gmail.com> <4989D545.4030409@mrabarnett.plus.com> <012101c98765$78df0c20$0d00a8c0@hendrik> Message-ID: <498AB3CC.3050806@wildenhain.de> Hendrik van Rooyen wrote: > "MRAB" wrote: > >> The actual names of the variables and functions shouldn't matter to the >> outside world; the name of an output file shouldn't depend on the name >> of a variable. > > That is a matter of opinion. > It is however, an interesting problem, namely: > > How does one get hold of the actual name by which some parameter > is passed? > > you may want to print, as a debug thingy: > > print "the name passed in was: ", ImpossibleThingYieldingName > print "and it evaluates to:" , ArgumentPassed This is possible to some degree: import inspect def F(a): frame_obj,filename,line_no, func_name,contextlines, contextindex=(inspect.getouterframes(inspect.currentframe()))[1] print "F(%s) called from '%s' within '%s' line %d" % (repr(a),filename,func_name,line_no) for ln,srcline in enumerate(contextlines or []): print "%3s : %s" % ('*>' if ln==contextindex else '',srcline) just play around calling the above function from different places and you should see what I mean :-) Regards Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From mnordhoff at mattnordhoff.com Thu Feb 5 04:39:47 2009 From: mnordhoff at mattnordhoff.com (Matt Nordhoff) Date: Thu, 05 Feb 2009 09:39:47 +0000 Subject: time: Daylight savings confusion In-Reply-To: References: Message-ID: <498AB3E3.1060804@mattnordhoff.com> Tim H wrote: > On Win XP 64bit, Python 2.6.1 64bit > > I am trying to rename files by their creation time. > > It seems the time module is too smart for its own good here. > > time.localtime(os.path.getctime(f)) returns a value one hour off from > what windows reports for files that were created when Daylight savings > time was in effect (ie when the tm_isdst field is one). I can kludge > it, but am I missing the "right" way to do it? > > Tim > > full code: >From what I remember, this is a bug in the Win32 API. Python probably could hack around it, but, well, I guess it doesn't. Googling a bit, Perl's Win32::UTCFileTime module [1] provides workarounds (not for Python, of course, but it could probably be ported) and explains all the gory details (which I have not read, so maybe I misunderstand ;-). [1] -- From dickinsm at gmail.com Thu Feb 5 04:40:52 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Thu, 5 Feb 2009 01:40:52 -0800 (PST) Subject: sys.float_info.epsilon References: <42b8c80f-b53c-4ec0-a1eb-c66410c60197@i18g2000prf.googlegroups.com> Message-ID: <5aa92561-8fec-4568-b19f-87ddc0c971e5@g1g2000pra.googlegroups.com> On Feb 4, 9:44?pm, Tim Rowe wrote: > That just leaves me puzzled as to why Mark Summerfield used it instead > of a check against zero on user input. No idea: you'd have to ask Mark Summerfield. If there's an email address published in his book, I'm sure he wouldn't object to the question. > So my next question is whether there is any x that can > be returned by float() such that x != 0 but some_number / (2 * x) > raises a ZeroDivisionError? Nope. If x is nonzero, then 2*x is definitely nonzero. It could be an infinity, or a nan, or the '2*x' computation could raise an exception, or perhaps cause the interpreter to crash (it shouldn't, but you never know...), but it's never going to be zero. Well, okay, *never* is a strong word: if 2*x is subnormal, and you're operating on a platform that for whatever reasons flushes subnormal results to zero, then it could happen. But not in *real* life. :) Mark From andrew at acooke.org Thu Feb 5 04:42:05 2009 From: andrew at acooke.org (andrew cooke) Date: Thu, 5 Feb 2009 01:42:05 -0800 (PST) Subject: Comparing two book chapters (text files) References: Message-ID: <72733721-53a4-4801-ad66-01cce5880d81@t11g2000yqg.googlegroups.com> On Feb 4, 10:20?pm, Nick Matzke wrote: > So I have an interesting challenge. ?I want to compare two book > chapters, which I have in plain text format, and find out (a) percentage > similarity and (b) what has changed. no idea if it will help, but i found this yesterday - http://www.nltk.org/ it's a python toolkit for natural language processing. there's a book at http://www.nltk.org/book with much more info. andrew From justin.mailinglists at gmail.com Thu Feb 5 04:46:25 2009 From: justin.mailinglists at gmail.com (Justin Ezequiel) Date: Thu, 5 Feb 2009 01:46:25 -0800 (PST) Subject: How do i add body to email.mime.multipart.MIMEMultipart instance? References: Message-ID: <69442cd1-7c20-4752-9280-ccaf237de218@r36g2000prf.googlegroups.com> On Feb 4, 2:48?pm, srinivasan srinivas wrote: > Hi, > Could someone tell me the way to add body to the instance email.mime.multipart.MIMEMultipart instance which has attachments? > > Thanks, msg = MIMEMultipart() msg.preamble = 'This is a multi-part message in MIME format.\n' msg.epilogue = '' body = MIMEMultipart('alternative') body.attach(MIMEText(text)) body.attach(MIMEText(html, 'html')) msg.attach(body) attachment = Message() attachment.add_header('Content-type', content_type, name=basename) attachment.add_header('Content-transfer-encoding', 'base64') attachment.add_header('Content-Disposition', 'attachment', filename=basename) attachment.set_payload(b.getvalue()) msg.attach(attachment) msg.add_header('Message-ID', generate_message_id(sender[1])) msg.add_header('Date', strftime(DATEFORMAT, gmtime())) msg.add_header('From', formataddr(sender)) msg.add_header('To', format_addresses(TOs)) msg.add_header('Cc', format_addresses(CCs)) msg.add_header('Subject', subj) From bearophileHUGS at lycos.com Thu Feb 5 04:47:24 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Thu, 5 Feb 2009 01:47:24 -0800 (PST) Subject: Ordered dict by default Message-ID: <47a82549-bc80-45ac-8b51-d58e597e768f@r24g2000vbp.googlegroups.com> Choosing the right data structure is usually a matter of compromises, and sometimes the best you can do is to change some data structures and look for the faster running time. To do this it helps to have a language that allows you to swap data structures in the more transparent way possible. It's not just a matter of the specific program, it's also a matter of the nature of the programming language. Python isn't meant to be high- performance in running time, it's meant to be easy to use, flexible, and easy to understand. (Ruby shares almost the same purposes, but it looks a bit less easy, a bit more flexible, and offers a bit more freedom, and it used to be a little slower). Now Ruby dicts are ordered by default: http://www.igvita.com/2009/02/04/ruby-19-internals-ordered-hash/ Of course Python can grow odicts into its collections module, that can be used everywhere a normal dict is used. But while this may be a good solution for faster languages like Java, C# and D, for me it doesn't sound like the best solution for Python. That page about Ruby dicts show a higher traversal speed (probably just because the CPU has to scan less memory, but I am not sure, because mordern CPUs are very complex) but lower insertion speed (I think mostly not because the added management of two pointers, but because the memory used increases, so there are more cache misses. If this turns out as true, then using the xor trick may halve the extra memory needed). I have no idea if such different balance of performance will lead to on average faster or slower Python programs, this has to be tested. But even if the average performance becomes a little worse I think making the default Python dict as ordered is a positive change for Python too, because built-ins are meant to be as flexible as possible, even if they aren't the fastest ones or the less memory hungry ones (and keeping dicts ordered decreases the surprises a newbie finds, makes some code cleaner, and doctests become simpler to write because the order of items may be more defined). Once the default dicts are ordered, it can be possible to add an unordereddict to the collections module to be used by programmers when max performance or low memory usage is very important :-) Namespaces and other internal things of Python can keep using the un- ordereddicts. I don't know what to do regarding Python sets yet. In mathematics sets aren't ordered, so they may be kept as they are now. Bye, bearophile From duncan.booth at invalid.invalid Thu Feb 5 04:56:51 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 5 Feb 2009 09:56:51 GMT Subject: Using while loop and if statement to tell if a binary has an odd or even number of 1's. References: <6c1875c3-8283-4764-a481-ebfa135868bc@v5g2000pre.googlegroups.com> Message-ID: Mark Dickinson wrote: > def count_set_bits(n): > # make sure we include an if, to > # satisfy OP's requirements: > if n < 0: > raise ValueError > count = 0 > while n: > count += 1 > n &= n-1 > return count > > is_even = count_set_bits(the_int) % 2 == 0 > > ...but anyone submitting this as a homework > solution had better be prepared to explain why > it works. > I remember a programming exercise when I was an undergraduate and anyone who *didn't* use that trick got marked down for writing inefficient code. -- Duncan Booth http://kupuguy.blogspot.com From robin at reportlab.com Thu Feb 5 05:10:17 2009 From: robin at reportlab.com (Robin Becker) Date: Thu, 05 Feb 2009 10:10:17 +0000 Subject: x64 speed In-Reply-To: <498A080D.3000703@egenix.com> References: <4988a1f1$0$3390$9b622d9e@news.freenet.de> <4988B615.4060206@jessikat.plus.net> <4988BAE8.2060204@v.loewis.de> <49896AA0.2050202@chamonix.reportlab.co.uk> <498A080D.3000703@egenix.com> Message-ID: <498ABB09.3050507@chamonix.reportlab.co.uk> ....... >>> ---------------------------------------------------------------------- >>> Ran 193 tests in 27.841s >>> >>> OK >>> >>> real 0m28.150s >>> user 0m26.606s >>> sys 0m0.917s >>> [rptlab at localhost tests]$ >> magical how the total python time is less than the real time. > > time(1) also measures the Python startup and shutdown time, so > I don't quite see the magic :-( > yes stupid me :( > FWIW: VMware VMs need the VMware tools installed to make their > clocks work more or less. With Linux, you need some extra tweaks > as well, otherwise the clocks are just completely unreliable. > I do have the tools installed and from what I can see the clock isn't so far off. At least when I run the two tests side by side the vm run always finishes first. Of course that could be because vmware is stealing cpu somehow. > See these notes: > > http://kb.vmware.com/selfservice/viewContent.do?language=en_US&externalId=1420 > http://communities.vmware.com/message/782173 > -- Robin Becker From digitig at gmail.com Thu Feb 5 05:10:31 2009 From: digitig at gmail.com (Tim Rowe) Date: Thu, 5 Feb 2009 10:10:31 +0000 Subject: Using while loop and if statement to tell if a binary has an odd or even number of 1's. In-Reply-To: References: <6c1875c3-8283-4764-a481-ebfa135868bc@v5g2000pre.googlegroups.com> Message-ID: 2009/2/5 Duncan Booth : > Mark Dickinson wrote: > >> def count_set_bits(n): >> # make sure we include an if, to >> # satisfy OP's requirements: >> if n < 0: >> raise ValueError >> count = 0 >> while n: >> count += 1 >> n &= n-1 >> return count >> >> is_even = count_set_bits(the_int) % 2 == 0 >> >> ...but anyone submitting this as a homework >> solution had better be prepared to explain why >> it works. >> > > I remember a programming exercise when I was an undergraduate and anyone > who *didn't* use that trick got marked down for writing inefficient code. Is adding and a modulus *really^ more efficient than flipping a bool as I suggested? I think I'd want to see measurements! -- Tim Rowe From robin at reportlab.com Thu Feb 5 05:12:15 2009 From: robin at reportlab.com (Robin Becker) Date: Thu, 05 Feb 2009 10:12:15 +0000 Subject: x64 speed In-Reply-To: <4989ee71$0$3356$9b622d9e@news.freenet.de> References: <4989ee71$0$3356$9b622d9e@news.freenet.de> Message-ID: <498ABB7F.6060006@chamonix.reportlab.co.uk> Martin v. L?wis wrote: >> Is it the >> x64 working faster at its design sizes > > Another guess (still from the darkness of not having received the > slightest clue what the test actually does): if it creates integers > in range(2**32, 2**64), then they fit into a Python int on AMD64-Linux, > but require a Python long on 32-bit Windows; long operations are much > slower than int operations. > ...... I don't think we're doing a lot of bignum arithmetic, some masking operations etc etc. -- Robin Becker From tino at wildenhain.de Thu Feb 5 05:21:44 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Thu, 05 Feb 2009 11:21:44 +0100 Subject: Comparing two book chapters (text files) In-Reply-To: <72733721-53a4-4801-ad66-01cce5880d81@t11g2000yqg.googlegroups.com> References: <72733721-53a4-4801-ad66-01cce5880d81@t11g2000yqg.googlegroups.com> Message-ID: <498ABDB8.1000001@wildenhain.de> andrew cooke wrote: > On Feb 4, 10:20 pm, Nick Matzke wrote: >> So I have an interesting challenge. I want to compare two book >> chapters, which I have in plain text format, and find out (a) percentage >> similarity and (b) what has changed. > > no idea if it will help, but i found this yesterday - http://www.nltk.org/ > > it's a python toolkit for natural language processing. there's a book > at http://www.nltk.org/book with much more info. Also there is difflib in the standard package which can be used depending on exact definition of "similarity". Regards Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From steve at holdenweb.com Thu Feb 5 05:22:35 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 05 Feb 2009 05:22:35 -0500 Subject: Ordered dict by default In-Reply-To: <47a82549-bc80-45ac-8b51-d58e597e768f@r24g2000vbp.googlegroups.com> References: <47a82549-bc80-45ac-8b51-d58e597e768f@r24g2000vbp.googlegroups.com> Message-ID: bearophileHUGS at lycos.com wrote: [a somewhat feeble case for ordered dicts] > Once the default dicts are ordered, it can be possible to add an > unordereddict to the collections module to be used by programmers when > max performance or low memory usage is very important :-) > I have no real idea why you think it's desirable to turn this important feature on its head, but if you've followed the various past threads on ordered dicts you would know that one of the prime issues every time this comes up is the inability of the various proponents to agree no ow dicts should actually be ordered. > Namespaces and other internal things of Python can keep using the un- > ordereddicts. > > I don't know what to do regarding Python sets yet. In mathematics sets > aren't ordered, so they may be kept as they are now. > In mathematics mappings aren't ordered either, and a pure dict is pretty much a mapping. So leave them alone, they are fine as they are! regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From http Thu Feb 5 05:25:03 2009 From: http (Paul Rubin) Date: 05 Feb 2009 02:25:03 -0800 Subject: Ordered dict by default References: <47a82549-bc80-45ac-8b51-d58e597e768f@r24g2000vbp.googlegroups.com> Message-ID: <7x7i45qiyo.fsf@ruckus.brouhaha.com> bearophileHUGS at lycos.com writes: > Now Ruby dicts are ordered by default: > http://www.igvita.com/2009/02/04/ruby-19-internals-ordered-hash/ Maybe I didn't read that carefully enough, but it looks like "ordered" means the dict records come out in the same order you inserted them in. That is if you insert B,A,D,C in that order, you get them out in that order. I would have thought an ordered dict meant you get A,B,C,D, which seems a lot more useful. Red-black trees as described at the bottom of the page are a good way to get A,B,C,D. They also make it simple to have "persistent" or "functional" dictionaries, which I've written about a few times before. From http Thu Feb 5 05:28:04 2009 From: http (Paul Rubin) Date: 05 Feb 2009 02:28:04 -0800 Subject: Ordered dict by default References: <47a82549-bc80-45ac-8b51-d58e597e768f@r24g2000vbp.googlegroups.com> Message-ID: <7x3aetqitn.fsf@ruckus.brouhaha.com> Steve Holden writes: > In mathematics mappings aren't ordered either, and a pure dict is pretty > much a mapping. So leave them alone, they are fine as they are! Ehhh, an ordered dict has to support a comparison operation on the keys, while a Python dict has to support a hashing operation on them. Neither really captures the idea of a pure mapping, which shouldn't have to support any operations (even equality) on the keys. There have been several times when I've wished for persistent ordered dicts in Python. I started writing a big post about it a while ago and maybe I'll finish it someday. From duncan.booth at invalid.invalid Thu Feb 5 05:47:52 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 5 Feb 2009 10:47:52 GMT Subject: Using while loop and if statement to tell if a binary has an odd or even number of 1's. References: <6c1875c3-8283-4764-a481-ebfa135868bc@v5g2000pre.googlegroups.com> Message-ID: Tim Rowe wrote: > 2009/2/5 Duncan Booth : >> Mark Dickinson wrote: >> >>> def count_set_bits(n): >>> # make sure we include an if, to >>> # satisfy OP's requirements: >>> if n < 0: >>> raise ValueError >>> count = 0 >>> while n: >>> count += 1 >>> n &= n-1 >>> return count >>> >>> is_even = count_set_bits(the_int) % 2 == 0 >>> >>> ...but anyone submitting this as a homework >>> solution had better be prepared to explain why >>> it works. >>> >> >> I remember a programming exercise when I was an undergraduate and >> anyone who *didn't* use that trick got marked down for writing >> inefficient code. > > Is adding and a modulus *really^ more efficient than flipping a bool > as I suggested? I think I'd want to see measurements! > > I meant the bitwise twiddling, but actually I misread it. I thought Mark was using the n&~n+1 trick to pull out bits from least significant upwards when of course he's just clearing the low bit not extracting it. -- Duncan Booth http://kupuguy.blogspot.com From simon at mullis.co.uk Thu Feb 5 05:50:05 2009 From: simon at mullis.co.uk (Simon Mullis) Date: Thu, 5 Feb 2009 11:50:05 +0100 Subject: parse date/time from a log entry with only strftime (and no regexen) In-Reply-To: <7e3602b0-57c0-4d9e-8c8d-fb0a5b00108d@d36g2000prf.googlegroups.com> References: <23d7e1bb0902030552j6a12dcbcy428c9ede8419fb7b@mail.gmail.com> <7e3602b0-57c0-4d9e-8c8d-fb0a5b00108d@d36g2000prf.googlegroups.com> Message-ID: <23d7e1bb0902050250k60cceb46jf7c1149f0b1e024@mail.gmail.com> That, my friend, is ingenious...! Thankyou SM 2009/2/3 andrew cooke > > > ValueError: unconverted data remains: this is the remainder of the log > > > > line > > > that I do not care about > > you could catch the ValueError and split at the ':' in the .args > attribute to find the extra data. you could then find the extra data > in the original string, use the index to remove it, and re-parse the > time. > > ugly, but should work. > andrew > -- > http://mail.python.org/mailman/listinfo/python-list > -- Simon Mullis _________________ simon at mullis.co.uk -------------- next part -------------- An HTML attachment was scrubbed... URL: From simon at mullis.co.uk Thu Feb 5 05:58:48 2009 From: simon at mullis.co.uk (Simon Mullis) Date: Thu, 5 Feb 2009 11:58:48 +0100 Subject: Should "open(sys.stdin)" and "open(file, 'r')" be equivalent? Message-ID: <23d7e1bb0902050258g3a7b3072w5635b1c9c7ae0d2d@mail.gmail.com> Hi All I've written a simple python script that accepts both stdin and a glob (or at least, that is the plan). Unfortunately, the glob part seems to hang when it's looped through to the end of the filehandle. And I have no idea why... ;-) sys.stdin and a normal file opened with "open" seem to both be identical filehandles. >>> import sys >>> foo = sys.stdin >>> type(foo) >>> repr(foo) "', mode 'r' at 0x16020>" >>> bar = open("test_file", 'r') >>> type(bar) >>> repr(bar) "" The stdin version is fine. I want to re-use the code for scan_data (and all of the other processing methods) so I'd like to be able to iterate over one line at a time, independently of the source (i.e. either file or stdin) Code that illustrates the issue follows: # cat test_fh.py #!/usr/bin/env python import glob, os, sys class TestParse(object): def __init__(self): if (options.stdin): self.scan_data(sys.stdin) if (options.glob): self.files = glob.glob(options.glob) for f in files: fh = open(f, 'r') self.scan_data(fh) fh.close() def scan_data(self,fileobject): i = int() for line in fileobject: print i i += 1 # do stuff with the line... pass print "finished file" def main(): T = TestParse() if __name__ == "__main__": from optparse import OptionParser p = OptionParser(__doc__, version="testing 1 2 3") p.add_option("--glob", dest="glob") p.add_option("--stdin", dest="stdin", action="store_true", default="False") (options, args) = p.parse_args() main() #EOF Running this against stdin outputs a count of lines and then exits fine (exit code 0). # cat test_file | ./test-fh.py --stdin ...output... # echo $? 0 Running against --glob "test_file" just hangs..... # ./test_fh.py --glob "test_file" ....wait 20 seconds or so... ^CTraceback (most recent call last): File "./test_fh.py", line 35, in main() File "./test_fh.py", line 26, in main T = TestParse() File "./test_fh.py", line 8, in __init__ self.scan_data(sys.stdin) File "./test_fh.py", line 18, in scan_data for line in fileobject: KeyboardInterrupt # echo $? 1 So, what am I doing wrong? Thanks in advance SM -- Simon Mullis _________________ simon at mullis.co.uk -------------- next part -------------- An HTML attachment was scrubbed... URL: From duncan.booth at invalid.invalid Thu Feb 5 06:08:09 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 5 Feb 2009 11:08:09 GMT Subject: Ordered dict by default References: <47a82549-bc80-45ac-8b51-d58e597e768f@r24g2000vbp.googlegroups.com> <7x7i45qiyo.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > bearophileHUGS at lycos.com writes: >> Now Ruby dicts are ordered by default: >> http://www.igvita.com/2009/02/04/ruby-19-internals-ordered-hash/ > > Maybe I didn't read that carefully enough, but it looks like "ordered" > means the dict records come out in the same order you inserted them > in. That is if you insert B,A,D,C in that order, you get them out in > that order. I would have thought an ordered dict meant you get A,B,C,D, > which seems a lot more useful. > If you want to write doctests then any stable order in the default dict type would be helpful no matter whether it means that keys are in original insertion or latest insertion order or sorted. There are other use cases where maintaining insertion order is important. For example any automated code generator which parses its previous output and then regenerates it maintaining edits. I ran into that before with one which just stored the methods in a Python dict so that every so often you'd find the entire source file had rearranged itself making a mess of version control. It would certainly be an interesting experiment to mimic the Ruby dict implementation in Python's dict code and see what effect it has on performance: the Ruby page claims that while inserts are slower traversal is much faster. I think it would need some pretty convincing arguments though to become the default. -- Duncan Booth http://kupuguy.blogspot.com From clp2 at rebertia.com Thu Feb 5 06:12:18 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 5 Feb 2009 03:12:18 -0800 Subject: Should "open(sys.stdin)" and "open(file, 'r')" be equivalent? In-Reply-To: <23d7e1bb0902050258g3a7b3072w5635b1c9c7ae0d2d@mail.gmail.com> References: <23d7e1bb0902050258g3a7b3072w5635b1c9c7ae0d2d@mail.gmail.com> Message-ID: <50697b2c0902050312g2aee4b0bu64dda5aa0716b365@mail.gmail.com> On Thu, Feb 5, 2009 at 2:58 AM, Simon Mullis wrote: > Hi All > > I've written a simple python script that accepts both stdin and a glob (or > at least, that is the plan). > Unfortunately, the glob part seems to hang when it's looped through to the > end of the filehandle. > > And I have no idea why... ;-) > > sys.stdin and a normal file opened with "open" seem to both be identical > filehandles. > >>>> import sys >>>> foo = sys.stdin >>>> type(foo) > >>>> repr(foo) > "', mode 'r' at 0x16020>" > >>>> bar = open("test_file", 'r') >>>> type(bar) > >>>> repr(bar) > "" > > The stdin version is fine. I want to re-use the code for scan_data (and all > of the other processing methods) so I'd like to be able to iterate over one > line at a time, independently of the source (i.e. either file or stdin) > > Code that illustrates the issue follows: > > # cat test_fh.py > > #!/usr/bin/env python > import glob, os, sys > class TestParse(object): > def __init__(self): > if (options.stdin): > self.scan_data(sys.stdin) > if (options.glob): > self.files = glob.glob(options.glob) > for f in files: > fh = open(f, 'r') > self.scan_data(fh) > fh.close() > > def scan_data(self,fileobject): > i = int() > for line in fileobject: > print i > i += 1 > # do stuff with the line... > pass > print "finished file" I'd add some print()s in the above loop (and also the 'for f in files' loop) to make sure the part of the code you didn't want to share ("do stuff with the line") works correctly, and that nothing is improperly looping in some unexpected way. Also, there are several series of lines with invalid indentation; could be an email artifact or could be the cause of your problem. If the print()s don't yield any useful insight, repost the code again with absolutely correct indentation. Finally, some stylistic points: - don't do 'if (foo):' use the less noisy 'if foo:' instead - don't do 'i = int()' use the more obvious 'i = 0' instead Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From bruno.42.desthuilliers at websiteburo.invalid Thu Feb 5 06:15:22 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 05 Feb 2009 12:15:22 +0100 Subject: Understanding descriptors In-Reply-To: References: Message-ID: <498aca36$0$24804$426a74cc@news.free.fr> Brian Allen Vanderburg II a ?crit : > I'm trying to better understand descriptors and I've got a few questions > still after reading some sites. Here is what I 'think', but please let > me know if any of this is wrong as I'm sure it probably is. > > > First when accessing an attribute on a class or instance it must be > found. For an instance, it's __dict__ is first search. Actually, this is not true - binding descriptors are searched (in the class and it's mro) _before_ the instance's __dict__ : >>> class Foo(object): ... @apply ... def bar(): ... def fget(self): ... return self._bar ... def fset(self, v): ... self._bar = v ... return property(**locals()) ... >>> f = Foo() >>> f.bar = 42 >>> f.bar 42 >>> f.__dict__['bar'] = "boo" >>> f.bar 42 >>> f.__dict__['bar'] 'boo' >>> Note that this works a bit differently for non-binding descriptors (descriptors that only implement the __get__ method), which are looked up after the instance's __dict__ So the lookup chain is: 1/ lookup the class and bases for a binding descriptor 2/ then lookup the instance's __dict__ 3/ then lookup the class and bases for a non-binding descriptor or plain attribute 4/ then class __getattr__ Also and FWIW, there's a "step zero" : calls __getattribute__. All the above lookup mechanism is actually implemented by object.__getattribute__. > If not found > the class and base class __dict__ are searched. For a class, the > __dict__ and base classes __dict__ are search. > > If assigning, and the attribute is found and is not a descriptor a binding descriptor > or if > the attribute is not found, then the assignment will occur in the > __dict__ of the class or instance. If it is found and is a descriptor, a binding descriptor > then __set__ will be call. > For reading, if the attribute is found and is a descriptor, __get__ will > be called, passing the object (if it is an instance) and class. If it > is not a descriptor, the attribute will be returned directly. > > Class methods are just functions: In Python, "classmethod" has a definite meaning - it's a method that takes the class (and not the instance) as first argument. So your assertion should be "Methods are just functions which are attributes of the class". Which is still not quite true. Sure, the def statement always create function objects, regardless of whether it happens within a class statement or not. OTHO, what you get when looking up the corresponding attribute is definitly a method object. So the correct formulation here is (IMHO of course) that methods are implemented by functions that are attributes of the class. Also, this is not restricted to functions : any callable object correctly implementing the descriptor protocol can be used (cf the classmethod and staticmethod objects). > class C(object): > def F(self): > pass > > C.__dict__['F'] # function object ... yes. > But functions are descriptors: yes. > C.__dict__['F'].__get__ # method wrapper ... > > def f1(): > pass > > f1.__get__ # method wrapper ... > > When a lookup is done it uses this descriptor to make a bound or unbound > method: yes. > c=C() > > C.F # unbound method object, expects explicit instance when calling the > function > c.F # bound method object provides instance implicitly when calling the > function > > This is also done when adding to the classes: Indeed. Whether the def statement happens within the class statement or not is irrelevant here. > C.f1 = f1 > > f1 # function > C.f1 # unbound method > c.f1 # bound method > > To prevent this it has to be decorated so the descriptor doesn't cause > the binding: > > C.f2 = staticmethod(f1) > C.f2 # functon > c.f2 # function yes. > Here is a question, why don't instance attributes do the same thing? Because the descriptor protocol is only invoked on class attributes. > c.f3 = f1 > c.f3 # function, not bound method > > So it is not calling the __get__ method for c.f3 After it finds c.f3 in > c.__dict__, and since it has a getter, shouldn't it call the __get__ to > return the bound method. Nope, cf above. > It is good that it doesn't I know, but I just > want to know why it doesn't from an implementation view. If by "from an implementation view", you mean "how it works", then the answer is above. If your question was about "why this design choice", I'll leave the answer to someone else... From thomasvangurp at gmail.com Thu Feb 5 06:16:46 2009 From: thomasvangurp at gmail.com (thomasvangurp at gmail.com) Date: Thu, 5 Feb 2009 03:16:46 -0800 (PST) Subject: Python 3.0 slow file IO Message-ID: <9e7dc260-1680-42e3-9b93-7bc6c86b2f10@r37g2000prr.googlegroups.com> I just recently learned python, I'm using it mainly to process huge <5GB txt files of ASCII information about DNA. I've decided to learn 3.0, but maybe I need to step back to 2.6? I'm getting exceedingly frustrated by the slow file IO behaviour of python 3.0. I know that a bug-report was submitted here: http://bugs.python.org/issue4533. And a solution was posted. However, i don't know how to apply this patch. I've searched the forums and tried: C:\python30> patch -p0 < fileio_buffer.patch The patch command is not recognized.. Any help on implementing this patch, or advice on moving back to the older version is appreciated. Kind regards, Thomas From http Thu Feb 5 06:25:52 2009 From: http (Paul Rubin) Date: 05 Feb 2009 03:25:52 -0800 Subject: Ordered dict by default References: <47a82549-bc80-45ac-8b51-d58e597e768f@r24g2000vbp.googlegroups.com> <7x7i45qiyo.fsf@ruckus.brouhaha.com> Message-ID: <7xmyd1rupr.fsf@ruckus.brouhaha.com> Duncan Booth writes: > If you want to write doctests then any stable order in the default dict > type would be helpful no matter whether it means that keys are in original > insertion or latest insertion order or sorted. Just use "sorted" in the test code: >>> print sorted(dict((a**2,a) for a in xrange(5)).keys()) [0, 1, 4, 9, 16] > There are other use cases where maintaining insertion order is > important. For example any automated code generator which parses > its previous output and then regenerates it maintaining edits. I ran > into that before with one which just stored the methods in a Python > dict so that every so often you'd find the entire source file had > rearranged itself making a mess of version control. Still doesn't sound so bad: just include a counter with the value. Something like (untested): odict = dict(zip(methodnames, zip(methodbodies, itertools.count()))) ... gen_code(sorted(odict.iteritems(), key=lambda(name,(body,n)): n)) > It would certainly be an interesting experiment to mimic the Ruby dict > implementation in Python's dict code and see what effect it has on > performance: the Ruby page claims that while inserts are slower traversal > is much faster. I think it would need some pretty convincing arguments > though to become the default. In my usage of dicts, traversal is rather rare, but YMMV. From eckhardt at satorlaser.com Thu Feb 5 06:33:44 2009 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Thu, 05 Feb 2009 12:33:44 +0100 Subject: Python 3.0 slow file IO References: <9e7dc260-1680-42e3-9b93-7bc6c86b2f10@r37g2000prr.googlegroups.com> Message-ID: thomasvangurp at gmail.com wrote: > C:\python30> patch -p0 < fileio_buffer.patch > The patch command is not recognized.. You need the 'patch' program first. Further, you will need a C compiler. If you don't know how to compile from sources, I would postpone patching sources to after learning that. > [...] advice on moving back to the older version is appreciated. Just install the latest 2.6 release. I think you can easily install it alongside 3.0, all you need to pay attention to is the "PATH" environment variable. Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From lists at cheimes.de Thu Feb 5 06:40:18 2009 From: lists at cheimes.de (Christian Heimes) Date: Thu, 05 Feb 2009 12:40:18 +0100 Subject: Python 3.0 slow file IO In-Reply-To: <9e7dc260-1680-42e3-9b93-7bc6c86b2f10@r37g2000prr.googlegroups.com> References: <9e7dc260-1680-42e3-9b93-7bc6c86b2f10@r37g2000prr.googlegroups.com> Message-ID: thomasvangurp at gmail.com schrieb: > I just recently learned python, I'm using it mainly to process huge > <5GB txt files of ASCII information about DNA. I've decided to learn > 3.0, but maybe I need to step back to 2.6? > > I'm getting exceedingly frustrated by the slow file IO behaviour of > python 3.0. I know that a bug-report was submitted here: > http://bugs.python.org/issue4533. And a solution was posted. > However, i don't know how to apply this patch. I've searched the > forums and tried: > C:\python30> patch -p0 < fileio_buffer.patch > The patch command is not recognized.. You need the Python sources, a patch utility and Microsoft Visual Studio 2008 in order to compile Python yourself. > > Any help on implementing this patch, or advice on moving back to the > older version is appreciated. I suggest you stick with Python 2.5 or 2.6. Python 3.0 isn't as mature as the 2.x series. It's brand new, lot's of things have changed, too. From s.selvamsiva at gmail.com Thu Feb 5 06:40:35 2009 From: s.selvamsiva at gmail.com (S.Selvam Siva) Date: Thu, 5 Feb 2009 17:10:35 +0530 Subject: string replace for back slash Message-ID: Hi all, I tried to do a string replace as follows, >>> s="hi & people" >>> s.replace("&","\&") 'hi \\& people' >>> but i was expecting 'hi \& people'.I dont know ,what is something different here with escape sequence. -- Yours, S.Selvam -------------- next part -------------- An HTML attachment was scrubbed... URL: From digitig at gmail.com Thu Feb 5 06:45:25 2009 From: digitig at gmail.com (Tim Rowe) Date: Thu, 5 Feb 2009 11:45:25 +0000 Subject: Using while loop and if statement to tell if a binary has an odd or even number of 1's. In-Reply-To: References: <6c1875c3-8283-4764-a481-ebfa135868bc@v5g2000pre.googlegroups.com> Message-ID: 2009/2/5 Duncan Booth : >>> I remember a programming exercise when I was an undergraduate and >>> anyone who *didn't* use that trick got marked down for writing >>> inefficient code. >> >> Is adding and a modulus *really^ more efficient than flipping a bool >> as I suggested? I think I'd want to see measurements! >> >> > I meant the bitwise twiddling, but actually I misread it. I thought Mark > was using the n&~n+1 trick to pull out bits from least significant upwards > when of course he's just clearing the low bit not extracting it. Ah, ok. Yes, that's faster than my bit shifting. A million bytes with your method on my computer with your bit-twiddling takes 1.047 seconds, with my bit-shifting it takes 1.578. On the other hand, unless that was demonstrated to be a bottleneck I'd still go for the bit shifting because I think it's clearer. And I'd want a word with a tutor who insisted on premature optimisation ("The root of all evil", according to C A R Hoare), especially in a scripting language! -- Tim Rowe From mal at egenix.com Thu Feb 5 06:47:03 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Thu, 05 Feb 2009 12:47:03 +0100 Subject: JDBC in CPYTHON In-Reply-To: <63dfd3f1-ce70-4b40-b375-82c0ee03d1c3@u14g2000yqg.googlegroups.com> References: <3e9865ac-ce12-492f-83db-74bd78ed3ee2@i18g2000prf.googlegroups.com> <63dfd3f1-ce70-4b40-b375-82c0ee03d1c3@u14g2000yqg.googlegroups.com> Message-ID: <498AD1B7.5010803@egenix.com> On 2009-02-05 03:49, KMCB wrote: > Thanks Simon and Marc, > > I currently have an app on OSX that I wanted to migrate to NIX, it > uses a ODBC DBAPI interface to communicate with Filemaker. > Unfortunately, FMP does not support linux drivers. They do have a > JDBC driver that looks like it may work. My preference was to run > that app on one machine. > > I may not be understand your suggestion Marc, can the app and bridge > run on the same machine. Can I specify the ODBC to a localhost, being > the bridge? Then have the JDBC driver installed. The setup would work as follows: Python -> mxODBC -> ODBC-JDBC bridge -> JDBC driver -> Filemaker [--- Linux ----------------------------------------] [Mac OS X] I am not sure how you'd have to configure the EasySoft bridge. Please check their documentation for details. We are currently working on releasing mxODBC Connect, our client server Python database interface, for Mac OS X. You will then be able to use a much simpler and more efficient setup: Python -> mxODBC Connect Client -> [--- Linux --------------------] mxODBC Connect Server -> ODBC driver -> Filemaker [--- Mac OS X -----------------------------------] and because the mxODBC Connect Cient is highly portable, moving your application to other platforms would be easily possible as well. Plus, you'd avoid having to carry around the whole JVM in your Python application: the ODBC-JDBC bridge essentially embeds the JVM in your application and then uses JNI to interface from C to Java and from there to the JDBC driver. > Also, your second link does not seam to have a download or anything in > the CVS. Sorry, I should have looked closer... the SF project page reveals that the "PROJECT IS DEAD!": http://sourceforge.net/projects/odbcjdbc/ -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Feb 05 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From clp2 at rebertia.com Thu Feb 5 06:59:16 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 5 Feb 2009 03:59:16 -0800 Subject: string replace for back slash In-Reply-To: References: Message-ID: <50697b2c0902050359y57812425pb31dbb561672b0a0@mail.gmail.com> On Thu, Feb 5, 2009 at 3:40 AM, S.Selvam Siva wrote: > Hi all, > > I tried to do a string replace as follows, > >>>> s="hi & people" >>>> s.replace("&","\&") > 'hi \\& people' >>>> > > but i was expecting 'hi \& people'.I dont know ,what is something different > here with escape sequence. The Python interactive interpreter does an implicit repr() (consult the docs if you're unfamiliar with the repr() function) on the return value of the expression. Note the single quotes in the output, which obviously wouldn't be present in the string itself; same thing with the doubling of the backslash. If you instead do `print s.replace("&","\&")`, you'll see that the outputted string does indeed only contain 1 backslash. It's a common newbie confuser, there really should be a FAQ about it; pity there isn't. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From mal at egenix.com Thu Feb 5 07:00:30 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Thu, 05 Feb 2009 13:00:30 +0100 Subject: Comparing two book chapters (text files) In-Reply-To: <498A3EC6.4040607@berkeley.edu> References: <498A3EC6.4040607@berkeley.edu> Message-ID: <498AD4DE.4080703@egenix.com> On 2009-02-05 02:20, Nick Matzke wrote: > Hi all, > > So I have an interesting challenge. I want to compare two book > chapters, which I have in plain text format, and find out (a) percentage > similarity and (b) what has changed. > > Some features make this problem different than what seems to be the > standard text-matching problem solvable with e.g. difflib. Here is what > I mean: > > * there is no guarantee that single lines from each file will be > directly comparable -- e.g., if a few words are inserted into a > sentence, then a chunk of the sentence will be moved to the next line, > then a chunk of that line moved to the next, etc. > > * Also, there are cases where paragraphs have been moved around, > sections re-ordered, etc. So it can't just be a "linear" match. > > I imagine this kind of thing can't be all that hard in the grand scheme > of things, but I couldn't find an easily applicable solution readily > available. I have advanced beginner python skills but am not quite > where I could do this kind of thing from scratch without some guidance > about the likely functions, libraries etc. to use. > > PS: I am going to have to do this for multiple book chapters so various > software packages, e.g. for windows, are not really usable. > > Any help is much appreciated!! difflib is in the Python stdlib and provides many ways to implement difference detection: http://docs.python.org/library/difflib.html Here's a script that I use for diff'ing text files on a word basis, called tdiff.py: http://downloads.egenix.com/python/tdiff.py It helps a lot with text that gets word wrapped or reformatted. Cheers, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Feb 05 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From mal at egenix.com Thu Feb 5 07:01:33 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Thu, 05 Feb 2009 13:01:33 +0100 Subject: global name 'sqrt' is not defined In-Reply-To: <498AAC89.5080002@berkeley.edu> References: <498AAC89.5080002@berkeley.edu> Message-ID: <498AD51D.5000609@egenix.com> On 2009-02-05 10:08, Nick Matzke wrote: > Hi all, > > So, I can run this in the ipython shell just fine: > > =========== > a = ["12", "15", "16", "38.2"] > dim = int(sqrt(size(a))) > > dim >>2 > =========== > > > But if I move these commands to a function in another file, it freaks out: You need to add: from math import sqrt > ================================= > a = distances_matrix.split('\t') > from LR_run_functions_v2 import make_half_square_array > d = make_half_square_array(a) > >> > --------------------------------------------------------------------------- > NameError Traceback (most recent call last) > > /bioinformatics/phylocom/ in () > > /bioinformatics/phylocom/_scripts/LR_run_functions_v2.py in > make_half_square_array(linear_version_of_square_array) > 1548 > 1549 a = linear_version_of_square_array > -> 1550 dim = int(sqrt(size(a))) > 1551 > 1552 > > NameError: global name 'sqrt' is not defined > > ================================= > > > > > Here's the function in LR_run_functions_v2.py > > ========================== > def make_half_square_array(linear_version_of_square_array): > > a = linear_version_of_square_array > dim = int(sqrt(size(a))) > ========================== > > > > Any ideas? If I do something like "import math" in the subfunction, > then the error changes to "global name 'math' is not defined". > > Thanks! > Nick > > > > > > > -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Feb 05 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From BrianVanderburg2 at aim.com Thu Feb 5 07:04:40 2009 From: BrianVanderburg2 at aim.com (Brian Allen Vanderburg II) Date: Thu, 05 Feb 2009 07:04:40 -0500 Subject: Understanding descriptors In-Reply-To: <498aca36$0$24804$426a74cc@news.free.fr> References: <498aca36$0$24804$426a74cc@news.free.fr> Message-ID: <498AD5D8.50501@aim.com> bruno.42.desthuilliers at websiteburo.invalid wrote: > > So the lookup chain is: > > 1/ lookup the class and bases for a binding descriptor > 2/ then lookup the instance's __dict__ > 3/ then lookup the class and bases for a non-binding descriptor or > plain attribute > 4/ then class __getattr__ > > Also and FWIW, there's a "step zero" : calls __getattribute__. All the > above lookup mechanism is actually implemented by > object.__getattribute__. Okay, so instance attributes never use their __get__/__set__/etc when looking up. A binding descriptor is one that has a __set__ (even if it doesn't do anything) and it takes priority over instance variables. Properties are binding descriptors even if they don't have a set function specified. A non-binding descriptor doesn't have __set__ and instance variables take priority over them. For reading: 1. Lookup in the class/bases for a binding descriptor and if found use its __get__ 2. If instance, look up in instance __dict__ and if found return it 3. Lookup in the class/bases a. if found and a descriptor use it's __get__ b. if found and not a descriptor return it 4. Use __getattr__ (if instance?) For writing: 1. If instance a. lookup in the class/bases for a binding descriptor and if found use its __set__ b. write to instance __dict__ 2. If class, write in class __dict__ I think I understand it now. Thanks. Brian Vanderburg II From duncan.booth at invalid.invalid Thu Feb 5 07:19:09 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 5 Feb 2009 12:19:09 GMT Subject: Ordered dict by default References: <47a82549-bc80-45ac-8b51-d58e597e768f@r24g2000vbp.googlegroups.com> <7x7i45qiyo.fsf@ruckus.brouhaha.com> <7xmyd1rupr.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Duncan Booth writes: >> If you want to write doctests then any stable order in the default >> dict type would be helpful no matter whether it means that keys are >> in original insertion or latest insertion order or sorted. > > Just use "sorted" in the test code: > >>> print sorted(dict((a**2,a) for a in xrange(5)).keys()) > [0, 1, 4, 9, 16] > No, that only works if you have control over the dict iteration. There are plenty of situations when tests become unstable because dicts are unstable and you don't have control over the order of iteration. Also, if you are using doctests as a form of documentation then you just want to be able to show the value, or at most pprint it, you don't want to obscure the documentation with calls to sort. For example if you have something that creates xml then almost certainly the library you are using stores the attributes for a tag in a dictionary and just outputs them in whatever order they iterate over. That's fine for creating XML but when you want a test like: >>> mydata.asXml() <... some xml here except we don't know what order the attributes will appear in ...> then you are stuffed. Actually it's also a problem if you want to store the output XML in Subversion. As with my round-trip coding problem you could obviously solve it by changing the code to sort the output, but stabilising the order of dict iteration would solve the problem for all such cases. -- Duncan Booth http://kupuguy.blogspot.com From rdmurray at bitdance.com Thu Feb 5 07:29:46 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Thu, 5 Feb 2009 12:29:46 +0000 (UTC) Subject: string replace for back slash References: Message-ID: "S.Selvam Siva" wrote: > I tried to do a string replace as follows, > > >>> s="hi & people" > >>> s.replace("&","\&") > 'hi \\& people' > >>> > > but i was expecting 'hi \& people'.I dont know ,what is something different > here with escape sequence. You are running into the difference between the 'repr' of a string (which is what is printed by default at the python prompt) and the actual contents of the string. In the repr the backslash needs to be escaped by prefixing it with a backslash, just as you would if you wanted to enter a backslash into a string in your program. If you print the string, you'll see there is only one backslash. Note that you didn't need to double the backslash in your replacement string only because it wasn't followed by a character that forms an escape...but the repr of that string will still have the backslash doubled, and that is really the way you should write it in your program to begin with for safety's sake. Python 2.6.1 (r261:67515, Jan 7 2009, 17:09:13) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> s="hi & people" >>> replacementstring = "\&" >>> replacementstring '\\&' >>> print replacementstring \& >>> x = s.replace("&","\\&") >>> x 'hi \\& people' >>> print x hi \& people From simon at mullis.co.uk Thu Feb 5 07:37:54 2009 From: simon at mullis.co.uk (Simon Mullis) Date: Thu, 5 Feb 2009 13:37:54 +0100 Subject: Should "open(sys.stdin)" and "open(file, 'r')" be equivalent? In-Reply-To: <50697b2c0902050312g2aee4b0bu64dda5aa0716b365@mail.gmail.com> References: <23d7e1bb0902050258g3a7b3072w5635b1c9c7ae0d2d@mail.gmail.com> <50697b2c0902050312g2aee4b0bu64dda5aa0716b365@mail.gmail.com> Message-ID: <23d7e1bb0902050437i72411bdfrd91732169fa5d0a1@mail.gmail.com> Hi Chris 2009/2/5 Chris Rebert > > I'd add some print()s in the above loop (and also the 'for f in files' > loop) to make sure the part of the code you didn't want to share ("do > stuff with the line") works correctly, and that nothing is improperly > looping in some unexpected way. The point is that even with the very, very simple script I posted above the behavior of open(sys.stdin) and open(filename, 'r') is different. The object foo (where foo = sys.stdin) allows me to iterate then hands back after the loop is finished. The object bar (where bar = open(filename, 'r')) does not. Both foo and bar have the same type, methods, repr etc. > Also, there are several series of lines with invalid indentation; > could be an email artifact or could be the cause of your problem. If > the print()s don't yield any useful insight, repost the code again > with absolutely correct indentation. (code posted again to fix indents) #!/usr/bin/env python import glob, os, sys class TestParse(object): def __init__(self): if options.stdin: self.scan_data(sys.stdin) if options.glob: self.files = glob.glob(options.glob) for f in files: fh = open(f, 'r') self.scan_data(fh) fh.close() def scan_data(self,fileobject): i = 0 for line in fileobject: print i i += 1 # do stuff with the line... pass print "finished file" def main(): T = TestParse() if __name__ == "__main__": from optparse import OptionParser p = OptionParser(__doc__, version="testing 1 2 3") p.add_option("--glob", dest="glob") p.add_option("--stdin", dest="stdin", action="store_true", default="False") (options, args) = p.parse_args() main() (The code I'm actually using is much more complex than this. I tried to create the most simple example of it _not_ working as expected...) > Finally, some stylistic points: > - don't do 'if (foo):' use the less noisy 'if foo:' instead > - don't do 'i = int()' use the more obvious 'i = 0' instead > ok. My question again, to be more explicit: Should the objects created by sys.stdin and open(filename, 'r') have the same behavior when iterated over? They both have __iter__ methods.... Thanks in advance for any suggestions SM From rdmurray at bitdance.com Thu Feb 5 07:39:09 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Thu, 5 Feb 2009 12:39:09 +0000 (UTC) Subject: Python 3.0 slow file IO References: <9e7dc260-1680-42e3-9b93-7bc6c86b2f10@r37g2000prr.googlegroups.com> Message-ID: Quoth Christian Heimes : > thomasvangurp at gmail.com schrieb: > > I just recently learned python, I'm using it mainly to process huge > > <5GB txt files of ASCII information about DNA. I've decided to learn > > 3.0, but maybe I need to step back to 2.6? > > > > I'm getting exceedingly frustrated by the slow file IO behaviour of > > python 3.0. I know that a bug-report was submitted here: > > http://bugs.python.org/issue4533. And a solution was posted. [snip stuff about patching] > > I suggest you stick with Python 2.5 or 2.6. Python 3.0 isn't as mature > as the 2.x series. It's brand new, lot's of things have changed, too. 3.1 will come out much sooner than a normal "next dot" release python would, and will contain very significant improvements in the IO speed. In the meantime, in your case at least, to get real work done you'll be better off using 2.6. You can use the 'from __future__ import' to bring various 3.0 features into 2.6 and make 2.6 look more like 3.0, and you can use the -3 flag to check your code for 3.0 compatibility, so that you will be ready to move back to the 3 series when 3.1 comes out. (Assuming you don't end up needing any 3rd party libraries that haven't been ported yet by then, that is.) Unless, of course, you are comfortable with compiling from source and would like to help _test_ the 3.1 IO library.... :) --RDM From andrew at acooke.org Thu Feb 5 07:50:39 2009 From: andrew at acooke.org (andrew cooke) Date: Thu, 5 Feb 2009 04:50:39 -0800 (PST) Subject: Ordered dict by default References: <47a82549-bc80-45ac-8b51-d58e597e768f@r24g2000vbp.googlegroups.com> Message-ID: <6e4959e8-b5e2-43da-9199-8bd0d2499e03@i18g2000prf.googlegroups.com> so what is happening with pep 372? http://www.python.org/dev/peps/pep-0372/ From mrkafk at gmail.com Thu Feb 5 07:54:15 2009 From: mrkafk at gmail.com (mk) Date: Thu, 05 Feb 2009 13:54:15 +0100 Subject: Arguments for map'ped functions Message-ID: Hello everyone, So I have this function I want to map onto a list of sequences of *several* arguments (while I would want to pass those arguments to each function in the normal fashion). I realize this is contrived, maybe an example would make this clear: params = [ ('comp.lang.python', ['rtfm', 'shut']), ('comp.lang.perl', ['rtfm','shut']) ] qurls = map(consqurls, params) def consqurls(args): ggroup, gkeywords = args ... Since the argument passed to map'ped function is a single tuple of arguments, I have to unpack them in the function. So the question is how to pass several arguments to a map'ped function here? Code in question: def fillurlfmt(args): urlfmt, ggroup, gkw = args return {'group':ggroup, 'keyword':gkw, 'url': urlfmt % (gkw, ggroup)} def consqurls(args): ggroup, gkeywords = args urlfmt = 'http://groups.google.com/groups/search?as_q=%s&as_epq=&as_oq=&as_eq=&num=10&scoring=&lr=&as_sitesearch=&as_qdr=&as_drrb=b&as_mind=1&as_minm=1&as_miny=1999&as_maxd=1&as_maxm=1&as_maxy=2009&as_ugroup=%s&as_usubject=&as_uauthors=&safe=off' qurls = map(fillurlfmt, [ (urlfmt, ggroup, gkw) for gkw in gkeywords]) return qurls if __name__ == "__main__": gkeywords = ['rtfm', 'shut'] ggroups = ['comp.lang.python', 'comp.lang.perl'] params = [(ggroup, gkeywords) for ggroup in ggroups] qurls = map(consqurls, params) print qurls Regards, mk From pythonsky at sky.com Thu Feb 5 07:55:42 2009 From: pythonsky at sky.com (garywood) Date: Thu, 5 Feb 2009 12:55:42 -0000 Subject: python 3 error i know the file works in python 2.6 Message-ID: can someone help me please #open file and read last names filename = input('name file') file = open(filename, 'r') names_list = file.readlines() file.close() #open a file for saving passwords outfile_name = input('Save passwords') outfile = open(outfile_name, 'a') #create a password for each name in list import random, string name = ('') for name in names_list: name_prefix = name[0:2] number = random.randrange(100,999) name_prefix = str.upper(name_prefix) password = name_prefix + str(number) whole_line = (password) print (password) outfile_name.write(whole_line) outfile_name.close() print (password) error Traceback (most recent call last): File "C:\Documents and Settings\Gary\Desktop\python\bembry\pa2.i.py", line 21, in outfile_name.write(whole_line) AttributeError: 'str' object has no attribute 'write' -------------- next part -------------- An HTML attachment was scrubbed... URL: From simon at mullis.co.uk Thu Feb 5 08:09:17 2009 From: simon at mullis.co.uk (Simon Mullis) Date: Thu, 5 Feb 2009 14:09:17 +0100 Subject: Should "open(sys.stdin)" and "open(file, 'r')" be equivalent? In-Reply-To: <23d7e1bb0902050437i72411bdfrd91732169fa5d0a1@mail.gmail.com> References: <23d7e1bb0902050258g3a7b3072w5635b1c9c7ae0d2d@mail.gmail.com> <50697b2c0902050312g2aee4b0bu64dda5aa0716b365@mail.gmail.com> <23d7e1bb0902050437i72411bdfrd91732169fa5d0a1@mail.gmail.com> Message-ID: <23d7e1bb0902050509q60318147r70175d636d220974@mail.gmail.com> Last try at getting the indenting to appear correctly.. #!/usr/bin/env python import glob, os, sys class TestParse(object): def __init__(self): if options.stdin: self.scan_data(sys.stdin) if options.glob: self.files = glob.glob(options.glob) for f in files: fh = open(f, 'r') self.scan_data(fh) fh.close() def scan_data(self,fileobject): i = 0 for line in fileobject: print i i += 1 # do stuff with the line... pass print "finished file" def main(): T = TestParse() if __name__ == "__main__": from optparse import OptionParser p = OptionParser(__doc__, version="testing 1 2 3") p.add_option("--glob", dest="glob", help="""use this glob""") p.add_option("--stdin", dest="stdin", action="store_true", default="False", help="""use stdin""") (options, args) = p.parse_args() main() From __peter__ at web.de Thu Feb 5 08:09:29 2009 From: __peter__ at web.de (Peter Otten) Date: Thu, 05 Feb 2009 14:09:29 +0100 Subject: Arguments for map'ped functions References: Message-ID: mk wrote: > So I have this function I want to map onto a list of sequences of > *several* arguments (while I would want to pass those arguments to each > function in the normal fashion). I realize this is contrived, maybe an You can either use a list comprehension [f(*args) for args in seq] or starmap() list(itertools.starmap(f, seq)) Peter From mrkafk at gmail.com Thu Feb 5 08:17:34 2009 From: mrkafk at gmail.com (mk) Date: Thu, 05 Feb 2009 14:17:34 +0100 Subject: Flattening lists Message-ID: Hello everybody, Any better solution than this? def flatten(x): res = [] for el in x: if isinstance(el,list): res.extend(flatten(el)) else: res.append(el) return res a = [1, 2, 3, [4, 5, 6], [[7, 8], [9, 10]]] print flatten(a) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Regards, mk From simon at mullis.co.uk Thu Feb 5 08:18:19 2009 From: simon at mullis.co.uk (Simon Mullis) Date: Thu, 5 Feb 2009 14:18:19 +0100 Subject: [SOLVED] Re: Should "open(sys.stdin)" and "open(file, 'r')" be equivalent? In-Reply-To: <23d7e1bb0902050509q60318147r70175d636d220974@mail.gmail.com> References: <23d7e1bb0902050258g3a7b3072w5635b1c9c7ae0d2d@mail.gmail.com> <50697b2c0902050312g2aee4b0bu64dda5aa0716b365@mail.gmail.com> <23d7e1bb0902050437i72411bdfrd91732169fa5d0a1@mail.gmail.com> <23d7e1bb0902050509q60318147r70175d636d220974@mail.gmail.com> Message-ID: <23d7e1bb0902050518h2e8752c9of1f90596accaa6f5@mail.gmail.com> Forget it all... I was being very very daft! The "default = 'False'" in the options for stdin was not being evaluated as I thought, so the script was waiting for stdin even when there was the glob switch was used...No stdin equals the script seeming to "hang". Ah well. SM From lists at cheimes.de Thu Feb 5 08:18:28 2009 From: lists at cheimes.de (Christian Heimes) Date: Thu, 05 Feb 2009 14:18:28 +0100 Subject: Ordered dict by default In-Reply-To: <6e4959e8-b5e2-43da-9199-8bd0d2499e03@i18g2000prf.googlegroups.com> References: <47a82549-bc80-45ac-8b51-d58e597e768f@r24g2000vbp.googlegroups.com> <6e4959e8-b5e2-43da-9199-8bd0d2499e03@i18g2000prf.googlegroups.com> Message-ID: andrew cooke schrieb: > so what is happening with pep 372? > > http://www.python.org/dev/peps/pep-0372/ It's still a draft and hasn't been implemented yet. Now is the time to get it ready for Python 3.1 and 2.7. Christian From andreas.tawn at ubisoft.com Thu Feb 5 08:22:04 2009 From: andreas.tawn at ubisoft.com (Andreas Tawn) Date: Thu, 5 Feb 2009 14:22:04 +0100 Subject: python 3 error i know the file works in python 2.6 In-Reply-To: References: Message-ID: <8AEDA5E3386EA742B8C24C95FF0C758005B55074@PDC-MAIL3.ubisoft.org> >#open file and read last names >filename = input('name file') >file = open(filename, 'r') >names_list = file.readlines() >file.close() >#open a file for saving passwords >outfile_name = input('Save passwords') >outfile = open(outfile_name, 'a') > > >#create a password for each name in list >import random, string >name = ('') >for name in names_list: > name_prefix = name[0:2] > number = random.randrange(100,999) > name_prefix = str.upper(name_prefix) > password = name_prefix + str(number) > whole_line = (password) > print (password) > outfile_name.write(whole_line) > outfile_name.close() > > print (password) > >error >Traceback (most recent call last): > File "C:\Documents and Settings\Gary\Desktop\python\bembry\pa2.i.py", line 21, in > outfile_name.write(whole_line) >AttributeError: 'str' object has no attribute 'write' You're trying to output to the output filename string rather that the output file you opened with that filename. Cheers, Drea From BrianVanderburg2 at aim.com Thu Feb 5 08:22:38 2009 From: BrianVanderburg2 at aim.com (Brian Allen Vanderburg II) Date: Thu, 05 Feb 2009 08:22:38 -0500 Subject: Flattening lists In-Reply-To: References: Message-ID: <498AE81E.6020100@aim.com> mrkafk at gmail.com wrote: > Hello everybody, > > Any better solution than this? > > def flatten(x): > res = [] > for el in x: > if isinstance(el,list): > res.extend(flatten(el)) > else: > res.append(el) > return res > > a = [1, 2, 3, [4, 5, 6], [[7, 8], [9, 10]]] > print flatten(a) > > > [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] > > Regards, > mk > > -- > http://mail.python.org/mailman/listinfo/python-list I think it may be just a 'little' more efficient to do this: def flatten(x, res=None): if res is None: res = [] for el in x: if isinstance(el, (tuple, list)): flatten(el, res) else: res.append(el) return res Brian Vanderburg II From mrkafk at gmail.com Thu Feb 5 08:44:09 2009 From: mrkafk at gmail.com (mk) Date: Thu, 05 Feb 2009 14:44:09 +0100 Subject: Flattening lists In-Reply-To: <498AE81E.6020100@aim.com> References: <498AE81E.6020100@aim.com> Message-ID: Brian Allen Vanderburg II wrote: >> def flatten(x): >> res = [] >> for el in x: >> if isinstance(el,list): >> res.extend(flatten(el)) >> else: >> res.append(el) >> return res > > I think it may be just a 'little' more efficient to do this: > > def flatten(x, res=None): > if res is None: > res = [] > > for el in x: > if isinstance(el, (tuple, list)): > flatten(el, res) > else: > res.append(el) > > return res Hmm why should it be more efficient? extend operation should not be very costly? Regards, mk From s.selvamsiva at gmail.com Thu Feb 5 08:48:11 2009 From: s.selvamsiva at gmail.com (S.Selvam Siva) Date: Thu, 5 Feb 2009 19:18:11 +0530 Subject: string replace for back slash In-Reply-To: References: Message-ID: On Thu, Feb 5, 2009 at 5:59 PM, wrote: > "S.Selvam Siva" wrote: > > I tried to do a string replace as follows, > > > > >>> s="hi & people" > > >>> s.replace("&","\&") > > 'hi \\& people' > > >>> > > > > but i was expecting 'hi \& people'.I dont know ,what is something > different > > here with escape sequence. > > You are running into the difference between the 'repr' of a string (which > is what is printed by default at the python prompt) and the actual > contents of the string. In the repr the backslash needs to be escaped > by prefixing it with a backslash, just as you would if you wanted to > enter a backslash into a string in your program. If you print the string, > you'll see there is only one backslash. Note that you didn't need to > double the backslash in your replacement string only because it wasn't > followed by a character that forms an escape...but the repr of that > string will still have the backslash doubled, and that is really the > way you should write it in your program to begin with for safety's sake. > > Python 2.6.1 (r261:67515, Jan 7 2009, 17:09:13) > [GCC 4.3.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> s="hi & people" > >>> replacementstring = "\&" > >>> replacementstring > '\\&' > >>> print replacementstring > \& > >>> x = s.replace("&","\\&") > >>> x > 'hi \\& people' > >>> print x > hi \& people > > -- > http://mail.python.org/mailman/listinfo/python-list Thank you all for your response, Now i understood the way python terminal expose '\'. -- Yours, S.Selvam -------------- next part -------------- An HTML attachment was scrubbed... URL: From youri_lammers_88 at hotmail.com Thu Feb 5 09:00:21 2009 From: youri_lammers_88 at hotmail.com (Youri Lammers) Date: Thu, 5 Feb 2009 15:00:21 +0100 Subject: os.system issues Message-ID: Ok, I want to run a program called 'muscle' with my python script, muscle uses the following command: 'muscle.exe -in filename -out filename' so far I got: import os args = ['-in filename', '-out filename'] os.system('E:\Programs\muscle\muscle.exe args') However, when I run this nothing happends, no error message, nothing. So what am I doing wrong here? Youri _________________________________________________________________ De leukste online filmpjes vind je op MSN Video! http://video.msn.com/video.aspx?mkt=nl-nl -------------- next part -------------- An HTML attachment was scrubbed... URL: From kyosohma at gmail.com Thu Feb 5 09:07:21 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Thu, 5 Feb 2009 06:07:21 -0800 (PST) Subject: How to find wxPython method documentation?? References: <10ead1a8-fc44-4392-b07d-54c00f0619f7@r36g2000prf.googlegroups.com> <5ef6e64b-1468-4ee2-8261-3ba027ca5370@p2g2000prf.googlegroups.com> Message-ID: <1cec1f1f-296c-4df6-abc3-447b5790ce41@p2g2000prn.googlegroups.com> On Feb 4, 5:49?pm, andrew cooke wrote: > On Feb 4, 8:06?pm, len wrote: > > > How does one find the methods that are available in the classes. > > heh. ?welcome to the wonderful world of wxpython :o( > > if you use eclipse to edit your code, then (providing the wind is in > the right direction and the file you are editing doesn't have any > syntax errors) pressing F3 when you are on a particular method will > take you to the definition. ?or, at least, one of the definitions with > that name. > > and if you want to see a list of available methods the simplest way is > to use tab completion (or dir() in python itself). > > if you're not using eclipse (with pydev) check to see if the ide/ > editor you are using has something similar. > > also, wxpython comes with some examples, all packaged in a demo > program. ?that is your best source of documentation. ?go through all > the examples in there and look at the code (the demo program will show > you the code and even let you edit it and see the results of your > changes). > > to be honest, wxpython is a bit of a nightmare (imho). but the results > can be worth it. > > good luck, > andrew I don't think the docs are any worse than any other complicated third party package. Reportlab comes to mind...and the wxPython list members are very helpful. Mike From lists at cheimes.de Thu Feb 5 09:08:14 2009 From: lists at cheimes.de (Christian Heimes) Date: Thu, 05 Feb 2009 15:08:14 +0100 Subject: os.system issues In-Reply-To: References: Message-ID: Youri Lammers schrieb: > Ok, > > I want to run a program called 'muscle' with my python script, > muscle uses the following command: > 'muscle.exe -in filename -out filename' > so far I got: > > import os > args = ['-in filename', '-out filename'] > os.system('E:\Programs\muscle\muscle.exe args') > > However, when I run this nothing happends, no error message, nothing. > > So what am I doing wrong here? For starters you should use the subprocess module instead of os.system. Next you have either write "E:\\..." or r"E:\..." (note the trailing 'r'). Try this: import subprocess subprocess.check_call(['E:\\Programs\\muscle\\muscle.exe', '-in', 'filename', '-out', 'filename']) Christian From kyosohma at gmail.com Thu Feb 5 09:08:50 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Thu, 5 Feb 2009 06:08:50 -0800 (PST) Subject: How to find wxPython method documentation?? References: <10ead1a8-fc44-4392-b07d-54c00f0619f7@r36g2000prf.googlegroups.com> Message-ID: On Feb 4, 5:06?pm, len wrote: > Hi > > I am going through the "wxPython in Action" book by Noel Rappin and > Robin Dunn. > > I have been typing in the example programs as I go and play with > modifing the code. > Thought I should start trying to find my way around the documentation > found on the wxPython web site. > > The problem I have been having is I can't find the methods or more > specifically > > 'SetBackgroundColour' or 'AddSimpleTool' for example. > > How does one find the methods that are available in the classes. > > I tried looking at the wxWidgets web site and still had the same > problem. > > Could someone give me a little direction in this? > > Thanks > Len In addition to what the others have said, there's also an alternate doc location done up by one guy who seems to have a lot of free time: http://xoomer.virgilio.it/infinity77/wxPython/index.html The wiki is also helpful: http://wiki.wxpython.org/ But I concur that the mailing list is definitely THE place to be to learn the most once you've gotten comfortable with the toolkit. Mike From sgeiger at councilforeconed.org Thu Feb 5 09:10:06 2009 From: sgeiger at councilforeconed.org (Shane Geiger) Date: Thu, 05 Feb 2009 09:10:06 -0500 Subject: Flattening lists In-Reply-To: <498AE81E.6020100@aim.com> References: <498AE81E.6020100@aim.com> Message-ID: <498AF33E.4080907@councilforeconed.org> These functions come from goopy: def flatten1(seq): """ Return a list with the contents of SEQ with sub-lists and tuples "exploded". This is only done one-level deep. """ lst = [] for x in seq: if type(x) is list or type(x) is tuple: for val in x: lst.append(val) else: lst.append(x) return lst def flatten(seq): """ Returns a list of the contents of seq with sublists and tuples "exploded". The resulting list does not contain any sequences, and all inner sequences are exploded. For example: >>> flatten([7,(6,[5,4],3),2,1]) [7,6,5,4,3,2,1] """ lst = [] for el in seq: if type(el) == list or type(el) is tuple: lst.extend(flatten(el)) else: lst.append(el) return lst Brian Allen Vanderburg II wrote: > mrkafk at gmail.com wrote: >> Hello everybody, >> >> Any better solution than this? >> >> def flatten(x): >> res = [] >> for el in x: >> if isinstance(el,list): >> res.extend(flatten(el)) >> else: >> res.append(el) >> return res >> >> a = [1, 2, 3, [4, 5, 6], [[7, 8], [9, 10]]] >> print flatten(a) >> >> >> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >> >> Regards, >> mk >> >> -- >> http://mail.python.org/mailman/listinfo/python-list > > I think it may be just a 'little' more efficient to do this: > > def flatten(x, res=None): > if res is None: > res = [] > > for el in x: > if isinstance(el, (tuple, list)): > flatten(el, res) > else: > res.append(el) > > return res > > Brian Vanderburg II > -- > http://mail.python.org/mailman/listinfo/python-list > -- Shane Geiger, IT Director Council For Economic Education / www.councilforeconed.org sgeiger at councilforeconed.org / 402-438-8958 Teaching Opportunity From rdmurray at bitdance.com Thu Feb 5 09:14:55 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Thu, 5 Feb 2009 14:14:55 +0000 (UTC) Subject: os.system issues References: Message-ID: Youri Lammers writes: > I want to run a program called 'muscle' with my python script=2C > muscle uses the following command: > 'muscle.exe -in filename -out filename' > so far I got: > > import os > args = ['-in filename', '-out filename'] > os.system('E:\Programs\muscle\muscle.exe args') > > However when I run this nothing happends no error message nothing. > > So what am I doing wrong here? You are calling the program muscle with the argument 'args'. If you want to put your arguments into the system call, you will want to write it like this: os.system('E:\Programs\muscle\muscle.exe -in filename -out filename') If you need to substitute args into the string passed to os.system, then take a look at python string handling in the tutorial. You also will probably want to look at the 'subprocess' module at some point, which is more flexible than os.system. --RDM From mrkafk at gmail.com Thu Feb 5 09:17:19 2009 From: mrkafk at gmail.com (mk) Date: Thu, 05 Feb 2009 15:17:19 +0100 Subject: Flattening lists In-Reply-To: <498AE81E.6020100@aim.com> References: <498AE81E.6020100@aim.com> Message-ID: Brian Allen Vanderburg II wrote: >> def flatten(x): >> res = [] >> for el in x: >> if isinstance(el,list): >> res.extend(flatten(el)) >> else: >> res.append(el) >> return res > > I think it may be just a 'little' more efficient to do this: > > def flatten(x, res=None): > if res is None: > res = [] > > for el in x: > if isinstance(el, (tuple, list)): > flatten(el, res) > else: > res.append(el) > > return res Hmm why should it be more efficient? extend operation should not be very costly? Regards, mk From netzhen at gmail.com Thu Feb 5 09:36:37 2009 From: netzhen at gmail.com (Baolong zhen) Date: Thu, 5 Feb 2009 22:36:37 +0800 Subject: Flattening lists In-Reply-To: References: <498AE81E.6020100@aim.com> Message-ID: less list creation. On Thu, Feb 5, 2009 at 10:17 PM, mk wrote: > Brian Allen Vanderburg II wrote: > >> def flatten(x): > >> res = [] > >> for el in x: > >> if isinstance(el,list): > >> res.extend(flatten(el)) > >> else: > >> res.append(el) > >> return res > > > > > I think it may be just a 'little' more efficient to do this: > > > > def flatten(x, res=None): > > if res is None: > > res = [] > > > > for el in x: > > if isinstance(el, (tuple, list)): > > flatten(el, res) > > else: > > res.append(el) > > > > return res > > > Hmm why should it be more efficient? extend operation should not be very > costly? > > > Regards, > mk > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From invalid at invalid Thu Feb 5 10:16:10 2009 From: invalid at invalid (Grant Edwards) Date: Thu, 05 Feb 2009 09:16:10 -0600 Subject: os.system issues References: Message-ID: On 2009-02-05, Christian Heimes wrote: > Youri Lammers schrieb: >> Ok, >> >> I want to run a program called 'muscle' with my python script, >> muscle uses the following command: >> 'muscle.exe -in filename -out filename' >> so far I got: >> >> import os >> args = ['-in filename', '-out filename'] >> os.system('E:\Programs\muscle\muscle.exe args') >> >> However, when I run this nothing happends, no error message, nothing. >> >> So what am I doing wrong here? > > For starters you should use the subprocess module instead of os.system. > Next you have either write "E:\\..." or r"E:\..." (note the trailing 'r'). Leading 'r'. Or just skip cmd.exe and use forward slashes like god intended. -- Grant Edwards grante Yow! I'd like MY data-base at JULIENNED and stir-fried! visi.com From ljjediknight at gmail.com Thu Feb 5 10:20:55 2009 From: ljjediknight at gmail.com (Luke) Date: Thu, 5 Feb 2009 07:20:55 -0800 (PST) Subject: Tkinter References: <593b7e33-f0ef-434f-b967-a4a1a102aab1@z6g2000pre.googlegroups.com> Message-ID: <92bb5b5e-bd93-4bc1-97a0-9d36be5f3a6b@t26g2000prh.googlegroups.com> Thanks, Its working smoothly now From dickinsm at gmail.com Thu Feb 5 10:21:22 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Thu, 5 Feb 2009 07:21:22 -0800 (PST) Subject: Flattening lists References: Message-ID: <0ac212c8-e148-44f8-8f30-050064303c96@f40g2000pri.googlegroups.com> On Feb 5, 1:17?pm, mk wrote: > Hello everybody, > > Any better solution than this? > > def flatten(x): Just out of interest, how often do people really need such a recursive flatten, as opposed to a single-level version? I often find myself needing a 'concat' method that turns a list of lists (or iterable of iterables) into a single list; itertools.chain does this quite nicely. But I don't think I've ever encountered a need for the full recursive version. Mark From durumdara at gmail.com Thu Feb 5 10:21:29 2009 From: durumdara at gmail.com (durumdara) Date: Thu, 05 Feb 2009 16:21:29 +0100 Subject: Cheetah and hungarian charset... Message-ID: <498B03F9.3040109@gmail.com> Hi! I wanna ask that have anyone some exp. with Cheetah and the non-ascii chars? I have a site. The html template documents are saved in ansi format, psp liked them. But the cheetah parser makes ParseError on hungarian characters, like "?", "?", "?", etc. When I remove them, I got good result, but I don't want to remove them all... I cannot parse them. Please help me, how to force cheetah to eat them all? Thanks for your help: dd From james at agentultra.com Thu Feb 5 10:22:20 2009 From: james at agentultra.com (J Kenneth King) Date: Thu, 05 Feb 2009 15:22:20 +0000 Subject: [Web 2.0] Added-value of frameworks? References: <498a1dc7$0$10675$426a74cc@news.free.fr> Message-ID: <877i44c3ir.fsf@agentultra.com> Bruno Desthuilliers writes: > Gilles Ganault a ?crit : >> Hello >> >> If I wanted to build some social web site such as Facebook, what do >> frameworks like Django or TurboGears provide over writing a site from >> scratch using Python? > > Quite a lot of abstractions and factorisation of the boilerplate code, > a known way to organize your application, and possibly a good > integration of the usual components (and wrt/ Django, a customizable > yet fairly usable OOTB admin interface). For simple to mediumly > complex applications, this can mean more than 80% of the grunt > work. The counterpart is mostly learning and understanding the > framework, which means you may not save that much time on a first > project - but it can really pay off then. One of my coworker started > this morning a (really simple...) project which acceptance tests are > to begin on monday, and we are all quite confident he'll deliver on > time, thanks to Django. Well the big negative is when you application design starts expanding past the framework design. A percolator makes a decent cup of coffee but it really isn't meant for making fancy lattes. This is where the 90/10 rule will catch you if you're not careful. "90% of the effort will be spent on the last 10% of the work." From jason-sage at creativetrax.com Thu Feb 5 10:22:29 2009 From: jason-sage at creativetrax.com (jason-sage at creativetrax.com) Date: Thu, 05 Feb 2009 09:22:29 -0600 Subject: Flattening lists In-Reply-To: References: Message-ID: <498B0435.9020104@creativetrax.com> mk wrote: > Hello everybody, > > Any better solution than this? > > def flatten(x): > res = [] > for el in x: > if isinstance(el,list): > res.extend(flatten(el)) > else: > res.append(el) > return res > > a = [1, 2, 3, [4, 5, 6], [[7, 8], [9, 10]]] > print flatten(a) It depends on what you mean by "better". More features? Here is the function from Sage (http://www.sagemath.org), which is a modified version of a more standard implementation to give a max_level argument. The first few lines of documentation: def flatten(in_list, ltypes=(list, tuple), max_level=sys.maxint): """ Flattens a nested list. INPUT: in_list -- a list or tuple ltypes -- optional list of particular types to flatten max_level -- the maximum level to flatten OUTPUT: a flat list of the entries of in_list (lots of examples follow this documentation) The implementation: http://www.sagemath.org/hg/sage-main/file/b0aa7ef45b3c/sage/misc/flatten.py Jason From mrkafk at gmail.com Thu Feb 5 10:24:53 2009 From: mrkafk at gmail.com (mk) Date: Thu, 05 Feb 2009 16:24:53 +0100 Subject: Flattening lists In-Reply-To: References: <498AE81E.6020100@aim.com> Message-ID: Baolong zhen wrote: > less list creation. At the cost of doing this at each 'flatten' call: if res is None: res = [] The number of situations of executing above code is the same as the number of list creations (once for each 'flatten' call, obviously). Is list creation really more costly than above? Regards, mk From google at mrabarnett.plus.com Thu Feb 5 10:29:20 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 05 Feb 2009 15:29:20 +0000 Subject: time: Daylight savings confusion In-Reply-To: <498AB3E3.1060804@mattnordhoff.com> References: <498AB3E3.1060804@mattnordhoff.com> Message-ID: <498B05D0.8060706@mrabarnett.plus.com> Matt Nordhoff wrote: > Tim H wrote: >> On Win XP 64bit, Python 2.6.1 64bit >> >> I am trying to rename files by their creation time. >> >> It seems the time module is too smart for its own good here. >> >> time.localtime(os.path.getctime(f)) returns a value one hour off >> from what windows reports for files that were created when Daylight >> savings time was in effect (ie when the tm_isdst field is one). I >> can kludge it, but am I missing the "right" way to do it? >> >> Tim >> >> full code: > > > >> From what I remember, this is a bug in the Win32 API. Python >> probably could hack around it, but, well, I guess it doesn't. > > Googling a bit, Perl's Win32::UTCFileTime module [1] provides > workarounds (not for Python, of course, but it could probably be > ported) and explains all the gory details (which I have not read, so > maybe I misunderstand ;-). > > [1] > > Windows does apply the current value of DST when converting from UTC to local time. The problem is that the rules for when DST starts and ends might change over time and from place to place, and local time depends on the timezone too. Probably the best you can do is just to apply the current rules and accept that the result might not match what the local time actually was. From michele.simionato at gmail.com Thu Feb 5 10:33:30 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Thu, 5 Feb 2009 07:33:30 -0800 (PST) Subject: Flattening lists References: Message-ID: On Feb 5, 2:17?pm, mk wrote: > Hello everybody, > > Any better solution than this? > > def flatten(x): > ? ? ?res = [] > ? ? ?for el in x: > ? ? ? ? ?if isinstance(el,list): > ? ? ? ? ? ? ?res.extend(flatten(el)) > ? ? ? ? ?else: > ? ? ? ? ? ? ?res.append(el) > ? ? ?return res > > a = [1, 2, 3, [4, 5, 6], [[7, 8], [9, 10]]] > print flatten(a) > > [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] > > Regards, > mk Looks fine to me. In some situations you may also use hasattr(el, '__iter__') instead of isinstance(el, list) (it depends if you want to flatten generic iterables or only lists). From google at mrabarnett.plus.com Thu Feb 5 10:36:14 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 05 Feb 2009 15:36:14 +0000 Subject: Using while loop and if statement to tell if a binary has an odd or even number of 1's. In-Reply-To: <6c1875c3-8283-4764-a481-ebfa135868bc@v5g2000pre.googlegroups.com> References: mailman.8817.1233796709.3487.python-list@python.org <6c1875c3-8283-4764-a481-ebfa135868bc@v5g2000pre.googlegroups.com> Message-ID: <498B076E.5050006@mrabarnett.plus.com> Mark Dickinson wrote: > On Feb 5, 1:18 am, Chris Rebert wrote: >> For an integer: >> is_even = bin(the_int)[2:].count('1') % 2 == 0 > > But the OP has to use if and while. How about: > > while 2+2 != 5: > if 'wkw' in 'just being awkward': > is_even = bin(the_int)[2:].count('1') % 2 == 0 > break > > or (Python 2.5 compatible): > > def count_set_bits(n): > # make sure we include an if, to > # satisfy OP's requirements: > if n < 0: > raise ValueError > count = 0 > while n: > count += 1 > n &= n-1 > return count > > is_even = count_set_bits(the_int) % 2 == 0 > > ...but anyone submitting this as a homework > solution had better be prepared to explain why > it works. > I haven't seen that algorithm before. Very clever! :-) From deets at nospam.web.de Thu Feb 5 10:36:30 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 05 Feb 2009 16:36:30 +0100 Subject: Cheetah and hungarian charset... In-Reply-To: References: Message-ID: <6v0fbuFho2e8U1@mid.uni-berlin.de> durumdara schrieb: > Hi! > > I wanna ask that have anyone some exp. with Cheetah and the non-ascii > chars? > > I have a site. The html template documents are saved in ansi format, psp > liked them. > But the cheetah parser makes ParseError on hungarian characters, like > "?", "?", "?", etc. When I remove them, I got good result, but I don't > want to remove them all... > > I cannot parse them. Please help me, how to force cheetah to eat them all? Please provide tracebacks and code and data examples. Diez From Scott.Daniels at Acm.Org Thu Feb 5 10:54:40 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 05 Feb 2009 07:54:40 -0800 Subject: global name 'sqrt' is not defined In-Reply-To: References: <498AAC89.5080002@berkeley.edu> Message-ID: <5rSdnfi3VIPQlhbUnZ2dnUVZ_r3inZ2d@pdx.net> M.-A. Lemburg wrote: > On 2009-02-05 10:08, Nick Matzke wrote: >> ..., I can run this in the ipython shell just fine: >> a = ["12", "15", "16", "38.2"] >> dim = int(sqrt(size(a))) >> ...But if I move these commands to a function in another file, it freaks out: > You need to add: > > from math import sqrt or: from cmath import sqrt or: from numpy import sqrt Each with their own, slightly different, meaning. Hence the reason many of us prefer to import the module and reference the function as a module attribute. Note that _many_ (especially older) package documents describe their code without the module name. I believe that such behavior is because, when working to produce prose about a package, it feels too much like useless redundancy when describing each function or class as "package.name". --Scott David Daniels Scott.Daniels at Acm.Org From mrkafk at gmail.com Thu Feb 5 11:00:05 2009 From: mrkafk at gmail.com (mk) Date: Thu, 05 Feb 2009 17:00:05 +0100 Subject: Is c.l.py becoming less friendly? Message-ID: (duck) 542 comp.lang.python rtfm 467 comp.lang.python shut+up 263 comp.lang.perl rtfm 45 comp.lang.perl shut+up Code: import urllib2 import re import time def fillurlfmt(args): urlfmt, ggroup, gkw = args return {'group':ggroup, 'keyword':gkw, 'url': urlfmt % (gkw, ggroup)} def consqurls(args): ggroup, gkeywords = args urlfmt = 'http://groups.google.com/groups/search?as_q=%s&as_epq=&as_oq=&as_eq=&num=10&scoring=&lr=&as_sitesearch=&as_drrb=q&as_qdr=&as_mind=1&as_minm=1&as_miny=1999&as_maxd=1&as_maxm=1&as_maxy=2009&as_ugroup=%s&as_usubject=&as_uauthors=&safe=off' qurls = map(fillurlfmt, [ (urlfmt, ggroup, gkw) for gkw in gkeywords ]) return qurls def flatten_list(x): res = [] for el in x: if isinstance(el,list): res.extend(flatten_list(el)) else: res.append(el) return res def ggsearch(urldict): opener = urllib2.build_opener() opener.addheaders = [('User-agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.20) Gecko/20081217 (CK-IBM) Firefox/2.0.0.20')] time.sleep(0.1) urlf = opener.open(urldict['url']) resdict = {'result': urlf.read()} resdict.update(urldict) urlf.close() return resdict def extrclosure(resregexp, groupno): def extrres(resdict): txtgr = resregexp.search(resdict['result']) resdict['result']=txtgr.group(groupno) return resdict return extrres def delcomma(x): x['result'] = x['result'].replace(',','') return x if __name__ == "__main__": gkeywords = ['rtfm', 'shut+up'] ggroups = ['comp.lang.python', 'comp.lang.perl'] params = [(ggroup, gkeywords) for ggroup in ggroups] qurls = map(consqurls, params) qurls = flatten_list(qurls) gresults = map(ggsearch, qurls) resre = re.compile('Results \1\ - \.+?\ of about \(.+?)\') gextrsearchresult = extrclosure(resre,1) gresults = map(gextrsearchresult, gresults) gresults = map(delcomma, gresults) for el in gresults: print el['result'], el['group'], el['keyword'] print This was inspired by http://mail.python.org/pipermail/python-list/2002-November/172466.html Regards, mk From apt.shansen at gmail.com Thu Feb 5 11:01:35 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Thu, 5 Feb 2009 08:01:35 -0800 Subject: Ordered dict by default In-Reply-To: <47a82549-bc80-45ac-8b51-d58e597e768f@r24g2000vbp.googlegroups.com> References: <47a82549-bc80-45ac-8b51-d58e597e768f@r24g2000vbp.googlegroups.com> Message-ID: <7a9c25c20902050801w4f2fdb84qdba397589b256318@mail.gmail.com> > That page about Ruby dicts show a higher traversal speed (probably > just because the CPU has to scan less memory, but I am not sure, > because mordern CPUs are very complex) but lower insertion speed (I > think mostly not because the added management of two pointers, but > because the memory used increases, so there are more cache misses. If > this turns out as true, then using the xor trick may halve the extra > memory needed). I have no idea if such different balance of > performance will lead to on average faster or slower Python programs, > this has to be tested. But even if the average performance becomes a > little worse I think making the default Python dict as ordered is a > positive change for Python too, because built-ins are meant to be as > flexible as possible, even if they aren't the fastest ones or the less > memory hungry ones (and keeping dicts ordered decreases the surprises > a newbie finds, makes some code cleaner, and doctests become simpler > to write because the order of items may be more defined). Er, doing a cursory review of my code has an overwhelmingly higher incidence of insertions then traversals with my dictionaries: many dictionaries are never traversed and when they are it is only once, and often had tens to thousands of insertions before that traversal happens. So a slight decrease in insertion speed at the cost of faster traversal seems like a complete loss to me. Now, I also do recognize the utility of ordered dictionaries in some cases, but exactly what you mean by ordered varies. I have two cases where "ordered" has the keys are in a specific custom order. I have four cases where "ordered" means maintaining insertion order. For the former I do sorted(dict) on access when I need to do something order-related. For the latter I have a simple ordered dictionary implementation that maintains the keys as a separate list attached to the dictionary. But interestingly enough to me, in all the cases where I use an ordered dict in my code, performance is completely irrelevant. Its tens to hundreds of items usually, and the best optimization in the world wouldn't add more then an imperceptible fraction of a second, and the memory lost to the extra list adds up to nothing relevant. I'm not claiming my use cases are everyones, not by any means. But: this seems like a complete lose-lose for an idea from my perspective. Sure you say an unordered dictionary could then be added for my needs, but... I like my syntactic sugar, thank you :) Ordered dictionaries can be useful, its good to see a standard implementation going into the core, but the default? I hope not! --Stephen From upton at virginia.edu Thu Feb 5 11:02:55 2009 From: upton at virginia.edu (Dan Upton) Date: Thu, 5 Feb 2009 11:02:55 -0500 Subject: Is c.l.py becoming less friendly? In-Reply-To: References: Message-ID: <5504f9ac0902050802t5c78ed43we0ef16001b371521@mail.gmail.com> On Thu, Feb 5, 2009 at 11:00 AM, mk wrote: > > (duck) > > 542 comp.lang.python rtfm > > 467 comp.lang.python shut+up > > 263 comp.lang.perl rtfm > > 45 comp.lang.perl shut+up > But over how many messages for each group? Wouldn't the percentage of messages containing those be more interesting than the raw number? ;p From apt.shansen at gmail.com Thu Feb 5 11:05:19 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Thu, 5 Feb 2009 08:05:19 -0800 Subject: Ordered dict by default In-Reply-To: <7a9c25c20902050801w4f2fdb84qdba397589b256318@mail.gmail.com> References: <47a82549-bc80-45ac-8b51-d58e597e768f@r24g2000vbp.googlegroups.com> <7a9c25c20902050801w4f2fdb84qdba397589b256318@mail.gmail.com> Message-ID: <7a9c25c20902050805l7d999cb4p74b6b11ef309ab41@mail.gmail.com> > Now, I also do recognize the utility of ordered dictionaries in some cases, but > exactly what you mean by ordered varies. I have two cases where "ordered" > has the keys are in a specific custom order. I have four cases where "ordered" > means maintaining insertion order. For the former I do sorted(dict) on access > when I need to do something order-related. For the latter I have a simple > ordered dictionary implementation that maintains the keys as a separate list > attached to the dictionary. Ooh, as an addendum... I found one case where I want insertion-and-update order: meaning that its an ordered dictionary that maintains insertion order, but an update to a particular item moves that item to the back so an update behaves like del d[key]; d[key] = value in terms of the key order. "Ordered Dictionaries" are a bit fuzzy. :) --S From mrkafk at gmail.com Thu Feb 5 11:06:28 2009 From: mrkafk at gmail.com (mk) Date: Thu, 05 Feb 2009 17:06:28 +0100 Subject: Flattening lists In-Reply-To: <0ac212c8-e148-44f8-8f30-050064303c96@f40g2000pri.googlegroups.com> References: <0ac212c8-e148-44f8-8f30-050064303c96@f40g2000pri.googlegroups.com> Message-ID: Mark Dickinson wrote: > I often find myself needing a 'concat' method that > turns a list of lists (or iterable of iterables) into > a single list; itertools.chain does this quite nicely. > But I don't think I've ever encountered a need for the > full recursive version. You're most probably right in this; however, my main goal here was finding 'more Pythonic' way of doing this and learning this way rather than the practical purpose of flattening deeply nested lists. Regards, mk From marduk at letterboxes.org Thu Feb 5 11:06:40 2009 From: marduk at letterboxes.org (Albert Hopkins) Date: Thu, 05 Feb 2009 11:06:40 -0500 Subject: Is c.l.py becoming less friendly? In-Reply-To: References: Message-ID: <1233850000.12935.4.camel@localhost.localdomain> Probably that [c.l.]python is becoming more popular and, like most things as they become popular, it loses its "purity"... much like the Internet in the early 1990s. From mrkafk at gmail.com Thu Feb 5 11:07:10 2009 From: mrkafk at gmail.com (mk) Date: Thu, 05 Feb 2009 17:07:10 +0100 Subject: Flattening lists In-Reply-To: References: Message-ID: Michele Simionato wrote: > Looks fine to me. In some situations you may also use hasattr(el, > '__iter__') instead of isinstance(el, list) (it depends if you want to > flatten generic iterables or only lists). Thanks! Such stuff is what I'm looking for. Regards, mk From BrianVanderburg2 at aim.com Thu Feb 5 11:10:51 2009 From: BrianVanderburg2 at aim.com (Brian Allen Vanderburg II) Date: Thu, 05 Feb 2009 11:10:51 -0500 Subject: Flattening lists In-Reply-To: References: <498AE81E.6020100@aim.com> Message-ID: <498B0F8B.8090109@aim.com> mrkafk at gmail.com wrote: > Baolong zhen wrote: >> less list creation. > > At the cost of doing this at each 'flatten' call: > > if res is None: > res = [] > > The number of situations of executing above code is the same as the > number of list creations (once for each 'flatten' call, obviously). > > Is list creation really more costly than above? > Probably not. I wrote a small test program using a list several levels deep, each list containing 5 sublists at each level and finally just a list of numbers. Flattening 1000 times took about 3.9 seconds for the one creating a list at each level, and 3.2 for the one not creating the list at each level. Brian Vanderburg II From bruno.42.desthuilliers at websiteburo.invalid Thu Feb 5 11:11:58 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 05 Feb 2009 17:11:58 +0100 Subject: Couple of noobish question In-Reply-To: References: <498a1b1d$0$24204$426a74cc@news.free.fr> Message-ID: <498b0fb8$0$23714$426a74cc@news.free.fr> Tim Rowe a ?crit : > 2009/2/4 Bruno Desthuilliers : > >> # somemodule.py >> >> import os >> >> if os.uname()[0] == "Linux": > > On an MS Windows system, os.uname()[0] raises an AttributeError Thanks for the correction - as you may have guessed, I have not used windows for years !-) From digitig at gmail.com Thu Feb 5 11:14:32 2009 From: digitig at gmail.com (Tim Rowe) Date: Thu, 5 Feb 2009 16:14:32 +0000 Subject: Is c.l.py becoming less friendly? In-Reply-To: References: Message-ID: 2009/2/5 mk : > > (duck) > > 542 comp.lang.python rtfm > > 467 comp.lang.python shut+up > > 263 comp.lang.perl rtfm > > 45 comp.lang.perl shut+up Yes, but is there any real traffic on comp.lang.perl nowadays? Sorry, cheap shot ;-) -- Tim Rowe From google at mrabarnett.plus.com Thu Feb 5 11:20:46 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 05 Feb 2009 16:20:46 +0000 Subject: Ordered dict by default In-Reply-To: <7x7i45qiyo.fsf@ruckus.brouhaha.com> References: <47a82549-bc80-45ac-8b51-d58e597e768f@r24g2000vbp.googlegroups.com> <7x7i45qiyo.fsf@ruckus.brouhaha.com> Message-ID: <498B11DE.8000804@mrabarnett.plus.com> Paul Rubin wrote: > bearophileHUGS at lycos.com writes: >> Now Ruby dicts are ordered by default: >> http://www.igvita.com/2009/02/04/ruby-19-internals-ordered-hash/ > > Maybe I didn't read that carefully enough, but it looks like "ordered" > means the dict records come out in the same order you inserted them > in. That is if you insert B,A,D,C in that order, you get them out in > that order. I would have thought an ordered dict meant you get A,B,C,D, > which seems a lot more useful. > [snip] You're confusing "ordered" with "sorted"! :-) A list is an ordered collection, for example. From skip at pobox.com Thu Feb 5 11:20:59 2009 From: skip at pobox.com (skip at pobox.com) Date: Thu, 5 Feb 2009 10:20:59 -0600 (CST) Subject: Is the subprocess module robust enough in 2.4? Message-ID: <20090205162059.CC9A8DB5569@montanaro.dyndns.org> The subprocess module was added in Python 2.4. I'm running 2.4.5 at work. I know it's seen many bugfixes since first released. Is the version in 2.4 robust enough to use in preference to os.popen and friends? Thx, -- Skip Montanaro - skip at pobox.com - http://www.smontanaro.net/ From deets at nospam.web.de Thu Feb 5 11:22:31 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 05 Feb 2009 17:22:31 +0100 Subject: Is c.l.py becoming less friendly? In-Reply-To: References: Message-ID: <6v0i28Fhcr76U1@mid.uni-berlin.de> mk schrieb: > > (duck) > > 542 comp.lang.python rtfm > > 467 comp.lang.python shut+up > > 263 comp.lang.perl rtfm > > 45 comp.lang.perl shut+up It appears to me that comp.lang.perl isn't even active anymore. Or googles interface is just crappy. c.l.perl.misc seems to be the place to search. And raw numbers are nothing without actual postings. FWIW, I can't remember reading the last time RTFM here, but then I usually skip the giant-size horse-beatings about GIL removal and encapsulation... Diez From mrkafk at gmail.com Thu Feb 5 11:29:41 2009 From: mrkafk at gmail.com (mk) Date: Thu, 05 Feb 2009 17:29:41 +0100 Subject: Flattening lists In-Reply-To: <498B0F8B.8090109@aim.com> References: <498AE81E.6020100@aim.com> <498B0F8B.8090109@aim.com> Message-ID: Brian Allen Vanderburg II wrote: >> Is list creation really more costly than above? >> > Probably not. I wrote a small test program using a list several levels > deep, each list containing 5 sublists at each level and finally just a > list of numbers. Flattening 1000 times took about 3.9 seconds for the > one creating a list at each level, and 3.2 for the one not creating the > list at each level. Hmm, I'm surprised by even that! Apparently list creation is more expensive than I thought - it seems somewhat more expensive than the cost of interpreting bytecode for "if var is None". Either list creation is somewhat costly, or "if var is None" is really cheap. Regards, mk From apt.shansen at gmail.com Thu Feb 5 11:41:36 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Thu, 5 Feb 2009 08:41:36 -0800 Subject: Flattening lists In-Reply-To: References: <498AE81E.6020100@aim.com> <498B0F8B.8090109@aim.com> Message-ID: <7a9c25c20902050841y57169afeid2d3b708faeafad6@mail.gmail.com> > Either list creation is somewhat > costly, or "if var is None" is really cheap. "if x is y" is extremely cheap, I believe. Unlike most comparisons which are (relatively) expensive, that one is just comparing simple object address. You can't override "is" so there's a whole series of checks that don't have to get done. You don't have to go through the richcompare machinery, check if there's a __ne__, etc, etc. --S From james at agentultra.com Thu Feb 5 11:45:55 2009 From: james at agentultra.com (J Kenneth King) Date: Thu, 05 Feb 2009 16:45:55 +0000 Subject: Flattening lists References: Message-ID: <873aesbzng.fsf@agentultra.com> mk writes: > Hello everybody, > > Any better solution than this? > > def flatten(x): > res = [] > for el in x: > if isinstance(el,list): > res.extend(flatten(el)) > else: > res.append(el) > return res > > a = [1, 2, 3, [4, 5, 6], [[7, 8], [9, 10]]] > print flatten(a) > > > [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] > > Regards, > mk http://mail.python.org/pipermail/python-list/2005-July/330367.html From siona at chiark.greenend.org.uk Thu Feb 5 11:49:22 2009 From: siona at chiark.greenend.org.uk (Sion Arrowsmith) Date: 05 Feb 2009 16:49:22 +0000 (GMT) Subject: Flattening lists References: <498AE81E.6020100@aim.com> Message-ID: mk wrote: >Brian Allen Vanderburg II wrote: >> I think it may be just a 'little' more efficient to do this: >> >> def flatten(x, res=None): >> if res is None: >> res = [] >> for el in x: >> if isinstance(el, (tuple, list)): >> flatten(el, res) >> else: >> res.append(el) >> return res > > >Hmm why should it be more efficient [than def flatten(x): res = [] for el in x: if isinstance(el,list): res.extend(flatten(el)) else: res.append(el) return res ]? extend operation should not be very costly? It's not a question of extend/append, it's the fact that your original function creates (and destroys) a new list for every recursive call. Which, if you've got large nested lists, will have an impact. -- \S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/ "Frankly I have no feelings towards penguins one way or the other" -- Arthur C. Clarke her nu become? se bera eadward ofdun hl?ddre heafdes b?ce bump bump bump From rdmurray at bitdance.com Thu Feb 5 11:49:25 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Thu, 5 Feb 2009 16:49:25 +0000 (UTC) Subject: Flattening lists References: <498AE81E.6020100@aim.com> Message-ID: Baolong zhen wrote: > On Thu, Feb 5, 2009 at 10:17 PM, mk wrote: > > > Brian Allen Vanderburg II wrote: > > >> def flatten(x): > > >> res = [] > > >> for el in x: > > >> if isinstance(el,list): > > >> res.extend(flatten(el)) > > >> else: > > >> res.append(el) > > >> return res > > > > > > > > I think it may be just a 'little' more efficient to do this: > > > > > > def flatten(x, res=None): > > > if res is None: > > > res = [] > > > > > > for el in x: > > > if isinstance(el, (tuple, list)): > > > flatten(el, res) > > > else: > > > res.append(el) > > > > > > return res > > > > > > Hmm why should it be more efficient? extend operation should not be very > > costly? > > less list creation. (Took me a while to find the content of your post because you top posted it. I've taken the liberty of correcting that.) This is all premature optimization, except for the goopy code, which is presumably used enough to make it worth optimizing. And guess what? The goopy code wins. What the people theorizing about the speed of extend vs list creation miss is that the things with high overhead in the above functions are (1) isinstance and (2) the recursive function call. The goopy code avoids this by using type and is, and by unrolling the lowest level without a function call. On the other hand, extend _is_ faster than append if you aren't creating a new list, so the goopy code can be optimized a little more. I remembered the bit about high function call overhead, but the rest of it measured: temp.py --------------------------------------------------------------------------------- from __future__ import print_function from timeit import Timer def flatten1(x): res = [] for el in x: if isinstance(el, list): res.extend(flatten1(el)) else: res.append(el) return res def flatten1a(x): res = [] for el in x: if isinstance(el, (tuple, list)): res.extend(flatten1a(el)) else: res.append(el) return res def flatten1b(x): res = [] for el in x: if type(el) is list or type(el) is tuple: res.extend(flatten1b(el)) else: res.append(el) return res def flatten2(x, res=None): if res is None: res = [] for el in x: if isinstance(el, list): flatten2(el, res) else: res.append(el) return res def flatten2a(x, res=None): if res is None: res = [] for el in x: if isinstance(el, (tuple, list)): flatten2a(el, res) else: res.append(el) return res def flatten2b(x, res=None): if res is None: res = [] for el in x: if type(el) is list or type(el) is tuple: flatten2b(el, res) else: res.append(el) return res def flatten3z(seq): lst = [] for x in seq: if type(x) is list or type(x) is tuple: for val in x: lst.append(val) else: lst.append(x) return lst def flatten3(seq): lst = [] for el in seq: if type(el) == list or type(el) is tuple: lst.extend(flatten3z(el)) else: lst.append(el) return lst def flatten3y(seq): lst = [] for x in seq: if type(x) is list or type(x) is tuple: lst.extend(x) else: lst.append(x) return lst def flatten3a(seq): lst = [] for el in seq: if type(el) == list or type(el) is tuple: lst.extend(flatten3y(el)) else: lst.append(el) return lst l = [[1, 2, 3], 5, [7, 8], 3, [9, [10, 11, 12], 4, [9, [10, 5, 7]], 1, [[[[[5, 4], 3], 4, 3], 3, 1, 45], 9], 10]] cases = dict( base = Timer(), c1 = Timer("flatten1(l)", "from temp import flatten1, l"), c1a = Timer("flatten1a(l)", "from temp import flatten1a, l"), c1b = Timer("flatten1b(l)", "from temp import flatten1b, l"), c2 = Timer("flatten2(l)", "from temp import flatten2, l"), c2a = Timer("flatten2a(l)", "from temp import flatten2a, l"), c2b = Timer("flatten2b(l)", "from temp import flatten2b, l"), c3 = Timer("flatten3(l)", "from temp import flatten3, l"), c3a = Timer("flatten3a(l)", "from temp import flatten3a, l"), ) if __name__=="__main__": for (name, case) in sorted(cases.items()): print("{0:4s} {1}".format(name, case.timeit())) ----------------------------------------------------------------------------- It is also interesting to note that python3.0 is faster in this particular case (unless there are timing vagrancies on my machine, which is possible, though the results were fairly consistent over several runs of the script). The second run below is using python2.6.1. >src/python/Python-3.0/python temp.py base 0.0278329849243 c1 30.4776289463 c1a 44.3886289597 c1b 32.5621030331 c2 25.6131818295 c2a 39.0944678783 c2b 27.1573381424 c3 15.346280098 c3a 14.3178970814 >python temp.py base 0.0288269519806 c1 35.8193409443 c1a 52.3054969311 c1b 36.3652667999 c2 32.3255820274 c2a 47.71251297 c2b 32.6813359261 c3 16.6060569286 c3a 15.1056449413 --RDM From linuxguy123 at gmail.com Thu Feb 5 12:13:15 2009 From: linuxguy123 at gmail.com (Linuxguy123) Date: Thu, 05 Feb 2009 10:13:15 -0700 Subject: HOWTO for setting up a PyQt project in Eclipse ? Message-ID: <1233853995.25301.12.camel@localhost.localdomain> Does anyone know of a HOWTO for setting up a PyQt project in Eclipse ? I know about setting up a PyDev project, just wondering how to integrate the QtDesigner parts. For example, should I save the QtDesigner project in the root PyDev directory ? Thanks From gagsl-py2 at yahoo.com.ar Thu Feb 5 12:16:03 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 05 Feb 2009 15:16:03 -0200 Subject: Scanning a file character by character References: Message-ID: En Thu, 05 Feb 2009 04:48:13 -0200, Spacebar265 escribi?: > Hi. Does anyone know how to scan a file character by character and > have each character so I can put it into a variable. I am attempting > to make a chatbot and need this to read the saved input to look for > spelling mistakes and further analysis of user input. Read the file one line at a time, and process each line one character at a time: with open(filename, "r") as f: for line in f: for c in line: process(c) But probably you want to process one *word* at a time; the easiest way (perhaps inaccurate) is to just split on whitespace: ... for word in line.split(): process(word) -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Thu Feb 5 12:16:12 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 05 Feb 2009 15:16:12 -0200 Subject: sorting mesh data an from abaqus simulation References: Message-ID: En Mon, 02 Feb 2009 10:10:15 -0200, Alessandro Zivelonghi escribi?: > *Ntop = odb.rootAssembly.instances['PART-1-1'].nodeSets['TOP'].nodes > * > Problem: > 1) the list of nodes Ntop contains all the node labels [2673, 2675, > 2676, 2677, 2678, 3655, 3656, 119939, 124154, 127919] already > ordered in ascending order. > What I need is the same list *ordered by coordinate_x* of each node, i.e. > from left to right in the model (unfortunately, for example node 124154 > cames before node 3656 in the model, if you read the model from left to > right) Use the key= argument to the sorted() builtin function def get_node_x(node): return node.coordinates[0] sorted_nodes = sorted(Ntop, key=get_node_x) (For a list of reasonable size, that's fine. For a giant list, this could be written more efficiently, although less readable) > 1b) I don't understand which kind of data are EL, N, Ntop (list?) and how > can I sort Ntop with the criterium based on coordinate_x (coordinate[0]) AFAIK those are plain lists. You can try: py> print type(Ntop) and see what happens. If you don't get , try with: py> type(Ntop).mro() to see the chain of base classes. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Thu Feb 5 12:16:21 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 05 Feb 2009 15:16:21 -0200 Subject: subprocess.Popen not creating a pipe References: <6c3f5e6c0902011046i59655f3cp2a81b3deb9258c61@mail.gmail.com> <6c3f5e6c0902011200s47372b8g49c794b7fa62a06b@mail.gmail.com> Message-ID: En Sun, 01 Feb 2009 18:00:36 -0200, Andrew Parker escribi?: > On Sun, Feb 1, 2009 at 1:46 PM, Andrew Parker wrote: >> I'm having some fun with Popen. I have the following line: >> >> process = subprocess.Popen(command, stdout=subprocess.PIPE, >> stderr=subprocess.STDOUT) >> print process.stdout >> >> Under normal circumstances, this displays: >> >> ', mode 'w' at 0xb7f8e068> >> >> However, I have a binary that I use to kick off this script, and when >> that runs, it displays: >> >> None >> >> So, two questions: >> >> 1. What the heck is this binary doing that upsets Popen so much? >> 2. What can *my script* do to get around this problem. >> >> Unfortunately I'm stuck using this binary, so its the python where I >> have to solve this. > > so, tracing through subprocess.Popen, I see that os.pipe() is being > invoked for stdout. This is returning (0, 3), and I assume the 0 is > conflicting with what python is assuming is stdin. Calling pipe() > before Popen gets around my problem, as the pipe the Popen gets then > returns (4,5) which Popen seems happy with. Seems that "your binary" is closing stdin before running your script, so the first available file descriptor is 0. > Sounds like a bug. Should I report this, or is it expected/known > behaviour? It's hardly a Python error, and I don't think the subprocess module should consider this very special case, but you may report it at http://bugs.python.org/ anyway. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Thu Feb 5 12:16:35 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 05 Feb 2009 15:16:35 -0200 Subject: Structuring Modules with a Ubiquitous Base Class (Circular Dependencies) References: Message-ID: En Wed, 04 Feb 2009 21:12:58 -0200, andrew cooke escribi?: > On Feb 4, 7:49?pm, andrew cooke wrote: >> This leads to a circular dependency - the base class wants to import >> the components, which in turn want to import the base class. > > well, to partially answer my own question, this is certainly > possible. in the general case it might get quite complex, but for the > structure described it is quite simple. the 'trick' is to import the > component in the *method* of the common base class. > > for example: > > class Base(object): > > def __init__(self): > from first import First > from second import Second > self.first = lambda *args: First(*args) > self.second = lambda *args: Second(*args) > > where First, defined in first, subclasses Base in the normal way. > > however, i suspect this will have a performance hit, since "linking" > is being done at "run time" rather than "compile time". anyone have > any guidance on how serious that would be? i guess it could be > ameliorated by doing the work in the constructor (as above, which is > just that way for a compact example - in "real life" the components > are used in a more complex manner). There is no "linking" step in Python, all is done at run time. Once a module is imported the first time, any subsequent import is very cheap. > and i still suspect there is a more efficient metaclass or similar > approach. This approach is fine to me. -- Gabriel Genellina From python.list at tim.thechases.com Thu Feb 5 12:26:32 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 05 Feb 2009 11:26:32 -0600 Subject: Is c.l.py becoming less friendly? In-Reply-To: References: Message-ID: <498B2148.80401@tim.thechases.com> > (duck) > > 542 comp.lang.python rtfm > 467 comp.lang.python shut+up > 263 comp.lang.perl rtfm > 45 comp.lang.perl shut+up Is this where we tell you to shut up? ;-) As others mentioned, the raw numbers don't mean much without a total-volume-of-posts to demonstrate the percentage. It would also be interesting to see how many of those posts are concentrated in certain threads -- for the most part, c.l.python has been a pretty civil place, but a few threads have degraded into puerile spats. -tkc From rdmurray at bitdance.com Thu Feb 5 12:29:46 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Thu, 5 Feb 2009 17:29:46 +0000 (UTC) Subject: Flattening lists References: <498AE81E.6020100@aim.com> Message-ID: Quoth rdmurray at bitdance.com: > This is all premature optimization, except for the goopy code, which is > presumably used enough to make it worth optimizing. And guess what? > The goopy code wins. What the people theorizing about the speed of > extend vs list creation miss is that the things with high overhead in the > above functions are (1) isinstance and (2) the recursive function call. > The goopy code avoids this by using type and is, and by unrolling the > lowest level without a function call. On the other hand, extend > _is_ faster than append if you aren't creating a new list, so the > goopy code can be optimized a little more. > > I remembered the bit about high function call overhead, but the rest > of it measured: Oooh, that's embarrassing. Not only didn't I read the code carefully enough, I didn't test the actual output of the functions. The goopy code doesn't flatten to arbitrary depth, so of course it is faster. --RDM From fakeaddress at nowhere.org Thu Feb 5 12:31:56 2009 From: fakeaddress at nowhere.org (Bryan Olson) Date: Thu, 05 Feb 2009 09:31:56 -0800 Subject: Ordered dict by default In-Reply-To: References: <47a82549-bc80-45ac-8b51-d58e597e768f@r24g2000vbp.googlegroups.com> <7x7i45qiyo.fsf@ruckus.brouhaha.com> Message-ID: MRAB wrote: > Paul Rubin wrote: >> bearophileHUGS at lycos.com writes: >>> Now Ruby dicts are ordered by default: >>> http://www.igvita.com/2009/02/04/ruby-19-internals-ordered-hash/ >> >> Maybe I didn't read that carefully enough, but it looks like "ordered" >> means the dict records come out in the same order you inserted them >> in. That is if you insert B,A,D,C in that order, you get them out in >> that order. I would have thought an ordered dict meant you get A,B,C,D, >> which seems a lot more useful. >> > [snip] > You're confusing "ordered" with "sorted"! :-) He's really not. http://en.wikipedia.org/wiki/Ordered_set > A list is an ordered collection, for example. True. -- --Bryan From fakeaddress at nowhere.org Thu Feb 5 12:36:06 2009 From: fakeaddress at nowhere.org (Bryan Olson) Date: Thu, 05 Feb 2009 09:36:06 -0800 Subject: Ordered dict by default In-Reply-To: References: <47a82549-bc80-45ac-8b51-d58e597e768f@r24g2000vbp.googlegroups.com> <7a9c25c20902050801w4f2fdb84qdba397589b256318@mail.gmail.com> Message-ID: Stephen Hansen wrote: > Ooh, as an addendum... I found one case where I want insertion-and-update > order: meaning that its an ordered dictionary that maintains insertion > order, but > an update to a particular item moves that item to the back so an update behaves > like del d[key]; d[key] = value in terms of the key order. > > "Ordered Dictionaries" are a bit fuzzy. :) A few bits fuzzy. Is the following True or False if dict is insert-ordered? dict(a=6, b=7) == dict(b=7, a=6) -- --Bryan From digitig at gmail.com Thu Feb 5 12:37:28 2009 From: digitig at gmail.com (Tim Rowe) Date: Thu, 5 Feb 2009 17:37:28 +0000 Subject: Is c.l.py becoming less friendly? In-Reply-To: <498B2148.80401@tim.thechases.com> References: <498B2148.80401@tim.thechases.com> Message-ID: 2009/2/5 Tim Chase : > Is this where we tell you to shut up? ;-) [snip] > It would also be interesting to see how many of those posts are concentrated > in certain threads And, as you have clearly demonstrated, how many of those posts also contain a smiley or some other form of hedging in a position that could modify the "unfriendly" text? -- Tim Rowe From upton at virginia.edu Thu Feb 5 12:40:24 2009 From: upton at virginia.edu (Dan Upton) Date: Thu, 5 Feb 2009 12:40:24 -0500 Subject: Is c.l.py becoming less friendly? In-Reply-To: References: <498B2148.80401@tim.thechases.com> Message-ID: <5504f9ac0902050940q7eb0d2bp8d17e9650c4b1659@mail.gmail.com> On Thu, Feb 5, 2009 at 12:37 PM, Tim Rowe wrote: > 2009/2/5 Tim Chase : > >> Is this where we tell you to shut up? ;-) > > [snip] > >> It would also be interesting to see how many of those posts are concentrated >> in certain threads > > And, as you have clearly demonstrated, how many of those posts also > contain a smiley or some other form of hedging in a position that > could modify the "unfriendly" text? I'd be amused to see "shut up and rtfm ;)" From digitig at gmail.com Thu Feb 5 12:42:02 2009 From: digitig at gmail.com (Tim Rowe) Date: Thu, 5 Feb 2009 17:42:02 +0000 Subject: Couple of noobish question In-Reply-To: <498b0fb8$0$23714$426a74cc@news.free.fr> References: <498a1b1d$0$24204$426a74cc@news.free.fr> <498b0fb8$0$23714$426a74cc@news.free.fr> Message-ID: 2009/2/5 Bruno Desthuilliers : > Thanks for the correction - as you may have guessed, I have not used windows > for years !-) And I can't get Linux running (more precisely, I can't /keep/ X-Windows running). Isn't it a good job that Python is cross-platform -- as long as we stay clear of the os module :-) -- Tim Rowe From engr.amkhan at gmail.com Thu Feb 5 12:46:03 2009 From: engr.amkhan at gmail.com (Ahmed Majeed) Date: Thu, 5 Feb 2009 09:46:03 -0800 (PST) Subject: Python Installation Error Message-ID: <64020629-a27e-45f8-bfd9-1cf61384a548@t26g2000prh.googlegroups.com> Hi, I am working over a research project and need Python 2.3 or later to be installed on my Intel Centrino machine, running Fedora 9 as OS. I have downloaded latest stable release Python 2.6.1 from Python.org, but when I tried installing it, terminal returned an error on 'make', saying: "Failed to find the necessory Bits to build these modules: _tkinter bsddb185, sunaaudiodev To find the necessory bits, look in setup.py in detect_modules() for the module's name." How should I correct this and go ahead for installation. Anxiously waiting reply and thanking you in anticiaption. -Ahmed From bruno.42.desthuilliers at websiteburo.invalid Thu Feb 5 12:58:50 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 05 Feb 2009 18:58:50 +0100 Subject: Is c.l.py becoming less friendly? In-Reply-To: References: <498B2148.80401@tim.thechases.com> Message-ID: <498b28c3$0$23719$426a74cc@news.free.fr> Tim Rowe a ?crit : > 2009/2/5 Tim Chase : > >> Is this where we tell you to shut up? ;-) > > [snip] > >> It would also be interesting to see how many of those posts are concentrated >> in certain threads > > And, as you have clearly demonstrated, how many of those posts also > contain a smiley or some other form of hedging in a position that > could modify the "unfriendly" text? > Not to mention when the "rtfm" comes with a pointer to the relevant url and a couple explanations. From bearophileHUGS at lycos.com Thu Feb 5 13:04:35 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Thu, 5 Feb 2009 10:04:35 -0800 (PST) Subject: where clause Message-ID: This comes after a small discussion in another Python newsgroup. Haskell supports a where clause, that's syntactic sugar that allows you to define things like this: p = a / b where a = 20 / len(c) b = foo(d) That means: a = 20 / len(c) b = foo(d) p = a / b I don't know how much good this syntax can be in my Python programs, probably I have to use it some time to judge. In the Python shell you usally have to use a bottom-up style of programming, while a where may allow you a more top-down too. I can enjoy this. Compared to Haskell a possible problem may from mutability, in Haskell often the order of the operations isn't important (it's only/mostly significant during I/O), while in Python is generally important. The interpreter has to look ahead, to use such 'where', because the point of 'where' is to allow the programmer with such inversions. In Python you probably want to put a : after where. But that Haskell syntax also enjoys having where too indented, this is less easy (or impossible?) to mix with the usual Python syntax. Bye, bearophile From philip at semanchuk.com Thu Feb 5 13:08:42 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Thu, 5 Feb 2009 13:08:42 -0500 Subject: How to call python from a foreign language thread (C++) In-Reply-To: References: Message-ID: <51318B30-3A5F-43D8-B2CC-5084F366B02E@semanchuk.com> On Feb 3, 2009, at 11:37 PM, Victor Lin wrote: > It does not work. But however, thanks your help. I have tired so many > methods to do. But it > crash...crash..deadlock...deadlock..crash...crash... I have no any > tried success. I am going crazy. Could someone help me, thanks. Hi Victor, I have some code that works, although I'm not terribly confident of it. The Python documentation in this area is as clear as mud. I'd be interested to see if my code works for you as well. This is part of my function that the Python code calls to set up the callback: if (!PyEval_ThreadsInitialized()) { DPRINTF("calling PyEval_InitThreads()\n"); PyEval_InitThreads(); // PyEval_InitThreads() acquires the GIL on my behalf but // I don't want it at the moment. PyEval_ReleaseLock(); } This sets up the GIL if necessary (i.e. if this is a single-threaded program) and is a no-op otherwise (i.e. if the app has already created a Python thread). Then I have this function to perform the callback. It is invoked in a new C thread. Comments are inline. void process_notification(union sigval notification_data) { /* Invoked by the system in a new thread as notification of a message arriving in the queue. */ PyObject *arglist; PyObject *result; PyGILState_STATE gstate; PyThreadState *main_thread; PyThreadState *callback_thread; MessageQueue *self = notification_data.sival_ptr; DPRINTF("C thread %ld invoked\n", pthread_self()); // PyGILState_Ensure() implicitly acquires the GIL so I don't need // to call PyEval_AcquireLock(). DPRINTF("Calling PyGILState_Ensure()\n"); gstate = PyGILState_Ensure(); // Get the current thread state so that I have an interpreter to // which to point. DPRINTF("Calling PyThreadState_Get()\n"); main_thread = PyThreadState_Get(); // Create a new Python thread for the callback. DPRINTF("Calling PyThreadState_New()\n"); callback_thread = PyThreadState_New(main_thread->interp); // Make the callback thread current. DPRINTF("Calling PyThreadState_Swap()\n"); PyThreadState_Swap(callback_thread); // Perform the callback. arglist = Py_BuildValue("(O)", self->notification_function_param); result = PyEval_CallObject(self->notification_function, arglist); Py_DECREF(arglist); DPRINTF("Done calling\n"); // Clean up my internal pointers Py_XDECREF(self->notification_function); Py_XDECREF(self->notification_function_param); self->notification_function = NULL; self->notification_function_param = NULL; // Now unwind the Python thread/GIL stuff above DPRINTF("Calling PyThreadState_Swap()\n"); PyThreadState_Swap(main_thread); DPRINTF("Calling PyThreadState_Clear()\n"); PyThreadState_Clear(callback_thread); DPRINTF("Calling PyThreadState_Delete()\n"); PyThreadState_Delete(callback_thread); // PyGILState_Ensure() acquires the lock, but does PyGILState_Release() // release it? The documentation doesn't say, but it seems like it does. DPRINTF("Calling PyGILState_Release()\n"); PyGILState_Release(gstate); DPRINTF("exiting thread\n"); }; This code works (in my limited testing) regardless of whether or not the Python code has created a thread. For the threaded test, I created a background thread that prints "ding!" every second. That thread continued to run even after my callback thread was invoked which I assume means that I released the GIL properly. As I mentioned before, this is part of my posix_ipc extension. This code (assuming I feel confident enough to release it) will be in the next version that should be out soon, so you will have a full working example with which to experiment. HTH, Philip From bearophileHUGS at lycos.com Thu Feb 5 13:10:42 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Thu, 5 Feb 2009 10:10:42 -0800 (PST) Subject: Ordered dict by default References: <47a82549-bc80-45ac-8b51-d58e597e768f@r24g2000vbp.googlegroups.com> <7a9c25c20902050801w4f2fdb84qdba397589b256318@mail.gmail.com> Message-ID: <80a93535-7662-4911-9abe-49a41d0fafe6@w1g2000prk.googlegroups.com> Bryan Olson: > A few bits fuzzy. Is the following True or False if dict is insert-ordered? > ? ? dict(a=6, b=7) == dict(b=7, a=6) In my odict implementation I have disallowed that syntax because if you want to define a mydict(**kwds) function that allows a syntax like: mydict(a=6, b=7) it takes a dict as argument, such dict is currently not ordered. If built-in dicts become ordered, then that dict too may become ordered :-) Anyway, maybe it's good to ignore the inserting order of items when you look for odict equality. Bye, bearophile From aahz at pythoncraft.com Thu Feb 5 13:24:13 2009 From: aahz at pythoncraft.com (Aahz) Date: 5 Feb 2009 10:24:13 -0800 Subject: Flattening lists References: Message-ID: In article , Michele Simionato wrote: > >Looks fine to me. In some situations you may also use hasattr(el, >'__iter__') instead of isinstance(el, list) (it depends if you want to >flatten generic iterables or only lists). Of course, once you do that, you need to special-case strings... -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From kellrott at gmail.com Thu Feb 5 13:38:12 2009 From: kellrott at gmail.com (Kyle) Date: Thu, 5 Feb 2009 10:38:12 -0800 (PST) Subject: Python Integrated Parallel Pipeline EnviRonment: PIPPER Message-ID: <74164566-8bc4-40d7-b9f0-881ed9a015e5@p2g2000prn.googlegroups.com> I wanted to share a Python based project which I've been working on. Python Integrated Parallel Pipeline EnviRonment (PIPPER) is an MPI based programming environment that works much like an OpenMP on Python code. It is designed to create a python programming environment where parallel computations on a set of distributed memory processors (you may call it a cluster, or a Beowulf cluster) is easy to accomplish. The idea is to make writing parallel code easy in order to promote rapid development of script based distributed calculations. There are tools, such as MPI or PVM that help with communicating between processes running on different machines, but most people are quickly scared off by the additional complexity in programming. PIPPER eliminates this barrier to entry by automating the process of data passing and job scheduling. Most importantly is that there is no code 'lock-in'. PIPPER works as a pre-parser and is designed to be completely backward compatible with a single CPU python environment. If you write a script for PIPPER, it will still work on systems that don't have PIPPER installed. You can find the source code and documentation at http://pipper.sourceforge.net A 'Hello Work' example of PIPPER code: #!/usr/bin/python import sys import os def do_call(x,y): print "Hello World", x, y, os.getpid() if __name__ == '__pipper_main__': a_range = range( int(sys.argv[1]) ) #pragma pipper_start for a in a_range : for b in a_range : do_call(a,b) #pragma pipper_end From steve at holdenweb.com Thu Feb 5 13:48:57 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 05 Feb 2009 13:48:57 -0500 Subject: Ordered dict by default In-Reply-To: <80a93535-7662-4911-9abe-49a41d0fafe6@w1g2000prk.googlegroups.com> References: <47a82549-bc80-45ac-8b51-d58e597e768f@r24g2000vbp.googlegroups.com> <7a9c25c20902050801w4f2fdb84qdba397589b256318@mail.gmail.com> <80a93535-7662-4911-9abe-49a41d0fafe6@w1g2000prk.googlegroups.com> Message-ID: bearophileHUGS at lycos.com wrote: > Bryan Olson: >> A few bits fuzzy. Is the following True or False if dict is insert-ordered? >> dict(a=6, b=7) == dict(b=7, a=6) > > In my odict implementation I have disallowed that syntax because if > you want to define a mydict(**kwds) function that allows a syntax > like: > > mydict(a=6, b=7) > > it takes a dict as argument, such dict is currently not ordered. If > built-in dicts become ordered, then that dict too may become > ordered :-) > > Anyway, maybe it's good to ignore the inserting order of items when > you look for odict equality. > But then they wouldn't be equal. As I said right at the start if this thread: > one of the prime issues every time > this comes up is the inability of the various proponents to agree on how > dicts should actually be ordered. The remainder of the thread vindicates that comment. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From deets at nospam.web.de Thu Feb 5 14:02:51 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 05 Feb 2009 20:02:51 +0100 Subject: Python Installation Error In-Reply-To: <64020629-a27e-45f8-bfd9-1cf61384a548@t26g2000prh.googlegroups.com> References: <64020629-a27e-45f8-bfd9-1cf61384a548@t26g2000prh.googlegroups.com> Message-ID: <6v0retFhn667U1@mid.uni-berlin.de> Ahmed Majeed schrieb: > Hi, > I am working over a research project and need Python 2.3 or later to > be installed on my Intel Centrino machine, running Fedora 9 as OS. I > have downloaded latest stable release Python 2.6.1 from Python.org, > but when I tried installing it, terminal returned an error on 'make', > saying: > > "Failed to find the necessory Bits to build these modules: > _tkinter bsddb185, sunaaudiodev > To find the necessory bits, look in setup.py in detect_modules() for > the module's name." > > How should I correct this and go ahead for installation. Anxiously > waiting reply and thanking you in anticiaption. You are missing tcl/tk and bsddb development packages. Or if you don't care about these functionalities, you should be able to disable them using configure. Diez From toby at tobiah.org Thu Feb 5 14:06:39 2009 From: toby at tobiah.org (Tobiah) Date: Thu, 05 Feb 2009 11:06:39 -0800 Subject: Flattening lists References: Message-ID: > Hello everybody, > > Any better solution than this? a = [1, 2, 3, [4, 5, 6], [[7, 8], [9, 10]]] print str(a).replace('[', '').replace(']', '').split(', ') ;) From rdmurray at bitdance.com Thu Feb 5 14:07:15 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Thu, 5 Feb 2009 19:07:15 +0000 (UTC) Subject: Flattening lists References: <873aesbzng.fsf@agentultra.com> Message-ID: Quoth J Kenneth King : > mk writes: > > > Hello everybody, > > > > Any better solution than this? > > > > def flatten(x): > > res = [] > > for el in x: > > if isinstance(el,list): > > res.extend(flatten(el)) > > else: > > res.append(el) > > return res > > > > a = [1, 2, 3, [4, 5, 6], [[7, 8], [9, 10]]] > > print flatten(a) > > > > > > [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] > > > > Regards, > > mk > > http://mail.python.org/pipermail/python-list/2005-July/330367.html That's worth reading. I'm not sure why I'm finding this fun, but who cares. I tried a couple of other functions after reading that article, and it looks like a generator that scans the nested lists is actually the winner, and also is in many ways the most elegant implementation. Of course, as noted in the emails following above article, the test data is really inadequate for proper optimization testing ;) ----------------------------------------------------------------- from __future__ import print_function from timeit import Timer from itertools import chain # This is the one from the article quoted above. def flatten6(seq): i = 0 while (i != len(seq)): while hasattr(seq[i], '__iter__'): seq[i:i+1] = seq[i] i = i + 1 return seq #This is my favorite from a readability standpoint out of #all the things I tried. It also performs the best. def flatten8(seq): for x in seq: if not hasattr(x, '__iter__'): yield x else: for y in flatten8(x): yield y l = [[1, 2, 3], 5, [7, 8], 3, [9, [10, 11, 12], 4, [9, [10, 5, 7]], 1, [[[[[5, 4], 3], 4, 3], 3, 1, 45], 9], 10]] if __name__=="__main__": print(l) print('flatten6', flatten6(l)) print('flatten8', list(flatten8(l))) print('flatten6', Timer("flatten6(l)", "from temp3 import flatten6, l").timeit()) print('flatten8', Timer("list(flatten8(l))", "from temp3 import flatten8, l").timeit()) ----------------------------------------------------------------- >src/python/Python-3.0/python temp3.py [[1, 2, 3], 5, [7, 8], 3, [9, [10, 11, 12], 4, [9, [10, 5, 7]], 1, [[[[[5, 4], 3], 4, 3], 3, 1, 45], 9], 10]] flatten6 [1, 2, 3, 5, 7, 8, 3, 9, 10, 11, 12, 4, 9, 10, 5, 7, 1, 5, 4, 3, 4, 3, 3, 1, 45, 9, 10] flatten8 [1, 2, 3, 5, 7, 8, 3, 9, 10, 11, 12, 4, 9, 10, 5, 7, 1, 5, 4, 3, 4, 3, 3, 1, 45, 9, 10] flatten6 32.8386368752 flatten8 30.7509689331 >python temp3.py [[1, 2, 3], 5, [7, 8], 3, [9, [10, 11, 12], 4, [9, [10, 5, 7]], 1, [[[[[5, 4], 3], 4, 3], 3, 1, 45], 9], 10]] flatten6 [1, 2, 3, 5, 7, 8, 3, 9, 10, 11, 12, 4, 9, 10, 5, 7, 1, 5, 4, 3, 4, 3, 3, 1, 45, 9, 10] flatten8 [1, 2, 3, 5, 7, 8, 3, 9, 10, 11, 12, 4, 9, 10, 5, 7, 1, 5, 4, 3, 4, 3, 3, 1, 45, 9, 10] flatten6 34.730714798 flatten8 32.3252940178 --RDM From toby at tobiah.org Thu Feb 5 14:13:20 2009 From: toby at tobiah.org (Tobiah) Date: Thu, 05 Feb 2009 11:13:20 -0800 Subject: Flattening lists References: Message-ID: On Thu, 05 Feb 2009 11:06:39 -0800, Tobiah wrote: > >> Hello everybody, >> >> Any better solution than this? > > a = [1, 2, 3, [4, 5, 6], [[7, 8], [9, 10]]] print str(a).replace('[', > '').replace(']', '').split(', ') > > ;) Or: a = ['text', 'string', 3, [4, 5, 6], [[7, 8], [9, 10]]] print eval("[" + str(a).replace('[', '').replace(']', '') + "]") Just tongue in cheek... From marduk at letterboxes.org Thu Feb 5 14:30:11 2009 From: marduk at letterboxes.org (Albert Hopkins) Date: Thu, 05 Feb 2009 14:30:11 -0500 Subject: where clause In-Reply-To: References: Message-ID: <1233862211.12935.21.camel@localhost.localdomain> On Thu, 2009-02-05 at 10:04 -0800, bearophileHUGS at lycos.com wrote: > This comes after a small discussion in another Python newsgroup. > Haskell supports a where clause, that's syntactic sugar that allows > you to define things like this: > > p = a / b > where > a = 20 / len(c) > b = foo(d) > > That means: > > a = 20 / len(c) > b = foo(d) > p = a / b > > I don't know how much good this syntax can be in my Python programs, > probably I have to use it some time to judge. > > In the Python shell you usally have to use a bottom-up style of > programming, while a where may allow you a more top-down too. I can > enjoy this. > I don't like it for the following reasons: * Flat is better than nested. * There should be one-- and preferably only one --obvious way to do it. One could imagine this getting "out of hand" e.g. p = a / b where a = 20 / len(c) where c = p / b try: b = foo(d) where d = bar() except: b = 0 It also begs the question, should the except: clause be written to handle an exception raised in foo() as well as bar()? or should one also write a try/except around bar()? Usually when I'm looking at an identifier (function, class, variable) being used, I tend to look *up* to see where it is defined. From andrew.replogle at gmail.com Thu Feb 5 14:34:29 2009 From: andrew.replogle at gmail.com (Andrew) Date: Thu, 5 Feb 2009 11:34:29 -0800 (PST) Subject: subprocess returncode windows References: <18348eae-5af1-47e9-a198-b95d4fcb6eac@a12g2000pro.googlegroups.com> Message-ID: <851774bd-5019-4347-8815-36782dcec4b6@p2g2000prf.googlegroups.com> On Dec 16 2008, 5:11?pm, "Gabriel Genellina" wrote: > En Tue, 16 Dec 2008 17:21:35 -0200, Andrew ? > escribi?: > > > > > On Dec 16, 12:50?pm, Christian Heimes wrote: > >> Andrew schrieb: > > >> > I'm running into a strange situation with getting incorrect > >> > returncodes / exit status from python subprocess.call. I'm using a > >> > python script (runtime 2.6.1 on windows) to automate the deploy of > >> > java applications to glassfish application server. Below is an example > > > I've removed shell=True, unfortunately, if I structure the call like: > > > call(["c:/glassfish/bin/asadmin.bat", "list-system-properties", "-- > > host > > mydomain", "--port 4848", "--user admin", "server-01"]) > > > It doesn't seem to recognize any arguments after list-system- > > properties. > > Should be: > > call(["c:/glassfish/bin/asadmin.bat", "list-system-properties", "--host", > "mydomain", "--port", "4848", "--user", "admin", "server-01"]) > > *Every* argument should be an item in the list (your way, "--port 4848" ? > becomes a single argument, not two: option plus value) > (This is independent of your other issue) > > > If I structure it like: > > > call("c:/glassfish/bin/asadmin.bat "+"list-system-properties --host > > mydomain --port 4848 --user admin server-01") > > > Then it executes correctly but still gives invalid returncode of 0 > > when it fails instead of 1. > > A similar example works fine for me: > > C:\temp>type ret.c > #include > > int main(int argc, char* argv[]) > { > ? ?return atoi(argv[1]); > > } > > C:\temp>ret 5 > > C:\temp>echo %errorlevel% > 5 > > C:\temp>type testret.bat > ret %1 > > C:\temp>testret 3 > > C:\temp>ret 3 > > C:\temp>echo %errorlevel% > 3 > > C:\temp>type testret.py > ?from subprocess import call > ret = call(["testret.bat", "42"]) > print "testret.bat exit code =", ret > > C:\temp>python testret.py > > C:\temp>ret 42 > testret.bat exit code = 42 > > C:\temp>python -V > Python 2.6 > > C:\temp>ver > > Microsoft Windows XP [Versi?n 5.1.2600] > > -- > Gabriel Genellina I've tried this several ways now. It seems to be something specific with python and asadmin.bat. I've tried the following manually in the cmd.exe prompt: ------ C:\temp>c:\glassfish\bin\asadmin.bat list-system-properties Instance-01 .... properties here .... Command list-system-properties executed successfully. C:\temp>echo %errorlevel% 0 C:\temp>c:\glassfish\bin\asadmin.bat list-system-properties Instance-05 //note that Instance-05 does not exist Cannot determine type for target : Instance-05 CLI137 Command list-system-properties failed. C:\temp>echo %errorlevel% 1 C:\temp>ping 019293.com Ping request could not find host 019293.com. Please check the name and try again . C:\temp>echo %errorlevel% 1 C:\temp>ping google.com Pinging google.com [74.125.45.100] with 32 bytes of data: Reply from 74.125.45.100: bytes=32 time=48ms TTL=234 Reply from 74.125.45.100: bytes=32 time=66ms TTL=234 Reply from 74.125.45.100: bytes=32 time=63ms TTL=234 Reply from 74.125.45.100: bytes=32 time=44ms TTL=234 Ping statistics for 74.125.45.100: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 44ms, Maximum = 66ms, Average = 55ms C:\temp>echo %errorlevel% 0 ---------------------------------------- Then I tried the following in python (2.6.1) ---script--- import subprocess import sys try: retcode = subprocess.call(["ping","019293.com"]) if retcode < 0: print >>sys.stderr, "Child was terminated by signal", -retcode else: print >>sys.stderr, "Child returned", retcode except OSError, e: print >>sys.stderr, "Execution failed:", e try: retcode = subprocess.call(["ping","google.com"]) if retcode < 0: print >>sys.stderr, "Child was terminated by signal", -retcode else: print >>sys.stderr, "Child returned", retcode except OSError, e: print >>sys.stderr, "Execution failed:", e try: retcode = subprocess.call(["c:/glassfish/bin/asadmin.bat","list- system-properties","Instance-01"], shell=False) if retcode < 0: print >>sys.stderr, "Child was terminated by signal", -retcode else: print >>sys.stderr, "Child returned", retcode except OSError, e: print >>sys.stderr, "Execution failed:", e try: retcode = subprocess.call(["c:/glassfish/bin/asadmin.bat","list- system-properties","Instance-05"], shell=False) if retcode < 0: print >>sys.stderr, "Child was terminated by signal", -retcode else: print >>sys.stderr, "Child returned", retcode except OSError, e: print >>sys.stderr, "Execution failed:", e ---script--- Executed Output: ---output--- C:\temp>c:\Python26\python.exe example2.py Ping request could not find host 019293.com. Please check the name and try again. Child returned 1 Pinging google.com [74.125.67.100] with 32 bytes of data: Reply from 74.125.67.100: bytes=32 time=244ms TTL=239 Reply from 74.125.67.100: bytes=32 time=244ms TTL=239 Reply from 74.125.67.100: bytes=32 time=191ms TTL=234 Reply from 74.125.67.100: bytes=32 time=59ms TTL=239 Ping statistics for 74.125.67.100: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 59ms, Maximum = 244ms, Average = 184ms Child returned 0 ...glassfish properties for Instance-01 display here... Command list-system-properties executed successfully. Child returned 0 Cannot determine type for target : Instance-05 CLI137 Command list-system-properties failed. Child returned 0 C:\temp> ---output--- Notice how python never gets the correct returncode from asadmin.bat but I can get the correct returncode from the shell every time. Can anyone tell me why Python wouldn't be able to get the correct returncode for asadmin? TIA, Andrew From bearophileHUGS at lycos.com Thu Feb 5 14:57:34 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Thu, 5 Feb 2009 11:57:34 -0800 (PST) Subject: where clause References: Message-ID: <2b9a5854-a5bd-4f69-b302-3bcc72c3107b@b38g2000prf.googlegroups.com> Albert Hopkins: > One could imagine this getting "out of hand" e.g. Yes, any syntax can be abused (your example isn't abusive enough). > a = 20 / len(c) > where > c = p / b > try: > b = foo(d) > where > d = bar() > except: > b = 0 > > It also begs the question, should the except: clause be written to > handle an exception raised in foo() as well as bar()? or should one also > write a try/except around bar()? This code: > a = 20 / len(c) > where > c = p / b > try: > b = foo(d) > where > d = bar() > except: > b = 0 Equals to: a = 20 / len(p / b) try: b = foo(bar()) except: b = 0 p = a / b So the answer is positive. > Usually when I'm looking at an identifier (function, class, variable) > being used, I tend to look *up* to see where it is defined. Right, the main purpose of where is to change that usual way, if you want. Note that where may also be designed to create a new scope (as in Haskell, I think), that's why I have inlined the bar and p/b. Bye, bearophile From clp2 at rebertia.com Thu Feb 5 15:08:09 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 5 Feb 2009 12:08:09 -0800 Subject: os.system issues In-Reply-To: References: Message-ID: <50697b2c0902051208w40c7c3f3k39c1d4c4aeb08990@mail.gmail.com> On Thu, Feb 5, 2009 at 6:00 AM, Youri Lammers wrote: > Ok, > > I want to run a program called 'muscle' with my python script, > muscle uses the following command: > 'muscle.exe -in filename -out filename' > so far I got: > > import os > args = ['-in filename', '-out filename'] As Christian indirectly points out, that's an incorrect tokenization of the arguments. Remember that the shell has no knowledge of what arguments a program takes and so doesn't treat the arguments differently or specially for each program; it instead applies the consistent rule of breaking arguments at spaces (unless you put an argument in quotes). Thus, args should be: args = ['-in', 'filename', '-out', 'filename'] The fact that the program happens to semantically pair those adjacent arguments together is entirely up to and done by the program itself. You can verify this by printing sys.argv from a command-line Python program which you've given arguments to. And of course, you'd only use `args` like this if you were using the `subprocess` module; as others have pointed out, os.system() is more primitive and just takes a single string of the entire command. But `subprocess` is better anyway. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From stefan_ml at behnel.de Thu Feb 5 15:10:10 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 05 Feb 2009 21:10:10 +0100 Subject: Python Integrated Parallel Pipeline EnviRonment: PIPPER In-Reply-To: <74164566-8bc4-40d7-b9f0-881ed9a015e5@p2g2000prn.googlegroups.com> References: <74164566-8bc4-40d7-b9f0-881ed9a015e5@p2g2000prn.googlegroups.com> Message-ID: <498b47a2$0$31338$9b4e6d93@newsspool4.arcor-online.net> Kyle wrote: > def do_call(x,y): > print "Hello World", x, y, os.getpid() > > if __name__ == '__pipper_main__': > a_range = range( int(sys.argv[1]) ) > #pragma pipper_start > for a in a_range : > for b in a_range : > do_call(a,b) > #pragma pipper_end I'm not a big fan of comments that change semantics. Wouldn't a modified 'with' statement look better? We have a couple of other syntax proposals in the Cython Wiki. http://wiki.cython.org/enhancements/parallel Stefan From michele.simionato at gmail.com Thu Feb 5 15:16:45 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Thu, 5 Feb 2009 12:16:45 -0800 (PST) Subject: Flattening lists References: Message-ID: On Feb 5, 7:24?pm, a... at pythoncraft.com (Aahz) wrote: > In article , > Michele Simionato ? wrote: > > > > >Looks fine to me. In some situations you may also use hasattr(el, > >'__iter__') instead of isinstance(el, list) (it depends if you want to > >flatten generic iterables or only lists). > > Of course, once you do that, you need to special-case strings... Strings are iterable but have no __iter__ method, which is fine in this context, since I would say 99.9% of times one wants to treat them as atomic objects, so no need to special case. From benjamin.kaplan at case.edu Thu Feb 5 15:18:54 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 5 Feb 2009 15:18:54 -0500 Subject: Python Installation Error In-Reply-To: <64020629-a27e-45f8-bfd9-1cf61384a548@t26g2000prh.googlegroups.com> References: <64020629-a27e-45f8-bfd9-1cf61384a548@t26g2000prh.googlegroups.com> Message-ID: On Thu, Feb 5, 2009 at 12:46 PM, Ahmed Majeed wrote: > Hi, > I am working over a research project and need Python 2.3 or later to > be installed on my Intel Centrino machine, running Fedora 9 as OS. I > have downloaded latest stable release Python 2.6.1 from Python.org, > but when I tried installing it, terminal returned an error on 'make', > saying: > > "Failed to find the necessory Bits to build these modules: > _tkinter bsddb185, sunaaudiodev > To find the necessory bits, look in setup.py in detect_modules() for > the module's name." > > How should I correct this and go ahead for installation. Anxiously > waiting reply and thanking you in anticiaption. Are you sure there was an error in make? What you see isn't a problem, it's just a notification. Make is telling you the tk, bsddb, and sunaaudiodev modules won't be installed because you don't have the libraries on your computer. If it got that far, I'm almost certain that the build was sucessful. Make install should work from there. If you aren't going to use those modules, go ahead and install it, otherwise download those libraries and try again. -------------- next part -------------- An HTML attachment was scrubbed... URL: From matzke at berkeley.edu Thu Feb 5 15:28:13 2009 From: matzke at berkeley.edu (Nick Matzke) Date: Thu, 05 Feb 2009 12:28:13 -0800 Subject: global name 'sqrt' is not defined In-Reply-To: <5rSdnfi3VIPQlhbUnZ2dnUVZ_r3inZ2d@pdx.net> References: <498AAC89.5080002@berkeley.edu> <5rSdnfi3VIPQlhbUnZ2dnUVZ_r3inZ2d@pdx.net> Message-ID: <498B4BDD.701@berkeley.edu> Scott David Daniels wrote: > M.-A. Lemburg wrote: >> On 2009-02-05 10:08, Nick Matzke wrote: >>> ..., I can run this in the ipython shell just fine: >>> a = ["12", "15", "16", "38.2"] >>> dim = int(sqrt(size(a))) >>> ...But if I move these commands to a function in another file, it >>> freaks out: >> You need to add: >> >> from math import sqrt > or: > from cmath import sqrt > or: > from numpy import sqrt The weird thing is, when I do this, I still get the error: ============ nick at mws2[phylocom]|27> a = ["12", "15", "16", "38.2"] nick at mws2[phylocom]|28> from LR_run_functions_v2 import make_half_square_array nick at mws2[phylocom]|24> d = make_half_square_array(a) --------------------------------------------------------------------------- NameError Traceback (most recent call last) /bioinformatics/phylocom/ in () /bioinformatics/phylocom/_scripts/LR_run_functions_v2.py in make_half_square_array(linear_version_of_square_array) 1548 from numpy import sqrt 1549 a = linear_version_of_square_array -> 1550 dim = int(sqrt(size(a))) 1551 1552 NameError: global name 'sqrt' is not defined nick at mws2[phylocom]|25> ============ Is there some other place I should put the import command? I.e.: 1. In the main script/ipython command line 2. In the called function, i.e. make_half_square_array() in LR_run_functions_v2.py 3. At the top of LR_run_functions_v2.py, outside of the individual functions? Thanks...sorry for the noob questions! Nick > > Each with their own, slightly different, meaning. > Hence the reason many of us prefer to import the module > and reference the function as a module attribute. > > Note that _many_ (especially older) package documents describe > their code without the module name. I believe that such behavior > is because, when working to produce prose about a package, it > feels too much like useless redundancy when describing each function > or class as "package.name". > > > --Scott David Daniels > Scott.Daniels at Acm.Org > -- > http://mail.python.org/mailman/listinfo/python-list > -- ==================================================== Nicholas J. Matzke Ph.D. student, Graduate Student Researcher Huelsenbeck Lab Center for Theoretical Evolutionary Genomics 4151 VLSB (Valley Life Sciences Building) Department of Integrative Biology University of California, Berkeley Lab websites: http://ib.berkeley.edu/people/lab_detail.php?lab=54 http://fisher.berkeley.edu/cteg/hlab.html Dept. personal page: http://ib.berkeley.edu/people/students/person_detail.php?person=370 Lab personal page: http://fisher.berkeley.edu/cteg/members/matzke.html Lab phone: 510-643-6299 Dept. fax: 510-643-6264 Cell phone: 510-301-0179 Email: matzke at berkeley.edu Mailing address: Department of Integrative Biology 3060 VLSB #3140 Berkeley, CA 94720-3140 ----------------------------------------------------- "[W]hen people thought the earth was flat, they were wrong. When people thought the earth was spherical, they were wrong. But if you think that thinking the earth is spherical is just as wrong as thinking the earth is flat, then your view is wronger than both of them put together." Isaac Asimov (1989). "The Relativity of Wrong." The Skeptical Inquirer, 14(1), 35-44. Fall 1989. http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm ==================================================== From kellrott at gmail.com Thu Feb 5 15:40:29 2009 From: kellrott at gmail.com (Kyle) Date: Thu, 5 Feb 2009 12:40:29 -0800 (PST) Subject: Python Integrated Parallel Pipeline EnviRonment: PIPPER References: <74164566-8bc4-40d7-b9f0-881ed9a015e5@p2g2000prn.googlegroups.com> <498b47a2$0$31338$9b4e6d93@newsspool4.arcor-online.net> Message-ID: PIPPER doesn't yet have a very large user base, and is still in Alpha. So if there is enough demand, syntax changes would still be possible at this stage. Kyle > I'm not a big fan of comments that change semantics. Wouldn't a modified > 'with' statement look better? > > We have a couple of other syntax proposals in the Cython Wiki. > > http://wiki.cython.org/enhancements/parallel > > Stefan From matt.dubins at sympatico.ca Thu Feb 5 15:40:29 2009 From: matt.dubins at sympatico.ca (inkhorn) Date: Thu, 5 Feb 2009 12:40:29 -0800 (PST) Subject: tkSimpleDialog window focus problem References: <238e1e3c-66aa-45de-9a67-2b91e15bc465@x6g2000pre.googlegroups.com> Message-ID: <987c2c11-7b16-4df2-97b1-6185010c333f@i18g2000prf.googlegroups.com> After much tinkering, I figured out the problem. Before the call to the ftp.login function, I had another simpledialog asking for a userid. The focus was leaving the parent Tk window altogether right after userid entry. So, right after the call to obtain the userid from the user, i called the Frame.focus_force() method. Observe: self.userid = tkSimpleDialog.askstring("UTSCID Entry","UTSCID:") self.focus_force() Now, the next tkSimpleDialog.askstring call that I made ACTUALLY gets the keyboard focus automatically. Cheers, Matt On Feb 4, 10:21?am, inkhorn wrote: > Hi all, > > As part of the program I've created and am maintaining, the user has > to type in his/her username and password into tkinter simple dialog > windows. ?What you'll see below is that I've nested an askstring > dialog window within a call to use the ftp module to login to an FTP > server. > > result = self.ftp.login(self.userid, tkSimpleDialog.askstring > ("Password Entry", > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "Password:", show="*")) > > Annoyingly, every time this password entry window pops up, the focus > does not go on it automatically. ?Anyone know what I can do to put the > focus on it automatically, while *not* storing the user's password in > my script for the remainder of its runtime? > > Thanks, > Matt Dubins From python-url at phaseit.net Thu Feb 5 15:50:07 2009 From: python-url at phaseit.net (Gabriel Genellina) Date: Thu, 5 Feb 2009 20:50:07 +0000 (UTC) Subject: Python-URL! - weekly Python news and links (Feb 5) Message-ID: QOTW: "Findability trumps usability. If you can't find it, you can't use it." - information architect Robert Morville Boolean expressions don't necesarily yield a boolean type - and that's very useful: http://groups.google.com/group/comp.lang.python/t/e834202d1a6a919/ Using __del__ is rather fragile: http://groups.google.com/group/comp.lang.python/t/c1e7fccbfd7e5e73/ http://groups.google.com/group/comp.lang.python/t/25d36f0a74245bc4/ Good or bad usage of __repr__? http://groups.google.com/group/comp.lang.python/t/d7e2b1637db02f2a/ Which OOP concepts apply to the Python language? A long thread, at the end mostly focused on access restrictions: http://groups.google.com/group/comp.lang.python/t/abf06e897aacc3d9/ A class implementing an iterator, and how the iterator protocol works: http://groups.google.com/group/comp.lang.python/t/edaa3cc79a0581ea/ Computing the n-th root of big numbers: http://groups.google.com/group/comp.lang.python/t/7eb4facfe4b0ffa1/ A list that knows when any of its elements is modified: http://groups.google.com/group/comp.lang.python/t/4b7f993274ece50d/ Embedding 2.6.1 in Windows doesn't work due to missing C runtime libraries: http://groups.google.com/group/comp.lang.python/t/3ec6af1279a162ca/ How to call Python code from another thread written in C: http://groups.google.com/group/comp.lang.python/t/1d05f3f215346249/ How SQLAlchemy compares to similar ORMs: http://groups.google.com/group/comp.lang.python/t/547d0a7c0477293c/ ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous daily python url http://www.pythonware.com/daily Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers The Python Papers aims to publish "the efforts of Python enthusiats": http://pythonpapers.org/ The Python Magazine is a technical monthly devoted to Python: http://pythonmagazine.com Readers have recommended the "Planet" sites: http://planetpython.org http://planet.python.org comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ The somewhat older Vaults of Parnassus ambitiously collects references to all sorts of Python resources. http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donations/ The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions. http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes. http://code.activestate.com/recipes/langs/python/ Many Python conferences around the world are in preparation. Watch this space for links to them. Among several Python-oriented RSS/RDF feeds available, see: http://www.python.org/channews.rdf For more, see: http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://www.python.org/dev/peps/pep-0042/ del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python *Py: the Journal of the Python Language* http://www.pyzine.com Dr.Dobb's Portal is another source of Python news and articles: http://www.ddj.com/TechSearch/searchResults.jhtml?queryText=python and Python articles regularly appear at IBM DeveloperWorks: http://www.ibm.com/developerworks/search/searchResults.jsp?searchSite=dW&searchScope=dW&encodedQuery=python&rankprofile=8 Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://search.gmane.org/?query=python+URL+weekly+news+links&group=gmane.comp.python.general&sort=date http://groups.google.com/groups/search?q=Python-URL!+group%3Acomp.lang.python&start=0&scoring=d& http://lwn.net/Search/DoSearch?words=python-url&ctype3=yes&cat_25=yes There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". Write to the same address to unsubscribe. -- The Python-URL! Team-- Phaseit, Inc. (http://phaseit.net) is pleased to participate in and sponsor the "Python-URL!" project. Watch this space for upcoming news about posting archives. From rNOSPAMon at flownet.com Thu Feb 5 15:52:42 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Thu, 05 Feb 2009 12:52:42 -0800 Subject: WebError documentation? Message-ID: Is there any? Where is it? Extensive Googling has proven fruitless. Thanks, rg From deets at nospam.web.de Thu Feb 5 15:57:52 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 05 Feb 2009 21:57:52 +0100 Subject: global name 'sqrt' is not defined In-Reply-To: References: <498AAC89.5080002@berkeley.edu> <5rSdnfi3VIPQlhbUnZ2dnUVZ_r3inZ2d@pdx.net> Message-ID: <6v126hFhj1beU1@mid.uni-berlin.de> Nick Matzke schrieb: > > > Scott David Daniels wrote: >> M.-A. Lemburg wrote: >>> On 2009-02-05 10:08, Nick Matzke wrote: >>>> ..., I can run this in the ipython shell just fine: >>>> a = ["12", "15", "16", "38.2"] >>>> dim = int(sqrt(size(a))) >>>> ...But if I move these commands to a function in another file, it >>>> freaks out: >>> You need to add: >>> >>> from math import sqrt >> or: >> from cmath import sqrt >> or: >> from numpy import sqrt > > > > > > The weird thing is, when I do this, I still get the error: > > ============ > nick at mws2[phylocom]|27> a = ["12", "15", "16", "38.2"] > nick at mws2[phylocom]|28> from LR_run_functions_v2 import > make_half_square_array > nick at mws2[phylocom]|24> d = make_half_square_array(a) > --------------------------------------------------------------------------- > NameError Traceback (most recent call last) > > /bioinformatics/phylocom/ in () > > /bioinformatics/phylocom/_scripts/LR_run_functions_v2.py in > make_half_square_array(linear_version_of_square_array) > 1548 from numpy import sqrt > 1549 a = linear_version_of_square_array > -> 1550 dim = int(sqrt(size(a))) > 1551 > 1552 > > NameError: global name 'sqrt' is not defined > nick at mws2[phylocom]|25> > ============ > > Is there some other place I should put the import command? I.e.: > 1. In the main script/ipython command line > > 2. In the called function, i.e. make_half_square_array() in > LR_run_functions_v2.py > > 3. At the top of LR_run_functions_v2.py, outside of the individual > functions? The latter. Python's imports are always local to the module/file they are in, not globally effective. Diez From http Thu Feb 5 16:27:46 2009 From: http (Paul Rubin) Date: 05 Feb 2009 13:27:46 -0800 Subject: where clause References: <2b9a5854-a5bd-4f69-b302-3bcc72c3107b@b38g2000prf.googlegroups.com> Message-ID: <7x7i44poa5.fsf@ruckus.brouhaha.com> bearophileHUGS at lycos.com writes: > Note that where may also be designed to create a new scope (as in > Haskell, I think), that's why I have inlined the bar and p/b. In Haskell, "where" is only allowed at the outermost level of a function definition (including a nested one), not in an arbitrary expression. From sluggoster at gmail.com Thu Feb 5 16:37:48 2009 From: sluggoster at gmail.com (Mike Orr) Date: Thu, 5 Feb 2009 13:37:48 -0800 (PST) Subject: database wrapper ? References: Message-ID: <8491d636-4084-4baf-8cc8-af2f800fd361@s9g2000prg.googlegroups.com> On Feb 1, 3:47?pm, Stephen Hansen wrote: > Googling, I found SQLalchemy, > which looks quit good. > SQLAlchemy is very good. I'm very slowly migrating our entire codebase to it. > ? > > > But as I only want to choose once, > I googled for ?"SQLalchemy alternatives", > but it didn't find many answers. > (Storm / Grok are of no interest, because manipulating the structure of the database is a key issue). > There's a few other alternatives-- if you google "Python ORM" you'll find a lot more, and PyPi might have a list. But IMHO, SQLAlchemy is the best of breed so far. Its very, very flexible and doesn't really impose on you with any rules about how you must do things. > Storm's not bad, don't get me wrong! > But one question on your requirements: manipulating the structure of the database. How so? If you mean that you want to be able to modify the object wrapper to change some field of a table and have that change propagated to the database layer... then SQLAlchemy doesn't support that. If you add new tables it'll create them, and it MIGHT add new columns or indexes if you add them after and it notices they aren't there... but I'm not entirely sure on that. engine.execute("ALTER TABLE ...") However, this may confuse ORM objects already in memory as well as transactions, so clear these out both before and afterward. The syntax is database specific. MySQL can add and delete columns and change a column's type. SQLite can only rename tables. However, your ORM objects won't know about the new columns unless you reinitialize the Table objects and mapper with autoloading. So it's best to modify the schema in a standalone program that does not use the ORM. As for modifying the columns in the Table objects and propagating the changes to the database, you can't do that. You have to execute "ALTER TABLE" as a string command. SQLAlchemy would have to add a whole new layer to deal with alternations at the Table or SQL builder level, and in the end they're still database specific. From gandalf at shopzeus.com Thu Feb 5 16:42:26 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Thu, 05 Feb 2009 22:42:26 +0100 Subject: kinterbasdb + firebird 1.5 with python 2.6 ? In-Reply-To: References: Message-ID: <498B5D42.6080408@shopzeus.com> Uwe Grauer ?rta: > Laszlo Nagy wrote: > >> Does anyone know how to get firebird 1.5 driver (kinterbasdb) for >> FireBird 1.5? >> >> My problem: >> >> * python 2.6 already installed on a server >> * there is a firebird 1.5 database on the same server >> * I need to access it from python 2.6 >> >> Any thoughts? >> >> >> > > Get it from here: > http://www.firebirdsql.org/index.php?op=devel&sub=python > Thanks. Unfortunately, this does not support Firebird 1.5 anymore. I can only find Python 2.5 + Firebird 1.5. But not for Python 2.6. I'm going to downgrade. :-( From btaylordesign at gmail.com Thu Feb 5 16:47:09 2009 From: btaylordesign at gmail.com (Brandon Taylor) Date: Thu, 5 Feb 2009 13:47:09 -0800 (PST) Subject: Extracting file from zip archive in Python 2.6.1 References: <7676f73d-2ee9-4151-8a09-b11a3eea2045@p37g2000yqd.googlegroups.com> <4d2b4207-e14a-4b4d-b518-1b7eb6322ce5@n33g2000pri.googlegroups.com> Message-ID: On Feb 4, 12:16?am, "Gabriel Genellina" wrote: > En Wed, 04 Feb 2009 00:36:40 -0200, Brandon Taylor ? > escribi?: > > > > > On Feb 3, 1:16?pm, Brandon Taylor wrote: > >> On Feb 3, 9:45?am, "Gabriel Genellina" wrote: > >> > En Tue, 03 Feb 2009 05:31:24 -0200, Brandon Taylor ? > >> > escribi?: > >> > > zip_file.extract(zip_name + '/' + thumbnail_image, thumbnail_path) > >> > > What is happening is that the extract method is creating a folder > ? > >> > with > >> > > the name of 'zip_name' and extracting the files to it. Example: > >> > extract will create all directories in member name. Use open instead: > >> > with zip_file.open(zip_name + '/' + thumbnail_image) as source: > >> > ? ?with open(os.path.join(thumbnail_path, thumbnail_image), "wb") as ? > >> > target: > >> > ? ? ?shutil.copyfileobj(source, target) > > Ok, the first thing I needed to do was add: > > > from __future__ import with_statement at the beginning of my file > > That should not be necesary with your Python version (2.6.1 isn't it?) > > > with zip_file.open(zip_name + '/' + thumbnail_image) as source: > > ? ? ? ? ? ? ? ? ? ? with open(os.path.join(thumbnail_path, > > thumbnail_image), 'wb') as target: > > ? ? ? ? ? ? ? ? ? ? ? ? shutil.copyfileobj(source, target) > > > Returns an error on the first line: > > > ZipExtFile instance has no attribute '__exit__' > > Ouch, sorry, this new feature will appear in the not-yet-released 2.7 ? > version... > Try this instead: > > source = zip_file.open(zip_name + '/' + thumbnail_image) > try: > ? ?with open(os.path.join(thumbnail_path, thumbnail_image), 'wb') as target: > ? ? ?shutil.copyfileobj(source, target) > finally: > ? ?source.close() > > -- > Gabriel Genellina Awesome. Works perfectly, and saves me the extra step of having to move the files. Many, many thanks! Kind regards, Brandon From tjreedy at udel.edu Thu Feb 5 17:09:16 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 05 Feb 2009 17:09:16 -0500 Subject: Ordered dict by default In-Reply-To: <7x7i45qiyo.fsf@ruckus.brouhaha.com> References: <47a82549-bc80-45ac-8b51-d58e597e768f@r24g2000vbp.googlegroups.com> <7x7i45qiyo.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > bearophileHUGS at lycos.com writes: >> Now Ruby dicts are ordered by default: >> http://www.igvita.com/2009/02/04/ruby-19-internals-ordered-hash/ > > Maybe I didn't read that carefully enough, but it looks like "ordered" > means the dict records come out in the same order you inserted them > in. That is if you insert B,A,D,C in that order, you get them out in > that order. This seems to have become the more common meaning of 'ordered dict'. > I would have thought an ordered dict meant you get A,B,C,D, > which seems a lot more useful. I once thought that too, but this would be a 'sorted dict'. tjr From tjreedy at udel.edu Thu Feb 5 17:11:30 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 05 Feb 2009 17:11:30 -0500 Subject: Ordered dict by default In-Reply-To: <6e4959e8-b5e2-43da-9199-8bd0d2499e03@i18g2000prf.googlegroups.com> References: <47a82549-bc80-45ac-8b51-d58e597e768f@r24g2000vbp.googlegroups.com> <6e4959e8-b5e2-43da-9199-8bd0d2499e03@i18g2000prf.googlegroups.com> Message-ID: andrew cooke wrote: > so what is happening with pep 372? > > http://www.python.org/dev/peps/pep-0372/ There seems to be a number of unanswered questions as to the exact behavior (see Q and A section). The author needs to promote more discussion by those interested, including here, and make a decision. From tjreedy at udel.edu Thu Feb 5 17:20:06 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 05 Feb 2009 17:20:06 -0500 Subject: Is c.l.py becoming less friendly? In-Reply-To: References: Message-ID: mk wrote: > > (duck) > > 542 comp.lang.python rtfm What is so unfriendly about 'read the fine manual'? From lionel.keene at gmail.com Thu Feb 5 17:22:35 2009 From: lionel.keene at gmail.com (Lionel) Date: Thu, 5 Feb 2009 14:22:35 -0800 (PST) Subject: Skipping bytes while reading a binary file? Message-ID: <279bf987-8e3c-465d-a173-49b3d99a298a@s9g2000prg.googlegroups.com> Hello, I have data stored in binary files. Some of these files are huge...upwards of 2 gigs or more. They consist of 32-bit float complex numbers where the first 32 bits of the file is the real component, the second 32bits is the imaginary, the 3rd 32-bits is the real component of the second number, etc. I'd like to be able to read in just the real components, load them into a numpy.ndarray, then load the imaginary coponents and load them into a numpy.ndarray. I need the real and imaginary components stored in seperate arrays, they cannot be in a single array of complex numbers except for temporarily. I'm trying to avoid temporary storage, though, because of the size of the files. I'm currently reading the file scanline-by-scanline to extract rows of complex numbers which I then loop over and load into the real/ imaginary arrays as follows: self._realData = numpy.empty((Rows, Columns), dtype = numpy.float32) self._imaginaryData = numpy.empty((Rows, Columns), dtype = numpy.float32) floatData = array.array('f') for CurrentRow in range(Rows): floatData.fromfile(DataFH, (Columns*2)) position = 0 for CurrentColumn in range(Columns): self._realData[CurrentRow, CurrentColumn] = floatData[position] self._imaginaryData[CurrentRow, CurrentColumn] = floatData[position+1] position = position + 2 The above code works but is much too slow. If I comment out the body of the "for CurrentColumn in range(Columns)" loop, the performance is perfectly adequate i.e. function call overhead associated with the "fromfile(...)" call is not very bad at all. What seems to be most time-consuming are the simple assignment statements in the "CurrentColumn" for-loop. Does anyone see any ways of speeding this up at all? Reading everything into a complex64 ndarray in one fell swoop would certainly be easier and faster, but at some point I'll need to split this array into two parts (real / imaginary). I'd like to have that done initially to keep the memory usage down since the files are so ginormous. Psyco is out because I need 64-bits, and I didn't see anything on the forums regarding a method that reads in every other 32-bit chunk form a file into an array. I'm not sure what else to try. Thanks in advance. L From mensanator at aol.com Thu Feb 5 17:29:50 2009 From: mensanator at aol.com (Mensanator) Date: Thu, 5 Feb 2009 14:29:50 -0800 (PST) Subject: Is c.l.py becoming less friendly? References: Message-ID: <1b50521f-b33b-4e3e-9a3e-65e8eb2f7242@v18g2000pro.googlegroups.com> On Feb 5, 4:20?pm, Terry Reedy wrote: > mk wrote: > > > (duck) > > > 542 comp.lang.python rtfm > > What is so unfriendly about 'read the fine manual'? You've seen a fine manual? From benjamin.kaplan at case.edu Thu Feb 5 17:30:51 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 5 Feb 2009 17:30:51 -0500 Subject: kinterbasdb + firebird 1.5 with python 2.6 ? In-Reply-To: <498B5D42.6080408@shopzeus.com> References: <498B5D42.6080408@shopzeus.com> Message-ID: On Thu, Feb 5, 2009 at 4:42 PM, Laszlo Nagy wrote: > Uwe Grauer ?rta: > >> Laszlo Nagy wrote: >> >> >>> Does anyone know how to get firebird 1.5 driver (kinterbasdb) for >>> FireBird 1.5? >>> >>> My problem: >>> >>> * python 2.6 already installed on a server >>> * there is a firebird 1.5 database on the same server >>> * I need to access it from python 2.6 >>> >>> Any thoughts? >>> >>> >>> >>> >> >> Get it from here: >> http://www.firebirdsql.org/index.php?op=devel&sub=python >> >> > Thanks. Unfortunately, this does not support Firebird 1.5 anymore. I can > only find Python 2.5 + Firebird 1.5. But not for Python 2.6. I'm going to > downgrade. :-( > The prebuilt binaries don't support Firebird 1.5. The installation guide says that you can compile it from source to get 1.5 support. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From travis+ml-python at subspacefield.org Thu Feb 5 17:40:36 2009 From: travis+ml-python at subspacefield.org (Travis) Date: Thu, 5 Feb 2009 16:40:36 -0600 Subject: updating nntplib Message-ID: <20090205224036.GH29170@subspacefield.org> Hello all, There are some notable deficiencies in nntlib. Here are two: 1) It says it implements NNTP as defined in RFC 977, but NNTP has a newer RFC, RFC 3977, which clarifies some vagueness and has more commands defined. However, as it currently stands you cannot issue these commands, since they aren't available to call. 2) In some cases, it will bomb out upon receiving certain greetings that it doesn't expect. As I understand it, it actually terminates the connection, not allowing for catching an exception or anything. I have not verified this myself. I'd like to remedy these deficiencies. In the case of #1, I'd like to implement some of the new commands and provide a way to send arbitrary commands to the server, because NNTP is designed to allow servers to implement optional features. I'm not sure how I'll remedy #2, but I imagine it will be clear once I examine the code. I am guessing that this is the right list for discussing this, but perhaps python-dev is better. Anyone have feedback? -- Crypto ergo sum. http://www.subspacefield.org/~travis/ Do unto other faiths as you would have them do unto yours. If you are a spammer, please email john at subspacefield.org to get blacklisted. From lionel.keene at gmail.com Thu Feb 5 17:40:49 2009 From: lionel.keene at gmail.com (Lionel) Date: Thu, 5 Feb 2009 14:40:49 -0800 (PST) Subject: Skipping bytes while reading a binary file? References: <279bf987-8e3c-465d-a173-49b3d99a298a@s9g2000prg.googlegroups.com> Message-ID: <44dc0091-1ea2-4636-952f-ee3ab4f33223@g1g2000pra.googlegroups.com> On Feb 5, 2:22?pm, Lionel wrote: > Hello, > I have data stored in binary files. Some of these files are > huge...upwards of 2 gigs or more. They consist of 32-bit float complex > numbers where the first 32 bits of the file is the real component, the > second 32bits is the imaginary, the 3rd 32-bits is the real component > of the second number, etc. > > I'd like to be able to read in just the real components, load them > into a numpy.ndarray, then load the imaginary coponents and load them > into a numpy.ndarray. ?I need the real and imaginary components stored > in seperate arrays, they cannot be in a single array of complex > numbers except for temporarily. I'm trying to avoid temporary storage, > though, because of the size of the files. > > I'm currently reading the file scanline-by-scanline to extract rows of > complex numbers which I then loop over and load into the real/ > imaginary arrays as follows: > > ? ? ? ? self._realData ? ? ? ? = numpy.empty((Rows, Columns), dtype = > numpy.float32) > ? ? ? ? self._imaginaryData = numpy.empty((Rows, Columns), dtype = > numpy.float32) > > ? ? ? ? floatData = array.array('f') > > ? ? ? ? for CurrentRow in range(Rows): > > ? ? ? ? ? ? floatData.fromfile(DataFH, (Columns*2)) > > ? ? ? ? ? ? position = 0 > ? ? ? ? ? ? for CurrentColumn in range(Columns): > > ? ? ? ? ? ? ? ? ?self._realData[CurrentRow, CurrentColumn] ? ? ? ? ?= > floatData[position] > ? ? ? ? ? ? ? ? self._imaginaryData[CurrentRow, CurrentColumn] ?= > floatData[position+1] > ? ? ? ? ? ? ? ? position = position + 2 > > The above code works but is much too slow. If I comment out the body > of the "for CurrentColumn in range(Columns)" loop, the performance is > perfectly adequate i.e. function call overhead associated with the > "fromfile(...)" call is not very bad at all. What seems to be most > time-consuming are the simple assignment statements in the > "CurrentColumn" for-loop. > > Does anyone see any ways of speeding this up at all? Reading > everything into a complex64 ndarray in one fell swoop would certainly > be easier and faster, but at some point I'll need to split this array > into two parts (real / imaginary). I'd like to have that done > initially to keep the memory usage down since the files are so > ginormous. > > Psyco is out because I need 64-bits, and I didn't see anything on the > forums regarding a method that reads in every other 32-bit chunk form > a file into an array. I'm not sure what else to try. > > Thanks in advance. > L Hmmm...I've just discovered "weave.inline()". Maybe I'll just do the assignments in C. Still soliciting advice, of course. :-) From david at boddie.org.uk Thu Feb 5 17:45:12 2009 From: david at boddie.org.uk (David Boddie) Date: Thu, 05 Feb 2009 23:45:12 +0100 Subject: HOWTO for setting up a PyQt project in Eclipse ? References: Message-ID: On Thursday 05 February 2009 18:13, Linuxguy123 wrote: > Does anyone know of a HOWTO for setting up a PyQt project in Eclipse ? > > I know about setting up a PyDev project, just wondering how to integrate > the QtDesigner parts. > > For example, should I save the QtDesigner project in the root PyDev > directory ? I'm not an Eclipse user, but I recently noticed that the Python(x,y) project uses (or at least refers to) both PyQt and PyDev. Maybe there's some useful information, or useful starting points, on these pages: http://pythonxy.com/help.php http://pythonxy.com/discussions.php David From steve at holdenweb.com Thu Feb 5 17:46:19 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 05 Feb 2009 17:46:19 -0500 Subject: Is c.l.py becoming less friendly? In-Reply-To: <1b50521f-b33b-4e3e-9a3e-65e8eb2f7242@v18g2000pro.googlegroups.com> References: <1b50521f-b33b-4e3e-9a3e-65e8eb2f7242@v18g2000pro.googlegroups.com> Message-ID: Mensanator wrote: > On Feb 5, 4:20 pm, Terry Reedy wrote: >> mk wrote: >> >>> (duck) >>> 542 comp.lang.python rtfm >> What is so unfriendly about 'read the fine manual'? > > You've seen a fine manual? Yes, and I'm fine well sure this is somewhere between a silly thread and a troll. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From google at mrabarnett.plus.com Thu Feb 5 17:48:49 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 05 Feb 2009 22:48:49 +0000 Subject: Skipping bytes while reading a binary file? In-Reply-To: <279bf987-8e3c-465d-a173-49b3d99a298a@s9g2000prg.googlegroups.com> References: <279bf987-8e3c-465d-a173-49b3d99a298a@s9g2000prg.googlegroups.com> Message-ID: <498B6CD1.30700@mrabarnett.plus.com> Lionel wrote: > Hello, > I have data stored in binary files. Some of these files are > huge...upwards of 2 gigs or more. They consist of 32-bit float complex > numbers where the first 32 bits of the file is the real component, the > second 32bits is the imaginary, the 3rd 32-bits is the real component > of the second number, etc. > > I'd like to be able to read in just the real components, load them > into a numpy.ndarray, then load the imaginary coponents and load them > into a numpy.ndarray. I need the real and imaginary components stored > in seperate arrays, they cannot be in a single array of complex > numbers except for temporarily. I'm trying to avoid temporary storage, > though, because of the size of the files. > > I'm currently reading the file scanline-by-scanline to extract rows of > complex numbers which I then loop over and load into the real/ > imaginary arrays as follows: > > > self._realData = numpy.empty((Rows, Columns), dtype = > numpy.float32) > self._imaginaryData = numpy.empty((Rows, Columns), dtype = > numpy.float32) > > floatData = array.array('f') > > for CurrentRow in range(Rows): > > floatData.fromfile(DataFH, (Columns*2)) > > position = 0 > for CurrentColumn in range(Columns): > > self._realData[CurrentRow, CurrentColumn] = > floatData[position] > self._imaginaryData[CurrentRow, CurrentColumn] = > floatData[position+1] > position = position + 2 > > > The above code works but is much too slow. If I comment out the body > of the "for CurrentColumn in range(Columns)" loop, the performance is > perfectly adequate i.e. function call overhead associated with the > "fromfile(...)" call is not very bad at all. What seems to be most > time-consuming are the simple assignment statements in the > "CurrentColumn" for-loop. > [snip] Try array slicing. floatData[0::2] will return the real parts and floatData[1::2] will return the imaginary parts. You'll have to read up how to assign to a slice of the numpy array (it might be "self._realData[CurrentRow] = real_parts" or "self._realData[CurrentRow, :] = real_parts"). BTW, it's not the function call overhead of fromfile() which takes the time, but actually reading data from the file. From lionel.keene at gmail.com Thu Feb 5 17:56:28 2009 From: lionel.keene at gmail.com (Lionel) Date: Thu, 5 Feb 2009 14:56:28 -0800 (PST) Subject: Skipping bytes while reading a binary file? References: <279bf987-8e3c-465d-a173-49b3d99a298a@s9g2000prg.googlegroups.com> Message-ID: <695d1efb-6144-4004-a4df-e387e26fa32f@p2g2000prf.googlegroups.com> On Feb 5, 2:48?pm, MRAB wrote: > Lionel wrote: > > ?> Hello, > ?> I have data stored in binary files. Some of these files are > ?> huge...upwards of 2 gigs or more. They consist of 32-bit float complex > ?> numbers where the first 32 bits of the file is the real component, the > ?> second 32bits is the imaginary, the 3rd 32-bits is the real component > ?> of the second number, etc. > ?> > ?> I'd like to be able to read in just the real components, load them > ?> into a numpy.ndarray, then load the imaginary coponents and load them > ?> into a numpy.ndarray. ?I need the real and imaginary components stored > ?> in seperate arrays, they cannot be in a single array of complex > ?> numbers except for temporarily. I'm trying to avoid temporary storage, > ?> though, because of the size of the files. > ?> > ?> I'm currently reading the file scanline-by-scanline to extract rows of > ?> complex numbers which I then loop over and load into the real/ > ?> imaginary arrays as follows: > ?> > ?> > ?> ? ? ? ? self._realData ? ? ? ? = numpy.empty((Rows, Columns), dtype = > ?> numpy.float32) > ?> ? ? ? ? self._imaginaryData = numpy.empty((Rows, Columns), dtype = > ?> numpy.float32) > ?> > ?> ? ? ? ? floatData = array.array('f') > ?> > ?> ? ? ? ? for CurrentRow in range(Rows): > ?> > ?> ? ? ? ? ? ? floatData.fromfile(DataFH, (Columns*2)) > ?> > ?> ? ? ? ? ? ? position = 0 > ?> ? ? ? ? ? ? for CurrentColumn in range(Columns): > ?> > ?> ? ? ? ? ? ? ? ? ?self._realData[CurrentRow, CurrentColumn] ? ? ? ? ?= > ?> floatData[position] > ?> ? ? ? ? ? ? ? ? self._imaginaryData[CurrentRow, CurrentColumn] ?= > ?> floatData[position+1] > ?> ? ? ? ? ? ? ? ? position = position + 2 > ?> > ?> > ?> The above code works but is much too slow. If I comment out the body > ?> of the "for CurrentColumn in range(Columns)" loop, the performance is > ?> perfectly adequate i.e. function call overhead associated with the > ?> "fromfile(...)" call is not very bad at all. What seems to be most > ?> time-consuming are the simple assignment statements in the > ?> "CurrentColumn" for-loop. > ?> > [snip] > Try array slicing. floatData[0::2] will return the real parts and > floatData[1::2] will return the imaginary parts. You'll have to read up > how to assign to a slice of the numpy array (it might be > "self._realData[CurrentRow] = real_parts" or "self._realData[CurrentRow, > :] = real_parts"). > > BTW, it's not the function call overhead of fromfile() which takes the > time, but actually reading data from the file. Very nice! I like that! I'll post the improvement (if any). L From prologic at shortcircuit.net.au Thu Feb 5 18:16:47 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 6 Feb 2009 09:16:47 +1000 Subject: Is the subprocess module robust enough in 2.4? In-Reply-To: <20090205162059.CC9A8DB5569@montanaro.dyndns.org> References: <20090205162059.CC9A8DB5569@montanaro.dyndns.org> Message-ID: On Fri, Feb 6, 2009 at 2:20 AM, wrote: > The subprocess module was added in Python 2.4. I'm running 2.4.5 at work. > I know it's seen many bugfixes since first released. Is the version in 2.4 > robust enough to use in preference to os.popen and friends? "Is xxx rubust enough" is an untangible question. What you really -should- be doing is looking at the bug reports (as you've mentioned) and determine whether or not they will affect your use-case(s) in any way. cheers James From aahz at pythoncraft.com Thu Feb 5 18:27:46 2009 From: aahz at pythoncraft.com (Aahz) Date: 5 Feb 2009 15:27:46 -0800 Subject: Where to host a (Python) project? References: <387f23cd-90e2-46fc-8c91-1c2f6b31c89e@u13g2000yqg.googlegroups.com> <6dcb8ce5-c93e-458c-9047-e5db60f27d90@v18g2000pro.googlegroups.com> Message-ID: In article <6dcb8ce5-c93e-458c-9047-e5db60f27d90 at v18g2000pro.googlegroups.com>, andrew cooke wrote: >On Feb 1, 8:45=A0pm, a... at pythoncraft.com (Aahz) wrote: >> >> [...]=A0I for one won't participate in any list hosted on >> Google because of the need for a Google login. > >hi, just fyi, i investigated this and you can join any publicly >readable group by sending an email to the "-subscribe" address. you >do not need a google login for this and, as far as i can tell, it then >operates for you like a normal mailing list. > >for example, to subscribe to the group foo, you would send an email to >foo-subscribe at googlegroups.com. to unsubscribe, use foo- >unsubscribe at googlegroups.com. > >this isn't exactly well-publicised, but i tested it and it does work. The same thing is theoretically true for Yahoo groups, but I've heard from people over the years about various difficulties fixing problems with list subscriptions in the absence of a real Yahoo login and I'm not particularly interested in finding out that the same thing ends up being true for Google lists. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From lionel.keene at gmail.com Thu Feb 5 18:35:22 2009 From: lionel.keene at gmail.com (Lionel) Date: Thu, 5 Feb 2009 15:35:22 -0800 (PST) Subject: Skipping bytes while reading a binary file? References: <279bf987-8e3c-465d-a173-49b3d99a298a@s9g2000prg.googlegroups.com> <695d1efb-6144-4004-a4df-e387e26fa32f@p2g2000prf.googlegroups.com> Message-ID: <4e375a89-9a53-49d0-b604-6d43643fca08@x6g2000pre.googlegroups.com> On Feb 5, 2:56?pm, Lionel wrote: > On Feb 5, 2:48?pm, MRAB wrote: > > > > > > > Lionel wrote: > > > ?> Hello, > > ?> I have data stored in binary files. Some of these files are > > ?> huge...upwards of 2 gigs or more. They consist of 32-bit float complex > > ?> numbers where the first 32 bits of the file is the real component, the > > ?> second 32bits is the imaginary, the 3rd 32-bits is the real component > > ?> of the second number, etc. > > ?> > > ?> I'd like to be able to read in just the real components, load them > > ?> into a numpy.ndarray, then load the imaginary coponents and load them > > ?> into a numpy.ndarray. ?I need the real and imaginary components stored > > ?> in seperate arrays, they cannot be in a single array of complex > > ?> numbers except for temporarily. I'm trying to avoid temporary storage, > > ?> though, because of the size of the files. > > ?> > > ?> I'm currently reading the file scanline-by-scanline to extract rows of > > ?> complex numbers which I then loop over and load into the real/ > > ?> imaginary arrays as follows: > > ?> > > ?> > > ?> ? ? ? ? self._realData ? ? ? ? = numpy.empty((Rows, Columns), dtype = > > ?> numpy.float32) > > ?> ? ? ? ? self._imaginaryData = numpy.empty((Rows, Columns), dtype = > > ?> numpy.float32) > > ?> > > ?> ? ? ? ? floatData = array.array('f') > > ?> > > ?> ? ? ? ? for CurrentRow in range(Rows): > > ?> > > ?> ? ? ? ? ? ? floatData.fromfile(DataFH, (Columns*2)) > > ?> > > ?> ? ? ? ? ? ? position = 0 > > ?> ? ? ? ? ? ? for CurrentColumn in range(Columns): > > ?> > > ?> ? ? ? ? ? ? ? ? ?self._realData[CurrentRow, CurrentColumn] ? ? ? ? ?= > > ?> floatData[position] > > ?> ? ? ? ? ? ? ? ? self._imaginaryData[CurrentRow, CurrentColumn] ?= > > ?> floatData[position+1] > > ?> ? ? ? ? ? ? ? ? position = position + 2 > > ?> > > ?> > > ?> The above code works but is much too slow. If I comment out the body > > ?> of the "for CurrentColumn in range(Columns)" loop, the performance is > > ?> perfectly adequate i.e. function call overhead associated with the > > ?> "fromfile(...)" call is not very bad at all. What seems to be most > > ?> time-consuming are the simple assignment statements in the > > ?> "CurrentColumn" for-loop. > > ?> > > [snip] > > Try array slicing. floatData[0::2] will return the real parts and > > floatData[1::2] will return the imaginary parts. You'll have to read up > > how to assign to a slice of the numpy array (it might be > > "self._realData[CurrentRow] = real_parts" or "self._realData[CurrentRow, > > :] = real_parts"). > > > BTW, it's not the function call overhead of fromfile() which takes the > > time, but actually reading data from the file. > > Very nice! I like that! I'll post the improvement (if any). > > L- Hide quoted text - > > - Show quoted text - Okay, the following: self._realData[CurrentRow] = floatData[0::2] self._imaginaryData[CurrentRow] = floatData[1::2] gives a 3.5x improvement in execution speed over the original that I posted. That's much better. Thank you for the suggestion. L From travis+ml-python at subspacefield.org Thu Feb 5 18:38:26 2009 From: travis+ml-python at subspacefield.org (Travis) Date: Thu, 5 Feb 2009 17:38:26 -0600 Subject: updating nntplib In-Reply-To: <20090205224036.GH29170@subspacefield.org> References: <20090205224036.GH29170@subspacefield.org> Message-ID: <20090205233826.GI29170@subspacefield.org> On Thu, Feb 05, 2009 at 04:40:36PM -0600, Travis wrote: > 2) In some cases, it will bomb out upon receiving certain greetings > that it doesn't expect. As I understand it, it actually terminates > the connection, not allowing for catching an exception or anything. > I have not verified this myself. I just verified this; if the server responds to authentication with the string "200 Welcome feeder", then nntplib bombs out with a: nntplib.NNTPPermanentError IMHO, it shouldn't be sensitive to anything but the numeric code, and 200 indicates success. -- Crypto ergo sum. http://www.subspacefield.org/~travis/ Do unto other faiths as you would have them do unto yours. If you are a spammer, please email john at subspacefield.org to get blacklisted. From bthate at gmail.com Thu Feb 5 18:50:50 2009 From: bthate at gmail.com (Bart Thate) Date: Thu, 5 Feb 2009 15:50:50 -0800 (PST) Subject: GOZERBOT 0.9 RELEASED Message-ID: <4128ec68-e489-4236-8930-45a196244e3c@p36g2000prp.googlegroups.com> Finally gozerbot 0.9 has been released. This is a huge step forward to version 1.0 and contains a number of changes: * use json as the format to save data in instead of pickles * let config files also use json, this makes them more readable and human editable * remove popen usage from the bot core * remove execfile() calls from the bot core * rewrite the gozerbot package into several subpackages * use sqlaclhemy to provide database backend (sqlite3 is default) * require python2.5 * move most of the plugins into their own package * restructure the gozerdata layout so its more readable All these changes makes upgrading from older versions of gozerbot necessary so a gozerbot-upgrade program is provided (upgrading from 0.7 is not supported yet, will follow soon). See http://gozerbot.org on how to install gozerbot 0.9 About GOZERBOT: 0.9 Requirements * a shell * python 2.5 or higher * gnupg * simplejson * sqlalchemy * xmpppy Why gozerbot? * provide both IRC and Jabber support * user management by userhost .. bot will not respond if it doesn't know you (see USER) * fleet .. use more than one bot in a program (list of bots) (see FLEET) * use the bot through dcc chat * fetch rss feeds (see RSS) * remember items * relaying between bots (see RELAY) * program your own plugins (see PROGRAMPLUGIN) * query other bots with json REST (see CLOUD) * serve as a udp <-> irc or jabber notification bot (see UDP * sqlalchemy support Bart From lionel.keene at gmail.com Thu Feb 5 18:51:07 2009 From: lionel.keene at gmail.com (Lionel) Date: Thu, 5 Feb 2009 15:51:07 -0800 (PST) Subject: Skipping bytes while reading a binary file? References: <279bf987-8e3c-465d-a173-49b3d99a298a@s9g2000prg.googlegroups.com> <695d1efb-6144-4004-a4df-e387e26fa32f@p2g2000prf.googlegroups.com> <4e375a89-9a53-49d0-b604-6d43643fca08@x6g2000pre.googlegroups.com> Message-ID: <471af752-fd37-41a8-8f07-c36e1eecb829@f40g2000pri.googlegroups.com> On Feb 5, 3:35?pm, Lionel wrote: > On Feb 5, 2:56?pm, Lionel wrote: > > > > > > > On Feb 5, 2:48?pm, MRAB wrote: > > > > Lionel wrote: > > > > ?> Hello, > > > ?> I have data stored in binary files. Some of these files are > > > ?> huge...upwards of 2 gigs or more. They consist of 32-bit float complex > > > ?> numbers where the first 32 bits of the file is the real component, the > > > ?> second 32bits is the imaginary, the 3rd 32-bits is the real component > > > ?> of the second number, etc. > > > ?> > > > ?> I'd like to be able to read in just the real components, load them > > > ?> into a numpy.ndarray, then load the imaginary coponents and load them > > > ?> into a numpy.ndarray. ?I need the real and imaginary components stored > > > ?> in seperate arrays, they cannot be in a single array of complex > > > ?> numbers except for temporarily. I'm trying to avoid temporary storage, > > > ?> though, because of the size of the files. > > > ?> > > > ?> I'm currently reading the file scanline-by-scanline to extract rows of > > > ?> complex numbers which I then loop over and load into the real/ > > > ?> imaginary arrays as follows: > > > ?> > > > ?> > > > ?> ? ? ? ? self._realData ? ? ? ? = numpy.empty((Rows, Columns), dtype = > > > ?> numpy.float32) > > > ?> ? ? ? ? self._imaginaryData = numpy.empty((Rows, Columns), dtype = > > > ?> numpy.float32) > > > ?> > > > ?> ? ? ? ? floatData = array.array('f') > > > ?> > > > ?> ? ? ? ? for CurrentRow in range(Rows): > > > ?> > > > ?> ? ? ? ? ? ? floatData.fromfile(DataFH, (Columns*2)) > > > ?> > > > ?> ? ? ? ? ? ? position = 0 > > > ?> ? ? ? ? ? ? for CurrentColumn in range(Columns): > > > ?> > > > ?> ? ? ? ? ? ? ? ? ?self._realData[CurrentRow, CurrentColumn] ? ? ? ? ?= > > > ?> floatData[position] > > > ?> ? ? ? ? ? ? ? ? self._imaginaryData[CurrentRow, CurrentColumn] ?= > > > ?> floatData[position+1] > > > ?> ? ? ? ? ? ? ? ? position = position + 2 > > > ?> > > > ?> > > > ?> The above code works but is much too slow. If I comment out the body > > > ?> of the "for CurrentColumn in range(Columns)" loop, the performance is > > > ?> perfectly adequate i.e. function call overhead associated with the > > > ?> "fromfile(...)" call is not very bad at all. What seems to be most > > > ?> time-consuming are the simple assignment statements in the > > > ?> "CurrentColumn" for-loop. > > > ?> > > > [snip] > > > Try array slicing. floatData[0::2] will return the real parts and > > > floatData[1::2] will return the imaginary parts. You'll have to read up > > > how to assign to a slice of the numpy array (it might be > > > "self._realData[CurrentRow] = real_parts" or "self._realData[CurrentRow, > > > :] = real_parts"). > > > > BTW, it's not the function call overhead of fromfile() which takes the > > > time, but actually reading data from the file. > > > Very nice! I like that! I'll post the improvement (if any). > > > L- Hide quoted text - > > > - Show quoted text - > > Okay, the following: > > ? ? ? ? ? ? self._realData[CurrentRow] ? ? ?= floatData[0::2] > ? ? ? ? ? ? self._imaginaryData[CurrentRow] = floatData[1::2] > > gives a 3.5x improvement in execution speed over the original that I > posted. That's much better. Thank you for the suggestion. > > L- Hide quoted text - > > - Show quoted text - Correction: improvement is around 7-8x. From tjreedy at udel.edu Thu Feb 5 19:07:02 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 05 Feb 2009 19:07:02 -0500 Subject: Is c.l.py becoming less friendly? In-Reply-To: <1b50521f-b33b-4e3e-9a3e-65e8eb2f7242@v18g2000pro.googlegroups.com> References: <1b50521f-b33b-4e3e-9a3e-65e8eb2f7242@v18g2000pro.googlegroups.com> Message-ID: Mensanator wrote: > On Feb 5, 4:20 pm, Terry Reedy wrote: >> mk wrote: >> >>> (duck) >>> 542 comp.lang.python rtfm >> What is so unfriendly about 'read the fine manual'? > > You've seen a fine manual? Yes, and I and others have spent hours and hours making the Python manuals finer. From orlenko at gmail.com Thu Feb 5 19:37:18 2009 From: orlenko at gmail.com (Volodya) Date: Thu, 5 Feb 2009 16:37:18 -0800 (PST) Subject: Using multiprocessing from a Windows service Message-ID: <0e4d6033-a130-4c19-b648-6bcef8bfc922@u18g2000pro.googlegroups.com> Hi all, I think I've found a small bug with multiprocessing package on Windows. If you try to start a multiprocessing.Process from a Python- based Windows service, the child process will fail to run. When running the parent process as a regular Python program, everything works as expected. I've tracked the problem down to how main_path is prepared in multiprocessing.forking.get_preparation_data() (lines 370-377): def get_preparation_data(name): [...skipped a few lines...] if not WINEXE: main_path = getattr(sys.modules['__main__'], '__file__', None) if not main_path and sys.argv[0] not in ('', '-c'): main_path = sys.argv[0] if main_path is not None: if not os.path.isabs(main_path) and \ process.ORIGINAL_DIR is not None: main_path = os.path.join(process.ORIGINAL_DIR, main_path) d['main_path'] = os.path.normpath(main_path) return d When the program is running as a Windows service, but is not packaged into a single executable, main_path will become the path to the service executable (typically, pythonservice.exe). When this data makes it to the child process, the prepare() function will treat main_path as a path to a python module, and will try to import it. This causes it to fail. My quick-and-dirty solution was to check in get_preparation_data() if main_path ends with '.exe', and if it does, to not pass it at all. This solves the problem in my case, but perhaps there's a better way to fix this? Here is my version of get_preparation_data(): def get_preparation_data(name): ''' Return info about parent needed by child to unpickle process object ''' from .util import _logger, _log_to_stderr d = dict( name=name, sys_path=sys.path, sys_argv=sys.argv, log_to_stderr=_log_to_stderr, orig_dir=process.ORIGINAL_DIR, authkey=process.current_process().authkey, ) if _logger is not None: d['log_level'] = _logger.getEffectiveLevel() if not WINEXE: main_path = getattr(sys.modules['__main__'], '__file__', None) if not main_path and sys.argv[0] not in ('', '-c'): main_path = sys.argv[0] if main_path is not None: if not os.path.isabs(main_path) and \ process.ORIGINAL_DIR is not None: main_path = os.path.join(process.ORIGINAL_DIR, main_path) if not main_path.endswith('.exe'): d['main_path'] = os.path.normpath(main_path) return d From matzke at berkeley.edu Thu Feb 5 19:48:09 2009 From: matzke at berkeley.edu (Nick Matzke) Date: Thu, 05 Feb 2009 16:48:09 -0800 Subject: global name 'sqrt' is not defined In-Reply-To: <6v126hFhj1beU1@mid.uni-berlin.de> References: <498AAC89.5080002@berkeley.edu> <5rSdnfi3VIPQlhbUnZ2dnUVZ_r3inZ2d@pdx.net> <6v126hFhj1beU1@mid.uni-berlin.de> Message-ID: <498B88C9.4010602@berkeley.edu> OK, so the problem was that I had to exit ipython, re-enter it, and then import my module to get the errors to disappear. Thanks for the help! (PS: Is there a way to force a complete reload of a module, without exiting ipython? Just doing the import command again doesn't seem to do it.) Thanks! Nick Diez B. Roggisch wrote: > Nick Matzke schrieb: >> >> >> Scott David Daniels wrote: >>> M.-A. Lemburg wrote: >>>> On 2009-02-05 10:08, Nick Matzke wrote: >>>>> ..., I can run this in the ipython shell just fine: >>>>> a = ["12", "15", "16", "38.2"] >>>>> dim = int(sqrt(size(a))) >>>>> ...But if I move these commands to a function in another file, it >>>>> freaks out: >>>> You need to add: >>>> >>>> from math import sqrt >>> or: >>> from cmath import sqrt >>> or: >>> from numpy import sqrt >> >> >> >> >> >> The weird thing is, when I do this, I still get the error: >> >> ============ >> nick at mws2[phylocom]|27> a = ["12", "15", "16", "38.2"] >> nick at mws2[phylocom]|28> from LR_run_functions_v2 import >> make_half_square_array >> nick at mws2[phylocom]|24> d = make_half_square_array(a) >> --------------------------------------------------------------------------- >> >> NameError Traceback (most recent call >> last) >> >> /bioinformatics/phylocom/ in () >> >> /bioinformatics/phylocom/_scripts/LR_run_functions_v2.py in >> make_half_square_array(linear_version_of_square_array) >> 1548 from numpy import sqrt >> 1549 a = linear_version_of_square_array >> -> 1550 dim = int(sqrt(size(a))) >> 1551 >> 1552 >> >> NameError: global name 'sqrt' is not defined >> nick at mws2[phylocom]|25> >> ============ >> >> Is there some other place I should put the import command? I.e.: >> 1. In the main script/ipython command line >> >> 2. In the called function, i.e. make_half_square_array() in >> LR_run_functions_v2.py >> >> 3. At the top of LR_run_functions_v2.py, outside of the individual >> functions? > > The latter. Python's imports are always local to the module/file they > are in, not globally effective. > > > Diez > -- > http://mail.python.org/mailman/listinfo/python-list > -- ==================================================== Nicholas J. Matzke Ph.D. student, Graduate Student Researcher Huelsenbeck Lab Center for Theoretical Evolutionary Genomics 4151 VLSB (Valley Life Sciences Building) Department of Integrative Biology University of California, Berkeley Lab websites: http://ib.berkeley.edu/people/lab_detail.php?lab=54 http://fisher.berkeley.edu/cteg/hlab.html Dept. personal page: http://ib.berkeley.edu/people/students/person_detail.php?person=370 Lab personal page: http://fisher.berkeley.edu/cteg/members/matzke.html Lab phone: 510-643-6299 Dept. fax: 510-643-6264 Cell phone: 510-301-0179 Email: matzke at berkeley.edu Mailing address: Department of Integrative Biology 3060 VLSB #3140 Berkeley, CA 94720-3140 ----------------------------------------------------- "[W]hen people thought the earth was flat, they were wrong. When people thought the earth was spherical, they were wrong. But if you think that thinking the earth is spherical is just as wrong as thinking the earth is flat, then your view is wronger than both of them put together." Isaac Asimov (1989). "The Relativity of Wrong." The Skeptical Inquirer, 14(1), 35-44. Fall 1989. http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm ==================================================== From skippy.hammond at gmail.com Thu Feb 5 19:48:45 2009 From: skippy.hammond at gmail.com (Mark Hammond) Date: Fri, 06 Feb 2009 11:48:45 +1100 Subject: subprocess returncode windows In-Reply-To: <851774bd-5019-4347-8815-36782dcec4b6@p2g2000prf.googlegroups.com> References: <18348eae-5af1-47e9-a198-b95d4fcb6eac@a12g2000pro.googlegroups.com> <851774bd-5019-4347-8815-36782dcec4b6@p2g2000prf.googlegroups.com> Message-ID: <498B88ED.3060100@gmail.com> On 6/02/2009 6:34 AM, Andrew wrote: > Notice how python never gets the correct returncode from asadmin.bat > but I can get the correct returncode from the shell every time. Can > anyone tell me why Python wouldn't be able to get the correct > returncode for asadmin? I think the problem will be that cmd.exe doesn't return the exit code to *its* caller correctly. You can often work around this by avoiding the use of cmd.exe to spawn the child process, but obviously you do need it with a .bat file. I'm not aware of an easy work-around. Cheers, Mark From bignose+hates-spam at benfinney.id.au Thu Feb 5 19:55:17 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Fri, 06 Feb 2009 11:55:17 +1100 Subject: Where to host a (Python) project? References: <387f23cd-90e2-46fc-8c91-1c2f6b31c89e@u13g2000yqg.googlegroups.com> <6dcb8ce5-c93e-458c-9047-e5db60f27d90@v18g2000pro.googlegroups.com> Message-ID: <87bptgxu2y.fsf@benfinney.id.au> aahz at pythoncraft.com (Aahz) writes: > In article <6dcb8ce5-c93e-458c-9047-e5db60f27d90 at v18g2000pro.googlegroups.com>, > andrew cooke wrote: > >hi, just fyi, i investigated this and you can join any publicly > >readable group by sending an email to the "-subscribe" address. you > >do not need a google login for this and, as far as i can tell, it > >then operates for you like a normal mailing list. > > The same thing is theoretically true for Yahoo groups, but I've > heard from people over the years about various difficulties fixing > problems with list subscriptions in the absence of a real Yahoo > login and I'm not particularly interested in finding out that the > same thing ends up being true for Google lists. Indeed it does. I have succeeded in subscribing to Google mailing lists in the absence of a Google account, but *managing* that subscription thereafter in the absence of a Google account is obnoxiously difficult. Your caution is well advised. -- \ ?I got fired from my job the other day. They said my | `\ personality was weird. ? That's okay, I have four more.? | _o__) ?Bug-Eyed Earl, _Red Meat_ | Ben Finney From prologic at shortcircuit.net.au Thu Feb 5 19:55:19 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 6 Feb 2009 10:55:19 +1000 Subject: global name 'sqrt' is not defined In-Reply-To: <498B88C9.4010602@berkeley.edu> References: <498AAC89.5080002@berkeley.edu> <5rSdnfi3VIPQlhbUnZ2dnUVZ_r3inZ2d@pdx.net> <6v126hFhj1beU1@mid.uni-berlin.de> <498B88C9.4010602@berkeley.edu> Message-ID: On Fri, Feb 6, 2009 at 10:48 AM, Nick Matzke wrote: > (PS: Is there a way to force a complete reload of a module, without exiting > ipython? Just doing the import command again doesn't seem to do it.) m = __import__("mymobile") reload(m) cheers James From rhodri at wildebst.demon.co.uk Thu Feb 5 19:57:05 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 06 Feb 2009 00:57:05 -0000 Subject: where clause In-Reply-To: References: Message-ID: On Thu, 05 Feb 2009 18:04:35 -0000, wrote: > p = a / b > where > a = 20 / len(c) > b = foo(d) You'd want to do it with paired keywords, in the manner of try/except, to avoid utterly breaking Python's syntax conventions. Perhaps something like this: do: p = a / b where: a = 20 / len(c) b = foo(d) or even: where: a = 20 / len(c) b = foo(d) do: p = a / b Effectively you're creating a little local namespace for temporary variables. I'm not sure it buys you a lot, even as sugar, and I'm really not convinced by the bypartite form, but it's definitely possible. -- Rhodri James *-* Wildebeeste Herder to the Masses From robert.kern at gmail.com Thu Feb 5 20:01:14 2009 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 05 Feb 2009 19:01:14 -0600 Subject: global name 'sqrt' is not defined In-Reply-To: References: <498AAC89.5080002@berkeley.edu> <5rSdnfi3VIPQlhbUnZ2dnUVZ_r3inZ2d@pdx.net> <6v126hFhj1beU1@mid.uni-berlin.de> <498B88C9.4010602@berkeley.edu> Message-ID: On 2009-02-05 18:55, James Mills wrote: > On Fri, Feb 6, 2009 at 10:48 AM, Nick Matzke wrote: >> (PS: Is there a way to force a complete reload of a module, without exiting >> ipython? Just doing the import command again doesn't seem to do it.) > > m = __import__("mymobile") > reload(m) Or more straightforwardly: import mymobile reload(mymobile) If you have done from mymobile import * anywhere, you will need to re-execute that line again. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From rhodri at wildebst.demon.co.uk Thu Feb 5 20:03:56 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 06 Feb 2009 01:03:56 -0000 Subject: Use list name as string In-Reply-To: <77e831100902041932h502dea32s66a4aacaf247790a@mail.gmail.com> References: <77e831100902040824q2a0b8465k4894f29ed4baba12@mail.gmail.com> <4989C6D0.2000604@tim.thechases.com> <77e831100902040857q2379bf80hc05b5575cba85bdd@mail.gmail.com> <4989CB47.3060806@mrabarnett.plus.com> <77e831100902040918j4be325d3y760120c92f8a0d7f@mail.gmail.com> <77e831100902040923k188e5df3q22423884f239e5a5@mail.gmail.com> <77e831100902041736w5194b59dubdd922c80dd82ece@mail.gmail.com> <77e831100902041932h502dea32s66a4aacaf247790a@mail.gmail.com> Message-ID: On Thu, 05 Feb 2009 03:32:59 -0000, Vincent Davis wrote: > "The problem is you seem to be thinking in terms of objects having names. > They don't. Names have objects."I agree this is my problem. This is not > correct terminology then? > The name of the object is anobject No. The name of the object is a name. It doesn't really exist as an object at all. As others have said, if you really want this information you'll need to write your own class with a "name" attribute, and assign a suitable string to it. -- Rhodri James *-* Wildebeeste Herder to the Masses From conradwt at gmail.com Thu Feb 5 20:29:29 2009 From: conradwt at gmail.com (Con) Date: Thu, 5 Feb 2009 17:29:29 -0800 (PST) Subject: MacPython 3.0 dmg installer? Message-ID: Hi, I was wondering, what's the status of the MacPython 3.0 installer (.i.e. dmg file) ? I have been using the previous MacPython dmg installers with great success without conflicting with other installations on the system. Thanks in advance, -Conrad From todpose at hotmail.com Thu Feb 5 20:43:30 2009 From: todpose at hotmail.com (todpose at hotmail.com) Date: Thu, 5 Feb 2009 17:43:30 -0800 Subject: Converting numbers to words Message-ID: I've been trying to figure this out for over 2 hours and I'm really frustrated right now.I first made Python to ask user to input height in meters. If user puts certain value in meter, then it converts it to feet and inches as follows: Enter the height (in metres): 1.6It is 5 feet, 3 inches high. What I want to do is to make it type only words. For example, instead of its saying, "It is 5 feet, 3 inches high," I want it to say, "it is five feet, three inches high."I'd appreciate any suggestions. _________________________________________________________________ Twice the fun?Share photos while you chat with Windows Live Messenger. http://www.microsoft.com/windows/windowslive/messenger.aspx -------------- next part -------------- An HTML attachment was scrubbed... URL: From aaron.watters at gmail.com Thu Feb 5 20:53:52 2009 From: aaron.watters at gmail.com (Aaron Watters) Date: Thu, 5 Feb 2009 17:53:52 -0800 (PST) Subject: ANN: Nucular full text indexing 0.4 Message-ID: <1eb08437-e2d2-4938-95ed-8ee4930e598c@g1g2000pra.googlegroups.com> ANNOUNCING NUCULAR 0.4 ====================== This release adds a simple "table space" wrapper which makes Nucular easier to use for some purposes. It also fixes a number of bugs. WHERE IS IT? Find documentation and downloads at http://nucular.sourceforge.net/ WHAT IS IT? Nucular is a system for creating full text indices for fielded data. It can be accessed via a Python API or via a suite of command line interfaces. Nucular archives fielded documents and retrieves them based on field value, field prefix, field word prefix, or full text word prefix, word proximity or combinations of these. Nucular also includes features for determining values related to a query often called query facets. FEATURES * Nucular is very light weight. Updates and accesses do not require any server process or other system support such as shared memory locking. * Nucular supports concurrency. Arbitrary concurrent updates and accesses by multiple processes or threads are supported, with no possible locking issues. * Nucular indexes and retrieves data quickly. * Nucular has a funny name. NOTES The file storage format for this release is not compatible with older formats (the change was needed to fix a bug). On Windows XP I had to delete the old package manually from the Python library before the install for the new package would work properly. I hope you like it. -- Aaron Watters === Fear has several advantages over gratitude. Gratitude is intrinsically limited, if only by the finite creative capacity of the scientific community. Moreover, as pointed out by a colleague at MIT, appealing to people?s gratitude and trust is usually less effective than pulling a gun. -- Richard Lindzen From ianare at gmail.com Thu Feb 5 21:34:05 2009 From: ianare at gmail.com (=?ISO-8859-1?B?aWFuYXLp?=) Date: Thu, 5 Feb 2009 18:34:05 -0800 (PST) Subject: sorting for recursive folder rename References: Message-ID: On Dec 16 2008, 7:36?pm, "Rhodri James" wrote: > On Tue, 16 Dec 2008 18:20:52 -0000, ianar? wrote: > > Hello all, > > > I trying to recursivelyrenamefolders and files, and am looking for > > some ideas on the best way of doing this. The problem is that the > > given list of items can be in order, and one to all items may be > > renamed. Here is some preliminary code I have, but which does not work > > very well. self.toRename has the following structure : [ [original_name, new_name, os.path.isdir] .. ] # define these here for faster processing def split(item): return os.path.split(item) def addSep(path): return os.sep + path + os.sep def recursiveFolderSort(x,y): return cmp(y[0], x[0]) sortedRename = sorted(self.toRename) # make a list of all folders that will be processed foldersToAdjust = [] for item in sortedRename: if item[2] is False: oF = split(item[0])[1] # original folder name nF = split(item[1])[1] # new folder name if oF is not nF: foldersToAdjust.append((oF, nF)) # replace all occurences of folders in path for i in range(len(self.toRename)): for f in foldersToAdjust: oF = addSep(f[0]) # original folder name nF = addSep(f[1]) # new folder name self.toRename[i][0] = self.toRename[i][0].replace(oF,nF) self.toRename[i][1] = self.toRename[i][1].replace(oF,nF) if progressDialog.update(i) is False: error = 'cancelled' break # make sure renaming will be in correct order ! self.toRename.sort(recursiveFolderSort) > import os > > for item in self.toRename: > ? ? ?os.renames(item[0], item[1]) > > That's it. ?os.renames will take care of all the intermediate > directory creation so you don't even need to sort the list. > > -- > Rhodri James *-* Wildebeeste Herder to the Masses It's been a while since I decided to work on this again ... Anyway, if only it were that easy !! Traceback (most recent call last): File "/home/ianare/Desktop/file-folder-ren/metamorphose2/Source/ MainWindow.py", line 1477, in renameItems os.renames(original[0], renamed[0]) File "/usr/lib/python2.5/os.py", line 213, in renames rename(old, new) OSError: [Errno 2] No such file or directory The problem is that if a directory is changed, all lower instances need to be changed as well. given the following directory structure ... recursive | |_1 | |_1 | | |_1.txt | | |_2.txt | |_2 | |_1.txt | |_2.txt |_2 |_1 | |_1.txt | |_2.txt |_2 |_1.txt |_2.txt ... and assuming I want to change : recursive/2/2/2.txt --> recursive/2/2/14.txt but, I ALSO want to change : recursive/2 --> recursive/04 it means that the first operation is really : recursive/04/2/2.txt --> recursive/04/2/14.txt os.renames will work, but it needs to have the correct path, so it comes down to the same thing. IOW, I need a way of : A) adjusting paths taking into consideration all changes up and down the tree B) sorting normalized paths so they are renamed in the proper sequence (depends on point 'A', obviously) I'm pretty sure I can take care of 'B' with the following sorting method: # order by path depth def recursiveFolderSort(x, y): x = x[0].count(os.sep) y = y[0].count(os.sep) return cmp(x, y) self.toRename.sort(recursiveFolderSort) but I still need a way of generating the correct names. Solution finder will have his/her name placed on the credits page. http://file-folder-ren.sourceforge.net/index.php?page=Links Thanks in advance !! From benjamin at python.org Thu Feb 5 21:41:21 2009 From: benjamin at python.org (Benjamin Peterson) Date: Fri, 6 Feb 2009 02:41:21 +0000 (UTC) Subject: MacPython 3.0 dmg installer? References: Message-ID: Con gmail.com> writes: > > Hi, I was wondering, what's the status of the MacPython 3.0 installer > (.i.e. dmg file) ? I have been using the previous MacPython dmg > installers with great success without conflicting with other > installations on the system. There should be ones for 3.0.1 which is coming out within the next few weeks. From steve at holdenweb.com Thu Feb 5 21:42:25 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 05 Feb 2009 21:42:25 -0500 Subject: Converting numbers to words In-Reply-To: References: Message-ID: todpose at hotmail.com wrote: > I've been trying to figure this out for over 2 hours and I'm really > frustrated right now. > > I first made Python to ask user to input height in meters. If user puts > certain value in meter, then it converts it to feet and inches as follows: > > > Enter the height (in metres): 1.6 > > It is 5 feet, 3 inches high. > > > What I want to do is to make it type only words. For example, instead of > its saying, "It is 5 feet, 3 inches high," I want it to say, "it is five > feet, three inches high." > I'd appreciate any suggestions. Create a list or tuple of strings, and use the numbers to index the list. lst = ['a', 'b', 'c'] ndx = 1 print "The letter", lst[ndx], "is number one" regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From benjamin at python.org Thu Feb 5 21:44:20 2009 From: benjamin at python.org (Benjamin Peterson) Date: Fri, 6 Feb 2009 02:44:20 +0000 (UTC) Subject: Flattening lists References: <498AE81E.6020100@aim.com> <498B0F8B.8090109@aim.com> Message-ID: mk gmail.com> writes: > Hmm, I'm surprised by even that! Apparently list creation is more > expensive than I thought - it seems somewhat more expensive than the > cost of interpreting bytecode for "if var is None". Either list creation > is somewhat costly, or "if var is None" is really cheap. Creating a list requires several function calls on the C level (including the dictionary lookup for the name "list") and memory allocation, which is usually quite expensive. In contrast, the eval loop for "is None" basically uses a pointer comparison. From vincent at vincentdavis.net Thu Feb 5 22:03:01 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Thu, 5 Feb 2009 20:03:01 -0700 Subject: return multiple objects Message-ID: <77e831100902051903x5a347591k74e69ca3da947d3d@mail.gmail.com> Is it correct that if I want to return multiple objects from a function I need to in some way combine them? def test1(): a = [1,3,5,7] b = [2,4,6,8] c=[a,b] return a, b # this does not work? return [a, b] # does not work? return c # this works but I don't like it, , is there a better way? I saw examples where dictionaries where used but I would prefer to just access the object names directly. As in test1() print a # not haing to refer to it as is there something I am missing? Thanks Vincent Davis -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Thu Feb 5 22:06:55 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 5 Feb 2009 19:06:55 -0800 Subject: return multiple objects In-Reply-To: <77e831100902051903x5a347591k74e69ca3da947d3d@mail.gmail.com> References: <77e831100902051903x5a347591k74e69ca3da947d3d@mail.gmail.com> Message-ID: <50697b2c0902051906r30bf26ck2ce914cf74e7aa88@mail.gmail.com> On Thu, Feb 5, 2009 at 7:03 PM, Vincent Davis wrote: > Is it correct that if I want to return multiple objects from a function I > need to in some way combine them? > def test1(): > a = [1,3,5,7] > b = [2,4,6,8] > c=[a,b] > return a, b # this does not work? > return [a, b] # does not work? > return c # this works but I don't like it, , is there a better way? All 3 of those *do work* just fine. I suspect you happen to not be familiar with how to retrieve the multiple results. Here's how: q, w = test1() print q # prints [1,3,5,7] print w # prints [2,4,6,8] Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From gagsl-py2 at yahoo.com.ar Thu Feb 5 22:17:01 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 06 Feb 2009 01:17:01 -0200 Subject: subprocess returncode windows References: <18348eae-5af1-47e9-a198-b95d4fcb6eac@a12g2000pro.googlegroups.com> <851774bd-5019-4347-8815-36782dcec4b6@p2g2000prf.googlegroups.com> Message-ID: En Thu, 05 Feb 2009 17:34:29 -0200, Andrew escribi?: > On Dec 16 2008, 5:11?pm, "Gabriel Genellina" > wrote: >> En Tue, 16 Dec 2008 17:21:35 -0200, Andrew ? >> escribi?: >> >> >> >> > On Dec 16, 12:50?pm, Christian Heimes wrote: >> >> Andrew schrieb: >> >> >> > I'm running into a strange situation with getting incorrect >> >> > returncodes / exit status from python subprocess.call. I'm using a >> >> > python script (runtime 2.6.1 on windows) to automate the deploy of >> >> > java applications to glassfish application server. Below is an >> >> > example > I've tried this several ways now. It seems to be something specific > with python and asadmin.bat. > > I've tried the following manually in the cmd.exe prompt: [examples showing %ERRORLEVEL% correctly set when running from the command line, but subprocess.call doesn't get it] > Notice how python never gets the correct returncode from asadmin.bat > but I can get the correct returncode from the shell every time. Can > anyone tell me why Python wouldn't be able to get the correct > returncode for asadmin? The last exit code set by a command *should* propagate as the exit code of the whole .bat, then as the exit code of the cmd.exe instance that runs it, and finally Python *should* receive that value. Some old Windows versions didn't behave like that, but AFAIK XP does the right thing here. Unless asadmin.bat is playing tricks with %ERRORLEVEL% or something. Can you post the contents of asadmin.bat? Without looking into it, I can think of a few alternatives: - rewrite asadmin.bat in Python, if feasible. Some scripts just check/set a few environment variables and execute some process at the end, and that's all; in this case it should be easy to emulate the same thing in Python. - try using another layer of your own, e.g., my_asadmin.bat: call asadmin.bat %* exit /b %ERRORLEVEL% - variation: write the exit code somewhere: call asadmin.bat %* echo %ERRORLEVEL% > asadmin.err and read asadmin.err from Python. (I've used something like this in a chain Win32 process --> 16 bits GUI application --> .bat script --> old DOS executable) -- Gabriel Genellina From BrianVanderburg2 at aim.com Thu Feb 5 22:20:35 2009 From: BrianVanderburg2 at aim.com (Brian Allen Vanderburg II) Date: Thu, 05 Feb 2009 22:20:35 -0500 Subject: Converting numbers to words In-Reply-To: References: Message-ID: <498BAC83.8090403@aim.com> todpose at hotmail.com wrote: > > I've been trying to figure this out for over 2 hours and I'm really frustrated right now. > > I first made Python to ask user to input height in meters. If user puts certain value in meter, then it converts it to feet and inches as follows: > > > Enter the height (in metres): 1.6 > > It is 5 feet, 3 inches high. > > > What I want to do is to make it type only words. For example, instead of its saying, "It is 5 feet, 3 inches high," I want it to say, "it is five feet, three inches high." > I'd appreciate any suggestions. I made something similar in the past. First I break it into two functions, one function handles 0-999 and return '' for zero or a meaningful value for 999, another function handles how many groups there are and for each one, gets the value for it calls the first function, and appends the correct word. This only works for the English language though Brian Vanderburg II num_words1 = ("zero", # not used "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen") num_words2 = ("twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety") num_words3 = ("thousand", "million", "billion", "trillion", "quadrillion") def word_func1(value): # value can be from 0 to 999 result = '' if value == 0: return result # Handle hundreds if value >= 100: hvalue = int(value / 100) if result: result += ' ' result += num_words1[hvalue] result += ' hundred' value -= (hvalue * 100) if value == 0: return result # Handle 1-19 if value < 20: if result: result += ' ' result += num_words1[value] return result # Handle 10s (20-90) tvalue = int(value / 10) if result: result += ' ' result += num_words2[tvalue - 2] value -= (tvalue * 10) if value == 0: return result # Handle ones if result: result += ' ' result += num_words1[value] return result def word_func2(value): result = '' if value == 0: return 'zero' # Determine support values divider = 1 l = len(num_words3) for i in range(l): divider *= 1000 for i in range(l): if value >= divider: dvalue = int(value / divider) if result: result += ' ' result += word_func1(dvalue) result += ' ' result += num_words3[l - i - 1] value -= (dvalue * divider) divider /= 1000 if value > 0: if result: result += ' ' result += word_func1(value) return result number_to_word = word_func2 From rhodri at wildebst.demon.co.uk Thu Feb 5 22:37:24 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 06 Feb 2009 03:37:24 -0000 Subject: return multiple objects In-Reply-To: <77e831100902051903x5a347591k74e69ca3da947d3d@mail.gmail.com> References: <77e831100902051903x5a347591k74e69ca3da947d3d@mail.gmail.com> Message-ID: On Fri, 06 Feb 2009 03:03:01 -0000, Vincent Davis wrote: > Is it correct that if I want to return multiple objects from a function I > need to in some way combine them? > def test1(): > a = [1,3,5,7] > b = [2,4,6,8] > c=[a,b] > return a, b # this does not work? > return [a, b] # does not work? > return c # this works but I don't like it, , is there a better way? Strictly speaking, you can only return one object from a function. However, that one object can be a container (list, tuple, dict, set, or what have you) that contains multiple objects. Tuples are a popular choice: return a, b ...but almost any ordered type would do, because you can automagically unpack the results if you want to: x, y = test1() (You might be expecting brackets around the "a, b" and the "x, y", and you'd be sort of right. The brackets (parentheses) for tuples are optional, except for a couple of cases where you *have* to put them in to avoid ambiguity. I tend to put them in always, but leaving them out in cases like this seems to be normal practice.) -- Rhodri James *-* Wildebeeste Herder to the Masses From skippy.hammond at gmail.com Thu Feb 5 22:50:53 2009 From: skippy.hammond at gmail.com (Mark Hammond) Date: Fri, 06 Feb 2009 14:50:53 +1100 Subject: Using multiprocessing from a Windows service In-Reply-To: <0e4d6033-a130-4c19-b648-6bcef8bfc922@u18g2000pro.googlegroups.com> References: <0e4d6033-a130-4c19-b648-6bcef8bfc922@u18g2000pro.googlegroups.com> Message-ID: <498BB39D.5070809@gmail.com> On 6/02/2009 11:37 AM, Volodya wrote: > Hi all, > > I think I've found a small bug with multiprocessing package on > Windows. I'd actually argue its a bug in pythonservice.exe - it should set sys.argv[] to resemble a normal python process with argv[0] being the script. I'll fix it... Cheers, Mark From skippy.hammond at gmail.com Thu Feb 5 23:26:08 2009 From: skippy.hammond at gmail.com (Mark Hammond) Date: Fri, 06 Feb 2009 15:26:08 +1100 Subject: Using multiprocessing from a Windows service In-Reply-To: <498BB39D.5070809@gmail.com> References: <0e4d6033-a130-4c19-b648-6bcef8bfc922@u18g2000pro.googlegroups.com> <498BB39D.5070809@gmail.com> Message-ID: <498BBBE0.6090704@gmail.com> On 6/02/2009 2:50 PM, Mark Hammond wrote: > On 6/02/2009 11:37 AM, Volodya wrote: >> Hi all, >> >> I think I've found a small bug with multiprocessing package on >> Windows. > > I'd actually argue its a bug in pythonservice.exe - it should set > sys.argv[] to resemble a normal python process with argv[0] being the > script. I'll fix it... Actually it appears I spoke too soon: * A bug in pywin32 exists such that when you use 'debug' on a service, the argv reflected the full argv of the application, including the '-debug' portion of the command-line. However, even if that is fixed, the next argument is actually the name of the service (as declared in the .py file for the service), not the .py module itself. Thus, I could make argv a little more sane in this case, but still the initial problem would remain as argv[0] would still not be a .py file. * When the service is started by windows itself, there are usually zero additional command-line arguments. If there *are* arguments, they are likely to be the string the user entered via control panel as a special case (Windows doesn't actually remember service args - they are used once and discarded). It is important we continue to expose whatever argv we actually got from Windows to the service code. So unfortunately I don't think I can change pythonservice to resolve the issue you reported. Cheers, Mark From vincent at vincentdavis.net Thu Feb 5 23:29:49 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Thu, 5 Feb 2009 21:29:49 -0700 Subject: return multiple objects In-Reply-To: References: <77e831100902051903x5a347591k74e69ca3da947d3d@mail.gmail.com> Message-ID: <77e831100902052029id5b939cn605e1f9728cb01cf@mail.gmail.com> That is what I was missing, Thanks Vincent Davis On Thu, Feb 5, 2009 at 8:37 PM, Rhodri James wrote: > On Fri, 06 Feb 2009 03:03:01 -0000, Vincent Davis < > vincent at vincentdavis.net> wrote: > > Is it correct that if I want to return multiple objects from a function I >> need to in some way combine them? >> def test1(): >> a = [1,3,5,7] >> b = [2,4,6,8] >> c=[a,b] >> return a, b # this does not work? >> return [a, b] # does not work? >> return c # this works but I don't like it, , is there a better way? >> > > Strictly speaking, you can only return one object from a function. > However, > that one object can be a container (list, tuple, dict, set, or what have > you) that contains multiple objects. Tuples are a popular choice: > > return a, b > > ...but almost any ordered type would do, because you can automagically > unpack the results if you want to: > > x, y = test1() > > (You might be expecting brackets around the "a, b" and the "x, y", and > you'd be sort of right. The brackets (parentheses) for tuples are > optional, except for a couple of cases where you *have* to put them > in to avoid ambiguity. I tend to put them in always, but leaving them > out in cases like this seems to be normal practice.) > > -- > Rhodri James *-* Wildebeeste Herder to the Masses > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg at cosc.canterbury.ac.nz Thu Feb 5 23:56:51 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Fri, 06 Feb 2009 17:56:51 +1300 Subject: ANN: SuPy - Script Sketchup with Python Message-ID: SuPy 1.0 -------- SuPy is a plugin for the Sketchup 3D modelling application that lets you script it in Python. http://www.cosc.canterbury.ac.nz/SuPy/ This is a first version and is highly experimental. Let me know if it works for you and whether you have any problems. -- Greg Ewing greg.ewing at canterbury.ac.nz From orlenko at gmail.com Fri Feb 6 00:21:40 2009 From: orlenko at gmail.com (Volodymyr Orlenko) Date: Thu, 05 Feb 2009 21:21:40 -0800 Subject: Using multiprocessing from a Windows service In-Reply-To: <498BBBE0.6090704@gmail.com> References: <0e4d6033-a130-4c19-b648-6bcef8bfc922@u18g2000pro.googlegroups.com> <498BB39D.5070809@gmail.com> <498BBBE0.6090704@gmail.com> Message-ID: <498BC8E4.7000108@gmail.com> On 05/02/2009 8:26 PM, Mark Hammond wrote: > On 6/02/2009 2:50 PM, Mark Hammond wrote: >> On 6/02/2009 11:37 AM, Volodya wrote: >>> Hi all, >>> >>> I think I've found a small bug with multiprocessing package on >>> Windows. >> >> I'd actually argue its a bug in pythonservice.exe - it should set >> sys.argv[] to resemble a normal python process with argv[0] being the >> script. I'll fix it... > > Actually it appears I spoke too soon: > > * A bug in pywin32 exists such that when you use 'debug' on a service, > the argv reflected the full argv of the application, including the > '-debug' portion of the command-line. However, even if that is fixed, > the next argument is actually the name of the service (as declared in > the .py file for the service), not the .py module itself. Thus, I > could make argv a little more sane in this case, but still the initial > problem would remain as argv[0] would still not be a .py file. > > * When the service is started by windows itself, there are usually > zero additional command-line arguments. If there *are* arguments, > they are likely to be the string the user entered via control panel as > a special case (Windows doesn't actually remember service args - they > are used once and discarded). It is important we continue to expose > whatever argv we actually got from Windows to the service code. > > So unfortunately I don't think I can change pythonservice to resolve > the issue you reported. > Thanks Mark, this makes perfect sense. In the patch I submitted, I simply check if the name of the supposed module ends with ".exe". It works fine for my case, but maybe this is too general. Is there a chance that a Python module would end in ".exe"? If so, maybe we should check specifically for "pythonservice.exe". But then, if someone renames the executable (as I did, because I wanted to see meaningful service names in the process list), the patch will not work. Maybe there's another way to fix the forking module? From agile.scrapping3 at gmail.com Fri Feb 6 00:52:26 2009 From: agile.scrapping3 at gmail.com (agile) Date: Thu, 5 Feb 2009 21:52:26 -0800 (PST) Subject: What is difference between ADO and RDO Message-ID: <4941fd6f-b0ea-41f5-b39c-071b6a658f7c@e1g2000pra.googlegroups.com> Explain ADO and RDO From prologic at shortcircuit.net.au Fri Feb 6 00:54:16 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 6 Feb 2009 15:54:16 +1000 Subject: Using multiprocessing from a Windows service In-Reply-To: <498BC8E4.7000108@gmail.com> References: <0e4d6033-a130-4c19-b648-6bcef8bfc922@u18g2000pro.googlegroups.com> <498BB39D.5070809@gmail.com> <498BBBE0.6090704@gmail.com> <498BC8E4.7000108@gmail.com> Message-ID: On Fri, Feb 6, 2009 at 3:21 PM, Volodymyr Orlenko wrote: > In the patch I submitted, I simply check if the name of the supposed module > ends with ".exe". It works fine for my case, but maybe this is too general. > Is there a chance that a Python module would end in ".exe"? If so, maybe we > should check specifically for "pythonservice.exe". But then, if someone > renames the executable (as I did, because I wanted to see meaningful service > names in the process list), the patch will not work. Maybe there's another > way to fix the forking module? I believe the best way to fix this is to fix the underlying issue that Mark has pointed out (monkey-patching mp won't do). --JamesMills From mail at microcorp.co.za Fri Feb 6 00:57:28 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Fri, 6 Feb 2009 07:57:28 +0200 Subject: Is c.l.py becoming less friendly? References: <1b50521f-b33b-4e3e-9a3e-65e8eb2f7242@v18g2000pro.googlegroups.com> Message-ID: <007701c9881f$cb9875e0$0d00a8c0@hendrik> "Mensanator" >On Feb 5, 4:20 pm, Terry Reedy wrote: >> mk wrote: >> >> > (duck) >> >> > 542 comp.lang.python rtfm >> >> What is so unfriendly about 'read the fine manual'? > >You've seen a fine manual? Oh Fine! - Hendrik From clp2 at rebertia.com Fri Feb 6 01:02:16 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 5 Feb 2009 22:02:16 -0800 Subject: What is difference between ADO and RDO In-Reply-To: <4941fd6f-b0ea-41f5-b39c-071b6a658f7c@e1g2000pra.googlegroups.com> References: <4941fd6f-b0ea-41f5-b39c-071b6a658f7c@e1g2000pra.googlegroups.com> Message-ID: <50697b2c0902052202hc2e8101r58bf7d2378864705@mail.gmail.com> On Thu, Feb 5, 2009 at 9:52 PM, agile wrote: > Explain ADO and RDO Take 5 seconds to Google them and find their Wikipedia pages: http://en.wikipedia.org/wiki/Remote_Data_Objects http://en.wikipedia.org/wiki/ActiveX_Data_Objects Apparently they're 2 Microsoft technology acronyms -- and they're **completely irrelevant** to this mailinglist, which is about *Python*. My but your post is lazy, terse, and rude. Bye now, Chris -- Follow the path of the Iguana... http://rebertia.com From mail at microcorp.co.za Fri Feb 6 01:23:32 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Fri, 6 Feb 2009 08:23:32 +0200 Subject: Is c.l.py becoming less friendly? References: <1b50521f-b33b-4e3e-9a3e-65e8eb2f7242@v18g2000pro.googlegroups.com> Message-ID: <00bb01c98824$592b9b40$0d00a8c0@hendrik> "Steve Holden" wrote: > Yes, and I'm fine well sure this is somewhere between a silly thread and > a troll. "Fine" reads wrong - it should be fining. Silly? Us here on clp, silly? What a monstrous thought! I'll have you know this is a respectable establishment, and you should be grateful that such fine, serious folk suffer your impertinence without taking umbrage ! Ok Steve now it's your turn to tell me it does not scan. I think this thread has buggered up a perfectly good word for me - It will be difficult, in future, to hear the word without having to suppress an involuntary snigger. - Hendrik From r.warhekar at gmail.com Fri Feb 6 01:27:02 2009 From: r.warhekar at gmail.com (Rahul) Date: Thu, 5 Feb 2009 22:27:02 -0800 (PST) Subject: i have an query regarding pyodbc Message-ID: <4f9834b0-98cd-486c-b91e-a6cab4d8744f@b38g2000prf.googlegroups.com> hello all, I have installed pyodbc on my red hat enterprise 4 linux machine but when i go to use that using statement, import pyodbc through python console it gives me error as ImportError : dynamic module does not define init function (initpyodbc) and when i do 'nm pyodbc.so' command i get output as [root at dbserver site-packages]# nm pyodbc.so 00001600 A __bss_start 000003ec t call_gmon_start 00001600 b completed.1 000014fc d __CTOR_END__ 000014f8 d __CTOR_LIST__ w __cxa_finalize@@GLIBC_2.1.3 000004a8 t __do_global_ctors_aux 00000410 t __do_global_dtors_aux 000015f8 d __dso_handle 00001504 d __DTOR_END__ 00001500 d __DTOR_LIST__ 0000150c A _DYNAMIC 00001600 A _edata 00001604 A _end 000004d8 T _fini 0000046c t frame_dummy 000004f4 r __FRAME_END__ 000015e8 A _GLOBAL_OFFSET_TABLE_ w __gmon_start__ 000003b4 T _init 00001508 d __JCR_END__ 00001508 d __JCR_LIST__ w _Jv_RegisterClasses 000015fc d p.0 which means there is no init function. So what might be the cause for that? I have build that pyodbc twice. Any help regarding this will be greatly appreciated. Thanks & Regards Rahul From ths at arl.com.pk Fri Feb 6 01:34:53 2009 From: ths at arl.com.pk (Tehseen Siddiqui) Date: Fri, 06 Feb 2009 11:34:53 +0500 Subject: Python Power Point Slides Message-ID: <4041891322e2bf49ab400664bc811fae@121.100.100.103> ---------------------------------------------------------------------- DISCLAIMER: The information in this email is confidential and may be legally privileged. It is intended solely for the addressee. Access to this email by anyone else is unauthorized. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful. ARL cannot accept liability for any loss or damage sustained as a result of software viruses. ---------------------------------------------------------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: From aleksandr.goretoy at gmail.com Fri Feb 6 01:41:20 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Fri, 6 Feb 2009 00:41:20 -0600 Subject: reconstruct html form in pyGTK window and create dict from pyGTK Message-ID: Hello All, What would be the best way to fetch a form/s from a webpage and then recreate it in a pygtk window? I'm doing some research on this for a project called pynutbutter. This is for jellpy actually, which handles creating option mappings for pynutbutter from a GUI. The things I know I would need some examples on: How to work multiple glade files? (so i can have multiple pages for different types of options) more efficient way, is this a good option? loading of forms fields and reconstructiting in pyGTK with comboboxes/comboboxtextentry textboxes/textentry and textviews, not how to load them or display them...I can see that on pygtk website....but the more efficient way to do this dynamically. What is the best way to create a dict from a gui? just have a user type the dict: somedict={"some":thing} or have another window pop up that handles for name value pairs of the dict and a field for dict name. After all this what would be the best way for me to merge this dict into a options file. There will be other options in there. How would I only either prepend the new dict or if one with same name exists overwrite it. Would that be a safe move? What would be the most effiecient and user friendly way to contruct this on a form basis in a pyGTK GUI defaults = {"formfield":"somevalue","anotherfield":"somefieldvalue"} mappings = {"somefield":"filefield1","anotherfield":"some_function(filefield2)"} headers = {"filefield1":"somefield","filefield2":"anotherfield"} What would be the best way for me to construct this dict from a user friendly form in pyGTK.... Sorry this is alot of questions. Any advise on this matter will be greatly appreciated. Thank you. -Alex Goretoy http://www.alexgoretoy.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From aleksandr.goretoy at gmail.com Fri Feb 6 02:07:41 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Fri, 6 Feb 2009 01:07:41 -0600 Subject: Where to host a (Python) project? In-Reply-To: <87bptgxu2y.fsf@benfinney.id.au> References: <387f23cd-90e2-46fc-8c91-1c2f6b31c89e@u13g2000yqg.googlegroups.com> <6dcb8ce5-c93e-458c-9047-e5db60f27d90@v18g2000pro.googlegroups.com> <87bptgxu2y.fsf@benfinney.id.au> Message-ID: I use google code. http://code.google.com/p/pynutbutter -Alex Goretoy http://www.alexgoretoy.com On Thu, Feb 5, 2009 at 6:55 PM, Ben Finney < bignose+hates-spam at benfinney.id.au >wrote: > aahz at pythoncraft.com (Aahz) writes: > > > In article < > 6dcb8ce5-c93e-458c-9047-e5db60f27d90 at v18g2000pro.googlegroups.com>, > > andrew cooke wrote: > > >hi, just fyi, i investigated this and you can join any publicly > > >readable group by sending an email to the "-subscribe" address. you > > >do not need a google login for this and, as far as i can tell, it > > >then operates for you like a normal mailing list. > > > > The same thing is theoretically true for Yahoo groups, but I've > > heard from people over the years about various difficulties fixing > > problems with list subscriptions in the absence of a real Yahoo > > login and I'm not particularly interested in finding out that the > > same thing ends up being true for Google lists. > > Indeed it does. I have succeeded in subscribing to Google mailing > lists in the absence of a Google account, but *managing* that > subscription thereafter in the absence of a Google account is > obnoxiously difficult. Your caution is well advised. > > -- > \ "I got fired from my job the other day. They said my | > `\ personality was weird. ? That's okay, I have four more." | > _o__) ?Bug-Eyed Earl, _Red Meat_ | > Ben Finney > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From orlenko at gmail.com Fri Feb 6 02:11:02 2009 From: orlenko at gmail.com (Volodymyr Orlenko) Date: Thu, 05 Feb 2009 23:11:02 -0800 Subject: Using multiprocessing from a Windows service In-Reply-To: References: <0e4d6033-a130-4c19-b648-6bcef8bfc922@u18g2000pro.googlegroups.com> <498BB39D.5070809@gmail.com> <498BBBE0.6090704@gmail.com> <498BC8E4.7000108@gmail.com> Message-ID: <498BE286.20008@gmail.com> On 05/02/2009 9:54 PM, James Mills wrote: > On Fri, Feb 6, 2009 at 3:21 PM, Volodymyr Orlenko wrote: > >> [...] Maybe there's another >> way to fix the forking module? >> > > I believe the best way to fix this is to fix the underlying > issue that Mark has pointed out (monkey-patching mp won't do). > > But according to Mark's second message in this thread, there's no way to make pythonservice.exe set its sys.argv[0] to a python module -- it uses sys.argv for debug parameters in debug mode, and for custom service parameters in normal mode. From m.gritsch at gmail.com Fri Feb 6 02:28:52 2009 From: m.gritsch at gmail.com (Markus Gritsch) Date: Fri, 6 Feb 2009 08:28:52 +0100 Subject: web2py 1.56 is OUT In-Reply-To: <9B19AA5B-306A-49F8-BBF2-1F8F31B2E818@cs.depaul.edu> References: <9B19AA5B-306A-49F8-BBF2-1F8F31B2E818@cs.depaul.edu> Message-ID: <533b7d320902052328ua9f8e41h922b5ef6645896d2@mail.gmail.com> Hi, when copying and pasting the example from the announcement into files, it wont run due to some errors: 2009/2/5 Massimo Di Pierro : > > Example of code (complete app) > ========================= > ## in model db.py > from gluon.tools import * > db=SQLDB() > db.define_table('puppy', db.Field('name'), db.Field('image','upload')) > auth=Auth(globals(),db) Here the line auth.define_tables() is missing. > crud=Crud(flobals(),db) flobals -> globals > ## in controller default.py > def user(): > " to expose register, login, logout, etc " > return dict(form=auth()) > > @auth.requires_login() > def data(): > " to expose select, create, update, delete, etc " The above line is indented one character too much which results in an error. > return dict(form=crud()) > > @auth.requires_login() > def download(): > " for downloading uploaded images " > return response.download(request,db) > > ## in view default/user.html > {{extend 'layout.html'}} >
{{=form}}
> > ## in view default/data.html > {{extend 'layout.html'}} >
{{=form}}
The above example is not (although stated) a complete app, even when correcting the errors. No index action, no links to register, login, etc, no functionality in the data action. If one has not already read the web2py auth docu, one cannot understand what should be going on. If I would have been looking at web2py for the first time, I would have been disapointed and would not bother looking deeper. Also the glued-together code style without spaces after colons and around operators looks quite special. When suggesting PEP 8 compliance I suggested using it in the *examples*, and just optionally in the gluon code itself. The example and the documentation is the stuff people are seeing and reading when trying to get started with web2py. I know, the above paragraphs sound quite negative. *I* like web2py very much and am a happy user. I just fear that such examples will not draw new users towards this great project. Maybe use a simple example without Auth the next time, which is *really* complete and fully functional. Kind regards, Markus From dq at gmail.com Fri Feb 6 02:32:54 2009 From: dq at gmail.com (dq) Date: Fri, 06 Feb 2009 08:32:54 +0100 Subject: urllib2 performance on windows, usb connection Message-ID: I've googled this pretty extensively and can't find anyone who's had the same problem, so here it is: I wrote a console program in python to download podcasts, so speed is an issue. I have 1.6 M down. The key bit of downloading code is this: source = urllib2.urlopen( url ) target = open( filename, 'wb' ) target.write( source.read() ) This runs great on Ubuntu. I get DL speeds of about 1.5 Mb/s on the SATA HD or on a usb-connected iPod, but if I run the same program on Windows (with a 2 GHz core 2 duo, 7200 rpm sata drive---better hardware specs than the Ubuntu box), it maxes out at about 500 kb/s. Worse, if I DL directly to my iPod in disk mode, I'm lucky if I even hit 100 kb/s. So does anyone know what the deal is with this? Why is the same code so much slower on Windows? Hope someone can tell me before a holy war erupts :-) --danny From martin at v.loewis.de Fri Feb 6 02:48:41 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 06 Feb 2009 08:48:41 +0100 Subject: urllib2 performance on windows, usb connection In-Reply-To: References: Message-ID: <498beb5a$0$3305$9b622d9e@news.freenet.de> > So does anyone know what the deal is with this? Why is the same code so > much slower on Windows? Hope someone can tell me before a holy war > erupts :-) Only the holy war can give an answer here. It certainly has *nothing* to do with Python; Python calls the operating system functions to read from the network and write to the disk almost directly. So it must be the operating system itself that slows it down. To investigate further, you might drop the write operating, and measure only source.read(). If that is slower, then, for some reason, the network speed is bad on Windows. Maybe you have the network interfaces misconfigured? Maybe you are using wireless on Windows, but cable on Linux? Maybe you have some network filtering software running on Windows? Maybe it's just that Windows sucks?-) If the network read speed is fine, but writing slows down, I ask the same questions. Perhaps you have some virus scanner installed that filters all write operations? Maybe Windows sucks? Regards, Martin From curt.hash at gmail.com Fri Feb 6 03:10:43 2009 From: curt.hash at gmail.com (Curt Hash) Date: Fri, 6 Feb 2009 01:10:43 -0700 Subject: Fastest database solution Message-ID: <736698790902060010x4263cb2cp643bbc63398f56f5@mail.gmail.com> I'm writing a small application for detecting source code plagiarism that currently relies on a database to store lines of code. The application has two primary functions: adding a new file to the database and comparing a file to those that are already stored in the database. I started out using sqlite3, but was not satisfied with the performance results. I then tried using psycopg2 with a local postgresql server, and the performance got even worse. My simple benchmarks show that sqlite3 is an average of 3.5 times faster at inserting a file, and on average less than a tenth of a second slower than psycopg2 at matching a file. I expected postgresql to be a lot faster ... is there some peculiarity in psycopg2 that could be causing slowdown? Are these performance results typical? Any suggestions on what to try from here? I don't think my code/queries are inherently slow, but I'm not a DBA or a very accomplished Python developer, so I could be wrong. Any advice is appreciated. -------------- next part -------------- An HTML attachment was scrubbed... URL: From duncan.booth at invalid.invalid Fri Feb 6 04:05:25 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 6 Feb 2009 09:05:25 GMT Subject: urllib2 performance on windows, usb connection References: Message-ID: dq wrote: > This runs great on Ubuntu. I get DL speeds of about 1.5 Mb/s on the > SATA HD or on a usb-connected iPod, but if I run the same program on > Windows (with a 2 GHz core 2 duo, 7200 rpm sata drive---better hardware > specs than the Ubuntu box), it maxes out at about 500 kb/s. Worse, if I > DL directly to my iPod in disk mode, I'm lucky if I even hit 100 kb/s. > > So does anyone know what the deal is with this? Why is the same code so > much slower on Windows? Hope someone can tell me before a holy war > erupts :-) > Just a guess, but are you running any kind of virus scanning software on Windows? That could have a massive impact on the speed of writing to disc. -- Duncan Booth http://kupuguy.blogspot.com From dickinsm at gmail.com Fri Feb 6 04:11:55 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Fri, 6 Feb 2009 01:11:55 -0800 (PST) Subject: Is c.l.py becoming less friendly? References: <1b50521f-b33b-4e3e-9a3e-65e8eb2f7242@v18g2000pro.googlegroups.com> Message-ID: <155f77da-1071-4122-bff0-44d868f2c7b2@i18g2000prf.googlegroups.com> On Feb 6, 6:23?am, "Hendrik van Rooyen" wrote: > I think this thread has buggered up a perfectly ^^^^^^^^^^^ Such language. I'm appalled. Mark From rogerb at rogerbinns.com Fri Feb 6 04:12:45 2009 From: rogerb at rogerbinns.com (Roger Binns) Date: Fri, 06 Feb 2009 01:12:45 -0800 Subject: Fastest database solution In-Reply-To: <736698790902060010x4263cb2cp643bbc63398f56f5@mail.gmail.com> References: <736698790902060010x4263cb2cp643bbc63398f56f5@mail.gmail.com> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Curt Hash wrote: > I started out using sqlite3, but was not satisfied with the performance > results. I then tried using psycopg2 with a local postgresql server, and > the performance got even worse. SQLite is in the same process. Communication with postgres is via another process so marshalling the traffic and context switches will impose overhead as you found. > I don't think > my code/queries are inherently slow, but I'm not a DBA or a very > accomplished Python developer, so I could be wrong. It doesn't sound like a database is the best solution to your issue anyway. A better solution would likely be some form of hashing the lines and storing something that gives quick hash lookups. The hash would have to do things like not care what variable names are used etc. There are already lots of plagiarism detectors out there so it may be more prudent using one of them, or at least learn how they do things so your own system could improve on them. Roger -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkmL/wgACgkQmOOfHg372QTAmACg0INMfUKA10Uc6UJwNhYhDeoV EKwAoKpDMRzr7GzCKeYxn93TU69nDx4X =4r01 -----END PGP SIGNATURE----- From tino at wildenhain.de Fri Feb 6 04:17:42 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Fri, 06 Feb 2009 10:17:42 +0100 Subject: Fastest database solution In-Reply-To: <736698790902060010x4263cb2cp643bbc63398f56f5@mail.gmail.com> References: <736698790902060010x4263cb2cp643bbc63398f56f5@mail.gmail.com> Message-ID: <498C0036.4070805@wildenhain.de> Hi Curt, Curt Hash wrote: > I'm writing a small application for detecting source code plagiarism > that currently relies on a database to store lines of code. > > The application has two primary functions: adding a new file to the > database and comparing a file to those that are already stored in the > database. > > I started out using sqlite3, but was not satisfied with the performance > results. I then tried using psycopg2 with a local postgresql server, and > the performance got even worse. My simple benchmarks show that sqlite3 > is an average of 3.5 times faster at inserting a file, and on average > less than a tenth of a second slower than psycopg2 at matching a file. > > I expected postgresql to be a lot faster ... is there some peculiarity > in psycopg2 that could be causing slowdown? Are these performance > results typical? Any suggestions on what to try from here? I don't think > my code/queries are inherently slow, but I'm not a DBA or a very > accomplished Python developer, so I could be wrong. Off hand thats hard to tell w/o any details on what you are actually doing. At least an outline what kind of data you are storing and of course details of your database configuration would be helpful. Please note that postgres is quite good at handling concurrent load - this does not mean its best or every desk top database application. Regards Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From soft_smith at yahoo.com Fri Feb 6 04:49:34 2009 From: soft_smith at yahoo.com (Kalyankumar Ramaseshan) Date: Fri, 6 Feb 2009 01:49:34 -0800 (PST) Subject: Question on Strings Message-ID: <984064.27780.qm@web112219.mail.gq1.yahoo.com> Hi, Excuse me if this is a repeat question! I just wanted to know how are strings represented in python? I need to know in terms of: a) Strings are stored as UTF-16 (LE/BE) or UTF-32 characters? b) They are converted to utf-8 format when it is needed for e.g. when storing the string to disk or sending it through a socket (tcp/ip)? Any help in this regard is appreciated. Thank you. Regards Kalyan From asmodai at in-nomine.org Fri Feb 6 04:54:06 2009 From: asmodai at in-nomine.org (Jeroen Ruigrok van der Werven) Date: Fri, 6 Feb 2009 10:54:06 +0100 Subject: Fastest database solution In-Reply-To: <736698790902060010x4263cb2cp643bbc63398f56f5@mail.gmail.com> References: <736698790902060010x4263cb2cp643bbc63398f56f5@mail.gmail.com> Message-ID: <20090206095406.GL14658@nexus.in-nomine.org> -On [20090206 09:11], Curt Hash (curt.hash at gmail.com) wrote: >I'm writing a small application for detecting source code plagiarism that >currently relies on a database to store lines of code. > >The application has two primary functions: adding a new file to the database >and comparing a file to those that are already stored in the database. Maybe CouchDB [1] is more in line with what you need. [1] http://couchdb.apache.org/ -- Jeroen Ruigrok van der Werven / asmodai ????? ?????? ??? ?? ?????? http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B Earth to earth, ashes to ashes, dust to dust... From agile.scrapping at gmail.com Fri Feb 6 04:56:22 2009 From: agile.scrapping at gmail.com (Agile Consulting) Date: Fri, 6 Feb 2009 01:56:22 -0800 (PST) Subject: What is difference between ADO and RDO Message-ID: <0f03c29f-04df-433b-8ea9-01be1acfa7cf@v39g2000pro.googlegroups.com> Explain ADO and RDO From clp2 at rebertia.com Fri Feb 6 05:24:09 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 6 Feb 2009 02:24:09 -0800 Subject: Question on Strings In-Reply-To: <984064.27780.qm@web112219.mail.gq1.yahoo.com> References: <984064.27780.qm@web112219.mail.gq1.yahoo.com> Message-ID: <50697b2c0902060224m6b5d5c09uf4c8cbdb0c83d1bf@mail.gmail.com> On Fri, Feb 6, 2009 at 1:49 AM, Kalyankumar Ramaseshan wrote: > > Hi, > > Excuse me if this is a repeat question! > > I just wanted to know how are strings represented in python? > > I need to know in terms of: > > a) Strings are stored as UTF-16 (LE/BE) or UTF-32 characters? IIRC, Depends on what the build settings were when CPython was compiled. UTF-16 is the default. > b) They are converted to utf-8 format when it is needed for e.g. when storing the string to disk or sending it through a socket (tcp/ip)? No. They are implicitly converted to ASCII in such cases. To properly handle non-ASCII Unicode characters, you need to encode/decode the strings to/from bytes manually by specifying the encoding. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From r.warhekar at gmail.com Fri Feb 6 05:53:31 2009 From: r.warhekar at gmail.com (Rahul) Date: Fri, 6 Feb 2009 02:53:31 -0800 (PST) Subject: i have an query regarding pyodbc References: <4f9834b0-98cd-486c-b91e-a6cab4d8744f@b38g2000prf.googlegroups.com> Message-ID: On Feb 6, 11:27?am, Rahul wrote: > hello all, > > I have installed pyodbc on my red hat enterprise 4 linux machine but > when i go to use that using statement, > > import pyodbc > > through python console it gives me error as > > ImportError : dynamic module does not define init function > (initpyodbc) > > and when i do 'nm pyodbc.so' command i get output as > > [root at dbserver site-packages]# nm pyodbc.so 00001600 A __bss_start > 000003ec t call_gmon_start 00001600 b completed.1 000014fc d > __CTOR_END__ > 000014f8 d __CTOR_LIST__ > ? ? ? ? ?w __cxa_finalize@@GLIBC_2.1.3 > 000004a8 t __do_global_ctors_aux > 00000410 t __do_global_dtors_aux > 000015f8 d __dso_handle > 00001504 d __DTOR_END__ > 00001500 d __DTOR_LIST__ > 0000150c A _DYNAMIC > 00001600 A _edata > 00001604 A _end > 000004d8 T _fini > 0000046c t frame_dummy > 000004f4 r __FRAME_END__ > 000015e8 A _GLOBAL_OFFSET_TABLE_ > ? ? ? ? ?w __gmon_start__ > 000003b4 T _init > 00001508 d __JCR_END__ > 00001508 d __JCR_LIST__ > ? ? ? ? ?w _Jv_RegisterClasses > 000015fc d p.0 > > which means there is no init function. > > So what might be the cause for that? > > I have build that pyodbc twice. > Any help regarding this will be greatly appreciated. > > Thanks & Regards > Rahul this problem was due to not proper building of pyodbc From r.warhekar at gmail.com Fri Feb 6 05:56:56 2009 From: r.warhekar at gmail.com (Rahul) Date: Fri, 6 Feb 2009 02:56:56 -0800 (PST) Subject: i have an query regarding pyodbc References: <4f9834b0-98cd-486c-b91e-a6cab4d8744f@b38g2000prf.googlegroups.com> Message-ID: <519d4dd8-c9b0-44ed-bad1-5df96adf1ea7@x16g2000prn.googlegroups.com> On Feb 6, 3:53?pm, Rahul wrote: > On Feb 6, 11:27?am, Rahul wrote: > > > > > hello all, > > > I have installed pyodbc on my red hat enterprise 4 linux machine but > > when i go to use that using statement, > > > import pyodbc > > > through python console it gives me error as > > > ImportError : dynamic module does not define init function > > (initpyodbc) > > > and when i do 'nm pyodbc.so' command i get output as > > > [root at dbserver site-packages]# nm pyodbc.so 00001600 A __bss_start > > 000003ec t call_gmon_start 00001600 b completed.1 000014fc d > > __CTOR_END__ > > 000014f8 d __CTOR_LIST__ > > ? ? ? ? ?w __cxa_finalize@@GLIBC_2.1.3 > > 000004a8 t __do_global_ctors_aux > > 00000410 t __do_global_dtors_aux > > 000015f8 d __dso_handle > > 00001504 d __DTOR_END__ > > 00001500 d __DTOR_LIST__ > > 0000150c A _DYNAMIC > > 00001600 A _edata > > 00001604 A _end > > 000004d8 T _fini > > 0000046c t frame_dummy > > 000004f4 r __FRAME_END__ > > 000015e8 A _GLOBAL_OFFSET_TABLE_ > > ? ? ? ? ?w __gmon_start__ > > 000003b4 T _init > > 00001508 d __JCR_END__ > > 00001508 d __JCR_LIST__ > > ? ? ? ? ?w _Jv_RegisterClasses > > 000015fc d p.0 > > > which means there is no init function. > > > So what might be the cause for that? > > > I have build that pyodbc twice. > > Any help regarding this will be greatly appreciated. > > > Thanks & Regards > > Rahul > > this problem was due to not proper building of pyodbc Now my problem was, i have two versions of python installed at different locations but when i use import statement from psp pages it displays the error as ImportError : dynamic module does not define init function(initpyodbc) this error was due to pointing to older version of python. So, i want to know how to point my import statements to the new version of python. Thanks & regards Rahul From Ken at Elkabany.com Fri Feb 6 06:03:28 2009 From: Ken at Elkabany.com (Ken Elkabany) Date: Fri, 6 Feb 2009 03:03:28 -0800 Subject: Changing return of type(obj) Message-ID: Hello, I am attempting to fully-simulate an 'int' object with a custom object type. It is part of a library I am creating for python futures and promises. Is there anyway such that type(my_object) can return ? Or for that matter, any other primitive? I do not care how dirty the solution might possibly be; Could there be a way through the C API? Though I predict it will cause a mess with the interpreter. Thanks, Ken Elkabany -------------- next part -------------- An HTML attachment was scrubbed... URL: From tino at wildenhain.de Fri Feb 6 06:11:38 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Fri, 06 Feb 2009 12:11:38 +0100 Subject: Question on Strings In-Reply-To: <984064.27780.qm@web112219.mail.gq1.yahoo.com> References: <984064.27780.qm@web112219.mail.gq1.yahoo.com> Message-ID: <498C1AEA.8060303@wildenhain.de> Hi, Kalyankumar Ramaseshan wrote: > Hi, > > Excuse me if this is a repeat question! > > I just wanted to know how are strings represented in python? It depents on if you mean python2.x or python3.x - the model changed. Python 2.x knows str and unicode - the former a sequence of single byte characters and unicode depending on configure options either 16 or 32 bit per character. str in python3.x replaces unicode and what formerly used to be like str is now bytes (iirc). > I need to know in terms of: > > a) Strings are stored as UTF-16 (LE/BE) or UTF-32 characters? It uses an internal fixed length encoding for unicode, not UTF > b) They are converted to utf-8 format when it is needed for e.g. when storing the string to disk or sending it through a socket (tcp/ip)? Nope. You need to do this explicitely. Default encoding for python2.x implicit conversion is ascii. In python2.x you would use unicodestr.encode('utf-8') and simplestr.decode('utf-8') to convert an utf-8 encoded string back to internal unicode. There are many encodings available to select from. > Any help in this regard is appreciated. Please see also pythons documentation which is very good and just try it out in the interactive interpreter Regards Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From clp2 at rebertia.com Fri Feb 6 06:42:30 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 6 Feb 2009 03:42:30 -0800 Subject: Changing return of type(obj) In-Reply-To: References: Message-ID: <50697b2c0902060342y198e6891xfe14ca5807effea5@mail.gmail.com> On Fri, Feb 6, 2009 at 3:03 AM, Ken Elkabany wrote: > Hello, > > I am attempting to fully-simulate an 'int' object with a custom object type. > It is part of a library I am creating for python futures and promises. Is > there anyway such that type(my_object) can return ? Or for that > matter, any other primitive? I do not care how dirty the solution might > possibly be; Could there be a way through the C API? Though I predict it > will cause a mess with the interpreter. Any particular reason why subclassing 'int' wouldn't be good enough? (You did know you can do that, right?) I know you can subclass int at the Python level and I would think you should be able to do it at the C level also (if not, the design just gets only slightly more involved). Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From Ken at Elkabany.com Fri Feb 6 06:49:17 2009 From: Ken at Elkabany.com (Ken Elkabany) Date: Fri, 6 Feb 2009 03:49:17 -0800 Subject: Changing return of type(obj) In-Reply-To: <50697b2c0902060342y198e6891xfe14ca5807effea5@mail.gmail.com> References: <50697b2c0902060342y198e6891xfe14ca5807effea5@mail.gmail.com> Message-ID: I would simply subclass 'int', but this object needs to be general enough to pretend to be an 'int', 'NoneType', 'str', etc... A long shot: Can I change the base class on an instance by instance basis depending on the need? Well, now I can imagine having a class factory that will spawn for me the class that inherits the correct base type. Any other solutions? Thanks Chris. On Fri, Feb 6, 2009 at 3:42 AM, Chris Rebert wrote: > On Fri, Feb 6, 2009 at 3:03 AM, Ken Elkabany wrote: > > Hello, > > > > I am attempting to fully-simulate an 'int' object with a custom object > type. > > It is part of a library I am creating for python futures and promises. Is > > there anyway such that type(my_object) can return ? Or for > that > > matter, any other primitive? I do not care how dirty the solution might > > possibly be; Could there be a way through the C API? Though I predict it > > will cause a mess with the interpreter. > > Any particular reason why subclassing 'int' wouldn't be good enough? > (You did know you can do that, right?) > I know you can subclass int at the Python level and I would think you > should be able to do it at the C level also (if not, the design just > gets only slightly more involved). > > Cheers, > Chris > > -- > Follow the path of the Iguana... > http://rebertia.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From unews at nospam.onlinehome.de Fri Feb 6 07:01:39 2009 From: unews at nospam.onlinehome.de (Uwe Grauer) Date: Fri, 06 Feb 2009 13:01:39 +0100 Subject: kinterbasdb + firebird 1.5 with python 2.6 ? In-Reply-To: References: Message-ID: Laszlo Nagy wrote: > Uwe Grauer ?rta: >> Laszlo Nagy wrote: >> Get it from here: >> http://www.firebirdsql.org/index.php?op=devel&sub=python >> > Thanks. Unfortunately, this does not support Firebird 1.5 anymore. I can > only find Python 2.5 + Firebird 1.5. But not for Python 2.6. I'm going > to downgrade. :-( > Can you point me to where you read about stopped support for FB 1.5? Could it be that you have to just compile it against FB 1.5 libs to get a working version? Uwe From __peter__ at web.de Fri Feb 6 07:02:12 2009 From: __peter__ at web.de (Peter Otten) Date: Fri, 06 Feb 2009 13:02:12 +0100 Subject: sorting for recursive folder rename References: Message-ID: ianar? wrote: > On Dec 16 2008, 7:36?pm, "Rhodri James" > wrote: >> On Tue, 16 Dec 2008 18:20:52 -0000, ianar? wrote: >> > Hello all, >> >> > I trying to recursivelyrenamefolders and files, and am looking for >> > some ideas on the best way of doing this. The problem is that the >> > given list of items can be in order, and one to all items may be >> > renamed. Here is some preliminary code I have, but which does not work >> > very well. > > self.toRename has the following structure : > [ > [original_name, new_name, os.path.isdir] > .. > ] > > # define these here for faster processing > def split(item): > return os.path.split(item) > def addSep(path): > return os.sep + path + os.sep > def recursiveFolderSort(x,y): > return cmp(y[0], x[0]) > > sortedRename = sorted(self.toRename) > > # make a list of all folders that will be processed > foldersToAdjust = [] > for item in sortedRename: > if item[2] is False: > oF = split(item[0])[1] # original folder name > nF = split(item[1])[1] # new folder name > if oF is not nF: > foldersToAdjust.append((oF, nF)) > > # replace all occurences of folders in path > for i in range(len(self.toRename)): > for f in foldersToAdjust: > oF = addSep(f[0]) # original folder name > nF = addSep(f[1]) # new folder name > self.toRename[i][0] = self.toRename[i][0].replace(oF,nF) > self.toRename[i][1] = self.toRename[i][1].replace(oF,nF) > > if progressDialog.update(i) is False: > error = 'cancelled' > break > > # make sure renaming will be in correct order ! > self.toRename.sort(recursiveFolderSort) > >> import os >> >> for item in self.toRename: >> os.renames(item[0], item[1]) >> >> That's it. ?os.renames will take care of all the intermediate >> directory creation so you don't even need to sort the list. >> >> -- >> Rhodri James *-* Wildebeeste Herder to the Masses > > It's been a while since I decided to work on this again ... > > Anyway, if only it were that easy !! > > Traceback (most recent call last): > File "/home/ianare/Desktop/file-folder-ren/metamorphose2/Source/ > MainWindow.py", line 1477, in renameItems > os.renames(original[0], renamed[0]) > File "/usr/lib/python2.5/os.py", line 213, in renames > rename(old, new) > OSError: [Errno 2] No such file or directory > > > The problem is that if a directory is changed, all lower instances > need to be changed as well. > > given the following directory structure ... > > recursive > | > |_1 > | |_1 > | | |_1.txt > | | |_2.txt > | |_2 > | |_1.txt > | |_2.txt > |_2 > |_1 > | |_1.txt > | |_2.txt > |_2 > |_1.txt > |_2.txt > > ... and assuming I want to change : > recursive/2/2/2.txt --> recursive/2/2/14.txt > > but, I ALSO want to change : > recursive/2 --> recursive/04 > > it means that the first operation is really : > recursive/04/2/2.txt --> recursive/04/2/14.txt > > os.renames will work, but it needs to have the correct path, so it > comes down to the same thing. > > IOW, I need a way of : > A) adjusting paths taking into consideration all changes up and down > the tree > B) sorting normalized paths so they are renamed in the proper sequence > (depends on point 'A', obviously) > > I'm pretty sure I can take care of 'B' with the following sorting > method: > > # order by path depth > def recursiveFolderSort(x, y): > x = x[0].count(os.sep) > y = y[0].count(os.sep) > return cmp(x, y) > self.toRename.sort(recursiveFolderSort) > > but I still need a way of generating the correct names. I don't see the problem. Just rename the deepest files and directories first. # untested def old_depth((old, new)): p = os.path.abspath(old) return p.count(os.sep) - p.endswith(os.sep) # don't count trailing slash pairs = sorted(self.toRename, key=old_depth, reverse=True) for old, new in pairs: os.rename(old, new) Because "recursive/2/2/2.txt" has more slashes it will be processed before "recursive/2" and thus when the latter is processed the former's path will change implicitly. Peter From lists at cheimes.de Fri Feb 6 07:05:50 2009 From: lists at cheimes.de (Christian Heimes) Date: Fri, 06 Feb 2009 13:05:50 +0100 Subject: Changing return of type(obj) In-Reply-To: References: <50697b2c0902060342y198e6891xfe14ca5807effea5@mail.gmail.com> Message-ID: Ken Elkabany schrieb: > I would simply subclass 'int', but this object needs to be general enough to > pretend to be an 'int', 'NoneType', 'str', etc... A long shot: Can I change > the base class on an instance by instance basis depending on the need? Well, > now I can imagine having a class factory that will spawn for me the class > that inherits the correct base type. Any other solutions? No, it's not possible. The type is an inherent part of an object. Python looks up methods and other attributes by looking at the type. The method call obj.method() is implemented as type(obj).method(obj). Christian From steve at holdenweb.com Fri Feb 6 07:09:29 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 06 Feb 2009 07:09:29 -0500 Subject: Python Power Point Slides In-Reply-To: <4041891322e2bf49ab400664bc811fae@121.100.100.103> References: <4041891322e2bf49ab400664bc811fae@121.100.100.103> Message-ID: Tehseen Siddiqui wrote: > ------------------------------------------------------------------------ > > DISCLAIMER: The information in this email is confidential and may be > legally privileged. [... etc.] What information? -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From sjmachin at lexicon.net Fri Feb 6 07:10:13 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 6 Feb 2009 04:10:13 -0800 (PST) Subject: Question on Strings References: <984064.27780.qm@web112219.mail.gq1.yahoo.com> Message-ID: <0c01fc50-f20f-4981-af81-a49499acf776@q30g2000prq.googlegroups.com> On Feb 6, 9:24?pm, Chris Rebert wrote: > On Fri, Feb 6, 2009 at 1:49 AM, Kalyankumar Ramaseshan > > wrote: > > > Hi, > > > Excuse me if this is a repeat question! > > > I just wanted to know how are strings represented in python? > > > I need to know in terms of: > > > a) Strings are stored as UTF-16 (LE/BE) or UTF-32 characters? Neither. > > IIRC, Depends on what the build settings were when CPython was > compiled. UTF-16 is the default. Unicode strings are held as arrays of 16-bit numbers or 32-bit numbers [of which only 21 are used]. If you must use an acronym, use UCS-2 or UCS-4. The UTF-n siblings are *external* representations. 2.x: a_unicode_object.decode('UTF-16') -> an_str_object 3.x: an_str_object.decode('UTF-16') -> a_bytes_object By the way, has anyone come up with a name for the shifting effect observed above on str, and also with repr, range, and the iter* family? If not, I suggest that the language's association with the best of English humour be widened so that it be dubbed the "Mad Hatter's Tea Party" effect. From mal at egenix.com Fri Feb 6 07:19:55 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Fri, 06 Feb 2009 13:19:55 +0100 Subject: Fastest database solution In-Reply-To: <736698790902060010x4263cb2cp643bbc63398f56f5@mail.gmail.com> References: <736698790902060010x4263cb2cp643bbc63398f56f5@mail.gmail.com> Message-ID: <498C2AEB.1010907@egenix.com> On 2009-02-06 09:10, Curt Hash wrote: > I'm writing a small application for detecting source code plagiarism that > currently relies on a database to store lines of code. > > The application has two primary functions: adding a new file to the database > and comparing a file to those that are already stored in the database. > > I started out using sqlite3, but was not satisfied with the performance > results. I then tried using psycopg2 with a local postgresql server, and the > performance got even worse. My simple benchmarks show that sqlite3 is an > average of 3.5 times faster at inserting a file, and on average less than a > tenth of a second slower than psycopg2 at matching a file. > > I expected postgresql to be a lot faster ... is there some peculiarity in > psycopg2 that could be causing slowdown? Are these performance results > typical? Any suggestions on what to try from here? I don't think my > code/queries are inherently slow, but I'm not a DBA or a very accomplished > Python developer, so I could be wrong. > > Any advice is appreciated. In general, if you do bulk insert into a large table, you should consider turning off indexing on the table and recreate/update the indexes in one go afterwards. But regardless of this detail, I think you should consider a filesystem based approach. This is going to be a lot faster than using a database to store the source code line by line. You can still use a database for the administration and indexing of the data, e.g. by storing a hash of each line in the database. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Feb 06 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From thomasvangurp at gmail.com Fri Feb 6 07:30:56 2009 From: thomasvangurp at gmail.com (thomasvangurp at gmail.com) Date: Fri, 6 Feb 2009 04:30:56 -0800 (PST) Subject: Python 3.0 slow file IO References: <9e7dc260-1680-42e3-9b93-7bc6c86b2f10@r37g2000prr.googlegroups.com> Message-ID: <5ea62aa0-5e5a-4faf-9c1f-dde84f01f643@r41g2000prr.googlegroups.com> Thanks a lot for all the responses. I'll move back to Python 2.5 for compatibility with SciPY and some other third party packages. I'll leave the compilation process for some other day, for now I'm a happy user, mayve In the future I would like to contribute to the developmental process.. From Olivier.Darge at gmail.com Fri Feb 6 07:37:54 2009 From: Olivier.Darge at gmail.com (OdarR) Date: Fri, 6 Feb 2009 04:37:54 -0800 (PST) Subject: What is difference between ADO and RDO References: <0f03c29f-04df-433b-8ea9-01be1acfa7cf@v39g2000pro.googlegroups.com> Message-ID: On 6 f?v, 10:56, Agile Consulting wrote: > Explain ADO and RDO RU a bot ? Olivier From agile.scrapping3 at gmail.com Fri Feb 6 07:59:19 2009 From: agile.scrapping3 at gmail.com (agile) Date: Fri, 6 Feb 2009 04:59:19 -0800 (PST) Subject: is python Object oriented?? References: <783b47270901290201p311b6681rc132ca7b175ede83@mail.gmail.com> <50697b2c0901290225ufb1580ep706c332b99cc59fa@mail.gmail.com> <4981985B.4070108@wildenhain.de> <783b47270901290558y7a4eed9bi59e362dad37879e1@mail.gmail.com> <498363C0.5070909@gmail.com> Message-ID: On Jan 31, 1:54?am, Christian Heimes wrote: > Michael Torrie schrieb: > > >> It all depends on implementation, I think even we can make "C" object > >> oriented with proper implementation. > > > Indeed, any code based on gobject libraries can be object-oriented in > > design and function. > > The Python C API is a good example for well designed and object oriented > C code. > > Christian hello From Krzysztof.Retel at googlemail.com Fri Feb 6 08:15:30 2009 From: Krzysztof.Retel at googlemail.com (Krzysztof Retel) Date: Fri, 6 Feb 2009 05:15:30 -0800 (PST) Subject: Skipping bytes while reading a binary file? References: <279bf987-8e3c-465d-a173-49b3d99a298a@s9g2000prg.googlegroups.com> <695d1efb-6144-4004-a4df-e387e26fa32f@p2g2000prf.googlegroups.com> <4e375a89-9a53-49d0-b604-6d43643fca08@x6g2000pre.googlegroups.com> <471af752-fd37-41a8-8f07-c36e1eecb829@f40g2000pri.googlegroups.com> Message-ID: <8605eb07-4995-4d96-a118-c5fa4565cd6c@b38g2000prf.googlegroups.com> On Feb 5, 11:51?pm, Lionel wrote: > On Feb 5, 3:35?pm, Lionel wrote: > > > > > On Feb 5, 2:56?pm, Lionel wrote: > > > > On Feb 5, 2:48?pm, MRAB wrote: > > > > > Lionel wrote: > > > > > ?> Hello, > > > > ?> I have data stored in binary files. Some of these files are > > > > ?> huge...upwards of 2 gigs or more. They consist of 32-bit float complex > > > > ?> numbers where the first 32 bits of the file is the real component, the > > > > ?> second 32bits is the imaginary, the 3rd 32-bits is the real component > > > > ?> of the second number, etc. > > > > ?> > > > > ?> I'd like to be able to read in just the real components, load them > > > > ?> into a numpy.ndarray, then load the imaginary coponents and load them > > > > ?> into a numpy.ndarray. ?I need the real and imaginary components stored > > > > ?> in seperate arrays, they cannot be in a single array of complex > > > > ?> numbers except for temporarily. I'm trying to avoid temporary storage, > > > > ?> though, because of the size of the files. > > > > ?> > > > > ?> I'm currently reading the file scanline-by-scanline to extract rows of > > > > ?> complex numbers which I then loop over and load into the real/ > > > > ?> imaginary arrays as follows: > > > > ?> > > > > ?> > > > > ?> ? ? ? ? self._realData ? ? ? ? = numpy.empty((Rows, Columns), dtype = > > > > ?> numpy.float32) > > > > ?> ? ? ? ? self._imaginaryData = numpy.empty((Rows, Columns), dtype = > > > > ?> numpy.float32) > > > > ?> > > > > ?> ? ? ? ? floatData = array.array('f') > > > > ?> > > > > ?> ? ? ? ? for CurrentRow in range(Rows): > > > > ?> > > > > ?> ? ? ? ? ? ? floatData.fromfile(DataFH, (Columns*2)) > > > > ?> > > > > ?> ? ? ? ? ? ? position = 0 > > > > ?> ? ? ? ? ? ? for CurrentColumn in range(Columns): > > > > ?> > > > > ?> ? ? ? ? ? ? ? ? ?self._realData[CurrentRow, CurrentColumn] ? ? ? ? ?= > > > > ?> floatData[position] > > > > ?> ? ? ? ? ? ? ? ? self._imaginaryData[CurrentRow, CurrentColumn] ?= > > > > ?> floatData[position+1] > > > > ?> ? ? ? ? ? ? ? ? position = position + 2 > > > > ?> > > > > ?> > > > > ?> The above code works but is much too slow. If I comment out the body > > > > ?> of the "for CurrentColumn in range(Columns)" loop, the performance is > > > > ?> perfectly adequate i.e. function call overhead associated with the > > > > ?> "fromfile(...)" call is not very bad at all. What seems to be most > > > > ?> time-consuming are the simple assignment statements in the > > > > ?> "CurrentColumn" for-loop. > > > > ?> > > > > [snip] > > > > Try array slicing. floatData[0::2] will return the real parts and > > > > floatData[1::2] will return the imaginary parts. You'll have to read up > > > > how to assign to a slice of the numpy array (it might be > > > > "self._realData[CurrentRow] = real_parts" or "self._realData[CurrentRow, > > > > :] = real_parts"). > > > > > BTW, it's not the function call overhead of fromfile() which takes the > > > > time, but actually reading data from the file. > > > > Very nice! I like that! I'll post the improvement (if any). > > > > L- Hide quoted text - > > > > - Show quoted text - > > > Okay, the following: > > > ? ? ? ? ? ? self._realData[CurrentRow] ? ? ?= floatData[0::2] > > ? ? ? ? ? ? self._imaginaryData[CurrentRow] = floatData[1::2] > > > gives a 3.5x improvement in execution speed over the original that I > > posted. That's much better. Thank you for the suggestion. > > > L- Hide quoted text - > > > - Show quoted text - > > Correction: improvement is around 7-8x. I had similar issues while Slicing Network packets (TCP/UDP) on a real time basis. I was using 're' and found it a lot more time and resource consuming, than 'normal' string slicing as suggested by MRAB. K From grahn+nntp at snipabacken.se Fri Feb 6 08:17:29 2009 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 6 Feb 2009 13:17:29 GMT Subject: Scanning a file character by character References: Message-ID: On Wed, 4 Feb 2009 22:48:13 -0800 (PST), Spacebar265 wrote: > Hi. Does anyone know how to scan a file character by character and > have each character so I can put it into a variable. I am attempting > to make a chatbot and need this to read the saved input to look for > spelling mistakes and further analysis of user input. That does not follow. To analyze a text, the worst possible starting point is one variable for each character (what would you call them -- character_1, character_2, ... character_65802 ?) /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! From Slaunger at gmail.com Fri Feb 6 08:20:08 2009 From: Slaunger at gmail.com (Slaunger) Date: Fri, 6 Feb 2009 05:20:08 -0800 (PST) Subject: Skipping bytes while reading a binary file? References: <279bf987-8e3c-465d-a173-49b3d99a298a@s9g2000prg.googlegroups.com> <695d1efb-6144-4004-a4df-e387e26fa32f@p2g2000prf.googlegroups.com> <4e375a89-9a53-49d0-b604-6d43643fca08@x6g2000pre.googlegroups.com> <471af752-fd37-41a8-8f07-c36e1eecb829@f40g2000pri.googlegroups.com> Message-ID: <77b8d066-0634-4a68-bd9a-a0a44079564c@r10g2000prf.googlegroups.com> You might also want to have a look at a numpy memmap viewed as a recarray. from numpy import dtype, memmap, recarray # Define your record in the file, 4bytes for the real value, # and 4 bytes for the imaginary (assuming Little Endian repr) descriptor = dtype([("r", " References: <984064.27780.qm@web112219.mail.gq1.yahoo.com> <0c01fc50-f20f-4981-af81-a49499acf776@q30g2000prq.googlegroups.com> Message-ID: <498C3A25.8010605@mrabarnett.plus.com> John Machin wrote: > On Feb 6, 9:24 pm, Chris Rebert wrote: >> On Fri, Feb 6, 2009 at 1:49 AM, Kalyankumar Ramaseshan >> >> wrote: >> >>> Hi, >>> Excuse me if this is a repeat question! >>> I just wanted to know how are strings represented in python? >>> I need to know in terms of: >>> a) Strings are stored as UTF-16 (LE/BE) or UTF-32 characters? > > Neither. > >> IIRC, Depends on what the build settings were when CPython was >> compiled. UTF-16 is the default. > > Unicode strings are held as arrays of 16-bit numbers or 32-bit numbers > [of which only 21 are used]. If you must use an acronym, use UCS-2 or > UCS-4. > > The UTF-n siblings are *external* representations. > 2.x: a_unicode_object.decode('UTF-16') -> an_str_object > 3.x: an_str_object.decode('UTF-16') -> a_bytes_object > > By the way, has anyone come up with a name for the shifting effect > observed above on str, and also with repr, range, and the iter* > family? If not, I suggest that the language's association with the > best of English humour be widened so that it be dubbed the "Mad > Hatter's Tea Party" effect. > Bitwise shifts and rotates are collectively referred to as skew operations. I therefore suggest the term "skewing". :-) From pc at p-cos.net Fri Feb 6 08:32:21 2009 From: pc at p-cos.net (Pascal Costanza) Date: Fri, 06 Feb 2009 14:32:21 +0100 Subject: programming by evolution? In-Reply-To: <03db1c69-828a-4961-914d-62fe10ed88fb@w39g2000prb.googlegroups.com> References: <42a2e3fc-ec2e-4c09-b456-95a5fc4ce5a2@g39g2000pri.googlegroups.com> <6uuc4eFhc1u1U1@mid.individual.net> <11809792-676f-4d95-87c1-26666cc46b3b@w24g2000prd.googlegroups.com> <03db1c69-828a-4961-914d-62fe10ed88fb@w39g2000prb.googlegroups.com> Message-ID: <6v2sf4Fhuh4mU1@mid.individual.net> Xah Lee wrote: > Pascal Constanza is a Common Lisp fanatic. It's Costanza, not Constanza. Thank you, Pascal -- ELS'09: http://www.european-lisp-symposium.org/ My website: http://p-cos.net Common Lisp Document Repository: http://cdr.eurolisp.org Closer to MOP & ContextL: http://common-lisp.net/project/closer/ From kdawg44 at gmail.com Fri Feb 6 08:43:33 2009 From: kdawg44 at gmail.com (K-Dawg) Date: Fri, 6 Feb 2009 08:43:33 -0500 Subject: WIn32api Message-ID: <5caea3690902060543s78b19efaxe95b63b4be89153d@mail.gmail.com> Hi, I have a python script that I want to run in the system tray and system tray only (windows system). I am looking at the win32gui_taskbar.py demo file but am having trouble making sense of what parts do. I understand what the whole does but I want to actually learn what it is doing so I can apply it, not just copy and paste parts to make it work the way I want. I have searched for some kind of explanation or tutorial on this and have come up empty. Is there anything out there? Thanks. Kevin -------------- next part -------------- An HTML attachment was scrubbed... URL: From noama at answers.com Fri Feb 6 08:56:03 2009 From: noama at answers.com (Noam Aigerman) Date: Fri, 6 Feb 2009 15:56:03 +0200 Subject: Distributing simple tasks Message-ID: <749CACF29BDFB64E9F80189ECD77868804C00A8C@jermail1.atomant.net> Hi, Suppose I have an array of functions which I execute in threads (each thread get a slice of the array, iterates over it and executes each function in it's slice one after the other). Now I want to distribute these tasks between two machines, i.e give each machine half of the slices and let it run them in threads as described above. Is there an easy way, or an article on this matter you can point me to? Thanks, Noam -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at microcorp.co.za Fri Feb 6 08:56:11 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Fri, 6 Feb 2009 15:56:11 +0200 Subject: Question on Strings References: <984064.27780.qm@web112219.mail.gq1.yahoo.com> <0c01fc50-f20f-4981-af81-a49499acf776@q30g2000prq.googlegroups.com> Message-ID: <002201c98862$ac137a60$0d00a8c0@hendrik> "John Machin" wrote: >By the way, has anyone come up with a name for the shifting effect >observed above on str, and also with repr, range, and the iter* >family? If not, I suggest that the language's association with the >best of English humour be widened so that it be dubbed the "Mad >Hatter's Tea Party" effect. The MHTP effect. Sounds educated, almost like a network protocol. +1 - Hendrik From traef at ebasedsecurity.com Fri Feb 6 09:01:02 2009 From: traef at ebasedsecurity.com (Thomas Raef) Date: Fri, 6 Feb 2009 08:01:02 -0600 Subject: Distributing simple tasks Message-ID: Hi, Suppose I have an array of functions which I execute in threads (each thread get a slice of the array, iterates over it and executes each function in it's slice one after the other). Now I want to distribute these tasks between two machines, i.e give each machine half of the slices and let it run them in threads as described above. Is there an easy way, or an article on this matter you can point me to? Thanks, Noam I would suggest maybe a separate queue machine that would hand out each "next" function. That way if one machine takes a little longer, the faster machine can keep picking off functions and running them, while the slower machine can finish it's task. Just a thought. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gh at ghaering.de Fri Feb 6 09:01:20 2009 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Fri, 06 Feb 2009 15:01:20 +0100 Subject: updating nntplib In-Reply-To: <20090205224036.GH29170@subspacefield.org> References: <20090205224036.GH29170@subspacefield.org> Message-ID: Travis wrote: > Hello all, > > There are some notable deficiencies in nntlib. Here are two: [...] Be sure to add a bug report/patch to the Python bug tracker. http://bugs.python.org/ Anything else will most likely be overlooked or forgotten. -- Gerhard From noama at answers.com Fri Feb 6 09:06:08 2009 From: noama at answers.com (Noam Aigerman) Date: Fri, 6 Feb 2009 16:06:08 +0200 Subject: Distributing simple tasks In-Reply-To: References: Message-ID: <749CACF29BDFB64E9F80189ECD77868804C00A91@jermail1.atomant.net> Hi, The delta between the finishing times of each machine is insignificant compared to the actual runtime, thus I don't feel it's necessary at the moment. Anyway, I want to keep it simple until I understand how to distribute tasks J Thanks! From: Thomas Raef [mailto:traef at ebasedsecurity.com] Sent: Friday, February 06, 2009 4:01 PM To: Noam Aigerman; python-list at python.org Subject: RE: Distributing simple tasks Hi, Suppose I have an array of functions which I execute in threads (each thread get a slice of the array, iterates over it and executes each function in it's slice one after the other). Now I want to distribute these tasks between two machines, i.e give each machine half of the slices and let it run them in threads as described above. Is there an easy way, or an article on this matter you can point me to? Thanks, Noam I would suggest maybe a separate queue machine that would hand out each "next" function. That way if one machine takes a little longer, the faster machine can keep picking off functions and running them, while the slower machine can finish it's task. Just a thought. -------------- next part -------------- An HTML attachment was scrubbed... URL: From paul at subsignal.org Fri Feb 6 09:28:15 2009 From: paul at subsignal.org (paul) Date: Fri, 06 Feb 2009 15:28:15 +0100 Subject: ANN: SuPy - Script Sketchup with Python In-Reply-To: References: Message-ID: greg schrieb: > SuPy 1.0 > -------- > > SuPy is a plugin for the Sketchup 3D modelling application > that lets you script it in Python. Great, will give it a try. > > http://www.cosc.canterbury.ac.nz/SuPy/ I think you meant to write http://www.cosc.canterbury.ac.nz/~greg/SuPy/ > > This is a first version and is highly experimental. Let me > know if it works for you and whether you have any problems. cheers Paul From mmcclaf at gmail.com Fri Feb 6 09:30:57 2009 From: mmcclaf at gmail.com (mmcclaf) Date: Fri, 6 Feb 2009 06:30:57 -0800 (PST) Subject: Using cPickle Message-ID: Hi there, I have to make a small database using cPickle. I'm having troubles trying to read in the information if it's more than one line. I'm pretty sure it's in the line "for line in stuff:" Can anyone help me out? Basically the end result is wanting it to look something like what is down below when list is typed in: Last name First Name Email Address Doe John john at doe.com [code] # @author: Ocdt Murray McClafferty 24656 # This will manage a small database using the cPickle module. # It must maintain a list of last names, first names and email addresses, and must let a user interact with the program # #!usr/bin/python # -*- coding: utf-8 -*- import sys import cPickle # format = '%s %s %s' try: filename = sys.argv[1] input = open(filename, 'r') except IOError: print 'File is not available, will create a new file now' lastName='Last Name' firstName='First Name' email= 'Email' #input.close() output=open (filename, 'w') total = format%(lastName, firstName, email) cPickle.dump(total,output) #cPickle.dump(firstName,output) #cPickle.dump(email,output) output.close() except EOFError: print 'File is empty' #datas = cPickle.load(input) while True: command=sys.stdin.readline()[:-1] if command=='list': #lists the data in the file input = open(filename, 'r') stuff=cPickle.load(input) for line in stuff: #firstName=cPickle.load(input) #email=cPickle.load(input) #print repr (lastName).rjust(10), repr(firstName).rjust(20), repr (email).rjust(20) stuff=cPickle.load(input) print stuff print line input.close() if command=='exit' or command=='quit' : #NEVER forget the exit!!! print 'Save changes? y for Yes, n for No' commandSave=sys.stdin.readline()[:-1] if commandSave =='y': #if the user wants to save output=open(filename, 'w') cPickle.dump(work,output) output.close() sys.exit(0) if commandSave =='n': #no save input.close() sys.exit(0) if command=='add': #adds an entity to the file print 'Last name?' lastName=sys.stdin.readline()[:-1] print 'First name?' firstName=sys.stdin.readline()[:-1] print 'Email address?' email=sys.stdin.readline()[:-1] work = format%(lastName, firstName, email) #output=open(filename, 'w') #data=cPickle.load(output) #data.append(work) #output.close() output=open(filename, 'a') cPickle.dump(work,output) output.close() [/code] All help would be appreciated. I am new to Python and this seems to be quite a challenge for me. From greywine at gmail.com Fri Feb 6 09:36:00 2009 From: greywine at gmail.com (greywine at gmail.com) Date: Fri, 6 Feb 2009 06:36:00 -0800 (PST) Subject: self-aware list of objects able to sense constituent member alterations? References: <3043ae5c-0168-4249-8a21-63d0268b36f1@k36g2000pri.googlegroups.com> Message-ID: <6c42d5ee-7bd1-4741-8d80-51c611790699@z28g2000prd.googlegroups.com> On Jan 28, 4:37?am, John O'Hagan wrote: > On Tue, 27 Jan 2009, Reckoner wrote: > > I'm not sure this is possible, but I would like to have > > a list of ?objects > > > A=[a,b,c,d,...,z] > > > where, ?in the midst of a lot of processing I might do something like, > > > A[0].do_something_which_changes_the_properties() > > > which alter the properties of the object 'a'. > > > The trick is that I would like A to be mysteriously aware that > > something about the ?object 'a' has changed so that when I revisit A, > > I will know that the other items in the list need to be refreshed to > > reflect the changes in A as a result of changing 'a'. > > > Even better would be to automatically percolate the subsequent changes > > that resulted from altering 'a' for the rest of the items in the list. > > [...] > > Interesting question. > > Maybe this is too simple for your purpose (or maybe just wrong!), but could > you subclass list and give it an "update" method which keeps a dictionary of > the state of its members and/or calls another method that makes the > appropriate changes in the other members when a change occurs, something > like: > > class SelfAwareList(list): > > ? ? state_dict = {} > > ? ? def update(self): > ? ? ? ? for i in self: > ? ? ? ? ? ? if i.state == 'some_condition': > ? ? ? ? ? ? ? ? self.do_stuff_to_other_members() > ? ? ? ? ? ? self.state_dict[i] = i.state > > ? ? def do_stuff_to_other_members(self): > ? ? ? ? print 'doing stuff...' > > ? > > You could manually call update() on the SelfAwareList instance after calling a > method on a SelfAwareList member, or even build it into the members' methods > so that it was automatic. > > HTH, > > John Hi Reckoner & John O'Hagan, Great thread, very interesting. John, I haven't seen anything like your class that uses list instead of object and refers to state directly (i.state in self). Could you elaborate? Here would be my implementation of your idea: class SelfAwareList2(object): def __init__(self, l): self.l = l self.changed = [False for element in l] def __str__(self): return str(self.l) def update(self, index, value): self.l[index] = value self.changed[index] = True def do_stuff_to_other_members(self): for i in self.changed: if i==False: self.l[i] += 1 Here you can print and whenever you update your list, self.changed keeps track of what changed. Later on you can call do_stuff_to_others which in this case adds 1 to each other element. I assume that your class replaces the awkwardness of l.update(0, 5) with l[0] = 5, but I can't quite wrap my mind around it. Luther. From invalid at invalid Fri Feb 6 09:48:23 2009 From: invalid at invalid (Grant Edwards) Date: Fri, 06 Feb 2009 08:48:23 -0600 Subject: urllib2 performance on windows, usb connection References: <498beb5a$0$3305$9b622d9e@news.freenet.de> Message-ID: On 2009-02-06, Martin v. L?wis wrote: > To investigate further, you might drop the write operating, > and measure only source.read(). If that is slower, then, for > some reason, the network speed is bad on Windows. Maybe you > have the network interfaces misconfigured? Maybe you are using > wireless on Windows, but cable on Linux? Maybe you have some > network filtering software running on Windows? > Maybe it's just that Windows sucks?-) MAYBE? Good one. A friend of mine signed up for 6MB/s DSL a while back. She set up the DSL modem/WAP/firewall according to QWest's instructions and it basically worked, but her download speeds were much slower than they should have been. It turns out that the Windows drivers for the Intel WiFi chipset used in many laptops completely and utterly sucked. Her laptop and my laptop used the same WiFi chipset and neither could sustain more than about 1MB/s speeds when running Windows. I know my Windows setup was running no firewall or virus scanner software. Connecting to the DSL modem via Ethernet cable brought the download speeds up to 6MB/s. When Linux was running on either laptop, the WiFi link ran at full speed, and DSL was the bottleneck as it should have been. Windows support was just plain broken for one of the most popular WiFi chipsets (the Intel Pro 2200BG). -- Grant Edwards grante Yow! I'm wearing PAMPERS!! at visi.com From christian at dowski.com Fri Feb 6 10:17:18 2009 From: christian at dowski.com (Christian) Date: Fri, 6 Feb 2009 07:17:18 -0800 (PST) Subject: database wrapper ? References: Message-ID: On Feb 1, 5:56 pm, Stef Mientki wrote: > Is SQLalchemy the best / most popular database wrapper ? > Are there any alternatives ? As others have confirmed, SQLAlchemy is far and away the most popular Python ORM. Another one to have a look at though is Dejavu (http://www.aminus.net/ dejavu). The user community isn't nearly as large but the software itself is quite good. One of its distinctives is that you can treat multiple disparate data stores as one cohesive relational structure. It also isn't bound to SQL databases. There are storage implementations included for file system, Shelve and in-memory storage. The 2.0 alpha code in trunk also has a memcached storage implementation. HTH, Christian http://www.dowski.com From christian at dowski.com Fri Feb 6 10:24:05 2009 From: christian at dowski.com (Christian) Date: Fri, 6 Feb 2009 07:24:05 -0800 (PST) Subject: database wrapper ? References: Message-ID: On Feb 6, 10:17 am, Christian wrote: > One of its distinctives is that ... Not sure how I forgot this, but Dejavu also lets you write your datastore queries in a LINQ-like syntax. Robert Brewer, the author, is giving a talk [1] about it at this year's PyCon in the US. Christian http://www.dowski.com [1] http://pycon.org/2009/conference/talks/#proposal_link_91 From steve at holdenweb.com Fri Feb 6 10:25:57 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 06 Feb 2009 10:25:57 -0500 Subject: Using cPickle In-Reply-To: References: Message-ID: mmcclaf wrote: > Hi there, > > I have to make a small database using cPickle. I'm having troubles > trying to read in the information if it's more than one line. I'm > pretty sure it's in the line "for line in stuff:" Can anyone help me > out? Basically the end result is wanting it to look something like > what is down below when list is typed in: > > Last name First Name Email Address > Doe John > john at doe.com > > > [code] > # @author: Ocdt Murray McClafferty 24656 > # This will manage a small database using the cPickle module. > # It must maintain a list of last names, first names and email > addresses, and must let a user interact with the program > > # > #!usr/bin/python > # -*- coding: utf-8 -*- > > import sys > import cPickle > > # > format = '%s %s %s' > > try: > filename = sys.argv[1] > input = open(filename, 'r') > > except IOError: > print 'File is not available, will create a new file now' > lastName='Last Name' > firstName='First Name' > email= 'Email' > #input.close() > output=open (filename, 'w') > total = format%(lastName, firstName, email) > cPickle.dump(total,output) > #cPickle.dump(firstName,output) > #cPickle.dump(email,output) > output.close() > except EOFError: > print 'File is empty' > > #datas = cPickle.load(input) > > while True: > command=sys.stdin.readline()[:-1] > if command=='list': #lists the data in the file > input = open(filename, 'r') > stuff=cPickle.load(input) > for line in stuff: > #firstName=cPickle.load(input) > #email=cPickle.load(input) > #print repr (lastName).rjust(10), repr(firstName).rjust(20), repr > (email).rjust(20) > stuff=cPickle.load(input) > print stuff > print line > > input.close() > > if command=='exit' or command=='quit' : #NEVER forget the exit!!! > print 'Save changes? y for Yes, n for No' > commandSave=sys.stdin.readline()[:-1] > if commandSave =='y': #if the user wants to save > output=open(filename, 'w') > cPickle.dump(work,output) > output.close() > sys.exit(0) > if commandSave =='n': #no save > input.close() > sys.exit(0) > > if command=='add': #adds an entity to the file > print 'Last name?' > lastName=sys.stdin.readline()[:-1] > print 'First name?' > firstName=sys.stdin.readline()[:-1] > print 'Email address?' > email=sys.stdin.readline()[:-1] > work = format%(lastName, firstName, email) > #output=open(filename, 'w') > #data=cPickle.load(output) > #data.append(work) > #output.close() > output=open(filename, 'a') > cPickle.dump(work,output) > output.close() > > [/code] > > All help would be appreciated. I am new to Python and this seems to be > quite a challenge for me. Make sure you use modes "rb" and "wb" when you open the pickle files. If you are running on Windows this can make a difference. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at spvi.com Fri Feb 6 10:37:42 2009 From: steve at spvi.com (Steve Spicklemire) Date: Fri, 6 Feb 2009 10:37:42 -0500 Subject: ANN: SuPy - Script Sketchup with Python In-Reply-To: <6v1u4pFho98dU1@mid.individual.net> References: <6v1u4pFho98dU1@mid.individual.net> Message-ID: <0179B31A-9FF1-46C9-990A-EB5F16EFB825@spvi.com> Hi Greg, Hm... "SuPy not found on this sever." ;-( Is there a better URL.. or did I just check too soon? thanks, -steve On Feb 5, 2009, at 11:56 PM, greg wrote: > SuPy 1.0 > -------- > > SuPy is a plugin for the Sketchup 3D modelling application > that lets you script it in Python. > > http://www.cosc.canterbury.ac.nz/SuPy/ > > This is a first version and is highly experimental. Let me > know if it works for you and whether you have any problems. > > -- > Greg Ewing > greg.ewing at canterbury.ac.nz > -- > http://mail.python.org/mailman/listinfo/python-announce-list > > Support the Python Software Foundation: > http://www.python.org/psf/donations.html From linuxguy123 at gmail.com Fri Feb 6 10:49:04 2009 From: linuxguy123 at gmail.com (Linuxguy123) Date: Fri, 06 Feb 2009 08:49:04 -0700 Subject: Object explorer for python ? Message-ID: <1233935344.3876.9.camel@localhost.localdomain> Is there a (stand alone ?) object explorer for python objects such as the PyQt4 collection ? How else could I find out what is in PyQt4.QtCore, .QtGui and .QtWebKit ? Thanks From benjamin.kaplan at case.edu Fri Feb 6 10:55:09 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 6 Feb 2009 10:55:09 -0500 Subject: Python Power Point Slides In-Reply-To: References: <4041891322e2bf49ab400664bc811fae@121.100.100.103> Message-ID: On Fri, Feb 6, 2009 at 7:09 AM, Steve Holden wrote: > Tehseen Siddiqui wrote: > > ------------------------------------------------------------------------ > > > > DISCLAIMER: The information in this email is confidential and may be > > legally privileged. [... etc.] > > What information? We can't tell you. It's confidential. :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From notvalid2 at sbcglobal.net Fri Feb 6 11:01:54 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Fri, 06 Feb 2009 08:01:54 -0800 Subject: Tkinter w.pack()? In-Reply-To: References: <_Lghl.12218$D32.6047@flpi146.ffdc.sbc.com> Message-ID: ... >> > The use of "letmegooglethatforyou" (not my video tool, by the way) is to > point out that with the right search string you could have answered the > question for yourself. > > Since you didn't appear to know that Google allowed you to search a > single site (something I perhaps take for granted) I am glad that point > wasn't lost. Yes, you can just search the PIL documentation. Isn't the > Internet great? ;-) > > regards > Steve > Yes, I agree on the internet, and I now see "letme...com. So, I've now tried in my browser's link window: site:effbot.org/tkinterbook tkfiledialog, and get "site is not a registered protocol." If I put the "site:..." in the Google window,it works fine. In fact it's quite clever. I thought some months ago, I found Google commands that would operate in the browser link window. Guess not. BTW, isn't there an O'Reilly book on Google hacks of this sort? Where else does one find out about these Google tools? -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From manu3d at gmail.com Fri Feb 6 11:11:55 2009 From: manu3d at gmail.com (Emanuele D'Arrigo) Date: Fri, 6 Feb 2009 08:11:55 -0800 (PST) Subject: thread-local data Message-ID: <73694758-4504-46ca-903c-555b16a2e2a5@y23g2000pre.googlegroups.com> Hi everybody, Assuming a snippet such as: threadLocalData = threading.local() threadLocalData.myDictionary = self.myDictionary is it correct to say that threadLocalData.myDictionary is NOT a thread- local -copy- of self.myDictionary but it's actually pointing to the same object? If that's the case, and assuming I want to iterate over the dictionary without it changing under my nose while I'm in the loop, would it be better to encase the whole loop in lock-protected section or would it be better to make a copy of the dictionary first and then iterate over that one? Given that in this particular thread I do not want to modify the dictionary, conceptually a copy would work. But would making thread-local copy be just as slow as making the whole loop thread safe? Thanks for your help! Manu From gherron at islandtraining.com Fri Feb 6 11:27:14 2009 From: gherron at islandtraining.com (Gary Herron) Date: Fri, 06 Feb 2009 08:27:14 -0800 Subject: ANN: SuPy - Script Sketchup with Python In-Reply-To: <6v1u4pFho98dU1@mid.individual.net> References: <6v1u4pFho98dU1@mid.individual.net> Message-ID: <498C64E2.1050204@islandtraining.com> greg wrote: > SuPy 1.0 > -------- > > SuPy is a plugin for the Sketchup 3D modelling application > that lets you script it in Python. > > http://www.cosc.canterbury.ac.nz/SuPy/ That URL fails with a 404 - not found. (At least for me at this moment in time.) > > This is a first version and is highly experimental. Let me > know if it works for you and whether you have any problems. > From kdawg44 at gmail.com Fri Feb 6 11:28:07 2009 From: kdawg44 at gmail.com (K-Dawg) Date: Fri, 6 Feb 2009 11:28:07 -0500 Subject: WIn32api In-Reply-To: <5caea3690902060543s78b19efaxe95b63b4be89153d@mail.gmail.com> References: <5caea3690902060543s78b19efaxe95b63b4be89153d@mail.gmail.com> Message-ID: <5caea3690902060828k29e139f9g87065322610f1151@mail.gmail.com> I have come up with what I need and will try tweaking some things that hopefully will help me learn what some of this stuff does. In the meantime, I am having an issue: class *KeepAlive*(threading.Thread): def *__init__*(*self*): *self*.count = 0 *self*.ie=win32com.client.Dispatch(*'internetexplorer.application'*) *self*.ie.Visible=0 threading.Thread.__init__(*self*) def *run*(*self*): *self*.ie.Navigate(URL) sleep(5) while True: sleep(1) *self*.count += 1 *self*.timeLeft = str((300 - *self*.count)/60) + *":"* + str(( 300 - *self*.count)%60) + *" until next refresh" * print *self*.timeLeft if *self*.count == 300: *self*.ie.Refresh() *self*.count = 0 This works if I call run() specifically. But when I try to initiate the thread with .start() I get the following error Exception in thread Thread-1: Traceback (most recent call last): File "C:\Python25\lib\threading.py", line 486, in __bootstrap_inner self.run() File "C:\app.py", line 104, in run self.ie.Navigate(URL) File "C:\Python25\lib\site-packages\win32com\client\dynamic.py", line 500, in __getattr__ raise AttributeError, "%s.%s" % (self._username_, attr) AttributeError: internetexplorer.application.Navigate What does this mean? Why is it only happening when I am trying to do this in a thread? Thanks for any help. Kevin -------------- next part -------------- An HTML attachment was scrubbed... URL: From kyosohma at gmail.com Fri Feb 6 11:30:26 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Fri, 6 Feb 2009 08:30:26 -0800 (PST) Subject: Object explorer for python ? References: Message-ID: On Feb 6, 9:49?am, Linuxguy123 wrote: > Is there a (stand alone ?) object explorer for python objects such as > the PyQt4 collection ? > > How else could I find out what is in PyQt4.QtCore, .QtGui > and .QtWebKit ? > > Thanks I like WingWare for this sort of thing, but you might like eric. Links are below: http://eric-ide.python-projects.org/index.html http://www.wingware.com/ Other editors: http://wiki.python.org/moin/PythonEditors Mike From google at mrabarnett.plus.com Fri Feb 6 11:45:07 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 06 Feb 2009 16:45:07 +0000 Subject: Tkinter w.pack()? In-Reply-To: References: <_Lghl.12218$D32.6047@flpi146.ffdc.sbc.com> Message-ID: <498C6913.6020201@mrabarnett.plus.com> W. eWatson wrote: > ... >>> >> The use of "letmegooglethatforyou" (not my video tool, by the way) is to >> point out that with the right search string you could have answered the >> question for yourself. >> >> Since you didn't appear to know that Google allowed you to search a >> single site (something I perhaps take for granted) I am glad that point >> wasn't lost. Yes, you can just search the PIL documentation. Isn't the >> Internet great? ;-) >> >> regards >> Steve >> > Yes, I agree on the internet, and I now see "letme...com. So, I've now > tried in my browser's link window: > site:effbot.org/tkinterbook tkfiledialog, and get "site is not a > registered protocol." > > If I put the "site:..." in the Google window,it works fine. In fact it's > quite clever. > > I thought some months ago, I found Google commands that would operate in > the browser link window. Guess not. > > BTW, isn't there an O'Reilly book on Google hacks of this sort? Where > else does one find out about these Google tools? > Google? :-) http://www.google.com/support/websearch/bin/answer.py?hl=en&answer=136861 From google at mrabarnett.plus.com Fri Feb 6 11:56:40 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 06 Feb 2009 16:56:40 +0000 Subject: thread-local data In-Reply-To: <73694758-4504-46ca-903c-555b16a2e2a5@y23g2000pre.googlegroups.com> References: <73694758-4504-46ca-903c-555b16a2e2a5@y23g2000pre.googlegroups.com> Message-ID: <498C6BC8.5020103@mrabarnett.plus.com> Emanuele D'Arrigo wrote: > Hi everybody, > > Assuming a snippet such as: > > threadLocalData = threading.local() > threadLocalData.myDictionary = self.myDictionary > > is it correct to say that threadLocalData.myDictionary is NOT a thread- > local -copy- of self.myDictionary but it's actually pointing to the > same object? > > If that's the case, and assuming I want to iterate over the dictionary > without it changing under my nose while I'm in the loop, would it be > better to encase the whole loop in lock-protected section or would it > be better to make a copy of the dictionary first and then iterate over > that one? Given that in this particular thread I do not want to modify > the dictionary, conceptually a copy would work. But would making > thread-local copy be just as slow as making the whole loop thread > safe? > It depends on how long it takes to iterate over the dict compared with how long it takes to copy the dict. Other threads will/should be denied access during the iteration/copying and therefore block, reducing throughput. I'd probably use the snapshot approach (take a copy). From steve at holdenweb.com Fri Feb 6 12:32:14 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 06 Feb 2009 12:32:14 -0500 Subject: Tkinter w.pack()? In-Reply-To: References: <_Lghl.12218$D32.6047@flpi146.ffdc.sbc.com> Message-ID: W. eWatson wrote: > ... >>> >> The use of "letmegooglethatforyou" (not my video tool, by the way) is to >> point out that with the right search string you could have answered the >> question for yourself. >> >> Since you didn't appear to know that Google allowed you to search a >> single site (something I perhaps take for granted) I am glad that point >> wasn't lost. Yes, you can just search the PIL documentation. Isn't the >> Internet great? ;-) >> >> regards >> Steve >> > Yes, I agree on the internet, and I now see "letme...com. So, I've now > tried in my browser's link window: > site:effbot.org/tkinterbook tkfiledialog, and get "site is not a > registered protocol." > > If I put the "site:..." in the Google window,it works fine. In fact it's > quite clever. > > I thought some months ago, I found Google commands that would operate in > the browser link window. Guess not. > > BTW, isn't there an O'Reilly book on Google hacks of this sort? Where > else does one find out about these Google tools? > I seem to pick them up as I go along. This group is actually a great source of google-fu enhancements - I believe this is where I found out about "letmegooglethatforyou". Of course you can do any Google search and then look at what Google puts in your Location: bar. Saving that URL means you can repeat the same search later, but you can also analyze it to find out about some useful tricks (and "letme..." uses the same everything except for the domain name). So your site search would also work with http://www.google.com/search?q=site%3Aeffbot.org+tkinterbook%2Bpack Of course it would be relatively easy to write a Python program that used the browser module to do this kind of search ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From richardlev at gmail.com Fri Feb 6 12:47:06 2009 From: richardlev at gmail.com (Richard Levasseur) Date: Fri, 6 Feb 2009 09:47:06 -0800 (PST) Subject: Is c.l.py becoming less friendly? References: Message-ID: On Feb 5, 8:02?am, Dan Upton wrote: > On Thu, Feb 5, 2009 at 11:00 AM, mk wrote: > > > (duck) > > > 542 comp.lang.python rtfm > > > 467 comp.lang.python shut+up > > > 263 comp.lang.perl rtfm > > > 45 comp.lang.perl shut+up > > But over how many messages for each group? ?Wouldn't the percentage of > messages containing those be more interesting than the raw number? ;p As would the percent of threads that ultimately have "GIL" within the last, oh, say 20% of their messages :) From deets at nospam.web.de Fri Feb 6 13:12:18 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 06 Feb 2009 19:12:18 +0100 Subject: thread-local data In-Reply-To: <73694758-4504-46ca-903c-555b16a2e2a5@y23g2000pre.googlegroups.com> References: <73694758-4504-46ca-903c-555b16a2e2a5@y23g2000pre.googlegroups.com> Message-ID: <6v3cs2Fhovi8U1@mid.uni-berlin.de> Emanuele D'Arrigo schrieb: > Hi everybody, > > Assuming a snippet such as: > > threadLocalData = threading.local() > threadLocalData.myDictionary = self.myDictionary > > is it correct to say that threadLocalData.myDictionary is NOT a thread- > local -copy- of self.myDictionary but it's actually pointing to the > same object? Yes, it's pointing to the same object, and it thus makes the whole purpose of threadlocal moot. Use a global. > If that's the case, and assuming I want to iterate over the dictionary > without it changing under my nose while I'm in the loop, would it be > better to encase the whole loop in lock-protected section or would it > be better to make a copy of the dictionary first and then iterate over > that one? Given that in this particular thread I do not want to modify > the dictionary, conceptually a copy would work. But would making > thread-local copy be just as slow as making the whole loop thread > safe? As MRAB pointed out - it depends. My gut feeling on this is that the copy-approach is fastest. Or even faster, if you can cope with keys getting lost while processing them: for key in self.myDictionary.keys(): try: value = self.myDictionary[key] except KeyError: pass Diez From deets at nospam.web.de Fri Feb 6 13:13:05 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 06 Feb 2009 19:13:05 +0100 Subject: thread-local data In-Reply-To: <6v3cs2Fhovi8U1@mid.uni-berlin.de> References: <73694758-4504-46ca-903c-555b16a2e2a5@y23g2000pre.googlegroups.com> <6v3cs2Fhovi8U1@mid.uni-berlin.de> Message-ID: <6v3ctiFhovi8U2@mid.uni-berlin.de> Diez B. Roggisch schrieb: > Emanuele D'Arrigo schrieb: >> Hi everybody, >> >> Assuming a snippet such as: >> >> threadLocalData = threading.local() >> threadLocalData.myDictionary = self.myDictionary >> >> is it correct to say that threadLocalData.myDictionary is NOT a thread- >> local -copy- of self.myDictionary but it's actually pointing to the >> same object? > > Yes, it's pointing to the same object, and it thus makes the whole > purpose of threadlocal moot. Use a global. Scratch the "use a global" - that's of course nonsense. Use self.myDictionary directly, or wherever the dict comes from. Diez From tjreedy at udel.edu Fri Feb 6 13:23:11 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 06 Feb 2009 13:23:11 -0500 Subject: Question on Strings In-Reply-To: <0c01fc50-f20f-4981-af81-a49499acf776@q30g2000prq.googlegroups.com> References: <984064.27780.qm@web112219.mail.gq1.yahoo.com> <0c01fc50-f20f-4981-af81-a49499acf776@q30g2000prq.googlegroups.com> Message-ID: John Machin wrote: > The UTF-n siblings are *external* representations. > 2.x: a_unicode_object.decode('UTF-16') -> an_str_object > 3.x: an_str_object.decode('UTF-16') -> a_bytes_object That should be .encode() to bytes, which is the coded form. .decode is bytes => str/unicode From tjreedy at udel.edu Fri Feb 6 13:30:57 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 06 Feb 2009 13:30:57 -0500 Subject: Changing return of type(obj) In-Reply-To: References: Message-ID: Ken Elkabany wrote: > Hello, > > I am attempting to fully-simulate an 'int' object with a custom object > type. It is part of a library I am creating for python futures and > promises. Is there anyway such that type(my_object) can return 'int'>? Or for that matter, any other primitive? I do not care how dirty > the solution might possibly be; Could there be a way through the C API? > Though I predict it will cause a mess with the interpreter. type(o) == o.__class__ o.__class__ can only be rebound if and only if it is a user-class (heap type) and then only to another (compatible) user-class (heap type). From deets at nospam.web.de Fri Feb 6 13:31:10 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 06 Feb 2009 19:31:10 +0100 Subject: i have an query regarding pyodbc In-Reply-To: <519d4dd8-c9b0-44ed-bad1-5df96adf1ea7@x16g2000prn.googlegroups.com> References: <4f9834b0-98cd-486c-b91e-a6cab4d8744f@b38g2000prf.googlegroups.com> <519d4dd8-c9b0-44ed-bad1-5df96adf1ea7@x16g2000prn.googlegroups.com> Message-ID: <6v3dveFhtbfjU1@mid.uni-berlin.de> Rahul schrieb: > On Feb 6, 3:53 pm, Rahul wrote: >> On Feb 6, 11:27 am, Rahul wrote: >> >> >> >>> hello all, >>> I have installed pyodbc on my red hat enterprise 4 linux machine but >>> when i go to use that using statement, >>> import pyodbc >>> through python console it gives me error as >>> ImportError : dynamic module does not define init function >>> (initpyodbc) >>> and when i do 'nm pyodbc.so' command i get output as >>> [root at dbserver site-packages]# nm pyodbc.so 00001600 A __bss_start >>> 000003ec t call_gmon_start 00001600 b completed.1 000014fc d >>> __CTOR_END__ >>> 000014f8 d __CTOR_LIST__ >>> w __cxa_finalize@@GLIBC_2.1.3 >>> 000004a8 t __do_global_ctors_aux >>> 00000410 t __do_global_dtors_aux >>> 000015f8 d __dso_handle >>> 00001504 d __DTOR_END__ >>> 00001500 d __DTOR_LIST__ >>> 0000150c A _DYNAMIC >>> 00001600 A _edata >>> 00001604 A _end >>> 000004d8 T _fini >>> 0000046c t frame_dummy >>> 000004f4 r __FRAME_END__ >>> 000015e8 A _GLOBAL_OFFSET_TABLE_ >>> w __gmon_start__ >>> 000003b4 T _init >>> 00001508 d __JCR_END__ >>> 00001508 d __JCR_LIST__ >>> w _Jv_RegisterClasses >>> 000015fc d p.0 >>> which means there is no init function. >>> So what might be the cause for that? >>> I have build that pyodbc twice. >>> Any help regarding this will be greatly appreciated. >>> Thanks & Regards >>> Rahul >> this problem was due to not proper building of pyodbc > > Now my problem was, > i have two versions of python installed at different locations but > when i use import statement from psp pages > it displays the error as > ImportError : dynamic module does not define init function(initpyodbc) > > this error was due to pointing to older version of python. > > So, i want to know how to point my import statements to the new > version of python. The problem are not the imports, the problem is the used interpreter. How is PSP integrated into your webserver? Diez From Scott.Daniels at Acm.Org Fri Feb 6 13:36:37 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 06 Feb 2009 10:36:37 -0800 Subject: What is difference between ADO and RDO In-Reply-To: References: <0f03c29f-04df-433b-8ea9-01be1acfa7cf@v39g2000pro.googlegroups.com> Message-ID: OdarR wrote: > On 6 f?v, 10:56, Agile Consulting wrote: >> Explain ADO and RDO > > RU a bot ? I expect someone is experimenting with their spam generator. From deets at nospam.web.de Fri Feb 6 13:42:36 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 06 Feb 2009 19:42:36 +0100 Subject: Have you ever thought to know your intelligence level? In-Reply-To: <1f832722-d2f1-4596-a27c-69e666bbf6cd@y38g2000prg.googlegroups.com> References: <29506468-3b1d-46c0-acba-15c4d5665954@x6g2000pre.googlegroups.com> <8f4ff01d-7660-4d71-b812-acb5acfb4671@u18g2000pro.googlegroups.com> <1f832722-d2f1-4596-a27c-69e666bbf6cd@y38g2000prg.googlegroups.com> Message-ID: <6v3eksFhv2c3U1@mid.uni-berlin.de> > > His IQ must suck considering all the spelling errors....or is that not > also a measure of one's IQ? I'm pretty sure there is a legasthenic nobel prize winner out there... so *if* it were a measure of IQ, it would make the whole affair even more braindead. I'd rather say he is of limited intelligence because he tries to convince us that his spam actually *isn't* spam... Diez From tjreedy at udel.edu Fri Feb 6 13:49:32 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 06 Feb 2009 13:49:32 -0500 Subject: Distributing simple tasks In-Reply-To: <749CACF29BDFB64E9F80189ECD77868804C00A8C@jermail1.atomant.net> References: <749CACF29BDFB64E9F80189ECD77868804C00A8C@jermail1.atomant.net> Message-ID: Noam Aigerman wrote: > Hi, > > Suppose I have an array of functions which I execute in threads (each > thread get a slice of the array, iterates over it and executes each > function in it?s slice one after the other). Now I want to distribute > these tasks between two machines, i.e give each machine half of the > slices and let it run them in threads as described above. Is there an > easy way, or an article on this matter you can point me to? Here is a standard approach that is slightly more general than you specified. It will work with more than two cores or machines. Write master/server program that reads data, listens to socket for calls from worker/client programs, splits work into multiple tasks, sends them out to workers, and collects and re-assembles the results. After a timeout, it should be able to reassign tasks not returned. Write worker/client program than calls master, gets task, completes it, and returns result. Assume all data is on machine A. Start master and worker on machine A. Start worker(s) on other cores or machines. You can either use socket module directly or use networking modules built on top of it. Twisted and pyro are two that come to mind immediately. I have seen code examples but do not remember where. Note: I do not see any advantage to having multiple compute-bound threads, as you seem to describe. Terry Jan Reedy From aioe.org at technicalbloke.com Fri Feb 6 13:50:05 2009 From: aioe.org at technicalbloke.com (r0g) Date: Fri, 06 Feb 2009 13:50:05 -0500 Subject: Returning a variable number of things... Message-ID: Hi There, I have a function that uses *args to accept a variable number of parameters and I would like it to return a variable number of objects. I could return a list but I would like to take advantage of tuple unpacking with the return values e.g. def unpack_struct( a_string, *args ): output_vars = [] for each in *args: <<< build a list of output values >>> return <<< the tuple equivalent of this list >>> ip, meat, zipcode = unpack_struct( "192.168.001.001Ham22132", 15, 3, 5 ) Thanks, Roger. From tjreedy at udel.edu Fri Feb 6 13:54:07 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 06 Feb 2009 13:54:07 -0500 Subject: updating nntplib In-Reply-To: References: <20090205224036.GH29170@subspacefield.org> Message-ID: Gerhard H?ring wrote: > Travis wrote: >> Hello all, >> >> There are some notable deficiencies in nntlib. Here are two: [...] > > Be sure to add a bug report/patch to the Python bug tracker. > > http://bugs.python.org/ > > Anything else will most likely be overlooked or forgotten. It is my impression that nntplib was and maybe still is a bit flakey on 3.0. 3.0.1 will be out this month and may or may not have improvements. I am fairly sure that updating it to a newer RFC would be welcome. Such upgrades have happened to other protocol modules when there has been someone willing to do the work. Please do check the tracker for existing nntplib issues and add one if appropriate. tjr From clp2 at rebertia.com Fri Feb 6 13:57:10 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 6 Feb 2009 10:57:10 -0800 Subject: Returning a variable number of things... In-Reply-To: References: Message-ID: <50697b2c0902061057h32ae0aes12ae96cad54cde6f@mail.gmail.com> On Fri, Feb 6, 2009 at 10:50 AM, r0g wrote: > Hi There, > > I have a function that uses *args to accept a variable number of > parameters and I would like it to return a variable number of objects. > > I could return a list but I would like to take advantage of tuple > unpacking with the return values e.g. Despite its name, tuple unpacking works with lists too. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From apt.shansen at gmail.com Fri Feb 6 13:57:45 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Fri, 6 Feb 2009 10:57:45 -0800 Subject: Returning a variable number of things... In-Reply-To: References: Message-ID: <7a9c25c20902061057h251c459eg43d7ffd906996d9c@mail.gmail.com> On Fri, Feb 6, 2009 at 10:50 AM, r0g wrote: > Hi There, > > I have a function that uses *args to accept a variable number of > parameters and I would like it to return a variable number of objects. > > I could return a list but I would like to take advantage of tuple > unpacking with the return values e.g. Just return the list :) It'll unpack any sequence, not just tuples. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From mmcclaf at gmail.com Fri Feb 6 14:05:36 2009 From: mmcclaf at gmail.com (mmcclaf) Date: Fri, 6 Feb 2009 11:05:36 -0800 (PST) Subject: Using cPickle References: Message-ID: <4d5ead6c-4e8a-4003-86c6-519a638da1e1@y38g2000prg.googlegroups.com> On Feb 6, 10:25?am, Steve Holden wrote: > mmcclaf wrote: > > Hi there, > > > I have to make a small database using cPickle. I'm having troubles > > trying to read in the information if it's more than one line. I'm > > pretty sure it's in the line "for line in stuff:" Can anyone help me > > out? Basically the end result is wanting it to look something like > > what is down below when list is typed in: > > > Last name ? ? ? ? ? ? ? ? First Name ? ? ? ? ? ? ? ?Email Address > > Doe ? ? ? ? ? ? ? ? ? ? ? ? ?John > > j... at doe.com > > > [code] > > # @author: Ocdt Murray McClafferty 24656 > > # This will manage a small database using the cPickle module. > > # It must maintain a list of last names, first names and email > > addresses, and must let a user interact with the program > > > # > > #!usr/bin/python > > # -*- coding: utf-8 -*- > > > import sys > > import cPickle > > > # > > format = '%s ? ? ? ? ? ? %s ? ? ? ? ? ? ? ? ?%s' > > > try: > > ? ?filename = sys.argv[1] > > ? ?input = open(filename, 'r') > > > except IOError: > > ? ?print 'File is not available, will create a new file now' > > ? ?lastName='Last Name' > > ? ?firstName='First Name' > > ? ?email= 'Email' > > ? ?#input.close() > > ? ?output=open (filename, 'w') > > ? ?total = format%(lastName, firstName, email) > > ? ?cPickle.dump(total,output) > > ? ?#cPickle.dump(firstName,output) > > ? ?#cPickle.dump(email,output) > > ? ?output.close() > > except EOFError: > > ? ?print 'File is empty' > > > #datas = cPickle.load(input) > > > while True: > > ? ?command=sys.stdin.readline()[:-1] > > ? ?if command=='list': #lists the data in the file > > ? ? ? ? ? ?input = open(filename, 'r') > > ? ? ? ? ? ?stuff=cPickle.load(input) > > ? ? ? ? ? ?for line in stuff: > > ? ? ? ? ? ? ? ? ? ?#firstName=cPickle.load(input) > > ? ? ? ? ? ? ? ? ? ?#email=cPickle.load(input) > > ? ? ? ? ? ? ? ? ? ?#print repr (lastName).rjust(10), repr(firstName).rjust(20), repr > > (email).rjust(20) > > ? ? ? ? ? ? ? ? ? ?stuff=cPickle.load(input) > > ? ? ? ? ? ? ? ? ? ?print stuff > > ? ? ? ? ? ? ? ? ? ?print line > > > ? ? ? ? ? ?input.close() > > > ? ?if command=='exit' or command=='quit' : #NEVER forget the exit!!! > > ? ? ? ? ? ?print 'Save changes? y for Yes, n for No' > > ? ? ? ? ? ?commandSave=sys.stdin.readline()[:-1] > > ? ? ? ? ? ?if commandSave =='y': #if the user wants to save > > ? ? ? ? ? ? ? ? ? ?output=open(filename, 'w') > > ? ? ? ? ? ? ? ? ? ?cPickle.dump(work,output) > > ? ? ? ? ? ? ? ? ? ?output.close() > > ? ? ? ? ? ? ? ? ? ?sys.exit(0) > > ? ? ? ? ? ?if commandSave =='n': #no save > > ? ? ? ? ? ? ? ? ? ?input.close() > > ? ? ? ? ? ? ? ? ? ?sys.exit(0) > > > ? ?if command=='add': #adds an entity to the file > > ? ? ? ? ? ?print 'Last name?' > > ? ? ? ? ? ?lastName=sys.stdin.readline()[:-1] > > ? ? ? ? ? ?print 'First name?' > > ? ? ? ? ? ?firstName=sys.stdin.readline()[:-1] > > ? ? ? ? ? ?print 'Email address?' > > ? ? ? ? ? ?email=sys.stdin.readline()[:-1] > > ? ? ? ? ? ?work = format%(lastName, firstName, email) > > ? ? ? ? ? ?#output=open(filename, 'w') > > ? ? ? ? ? ?#data=cPickle.load(output) > > ? ? ? ? ? ?#data.append(work) > > ? ? ? ? ? ?#output.close() > > ? ? ? ? ? ?output=open(filename, 'a') > > ? ? ? ? ? ?cPickle.dump(work,output) > > ? ? ? ? ? ?output.close() > > > [/code] > > > All help would be appreciated. I am new to Python and this seems to be > > quite a challenge for me. > > Make sure you use modes "rb" and "wb" when you open the pickle files. If > you are running on Windows this can make a difference. > > regards > ?Steve > -- > Steve Holden ? ? ? ?+1 571 484 6266 ? +1 800 494 3119 > Holden Web LLC ? ? ? ? ? ? ?http://www.holdenweb.com/ I've tried both rb and wb as well as r and w, there appears to be no difference in the running of the code. From Olivier.Darge at gmail.com Fri Feb 6 14:13:32 2009 From: Olivier.Darge at gmail.com (OdarR) Date: Fri, 6 Feb 2009 11:13:32 -0800 (PST) Subject: What is difference between ADO and RDO References: <0f03c29f-04df-433b-8ea9-01be1acfa7cf@v39g2000pro.googlegroups.com> Message-ID: <23ea9cc9-78d0-46d8-be1f-6dcd959c6b04@p36g2000prp.googlegroups.com> On 6 f?v, 19:36, Scott David Daniels wrote: > OdarR wrote: > > On 6 f?v, 10:56, Agile Consulting wrote: > >> Explain ADO and RDO > > > RU a bot ? > > I expect someone is experimenting with their spam generator. An agile one :) Olivier From wimmersimon at googlemail.com Fri Feb 6 14:34:58 2009 From: wimmersimon at googlemail.com (SiWi) Date: Fri, 6 Feb 2009 11:34:58 -0800 (PST) Subject: Parallel port interfacing in python on Vista x64 Message-ID: <162a8d2c-04a6-4b26-a36c-48a638f72349@r15g2000prd.googlegroups.com> I have done some googling on this topic, but I haven't found anything thats really working on Vista x64. The most promising result I found was the Inpout32.dll: http://logix4u.net/Legacy_Ports/Parallel_Port/A_tutorial_on_Parallel_port_Interfacing.html But when using some code like that, I can't measure I differing state on my breadboard circurity: from ctypes import windll p = windll.inpout32 p.Inp32(0x378) #default 255(all high) on my pc p.Out32(0x378, 0) #put all low on port 2-9 Is it even possible to interface the Parallel Port on Vista64, and if so, how does one do that? From otsaloma at cc.hut.fi Fri Feb 6 14:39:51 2009 From: otsaloma at cc.hut.fi (Osmo Salomaa) Date: Fri, 06 Feb 2009 21:39:51 +0200 Subject: Installation directory for extensions on Unix Message-ID: <1233949191.3825.9.camel@stoa.kyla.fi> I have written an extension (a.k.a. plugin or add-on, not C-extension) system for my application and I'm going to ship two extensions with it. Each extension is in a directory of its own and that directory contains Python files and various data files, e.g. Glade XML files and PNG icons. Where should I install these extension directories on a Unix system? $PREFIX/share/foo or $PREFIX/lib/foo? How do I handle compiling with distutils if installing Python code outside the default site-packages directory? Importing these extensions is handled by listing the contents of the extension directory and using __import__ on the specified files, so the installation directory does not need to be anywhere near $PYTHONPATH. -- Osmo Salomaa From thudfoo at opensuse.us Fri Feb 6 14:48:18 2009 From: thudfoo at opensuse.us (member thudfoo) Date: Fri, 6 Feb 2009 11:48:18 -0800 Subject: ANN: SuPy - Script Sketchup with Python In-Reply-To: <498C64E2.1050204@islandtraining.com> References: <6v1u4pFho98dU1@mid.individual.net> <498C64E2.1050204@islandtraining.com> Message-ID: <3d881a310902061148k251466eay57562acb1d51c812@mail.gmail.com> On Fri, Feb 6, 2009 at 8:27 AM, Gary Herron wrote: > greg wrote: >> SuPy 1.0 >> -------- >> >> SuPy is a plugin for the Sketchup 3D modelling application >> that lets you script it in Python. >> >> http://www.cosc.canterbury.ac.nz/SuPy/ > > > That URL fails with a 404 - not found. (At least for me at this moment > in time.) > > >> >> This is a first version and is highly experimental. Let me >> know if it works for you and whether you have any problems. >> > > -- > http://mail.python.org/mailman/listinfo/python-list > This URL works: http://www.cosc.canterbury.ac.nz/greg.ewing/SuPy/ From manu3d at gmail.com Fri Feb 6 14:53:44 2009 From: manu3d at gmail.com (Emanuele D'Arrigo) Date: Fri, 6 Feb 2009 11:53:44 -0800 (PST) Subject: thread-local data References: <73694758-4504-46ca-903c-555b16a2e2a5@y23g2000pre.googlegroups.com> <6v3cs2Fhovi8U1@mid.uni-berlin.de> <6v3ctiFhovi8U2@mid.uni-berlin.de> Message-ID: <707009a2-33d7-48f9-bf0d-0c7e13e19f94@a12g2000pro.googlegroups.com> Thank you both MRAB and Diez. I think I'll stick to making copies inside a thread-protected section unless I need to speed up things, at which point I might go for the key exception path. Thank you again! Manu From deets at nospam.web.de Fri Feb 6 14:55:43 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 06 Feb 2009 20:55:43 +0100 Subject: Parallel port interfacing in python on Vista x64 In-Reply-To: <162a8d2c-04a6-4b26-a36c-48a638f72349@r15g2000prd.googlegroups.com> References: <162a8d2c-04a6-4b26-a36c-48a638f72349@r15g2000prd.googlegroups.com> Message-ID: <6v3iu0Fi5knrU1@mid.uni-berlin.de> SiWi schrieb: > I have done some googling on this topic, but I haven't found anything > thats really working on Vista x64. > The most promising result I found was the Inpout32.dll: > http://logix4u.net/Legacy_Ports/Parallel_Port/A_tutorial_on_Parallel_port_Interfacing.html > But when using some code like that, I can't measure I differing state > on my breadboard circurity: > from ctypes import windll > p = windll.inpout32 > p.Inp32(0x378) #default 255(all high) on my pc > p.Out32(0x378, 0) #put all low on port 2-9 > > Is it even possible to interface the Parallel Port on Vista64, and if > so, how does one do that? Did you try pyparallel? Diez From curt.hash at gmail.com Fri Feb 6 15:03:23 2009 From: curt.hash at gmail.com (Curt Hash) Date: Fri, 6 Feb 2009 13:03:23 -0700 Subject: Fastest database solution In-Reply-To: References: <736698790902060010x4263cb2cp643bbc63398f56f5@mail.gmail.com> Message-ID: <736698790902061203p7fa5f22cw982e70876b4745c6@mail.gmail.com> On Fri, Feb 6, 2009 at 2:12 AM, Roger Binns wrote: > > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Curt Hash wrote: > > I started out using sqlite3, but was not satisfied with the performance > > results. I then tried using psycopg2 with a local postgresql server, and > > the performance got even worse. > > SQLite is in the same process. Communication with postgres is via > another process so marshalling the traffic and context switches will > impose overhead as you found. > > > I don't think > > my code/queries are inherently slow, but I'm not a DBA or a very > > accomplished Python developer, so I could be wrong. > > It doesn't sound like a database is the best solution to your issue > anyway. A better solution would likely be some form of hashing the > lines and storing something that gives quick hash lookups. The hash > would have to do things like not care what variable names are used etc. > > There are already lots of plagiarism detectors out there so it may be > more prudent using one of them, or at least learn how they do things so > your own system could improve on them. Currently, I am stripping extra whitespace and end-of-line characters from each line of source code and storing that in addition to its hash in a table. That table is used for exact-match comparisons. I am also passing the source code through flex/bison to canonicalize identifiers -- the resulting lines are also hashed and stored in a table. That table is used for structural matching. Both tables are queried to find matching hashes. I'm not sure how I could make the hash lookups faster... On my small test dataset, this solution has detected all of the plagiarism with high confidence. It's also beneficial to me to use this Python application as I can easily integrate it with other Python scripts I use to prepare code for review. > > Roger > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.9 (GNU/Linux) > > iEYEARECAAYFAkmL/wgACgkQmOOfHg372QTAmACg0INMfUKA10Uc6UJwNhYhDeoV > EKwAoKpDMRzr7GzCKeYxn93TU69nDx4X > =4r01 > -----END PGP SIGNATURE----- > > -- > http://mail.python.org/mailman/listinfo/python-list From wimmersimon at googlemail.com Fri Feb 6 15:03:50 2009 From: wimmersimon at googlemail.com (SiWi) Date: Fri, 6 Feb 2009 12:03:50 -0800 (PST) Subject: Parallel port interfacing in python on Vista x64 References: <162a8d2c-04a6-4b26-a36c-48a638f72349@r15g2000prd.googlegroups.com> <6v3iu0Fi5knrU1@mid.uni-berlin.de> Message-ID: <2aa2e6d0-b217-4f76-912c-240511505c12@g1g2000pra.googlegroups.com> On Feb 6, 8:55?pm, "Diez B. Roggisch" wrote: > SiWi schrieb: > > > I have done some googling on this topic, but I haven't found anything > > thats really working on Vista x64. > > The most promising result I found was the Inpout32.dll: > >http://logix4u.net/Legacy_Ports/Parallel_Port/A_tutorial_on_Parallel_... > > But when using some code like that, I can't measure I differing state > > on my breadboard circurity: > > from ctypes import windll > > p = windll.inpout32 > > p.Inp32(0x378) #default 255(all high) on my pc > > p.Out32(0x378, 0) #put all low on port 2-9 > > > Is it even possible to interface the Parallel Port on Vista64, and if > > so, how does one do that? > > Did you try pyparallel? > > Diez Yep, but when trying to make a instance of the Parallel class I get an windows error. From google at mrabarnett.plus.com Fri Feb 6 15:09:03 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 06 Feb 2009 20:09:03 +0000 Subject: Using cPickle In-Reply-To: <4d5ead6c-4e8a-4003-86c6-519a638da1e1@y38g2000prg.googlegroups.com> References: <4d5ead6c-4e8a-4003-86c6-519a638da1e1@y38g2000prg.googlegroups.com> Message-ID: <498C98DF.5080507@mrabarnett.plus.com> mmcclaf wrote: > On Feb 6, 10:25 am, Steve Holden wrote: >> mmcclaf wrote: >>> Hi there, >>> I have to make a small database using cPickle. I'm having troubles >>> trying to read in the information if it's more than one line. I'm >>> pretty sure it's in the line "for line in stuff:" Can anyone help me >>> out? Basically the end result is wanting it to look something like >>> what is down below when list is typed in: >>> Last name First Name Email Address >>> Doe John >>> j... at doe.com >>> [code] >>> # @author: Ocdt Murray McClafferty 24656 >>> # This will manage a small database using the cPickle module. >>> # It must maintain a list of last names, first names and email >>> addresses, and must let a user interact with the program >>> # >>> #!usr/bin/python >>> # -*- coding: utf-8 -*- >>> import sys >>> import cPickle >>> # >>> format = '%s %s %s' >>> try: >>> filename = sys.argv[1] >>> input = open(filename, 'r') >>> except IOError: >>> print 'File is not available, will create a new file now' >>> lastName='Last Name' >>> firstName='First Name' >>> email= 'Email' >>> #input.close() >>> output=open (filename, 'w') >>> total = format%(lastName, firstName, email) >>> cPickle.dump(total,output) >>> #cPickle.dump(firstName,output) >>> #cPickle.dump(email,output) >>> output.close() >>> except EOFError: >>> print 'File is empty' >>> #datas = cPickle.load(input) >>> while True: >>> command=sys.stdin.readline()[:-1] >>> if command=='list': #lists the data in the file >>> input = open(filename, 'r') >>> stuff=cPickle.load(input) >>> for line in stuff: >>> #firstName=cPickle.load(input) >>> #email=cPickle.load(input) >>> #print repr (lastName).rjust(10), repr(firstName).rjust(20), repr >>> (email).rjust(20) >>> stuff=cPickle.load(input) >>> print stuff >>> print line >>> input.close() >>> if command=='exit' or command=='quit' : #NEVER forget the exit!!! >>> print 'Save changes? y for Yes, n for No' >>> commandSave=sys.stdin.readline()[:-1] >>> if commandSave =='y': #if the user wants to save >>> output=open(filename, 'w') >>> cPickle.dump(work,output) >>> output.close() >>> sys.exit(0) >>> if commandSave =='n': #no save >>> input.close() >>> sys.exit(0) >>> if command=='add': #adds an entity to the file >>> print 'Last name?' >>> lastName=sys.stdin.readline()[:-1] >>> print 'First name?' >>> firstName=sys.stdin.readline()[:-1] >>> print 'Email address?' >>> email=sys.stdin.readline()[:-1] >>> work = format%(lastName, firstName, email) >>> #output=open(filename, 'w') >>> #data=cPickle.load(output) >>> #data.append(work) >>> #output.close() >>> output=open(filename, 'a') >>> cPickle.dump(work,output) >>> output.close() >>> [/code] >>> All help would be appreciated. I am new to Python and this seems to be >>> quite a challenge for me. >> Make sure you use modes "rb" and "wb" when you open the pickle files. If >> you are running on Windows this can make a difference. >> >> regards >> Steve >> -- >> Steve Holden +1 571 484 6266 +1 800 494 3119 >> Holden Web LLC http://www.holdenweb.com/ > > I've tried both rb and wb as well as r and w, there appears to be no > difference in the running of the code. > "cPickle.dump(work,output)" writes a string and "stuff=cPickle.load(input)" just reads that string, so "for line in stuff:" is iterating through the characters if the string. You need to use cPickle.load() to read each string (line). From curt.hash at gmail.com Fri Feb 6 15:09:41 2009 From: curt.hash at gmail.com (Curt Hash) Date: Fri, 6 Feb 2009 13:09:41 -0700 Subject: Fastest database solution In-Reply-To: <498C2AEB.1010907@egenix.com> References: <736698790902060010x4263cb2cp643bbc63398f56f5@mail.gmail.com> <498C2AEB.1010907@egenix.com> Message-ID: <736698790902061209r207d7e03lc6fe1afd92bfef2a@mail.gmail.com> On Fri, Feb 6, 2009 at 5:19 AM, M.-A. Lemburg wrote: > On 2009-02-06 09:10, Curt Hash wrote: >> I'm writing a small application for detecting source code plagiarism that >> currently relies on a database to store lines of code. >> >> The application has two primary functions: adding a new file to the database >> and comparing a file to those that are already stored in the database. >> >> I started out using sqlite3, but was not satisfied with the performance >> results. I then tried using psycopg2 with a local postgresql server, and the >> performance got even worse. My simple benchmarks show that sqlite3 is an >> average of 3.5 times faster at inserting a file, and on average less than a >> tenth of a second slower than psycopg2 at matching a file. >> >> I expected postgresql to be a lot faster ... is there some peculiarity in >> psycopg2 that could be causing slowdown? Are these performance results >> typical? Any suggestions on what to try from here? I don't think my >> code/queries are inherently slow, but I'm not a DBA or a very accomplished >> Python developer, so I could be wrong. >> >> Any advice is appreciated. > > In general, if you do bulk insert into a large table, you should consider > turning off indexing on the table and recreate/update the indexes in one > go afterwards. > > But regardless of this detail, I think you should consider a filesystem > based approach. This is going to be a lot faster than using a > database to store the source code line by line. You can still use > a database for the administration and indexing of the data, e.g. > by storing a hash of each line in the database. > I can see how reconstructing source code from individual lines in the database would be much slower than a filesystem-based approach. However, what is of particular importance is that the matching itself be fast. While the original lines of code are stored in the database, I am performing matching based on only hashes. Would storing the original code in the same table as the hash cause significant slowdown if I am querying by hash only? I think I may try this approach anyways, just to make retrieving the original source code after finding a match faster, but I am still primarily concerned with the speed of the hash lookups. > -- > Marc-Andre Lemburg > eGenix.com > > Professional Python Services directly from the Source (#1, Feb 06 2009) >>>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ > ________________________________________________________________________ > > ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: > > > eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 > D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg > Registered at Amtsgericht Duesseldorf: HRB 46611 > http://www.egenix.com/company/contact/ > From bthayre at physics.ucsd.edu Fri Feb 6 15:31:08 2009 From: bthayre at physics.ucsd.edu (Robocop) Date: Fri, 6 Feb 2009 12:31:08 -0800 (PST) Subject: Trouble sorting a list of objects by attributes Message-ID: <49ddc228-c4ef-48b2-8fce-70f9e881e216@o40g2000prn.googlegroups.com> Hello again, I've found myself stumped when trying to organize this list of objects. The objects in question are timesheets which i'd like to sort by four attributes: class TimeSheet: department = string engagement = string date = datetime.date stare_hour = datetime.time My ultimate goal is to have a list of this timesheet objects which are first sorted by departments, then within each department block of the list, have it organized by projects. Within each project block i finally want them sorted chronologically by date and time. To sort the strings i tried: timesheets.sort(key=operator.attrgetter('string')) which is not doing anything to my list unfortunately; it leaves it untouched. Giving up on that i tried to sort the dates or times using: def sorter_time(a,b): if a.engagement == engagement: # I only want sorting done within each engagement block return cmp(a.start, b.start) return 0 timesheets.sort(sorter_time) But this also did nothing to my list, and at this point i'm incredibly confused. From what i know of the involved functions, i would think that these lines of code (while they wouldn't do exactly what i want yet) would at least do something to my lists. Any explanations, or suggestions for a different approach would be greatly appreciated. My brain might explode if i continue. From miki.tebeka at gmail.com Fri Feb 6 15:56:25 2009 From: miki.tebeka at gmail.com (Miki) Date: Fri, 6 Feb 2009 12:56:25 -0800 (PST) Subject: Trouble sorting a list of objects by attributes References: <49ddc228-c4ef-48b2-8fce-70f9e881e216@o40g2000prn.googlegroups.com> Message-ID: <0898369a-495e-44f3-8771-c26daf48db39@40g2000prx.googlegroups.com> > I've found myself stumped when trying to organize this list of > objects. ?The objects in question are timesheets which i'd like to > sort by four attributes: > > class TimeSheet: > ? department = string > ? engagement = string > ? date = datetime.date > ? stare_hour = datetime.time > > My ultimate goal is to have a list of this timesheet objects which are > first sorted by departments, then within each department block of the > list, have it organized by projects. ?Within each project block i > finally want them sorted chronologically by date and time. Python "natural" sort for tuples is doing the right thing for you, for example: from operator import attrgetter from random import randint class Point: def __init__(self, x, y): self.x = x self.y = y def __repr__(self): return "(%s, %s)" % (self.x, self.y) points = [Point(randint(1, 10), randint(1, 10)) for i in range(10)] print points points.sort(key=attrgetter("x", "y")) print points Gave me: [(2, 3), (1, 4), (4, 4), (6, 6), (2, 10), (3, 5), (7, 1), (3, 6), (4, 1), (9, 6)] [(1, 4), (2, 3), (2, 10), (3, 5), (3, 6), (4, 1), (4, 4), (6, 6), (7, 1), (9, 6)] Points first sorted by 'x' and then by 'y'. HTH, -- Miki http://pythonwise.blogspot.com From rdmurray at bitdance.com Fri Feb 6 15:58:10 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Fri, 6 Feb 2009 20:58:10 +0000 (UTC) Subject: Trouble sorting a list of objects by attributes References: <49ddc228-c4ef-48b2-8fce-70f9e881e216@o40g2000prn.googlegroups.com> Message-ID: Quoth Robocop : > Hello again, > I've found myself stumped when trying to organize this list of > objects. The objects in question are timesheets which i'd like to > sort by four attributes: > > class TimeSheet: > department = string > engagement = string > date = datetime.date > stare_hour = datetime.time > > My ultimate goal is to have a list of this timesheet objects which are > first sorted by departments, then within each department block of the > list, have it organized by projects. Within each project block i > finally want them sorted chronologically by date and time. > > To sort the strings i tried: > > timesheets.sort(key=operator.attrgetter('string')) > > which is not doing anything to my list unfortunately; it leaves it > untouched. Python 2.6.1 (r261:67515, Jan 7 2009, 17:09:13) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> class Timesheet(object): ... def __init__(self, department): self.department=department ... def __repr__(self): return "Timesheet(%s)" % self.department ... >>> timesheets = [Timesheet('abc'), Timesheet('def'), Timesheet('acd')] >>> timesheets [Timesheet(abc), Timesheet(def), Timesheet(acd)] >>> import operator >>> timesheets.sort(key=operator.attrgetter('department')) >>> timesheets [Timesheet(abc), Timesheet(acd), Timesheet(def)] The key bit here being the argument to attrgetter, which is the name of the attribute to use as they key. --RDM From andrew.replogle at gmail.com Fri Feb 6 15:58:40 2009 From: andrew.replogle at gmail.com (Andrew) Date: Fri, 6 Feb 2009 12:58:40 -0800 (PST) Subject: subprocess returncode windows References: <18348eae-5af1-47e9-a198-b95d4fcb6eac@a12g2000pro.googlegroups.com> <851774bd-5019-4347-8815-36782dcec4b6@p2g2000prf.googlegroups.com> Message-ID: <8ac1c027-3bd4-43ae-99a9-012462cb06d7@r37g2000prr.googlegroups.com> On Feb 5, 9:17?pm, "Gabriel Genellina" wrote: > En Thu, 05 Feb 2009 17:34:29 -0200, Andrew ? > escribi?: > > > > > On Dec 16 2008, 5:11?pm, "Gabriel Genellina" > > wrote: > >> En Tue, 16 Dec 2008 17:21:35 -0200, Andrew ? > >> escribi?: > > >> > On Dec 16, 12:50?pm, Christian Heimes wrote: > >> >> Andrew schrieb: > > >> >> > I'm running into a strange situation with getting incorrect > >> >> > returncodes / exit status from python subprocess.call. I'm using a > >> >> > python script (runtime 2.6.1 on windows) to automate the deploy of > >> >> > java applications to glassfish application server. Below is an >> ? > >> > example > > I've tried this several ways now. It seems to be something specific > > with python and asadmin.bat. > > > I've tried the following manually in the cmd.exe prompt: > > [examples showing %ERRORLEVEL% correctly set when running from the command ? > line, but subprocess.call doesn't get it] > > > Notice how python never gets the correct returncode from asadmin.bat > > but I can get the correct returncode from the shell every time. Can > > anyone tell me why Python wouldn't be able to get the correct > > returncode for asadmin? > > The last exit code set by a command *should* propagate as the exit code of ? > the whole .bat, then as the exit code of the cmd.exe instance that runs ? > it, and finally Python *should* receive that value. Some old Windows ? > versions didn't behave like that, but AFAIK XP does the right thing here. > Unless asadmin.bat is playing tricks with %ERRORLEVEL% or something. > Can you post the contents of asadmin.bat? > > Without looking into it, I can think of a few alternatives: > > - rewrite asadmin.bat in Python, if feasible. Some scripts just check/set ? > a few environment variables and execute some process at the end, and ? > that's all; in this case it should be easy to emulate the same thing in ? > Python. > > - try using another layer of your own, e.g., my_asadmin.bat: > > call asadmin.bat %* > exit /b %ERRORLEVEL% > > - variation: write the exit code somewhere: > > call asadmin.bat %* > echo %ERRORLEVEL% > asadmin.err > > and read asadmin.err from Python. (I've used something like this in a ? > chain Win32 process --> 16 bits GUI application --> .bat script --> old ? > DOS executable) > > -- > Gabriel Genellina Thanks Gabriel, Someone on the glassfish forums also pointed out the "exit /B %ERRORLEVEL%" for the bottom of the batch file and that corrected the issue for me. As well as not using that and removing "endlocal" which I admit I have no clue what that does. Removing endlocal seems to cause the batch script to pass out the correct returncode. Thanks everyone for your input and assistance =] Andrew From bearophileHUGS at lycos.com Fri Feb 6 16:03:32 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Fri, 6 Feb 2009 13:03:32 -0800 (PST) Subject: Trouble sorting a list of objects by attributes References: <49ddc228-c4ef-48b2-8fce-70f9e881e216@o40g2000prn.googlegroups.com> Message-ID: <20261325-e75d-4ed6-8c4b-7a4ec7ff2fc5@k1g2000prb.googlegroups.com> Robocop: >then within each department block of the list, have it organized by projects.< I don't know what does it means. > timesheets.sort(key=operator.attrgetter('string')) Try something like: timesheets.sort(key=attrgetter("department", "engagement", "date", "stare_hour")) > My brain might explode if i continue. Relax. Bye, bearophile From cs at zip.com.au Fri Feb 6 16:08:57 2009 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 7 Feb 2009 08:08:57 +1100 Subject: Ordered dict by default In-Reply-To: <47a82549-bc80-45ac-8b51-d58e597e768f@r24g2000vbp.googlegroups.com> Message-ID: <20090206210857.GA6933@cskk.homeip.net> On 05Feb2009 01:47, bearophileHUGS at lycos.com wrote: | [...] But even if the average performance becomes a | little worse I think making the default Python dict as ordered is a | positive change for Python too, because built-ins are meant to be as | flexible as possible, even if they aren't the fastest ones or the less | memory hungry ones I like the builtins to be as fast as possible. If I'm not "abusing" a built in facility I like to have the peace of mind that there's no point being concerned about the performance of the built-in - it will be optimal or close to it. So I feel no temptation to reimplement the wheel and can devote my energies to the code using the wheel. So if a dictionary has a performance weakness to add a non-widely-needed behaviour, it's not longer a "pure" mapping and I will feel unhappy using it. | (and keeping dicts ordered decreases the surprises | a newbie finds, makes some code cleaner, and doctests become simpler | to write because the order of items may be more defined). I read this as: - increases the unrealised assumptions about mappings in general which a newbie may acquire, causing them pain/complaint later with other mappings - makes some code shorter - making tests slightly simpler to write; it's not very hard to track insert order for purposes of a test short that be needed, is it? it seems a small gain for a loss in every production scenario | Once the default dicts are ordered, it can be possible to add an | unordereddict to the collections module to be used by programmers when | max performance or low memory usage is very important :-) I would much rather keep dictionaries as performant as possible, as a bare mapping, and add an odict for when order matters. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ The wireless music box has no imaginable commercial value. Who would pay for a message sent to nobody in particular? --David Sarnoff's associates in response to his urgings for investment in the radio in the 1920s. From dq at gmail.com Fri Feb 6 16:09:22 2009 From: dq at gmail.com (dq) Date: Fri, 06 Feb 2009 22:09:22 +0100 Subject: urllib2 performance on windows, usb connection In-Reply-To: <498beb5a$0$3305$9b622d9e@news.freenet.de> References: <498beb5a$0$3305$9b622d9e@news.freenet.de> Message-ID: Martin v. L?wis wrote: >> So does anyone know what the deal is with this? Why is the same code so >> much slower on Windows? Hope someone can tell me before a holy war >> erupts :-) > > Only the holy war can give an answer here. It certainly has *nothing* to > do with Python; Python calls the operating system functions to read from > the network and write to the disk almost directly. So it must be the > operating system itself that slows it down. > > To investigate further, you might drop the write operating, and measure > only source.read(). If that is slower, then, for some reason, the > network speed is bad on Windows. Maybe you have the network interfaces > misconfigured? Maybe you are using wireless on Windows, but cable on > Linux? Maybe you have some network filtering software running on > Windows? Maybe it's just that Windows sucks?-) > > If the network read speed is fine, but writing slows down, I ask the > same questions. Perhaps you have some virus scanner installed that > filters all write operations? Maybe Windows sucks? > > Regards, > Martin > Thanks for the ideas, Martin. I ran a couple of experiments to find the culprit, by downloading the same 20 MB file from the same fast server. I compared: 1. DL to HD vs USB iPod. 2. AV on-access protection on vs. off 3. "source. read()" only vs. "file.write( source.read() )" The culprit is definitely the write speed on the iPod. That is, everything runs plenty fast (~1 MB/s down) as long as I'm not writing directly to the iPod. This is kind of odd, because if I copy the file over from the HD to the iPod using windows (drag-n-drop), it takes about a second or two, so about 10 MB/s. So the problem is definitely partially Windows, but it also seems that Python's file.write() function is not without blame. It's the combination of Windows, iPod and Python's data stream that is slowing me down. I'm not really sure what I can do about this. I'll experiment a little more and see if there's any way around this bottleneck. If anyone has run into a problem like this, I'd love to hear about it... thanks again, --danny From sjmachin at lexicon.net Fri Feb 6 16:14:43 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 6 Feb 2009 13:14:43 -0800 (PST) Subject: Question on Strings References: <984064.27780.qm@web112219.mail.gq1.yahoo.com> <0c01fc50-f20f-4981-af81-a49499acf776@q30g2000prq.googlegroups.com> Message-ID: <786fac80-ebac-4264-ab45-6bf20c77b4c6@f40g2000pri.googlegroups.com> On Feb 7, 5:23?am, Terry Reedy wrote: > John Machin wrote: > > The UTF-n siblings are *external* representations. > > 2.x: a_unicode_object.decode('UTF-16') -> an_str_object > > 3.x: an_str_object.decode('UTF-16') -> a_bytes_object > > That should be .encode() to bytes, which is the coded form. > .decode is bytes => str/unicode True. I guess that makes me the Dohmouse :-) From rhamph at gmail.com Fri Feb 6 16:23:48 2009 From: rhamph at gmail.com (Rhamphoryncus) Date: Fri, 6 Feb 2009 13:23:48 -0800 (PST) Subject: Flattening lists References: Message-ID: <9a8af8a3-27fb-4f5b-90ea-ee0276c7e5e3@r15g2000prd.googlegroups.com> On Feb 5, 1:16?pm, Michele Simionato wrote: > On Feb 5, 7:24?pm, a... at pythoncraft.com (Aahz) wrote: > > > In article , > > Michele Simionato ? wrote: > > > >Looks fine to me. In some situations you may also use hasattr(el, > > >'__iter__') instead of isinstance(el, list) (it depends if you want to > > >flatten generic iterables or only lists). > > > Of course, once you do that, you need to special-case strings... > > Strings are iterable but have no __iter__ method, which is fine in > this context, since I would say 99.9% of times one wants to treat them > as atomic objects, so no need to special case. Don't worry, that little oddity was fixed for you: Python 3.0+ (unknown, Dec 8 2008, 14:26:15) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> str.__iter__ >>> bytes.__iter__ >>> bytearray.__iter__ I'm in the "why do you need more than 1 depth?" camp. Dispatching based on your own type should be given an extra look. Dispatching based passed in types should be given three extra looks. I didn't realize itertools.chain(*iterable) worked. I guess that needs to be pushed as the canonical form. From mmcclaf at gmail.com Fri Feb 6 16:29:53 2009 From: mmcclaf at gmail.com (mmcclaf) Date: Fri, 6 Feb 2009 13:29:53 -0800 (PST) Subject: Using cPickle References: <4d5ead6c-4e8a-4003-86c6-519a638da1e1@y38g2000prg.googlegroups.com> Message-ID: <60dcd0f0-367f-4404-a9d2-62b96ddee389@i24g2000prf.googlegroups.com> On Feb 6, 3:09?pm, MRAB wrote: > mmcclaf wrote: > > On Feb 6, 10:25 am, Steve Holden wrote: > >> mmcclaf wrote: > >>> Hi there, > >>> I have to make a small database using cPickle. I'm having troubles > >>> trying to read in the information if it's more than one line. I'm > >>> pretty sure it's in the line "for line in stuff:" Can anyone help me > >>> out? Basically the end result is wanting it to look something like > >>> what is down below when list is typed in: > >>> Last name ? ? ? ? ? ? ? ? First Name ? ? ? ? ? ? ? ?Email Address > >>> Doe ? ? ? ? ? ? ? ? ? ? ? ? ?John > >>> j... at doe.com > >>> [code] > >>> # @author: Ocdt Murray McClafferty 24656 > >>> # This will manage a small database using the cPickle module. > >>> # It must maintain a list of last names, first names and email > >>> addresses, and must let a user interact with the program > >>> # > >>> #!usr/bin/python > >>> # -*- coding: utf-8 -*- > >>> import sys > >>> import cPickle > >>> # > >>> format = '%s ? ? ? ? ? ? %s ? ? ? ? ? ? ? ? ?%s' > >>> try: > >>> ? ?filename = sys.argv[1] > >>> ? ?input = open(filename, 'r') > >>> except IOError: > >>> ? ?print 'File is not available, will create a new file now' > >>> ? ?lastName='Last Name' > >>> ? ?firstName='First Name' > >>> ? ?email= 'Email' > >>> ? ?#input.close() > >>> ? ?output=open (filename, 'w') > >>> ? ?total = format%(lastName, firstName, email) > >>> ? ?cPickle.dump(total,output) > >>> ? ?#cPickle.dump(firstName,output) > >>> ? ?#cPickle.dump(email,output) > >>> ? ?output.close() > >>> except EOFError: > >>> ? ?print 'File is empty' > >>> #datas = cPickle.load(input) > >>> while True: > >>> ? ?command=sys.stdin.readline()[:-1] > >>> ? ?if command=='list': #lists the data in the file > >>> ? ? ? ? ? ?input = open(filename, 'r') > >>> ? ? ? ? ? ?stuff=cPickle.load(input) > >>> ? ? ? ? ? ?for line in stuff: > >>> ? ? ? ? ? ? ? ? ? ?#firstName=cPickle.load(input) > >>> ? ? ? ? ? ? ? ? ? ?#email=cPickle.load(input) > >>> ? ? ? ? ? ? ? ? ? ?#print repr (lastName).rjust(10), repr(firstName).rjust(20), repr > >>> (email).rjust(20) > >>> ? ? ? ? ? ? ? ? ? ?stuff=cPickle.load(input) > >>> ? ? ? ? ? ? ? ? ? ?print stuff > >>> ? ? ? ? ? ? ? ? ? ?print line > >>> ? ? ? ? ? ?input.close() > >>> ? ?if command=='exit' or command=='quit' : #NEVER forget the exit!!! > >>> ? ? ? ? ? ?print 'Save changes? y for Yes, n for No' > >>> ? ? ? ? ? ?commandSave=sys.stdin.readline()[:-1] > >>> ? ? ? ? ? ?if commandSave =='y': #if the user wants to save > >>> ? ? ? ? ? ? ? ? ? ?output=open(filename, 'w') > >>> ? ? ? ? ? ? ? ? ? ?cPickle.dump(work,output) > >>> ? ? ? ? ? ? ? ? ? ?output.close() > >>> ? ? ? ? ? ? ? ? ? ?sys.exit(0) > >>> ? ? ? ? ? ?if commandSave =='n': #no save > >>> ? ? ? ? ? ? ? ? ? ?input.close() > >>> ? ? ? ? ? ? ? ? ? ?sys.exit(0) > >>> ? ?if command=='add': #adds an entity to the file > >>> ? ? ? ? ? ?print 'Last name?' > >>> ? ? ? ? ? ?lastName=sys.stdin.readline()[:-1] > >>> ? ? ? ? ? ?print 'First name?' > >>> ? ? ? ? ? ?firstName=sys.stdin.readline()[:-1] > >>> ? ? ? ? ? ?print 'Email address?' > >>> ? ? ? ? ? ?email=sys.stdin.readline()[:-1] > >>> ? ? ? ? ? ?work = format%(lastName, firstName, email) > >>> ? ? ? ? ? ?#output=open(filename, 'w') > >>> ? ? ? ? ? ?#data=cPickle.load(output) > >>> ? ? ? ? ? ?#data.append(work) > >>> ? ? ? ? ? ?#output.close() > >>> ? ? ? ? ? ?output=open(filename, 'a') > >>> ? ? ? ? ? ?cPickle.dump(work,output) > >>> ? ? ? ? ? ?output.close() > >>> [/code] > >>> All help would be appreciated. I am new to Python and this seems to be > >>> quite a challenge for me. > >> Make sure you use modes "rb" and "wb" when you open the pickle files. If > >> you are running on Windows this can make a difference. > > >> regards > >> ?Steve > >> -- > >> Steve Holden ? ? ? ?+1 571 484 6266 ? +1 800 494 3119 > >> Holden Web LLC ? ? ? ? ? ? ?http://www.holdenweb.com/ > > > I've tried both rb and wb as well as r and w, there appears to be no > > difference in the running of the code. > > "cPickle.dump(work,output)" writes a string and > "stuff=cPickle.load(input)" just reads that string, so "for line in > stuff:" is iterating through the characters if the string. You need to > use cPickle.load() to read each string (line). Ok, so I just modified that section to: [code] if command=='list': #lists the data in the file input = open(filename, 'r') stuff=cPickle.load(input) for line in stuff: #firstName=cPickle.load(input) #email=cPickle.load(input) #print repr (lastName).rjust(10), repr(firstName).rjust(20), repr (email).rjust(20) stuff=cPickle.load(input) print stuff input.close() [/code] And now it's printing it out ok, but then I get an EOFError at stuff=cPickle.load(onput) at line 45. From google at mrabarnett.plus.com Fri Feb 6 16:47:41 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 06 Feb 2009 21:47:41 +0000 Subject: Ordered dict by default In-Reply-To: <20090206210857.GA6933@cskk.homeip.net> References: <20090206210857.GA6933@cskk.homeip.net> Message-ID: <498CAFFD.9010703@mrabarnett.plus.com> Cameron Simpson wrote: > On 05Feb2009 01:47, bearophileHUGS at lycos.com wrote: > | [...] But even if the average performance becomes a > | little worse I think making the default Python dict as ordered is a > | positive change for Python too, because built-ins are meant to be as > | flexible as possible, even if they aren't the fastest ones or the less > | memory hungry ones [snip] > I would much rather keep dictionaries as performant as possible, as a > bare mapping, and add an odict for when order matters. > +1 From skippy.hammond at gmail.com Fri Feb 6 16:54:16 2009 From: skippy.hammond at gmail.com (Mark Hammond) Date: Sat, 07 Feb 2009 08:54:16 +1100 Subject: Using multiprocessing from a Windows service In-Reply-To: <498BC8E4.7000108@gmail.com> References: <0e4d6033-a130-4c19-b648-6bcef8bfc922@u18g2000pro.googlegroups.com> <498BB39D.5070809@gmail.com> <498BBBE0.6090704@gmail.com> <498BC8E4.7000108@gmail.com> Message-ID: <498CB188.40104@gmail.com> On 6/02/2009 4:21 PM, Volodymyr Orlenko wrote: > In the patch I submitted, I simply check if the name of the supposed > module ends with ".exe". It works fine for my case, but maybe this is > too general. Is there a chance that a Python module would end in ".exe"? IIRC, py2exe may create executables where sys.argv[0] is the executable itself. Maybe if we consider and handle both these cases a patch to mp might be looked upon in a better light... Cheers, Mark From google at mrabarnett.plus.com Fri Feb 6 16:54:40 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 06 Feb 2009 21:54:40 +0000 Subject: urllib2 performance on windows, usb connection In-Reply-To: References: <498beb5a$0$3305$9b622d9e@news.freenet.de> Message-ID: <498CB1A0.7090003@mrabarnett.plus.com> dq wrote: > Martin v. L?wis wrote: >>> So does anyone know what the deal is with this? Why is the same code so >>> much slower on Windows? Hope someone can tell me before a holy war >>> erupts :-) >> >> Only the holy war can give an answer here. It certainly has *nothing* to >> do with Python; Python calls the operating system functions to read from >> the network and write to the disk almost directly. So it must be the >> operating system itself that slows it down. >> >> To investigate further, you might drop the write operating, and measure >> only source.read(). If that is slower, then, for some reason, the >> network speed is bad on Windows. Maybe you have the network interfaces >> misconfigured? Maybe you are using wireless on Windows, but cable on >> Linux? Maybe you have some network filtering software running on >> Windows? Maybe it's just that Windows sucks?-) >> >> If the network read speed is fine, but writing slows down, I ask the >> same questions. Perhaps you have some virus scanner installed that >> filters all write operations? Maybe Windows sucks? >> >> Regards, >> Martin >> > > Thanks for the ideas, Martin. I ran a couple of experiments to find the > culprit, by downloading the same 20 MB file from the same fast server. I > compared: > > 1. DL to HD vs USB iPod. > 2. AV on-access protection on vs. off > 3. "source. read()" only vs. "file.write( source.read() )" > > The culprit is definitely the write speed on the iPod. That is, > everything runs plenty fast (~1 MB/s down) as long as I'm not writing > directly to the iPod. This is kind of odd, because if I copy the file > over from the HD to the iPod using windows (drag-n-drop), it takes about > a second or two, so about 10 MB/s. > > So the problem is definitely partially Windows, but it also seems that > Python's file.write() function is not without blame. It's the > combination of Windows, iPod and Python's data stream that is slowing me > down. > > I'm not really sure what I can do about this. I'll experiment a little > more and see if there's any way around this bottleneck. If anyone has > run into a problem like this, I'd love to hear about it... > You could try copying the file to the iPod using the command line, or copying data from disk to iPod in, say, C, anything but Python. This would allow you to identify whether Python itself has anything to do with it. From skippy.hammond at gmail.com Fri Feb 6 16:59:57 2009 From: skippy.hammond at gmail.com (Mark Hammond) Date: Sat, 07 Feb 2009 08:59:57 +1100 Subject: WIn32api In-Reply-To: <5caea3690902060828k29e139f9g87065322610f1151@mail.gmail.com> References: <5caea3690902060543s78b19efaxe95b63b4be89153d@mail.gmail.com> <5caea3690902060828k29e139f9g87065322610f1151@mail.gmail.com> Message-ID: <498CB2DD.8010909@gmail.com> On 7/02/2009 3:28 AM, K-Dawg wrote: You might like to seek out the python-win32 mailing list for stuff like this where more people tend to pay attention to windows problems. > This works if I call run() specifically. But when I try to initiate the > thread with .start() I get the following error Unfortunately threads and COM are tricky. The short story is that you can't, in the general case, pass a COM object from one thread to another. You need to google "COM threading models", and if you *really* want to pass objects between threads, the impressively named MSCOM function CoMarshalInterThreadInterfaceInStream (exposed via the pythoncom module). The above mailing list has had a number of threads on this issue over the years... Cheers, Mark From google at mrabarnett.plus.com Fri Feb 6 17:04:09 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 06 Feb 2009 22:04:09 +0000 Subject: Using cPickle In-Reply-To: <60dcd0f0-367f-4404-a9d2-62b96ddee389@i24g2000prf.googlegroups.com> References: <4d5ead6c-4e8a-4003-86c6-519a638da1e1@y38g2000prg.googlegroups.com> <60dcd0f0-367f-4404-a9d2-62b96ddee389@i24g2000prf.googlegroups.com> Message-ID: <498CB3D9.6000203@mrabarnett.plus.com> mmcclaf wrote: > On Feb 6, 3:09 pm, MRAB wrote: >> mmcclaf wrote: >>> On Feb 6, 10:25 am, Steve Holden wrote: >>>> mmcclaf wrote: >>>>> Hi there, >>>>> I have to make a small database using cPickle. I'm having troubles >>>>> trying to read in the information if it's more than one line. I'm >>>>> pretty sure it's in the line "for line in stuff:" Can anyone help me >>>>> out? Basically the end result is wanting it to look something like >>>>> what is down below when list is typed in: >>>>> Last name First Name Email Address >>>>> Doe John >>>>> j... at doe.com >>>>> [code] >>>>> # @author: Ocdt Murray McClafferty 24656 >>>>> # This will manage a small database using the cPickle module. >>>>> # It must maintain a list of last names, first names and email >>>>> addresses, and must let a user interact with the program >>>>> # >>>>> #!usr/bin/python >>>>> # -*- coding: utf-8 -*- >>>>> import sys >>>>> import cPickle >>>>> # >>>>> format = '%s %s %s' >>>>> try: >>>>> filename = sys.argv[1] >>>>> input = open(filename, 'r') >>>>> except IOError: >>>>> print 'File is not available, will create a new file now' >>>>> lastName='Last Name' >>>>> firstName='First Name' >>>>> email= 'Email' >>>>> #input.close() >>>>> output=open (filename, 'w') >>>>> total = format%(lastName, firstName, email) >>>>> cPickle.dump(total,output) >>>>> #cPickle.dump(firstName,output) >>>>> #cPickle.dump(email,output) >>>>> output.close() >>>>> except EOFError: >>>>> print 'File is empty' >>>>> #datas = cPickle.load(input) >>>>> while True: >>>>> command=sys.stdin.readline()[:-1] >>>>> if command=='list': #lists the data in the file >>>>> input = open(filename, 'r') >>>>> stuff=cPickle.load(input) >>>>> for line in stuff: >>>>> #firstName=cPickle.load(input) >>>>> #email=cPickle.load(input) >>>>> #print repr (lastName).rjust(10), repr(firstName).rjust(20), repr >>>>> (email).rjust(20) >>>>> stuff=cPickle.load(input) >>>>> print stuff >>>>> print line >>>>> input.close() >>>>> if command=='exit' or command=='quit' : #NEVER forget the exit!!! >>>>> print 'Save changes? y for Yes, n for No' >>>>> commandSave=sys.stdin.readline()[:-1] >>>>> if commandSave =='y': #if the user wants to save >>>>> output=open(filename, 'w') >>>>> cPickle.dump(work,output) >>>>> output.close() >>>>> sys.exit(0) >>>>> if commandSave =='n': #no save >>>>> input.close() >>>>> sys.exit(0) >>>>> if command=='add': #adds an entity to the file >>>>> print 'Last name?' >>>>> lastName=sys.stdin.readline()[:-1] >>>>> print 'First name?' >>>>> firstName=sys.stdin.readline()[:-1] >>>>> print 'Email address?' >>>>> email=sys.stdin.readline()[:-1] >>>>> work = format%(lastName, firstName, email) >>>>> #output=open(filename, 'w') >>>>> #data=cPickle.load(output) >>>>> #data.append(work) >>>>> #output.close() >>>>> output=open(filename, 'a') >>>>> cPickle.dump(work,output) >>>>> output.close() >>>>> [/code] >>>>> All help would be appreciated. I am new to Python and this seems to be >>>>> quite a challenge for me. >>>> Make sure you use modes "rb" and "wb" when you open the pickle files. If >>>> you are running on Windows this can make a difference. >>>> regards >>>> Steve >>>> -- >>>> Steve Holden +1 571 484 6266 +1 800 494 3119 >>>> Holden Web LLC http://www.holdenweb.com/ >>> I've tried both rb and wb as well as r and w, there appears to be no >>> difference in the running of the code. >> "cPickle.dump(work,output)" writes a string and >> "stuff=cPickle.load(input)" just reads that string, so "for line in >> stuff:" is iterating through the characters if the string. You need to >> use cPickle.load() to read each string (line). > > Ok, so I just modified that section to: > [code] > if command=='list': #lists the data in the file > input = open(filename, 'r') > stuff=cPickle.load(input) > for line in stuff: You're still iterating over the string. > #firstName=cPickle.load(input) > #email=cPickle.load(input) > #print repr (lastName).rjust(10), repr(firstName).rjust(20), repr > (email).rjust(20) > stuff=cPickle.load(input) > print stuff > > > input.close() > [/code] > > And now it's printing it out ok, but then I get an EOFError at > stuff=cPickle.load(onput) at line 45. > You can just keep reading until EOFError occurs, at which point you know you've reached the end of the file: input = open(filename, 'rb') try: while True: stuff = cPickle.load(input) print stuff except EOFError: pass input.close() From bthayre at physics.ucsd.edu Fri Feb 6 17:08:30 2009 From: bthayre at physics.ucsd.edu (Robocop) Date: Fri, 6 Feb 2009 14:08:30 -0800 (PST) Subject: Trouble sorting a list of objects by attributes References: <49ddc228-c4ef-48b2-8fce-70f9e881e216@o40g2000prn.googlegroups.com> <20261325-e75d-4ed6-8c4b-7a4ec7ff2fc5@k1g2000prb.googlegroups.com> Message-ID: On Feb 6, 1:03?pm, bearophileH... at lycos.com wrote: > Robocop: > > >then within each department block of the list, have it organized by projects.< > > I don't know what does it means. > > > timesheets.sort(key=operator.attrgetter('string')) > > Try something like: > timesheets.sort(key=attrgetter("department", "engagement", "date", > "stare_hour")) > > > My brain might explode if i continue. > > Relax. > > Bye, > bearophile Projects was meant to be engagements. All these suggestions are great, let me see what i can make happen right now. Thanks all! From bthayre at physics.ucsd.edu Fri Feb 6 17:17:10 2009 From: bthayre at physics.ucsd.edu (Robocop) Date: Fri, 6 Feb 2009 14:17:10 -0800 (PST) Subject: Trouble sorting a list of objects by attributes References: <49ddc228-c4ef-48b2-8fce-70f9e881e216@o40g2000prn.googlegroups.com> <20261325-e75d-4ed6-8c4b-7a4ec7ff2fc5@k1g2000prb.googlegroups.com> Message-ID: On Feb 6, 1:03?pm, bearophileH... at lycos.com wrote: > Robocop: > > >then within each department block of the list, have it organized by projects.< > > I don't know what does it means. > > > timesheets.sort(key=operator.attrgetter('string')) > > Try something like: > timesheets.sort(key=attrgetter("department", "engagement", "date", > "stare_hour")) > > > My brain might explode if i continue. > > Relax. > > Bye, > bearophile UH OH GUYS! line 110, in sorter timesheets.sort(key=attrgetter("department", "engagement", "date","start")) TypeError: attrgetter expected 1 arguments, got 4 From bthayre at physics.ucsd.edu Fri Feb 6 17:20:09 2009 From: bthayre at physics.ucsd.edu (Robocop) Date: Fri, 6 Feb 2009 14:20:09 -0800 (PST) Subject: Trouble sorting a list of objects by attributes References: <49ddc228-c4ef-48b2-8fce-70f9e881e216@o40g2000prn.googlegroups.com> <20261325-e75d-4ed6-8c4b-7a4ec7ff2fc5@k1g2000prb.googlegroups.com> Message-ID: <3f1a6661-2bd6-4b12-aa79-03b055ce6745@a39g2000prl.googlegroups.com> On Feb 6, 2:17?pm, Robocop wrote: > On Feb 6, 1:03?pm, bearophileH... at lycos.com wrote: > > > > > Robocop: > > > >then within each department block of the list, have it organized by projects.< > > > I don't know what does it means. > > > > timesheets.sort(key=operator.attrgetter('string')) > > > Try something like: > > timesheets.sort(key=attrgetter("department", "engagement", "date", > > "stare_hour")) > > > > My brain might explode if i continue. > > > Relax. > > > Bye, > > bearophile > > UH OH GUYS! > > line 110, in sorter > ? ? timesheets.sort(key=attrgetter("department", "engagement", > "date","start")) > TypeError: attrgetter expected 1 arguments, got 4 I think there may have been a misunderstanding. I was already using attrgetter, my problem is that it doesn't appear to be sorting by the argument i give it. How does sort work with strings? How about with datetime.time or datetime.date? So far i can get it sorting strictly by the datetime objects, but i need all of this sorting done within the constraints imposed by doing sorts via department and engagements. Any ideas? From bthayre at physics.ucsd.edu Fri Feb 6 17:34:35 2009 From: bthayre at physics.ucsd.edu (Robocop) Date: Fri, 6 Feb 2009 14:34:35 -0800 (PST) Subject: Trouble sorting a list of objects by attributes References: <49ddc228-c4ef-48b2-8fce-70f9e881e216@o40g2000prn.googlegroups.com> <20261325-e75d-4ed6-8c4b-7a4ec7ff2fc5@k1g2000prb.googlegroups.com> <3f1a6661-2bd6-4b12-aa79-03b055ce6745@a39g2000prl.googlegroups.com> Message-ID: <9c1c8e31-98fc-4fbf-827c-d785685b91e5@v5g2000pre.googlegroups.com> On Feb 6, 2:20?pm, Robocop wrote: > On Feb 6, 2:17?pm, Robocop wrote: > > > > > On Feb 6, 1:03?pm, bearophileH... at lycos.com wrote: > > > > Robocop: > > > > >then within each department block of the list, have it organized by projects.< > > > > I don't know what does it means. > > > > > timesheets.sort(key=operator.attrgetter('string')) > > > > Try something like: > > > timesheets.sort(key=attrgetter("department", "engagement", "date", > > > "stare_hour")) > > > > > My brain might explode if i continue. > > > > Relax. > > > > Bye, > > > bearophile > > > UH OH GUYS! > > > line 110, in sorter > > ? ? timesheets.sort(key=attrgetter("department", "engagement", > > "date","start")) > > TypeError: attrgetter expected 1 arguments, got 4 > > I think there may have been a misunderstanding. ?I was already using > attrgetter, my problem is that it doesn't appear to be sorting by the > argument i give it. ?How does sort work with strings? ?How about with > datetime.time or datetime.date? > > So far i can get it sorting strictly by the datetime objects, but i > need all of this sorting done within the constraints imposed by doing > sorts via department and engagements. > > Any ideas? I'm stuck with python 2.4 right now:( From tjreedy at udel.edu Fri Feb 6 17:34:51 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 06 Feb 2009 17:34:51 -0500 Subject: Trouble sorting a list of objects by attributes In-Reply-To: References: <49ddc228-c4ef-48b2-8fce-70f9e881e216@o40g2000prn.googlegroups.com> <20261325-e75d-4ed6-8c4b-7a4ec7ff2fc5@k1g2000prb.googlegroups.com> Message-ID: Robocop wrote: > UH OH GUYS! > > line 110, in sorter > timesheets.sort(key=attrgetter("department", "engagement", > "date","start")) > TypeError: attrgetter expected 1 arguments, got 4 Um... what version of Python are you running? Alway specify. (Too many people do not). In 3.0 from operator import attrgetter f=attrgetter("department", "engagement","date","start") runs fine as per the doc. operator.attrgetter(attr[, args...]) Return a callable object that fetches attr from its operand. If more than one attribute is requested, returns a tuple of attributes. After, f = attrgetter('name'), the call f(b) returns b.name. After, f = attrgetter('name', 'date'), the call f(b) returns (b.name, b.date). From dq at gmail.com Fri Feb 6 17:35:58 2009 From: dq at gmail.com (dq) Date: Fri, 06 Feb 2009 23:35:58 +0100 Subject: urllib2 performance on windows, usb connection In-Reply-To: References: <498beb5a$0$3305$9b622d9e@news.freenet.de> Message-ID: MRAB wrote: > dq wrote: > > Martin v. L?wis wrote: > >>> So does anyone know what the deal is with this? Why is the same > code so > >>> much slower on Windows? Hope someone can tell me before a holy war > >>> erupts :-) > >> > >> Only the holy war can give an answer here. It certainly has > *nothing* to > >> do with Python; Python calls the operating system functions to read > from > >> the network and write to the disk almost directly. So it must be the > >> operating system itself that slows it down. > >> > >> To investigate further, you might drop the write operating, and measure > >> only source.read(). If that is slower, then, for some reason, the > >> network speed is bad on Windows. Maybe you have the network interfaces > >> misconfigured? Maybe you are using wireless on Windows, but cable on > >> Linux? Maybe you have some network filtering software running on > >> Windows? Maybe it's just that Windows sucks?-) > >> > >> If the network read speed is fine, but writing slows down, I ask the > >> same questions. Perhaps you have some virus scanner installed that > >> filters all write operations? Maybe Windows sucks? > >> > >> Regards, > >> Martin > >> > > > > Thanks for the ideas, Martin. I ran a couple of experiments to find the > > culprit, by downloading the same 20 MB file from the same fast server. I > > compared: > > > > 1. DL to HD vs USB iPod. > > 2. AV on-access protection on vs. off > > 3. "source. read()" only vs. "file.write( source.read() )" > > > > The culprit is definitely the write speed on the iPod. That is, > > everything runs plenty fast (~1 MB/s down) as long as I'm not writing > > directly to the iPod. This is kind of odd, because if I copy the file > > over from the HD to the iPod using windows (drag-n-drop), it takes about > > a second or two, so about 10 MB/s. > > > > So the problem is definitely partially Windows, but it also seems that > > Python's file.write() function is not without blame. It's the > > combination of Windows, iPod and Python's data stream that is slowing me > > down. > > > > I'm not really sure what I can do about this. I'll experiment a little > > more and see if there's any way around this bottleneck. If anyone has > > run into a problem like this, I'd love to hear about it... > > > You could try copying the file to the iPod using the command line, or > copying data from disk to iPod in, say, C, anything but Python. This > would allow you to identify whether Python itself has anything to do > with it. Well, I think I've partially identified the problem. target.write( source.read() ) runs perfectly fast, copies 20 megs in about a second, from HD to iPod. However, if I run the same code in a while loop, using a certain block size, say target.write( source.read(4096) ), it takes forever (or at least I'm still timing it while I write this post). The mismatch seems to be between urllib2's block size and the write speed of the iPod, I might try to tweak this a little in the code and see if it has any effect. Oh, there we go: 20 megs in 135.8 seconds. Yeah... I might want to try to improve that... From bthayre at physics.ucsd.edu Fri Feb 6 17:38:37 2009 From: bthayre at physics.ucsd.edu (Robocop) Date: Fri, 6 Feb 2009 14:38:37 -0800 (PST) Subject: Trouble sorting a list of objects by attributes References: <49ddc228-c4ef-48b2-8fce-70f9e881e216@o40g2000prn.googlegroups.com> <20261325-e75d-4ed6-8c4b-7a4ec7ff2fc5@k1g2000prb.googlegroups.com> <3f1a6661-2bd6-4b12-aa79-03b055ce6745@a39g2000prl.googlegroups.com> <9c1c8e31-98fc-4fbf-827c-d785685b91e5@v5g2000pre.googlegroups.com> Message-ID: <635e13a8-cdc8-4535-bdd8-4df2fe719215@n33g2000pri.googlegroups.com> On Feb 6, 2:34?pm, Robocop wrote: > On Feb 6, 2:20?pm, Robocop wrote: > > > > > On Feb 6, 2:17?pm, Robocop wrote: > > > > On Feb 6, 1:03?pm, bearophileH... at lycos.com wrote: > > > > > Robocop: > > > > > >then within each department block of the list, have it organized by projects.< > > > > > I don't know what does it means. > > > > > > timesheets.sort(key=operator.attrgetter('string')) > > > > > Try something like: > > > > timesheets.sort(key=attrgetter("department", "engagement", "date", > > > > "stare_hour")) > > > > > > My brain might explode if i continue. > > > > > Relax. > > > > > Bye, > > > > bearophile > > > > UH OH GUYS! > > > > line 110, in sorter > > > ? ? timesheets.sort(key=attrgetter("department", "engagement", > > > "date","start")) > > > TypeError: attrgetter expected 1 arguments, got 4 > > > I think there may have been a misunderstanding. ?I was already using > > attrgetter, my problem is that it doesn't appear to be sorting by the > > argument i give it. ?How does sort work with strings? ?How about with > > datetime.time or datetime.date? > > > So far i can get it sorting strictly by the datetime objects, but i > > need all of this sorting done within the constraints imposed by doing > > sorts via department and engagements. > > > Any ideas? > > I'm stuck with python 2.4 right now:( I've got a python 2.4 fix though! timesheets.sort(key= lambda i:(i.department,i.engagement,i.start)) Thanks for the help and time!!!!! From apt.shansen at gmail.com Fri Feb 6 17:41:25 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Fri, 6 Feb 2009 14:41:25 -0800 Subject: Trouble sorting a list of objects by attributes In-Reply-To: <3f1a6661-2bd6-4b12-aa79-03b055ce6745@a39g2000prl.googlegroups.com> References: <49ddc228-c4ef-48b2-8fce-70f9e881e216@o40g2000prn.googlegroups.com> <20261325-e75d-4ed6-8c4b-7a4ec7ff2fc5@k1g2000prb.googlegroups.com> <3f1a6661-2bd6-4b12-aa79-03b055ce6745@a39g2000prl.googlegroups.com> Message-ID: <7a9c25c20902061441u56a646e2lc1767fc03360f55c@mail.gmail.com> > I think there may have been a misunderstanding. I was already using > attrgetter, my problem is that it doesn't appear to be sorting by the > argument i give it. How does sort work with strings? How about with > datetime.time or datetime.date? You were using the attrgetter, but it looks like you weren't doing it correctly: timesheets.sort(key=operator.attrgetter('string')) You don't specify a type, be it string or date or anything: you specify the /name/ of the attribute to get. It'll handle sorting by any data type that has an order to it without you having to worry about it at all. Strings, ints, dates, times. It should be: timesheets.sort(key=operator.attrgetter("department")) If you want to sort by the value of the "department" attribute, which happens to be a string. If you want to sort by the "date" attribute, which happens to be a datetime.date, you do: timesheets.sort(key=operator.attrgetter("date")) Where date is not a datatype a la datetime.date, but the name of an attribute on your TimeSheet instances. --S From bearophileHUGS at lycos.com Fri Feb 6 18:19:22 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Fri, 6 Feb 2009 15:19:22 -0800 (PST) Subject: Ordered dict by default References: Message-ID: Cameron Simpson: >increases the unrealised assumptions about mappings in general which a newbie may acquire, causing them pain/complaint later with other mappings< This is wrong in several different ways. > I would much rather keep dictionaries as performant as possible, as a > bare mapping, and add an odict for when order matters. In Python 3 strings are all unicode, integral numbers are all multiprecision, chars in Python 2.x+ are strings, lists are arrays that can grow dynamically, and so on because the Purpose of Python isn't to be as fast as possible, but to be first of all flexible, safe, easy, not but-prone, even if other solution or older versions were faster. Ruby shares almost same purposes. I presume Ruby wants to become a bit higher level than Python, because it now has a more flexible built-in. But even in a language designed to run way faster than Python, like D, I think the right thing for built-ins is to be as flexible&easy as possible, so they are good enough in as many situations as possible, where performance isn't the most important thing, and to put the more specialized and faster versions into external libs. Making the built-ins be as optimized as possible (but limited too) looks like premature optimization to me, and in a language like Python premature optimization looks even more silly than usual. Bye, bearophile From patrick.hartling at gmail.com Fri Feb 6 18:19:52 2009 From: patrick.hartling at gmail.com (Patrick Hartling) Date: Fri, 6 Feb 2009 17:19:52 -0600 Subject: Module unloading resulting from SystemExit exception Message-ID: <944f7d8e0902061519x5dbc531au87003997a7a9bd10@mail.gmail.com> I am trying to understand how the SystemExit exception influences module unloading. The situation that I am facing is that a Python application behaves just fine upon exiting when executed using the standard Python interpreter, but when run as a frozen executable, modules are unloaded unexpectedly as a result of sys.exit() being called. This wouldn't be an issue at all except that callbacks registered with the atexit module have to re-import all modules that they want to use, and this can be rather unwieldy. I have narrowed it down to the SystemExit exception by determining that the problem does not occur if my __main__ module catches SystemExit and allows the script to terminate by reaching the end of __main__. If the exception is not caught or is re-raised, then the problem occurs. Since SystemExit influences the shutdown of threads, it seems that I need to let it be raised to keep the application from deadlocking on exit. I am working with Python 2.6.1, and I saw this behavior with 2.5 as well. It happens on Windows, Mac OS X, and Linux. The code that I am using for the frozen executable is generated by sib.py from VendorID 1.0.0. The fact that VendorID is being used is inconsequential. I have verified that its use in the executable is not causing this behavior by removing all references to it. I have reduced this to the minimum amount of code required to reproduce the problem and attached the Python script an the C code generated by sib.py for the application main() function. My guess is that the code that sib.py generates is failing to do something that Py_Main() would normally do. To that end, I have tried modifying the main() function in a variety of ways to get it as close to Py_Main() as I can, but it still exhibits the undesirable behavior when sys.exit() is called. That pretty much leaves me thinking that PyImport_ExecCodeModule() or PyImport_ImportFrozenModule() (I have also looked at Py_FrozenMain() for insight) is the culprit. Can anyone point me in the right direction for understanding how the SystemExit exception results in this behavior? My hope is that there is a change (simple or not) that can be made to the C code for the frozen executable to resolve the problem. Thanks in advance. -Patrick -- Patrick L. Hartling http://www.137.org/patrick/ -------------- next part -------------- /*==========================================================================*/ /* Main startup code for test */ /* This is generated code; Do not modify it! */ /*--------------------------------------------------------------------------*/ #include #include #include /* #include */ extern unsigned char M___main__[]; static struct _frozen _PyImport_FrozenModules[] = { {0, 0, 0} /* sentinel */ }; int main(int argc, char **argv) { PyObject *v, *co; PyImport_FrozenModules = _PyImport_FrozenModules; Py_SetProgramName((char *)"test"); /* vendorid_init(); */ Py_Initialize(); PySys_SetArgv(argc, argv); co = PyMarshal_ReadObjectFromString((char *)M___main__, 655); v = PyImport_ExecCodeModule((char *)"__main__", co); if(v == NULL) { PyErr_Print(); return -1; } Py_DECREF(v); Py_Finalize(); return 0; } /*==========================================================================*/ /* EOF */ /*--------------------------------------------------------------------------*/ -------------- next part -------------- A non-text attachment was scrubbed... Name: test.py Type: text/x-python Size: 243 bytes Desc: not available URL: From bearophileHUGS at lycos.com Fri Feb 6 18:26:57 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Fri, 6 Feb 2009 15:26:57 -0800 (PST) Subject: Ordered dict by default References: Message-ID: <6f38e8bc-4ecd-4b9f-abef-b885cd16b375@p37g2000yqd.googlegroups.com> bearophile: > In Python 3 strings are all unicode, integral numbers are all > multiprecision, chars in Python 2.x+ are strings, lists are arrays > that can grow dynamically, and so on because the Purpose of Python > isn't to be as fast as possible, but to be first of all flexible, > safe, easy, not but-prone, even if other solution or older versions > were faster. I have missed another example: It may be possible to create a sorting routine that's not stable but is faster than the current stable timsort (for example in C++ STL you have both sorting routines, and the unstable one is a variant of introsort that is faster than the stable version). I think Python will keep the stable one, because even if (in theory. In practice it may be quite difficult to write such unstable sorter faster than timsort) it can be slower, it's safer and more useful than an unstable sort. Bye, bearophile From google at mrabarnett.plus.com Fri Feb 6 18:30:38 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 06 Feb 2009 23:30:38 +0000 Subject: urllib2 performance on windows, usb connection In-Reply-To: References: <498beb5a$0$3305$9b622d9e@news.freenet.de> Message-ID: <498CC81E.8050607@mrabarnett.plus.com> dq wrote: > MRAB wrote: >> dq wrote: >>> Martin v. L?wis wrote: >>>>> So does anyone know what the deal is with this? Why is the >>>>> same code so much slower on Windows? Hope someone can tell >>>>> me before a holy war erupts :-) >>>> >>>> Only the holy war can give an answer here. It certainly has >>>> *nothing* to do with Python; Python calls the operating system >>>> functions to read from the network and write to the disk almost >>>> directly. So it must be the operating system itself that slows >>>> it down. >>>> >>>> To investigate further, you might drop the write operating, and >>>> measure only source.read(). If that is slower, then, for some >>>> reason, the network speed is bad on Windows. Maybe you have the >>>> network interfaces misconfigured? Maybe you are using wireless >>>> on Windows, but cable on Linux? Maybe you have some network >>>> filtering software running on Windows? Maybe it's just that >>>> Windows sucks?-) >>>> >>>> If the network read speed is fine, but writing slows down, I >>>> ask the same questions. Perhaps you have some virus scanner >>>> installed that filters all write operations? Maybe Windows >>>> sucks? >>>> >>> Thanks for the ideas, Martin. I ran a couple of experiments to >>> find the culprit, by downloading the same 20 MB file from the >>> same fast server. I compared: >>> >>> 1. DL to HD vs USB iPod. >>> 2. AV on-access protection on vs. off >>> 3. "source. read()" only vs. "file.write( source.read() )" >>> >>> The culprit is definitely the write speed on the iPod. That is, >>> everything runs plenty fast (~1 MB/s down) as long as I'm not >>> writing directly to the iPod. This is kind of odd, because if I >>> copy the file over from the HD to the iPod using windows >>> (drag-n-drop), it takes about a second or two, so about 10 MB/s. >>> >>> So the problem is definitely partially Windows, but it also seems >>> that Python's file.write() function is not without blame. It's >>> the combination of Windows, iPod and Python's data stream that is >>> slowing me down. >>> >>> I'm not really sure what I can do about this. I'll experiment a >>> little more and see if there's any way around this bottleneck. >>> If anyone has run into a problem like this, I'd love to hear >>> about it... >>> >> You could try copying the file to the iPod using the command line, >> or copying data from disk to iPod in, say, C, anything but Python. >> This would allow you to identify whether Python itself has anything >> to do with it. > > Well, I think I've partially identified the problem. target.write( > source.read() ) runs perfectly fast, copies 20 megs in about a > second, from HD to iPod. However, if I run the same code in a while > loop, using a certain block size, say target.write( source.read(4096) > ), it takes forever (or at least I'm still timing it while I write > this post). > > The mismatch seems to be between urllib2's block size and the write > speed of the iPod, I might try to tweak this a little in the code and > see if it has any effect. > > Oh, there we go: 20 megs in 135.8 seconds. Yeah... I might want to > try to improve that... > How long does it take to transfer 4KB? If it can transfer 1MB/s then I'd say that 4KB is too small. Generally speaking, the higher the data rate, the larger the blocks you should be transferring at a time, IMHO. You could write a script to test the transfer speed with different block sizes. From google at mrabarnett.plus.com Fri Feb 6 18:34:49 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 06 Feb 2009 23:34:49 +0000 Subject: Ordered dict by default In-Reply-To: References: Message-ID: <498CC919.8000208@mrabarnett.plus.com> bearophileHUGS at lycos.com wrote: > Cameron Simpson: > >> increases the unrealised assumptions about mappings in general >> which a newbie may acquire, causing them pain/complaint later with >> other mappings< > > This is wrong in several different ways. > >> I would much rather keep dictionaries as performant as possible, as >> a bare mapping, and add an odict for when order matters. > > In Python 3 strings are all unicode, integral numbers are all > multiprecision, chars in Python 2.x+ are strings, lists are arrays > that can grow dynamically, and so on because the Purpose of Python > isn't to be as fast as possible, but to be first of all flexible, > safe, easy, not but-prone, even if other solution or older versions > were faster. Ruby shares almost same purposes. > > I presume Ruby wants to become a bit higher level than Python, > because it now has a more flexible built-in. But even in a language > designed to run way faster than Python, like D, I think the right > thing for built-ins is to be as flexible&easy as possible, so they > are good enough in as many situations as possible, where performance > isn't the most important thing, and to put the more specialized and > faster versions into external libs. Making the built-ins be as > optimized as possible (but limited too) looks like premature > optimization to me, and in a language like Python premature > optimization looks even more silly than usual. > You'll be wanting ordered sets next! :-) From dq at gmail.com Fri Feb 6 18:36:02 2009 From: dq at gmail.com (dq) Date: Sat, 07 Feb 2009 00:36:02 +0100 Subject: urllib2 performance on windows, usb connection In-Reply-To: References: <498beb5a$0$3305$9b622d9e@news.freenet.de> Message-ID: dq wrote: > MRAB wrote: >> dq wrote: >> > Martin v. L?wis wrote: >> >>> So does anyone know what the deal is with this? Why is the same >> code so >> >>> much slower on Windows? Hope someone can tell me before a holy war >> >>> erupts :-) >> >> >> >> Only the holy war can give an answer here. It certainly has >> *nothing* to >> >> do with Python; Python calls the operating system functions to >> read from >> >> the network and write to the disk almost directly. So it must be the >> >> operating system itself that slows it down. >> >> >> >> To investigate further, you might drop the write operating, and >> measure >> >> only source.read(). If that is slower, then, for some reason, the >> >> network speed is bad on Windows. Maybe you have the network >> interfaces >> >> misconfigured? Maybe you are using wireless on Windows, but cable on >> >> Linux? Maybe you have some network filtering software running on >> >> Windows? Maybe it's just that Windows sucks?-) >> >> >> >> If the network read speed is fine, but writing slows down, I ask the >> >> same questions. Perhaps you have some virus scanner installed that >> >> filters all write operations? Maybe Windows sucks? >> >> >> >> Regards, >> >> Martin >> >> >> > >> > Thanks for the ideas, Martin. I ran a couple of experiments to >> find the >> > culprit, by downloading the same 20 MB file from the same fast >> server. I >> > compared: >> > >> > 1. DL to HD vs USB iPod. >> > 2. AV on-access protection on vs. off >> > 3. "source. read()" only vs. "file.write( source.read() )" >> > >> > The culprit is definitely the write speed on the iPod. That is, >> > everything runs plenty fast (~1 MB/s down) as long as I'm not writing >> > directly to the iPod. This is kind of odd, because if I copy the file >> > over from the HD to the iPod using windows (drag-n-drop), it takes >> about >> > a second or two, so about 10 MB/s. >> > >> > So the problem is definitely partially Windows, but it also seems that >> > Python's file.write() function is not without blame. It's the >> > combination of Windows, iPod and Python's data stream that is >> slowing me >> > down. >> > >> > I'm not really sure what I can do about this. I'll experiment a >> little >> > more and see if there's any way around this bottleneck. If anyone has >> > run into a problem like this, I'd love to hear about it... >> > >> You could try copying the file to the iPod using the command line, or >> copying data from disk to iPod in, say, C, anything but Python. This >> would allow you to identify whether Python itself has anything to do >> with it. > > Well, I think I've partially identified the problem. target.write( > source.read() ) runs perfectly fast, copies 20 megs in about a second, > from HD to iPod. However, if I run the same code in a while loop, using > a certain block size, say target.write( source.read(4096) ), it takes > forever (or at least I'm still timing it while I write this post). > > The mismatch seems to be between urllib2's block size and the write > speed of the iPod, I might try to tweak this a little in the code and > see if it has any effect. > > Oh, there we go: 20 megs in 135.8 seconds. Yeah... I might want to > try to improve that... After some tweaking of the block size, I managed to get the DL speed up to about 900 Mb/s. It's still not quite Ubuntu, but it's a good order of magnitude better. The new DL code is pretty much this: """ blocksize = 2 ** 16 # plus or minus a power of 2 source = urllib2.urlopen( 'url://string' ) target = open( pathname, 'wb') fullsize = float( source.info()['Content-Length'] ) DLd = 0 while DLd < fullsize: DLd = DLd + blocksize # optional: write some DL progress info # somewhere, e.g. stdout target.close() source.close() """ From dq at gmail.com Fri Feb 6 18:40:00 2009 From: dq at gmail.com (dq) Date: Sat, 07 Feb 2009 00:40:00 +0100 Subject: urllib2 performance on windows, usb connection In-Reply-To: References: <498beb5a$0$3305$9b622d9e@news.freenet.de> Message-ID: MRAB wrote: > dq wrote: >> MRAB wrote: >>> dq wrote: >>>> Martin v. L?wis wrote: >>>>>> So does anyone know what the deal is with this? Why is the >>>>>> same code so much slower on Windows? Hope someone can tell >>>>>> me before a holy war erupts :-) >>>>> >>>>> Only the holy war can give an answer here. It certainly has >>>>> *nothing* to do with Python; Python calls the operating system >>>>> functions to read from the network and write to the disk almost >>>>> directly. So it must be the operating system itself that slows >>>>> it down. >>>>> >>>>> To investigate further, you might drop the write operating, and >>>>> measure only source.read(). If that is slower, then, for some >>>>> reason, the network speed is bad on Windows. Maybe you have the >>>>> network interfaces misconfigured? Maybe you are using wireless >>>>> on Windows, but cable on Linux? Maybe you have some network >>>>> filtering software running on Windows? Maybe it's just that >>>>> Windows sucks?-) >>>>> >>>>> If the network read speed is fine, but writing slows down, I >>>>> ask the same questions. Perhaps you have some virus scanner >>>>> installed that filters all write operations? Maybe Windows >>>>> sucks? >>>>> >>>> Thanks for the ideas, Martin. I ran a couple of experiments to find >>>> the culprit, by downloading the same 20 MB file from the >>>> same fast server. I compared: >>>> >>>> 1. DL to HD vs USB iPod. >>>> 2. AV on-access protection on vs. off >>>> 3. "source. read()" only vs. "file.write( source.read() )" >>>> >>>> The culprit is definitely the write speed on the iPod. That is, >>>> everything runs plenty fast (~1 MB/s down) as long as I'm not >>>> writing directly to the iPod. This is kind of odd, because if I >>>> copy the file over from the HD to the iPod using windows >>>> (drag-n-drop), it takes about a second or two, so about 10 MB/s. >>>> >>>> So the problem is definitely partially Windows, but it also seems >>>> that Python's file.write() function is not without blame. It's >>>> the combination of Windows, iPod and Python's data stream that is >>>> slowing me down. >>>> >>>> I'm not really sure what I can do about this. I'll experiment a >>>> little more and see if there's any way around this bottleneck. >>>> If anyone has run into a problem like this, I'd love to hear >>>> about it... >>>> >>> You could try copying the file to the iPod using the command line, >>> or copying data from disk to iPod in, say, C, anything but Python. >>> This would allow you to identify whether Python itself has anything >>> to do with it. >> >> Well, I think I've partially identified the problem. target.write( >> source.read() ) runs perfectly fast, copies 20 megs in about a >> second, from HD to iPod. However, if I run the same code in a while >> loop, using a certain block size, say target.write( source.read(4096) >> ), it takes forever (or at least I'm still timing it while I write >> this post). >> >> The mismatch seems to be between urllib2's block size and the write >> speed of the iPod, I might try to tweak this a little in the code and >> see if it has any effect. >> >> Oh, there we go: 20 megs in 135.8 seconds. Yeah... I might want to >> try to improve that... >> > How long does it take to transfer 4KB? If it can transfer 1MB/s then I'd > say that 4KB is too small. Generally speaking, the higher the data rate, > the larger the blocks you should be transferring at a time, IMHO. > > You could write a script to test the transfer speed with different block > sizes. Thanks MRAB, 32 or 64 KB seems to be quickest, but I'll do a more scientific test soon and see what turns up. From mensanator at aol.com Fri Feb 6 18:55:14 2009 From: mensanator at aol.com (Mensanator) Date: Fri, 6 Feb 2009 15:55:14 -0800 (PST) Subject: Flattening lists References: <9a8af8a3-27fb-4f5b-90ea-ee0276c7e5e3@r15g2000prd.googlegroups.com> Message-ID: <9c2ed038-7a9b-4a35-adae-8b0df890040e@k36g2000pri.googlegroups.com> On Feb 6, 3:23?pm, Rhamphoryncus wrote: > On Feb 5, 1:16?pm, Michele Simionato > wrote: > > > On Feb 5, 7:24?pm, a... at pythoncraft.com (Aahz) wrote: > > > > In article , > > > Michele Simionato ? wrote: > > > > >Looks fine to me. In some situations you may also use hasattr(el, > > > >'__iter__') instead of isinstance(el, list) (it depends if you want to > > > >flatten generic iterables or only lists). > > > > Of course, once you do that, you need to special-case strings... > > > Strings are iterable but have no __iter__ method, which is fine in > > this context, since I would say 99.9% of times one wants to treat them > > as atomic objects, so no need to special case. > > Don't worry, that little oddity was fixed for you: > > Python 3.0+ (unknown, Dec ?8 2008, 14:26:15) > [GCC 4.3.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information.>>> str.__iter__ > > >>> bytes.__iter__ > > >>> bytearray.__iter__ > > > > I'm in the "why do you need more than 1 depth?" camp. ?Dispatching > based on your own type should be given an extra look. ?Dispatching > based passed in types should be given three extra looks. > > I didn't realize itertools.chain(*iterable) worked. ?I guess that > needs to be pushed as the canonical form. What about this (from the Recipes section of the itertools manual)? def flatten(listOfLists): return list(chain.from_iterable(listOfLists)) From ihatespam at hotmail.com Fri Feb 6 19:23:32 2009 From: ihatespam at hotmail.com (Just Another Victim of the Ambient Morality) Date: Fri, 6 Feb 2009 19:23:32 -0500 Subject: Why doesn't this RE match? Message-ID: I'm confused by this behaviour: import re regex = re.compile('foo') match = regex.match('whatfooever') In my experience with regular expressions, regex should have found a match. However, in this case regex.match() returns None. Why is that? What am I missing? Thank you... From google at mrabarnett.plus.com Fri Feb 6 19:26:40 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 07 Feb 2009 00:26:40 +0000 Subject: urllib2 performance on windows, usb connection In-Reply-To: References: <498beb5a$0$3305$9b622d9e@news.freenet.de> Message-ID: <498CD540.1080407@mrabarnett.plus.com> dq wrote: > dq wrote: >> MRAB wrote: >>> dq wrote: >>>> Martin v. L?wis wrote: >>>>>> So does anyone know what the deal is with this? Why is the >>>>>> same code so much slower on Windows? Hope someone can tell >>>>>> me before a holy war erupts :-) >>>>> >>>>> Only the holy war can give an answer here. It certainly has >>>>> *nothing* to do with Python; Python calls the operating >>>>> system functions to read from the network and write to the >>>>> disk almost directly. So it must be the operating system >>>>> itself that slows it down. >>>>> >>>>> To investigate further, you might drop the write operating, >>>>> and measure only source.read(). If that is slower, then, for >>>>> some reason, the network speed is bad on Windows. Maybe you >>>>> have the network interfaces misconfigured? Maybe you are >>>>> using wireless on Windows, but cable on Linux? Maybe you have >>>>> some network filtering software running on Windows? Maybe >>>>> it's just that Windows sucks?-) >>>>> >>>>> If the network read speed is fine, but writing slows down, I >>>>> ask the same questions. Perhaps you have some virus scanner >>>>> installed that filters all write operations? Maybe Windows >>>>> sucks? >>>>> >>>>> Regards, Martin >>>>> >>>> >>>> Thanks for the ideas, Martin. I ran a couple of experiments to >>>> find the culprit, by downloading the same 20 MB file from the >>>> same fast server. I compared: >>>> >>>> 1. DL to HD vs USB iPod. >>>> 2. AV on-access protection on vs. off >>>> 3. "source. read()" only vs. "file.write( source.read() )" >>>> >>>> The culprit is definitely the write speed on the iPod. That >>>> is, everything runs plenty fast (~1 MB/s down) as long as I'm >>>> not writing directly to the iPod. This is kind of odd, because >>>> if I copy the file over from the HD to the iPod using windows >>>> (drag-n-drop), it takes about a second or two, so about 10 >>>> MB/s. >>>> >>>> So the problem is definitely partially Windows, but it also >>>> seems that Python's file.write() function is not without blame. >>>> It's the combination of Windows, iPod and Python's data stream >>>> that is slowing me down. >>>> >>>> I'm not really sure what I can do about this. I'll experiment >>>> a little more and see if there's any way around this >>>> bottleneck. If anyone has run into a problem like this, I'd >>>> love to hear about it... >>>> >>> You could try copying the file to the iPod using the command >>> line, or copying data from disk to iPod in, say, C, anything but >>> Python. This would allow you to identify whether Python itself >>> has anything to do with it. >> >> Well, I think I've partially identified the problem. target.write( >> source.read() ) runs perfectly fast, copies 20 megs in about a >> second, from HD to iPod. However, if I run the same code in a >> while loop, using a certain block size, say target.write( >> source.read(4096) ), it takes forever (or at least I'm still timing >> it while I write this post). >> >> The mismatch seems to be between urllib2's block size and the write >> speed of the iPod, I might try to tweak this a little in the code >> and see if it has any effect. >> >> Oh, there we go: 20 megs in 135.8 seconds. Yeah... I might want >> to try to improve that... > > After some tweaking of the block size, I managed to get the DL speed > up to about 900 Mb/s. It's still not quite Ubuntu, but it's a good > order of magnitude better. The new DL code is pretty much this: > > """ > blocksize = 2 ** 16 # plus or minus a power of 2 > source = urllib2.urlopen( 'url://string' ) > target = open( pathname, 'wb') > fullsize = float( source.info()['Content-Length'] ) > DLd = 0 > while DLd < fullsize: > DLd = DLd + blocksize > # optional: write some DL progress info > # somewhere, e.g. stdout > target.close() > source.close() > """ > I'd like to suggest that the block size you add to 'DLd' be the actual size of the returned block, just in case the read() doesn't return all you asked for (it might not be guaranteed, and the chances are that the final block will be shorter, unless 'fullsize' happens to be a multiple of 'blocksize'). If less is returned by read() then the while-loop might finish before all the data has been downloaded, and if you just add 'blocksize' each time it might end up > 'fullsize', ie apparently >100% downloaded! From vlastimil.brom at gmail.com Fri Feb 6 19:34:05 2009 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sat, 7 Feb 2009 01:34:05 +0100 Subject: Why doesn't this RE match? In-Reply-To: References: Message-ID: <9fdb569a0902061634u3488d8ebs37ea5132f0438ac0@mail.gmail.com> 2009/2/7 Just Another Victim of the Ambient Morality : > ? ?I'm confused by this behaviour: > > > import re > > regex = re.compile('foo') > match = regex.match('whatfooever') > > > ? ?In my experience with regular expressions, regex should have found a > match. ?However, in this case regex.match() returns None. ?Why is that? > What am I missing? > ? ?Thank you... > > > > -- > http://mail.python.org/mailman/listinfo/python-list > Try re.search() instead of match(), if nod only the beginning should be checked for a match: see http://docs.python.org/library/re.html#matching-vs-searching vbr From google at mrabarnett.plus.com Fri Feb 6 19:34:52 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 07 Feb 2009 00:34:52 +0000 Subject: Why doesn't this RE match? In-Reply-To: References: Message-ID: <498CD72C.9010808@mrabarnett.plus.com> Just Another Victim of the Ambient Morality wrote: > I'm confused by this behaviour: > > > import re > > regex = re.compile('foo') > match = regex.match('whatfooever') > > > In my experience with regular expressions, regex should have found a > match. However, in this case regex.match() returns None. Why is that? > What am I missing? > Thank you... > match() is anchored at (ie matches only at) the start of the string. You need search(). It's in the docs! :-) From apt.shansen at gmail.com Fri Feb 6 19:34:54 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Fri, 6 Feb 2009 16:34:54 -0800 Subject: Why doesn't this RE match? In-Reply-To: References: Message-ID: <7a9c25c20902061634o19210809la6573b54ba4528c9@mail.gmail.com> > In my experience with regular expressions, regex should have found a > match. However, in this case regex.match() returns None. Why is that? > What am I missing? You want regex.search(). match specifically looks for the pattern from the start of the screen, search anywhere. --S From robert.kern at gmail.com Fri Feb 6 19:38:16 2009 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 06 Feb 2009 18:38:16 -0600 Subject: Why doesn't this RE match? In-Reply-To: References: Message-ID: On 2009-02-06 18:23, Just Another Victim of the Ambient Morality wrote: > I'm confused by this behaviour: > > > import re > > regex = re.compile('foo') > match = regex.match('whatfooever') > > > In my experience with regular expressions, regex should have found a > match. However, in this case regex.match() returns None. Why is that? > What am I missing? http://docs.python.org/library/re#re.RegexObject.match Basically, regex.match() tries to apply the regexp to the beginning of the string. Use regex.search() to search for a match later in the string. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From bthayre at physics.ucsd.edu Fri Feb 6 19:43:48 2009 From: bthayre at physics.ucsd.edu (Robocop) Date: Fri, 6 Feb 2009 16:43:48 -0800 (PST) Subject: Trouble sorting a list of objects by attributes References: <49ddc228-c4ef-48b2-8fce-70f9e881e216@o40g2000prn.googlegroups.com> <20261325-e75d-4ed6-8c4b-7a4ec7ff2fc5@k1g2000prb.googlegroups.com> <3f1a6661-2bd6-4b12-aa79-03b055ce6745@a39g2000prl.googlegroups.com> Message-ID: <1325a031-2f3a-4e79-b7c9-0da32fbdee16@p23g2000prp.googlegroups.com> On Feb 6, 2:41?pm, Stephen Hansen wrote: > > I think there may have been a misunderstanding. ?I was already using > > attrgetter, my problem is that it doesn't appear to be sorting by the > > argument i give it. ?How does sort work with strings? ?How about with > > datetime.time or datetime.date? > > You were using the attrgetter, but it looks like you weren't doing it correctly: > > ? ? timesheets.sort(key=operator.attrgetter('string')) > > You don't specify a type, be it string or date or anything: you > specify the /name/ of the attribute to get. It'll handle sorting by > any data type that has an order to it without you having to worry > about it at all. Strings, ints, dates, times. > > It should be: > > ? ?timesheets.sort(key=operator.attrgetter("department")) > > If you want to sort by the value of the "department" attribute, which > happens to be a string. > If you want to sort by the "date" attribute, which happens to be a > datetime.date, you do: > ? ?timesheets.sort(key=operator.attrgetter("date")) > > Where date is not a datatype a la datetime.date, but the name of an > attribute on your TimeSheet instances. > > --S Yeah this i totally understand. In my code i was using attrgetter correctly, in the above answer i used string to represent the datatype of the attribute, not what i actually put in there. More my laziness than anything else. The problem boiled down attrgetter taking multiple arguments in 2.5, but only one in 2.4. Thanks for the input though. From sjmachin at lexicon.net Fri Feb 6 19:55:41 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 6 Feb 2009 16:55:41 -0800 (PST) Subject: Why doesn't this RE match? References: Message-ID: On Feb 7, 11:23?am, "Just Another Victim of the Ambient Morality" wrote: > ? ? I'm confused by this behaviour: > > import re > > regex = re.compile('foo') > match = regex.match('whatfooever') > > ? ? In my experience with regular expressions, regex should have found a > match. ?However, in this case regex.match() returns None. ?Why is that? Because that is exactly what it is documented to do. > What am I missing? Inter alia: (1) The whole section of the fantastic manual devoted to this topic: http://www.python.org/doc/2.6/library/re.html#matching-vs-searching (2) a section in the fabulous HOWTO: http://www.python.org/doc/2.6/howto/regex.html#performing-matches (3) the re section in the phantasmagorical help sub-system (very handy if your internet connection goes on the fritz): Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import re >>> help(re) Help on module re: [snip] This module exports the following functions: match Match a regular expression pattern to the beginning of a string. search Search a string for the presence of a pattern. [snip] From kenneth.m.mcdonald at sbcglobal.net Fri Feb 6 19:58:01 2009 From: kenneth.m.mcdonald at sbcglobal.net (Kenneth McDonald) Date: Fri, 6 Feb 2009 18:58:01 -0600 Subject: Possible to access MS Access 2007 password-protected database from Python? Message-ID: <032DE756-C4E7-40E5-BE8F-D959EACD024B@sbcglobal.net> Googling has shown me various ways of connecting to a non-password- protected Access database, but I was wondering if someone could point to code illustrating how to use an Access db that's password- protected. I haven't been able to find anything on this. Thanks, Ken From dq at gmail.com Fri Feb 6 20:51:13 2009 From: dq at gmail.com (dq) Date: Sat, 07 Feb 2009 02:51:13 +0100 Subject: urllib2 performance on windows, usb connection In-Reply-To: References: <498beb5a$0$3305$9b622d9e@news.freenet.de> Message-ID: MRAB wrote: > dq wrote: >> dq wrote: >>> MRAB wrote: >>>> dq wrote: >>>>> Martin v. L?wis wrote: >>>>>>> So does anyone know what the deal is with this? Why is >>>>>>> the same code so much slower on Windows? Hope someone >>>>>>> can tell me before a holy war erupts :-) >>>>>> >>>>>> Only the holy war can give an answer here. It certainly has >>>>>> *nothing* to do with Python; Python calls the operating >>>>>> system functions to read from the network and write to the >>>>>> disk almost directly. So it must be the operating system >>>>>> itself that slows it down. >>>>>> >>>>>> To investigate further, you might drop the write operating, >>>>>> and measure only source.read(). If that is slower, then, >>>>>> for some reason, the network speed is bad on Windows. Maybe >>>>>> you have the network interfaces misconfigured? Maybe you >>>>>> are using wireless on Windows, but cable on Linux? Maybe >>>>>> you have some network filtering software running on >>>>>> Windows? Maybe it's just that Windows sucks?-) >>>>>> >>>>>> If the network read speed is fine, but writing slows down, >>>>>> I ask the same questions. Perhaps you have some virus >>>>>> scanner installed that filters all write operations? Maybe >>>>>> Windows sucks? >>>>>> >>>>>> Regards, Martin >>>>>> >>>>> >>>>> Thanks for the ideas, Martin. I ran a couple of experiments >>>>> to find the culprit, by downloading the same 20 MB file from >>>>> the same fast server. I compared: >>>>> >>>>> 1. DL to HD vs USB iPod. 2. AV on-access protection on vs. >>>>> off 3. "source. read()" only vs. "file.write( >>>>> source.read() )" >>>>> >>>>> The culprit is definitely the write speed on the iPod. That >>>>> is, everything runs plenty fast (~1 MB/s down) as long as I'm >>>>> not writing directly to the iPod. This is kind of odd, >>>>> because if I copy the file over from the HD to the iPod using >>>>> windows (drag-n-drop), it takes about a second or two, so >>>>> about 10 MB/s. >>>>> >>>>> So the problem is definitely partially Windows, but it also >>>>> seems that Python's file.write() function is not without >>>>> blame. It's the combination of Windows, iPod and Python's >>>>> data stream that is slowing me down. >>>>> >>>>> I'm not really sure what I can do about this. I'll >>>>> experiment a little more and see if there's any way around >>>>> this bottleneck. If anyone has run into a problem like this, >>>>> I'd love to hear about it... >>>>> >>>> You could try copying the file to the iPod using the command >>>> line, or copying data from disk to iPod in, say, C, anything >>>> but Python. This would allow you to identify whether Python >>>> itself has anything to do with it. >>> >>> Well, I think I've partially identified the problem. >>> target.write( source.read() ) runs perfectly fast, copies 20 megs >>> in about a second, from HD to iPod. However, if I run the same >>> code in a while loop, using a certain block size, say >>> target.write( source.read(4096) ), it takes forever (or at least >>> I'm still timing it while I write this post). >>> >>> The mismatch seems to be between urllib2's block size and the >>> write speed of the iPod, I might try to tweak this a little in >>> the code and see if it has any effect. >>> >>> Oh, there we go: 20 megs in 135.8 seconds. Yeah... I might >>> want to try to improve that... >> >> After some tweaking of the block size, I managed to get the DL >> speed up to about 900 Mb/s. It's still not quite Ubuntu, but it's >> a good order of magnitude better. The new DL code is pretty much >> this: >> >> """ blocksize = 2 ** 16 # plus or minus a power of 2 source = >> urllib2.urlopen( 'url://string' ) target = open( pathname, 'wb') >> fullsize = float( source.info()['Content-Length'] ) DLd = 0 while >> DLd < fullsize: DLd = DLd + blocksize # optional: write some DL >> progress info # somewhere, e.g. stdout target.close() >> source.close() """ >> > I'd like to suggest that the block size you add to 'DLd' be the > actual size of the returned block, just in case the read() doesn't > return all you asked for (it might not be guaranteed, and the chances > are that the final block will be shorter, unless 'fullsize' happens > to be a multiple of 'blocksize'). > > If less is returned by read() then the while-loop might finish before > all the data has been downloaded, and if you just add 'blocksize' > each time it might end up > 'fullsize', ie apparently >100% > downloaded! Interesting. I'll if to see if any of the downloaded files end prematurely :) btw, I forgot the most important line of the code! """ blocksize = 2 ** 16 # plus or minus a power of 2 source = urllib2.urlopen( 'url://string' ) target = open( pathname, 'wb') fullsize = float( source.info()['Content-Length'] ) DLd = 0 while DLd < fullsize: # +++ target.write( source.read( blocksize ) ) # +++ # +++ DLd = DLd + blocksize # optional: write some DL progress info # somewhere, e.g. stdout target.close() source.close() """ Using that, I'm not quite sure where I can grab onto the value of how much was actually read from the block. I suppose I could use an intermediate variable, read the data into it, measure the size, and then write it to the file stream, but I'm not sure it would be worth the overhead. Or is there some other magic I should know about? If I start to get that problem, at least I'll know where to look... From jason at jvoegele.com Fri Feb 6 21:11:15 2009 From: jason at jvoegele.com (Jason Voegele) Date: Fri, 06 Feb 2009 21:11:15 -0500 Subject: Running all unit tests Message-ID: I'm working on my first substantial Python project, and I'm following a fully test-first approach. I'd like to know how Pythonistas typically go about running all of their tests to ensure that my application stays "green". In Ruby, I would have a Rake task so that I could say "rake test" and all tests would be executed. In C or C++ I would have a make target so I could run all my tests with "make test". In Java it would be an Ant task and "ant test". And so forth and so on. What's the recommended approach for Python programs? I'm sure I could write a shell script (or a Python script even) that scans my "test" directory for test cases and runs them, but I'm wondering if there's something already built in that could do this for me. -- Jason Voegele Only fools are quoted. -- Anonymous From google at mrabarnett.plus.com Fri Feb 6 21:28:09 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 07 Feb 2009 02:28:09 +0000 Subject: urllib2 performance on windows, usb connection In-Reply-To: References: <498beb5a$0$3305$9b622d9e@news.freenet.de> Message-ID: <498CF1B9.70101@mrabarnett.plus.com> dq wrote: > MRAB wrote: >> dq wrote: >>> dq wrote: >>>> MRAB wrote: >>>>> dq wrote: >>>>>> Martin v. L?wis wrote: >>>>>>>> So does anyone know what the deal is with this? Why is the same >>>>>>>> code so much slower on Windows? Hope someone can tell me before >>>>>>>> a holy war erupts :-) >>>>>>> >>>>>>> Only the holy war can give an answer here. It certainly has >>>>>>> *nothing* to do with Python; Python calls the operating system >>>>>>> functions to read from the network and write to the disk almost >>>>>>> directly. So it must be the operating system itself that slows it >>>>>>> down. >>>>>>> >>>>>>> To investigate further, you might drop the write operating, >>>>>>> and measure only source.read(). If that is slower, then, for >>>>>>> some reason, the network speed is bad on Windows. Maybe >>>>>>> you have the network interfaces misconfigured? Maybe you are >>>>>>> using wireless on Windows, but cable on Linux? Maybe you have >>>>>>> some network filtering software running on Windows? Maybe it's >>>>>>> just that Windows sucks?-) >>>>>>> >>>>>>> If the network read speed is fine, but writing slows down, >>>>>>> I ask the same questions. Perhaps you have some virus scanner >>>>>>> installed that filters all write operations? Maybe >>>>>>> Windows sucks? >>>>>>> >>>>>>> Regards, Martin >>>>>>> >>>>>> >>>>>> Thanks for the ideas, Martin. I ran a couple of experiments >>>>>> to find the culprit, by downloading the same 20 MB file from >>>>>> the same fast server. I compared: >>>>>> >>>>>> 1. DL to HD vs USB iPod. 2. AV on-access protection on vs. >>>>>> off 3. "source. read()" only vs. "file.write( >>>>>> source.read() )" >>>>>> >>>>>> The culprit is definitely the write speed on the iPod. That is, >>>>>> everything runs plenty fast (~1 MB/s down) as long as I'm >>>>>> not writing directly to the iPod. This is kind of odd, because if >>>>>> I copy the file over from the HD to the iPod using >>>>>> windows (drag-n-drop), it takes about a second or two, so about >>>>>> 10 MB/s. >>>>>> >>>>>> So the problem is definitely partially Windows, but it also seems >>>>>> that Python's file.write() function is not without blame. It's the >>>>>> combination of Windows, iPod and Python's data stream that is >>>>>> slowing me down. >>>>>> >>>>>> I'm not really sure what I can do about this. I'll experiment a >>>>>> little more and see if there's any way around this bottleneck. If >>>>>> anyone has run into a problem like this, >>>>>> I'd love to hear about it... >>>>>> >>>>> You could try copying the file to the iPod using the command line, >>>>> or copying data from disk to iPod in, say, C, anything but Python. >>>>> This would allow you to identify whether Python itself has anything >>>>> to do with it. >>>> >>>> Well, I think I've partially identified the problem. target.write( >>>> source.read() ) runs perfectly fast, copies 20 megs >>>> in about a second, from HD to iPod. However, if I run the same >>>> code in a while loop, using a certain block size, say target.write( >>>> source.read(4096) ), it takes forever (or at least >>>> I'm still timing it while I write this post). >>>> >>>> The mismatch seems to be between urllib2's block size and the write >>>> speed of the iPod, I might try to tweak this a little in the code >>>> and see if it has any effect. >>>> >>>> Oh, there we go: 20 megs in 135.8 seconds. Yeah... I might want >>>> to try to improve that... >>> >>> After some tweaking of the block size, I managed to get the DL speed >>> up to about 900 Mb/s. It's still not quite Ubuntu, but it's >>> a good order of magnitude better. The new DL code is pretty much >>> this: >>> >>> """ blocksize = 2 ** 16 # plus or minus a power of 2 source = >>> urllib2.urlopen( 'url://string' ) target = open( pathname, 'wb') >>> fullsize = float( source.info()['Content-Length'] ) DLd = 0 while DLd >>> < fullsize: DLd = DLd + blocksize # optional: write some DL progress >>> info # somewhere, e.g. stdout target.close() source.close() """ >>> >> I'd like to suggest that the block size you add to 'DLd' be the actual >> size of the returned block, just in case the read() doesn't return all >> you asked for (it might not be guaranteed, and the chances >> are that the final block will be shorter, unless 'fullsize' happens >> to be a multiple of 'blocksize'). >> >> If less is returned by read() then the while-loop might finish before >> all the data has been downloaded, and if you just add 'blocksize' >> each time it might end up > 'fullsize', ie apparently >100% downloaded! > > Interesting. I'll if to see if any of the downloaded files end > prematurely :) > > btw, I forgot the most important line of the code! > > """ > blocksize = 2 ** 16 # plus or minus a power of 2 > source = urllib2.urlopen( 'url://string' ) > target = open( pathname, 'wb') > fullsize = float( source.info()['Content-Length'] ) > DLd = 0 > while DLd < fullsize: > # +++ > target.write( source.read( blocksize ) ) # +++ > # +++ > DLd = DLd + blocksize > # optional: write some DL progress info > # somewhere, e.g. stdout > target.close() > source.close() > """ > > Using that, I'm not quite sure where I can grab onto the value of how > much was actually read from the block. I suppose I could use an > intermediate variable, read the data into it, measure the size, and then > write it to the file stream, but I'm not sure it would be worth the > overhead. Or is there some other magic I should know about? > > If I start to get that problem, at least I'll know where to look... > It's just: data = source.read(blocksize) target.write(data) DLd = DLd + len(data) The overhead is tiny because you're not copying the data. If 'x' refers to a 1MB bytestring and you do "y = x" or "foo(x)", you're not actually copying that bytestring; you're just making 'y' also refer to it or passing the reference to it into 'foo'. It's a bit passing pointers around, but without the nasty bits! :-) From mdw at distorted.org.uk Fri Feb 6 21:42:44 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 07 Feb 2009 02:42:44 +0000 Subject: Using while loop and if statement to tell if a binary has an odd or even number of 1's. References: <6c1875c3-8283-4764-a481-ebfa135868bc@v5g2000pre.googlegroups.com> Message-ID: <874oz7klwb.fsf.mdw@metalzone.distorted.org.uk> Duncan Booth writes: > Mark Dickinson wrote: [snip] >> while n: >> count += 1 >> n &= n-1 >> return count >> >> is_even = count_set_bits(the_int) % 2 == 0 >> >> ...but anyone submitting this as a homework >> solution had better be prepared to explain why >> it works. >> > > I remember a programming exercise when I was an undergraduate and anyone > who *didn't* use that trick got marked down for writing inefficient > code. Curious. I don't see why def parity(x): b = 2 l = 1 while True: b <<= l if x < b: break l <<= 1 while l: b >>= l x ^= x >> l x &= b - 1 l >>= 1 return x & 1 is any less efficient. Indeed, it seems more so to me. The number of top-level loop iterations is bounded by the logarithm of the total number of bits in the input rather than the Hamming weight. In terms of single-precision operations (if we're dealing with bignums) the analysis is more complicated; but the number of single-precision operations in one of my loops is a linear function of l (assuming that the comparison is done sensibly), and l increases and decreases geometrically, so I have performance which is O(log x). Assuming no special Hamming-weight distribution on the input, the `efficient' version takes O(log^2 x) single-precision operations. Given an /a-priori/ upper bound on the length of the input, e.g., it fits in a machine word, the above technique is still probably faster. That is, assuming arithmetic and bitwise operations on integers take constant time, my version runs in O(log log x) time whereas the `efficient' version takes O(log x) time. (My function returns the complement of the value requested. Fixing it is obviously trivial.) -- [mdw] From vlastimil.brom at gmail.com Fri Feb 6 21:45:10 2009 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sat, 7 Feb 2009 03:45:10 +0100 Subject: sys.exc_info() different between python 2.5.4 and 2.6.1? Message-ID: <9fdb569a0902061845k31cffbb4l28927c2fc8ecb3a9@mail.gmail.com> Hi all, I just noticed a changed behaviour of sys.exc_info() between python 2.5.4 and 2.6.1 and wanted to ask, wheter it was intended, and how to deal with the new state. Some code triggers an error while opening a text file (windows 1250 - with non-ascii characters) wrongly as utf-8, this gets catched by a bare except clause. Further the mentioned versions of python differ in handling sys.exc_info() The following lines: print sys.exc_info()[1] print repr(sys.exc_info()[1]) print str(sys.exc_info()[1]) print unicode(sys.exc_info()[1]) result in python 2.5 in: 'utf8' codec can't decode byte 0x9a in position 2: unexpected code byte UnicodeDecodeError('utf8', 'ab\x9acd', 2, 3, 'unexpected code byte') 'utf8' codec can't decode byte 0x9a in position 2: unexpected code byte 'utf8' codec can't decode byte 0x9a in position 2: unexpected code byte in python 2.6 it is: 'utf8' codec can't decode byte 0x9a in position 2: unexpected code byte UnicodeDecodeError('utf8', 'ab\x9acd', 2, 3, 'unexpected code byte') 'utf8' codec can't decode byte 0x9a in position 2: unexpected code byte ('utf8', 'ab\x9acd', 2, 3, 'unexpected code byte') Which is kind of confusing as my the excepthook function uses the unicode() form of sys.exc_info()[1] (The second part "ab\x9acd" is the whole content of the file being read - which is normally quite a bit longer than this sample...) Is this the expected behaviour? If so, what might be the reason for differently outputting str() and unicode()? How can this be dealt with, are the standard error values somehow expected to be ascii, so that str() can be used reasonably? Any hints are much appreciated, Vlasta From darcymason at gmail.com Fri Feb 6 21:46:39 2009 From: darcymason at gmail.com (Darcy Mason) Date: Fri, 6 Feb 2009 18:46:39 -0800 (PST) Subject: Running all unit tests References: Message-ID: <77db8f43-3196-41c9-bbfe-f7da9c27c4a6@r41g2000yqm.googlegroups.com> On Feb 6, 9:11?pm, Jason Voegele wrote: > I'm working on my first substantial Python project, and I'm following a fully > test-first approach. ?I'd like to know how Pythonistas typically go about > running all of their tests to ensure that my application stays "green". > > In Ruby, I would have a Rake task so that I could say "rake test" and all > tests would be executed. ?In C or C++ I would have a make target so I could > run all my tests with "make test". ?In Java it would be an Ant task and "ant > test". ?And so forth and so on. > > What's the recommended approach for Python programs? ?I'm sure I could write > a shell script (or a Python script even) that scans my "test" directory for > test cases and runs them, but I'm wondering if there's something already > built in that could do this for me. > > -- > Jason Voegele > Only fools are quoted. > ? ? ? ? ? ? ? ? -- Anonymous I don't know about the recommended approach, but I've done something like you suggest in a library I authored. Any files named test*.py are found and added to the unittest test suite. See http://code.google.com/p/pydicom/source/browse/trunk/source/dicom/test/run_tests.py. HTH Darcy From darcy at druid.net Fri Feb 6 21:52:29 2009 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 6 Feb 2009 21:52:29 -0500 Subject: Running all unit tests In-Reply-To: References: Message-ID: <20090206215229.f0951075.darcy@druid.net> On Fri, 06 Feb 2009 21:11:15 -0500 Jason Voegele wrote: > I'm working on my first substantial Python project, and I'm following a fully > test-first approach. I'd like to know how Pythonistas typically go about > running all of their tests to ensure that my application stays "green". I check in my unit tests to CVS along with the code and name the unit test files with the form "TEST_xxx.py" to identify them. I then put the following script into my crontab so that my tests are run every day. I make the TEST_xxx.py executible so that I can always run a specific test at any time if I am working on specific code. Note that the script only sends email when something goes "red" so I don't have to wade through "green" reports every day. The errors stand out that way. #! /bin/sh # $Id: run_unit_tests,v 1.4 2008/06/23 01:07:24 darcy Exp $ # This script runs all of the unit tests if [ $# -lt 2 ] then echo "Usage: $0 []" exit 1 fi cd $1 trap "rm -f /tmp/run_tests.$$" 0 HOST=`hostname` find -L . -type f -name 'TEST_*.py' | while read TEST do $TEST > /tmp/run_tests.$$ 2>&1 || mail -s "TEST failure on $HOST: $TEST" $2 < /tmp/run_tests.$$ done -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From erobererunc at gmail.com Fri Feb 6 22:18:37 2009 From: erobererunc at gmail.com (er) Date: Fri, 6 Feb 2009 22:18:37 -0500 Subject: Lists implemented as integer-hashed Dictionaries? Message-ID: <775033410902061918l3a16c8fi82329b8f6f244daa@mail.gmail.com> Somebody much more intelligent than I said today that someone told him that Python lists are just dictionaries with lists hashed by integers. Since he said that someone else told him this, I piped up and said that I thought that wasn't true. I looked at the source code for lists in python, and I did not expressly remember seeing dictionaries. Unfortunately I am not somewhere where I can easily look at the code right now (I'm logged into Windows!), and I might not realize exactly what I'm looking at anyways, but I'd like to extend an apology to the guy soon if I was wrong. So, can anyone tell me if lists are really just dictionaries? Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From erobererunc at gmail.com Fri Feb 6 22:24:08 2009 From: erobererunc at gmail.com (er) Date: Fri, 6 Feb 2009 22:24:08 -0500 Subject: Lists implemented as integer-hashed Dictionaries? In-Reply-To: <775033410902061918l3a16c8fi82329b8f6f244daa@mail.gmail.com> References: <775033410902061918l3a16c8fi82329b8f6f244daa@mail.gmail.com> Message-ID: <775033410902061924l6997998dh617fa72c4852d098@mail.gmail.com> Correction, the first sentence should read, "lists are just dictionaries keyed with integers." On Fri, Feb 6, 2009 at 10:18 PM, er wrote: > Somebody much more intelligent than I said today that someone told him that > Python lists are just dictionaries with lists hashed by integers. Since he > said that someone else told him this, I piped up and said that I thought > that wasn't true. I looked at the source code for lists in python, and I > did not expressly remember seeing dictionaries. Unfortunately I am not > somewhere where I can easily look at the code right now (I'm logged into > Windows!), and I might not realize exactly what I'm looking at anyways, but > I'd like to extend an apology to the guy soon if I was wrong. So, can > anyone tell me if lists are really just dictionaries? Thanks! > -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Fri Feb 6 22:25:08 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 6 Feb 2009 19:25:08 -0800 Subject: Lists implemented as integer-hashed Dictionaries? In-Reply-To: <775033410902061918l3a16c8fi82329b8f6f244daa@mail.gmail.com> References: <775033410902061918l3a16c8fi82329b8f6f244daa@mail.gmail.com> Message-ID: <50697b2c0902061925w36ed850bw796f6737c15e06af@mail.gmail.com> On Fri, Feb 6, 2009 at 7:18 PM, er wrote: > Somebody much more intelligent than I said today that someone told him that > Python lists are just dictionaries with lists hashed by integers. Since he > said that someone else told him this, I piped up and said that I thought > that wasn't true. I looked at the source code for lists in python, and I > did not expressly remember seeing dictionaries. Unfortunately I am not > somewhere where I can easily look at the code right now (I'm logged into > Windows!), and I might not realize exactly what I'm looking at anyways, but > I'd like to extend an apology to the guy soon if I was wrong. So, can > anyone tell me if lists are really just dictionaries? Thanks! They most certainly are not. This is Python, not Lua or PHP (where for reasons I cannot fathom, they've seen fit to conflate dictionaries and lists; although it does make slightly more sense in Lua's case) Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From bignose+hates-spam at benfinney.id.au Fri Feb 6 22:29:30 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Sat, 07 Feb 2009 14:29:30 +1100 Subject: Running all unit tests References: Message-ID: <877i42x6ud.fsf@benfinney.id.au> Jason Voegele writes: > What's the recommended approach for Python programs? I'm sure I > could write a shell script (or a Python script even) that scans my > "test" directory for test cases and runs them, but I'm wondering if > there's something already built in that could do this for me. The lack of a built-in ?collect and run all the tests in this working tree? in the Python unit test system is a known problem; discussions are ongoing what to do about it. Meanwhile, the third-party ?nose? system provides this and much more, while remaining compatible with both testing systems in the standard library. I generally set up a ?test? target in my Makefile, such that it will use ?nosetests? to collect and run all the tests; then I just run ?make test? in a loop that is triggered by any filesystem change in my project working tree. -- \ ?I have a microwave fireplace in my house. The other night I | `\ laid down in front of the fire for the evening in two minutes.? | _o__) ?Steven Wright | Ben Finney From roy at panix.com Fri Feb 6 22:32:20 2009 From: roy at panix.com (Roy Smith) Date: Fri, 6 Feb 2009 19:32:20 -0800 (PST) Subject: Portable way to refer to the null device? Message-ID: I need to run a command using subprocess.Popen() and have stdin connected to the null device. On unix, I would do: self.process = subprocess.Popen(argv, env=new_env, stdout=open(outfile, 'w'), stderr=open(errfile, 'w'), stdin=open('/dev/null') ) but that's not portable to windows. Does Python have a portable way to get a file object connected to the null device, regardless of what operating system you're running on? From erobererunc at gmail.com Fri Feb 6 22:32:31 2009 From: erobererunc at gmail.com (er) Date: Fri, 6 Feb 2009 22:32:31 -0500 Subject: Lists implemented as integer-hashed Dictionaries? In-Reply-To: <50697b2c0902061925w36ed850bw796f6737c15e06af@mail.gmail.com> References: <775033410902061918l3a16c8fi82329b8f6f244daa@mail.gmail.com> <50697b2c0902061925w36ed850bw796f6737c15e06af@mail.gmail.com> Message-ID: <775033410902061932g6f943500s267d07f68accef98@mail.gmail.com> Thanks Chris. Lua tables are one of my favorite linguistic traits, which was actually part of the discussion that brought up this nugget. Nevertheless, any details you care to provide about the details. I'm going to dive into the source code in more depth tomorrow, just so I can get a better understanding anyway, but I'd love to hear some details, or see any links, if you have them. On Fri, Feb 6, 2009 at 10:25 PM, Chris Rebert wrote: > On Fri, Feb 6, 2009 at 7:18 PM, er wrote: > > Somebody much more intelligent than I said today that someone told him > that > > Python lists are just dictionaries with lists hashed by integers. Since > he > > said that someone else told him this, I piped up and said that I thought > > that wasn't true. I looked at the source code for lists in python, and I > > did not expressly remember seeing dictionaries. Unfortunately I am not > > somewhere where I can easily look at the code right now (I'm logged into > > Windows!), and I might not realize exactly what I'm looking at anyways, > but > > I'd like to extend an apology to the guy soon if I was wrong. So, can > > anyone tell me if lists are really just dictionaries? Thanks! > > They most certainly are not. This is Python, not Lua or PHP (where for > reasons I cannot fathom, they've seen fit to conflate dictionaries and > lists; although it does make slightly more sense in Lua's case) > > Cheers, > Chris > > -- > Follow the path of the Iguana... > http://rebertia.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Fri Feb 6 22:44:09 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 6 Feb 2009 19:44:09 -0800 Subject: Lists implemented as integer-hashed Dictionaries? In-Reply-To: <775033410902061932g6f943500s267d07f68accef98@mail.gmail.com> References: <775033410902061918l3a16c8fi82329b8f6f244daa@mail.gmail.com> <50697b2c0902061925w36ed850bw796f6737c15e06af@mail.gmail.com> <775033410902061932g6f943500s267d07f68accef98@mail.gmail.com> Message-ID: <50697b2c0902061944p16054f68r7bd9175e9fddbdf7@mail.gmail.com> > On Fri, Feb 6, 2009 at 10:25 PM, Chris Rebert wrote: >> On Fri, Feb 6, 2009 at 7:18 PM, er wrote: >> > Somebody much more intelligent than I said today that someone told him >> > that >> > Python lists are just dictionaries with lists hashed by integers. Since >> > he >> > said that someone else told him this, I piped up and said that I thought >> > that wasn't true. I looked at the source code for lists in python, and >> > I >> > did not expressly remember seeing dictionaries. Unfortunately I am not >> > somewhere where I can easily look at the code right now (I'm logged into >> > Windows!), and I might not realize exactly what I'm looking at anyways, >> > but >> > I'd like to extend an apology to the guy soon if I was wrong. So, can >> > anyone tell me if lists are really just dictionaries? Thanks! >> >> They most certainly are not. This is Python, not Lua or PHP (where for >> reasons I cannot fathom, they've seen fit to conflate dictionaries and >> lists; although it does make slightly more sense in Lua's case) >> On Fri, Feb 6, 2009 at 7:32 PM, er wrote: > Thanks Chris. Lua tables are one of my favorite linguistic traits, which > was actually part of the discussion that brought up this nugget. > Nevertheless, any details you care to provide about the details. I'm going > to dive into the source code in more depth tomorrow, just so I can get a > better understanding anyway, but I'd love to hear some details, or see any > links, if you have them. Unfortunately, I don't know the details as I'm not a CPython dev. I only indirectly know that arrays are used from having read so previously in writings talking about the implementation. Also, Python generally tries to make its basic datatypes speedy, and using dictionaries to implement lists would be completely counter to that goal, no matter how excellent the dictionary implementation is. In all likelihood, someone who /is/ familiar with the implementation will probably chime in with the actual details. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From skip at pobox.com Fri Feb 6 22:51:13 2009 From: skip at pobox.com (skip at pobox.com) Date: Fri, 6 Feb 2009 21:51:13 -0600 Subject: Portable way to refer to the null device? In-Reply-To: References: Message-ID: <18829.1329.91043.255369@montanaro.dyndns.org> Roy> I need to run a command using subprocess.Popen() and have stdin Roy> connected to the null device. os.path.devnull should do what you want: >>> os.path.devnull '/dev/null' >>> import ntpath >>> ntpath.devnull 'nul' -- Skip Montanaro - skip at pobox.com - http://www.smontanaro.net/ From bignose+hates-spam at benfinney.id.au Fri Feb 6 23:07:09 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Sat, 07 Feb 2009 15:07:09 +1100 Subject: Portable way to refer to the null device? References: Message-ID: <871vuax53m.fsf@benfinney.id.au> Roy Smith writes: > I need to run a command using subprocess.Popen() and have stdin > connected to the null device. On unix, I would do: > > self.process = subprocess.Popen(argv, > env=new_env, > stdout=open(outfile, 'w'), > stderr=open(errfile, 'w'), > stdin=open('/dev/null') > ) Yikes, that's a nasty indentation you've got going on there. I'd be writing the above as: self.process = subprocess.Popen( argv, env=new_env, stdout=open(outfile, 'w'), stderr=open(errfile, 'w'), stdin=open('/dev/null'), ) > but that's not portable to windows. Does Python have a portable way > to get a file object connected to the null device, regardless of what > operating system you're running on? Almost: the ?os.devnull? attribute is documented (in the documentation for the ?os? module) as ?os.devnull is the file path of the null device ('/dev/null', etc.)?. So the above becomes: self.process = subprocess.Popen( argv, env=new_env, stdout=open(outfile, 'w'), stderr=open(errfile, 'w'), stdin=open(os.devnull), ) -- \ ?Pinky, are you pondering what I'm pondering?? ?I think so, | `\ Brain, but how will we get a pair of Abe Vigoda's pants?? | _o__) ?_Pinky and The Brain_ | Ben Finney From vincent at vincentdavis.net Fri Feb 6 23:16:02 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Fri, 6 Feb 2009 21:16:02 -0700 Subject: simple web app, where to start Message-ID: <77e831100902062016q2d92ee3awb907baf47f477858@mail.gmail.com> I have a simple script that takes a few input values and returns a csv file and a few stats. If I wanted to host this on the web how would I. I have no idea where to begin. If someone could point me in the right direction like maybe a tutorial, tools I will need, functions..... I would appreciate it.I know a little html but am not sure how to integrate python or know what servers will handle it ..... Thanks Vincent Davis -------------- next part -------------- An HTML attachment was scrubbed... URL: From aioe.org at technicalbloke.com Fri Feb 6 23:19:24 2009 From: aioe.org at technicalbloke.com (r0g) Date: Fri, 06 Feb 2009 23:19:24 -0500 Subject: Returning a variable number of things... References: Message-ID: Chris Rebert wrote: > On Fri, Feb 6, 2009 at 10:50 AM, r0g wrote: >> Hi There, >> >> I have a function that uses *args to accept a variable number of >> parameters and I would like it to return a variable number of objects. >> >> I could return a list but I would like to take advantage of tuple >> unpacking with the return values e.g. > > Despite its name, tuple unpacking works with lists too. > > Cheers, > Chris > Ah so it does! Thanks Chris! I'm losing count of all the reasons I have to love this language :-) From clp2 at rebertia.com Fri Feb 6 23:37:28 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 6 Feb 2009 20:37:28 -0800 Subject: WebError documentation? In-Reply-To: References: Message-ID: <50697b2c0902062037w572445f1t42ca2a29d8ec60f0@mail.gmail.com> On Thu, Feb 5, 2009 at 12:52 PM, Ron Garret wrote: > Is there any? Where is it? Extensive Googling has proven fruitless. It's not a standard Python exception. A third-party library you're using must be raising it. Check the exception traceback. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From michele.simionato at gmail.com Fri Feb 6 23:40:20 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 6 Feb 2009 20:40:20 -0800 (PST) Subject: Flattening lists References: <9a8af8a3-27fb-4f5b-90ea-ee0276c7e5e3@r15g2000prd.googlegroups.com> Message-ID: <9b81090e-4a29-4feb-bcf3-c5ba26c20188@o36g2000yqh.googlegroups.com> On Feb 6, 10:23?pm, Rhamphoryncus wrote: > On Feb 5, 1:16?pm, Michele Simionato > wrote: > > > On Feb 5, 7:24?pm, a... at pythoncraft.com (Aahz) wrote: > > > > In article , > > > Michele Simionato ? wrote: > > > > >Looks fine to me. In some situations you may also use hasattr(el, > > > >'__iter__') instead of isinstance(el, list) (it depends if you want to > > > >flatten generic iterables or only lists). > > > > Of course, once you do that, you need to special-case strings... > > > Strings are iterable but have no __iter__ method, which is fine in > > this context, since I would say 99.9% of times one wants to treat them > > as atomic objects, so no need to special case. > > Don't worry, that little oddity was fixed for you: Acc! I have a few places in my code with checks of the kind ``hasattr(x, '__iter__')`` and I guess those spots will be tricky when converting to Python 3. I guess 2to3 cannot help either :-( From apt.shansen at gmail.com Fri Feb 6 23:47:52 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Fri, 6 Feb 2009 20:47:52 -0800 Subject: Lists implemented as integer-hashed Dictionaries? In-Reply-To: <775033410902061932g6f943500s267d07f68accef98@mail.gmail.com> References: <775033410902061918l3a16c8fi82329b8f6f244daa@mail.gmail.com> <50697b2c0902061925w36ed850bw796f6737c15e06af@mail.gmail.com> <775033410902061932g6f943500s267d07f68accef98@mail.gmail.com> Message-ID: <7a9c25c20902062047y8afacb8xd0ab1649d7ab843e@mail.gmail.com> On Fri, Feb 6, 2009 at 7:32 PM, er wrote: > Thanks Chris. Lua tables are one of my favorite linguistic traits, which > was actually part of the discussion that brought up this nugget. > Nevertheless, any details you care to provide about the details. I'm going > to dive into the source code in more depth tomorrow, just so I can get a > better understanding anyway, but I'd love to hear some details, or see any > links, if you have them. Yeah, as Chris said, Python lists are not dictionaries at all. They're PyObjects that contain an array of pointers to other PyObjects. Basic Python types try to be efficient and reliable. They're not always the perfect choice, but they strive to be good enough for most situations in terms of both functionality and speed... and while they have put a lot of effort into tuning Python's hash implementation, an array has to beat it hands down when you're implementing an ordered sequence. Now, I believe Python sets *are* for all intents and purposes dictionaries, but I think that's just because its the easiest and most efficient way to implement their uniqueness properties; they took the very-well-tuned dictionary implementation and cut out the stuff not needed by sets and did some tweaks here or there. I /believe/. --S From exarkun at divmod.com Sat Feb 7 00:15:20 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Sat, 7 Feb 2009 00:15:20 -0500 Subject: Running all unit tests In-Reply-To: Message-ID: <20090207051520.12853.2145202965.divmod.quotient.6828@henry.divmod.com> On Fri, 06 Feb 2009 21:11:15 -0500, Jason Voegele wrote: >I'm working on my first substantial Python project, and I'm following a fully >test-first approach. I'd like to know how Pythonistas typically go about >running all of their tests to ensure that my application stays "green". > >In Ruby, I would have a Rake task so that I could say "rake test" and all >tests would be executed. In C or C++ I would have a make target so I could >run all my tests with "make test". In Java it would be an Ant task and "ant >test". And so forth and so on. > >What's the recommended approach for Python programs? I'm sure I could write >a shell script (or a Python script even) that scans my "test" directory for >test cases and runs them, but I'm wondering if there's something already >built in that could do this for me. There are a bunch of tools for this. I use trial (part of Twisted), which will collect your tests, run them, and report the results (and has helpers for debugging, profiling, and some other stuff) and buildbot. Jean-Paul From rdmurray at bitdance.com Sat Feb 7 00:21:45 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Sat, 7 Feb 2009 05:21:45 +0000 (UTC) Subject: Flattening lists References: <9a8af8a3-27fb-4f5b-90ea-ee0276c7e5e3@r15g2000prd.googlegroups.com> <9c2ed038-7a9b-4a35-adae-8b0df890040e@k36g2000pri.googlegroups.com> Message-ID: Quoth Mensanator : > On Feb 6, 3:23=A0pm, Rhamphoryncus wrote: > > On Feb 5, 1:16=A0pm, Michele Simionato > > wrote: > > > > > On Feb 5, 7:24=A0pm, a... at pythoncraft.com (Aahz) wrote: > > > > In article , > > > > Michele Simionato =A0 wrote: > > > > >Looks fine to me. In some situations you may also use hasattr(el, > > > > >'__iter__') instead of isinstance(el, list) (it depends if you want to > > > > >flatten generic iterables or only lists). > > > > Of course, once you do that, you need to special-case strings... > > > > > Strings are iterable but have no __iter__ method, which is fine in > > > this context, since I would say 99.9% of times one wants to treat them > > > as atomic objects, so no need to special case. > > > > Don't worry, that little oddity was fixed for you: > > > > Python 3.0+ (unknown, Dec =A08 2008, 14:26:15) > > [GCC 4.3.2] on linux2 > > Type "help", "copyright", "credits" or "license" for more information. > > >>> str.__iter__ > > > >>> bytes.__iter__ > > > >>> bytearray.__iter__ > > > > > > I'm in the "why do you need more than 1 depth?" camp. Dispatching > > based on your own type should be given an extra look. Dispatching > > based passed in types should be given three extra looks. > > > > I didn't realize itertools.chain(*iterable) worked. I guess that > > needs to be pushed as the canonical form. > > What about this (from the Recipes section of the itertools manual)? > > def flatten(listOfLists): > return list(chain.from_iterable(listOfLists)) Python 2.6.1 (r261:67515, Jan 7 2009, 17:09:13) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from itertools import chain >>> list(chain.from_iterable([1, 2, [3, 4]])) Traceback (most recent call last): File "", line 1, in TypeError: 'int' object is not iterable >>> list(chain(*[1, 2, [3, 4]])) Traceback (most recent call last): File "", line 1, in TypeError: 'int' object is not iterable >>> list(chain.from_iterable(['abcd', 'efg', [3, 4]])) ['a', 'b', 'c', 'd', 'e', 'f', 'g', 3, 4] --RDM From ntwrkd at gmail.com Sat Feb 7 00:41:30 2009 From: ntwrkd at gmail.com (Matthew Sacks) Date: Fri, 6 Feb 2009 21:41:30 -0800 Subject: simple web app, where to start In-Reply-To: <77e831100902062016q2d92ee3awb907baf47f477858@mail.gmail.com> References: <77e831100902062016q2d92ee3awb907baf47f477858@mail.gmail.com> Message-ID: have a loo at the django framework http://www.djangoproject.com/ On Fri, Feb 6, 2009 at 8:16 PM, Vincent Davis wrote: > I have a simple script that takes a few input values and returns a csv file > and a few stats. If I wanted to host this on the web how would I. I have no > idea where to begin. If someone could point me in the right direction like > maybe a tutorial, tools I will need, functions..... I would appreciate it. > I know a little html but am not sure how to integrate python or know what > servers will handle it ..... > Thanks > Vincent Davis > > > -- > http://mail.python.org/mailman/listinfo/python-list > > From terry.yinzhe at gmail.com Sat Feb 7 00:50:12 2009 From: terry.yinzhe at gmail.com (Terry) Date: Fri, 6 Feb 2009 21:50:12 -0800 (PST) Subject: Python3.0 has more duplication in source code than Python2.5 Message-ID: I used a CPD (copy/paste detector) in PMD to analyze the code duplication in Python source code. I found that Python3.0 contains more duplicated code than the previous versions. The CPD tool is far from perfect, but I still feel the analysis makes some sense. |Source Code | NLOC | Dup60 | Dup30 | Rate60 | Rate 30 | Python1.5(Core) 19418 1072 3023 6% 16% Python2.5(Core) 35797 1656 6441 5% 18% Python3.0(Core) 40737 3460 9076 8% 22% Apache(server) 18693 1114 2553 6% 14% NLOC: The net lines of code Dup60: Lines of code that has 60 continuous tokens duplicated to other code (counted twice or more) Dup30: 30 tokens duplicated Rate60: Dup60/NLOC Rate30: Dup30/NLOC We can see that the common duplicated rate is tended to be stable. But Python3.0 is slightly bigger than that. Consider the small increase in NLOC, the duplication rate of Python3.0 might be too big. Does that say something about the code quality of Python3.0? From tjreedy at udel.edu Sat Feb 7 02:31:20 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 07 Feb 2009 02:31:20 -0500 Subject: Lists implemented as integer-hashed Dictionaries? In-Reply-To: <775033410902061918l3a16c8fi82329b8f6f244daa@mail.gmail.com> References: <775033410902061918l3a16c8fi82329b8f6f244daa@mail.gmail.com> Message-ID: er wrote: > Somebody much more intelligent than I said today that someone told him > that Python lists are just dictionaries with lists hashed by integers. Abstractly, which is to say, behaviorally, a Python list is a sequence class as defined under Built-in Types in the Library manual. Dictionaries are a mapping class. The two categories have different methods. So at this level, the claim is nonsensical, wrong by definition. A list *must* have it n entries indexed from 0 to n-1 and dicts do not and could not enforce such an invariant. Concretely, an implementation could do as claimed under the covers, but CPython and I suspect all the other implementations actually use extensible arrays. People *do* use dicts for sparse arrays, but then they are *not* sequences. Good for you for asking here. Terry Jan Reedy From martin at v.loewis.de Sat Feb 7 02:36:36 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 07 Feb 2009 08:36:36 +0100 Subject: Python3.0 has more duplication in source code than Python2.5 In-Reply-To: References: Message-ID: <498D3A04.60503@v.loewis.de> > Does that say something about the code quality of Python3.0? Not necessarily. IIUC, copying a single file with 2000 lines completely could already account for that increase. It would be interesting to see what specific files have gained large numbers of additional files, compared to 2.5. Regards, Martin From tjreedy at udel.edu Sat Feb 7 02:37:19 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 07 Feb 2009 02:37:19 -0500 Subject: Is c.l.py becoming less friendly? In-Reply-To: <1233850000.12935.4.camel@localhost.localdomain> References: <1233850000.12935.4.camel@localhost.localdomain> Message-ID: Albert Hopkins wrote: > Probably that [c.l.]python is becoming more popular and, like most > things as they become popular, it loses its "purity"... much like the > Internet in the early 1990s. Several years ago when I proposed the addition of list.pop(), a couple of people accused me of trying to ruin Python (by spoiling its 'purity', I guess). There were some other unfriendly things said a few years later, by and to various people, in the discussion of integer division. So I think python-list has become more friendly since. Terry Jan Reedy From rNOSPAMon at flownet.com Sat Feb 7 03:06:08 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Sat, 07 Feb 2009 00:06:08 -0800 Subject: WebError documentation? References: Message-ID: In article , Chris Rebert wrote: > On Thu, Feb 5, 2009 at 12:52 PM, Ron Garret wrote: > > Is there any? Where is it? Extensive Googling has proven fruitless. > > It's not a standard Python exception. A third-party library you're > using must be raising it. Check the exception traceback. I see I did not make myself clear. I meant the Python software package called "weberror", not a generic web error. http://pypi.python.org/pypi/WebError rg From jstroud at mbi.ucla.edu Sat Feb 7 04:04:47 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Sat, 07 Feb 2009 01:04:47 -0800 Subject: Is c.l.py becoming less friendly? In-Reply-To: References: Message-ID: Tim Chase wrote: > Is this where we tell you to shut up? ;-) Don't you mean STFU? -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com From rhamph at gmail.com Sat Feb 7 04:06:06 2009 From: rhamph at gmail.com (Rhamphoryncus) Date: Sat, 7 Feb 2009 01:06:06 -0800 (PST) Subject: Flattening lists References: <9a8af8a3-27fb-4f5b-90ea-ee0276c7e5e3@r15g2000prd.googlegroups.com> <9c2ed038-7a9b-4a35-adae-8b0df890040e@k36g2000pri.googlegroups.com> Message-ID: <76695d3b-bc74-4b72-b0ee-0c646d228b6f@t13g2000yqc.googlegroups.com> On Feb 6, 10:21?pm, rdmur... at bitdance.com wrote: > Quoth Mensanator : > > def flatten(listOfLists): > > ? ? return list(chain.from_iterable(listOfLists)) > > ? ? Python 2.6.1 (r261:67515, Jan ?7 2009, 17:09:13) > ? ? [GCC 4.3.2] on linux2 > ? ? Type "help", "copyright", "credits" or "license" for more information. > ? ? >>> from itertools import chain > ? ? >>> list(chain.from_iterable([1, 2, [3, 4]])) > ? ? Traceback (most recent call last): > ? ? ? File "", line 1, in > ? ? TypeError: 'int' object is not iterable > ? ? >>> list(chain(*[1, 2, [3, 4]])) > ? ? Traceback (most recent call last): > ? ? ? File "", line 1, in > ? ? TypeError: 'int' object is not iterable > ? ? >>> list(chain.from_iterable(['abcd', 'efg', [3, 4]])) > ? ? ['a', 'b', 'c', 'd', 'e', 'f', 'g', 3, 4] What usecase do you have for such inconsistently structured data? If I'm building a tree I use my own type for the nodes, keeping them purely internal, so I can always use isinstance without worrying about getting something inconvenient passed in. From dq at gmail.com Sat Feb 7 04:36:14 2009 From: dq at gmail.com (dq) Date: Sat, 07 Feb 2009 10:36:14 +0100 Subject: urllib2 performance on windows, usb connection In-Reply-To: References: <498beb5a$0$3305$9b622d9e@news.freenet.de> Message-ID: MRAB wrote: > dq wrote: >> MRAB wrote: >>> dq wrote: >>>> dq wrote: >>>>> MRAB wrote: >>>>>> dq wrote: >>>>>>> Martin v. L?wis wrote: >>>>>>>>> So does anyone know what the deal is with this? Why is the >>>>>>>>> same code so much slower on Windows? Hope someone can tell me >>>>>>>>> before a holy war erupts :-) >>>>>>>> >>>>>>>> Only the holy war can give an answer here. It certainly has >>>>>>>> *nothing* to do with Python; Python calls the operating system >>>>>>>> functions to read from the network and write to the disk almost >>>>>>>> directly. So it must be the operating system itself that slows >>>>>>>> it down. >>>>>>>> >>>>>>>> To investigate further, you might drop the write operating, >>>>>>>> and measure only source.read(). If that is slower, then, for >>>>>>>> some reason, the network speed is bad on Windows. Maybe >>>>>>>> you have the network interfaces misconfigured? Maybe you are >>>>>>>> using wireless on Windows, but cable on Linux? Maybe you have >>>>>>>> some network filtering software running on Windows? Maybe it's >>>>>>>> just that Windows sucks?-) >>>>>>>> >>>>>>>> If the network read speed is fine, but writing slows down, >>>>>>>> I ask the same questions. Perhaps you have some virus scanner >>>>>>>> installed that filters all write operations? Maybe >>>>>>>> Windows sucks? >>>>>>>> >>>>>>>> Regards, Martin >>>>>>>> >>>>>>> >>>>>>> Thanks for the ideas, Martin. I ran a couple of experiments >>>>>>> to find the culprit, by downloading the same 20 MB file from >>>>>>> the same fast server. I compared: >>>>>>> >>>>>>> 1. DL to HD vs USB iPod. 2. AV on-access protection on vs. >>>>>>> off 3. "source. read()" only vs. "file.write( >>>>>>> source.read() )" >>>>>>> >>>>>>> The culprit is definitely the write speed on the iPod. That is, >>>>>>> everything runs plenty fast (~1 MB/s down) as long as I'm >>>>>>> not writing directly to the iPod. This is kind of odd, because >>>>>>> if I copy the file over from the HD to the iPod using >>>>>>> windows (drag-n-drop), it takes about a second or two, so about >>>>>>> 10 MB/s. >>>>>>> >>>>>>> So the problem is definitely partially Windows, but it also seems >>>>>>> that Python's file.write() function is not without blame. It's >>>>>>> the combination of Windows, iPod and Python's data stream that is >>>>>>> slowing me down. >>>>>>> >>>>>>> I'm not really sure what I can do about this. I'll experiment a >>>>>>> little more and see if there's any way around this bottleneck. >>>>>>> If anyone has run into a problem like this, >>>>>>> I'd love to hear about it... >>>>>>> >>>>>> You could try copying the file to the iPod using the command line, >>>>>> or copying data from disk to iPod in, say, C, anything but Python. >>>>>> This would allow you to identify whether Python itself has >>>>>> anything to do with it. >>>>> >>>>> Well, I think I've partially identified the problem. target.write( >>>>> source.read() ) runs perfectly fast, copies 20 megs >>>>> in about a second, from HD to iPod. However, if I run the same >>>>> code in a while loop, using a certain block size, say >>>>> target.write( source.read(4096) ), it takes forever (or at least >>>>> I'm still timing it while I write this post). >>>>> >>>>> The mismatch seems to be between urllib2's block size and the write >>>>> speed of the iPod, I might try to tweak this a little in the code >>>>> and see if it has any effect. >>>>> >>>>> Oh, there we go: 20 megs in 135.8 seconds. Yeah... I might want >>>>> to try to improve that... >>>> >>>> After some tweaking of the block size, I managed to get the DL speed >>>> up to about 900 Mb/s. It's still not quite Ubuntu, but it's >>>> a good order of magnitude better. The new DL code is pretty much >>>> this: >>>> >>>> """ blocksize = 2 ** 16 # plus or minus a power of 2 source = >>>> urllib2.urlopen( 'url://string' ) target = open( pathname, 'wb') >>>> fullsize = float( source.info()['Content-Length'] ) DLd = 0 while >>>> DLd < fullsize: DLd = DLd + blocksize # optional: write some DL >>>> progress info # somewhere, e.g. stdout target.close() source.close() >>>> """ >>>> >>> I'd like to suggest that the block size you add to 'DLd' be the >>> actual size of the returned block, just in case the read() doesn't >>> return all you asked for (it might not be guaranteed, and the chances >>> are that the final block will be shorter, unless 'fullsize' happens >>> to be a multiple of 'blocksize'). >>> >>> If less is returned by read() then the while-loop might finish before >>> all the data has been downloaded, and if you just add 'blocksize' >>> each time it might end up > 'fullsize', ie apparently >100% downloaded! >> >> Interesting. I'll if to see if any of the downloaded files end >> prematurely :) >> >> btw, I forgot the most important line of the code! >> >> """ >> blocksize = 2 ** 16 # plus or minus a power of 2 >> source = urllib2.urlopen( 'url://string' ) >> target = open( pathname, 'wb') >> fullsize = float( source.info()['Content-Length'] ) >> DLd = 0 >> while DLd < fullsize: >> # +++ >> target.write( source.read( blocksize ) ) # +++ >> # +++ >> DLd = DLd + blocksize >> # optional: write some DL progress info >> # somewhere, e.g. stdout >> target.close() >> source.close() >> """ >> >> Using that, I'm not quite sure where I can grab onto the value of how >> much was actually read from the block. I suppose I could use an >> intermediate variable, read the data into it, measure the size, and >> then write it to the file stream, but I'm not sure it would be worth >> the overhead. Or is there some other magic I should know about? >> >> If I start to get that problem, at least I'll know where to look... >> > It's just: > > data = source.read(blocksize) > target.write(data) > DLd = DLd + len(data) > > The overhead is tiny because you're not copying the data. > > If 'x' refers to a 1MB bytestring and you do "y = x" or "foo(x)", you're > not actually copying that bytestring; you're just making 'y' also refer > to it or passing the reference to it into 'foo'. It's a bit passing > pointers around, but without the nasty bits! :-) Yeah, that's about what I was thinking, although not quite as succintly. Thanks for the help! From duncan.booth at invalid.invalid Sat Feb 7 05:01:28 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 7 Feb 2009 10:01:28 GMT Subject: subprocess returncode windows References: <18348eae-5af1-47e9-a198-b95d4fcb6eac@a12g2000pro.googlegroups.com> <851774bd-5019-4347-8815-36782dcec4b6@p2g2000prf.googlegroups.com> <8ac1c027-3bd4-43ae-99a9-012462cb06d7@r37g2000prr.googlegroups.com> Message-ID: Andrew wrote: > As well as not using that and removing "endlocal" which > I admit I have no clue what that does. Python isn't the only system in the world to include a help command. C:\>help endlocal Ends localization of environment changes in a batch file. Environment changes made after ENDLOCAL has been issued are not local to the batch file; the previous settings are not restored on termination of the batch file. ENDLOCAL If Command Extensions are enabled ENDLOCAL changes as follows: If the corresponding SETLOCAL enable or disabled command extensions using the new ENABLEEXTENSIONS or DISABLEEXTENSIONS options, then after the ENDLOCAL, the enabled/disabled state of command extensions will be restored to what it was prior to the matching SETLOCAL command execution. From terry.yinzhe at gmail.com Sat Feb 7 05:51:07 2009 From: terry.yinzhe at gmail.com (Terry) Date: Sat, 7 Feb 2009 02:51:07 -0800 (PST) Subject: Python3.0 has more duplication in source code than Python2.5 References: <498D3A04.60503@v.loewis.de> Message-ID: On 2?7?, ??3?36?, "Martin v. L?wis" wrote: > > Does that say something about the code quality of Python3.0? > > Not necessarily. IIUC, copying a single file with 2000 lines > completely could already account for that increase. > > It would be interesting to see what specific files have gained > large numbers of additional files, compared to 2.5. > > Regards, > Martin But the duplication are always not very big, from about 100 lines (rare) to less the 5 lines. As you can see the Rate30 is much bigger than Rate60, that means there are a lot of small duplications. From deets at nospam.web.de Sat Feb 7 06:10:17 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 07 Feb 2009 12:10:17 +0100 Subject: Python3.0 has more duplication in source code than Python2.5 In-Reply-To: References: <498D3A04.60503@v.loewis.de> Message-ID: <6v58gpFi7nnvU1@mid.uni-berlin.de> Terry schrieb: > On 2?7?, ??3?36?, "Martin v. L?wis" wrote: >>> Does that say something about the code quality of Python3.0? >> Not necessarily. IIUC, copying a single file with 2000 lines >> completely could already account for that increase. >> >> It would be interesting to see what specific files have gained >> large numbers of additional files, compared to 2.5. >> >> Regards, >> Martin > > But the duplication are always not very big, from about 100 lines > (rare) to less the 5 lines. As you can see the Rate30 is much bigger > than Rate60, that means there are a lot of small duplications. Do you by any chance have a few examples of these? There is a lot of idiomatic code in python to e.g. acquire and release the GIL or doing refcount-stuff. If that happens to be done with rather generic names as arguments, I can well imagine that as being the cause. Diez From Laundro at gmail.com Sat Feb 7 07:18:45 2009 From: Laundro at gmail.com (LaundroMat) Date: Sat, 7 Feb 2009 04:18:45 -0800 (PST) Subject: Trouble with regular expressions Message-ID: Hi, I'm quite new to regular expressions, and I wonder if anyone here could help me out. I'm looking to split strings that ideally look like this: "Update: New item (Household)" into a group. This expression works ok: '^(Update:)?(.*)(\(.*\))$' - it returns ("Update", "New item", "(Household)") Some strings will look like this however: "Update: New item (item) (Household)". The expression above still does its job, as it returns ("Update", "New item (item)", "(Household)"). It does not work however when there is no text in parentheses (eg "Update: new item"). How can I get the expression to return a tuple such as ("Update:", "new item", None)? Thanks in advance, Mathieu From jason at jvoegele.com Sat Feb 7 07:54:23 2009 From: jason at jvoegele.com (Jason Voegele) Date: Sat, 07 Feb 2009 07:54:23 -0500 Subject: Running all unit tests References: <877i42x6ud.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > Jason Voegele writes: > >> What's the recommended approach for Python programs? I'm sure I >> could write a shell script (or a Python script even) that scans my >> "test" directory for test cases and runs them, but I'm wondering if >> there's something already built in that could do this for me. > > The lack of a built-in ???collect and run all the tests in this working > tree??? in the Python unit test system is a known problem; discussions > are ongoing what to do about it. > > Meanwhile, the third-party ???nose??? system > provides this > and much more, while remaining compatible with both testing systems in > the standard library. > > I generally set up a ???test??? target in my Makefile, such that it will > use ???nosetests??? to collect and run all the tests; then I just run > ???make test??? in a loop that is triggered by any filesystem change in my > project working tree. Thanks to all for the helpful responses. It's good to know I'm not the only one that has thought of this as a shortcoming. -- Jason Voegele Different all twisty a of in maze are you, passages little. From gslindstrom at gmail.com Sat Feb 7 07:56:22 2009 From: gslindstrom at gmail.com (gslindstrom) Date: Sat, 7 Feb 2009 06:56:22 -0600 Subject: PyCon 2009 Tutorial Days Message-ID: Registration for PyCon 2009 (US) is open. Because of the popularity of the tutorials in years past, this year features 2 days of tutorials (32 total class on Wednesday, March 25 and Thursday, March 26) including: - 2 tracks on Introduciton to Python - Working with Excel spreadsheets - GIS with Python - Django - Concurrency and Kamaelia - Testing - SQLAlchemy - Advanced topics - much, much more These classes are being presented by some of the smartest cookies in the Python community and are 3-hours each (with break). You get to rub shoulders with other Python programmers who share your interests and all sessions have time for you to ask questions. There is a (modest) cost to attend, but you will get great training as well as class notes. We even feed you lunch and provide snacks during the breaks. Click http://us.pycon.org/2009/about/ for more information. Questions? Email us at pycon-tutorials at python.org. Greg Lindstrom Tutorial Coordinator -------------- next part -------------- An HTML attachment was scrubbed... URL: From terry.yinzhe at gmail.com Sat Feb 7 08:36:07 2009 From: terry.yinzhe at gmail.com (Terry) Date: Sat, 7 Feb 2009 05:36:07 -0800 (PST) Subject: Python3.0 has more duplication in source code than Python2.5 References: <498D3A04.60503@v.loewis.de> <6v58gpFi7nnvU1@mid.uni-berlin.de> Message-ID: <5ae6f965-f983-47da-a9e7-ed47397f1317@i18g2000prf.googlegroups.com> On 2?7?, ??7?10?, "Diez B. Roggisch" wrote: > Terry schrieb: > > > On 2?7?, ??3?36?, "Martin v. L?wis" wrote: > >>> Does that say something about the code quality of Python3.0? > >> Not necessarily. IIUC, copying a single file with 2000 lines > >> completely could already account for that increase. > > >> It would be interesting to see what specific files have gained > >> large numbers of additional files, compared to 2.5. > > >> Regards, > >> Martin > > > But the duplication are always not very big, from about 100 lines > > (rare) to less the 5 lines. As you can see the Rate30 is much bigger > > than Rate60, that means there are a lot of small duplications. > > Do you by any chance have a few examples of these? There is a lot of > idiomatic code in python to e.g. acquire and release the GIL or doing > refcount-stuff. If that happens to be done with rather generic names as > arguments, I can well imagine that as being the cause. > > Diez Example 1: Found a 64 line (153 tokens) duplication in the following files: Starting at line 73 of D:\DOWNLOADS\Python-3.0\Python\thread_pth.h Starting at line 222 of D:\DOWNLOADS\Python-3.0\Python \thread_pthread.h return (long) threadid; #else return (long) *(long *) &threadid; #endif } static void do_PyThread_exit_thread(int no_cleanup) { dprintf(("PyThread_exit_thread called\n")); if (!initialized) { if (no_cleanup) _exit(0); else exit(0); } } void PyThread_exit_thread(void) { do_PyThread_exit_thread(0); } void PyThread__exit_thread(void) { do_PyThread_exit_thread(1); } #ifndef NO_EXIT_PROG static void do_PyThread_exit_prog(int status, int no_cleanup) { dprintf(("PyThread_exit_prog(%d) called\n", status)); if (!initialized) if (no_cleanup) _exit(status); else exit(status); } void PyThread_exit_prog(int status) { do_PyThread_exit_prog(status, 0); } void PyThread__exit_prog(int status) { do_PyThread_exit_prog(status, 1); } #endif /* NO_EXIT_PROG */ #ifdef USE_SEMAPHORES /* * Lock support. */ PyThread_type_lock PyThread_allocate_lock(void) { From terry.yinzhe at gmail.com Sat Feb 7 08:36:36 2009 From: terry.yinzhe at gmail.com (Terry) Date: Sat, 7 Feb 2009 05:36:36 -0800 (PST) Subject: Python3.0 has more duplication in source code than Python2.5 References: <498D3A04.60503@v.loewis.de> <6v58gpFi7nnvU1@mid.uni-berlin.de> Message-ID: On 2?7?, ??7?10?, "Diez B. Roggisch" wrote: > Terry schrieb: > > > On 2?7?, ??3?36?, "Martin v. L?wis" wrote: > >>> Does that say something about the code quality of Python3.0? > >> Not necessarily. IIUC, copying a single file with 2000 lines > >> completely could already account for that increase. > > >> It would be interesting to see what specific files have gained > >> large numbers of additional files, compared to 2.5. > > >> Regards, > >> Martin > > > But the duplication are always not very big, from about 100 lines > > (rare) to less the 5 lines. As you can see the Rate30 is much bigger > > than Rate60, that means there are a lot of small duplications. > > Do you by any chance have a few examples of these? There is a lot of > idiomatic code in python to e.g. acquire and release the GIL or doing > refcount-stuff. If that happens to be done with rather generic names as > arguments, I can well imagine that as being the cause. > > Diez Example 2: Found a 16 line (106 tokens) duplication in the following files: Starting at line 4970 of D:\DOWNLOADS\Python-3.0\Python\Python-ast.c Starting at line 5015 of D:\DOWNLOADS\Python-3.0\Python\Python-ast.c Starting at line 5073 of D:\DOWNLOADS\Python-3.0\Python\Python-ast.c Starting at line 5119 of D:\DOWNLOADS\Python-3.0\Python\Python-ast.c PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp- >ob_type->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); generators = asdl_seq_new(len, arena); if (generators == NULL) goto failed; for (i = 0; i < len; i++) { comprehension_ty value; res = obj2ast_comprehension (PyList_GET_ITEM(tmp, i), &value, arena); if (res != 0) goto failed; asdl_seq_SET(generators, i, value); } Py_XDECREF(tmp); tmp = NULL; } else { PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp"); From terry.yinzhe at gmail.com Sat Feb 7 08:38:02 2009 From: terry.yinzhe at gmail.com (Terry) Date: Sat, 7 Feb 2009 05:38:02 -0800 (PST) Subject: Python3.0 has more duplication in source code than Python2.5 References: <498D3A04.60503@v.loewis.de> <6v58gpFi7nnvU1@mid.uni-berlin.de> Message-ID: <3ff230fd-65fc-4e6a-b943-d290a021b8f2@w24g2000prd.googlegroups.com> On 2?7?, ??7?10?, "Diez B. Roggisch" wrote: > Terry schrieb: > > > On 2?7?, ??3?36?, "Martin v. L?wis" wrote: > >>> Does that say something about the code quality of Python3.0? > >> Not necessarily. IIUC, copying a single file with 2000 lines > >> completely could already account for that increase. > > >> It would be interesting to see what specific files have gained > >> large numbers of additional files, compared to 2.5. > > >> Regards, > >> Martin > > > But the duplication are always not very big, from about 100 lines > > (rare) to less the 5 lines. As you can see the Rate30 is much bigger > > than Rate60, that means there are a lot of small duplications. > > Do you by any chance have a few examples of these? There is a lot of > idiomatic code in python to e.g. acquire and release the GIL or doing > refcount-stuff. If that happens to be done with rather generic names as > arguments, I can well imagine that as being the cause. > > Diez Example of a small one (61 token duplicated): Found a 19 line (61 tokens) duplication in the following files: Starting at line 132 of D:\DOWNLOADS\Python-3.0\Python\modsupport.c Starting at line 179 of D:\DOWNLOADS\Python-3.0\Python\modsupport.c PyTuple_SET_ITEM(v, i, w); } if (itemfailed) { /* do_mkvalue() should have already set an error */ Py_DECREF(v); return NULL; } if (**p_format != endchar) { Py_DECREF(v); PyErr_SetString(PyExc_SystemError, "Unmatched paren in format"); return NULL; } if (endchar) ++*p_format; return v; } static PyObject * From terry.yinzhe at gmail.com Sat Feb 7 08:39:42 2009 From: terry.yinzhe at gmail.com (Terry) Date: Sat, 7 Feb 2009 05:39:42 -0800 (PST) Subject: Python3.0 has more duplication in source code than Python2.5 References: <498D3A04.60503@v.loewis.de> <6v58gpFi7nnvU1@mid.uni-berlin.de> Message-ID: <65261947-714a-46d6-8769-2a32bf56caa1@p23g2000prp.googlegroups.com> On 2?7?, ??7?10?, "Diez B. Roggisch" wrote: > Terry schrieb: > > > On 2?7?, ??3?36?, "Martin v. L?wis" wrote: > >>> Does that say something about the code quality of Python3.0? > >> Not necessarily. IIUC, copying a single file with 2000 lines > >> completely could already account for that increase. > > >> It would be interesting to see what specific files have gained > >> large numbers of additional files, compared to 2.5. > > >> Regards, > >> Martin > > > But the duplication are always not very big, from about 100 lines > > (rare) to less the 5 lines. As you can see the Rate30 is much bigger > > than Rate60, that means there are a lot of small duplications. > > Do you by any chance have a few examples of these? There is a lot of > idiomatic code in python to e.g. acquire and release the GIL or doing > refcount-stuff. If that happens to be done with rather generic names as > arguments, I can well imagine that as being the cause. > > Diez Example of a even small one (30 token duplicated): Found a 11 line (30 tokens) duplication in the following files: Starting at line 2551 of D:\DOWNLOADS\Python-3.0\Python\Python-ast.c Starting at line 3173 of D:\DOWNLOADS\Python-3.0\Python\Python-ast.c if (PyObject_SetAttrString(result, "ifs", value) == -1) goto failed; Py_DECREF(value); return result; failed: Py_XDECREF(value); Py_XDECREF(result); return NULL; } PyObject* From terry.yinzhe at gmail.com Sat Feb 7 08:42:00 2009 From: terry.yinzhe at gmail.com (Terry) Date: Sat, 7 Feb 2009 05:42:00 -0800 (PST) Subject: Python3.0 has more duplication in source code than Python2.5 References: <498D3A04.60503@v.loewis.de> <6v58gpFi7nnvU1@mid.uni-berlin.de> Message-ID: <218c44da-6086-4f02-843a-5d63520348b3@f40g2000pri.googlegroups.com> On 2?7?, ??7?10?, "Diez B. Roggisch" wrote: > Terry schrieb: > > > On 2?7?, ??3?36?, "Martin v. L?wis" wrote: > >>> Does that say something about the code quality of Python3.0? > >> Not necessarily. IIUC, copying a single file with 2000 lines > >> completely could already account for that increase. > > >> It would be interesting to see what specific files have gained > >> large numbers of additional files, compared to 2.5. > > >> Regards, > >> Martin > > > But the duplication are always not very big, from about 100 lines > > (rare) to less the 5 lines. As you can see the Rate30 is much bigger > > than Rate60, that means there are a lot of small duplications. > > Do you by any chance have a few examples of these? There is a lot of > idiomatic code in python to e.g. acquire and release the GIL or doing > refcount-stuff. If that happens to be done with rather generic names as > arguments, I can well imagine that as being the cause. > > Diez And I'm not saying that you can not have duplication in code. But it seems that the stable & successful software releases tend to have relatively stable duplication rate. From cosmo_general at yahoo.com Sat Feb 7 08:47:27 2009 From: cosmo_general at yahoo.com (Muddy Coder) Date: Sat, 7 Feb 2009 05:47:27 -0800 (PST) Subject: urllib2: problem of handling space in parameter Message-ID: <3afe6c35-7610-47ea-8165-115e41a11763@13g2000yql.googlegroups.com> Hi Folks, I encrountered a problem of using urllib2: the space handling. Look at the code below: import urllib2 url = r'http://somedomain.com/a.cgi?name=muddy coder&password=foobar cgi_back = urllib2.urlopen(url).read() In this cgi_back, I saw field password worked fine, but field name not, only muddy was picked up by CGI. So, I had to cover the space, by using syntax name=muddy-coder, it went through. So, I presume urllib2 may have an approach of handling white space in this regard. Can anybody help? Thanks! Muddy Coder From aquagnu at gmail.com Sat Feb 7 08:50:18 2009 From: aquagnu at gmail.com (Yosifov Pavel) Date: Sat, 7 Feb 2009 05:50:18 -0800 (PST) Subject: typedef (type alias) and ctypes Message-ID: <99a964c1-85a0-4139-93a3-e8bce614cccb@o11g2000yql.googlegroups.com> I try to create type aliases, like typedef in C (a specially aliases to ctypes objects). This case: >>> some_type = c_ulong >>> oth_type = c_ulong works in all cases but not with type qualification: >>> t1 = c_ulong # reference to c_ulong, nothing else :( >>> t2 = c_ulong >>> x = t1() >>> y = t2() >>> type(x)==type(y) True This trivial way for typedef doesn't allow to determine real type and it's absolutely right :) >>> t1 = type('t1',(c_ulong,),{}) >>> t2 = type('t2',(c_ulong,),{}) >>> x = t1() >>> y = t2() >>> type(x)==type(y) False The problem: 1st way work in complex using of ctypes (interfacing with some DLLs), but doesn't allow to determine real type! 2st way allows to determine real type, but "access violation reading 0x0000000C'" occurs in some DLL calls! Question: what "warts", errors are in 2nd way (may be reason of access violation)? -- Pavel From rdmurray at bitdance.com Sat Feb 7 09:16:42 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Sat, 7 Feb 2009 14:16:42 +0000 (UTC) Subject: urllib2: problem of handling space in parameter References: <3afe6c35-7610-47ea-8165-115e41a11763@13g2000yql.googlegroups.com> Message-ID: Quoth Muddy Coder : > Hi Folks, > > I encrountered a problem of using urllib2: the space handling. Look at > the code below: > > import urllib2 > url = r'http://somedomain.com/a.cgi?name=muddy coder&password=foobar > cgi_back = urllib2.urlopen(url).read() > > In this cgi_back, I saw field password worked fine, but field name > not, only muddy was picked up by CGI. So, I had to cover the space, by > using syntax name=muddy-coder, it went through. So, I presume urllib2 > may have an approach of handling white space in this regard. Can > anybody help? Thanks! urllib.urlencode. Unecoded spaces aren't actually valid in a URL. --David From sjmachin at lexicon.net Sat Feb 7 09:18:07 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 7 Feb 2009 06:18:07 -0800 (PST) Subject: Trouble with regular expressions References: Message-ID: <65540e37-69a0-4664-a258-a5b0543c0ecd@s9g2000prg.googlegroups.com> On Feb 7, 11:18?pm, LaundroMat wrote: > Hi, > > I'm quite new to regular expressions, and I wonder if anyone here > could help me out. > > I'm looking to split strings that ideally look like this: "Update: New > item (Household)" into a group. > This expression works ok: '^(Update:)?(.*)(\(.*\))$' - it returns > ("Update", "New item", "(Household)") > > Some strings will look like this however: "Update: New item (item) > (Household)". The expression above still does its job, as it returns > ("Update", "New item (item)", "(Household)"). > > It does not work however when there is no text in parentheses (eg > "Update: new item"). How can I get the expression to return a tuple > such as ("Update:", "new item", None)? I don't see how it can be done without some post-matching adjustment. Try this: C:\junk>type mathieu.py import re tests = [ "Update: New item (Household)", "Update: New item (item) (Household)", "Update: new item", "minimal", "parenthesis (plague) (has) (struck)", ] regex = re.compile(""" (Update:)? # optional prefix \s* # ignore whitespace ([^()]*) # any non-parentheses stuff (\([^()]*\))? # optional (blahblah) \s* # ignore whitespace (\([^()]*\))? # another optional (blahblah) $ """, re.VERBOSE) for i, test in enumerate(tests): print "Test #%d: %r" % (i, test) m = regex.match(test) if not m: print "No match" else: g = m.groups() print g if g[3] is not None: x = (g[0], g[1] + g[2], g[3]) else: x = g[:3] print x print C:\junk>mathieu.py Test #0: 'Update: New item (Household)' ('Update:', 'New item ', '(Household)', None) ('Update:', 'New item ', '(Household)') Test #1: 'Update: New item (item) (Household)' ('Update:', 'New item ', '(item)', '(Household)') ('Update:', 'New item (item)', '(Household)') Test #2: 'Update: new item' ('Update:', 'new item', None, None) ('Update:', 'new item', None) Test #3: 'minimal' (None, 'minimal', None, None) (None, 'minimal', None) Test #4: 'parenthesis (plague) (has) (struck)' No match HTH, John From geekmail at usenot.de Sat Feb 7 09:21:22 2009 From: geekmail at usenot.de (Andreas Waldenburger) Date: Sat, 7 Feb 2009 15:21:22 +0100 Subject: "Weird" Indentation? (Or: is there a for...else construct?) Message-ID: <20090207152122.683de28e@usenot.de> I've found something in the spirit of the following (in the epydoc sources, if you care): if True: print "outer if" for t in range(2): if True: print "for if" else: print "phantom else" For the life of me I can't place the "else". Which if clause does it belong to? None, it would seem from running the above snippet: outer if For if For if Phantom else It seems that there is a for...else construct. Replacing the inner if with pass seems to confirm this. The else clause is still executed. What's broken here: Python or my brain? /W -- My real email address is constructed by swapping the domain with the recipient (local part). From rdmurray at bitdance.com Sat Feb 7 09:25:02 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Sat, 7 Feb 2009 14:25:02 +0000 (UTC) Subject: Flattening lists References: <9a8af8a3-27fb-4f5b-90ea-ee0276c7e5e3@r15g2000prd.googlegroups.com> <9c2ed038-7a9b-4a35-adae-8b0df890040e@k36g2000pri.googlegroups.com> <76695d3b-bc74-4b72-b0ee-0c646d228b6f@t13g2000yqc.googlegroups.com> Message-ID: Rhamphoryncus wrote: > On Feb 6, 10:21=A0pm, rdmur... at bitdance.com wrote: > > Quoth Mensanator : > > > def flatten(listOfLists): > > > =A0 =A0 return list(chain.from_iterable(listOfLists)) > > > > =A0 =A0 Python 2.6.1 (r261:67515, Jan =A07 2009, 17:09:13) > > =A0 =A0 [GCC 4.3.2] on linux2 > > =A0 =A0 Type "help", "copyright", "credits" or "license" for more informa= > tion. > > =A0 =A0 >>> from itertools import chain > > =A0 =A0 >>> list(chain.from_iterable([1, 2, [3, 4]])) > > =A0 =A0 Traceback (most recent call last): > > =A0 =A0 =A0 File "", line 1, in > > =A0 =A0 TypeError: 'int' object is not iterable > > =A0 =A0 >>> list(chain(*[1, 2, [3, 4]])) > > =A0 =A0 Traceback (most recent call last): > > =A0 =A0 =A0 File "", line 1, in > > =A0 =A0 TypeError: 'int' object is not iterable > > =A0 =A0 >>> list(chain.from_iterable(['abcd', 'efg', [3, 4]])) > > =A0 =A0 ['a', 'b', 'c', 'd', 'e', 'f', 'g', 3, 4] > > What usecase do you have for such inconsistently structured data? > > If I'm building a tree I use my own type for the nodes, keeping them > purely internal, so I can always use isinstance without worrying about > getting something inconvenient passed in. I don't have any use cases myself, I'm just pointing out that this doesn't answer the concerns of the OP, who presumably does. --RDM From mdemenko at gmail.com Sat Feb 7 09:27:24 2009 From: mdemenko at gmail.com (Maxim Demenko) Date: Sat, 07 Feb 2009 15:27:24 +0100 Subject: py2exe and distutils Message-ID: Hi, i have installed Python 2.5.4 on WinXP, setuptools-0.6c9 and py2exe 0.6.9 Now i can't list installed modules, here is the stacktrace: help> modules Please wait a moment while I gather a list of all available modules... Traceback (most recent call last): File "", line 1, in File "C:\Programme\Python25\lib\site.py", line 346, in __call__ return pydoc.help(*args, **kwds) File "C:\Programme\Python25\lib\pydoc.py", line 1649, in __call__ self.interact() File "C:\Programme\Python25\lib\pydoc.py", line 1667, in interact self.help(request) File "C:\Programme\Python25\lib\pydoc.py", line 1683, in help elif request == 'modules': self.listmodules() File "C:\Programme\Python25\lib\pydoc.py", line 1804, in listmodules ModuleScanner().run(callback) File "C:\Programme\Python25\lib\pydoc.py", line 1855, in run for importer, modname, ispkg in pkgutil.walk_packages(): File "C:\Programme\Python25\lib\pkgutil.py", line 110, in walk_packages __import__(name) File "C:\Programme\Python25\Lib\site-packages\setuptools\__init__.py", line 2, in from setuptools.extension import Extension, Library File "C:\Programme\Python25\Lib\site-packages\setuptools\extension.py", line 2, in from dist import _get_unpatched File "C:\Programme\Python25\Lib\site-packages\setuptools\dist.py", line 27, in _Distribution = _get_unpatched(_Distribution) File "C:\Programme\Python25\Lib\site-packages\setuptools\dist.py", line 23, in _get_unpatched "distutils has already been patched by %r" % cls AssertionError: distutils has already been patched by Any suggestion, how to fix this issue? Best regards Maxim From geekmail at usenot.de Sat Feb 7 09:27:53 2009 From: geekmail at usenot.de (Andreas Waldenburger) Date: Sat, 7 Feb 2009 15:27:53 +0100 Subject: "Weird" Indentation? (Or: is there a for...else construct?) References: <20090207152122.683de28e@usenot.de> Message-ID: <20090207152753.6526a574@usenot.de> On Sat, 7 Feb 2009 15:21:22 +0100 Andreas Waldenburger wrote: > outer if > For if > For if > Phantom else > Geez, I'm a moron. This is obviously not the output from the snippet. But if you fix the capitalization, it is. Sorry for that. /W -- My real email address is constructed by swapping the domain with the recipient (local part). From steve at pearwood.info Sat Feb 7 09:28:00 2009 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 08 Feb 2009 01:28:00 +1100 Subject: "Weird" Indentation? (Or: is there a for...else construct?) References: <20090207152122.683de28e@usenot.de> Message-ID: <019d9052$0$20640$c3e8da3@news.astraweb.com> Andreas Waldenburger wrote: > It seems that there is a for...else construct. Replacing the inner if > with pass seems to confirm this. The else clause is still executed. Yes, there is a for...else construct. The else block runs if the for loop exits *without* a break. for i in range(20): if i == 10: break else: print "no break here" for i in range(20): if i == 100: break else: print "no break here" > What's broken here: Python or my brain? Perhaps we should not answer that question. -- Steven From __peter__ at web.de Sat Feb 7 09:32:54 2009 From: __peter__ at web.de (Peter Otten) Date: Sat, 07 Feb 2009 15:32:54 +0100 Subject: "Weird" Indentation? (Or: is there a for...else construct?) References: <20090207152122.683de28e@usenot.de> Message-ID: Andreas Waldenburger wrote: > I've found something in the spirit of the following (in the epydoc > sources, if you care): > > if True: > print "outer if" > for t in range(2): > if True: > print "for if" > else: > print "phantom else" > > For the life of me I can't place the "else". Which if clause does it > belong to? None, it would seem from running the above snippet: > > outer if > For if > For if > Phantom else > > It seems that there is a for...else construct. Replacing the inner if > with pass seems to confirm this. The else clause is still executed. > > What's broken here: Python or my brain? Your rtfm sensor? http://docs.python.org/reference/compound_stmts.html#the-for-statement In short, the else suite is executed unless the for-loop is left via 'break': >>> for i in [1]: ... break ... else: ... print "else" ... >>> for i in [1]: ... pass ... else: ... print "else" ... else >>> Peter From geekmail at usenot.de Sat Feb 7 09:34:59 2009 From: geekmail at usenot.de (Andreas Waldenburger) Date: Sat, 7 Feb 2009 15:34:59 +0100 Subject: "Weird" Indentation? (Or: is there a for...else construct?) References: <20090207152122.683de28e@usenot.de> <019d9052$0$20640$c3e8da3@news.astraweb.com> Message-ID: <20090207153459.123c5706@usenot.de> On Sun, 08 Feb 2009 01:28:00 +1100 Steven D'Aprano wrote: > Andreas Waldenburger wrote: > > > It seems that there is a for...else construct. Replacing the inner > > if with pass seems to confirm this. The else clause is still > > executed. > > Yes, there is a for...else construct. > That's something. In 6+ years of Python programming I've never seen or heard of this thing. This might be useful, apparently. > [snip] > > > What's broken here: Python or my brain? > > Perhaps we should not answer that question. > I did phrase that rather provocatively, didn't I? Well thanks. I'll try to learn less noisily in the future. :) /W -- My real email address is constructed by swapping the domain with the recipient (local part). From google at mrabarnett.plus.com Sat Feb 7 09:37:31 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 07 Feb 2009 14:37:31 +0000 Subject: Trouble with regular expressions In-Reply-To: References: Message-ID: <498D9CAB.9090900@mrabarnett.plus.com> LaundroMat wrote: > Hi, > > I'm quite new to regular expressions, and I wonder if anyone here > could help me out. > > I'm looking to split strings that ideally look like this: "Update: New > item (Household)" into a group. > This expression works ok: '^(Update:)?(.*)(\(.*\))$' - it returns > ("Update", "New item", "(Household)") > > Some strings will look like this however: "Update: New item (item) > (Household)". The expression above still does its job, as it returns > ("Update", "New item (item)", "(Household)"). > > It does not work however when there is no text in parentheses (eg > "Update: new item"). How can I get the expression to return a tuple > such as ("Update:", "new item", None)? > You need to make the last group optional and also make the middle group lazy: r'^(Update:)?(.*?)(?:(\(.*\)))?$'. (?:...) is the non-capturing version of (...). If you don't make the middle group lazy then it'll capture the rest of the string and the last group would never match anything! From andrew at acooke.org Sat Feb 7 09:42:05 2009 From: andrew at acooke.org (andrew cooke) Date: Sat, 7 Feb 2009 11:42:05 -0300 (CLST) Subject: "Weird" Indentation? (Or: is there a for...else construct?) In-Reply-To: <019d9052$0$20640$c3e8da3@news.astraweb.com> References: <20090207152122.683de28e@usenot.de> <019d9052$0$20640$c3e8da3@news.astraweb.com> Message-ID: there's a justification for this awful mess here - http://mail.python.org/pipermail/python-3000/2006-March/000104.html i didn't know about this, and even after reading steven's broken (i assume) example, managed to get it backwards. the else is if there *isn't* a break and is for search loops (see link above). (it's still in 3). andrew Steven D'Aprano wrote: > Andreas Waldenburger wrote: > >> It seems that there is a for...else construct. Replacing the inner if >> with pass seems to confirm this. The else clause is still executed. > > Yes, there is a for...else construct. > > The else block runs if the for loop exits *without* a break. > > for i in range(20): > if i == 10: break > else: > print "no break here" > > for i in range(20): > if i == 100: break > else: > print "no break here" > > >> What's broken here: Python or my brain? > > Perhaps we should not answer that question. > > > -- > Steven > > -- > http://mail.python.org/mailman/listinfo/python-list > > From google at mrabarnett.plus.com Sat Feb 7 09:44:25 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 07 Feb 2009 14:44:25 +0000 Subject: "Weird" Indentation? (Or: is there a for...else construct?) In-Reply-To: <20090207153459.123c5706@usenot.de> References: <20090207152122.683de28e@usenot.de> <019d9052$0$20640$c3e8da3@news.astraweb.com> <20090207153459.123c5706@usenot.de> Message-ID: <498D9E49.6070001@mrabarnett.plus.com> Andreas Waldenburger wrote: > On Sun, 08 Feb 2009 01:28:00 +1100 Steven D'Aprano > wrote: > >> Andreas Waldenburger wrote: >> >>> It seems that there is a for...else construct. Replacing the inner >>> if with pass seems to confirm this. The else clause is still >>> executed. >> Yes, there is a for...else construct. >> > That's something. In 6+ years of Python programming I've never seen or > heard of this thing. This might be useful, apparently. > One use case is: for x in list_of_items: if x.value == desired_value: desired_name = x.name break else: print "Couldn't find %s" % x.value > >> [snip] >> >>> What's broken here: Python or my brain? >> Perhaps we should not answer that question. >> > I did phrase that rather provocatively, didn't I? > > Well thanks. I'll try to learn less noisily in the future. :) > From REMpeteOVE at CAPpetezilla.ITALSco.uk Sat Feb 7 09:46:17 2009 From: REMpeteOVE at CAPpetezilla.ITALSco.uk (Peter Chant) Date: Sat, 07 Feb 2009 14:46:17 +0000 Subject: Newbie SWMixer / numpy help - AssertionError Message-ID: Hello, I'm a bit of a python newby. I want to play and record sound simultaneously. SWMixer seems able to do this but the examples use WAV files. I'm trying to play a test tone. Can anyone give me a steer as to why this fails? import sys import swmixer import numpy swmixer.init(samplerate=44100, chunksize=1024, stereo=False, microphone=True) #snd = swmixer.Sound("test1.wav") time = 1 freq = 440 time = numpy.linspace(0,1,44100*time) # 44100 numbers between 0 and 1 tone_data = numpy.sin(time*2*numpy.pi*freq) # A above Middle C snd = swmixer.Sound(tone_data) snd.play(loops=-1) I know this may be in a little at the deep end for someone who has just started to learn python, but I find I learn a lot faster if I try to do something that is useful. Pete -- http://www.petezilla.co.uk From mail at joaomoreno.com Sat Feb 7 09:55:06 2009 From: mail at joaomoreno.com (mail at joaomoreno.com) Date: Sat, 7 Feb 2009 06:55:06 -0800 (PST) Subject: BaseHTTPRequestHandler freezes while writing to self.wfile after installing Python 3.0 Message-ID: Hey guys, I'm starting to lose my head with this one. I have a class that extends BaseHTTPRequestHandler. It works fine on Python 2.5. And yesterday I was curious and decided to install Python 3.0 on my Mac (I followed this tutorial, to be sure I wasn't messing things up: http://farmdev.com/thoughts/66/python-3-0-on-mac-os-x-alongside-2-6-2-5-etc-/ ). I tried my application on Python 3.0 and the code just freezed on this line: self.wfile.write(f.read()) I searched and got to this bug http://bugs.python.org/issue3826 . I couldn't understand if there's already a fix for that. But, the strangest thing was that, when I tried my application on 2.5, it started freezing on the same spot! I then removed everything I installed from 3.0, fixed the paths, and it still gives me the error. I don't know what else to do. The app works fine on 2.5, because I tried it on another computer. Thanks for your help. From floatingpeanut at gmail.com Sat Feb 7 10:00:55 2009 From: floatingpeanut at gmail.com (floatingpeanut) Date: Sat, 7 Feb 2009 07:00:55 -0800 (PST) Subject: Is c.l.py becoming less friendly? References: <1233850000.12935.4.camel@localhost.localdomain> Message-ID: On Feb 7, 2:37?am, Terry Reedy wrote: > ? So I think python-list has become more friendly since. I've experienced the same sort of thing. About a year ago (I think) there were one or more regulars here who were often somewhat rude, unfriendly, or snobbish (not naming any names). Trouble was, they were experienced and often helpful too so the behaviour was mostly tolerated. Haven't seen that sort of thing in a while though. c.l.py is a very friendly place these days. From deets at nospam.web.de Sat Feb 7 10:45:28 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 07 Feb 2009 16:45:28 +0100 Subject: "Weird" Indentation? (Or: is there a for...else construct?) In-Reply-To: References: <20090207152122.683de28e@usenot.de> Message-ID: <6v5okoFi8vgdU2@mid.uni-berlin.de> Peter Otten schrieb: > Andreas Waldenburger wrote: > >> I've found something in the spirit of the following (in the epydoc >> sources, if you care): >> >> if True: >> print "outer if" >> for t in range(2): >> if True: >> print "for if" >> else: >> print "phantom else" >> >> For the life of me I can't place the "else". Which if clause does it >> belong to? None, it would seem from running the above snippet: >> >> outer if >> For if >> For if >> Phantom else >> >> It seems that there is a for...else construct. Replacing the inner if >> with pass seems to confirm this. The else clause is still executed. >> >> What's broken here: Python or my brain? > > Your rtfm sensor? > > http://docs.python.org/reference/compound_stmts.html#the-for-statement > > In short, the else suite is executed unless the for-loop is left > via 'break': Or exceptions of course. Might be obvious, but for completeness' sake. Diez From dave.nuttall at blueyonder.co.uk Sat Feb 7 10:52:53 2009 From: dave.nuttall at blueyonder.co.uk (David Nuttall) Date: Sat, 7 Feb 2009 15:52:53 -0000 Subject: Beginner Python OpenGL difficulties Message-ID: <20090207163720.4FD351E4002@bag.python.org> Hi Mike, I am just getting into OPENGL from Python. But I am having problems. Each time I try to run some OPENGL code I get the following sort of error: Traceback (most recent call last): File "C:\Documents and Settings\Owner\My Documents\My Work\Python Modules\PyOpenGL-Demo-3.0.0b6\PyOpenGL-Demo\NeHe\lesson1.py", line 142, in main() File "C:\Documents and Settings\Owner\My Documents\My Work\Python Modules\PyOpenGL-Demo-3.0.0b6\PyOpenGL-Demo\NeHe\lesson1.py", line 97, in main glutInit(sys.argv) File "C:\Python25\Lib\site-packages\OpenGL\GLUT\special.py", line 316, in glutInit _base_glutInit( ctypes.byref(count), holder ) File "C:\Python25\Lib\site-packages\OpenGL\GLUT\special.py", line 57, in _base_glutInit return __glutInitWithExit(pargc, argv, _exitfunc) File "C:\Python25\Lib\site-packages\OpenGL\platform\baseplatform.py", line 280, in __call__ self.__name__, self.__name__, NullFunctionError: Attempt to call an undefined function __glutInitWithExit, check for bool(__glutInitWithExit) before calling I can only think that the installation might be wrong. I have an AMD machine running Win32 - XP. Hope you can help me? Best regards Dave -------------- next part -------------- An HTML attachment was scrubbed... URL: From notvalid2 at sbcglobal.net Sat Feb 7 11:10:43 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Sat, 07 Feb 2009 08:10:43 -0800 Subject: Tkinter w.pack()? In-Reply-To: References: <_Lghl.12218$D32.6047@flpi146.ffdc.sbc.com> Message-ID: MRAB wrote: > W. eWatson wrote: ... >> I thought some months ago, I found Google commands that would operate >> in the browser link window. Guess not. >> >> BTW, isn't there an O'Reilly book on Google hacks of this sort? Where >> else does one find out about these Google tools? >> > Google? :-) > > http://www.google.com/support/websearch/bin/answer.py?hl=en&answer=136861 > Thanks. I may have that book marked from many, many months ago. If so, I see why I'd never find it. The BM entry does not show "Google". It does now. ;-) -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From benjamin at python.org Sat Feb 7 11:20:08 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 7 Feb 2009 16:20:08 +0000 (UTC) Subject: Python3.0 has more duplication in source code than Python2.5 References: <498D3A04.60503@v.loewis.de> <6v58gpFi7nnvU1@mid.uni-berlin.de> Message-ID: Terry gmail.com> writes: > On 2?7?, ??7?10?, "Diez B. Roggisch" wrote: > > Do you by any chance have a few examples of these? There is a lot of > > idiomatic code in python to e.g. acquire and release the GIL or doing > > refcount-stuff. If that happens to be done with rather generic names as > > arguments, I can well imagine that as being the cause. > Starting at line 5119 of D:\DOWNLOADS\Python-3.0\Python\Python-ast.c This isn't really fair because Python-ast.c is auto generated. ;) From zaheer.agadi at gmail.com Sat Feb 7 11:24:41 2009 From: zaheer.agadi at gmail.com (zaheer.agadi at gmail.com) Date: Sat, 7 Feb 2009 08:24:41 -0800 (PST) Subject: Java to Python Message-ID: <47cc94b7-afbe-4224-97d1-b268336d92a5@e1g2000pra.googlegroups.com> Hi I have a following class that is written Java and makes use of apache http client library,I am new to python can any one suggest me a python equivalent of this following class, Thanks , public class Authenticate{ private String storageUserName=null; private String storagePassword=null; private String authorization=null; private String identityHostName = null; private String identityPortNumber = null; private String accessKey=null; private String secretKey=null; public String getStoragePassword() { return storagePassword; } public void setStoragePassword(String storagePassword) { this.storagePassword = storagePassword; } public String getStorageUserName() { return storageUserName; } public void setStorageUserName(String storageUserName) { this.storageUserName = storageUserName; } public String getIdentityHostName() { return identityHostName; } public void setIdentityHostName(String identityHostName) { this.identityHostName = identityHostName; } public String getIdentityPortNumber() { return identityPortNumber; } public void setIdentityPortNumber(String identityPortNumber) { this.identityPortNumber = identityPortNumber; } public String getAccessKey() { return accessKey; } public void setAccessKey(String accessKey) { this.accessKey = accessKey; } public String getSecretKey() { return secretKey; } public void setSecretKey(String secretKey) { this.secretKey = secretKey; } /** *

Convenience string for Base 64 encoding.

*/ private static final String BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789+/"; /** *

Encode the specified credentials into a String as required by * HTTP Basic Authentication (RFC 2617).

* * @param username Username to be encoded * @param password Password to be encoded * @return String string containing encoded username and password. */ public String encodeCredentialsBasic(String username, String password) { String encode = username + ":" + password; int paddingCount = (3 - (encode.length() % 3)) % 3; encode += "\0\0".substring(0, paddingCount); StringBuilder encoded = new StringBuilder(); for (int i = 0; i < encode.length(); i += 3) { } return encoded.toString(); } public void fetchDetails(){ HttpClient client=new HttpClient(); //reqDetails = new RequestDetails(); //String identityURL=MessageUtil.getMessage ("IDENTITY_INSTANCE"); //int portNumber=Integer.parseInt(MessageUtil.getMessage ("IDENTITY_PORT")); authorization="Basic " + encodeCredentialsBasic (storageUserName, storagePassword); String url="https://"+identityHostName+ ":"+identityPortNumber+"/test/ndcsd2/persons/"+UserName +"/attributes/"; Protocol https=null; //try { https = new Protocol("https", new EasySSLProtocolSocketFactory(), Integer.parseInt(identityPortNumber)); /*} catch (GeneralSecurityException ex) { Logger.getLogger(Authenticate.class.getName()).log (Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(Authenticate.class.getName()).log (Level.SEVERE, null, ex); }*/ Protocol.registerProtocol("https", https); GetMethod method=new GetMethod(url); method.setRequestHeader("Authorization",authorization); method.setRequestHeader("Accept","application/xml"); try { int responseCode=client.executeMethod(method); if(responseCode==200){ InputStream is=method.getResponseBodyAsStream(); BufferedReader bis=new BufferedReader(new InputStreamReader(is)); String temp=null,sKey=null, aKey=null; String accessKeySearchString="AccessKey"; String secretKeySearchString="SecretKey"; int searchStringLength=0; while((temp=bis.readLine())!=null){ if(temp.indexOf(accessKeySearchString)!=-1){ int beginIndex=temp.indexOf (accessKeySearchString); searchStringLength=accessKeySearchString.length (); int endIndex=temp.indexOf("",beginIndex); aKey=temp.substring(beginIndex +searchStringLength,endIndex); } if(temp.indexOf(secretKeySearchString)!=-1){ int beginIndex=temp.indexOf (secretKeySearchString); searchStringLength=secretKeySearchString.length (); int endIndex=temp.indexOf("",beginIndex); sKey=temp.substring(beginIndex +searchStringLength,endIndex); } } setSecretKey(sKey); setAccessKey(aKey); } else { System.out.println("Not able to get the credentials. Returned : " + responseCode + " response code!!!"); } } catch (IOException ex) { Logger.getLogger(Authenticate.class.getName()).log (Level.SEVERE, null, ex); } } From banibrata.dutta at gmail.com Sat Feb 7 11:27:04 2009 From: banibrata.dutta at gmail.com (Banibrata Dutta) Date: Sat, 7 Feb 2009 21:57:04 +0530 Subject: Java to Python In-Reply-To: <47cc94b7-afbe-4224-97d1-b268336d92a5@e1g2000pra.googlegroups.com> References: <47cc94b7-afbe-4224-97d1-b268336d92a5@e1g2000pra.googlegroups.com> Message-ID: <3de8e1f70902070827s3faefa54y68ddad20d3178297@mail.gmail.com> Jython is not an option ? On Sat, Feb 7, 2009 at 9:54 PM, wrote: > Hi > > I have a following class that is written Java and makes use of apache > http client library,I am new to python can any one suggest me a python > equivalent of this following class, > > Thanks , > > public class Authenticate{ > > private String storageUserName=null; > private String storagePassword=null; > private String authorization=null; > private String identityHostName = null; > private String identityPortNumber = null; > > private String accessKey=null; > private String secretKey=null; > > public String getStoragePassword() { > return storagePassword; > } > > public void setStoragePassword(String storagePassword) { > this.storagePassword = storagePassword; > } > > public String getStorageUserName() { > return storageUserName; > } > > public void setStorageUserName(String storageUserName) { > this.storageUserName = storageUserName; > } > > public String getIdentityHostName() { > return identityHostName; > } > > public void setIdentityHostName(String identityHostName) { > this.identityHostName = identityHostName; > } > > public String getIdentityPortNumber() { > return identityPortNumber; > } > > public void setIdentityPortNumber(String identityPortNumber) { > this.identityPortNumber = identityPortNumber; > } > > public String getAccessKey() { > return accessKey; > } > > public void setAccessKey(String accessKey) { > this.accessKey = accessKey; > } > > public String getSecretKey() { > return secretKey; > } > > public void setSecretKey(String secretKey) { > this.secretKey = secretKey; > } > > > /** > *

Convenience string for Base 64 encoding.

> */ > private static final String BASE64_CHARS = > "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + > "abcdefghijklmnopqrstuvwxyz" + > "0123456789+/"; > > /** > *

Encode the specified credentials into a String as required > by > * HTTP Basic Authentication (RFC 2617).

> * > * @param username Username to be encoded > * @param password Password to be encoded > * @return String string containing encoded username and password. > */ > public String encodeCredentialsBasic(String username, String > password) { > String encode = username + ":" + password; > int paddingCount = (3 - (encode.length() % 3)) % 3; > encode += "\0\0".substring(0, paddingCount); > StringBuilder encoded = new StringBuilder(); > > for (int i = 0; i < encode.length(); i += 3) { > } > return encoded.toString(); > } > > public void fetchDetails(){ > HttpClient client=new HttpClient(); > //reqDetails = new RequestDetails(); > //String identityURL=MessageUtil.getMessage > ("IDENTITY_INSTANCE"); > //int portNumber=Integer.parseInt(MessageUtil.getMessage > ("IDENTITY_PORT")); > authorization="Basic " + encodeCredentialsBasic > (storageUserName, storagePassword); > String url="https://"+identityHostName+ > ":"+identityPortNumber+"/test/ndcsd2/persons/"+UserName > +"/attributes/"; > > Protocol https=null; > //try { > https = new Protocol("https", new > EasySSLProtocolSocketFactory(), Integer.parseInt(identityPortNumber)); > /*} catch (GeneralSecurityException ex) { > Logger.getLogger(Authenticate.class.getName()).log > (Level.SEVERE, null, ex); > } catch (IOException ex) { > Logger.getLogger(Authenticate.class.getName()).log > (Level.SEVERE, null, ex); > }*/ > Protocol.registerProtocol("https", https); > GetMethod method=new GetMethod(url); > method.setRequestHeader("Authorization",authorization); > method.setRequestHeader("Accept","application/xml"); > try { > int responseCode=client.executeMethod(method); > if(responseCode==200){ > InputStream is=method.getResponseBodyAsStream(); > BufferedReader bis=new BufferedReader(new > InputStreamReader(is)); > String temp=null,sKey=null, aKey=null; > String accessKeySearchString="AccessKey Name>"; > String secretKeySearchString="SecretKey Name>"; > int searchStringLength=0; > while((temp=bis.readLine())!=null){ > if(temp.indexOf(accessKeySearchString)!=-1){ > int beginIndex=temp.indexOf > (accessKeySearchString); > searchStringLength=accessKeySearchString.length > (); > int endIndex=temp.indexOf(" Value>",beginIndex); > aKey=temp.substring(beginIndex > +searchStringLength,endIndex); > } > if(temp.indexOf(secretKeySearchString)!=-1){ > int beginIndex=temp.indexOf > (secretKeySearchString); > searchStringLength=secretKeySearchString.length > (); > int endIndex=temp.indexOf(" Value>",beginIndex); > sKey=temp.substring(beginIndex > +searchStringLength,endIndex); > } > } > setSecretKey(sKey); > setAccessKey(aKey); > } else { > System.out.println("Not able to get the credentials. > Returned : " + responseCode + " response code!!!"); > } > } catch (IOException ex) { > Logger.getLogger(Authenticate.class.getName()).log > (Level.SEVERE, null, ex); > } > } > -- > http://mail.python.org/mailman/listinfo/python-list > -- regards, Banibrata http://www.linkedin.com/in/bdutta -------------- next part -------------- An HTML attachment was scrubbed... URL: From zaheer.agadi at gmail.com Sat Feb 7 11:49:48 2009 From: zaheer.agadi at gmail.com (zaheer agadi) Date: Sat, 7 Feb 2009 22:19:48 +0530 Subject: Java to Python In-Reply-To: <3de8e1f70902070827s3faefa54y68ddad20d3178297@mail.gmail.com> References: <47cc94b7-afbe-4224-97d1-b268336d92a5@e1g2000pra.googlegroups.com> <3de8e1f70902070827s3faefa54y68ddad20d3178297@mail.gmail.com> Message-ID: <397dfed40902070849k723d3594yb1c6a9c012383027@mail.gmail.com> Hi Thanks for replying .. I am actually looking for the pure Python options Are there any equivalent clasees for the following import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.protocol.Protocol; Thanks for your help -Zaheer On Sat, Feb 7, 2009 at 9:57 PM, Banibrata Dutta wrote: > Jython is not an option ? > > On Sat, Feb 7, 2009 at 9:54 PM, wrote: > >> Hi >> >> I have a following class that is written Java and makes use of apache >> http client library,I am new to python can any one suggest me a python >> equivalent of this following class, >> >> Thanks , >> >> public class Authenticate{ >> >> private String storageUserName=null; >> private String storagePassword=null; >> private String authorization=null; >> private String identityHostName = null; >> private String identityPortNumber = null; >> >> private String accessKey=null; >> private String secretKey=null; >> >> public String getStoragePassword() { >> return storagePassword; >> } >> >> public void setStoragePassword(String storagePassword) { >> this.storagePassword = storagePassword; >> } >> >> public String getStorageUserName() { >> return storageUserName; >> } >> >> public void setStorageUserName(String storageUserName) { >> this.storageUserName = storageUserName; >> } >> >> public String getIdentityHostName() { >> return identityHostName; >> } >> >> public void setIdentityHostName(String identityHostName) { >> this.identityHostName = identityHostName; >> } >> >> public String getIdentityPortNumber() { >> return identityPortNumber; >> } >> >> public void setIdentityPortNumber(String identityPortNumber) { >> this.identityPortNumber = identityPortNumber; >> } >> >> public String getAccessKey() { >> return accessKey; >> } >> >> public void setAccessKey(String accessKey) { >> this.accessKey = accessKey; >> } >> >> public String getSecretKey() { >> return secretKey; >> } >> >> public void setSecretKey(String secretKey) { >> this.secretKey = secretKey; >> } >> >> >> /** >> *

Convenience string for Base 64 encoding.

>> */ >> private static final String BASE64_CHARS = >> "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + >> "abcdefghijklmnopqrstuvwxyz" + >> "0123456789+/"; >> >> /** >> *

Encode the specified credentials into a String as required >> by >> * HTTP Basic Authentication (RFC 2617).

>> * >> * @param username Username to be encoded >> * @param password Password to be encoded >> * @return String string containing encoded username and password. >> */ >> public String encodeCredentialsBasic(String username, String >> password) { >> String encode = username + ":" + password; >> int paddingCount = (3 - (encode.length() % 3)) % 3; >> encode += "\0\0".substring(0, paddingCount); >> StringBuilder encoded = new StringBuilder(); >> >> for (int i = 0; i < encode.length(); i += 3) { >> } >> return encoded.toString(); >> } >> >> public void fetchDetails(){ >> HttpClient client=new HttpClient(); >> //reqDetails = new RequestDetails(); >> //String identityURL=MessageUtil.getMessage >> ("IDENTITY_INSTANCE"); >> //int portNumber=Integer.parseInt(MessageUtil.getMessage >> ("IDENTITY_PORT")); >> authorization="Basic " + encodeCredentialsBasic >> (storageUserName, storagePassword); >> String url="https://"+identityHostName+ >> ":"+identityPortNumber+"/test/ndcsd2/persons/"+UserName >> +"/attributes/"; >> >> Protocol https=null; >> //try { >> https = new Protocol("https", new >> EasySSLProtocolSocketFactory(), Integer.parseInt(identityPortNumber)); >> /*} catch (GeneralSecurityException ex) { >> Logger.getLogger(Authenticate.class.getName()).log >> (Level.SEVERE, null, ex); >> } catch (IOException ex) { >> Logger.getLogger(Authenticate.class.getName()).log >> (Level.SEVERE, null, ex); >> }*/ >> Protocol.registerProtocol("https", https); >> GetMethod method=new GetMethod(url); >> method.setRequestHeader("Authorization",authorization); >> method.setRequestHeader("Accept","application/xml"); >> try { >> int responseCode=client.executeMethod(method); >> if(responseCode==200){ >> InputStream is=method.getResponseBodyAsStream(); >> BufferedReader bis=new BufferedReader(new >> InputStreamReader(is)); >> String temp=null,sKey=null, aKey=null; >> String accessKeySearchString="AccessKey> Name>"; >> String secretKeySearchString="SecretKey> Name>"; >> int searchStringLength=0; >> while((temp=bis.readLine())!=null){ >> if(temp.indexOf(accessKeySearchString)!=-1){ >> int beginIndex=temp.indexOf >> (accessKeySearchString); >> searchStringLength=accessKeySearchString.length >> (); >> int endIndex=temp.indexOf("> Value>",beginIndex); >> aKey=temp.substring(beginIndex >> +searchStringLength,endIndex); >> } >> if(temp.indexOf(secretKeySearchString)!=-1){ >> int beginIndex=temp.indexOf >> (secretKeySearchString); >> searchStringLength=secretKeySearchString.length >> (); >> int endIndex=temp.indexOf("> Value>",beginIndex); >> sKey=temp.substring(beginIndex >> +searchStringLength,endIndex); >> } >> } >> setSecretKey(sKey); >> setAccessKey(aKey); >> } else { >> System.out.println("Not able to get the credentials. >> Returned : " + responseCode + " response code!!!"); >> } >> } catch (IOException ex) { >> Logger.getLogger(Authenticate.class.getName()).log >> (Level.SEVERE, null, ex); >> } >> } >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > > -- > regards, > Banibrata > http://www.linkedin.com/in/bdutta > -------------- next part -------------- An HTML attachment was scrubbed... URL: From alex at a13x.net Sat Feb 7 12:09:42 2009 From: alex at a13x.net (Aleksandar Radulovic) Date: Sat, 7 Feb 2009 17:09:42 +0000 Subject: Java to Python In-Reply-To: <397dfed40902070849k723d3594yb1c6a9c012383027@mail.gmail.com> References: <47cc94b7-afbe-4224-97d1-b268336d92a5@e1g2000pra.googlegroups.com> <3de8e1f70902070827s3faefa54y68ddad20d3178297@mail.gmail.com> <397dfed40902070849k723d3594yb1c6a9c012383027@mail.gmail.com> Message-ID: <845b10c50902070909r646b16a2rddc6e0e19c2df4d1@mail.gmail.com> Hi, This looks like a perfect job for httplib and urllib2 modules. On Sat, Feb 7, 2009 at 4:49 PM, zaheer agadi wrote: > Hi Thanks for replying .. > I am actually looking for the pure Python options > > Are there any equivalent clasees for the following > > import org.apache.commons.httpclient.HttpClient; > import org.apache.commons.httpclient.HttpException; > import > org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory; > import org.apache.commons.httpclient.methods.GetMethod; > import org.apache.commons.httpclient.protocol.Protocol; > > > Thanks for your help > -Zaheer > > On Sat, Feb 7, 2009 at 9:57 PM, Banibrata Dutta > wrote: >> >> Jython is not an option ? >> >> On Sat, Feb 7, 2009 at 9:54 PM, wrote: >>> >>> Hi >>> >>> I have a following class that is written Java and makes use of apache >>> http client library,I am new to python can any one suggest me a python >>> equivalent of this following class, >>> >>> Thanks , >>> >>> public class Authenticate{ >>> >>> private String storageUserName=null; >>> private String storagePassword=null; >>> private String authorization=null; >>> private String identityHostName = null; >>> private String identityPortNumber = null; >>> >>> private String accessKey=null; >>> private String secretKey=null; >>> >>> public String getStoragePassword() { >>> return storagePassword; >>> } >>> >>> public void setStoragePassword(String storagePassword) { >>> this.storagePassword = storagePassword; >>> } >>> >>> public String getStorageUserName() { >>> return storageUserName; >>> } >>> >>> public void setStorageUserName(String storageUserName) { >>> this.storageUserName = storageUserName; >>> } >>> >>> public String getIdentityHostName() { >>> return identityHostName; >>> } >>> >>> public void setIdentityHostName(String identityHostName) { >>> this.identityHostName = identityHostName; >>> } >>> >>> public String getIdentityPortNumber() { >>> return identityPortNumber; >>> } >>> >>> public void setIdentityPortNumber(String identityPortNumber) { >>> this.identityPortNumber = identityPortNumber; >>> } >>> >>> public String getAccessKey() { >>> return accessKey; >>> } >>> >>> public void setAccessKey(String accessKey) { >>> this.accessKey = accessKey; >>> } >>> >>> public String getSecretKey() { >>> return secretKey; >>> } >>> >>> public void setSecretKey(String secretKey) { >>> this.secretKey = secretKey; >>> } >>> >>> >>> /** >>> *

Convenience string for Base 64 encoding.

>>> */ >>> private static final String BASE64_CHARS = >>> "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + >>> "abcdefghijklmnopqrstuvwxyz" + >>> "0123456789+/"; >>> >>> /** >>> *

Encode the specified credentials into a String as required >>> by >>> * HTTP Basic Authentication (RFC 2617).

>>> * >>> * @param username Username to be encoded >>> * @param password Password to be encoded >>> * @return String string containing encoded username and password. >>> */ >>> public String encodeCredentialsBasic(String username, String >>> password) { >>> String encode = username + ":" + password; >>> int paddingCount = (3 - (encode.length() % 3)) % 3; >>> encode += "\0\0".substring(0, paddingCount); >>> StringBuilder encoded = new StringBuilder(); >>> >>> for (int i = 0; i < encode.length(); i += 3) { >>> } >>> return encoded.toString(); >>> } >>> >>> public void fetchDetails(){ >>> HttpClient client=new HttpClient(); >>> //reqDetails = new RequestDetails(); >>> //String identityURL=MessageUtil.getMessage >>> ("IDENTITY_INSTANCE"); >>> //int portNumber=Integer.parseInt(MessageUtil.getMessage >>> ("IDENTITY_PORT")); >>> authorization="Basic " + encodeCredentialsBasic >>> (storageUserName, storagePassword); >>> String url="https://"+identityHostName+ >>> ":"+identityPortNumber+"/test/ndcsd2/persons/"+UserName >>> +"/attributes/"; >>> >>> Protocol https=null; >>> //try { >>> https = new Protocol("https", new >>> EasySSLProtocolSocketFactory(), Integer.parseInt(identityPortNumber)); >>> /*} catch (GeneralSecurityException ex) { >>> Logger.getLogger(Authenticate.class.getName()).log >>> (Level.SEVERE, null, ex); >>> } catch (IOException ex) { >>> Logger.getLogger(Authenticate.class.getName()).log >>> (Level.SEVERE, null, ex); >>> }*/ >>> Protocol.registerProtocol("https", https); >>> GetMethod method=new GetMethod(url); >>> method.setRequestHeader("Authorization",authorization); >>> method.setRequestHeader("Accept","application/xml"); >>> try { >>> int responseCode=client.executeMethod(method); >>> if(responseCode==200){ >>> InputStream is=method.getResponseBodyAsStream(); >>> BufferedReader bis=new BufferedReader(new >>> InputStreamReader(is)); >>> String temp=null,sKey=null, aKey=null; >>> String accessKeySearchString="AccessKey>> Name>"; >>> String secretKeySearchString="SecretKey>> Name>"; >>> int searchStringLength=0; >>> while((temp=bis.readLine())!=null){ >>> if(temp.indexOf(accessKeySearchString)!=-1){ >>> int beginIndex=temp.indexOf >>> (accessKeySearchString); >>> searchStringLength=accessKeySearchString.length >>> (); >>> int endIndex=temp.indexOf(">> Value>",beginIndex); >>> aKey=temp.substring(beginIndex >>> +searchStringLength,endIndex); >>> } >>> if(temp.indexOf(secretKeySearchString)!=-1){ >>> int beginIndex=temp.indexOf >>> (secretKeySearchString); >>> searchStringLength=secretKeySearchString.length >>> (); >>> int endIndex=temp.indexOf(">> Value>",beginIndex); >>> sKey=temp.substring(beginIndex >>> +searchStringLength,endIndex); >>> } >>> } >>> setSecretKey(sKey); >>> setAccessKey(aKey); >>> } else { >>> System.out.println("Not able to get the credentials. >>> Returned : " + responseCode + " response code!!!"); >>> } >>> } catch (IOException ex) { >>> Logger.getLogger(Authenticate.class.getName()).log >>> (Level.SEVERE, null, ex); >>> } >>> } >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >> >> >> >> -- >> regards, >> Banibrata >> http://www.linkedin.com/in/bdutta > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- a lex 13 x http://www.a13x.info From rdmurray at bitdance.com Sat Feb 7 12:12:01 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Sat, 7 Feb 2009 17:12:01 +0000 (UTC) Subject: isfifo? Message-ID: I've googled and looked through os.path, but I don't see a method for determining if a path points to a FIFO. Anyone know of a simple way to do so? --RDM From marduk at letterboxes.org Sat Feb 7 12:23:20 2009 From: marduk at letterboxes.org (Albert Hopkins) Date: Sat, 07 Feb 2009 12:23:20 -0500 Subject: isfifo? In-Reply-To: References: Message-ID: <1234027400.12522.2.camel@centar.nbk> On Sat, 2009-02-07 at 17:12 +0000, rdmurray at bitdance.com wrote: > I've googled and looked through os.path, but I don't see a method for > determining if a path points to a FIFO. Anyone know of a simple way to > do so? import os import stat st_mode = os.stat(path)[0] isfifo = stat.S_ISFIFO(st_mode) From Scott.Daniels at Acm.Org Sat Feb 7 12:26:40 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 07 Feb 2009 09:26:40 -0800 Subject: Python3.0 has more duplication in source code than Python2.5 In-Reply-To: <218c44da-6086-4f02-843a-5d63520348b3@f40g2000pri.googlegroups.com> References: <498D3A04.60503@v.loewis.de> <6v58gpFi7nnvU1@mid.uni-berlin.de> <218c44da-6086-4f02-843a-5d63520348b3@f40g2000pri.googlegroups.com> Message-ID: Terry wrote: > ... I'm not saying that you can not have duplication in code. But it > seems that the stable & successful software releases tend to have > relatively stable duplication rate. This analysis overlooks the fact that 3.0 _was_ a major change, and is likely to grow cut-and-paste solutions to some problems as we switch to Unicode strings from byte strings. You are comparing a .0 version to .5 versions. I expect the polishing that follows as we go up through .1, .2, and so on will lower those redundancy measures. --Scott David Daniels Scott.Daniels at Acm.Org From martin at v.loewis.de Sat Feb 7 12:28:15 2009 From: martin at v.loewis.de (=?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=) Date: Sat, 07 Feb 2009 18:28:15 +0100 Subject: Python3.0 has more duplication in source code than Python2.5 In-Reply-To: <218c44da-6086-4f02-843a-5d63520348b3@f40g2000pri.googlegroups.com> References: <498D3A04.60503@v.loewis.de> <6v58gpFi7nnvU1@mid.uni-berlin.de> <218c44da-6086-4f02-843a-5d63520348b3@f40g2000pri.googlegroups.com> Message-ID: <498dc4af$0$7112$9b622d9e@news.freenet.de> > And I'm not saying that you can not have duplication in code. But it > seems that the stable & successful software releases tend to have > relatively stable duplication rate. So if some software has an instable duplication rate, it probably means that it is either not stable, or not successful. In the case of Python 3.0, it's fairly obvious which one it is: it's not stable. Indeed, Python 3.0 is a significant change from Python 2.x. Of course, anybody following the Python 3 development process could have told you see even without any code metrics. I still find the raw numbers fairly useless. What matters more to me is what specific code duplications have been added. Furthermore, your Dup30 classification is not important to me, but I'm rather after the nearly 2000 new chunks of code that has more than 60 subsequent tokens duplicated. Regards, Martin From martin at v.loewis.de Sat Feb 7 12:30:21 2009 From: martin at v.loewis.de (=?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=) Date: Sat, 07 Feb 2009 18:30:21 +0100 Subject: Python3.0 has more duplication in source code than Python2.5 In-Reply-To: References: <498D3A04.60503@v.loewis.de> Message-ID: <498dc52d$0$7112$9b622d9e@news.freenet.de> > But the duplication are always not very big, from about 100 lines > (rare) to less the 5 lines. As you can see the Rate30 is much bigger > than Rate60, that means there are a lot of small duplications. I don't find that important for code quality. It's the large chunks that I would like to see de-duplicated (unless, of course, they are in generated code, in which case I couldn't care less). Unfortunately, none of the examples you have posted so far are - large chunks, and - new in 3.0. Regards, Martin From martin at v.loewis.de Sat Feb 7 12:35:02 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 07 Feb 2009 18:35:02 +0100 Subject: isfifo? In-Reply-To: References: Message-ID: <498dc646$0$7112$9b622d9e@news.freenet.de> rdmurray at bitdance.com wrote: > I've googled and looked through os.path, but I don't see a method for > determining if a path points to a FIFO. Anyone know of a simple way to > do so? def isfifo(fn): return stat.S_ISFIFO(os.stat(fn).st_mode) HTH, Martin From rdmurray at bitdance.com Sat Feb 7 13:28:50 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Sat, 7 Feb 2009 18:28:50 +0000 (UTC) Subject: isfifo? References: <498dc646$0$7112$9b622d9e@news.freenet.de> Message-ID: =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?= wrote: > rdmurray at bitdance.com wrote: > > I've googled and looked through os.path, but I don't see a method for > > determining if a path points to a FIFO. Anyone know of a simple way to > > do so? > > def isfifo(fn): > return stat.S_ISFIFO(os.stat(fn).st_mode) Thanks. I should have thought of looking in os.stat. Odd that S_ISFIFO didn't come up in my google search. --RDM From bdesth.quelquechose at free.quelquepart.fr Sat Feb 7 14:06:20 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sat, 07 Feb 2009 20:06:20 +0100 Subject: WebError documentation? In-Reply-To: References: Message-ID: <498de947$0$24412$426a74cc@news.free.fr> Ron Garret a ?crit : > In article , > Chris Rebert wrote: > >> On Thu, Feb 5, 2009 at 12:52 PM, Ron Garret wrote: >>> Is there any? Where is it? Extensive Googling has proven fruitless. >> It's not a standard Python exception. A third-party library you're >> using must be raising it. Check the exception traceback. > > I see I did not make myself clear. Now *that* is an understatement... > I meant the Python software package > called "weberror", not a generic web error. > > http://pypi.python.org/pypi/WebError Google is your friend: http://bel-epa.com/docs/thirdparty/weberror/ From asmodai at in-nomine.org Sat Feb 7 14:48:34 2009 From: asmodai at in-nomine.org (Jeroen Ruigrok van der Werven) Date: Sat, 7 Feb 2009 20:48:34 +0100 Subject: Python3.0 has more duplication in source code than Python2.5 In-Reply-To: References: <498D3A04.60503@v.loewis.de> <6v58gpFi7nnvU1@mid.uni-berlin.de> <218c44da-6086-4f02-843a-5d63520348b3@f40g2000pri.googlegroups.com> Message-ID: <20090207194834.GP14658@nexus.in-nomine.org> -On [20090207 18:25], Scott David Daniels (Scott.Daniels at Acm.Org) wrote: >This analysis overlooks the fact that 3.0 _was_ a major change, and is >likely to grow cut-and-paste solutions to some problems as we switch to >Unicode strings from byte strings. You'd best hope the copied section was thoroughly reviewed otherwise you're duplicating a flaw across X other sections. And then you also best hope that whoever finds said flaw and fixes it is also smart enough to check for similar constructs around the code base. -- Jeroen Ruigrok van der Werven / asmodai ????? ?????? ??? ?? ?????? http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B Earth to earth, ashes to ashes, dust to dust... From alex at a13x.net Sat Feb 7 15:02:07 2009 From: alex at a13x.net (Aleksandar Radulovic) Date: Sat, 7 Feb 2009 20:02:07 +0000 Subject: Java to Python In-Reply-To: <397dfed40902070928k5d8fa7f5tc7ff0efe2d44599a@mail.gmail.com> References: <47cc94b7-afbe-4224-97d1-b268336d92a5@e1g2000pra.googlegroups.com> <3de8e1f70902070827s3faefa54y68ddad20d3178297@mail.gmail.com> <397dfed40902070849k723d3594yb1c6a9c012383027@mail.gmail.com> <845b10c50902070909h111ac623u565ec1d1c5d9ad52@mail.gmail.com> <397dfed40902070928k5d8fa7f5tc7ff0efe2d44599a@mail.gmail.com> Message-ID: <845b10c50902071202p78aad1fao93c1d6a3148b589a@mail.gmail.com> Hi, On Sat, Feb 7, 2009 at 5:28 PM, zaheer agadi wrote: > Thanks Alex, > > Can you provide me more details on httplib and urllib ? The details can be found in Python documentation (http://python.org/doc), on these pages: http://docs.python.org/library/httplib.html I'm sure you can figure out the location of the documentation for the urllib2 module. Documentation includes examples too. Regards, alex. -- a lex 13 x http://www.a13x.info From steve at holdenweb.com Sat Feb 7 15:06:12 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 07 Feb 2009 15:06:12 -0500 Subject: Python3.0 has more duplication in source code than Python2.5 In-Reply-To: <20090207194834.GP14658@nexus.in-nomine.org> References: <498D3A04.60503@v.loewis.de> <6v58gpFi7nnvU1@mid.uni-berlin.de> <218c44da-6086-4f02-843a-5d63520348b3@f40g2000pri.googlegroups.com> <20090207194834.GP14658@nexus.in-nomine.org> Message-ID: Jeroen Ruigrok van der Werven wrote: > -On [20090207 18:25], Scott David Daniels (Scott.Daniels at Acm.Org) wrote: >> This analysis overlooks the fact that 3.0 _was_ a major change, and is >> likely to grow cut-and-paste solutions to some problems as we switch to >> Unicode strings from byte strings. > > You'd best hope the copied section was thoroughly reviewed otherwise you're > duplicating a flaw across X other sections. And then you also best hope that > whoever finds said flaw and fixes it is also smart enough to check for > similar constructs around the code base. > This is probably preferable to five different developers solving the same problem five different ways and introducing three *different* bugs, no? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From theller at python.net Sat Feb 7 15:37:14 2009 From: theller at python.net (Thomas Heller) Date: Sat, 07 Feb 2009 21:37:14 +0100 Subject: py2exe and distutils In-Reply-To: References: Message-ID: <6v69nnFi8bmqU1@mid.individual.net> Maxim Demenko schrieb: > Hi, > i have installed Python 2.5.4 on WinXP, setuptools-0.6c9 and py2exe 0.6.9 > Now i can't list installed modules, here is the stacktrace: > > > > help> modules > > Please wait a moment while I gather a list of all available modules... > > Traceback (most recent call last): > File "", line 1, in > File "C:\Programme\Python25\lib\site.py", line 346, in __call__ > return pydoc.help(*args, **kwds) > File "C:\Programme\Python25\lib\pydoc.py", line 1649, in __call__ > self.interact() > File "C:\Programme\Python25\lib\pydoc.py", line 1667, in interact > self.help(request) > File "C:\Programme\Python25\lib\pydoc.py", line 1683, in help > elif request == 'modules': self.listmodules() > File "C:\Programme\Python25\lib\pydoc.py", line 1804, in listmodules > ModuleScanner().run(callback) > File "C:\Programme\Python25\lib\pydoc.py", line 1855, in run > for importer, modname, ispkg in pkgutil.walk_packages(): > File "C:\Programme\Python25\lib\pkgutil.py", line 110, in walk_packages > __import__(name) > File > "C:\Programme\Python25\Lib\site-packages\setuptools\__init__.py", line > 2, in > from setuptools.extension import Extension, Library > File > "C:\Programme\Python25\Lib\site-packages\setuptools\extension.py", line > 2, in > from dist import _get_unpatched > File "C:\Programme\Python25\Lib\site-packages\setuptools\dist.py", > line 27, in > _Distribution = _get_unpatched(_Distribution) > File "C:\Programme\Python25\Lib\site-packages\setuptools\dist.py", > line 23, in _get_unpatched > "distutils has already been patched by %r" % cls > AssertionError: distutils has already been patched by py2exe.Distribution at 0x011B4F90> > > Any suggestion, how to fix this issue? Looks like a setuptools problem to me. Here's the output on my system: >>> help("modules") Please wait a moment while I gather a list of all available modules... Traceback (most recent call last): File "", line 1, in File "c:\python25\lib\site.py", line 346, in __call__ return pydoc.help(*args, **kwds) File "c:\python25\lib\pydoc.py", line 1645, in __call__ self.help(request) File "c:\python25\lib\pydoc.py", line 1682, in help elif request == 'modules': self.listmodules() File "c:\python25\lib\pydoc.py", line 1803, in listmodules ModuleScanner().run(callback) File "c:\python25\lib\pydoc.py", line 1854, in run for importer, modname, ispkg in pkgutil.walk_packages(): File "c:\python25\lib\pkgutil.py", line 125, in walk_packages for item in walk_packages(path, name+'.', onerror): File "c:\python25\lib\pkgutil.py", line 110, in walk_packages __import__(name) File "c:\python25\lib\site-packages\pyopengl-3.0.0b1-py2.5.egg\OpenGL\Tk\__init__.py", line 87, in _default_root.tk.call('package', 'require', 'Togl') _tkinter.TclError: can't find package Togl >>> ^Z Thomas From mmanns at gmx.net Sat Feb 7 15:39:17 2009 From: mmanns at gmx.net (mmanns at gmx.net) Date: Sat, 7 Feb 2009 21:39:17 +0100 Subject: Flattening lists References: <9a8af8a3-27fb-4f5b-90ea-ee0276c7e5e3@r15g2000prd.googlegroups.com> <9c2ed038-7a9b-4a35-adae-8b0df890040e@k36g2000pri.googlegroups.com> <76695d3b-bc74-4b72-b0ee-0c646d228b6f@t13g2000yqc.googlegroups.com> Message-ID: <20090207213917.24c8433a@gmx.net> On Sat, 7 Feb 2009 01:06:06 -0800 (PST) Rhamphoryncus wrote: > On Feb 6, 10:21?pm, rdmur... at bitdance.com wrote: > > Quoth Mensanator : > > > def flatten(listOfLists): > > > ? ? return list(chain.from_iterable(listOfLists)) > > > > ? ? Python 2.6.1 (r261:67515, Jan ?7 2009, 17:09:13) > > ? ? [GCC 4.3.2] on linux2 > > ? ? Type "help", "copyright", "credits" or "license" for more > > information. >>> from itertools import chain > > ? ? >>> list(chain.from_iterable([1, 2, [3, 4]])) > > ? ? Traceback (most recent call last): > > ? ? ? File "", line 1, in > > ? ? TypeError: 'int' object is not iterable > > ? ? >>> list(chain(*[1, 2, [3, 4]])) > > ? ? Traceback (most recent call last): > > ? ? ? File "", line 1, in > > ? ? TypeError: 'int' object is not iterable > > ? ? >>> list(chain.from_iterable(['abcd', 'efg', [3, 4]])) > > ? ? ['a', 'b', 'c', 'd', 'e', 'f', 'g', 3, 4] > > What usecase do you have for such inconsistently structured data? I have a similar use case in pyspread, which is a Python spreadsheet that employs numpy object arrays. Since the Python objects in the numpy arrays are derived from user input, they can be anything, including nested lists as well as strings, etc. Since I consider my work-around that treats strings as a special case a rather ugly hack, I would welcome a robust, generic approach to the OP's problem. Martin From theller at python.net Sat Feb 7 15:39:19 2009 From: theller at python.net (Thomas Heller) Date: Sat, 07 Feb 2009 21:39:19 +0100 Subject: py2exe and distutils In-Reply-To: <6v69nnFi8bmqU1@mid.individual.net> References: <6v69nnFi8bmqU1@mid.individual.net> Message-ID: <6v69rkFi8bmqU2@mid.individual.net> > Maxim Demenko schrieb: >> Hi, >> i have installed Python 2.5.4 on WinXP, setuptools-0.6c9 and py2exe 0.6.9 >> Now i can't list installed modules, here is the stacktrace: [...] >> Any suggestion, how to fix this issue? > Thomas Heller schrieb: > Looks like a setuptools problem to me. Here's the output on my system: Actually, I don't know where the problem is. Maybe pydoc? > > Thomas From sjmachin at lexicon.net Sat Feb 7 15:40:09 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 7 Feb 2009 12:40:09 -0800 (PST) Subject: Trouble with regular expressions References: Message-ID: On Feb 8, 1:37?am, MRAB wrote: > LaundroMat wrote: > > Hi, > > > I'm quite new to regular expressions, and I wonder if anyone here > > could help me out. > > > I'm looking to split strings that ideally look like this: "Update: New > > item (Household)" into a group. > > This expression works ok: '^(Update:)?(.*)(\(.*\))$' - it returns > > ("Update", "New item", "(Household)") > > > Some strings will look like this however: "Update: New item (item) > > (Household)". The expression above still does its job, as it returns > > ("Update", "New item (item)", "(Household)"). Not quite true; it actually returns ('Update:', ' New item (item) ', '(Household)') However ignoring the difference in whitespace, the OP's intention is clear. Yours returns ('Update:', ' New item ', '(item) (Household)') > > It does not work however when there is no text in parentheses (eg > > "Update: new item"). How can I get the expression to return a tuple > > such as ("Update:", "new item", None)? > > You need to make the last group optional and also make the middle group > lazy: r'^(Update:)?(.*?)(?:(\(.*\)))?$'. Why do you perpetuate the redundant ^ anchor? > (?:...) is the non-capturing version of (...). Why do you use (?:(subpattern))? instead of just plain (subpattern)? ? From rhamph at gmail.com Sat Feb 7 15:50:22 2009 From: rhamph at gmail.com (Rhamphoryncus) Date: Sat, 7 Feb 2009 12:50:22 -0800 (PST) Subject: Flattening lists References: <9a8af8a3-27fb-4f5b-90ea-ee0276c7e5e3@r15g2000prd.googlegroups.com> <9c2ed038-7a9b-4a35-adae-8b0df890040e@k36g2000pri.googlegroups.com> <76695d3b-bc74-4b72-b0ee-0c646d228b6f@t13g2000yqc.googlegroups.com> <20090207213917.24c8433a@gmx.net> Message-ID: On Feb 7, 1:39?pm, wrote: > On Sat, 7 Feb 2009 01:06:06 -0800 (PST) > Rhamphoryncus wrote: > > > What usecase do you have for such inconsistently structured data? > > I have a similar use case in pyspread, which is a Python spreadsheet > that employs numpy object arrays. Since the Python objects in the numpy > arrays are derived from user input, they can be anything, including > nested lists as well as strings, etc. > > Since I consider my work-around that treats strings as a special case a > rather ugly hack, I would welcome a robust, generic approach to the > OP's problem. Can you explain this in a little more detail? From aleksandr.goretoy at gmail.com Sat Feb 7 15:51:58 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Sat, 7 Feb 2009 14:51:58 -0600 Subject: Where to host a (Python) project? In-Reply-To: References: <387f23cd-90e2-46fc-8c91-1c2f6b31c89e@u13g2000yqg.googlegroups.com> <6dcb8ce5-c93e-458c-9047-e5db60f27d90@v18g2000pro.googlegroups.com> <87bptgxu2y.fsf@benfinney.id.au> Message-ID: If you don't mind changing dns entries. You can also use Google App Engine. It's really nice. http://code.google.com/appengine/docs/python/tools/webapp/overview.html -Alex Goretoy http://www.alexgoretoy.com On Fri, Feb 6, 2009 at 1:07 AM, alex goretoy wrote: > I use google code. > http://code.google.com/p/pynutbutter > > -Alex Goretoy > http://www.alexgoretoy.com > > > > > On Thu, Feb 5, 2009 at 6:55 PM, Ben Finney < > bignose+hates-spam at benfinney.id.au >wrote: > >> aahz at pythoncraft.com (Aahz) writes: >> >> > In article < >> 6dcb8ce5-c93e-458c-9047-e5db60f27d90 at v18g2000pro.googlegroups.com>, >> > andrew cooke wrote: >> > >hi, just fyi, i investigated this and you can join any publicly >> > >readable group by sending an email to the "-subscribe" address. you >> > >do not need a google login for this and, as far as i can tell, it >> > >then operates for you like a normal mailing list. >> > >> > The same thing is theoretically true for Yahoo groups, but I've >> > heard from people over the years about various difficulties fixing >> > problems with list subscriptions in the absence of a real Yahoo >> > login and I'm not particularly interested in finding out that the >> > same thing ends up being true for Google lists. >> >> Indeed it does. I have succeeded in subscribing to Google mailing >> lists in the absence of a Google account, but *managing* that >> subscription thereafter in the absence of a Google account is >> obnoxiously difficult. Your caution is well advised. >> >> -- >> \ "I got fired from my job the other day. They said my | >> `\ personality was weird. ? That's okay, I have four more." | >> _o__) ?Bug-Eyed Earl, _Red Meat_ | >> Ben Finney >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin at v.loewis.de Sat Feb 7 15:52:47 2009 From: martin at v.loewis.de (=?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=) Date: Sat, 07 Feb 2009 21:52:47 +0100 Subject: Python3.0 has more duplication in source code than Python2.5 In-Reply-To: References: <498D3A04.60503@v.loewis.de> <6v58gpFi7nnvU1@mid.uni-berlin.de> <218c44da-6086-4f02-843a-5d63520348b3@f40g2000pri.googlegroups.com> <20090207194834.GP14658@nexus.in-nomine.org> Message-ID: <498df49f$0$11402$9b622d9e@news.freenet.de> > This is probably preferable to five different developers solving the > same problem five different ways and introducing three *different* bugs, no? With the examples presented, I'm not convinced that there is actually significant code duplication going on in the first place. Regards, Martin From mdemenko at gmail.com Sat Feb 7 16:20:01 2009 From: mdemenko at gmail.com (Maxim Demenko) Date: Sat, 07 Feb 2009 22:20:01 +0100 Subject: py2exe and distutils In-Reply-To: <6v69rkFi8bmqU2@mid.individual.net> References: <6v69nnFi8bmqU1@mid.individual.net> <6v69rkFi8bmqU2@mid.individual.net> Message-ID: <498DFB01.5060308@gmail.com> Thomas Heller schrieb: >> Maxim Demenko schrieb: >>> Hi, >>> i have installed Python 2.5.4 on WinXP, setuptools-0.6c9 and py2exe 0.6.9 >>> Now i can't list installed modules, here is the stacktrace: > [...] >>> Any suggestion, how to fix this issue? > Thomas Heller schrieb: >> Looks like a setuptools problem to me. Here's the output on my system: > > Actually, I don't know where the problem is. Maybe pydoc? > >> Thomas Thank you Thomas, i found http://thread.gmane.org/gmane.comp.python.distutils.devel/3340 and tried to import setuptools first - indeed, in this case the problem seems to be solved, however, would like to know, how to persist it. If i put it into py2exe.__init__.py - is it a very bad idea? Best regards Maxim From asmodai at in-nomine.org Sat Feb 7 16:25:14 2009 From: asmodai at in-nomine.org (Jeroen Ruigrok van der Werven) Date: Sat, 7 Feb 2009 22:25:14 +0100 Subject: Python3.0 has more duplication in source code than Python2.5 In-Reply-To: References: <498D3A04.60503@v.loewis.de> <6v58gpFi7nnvU1@mid.uni-berlin.de> <218c44da-6086-4f02-843a-5d63520348b3@f40g2000pri.googlegroups.com> <20090207194834.GP14658@nexus.in-nomine.org> Message-ID: <20090207212514.GB58127@nexus.in-nomine.org> -On [20090207 21:07], Steve Holden (steve at holdenweb.com) wrote: >This is probably preferable to five different developers solving the >same problem five different ways and introducing three *different* bugs, no? I guess the answer would be 'that depends', but in most cases you would be correct, yes. -- Jeroen Ruigrok van der Werven / asmodai ????? ?????? ??? ?? ?????? http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B Earth to earth, ashes to ashes, dust to dust... From mmanns at gmx.net Sat Feb 7 17:07:19 2009 From: mmanns at gmx.net (mmanns at gmx.net) Date: Sat, 7 Feb 2009 23:07:19 +0100 Subject: Flattening lists References: <9a8af8a3-27fb-4f5b-90ea-ee0276c7e5e3@r15g2000prd.googlegroups.com> <9c2ed038-7a9b-4a35-adae-8b0df890040e@k36g2000pri.googlegroups.com> <76695d3b-bc74-4b72-b0ee-0c646d228b6f@t13g2000yqc.googlegroups.com> <20090207213917.24c8433a@gmx.net> Message-ID: <20090207230719.5bfd6022@gmx.net> On Sat, 7 Feb 2009 12:50:22 -0800 (PST) Rhamphoryncus wrote: > On Feb 7, 1:39?pm, wrote: > > On Sat, 7 Feb 2009 01:06:06 -0800 (PST) > > Rhamphoryncus wrote: > > > > > What usecase do you have for such inconsistently structured data? > > > > I have a similar use case in pyspread, which is a Python spreadsheet > > that employs numpy object arrays. Since the Python objects in the > > numpy arrays are derived from user input, they can be anything, > > including nested lists as well as strings, etc. > > > > Since I consider my work-around that treats strings as a special > > case a rather ugly hack, I would welcome a robust, generic approach > > to the OP's problem. > > Can you explain this in a little more detail? In the application, there is one main numpy array of type "O". Each element of the array corresponds to one cell in a grid. The user may enter a Python expression into the grid cell. The input is evaled and the result is stored in the numpy array (the actual process is a bit more complicated). Therefore, the object inside a numpy array element may be an inconsistent, nested, iterable type. The user now may access the result grid via __getitem__. When doing this, a numpy array that is as flat as possible while comprising the maximum possible data depth is returned, i.e.: 1. Non-string and non-unicode iterables of similar length for each of the cells form extra dimensions. 2. In order to remove different container types, the result is flattened, cast into a numpy.array and re-shaped. 3. Dimensions of length 1 are eliminated. Therefore, the user can conveniently use numpy ufuncs on the results. I am referring to the flatten operation in step 2 From andrew at acooke.org Sat Feb 7 17:08:09 2009 From: andrew at acooke.org (andrew cooke) Date: Sat, 7 Feb 2009 19:08:09 -0300 (CLST) Subject: Python3.0 has more duplication in source code than Python2.5 In-Reply-To: References: <498D3A04.60503@v.loewis.de> <6v58gpFi7nnvU1@mid.uni-berlin.de> <218c44da-6086-4f02-843a-5d63520348b3@f40g2000pri.googlegroups.com> <20090207194834.GP14658@nexus.in-nomine.org> Message-ID: <6ba795a7aadcaf351089065e775555ec.squirrel@acooke.dyndns.org> Steve Holden wrote: >> You'd best hope the copied section was thoroughly reviewed otherwise >> you're >> duplicating a flaw across X other sections. And then you also best hope >> that >> whoever finds said flaw and fixes it is also smart enough to check for >> similar constructs around the code base. >> > This is probably preferable to five different developers solving the > same problem five different ways and introducing three *different* bugs, > no? someone posted some numbers that suggested that more code than normal was copied in python 3.0. that seems reasonable, as others have said, because it's a new major release. but as far as i know, this is the first time it's been raised. so it seems like a useful piece of information that might help improve python in some way. which should be welcomed. yet the general tone of the responses has been more defensive than i would have expected. i don't really understand why. nothing really terrible, given the extremes you get on the net in general, but still a little disappointing. the email quoted above is a typical example. as i said - nothing terrible, just a misleading false dichotomy. yes, five people solving it five different ways would be worse, but that doesn't mean there isn't some better solution. surely it would be preferable if there was one way, that didn't involve copying code, that everyone could use? i'm not saying there is such a solution. i'm not even saying that there is certainly a problem. i'm just making the quiet observation that the original information is interesting, might be useful, and should be welcomed. andrew From martin at v.loewis.de Sat Feb 7 17:36:25 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 07 Feb 2009 23:36:25 +0100 Subject: Python3.0 has more duplication in source code than Python2.5 In-Reply-To: References: <498D3A04.60503@v.loewis.de> <6v58gpFi7nnvU1@mid.uni-berlin.de> <218c44da-6086-4f02-843a-5d63520348b3@f40g2000pri.googlegroups.com> <20090207194834.GP14658@nexus.in-nomine.org> Message-ID: <498e0cea$0$30915$9b622d9e@news.freenet.de> > yet the general tone of the responses has been more defensive than i would > have expected. i don't really understand why. nothing really terrible, > given the extremes you get on the net in general, but still a little > disappointing. I think this is fairly easy to explain. The OP closes with the question "Does that say something about the code quality of Python3.0?" thus suggesting that the quality of Python 3 is poor. Nobody likes to hear that the quality of his work is poor. He then goes on saying "But it seems that the stable & successful software releases tend to have relatively stable duplication rate." suggesting that Python 3.0 cannot be successful, because it doesn't have a relatively stable duplication rate. Nobody likes to hear that a project one has put many month into cannot be successful. Hence the defensive responses. > i'm not saying there is such a solution. i'm not even saying that there > is certainly a problem. i'm just making the quiet observation that the > original information is interesting, might be useful, and should be > welcomed. The information is interesting. I question whether it is useful as-is, as it doesn't tell me *what* code got duplicated (and it seems it is also incorrect, since it includes analysis of generated code). While I can welcome the information, I cannot welcome the conclusion that the OP apparently draws from them. Regards, Martin From robert.kern at gmail.com Sat Feb 7 17:47:55 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 07 Feb 2009 16:47:55 -0600 Subject: Newbie SWMixer / numpy help - AssertionError In-Reply-To: References: Message-ID: On 2009-02-07 08:46, Peter Chant wrote: > Hello, > > I'm a bit of a python newby. I want to play and record sound > simultaneously. SWMixer seems able to do this but the examples use WAV > files. I'm trying to play a test tone. Can anyone give me a steer as to > why this fails? Looking at the SWMixer docs, you probably want snd = swmixer.Sound(data=tone_data) Well, sort of. You probably need to scale your data and convert it to int16 format. It's currently in floating point format. When asking about why something fails, it helps a lot if you specify exactly how it fails and what you expected to happen. Copy-and-paste any error messages exactly. If you need more help with SWMixer's API, I recommend asking the author. It's not in widespread use, so he can probably give you better and faster help than we can. If you need more help with numpy, specifically, you can ask on the numpy-discussion mailing list. numpy *is* in widespread use, but there's a higher concentration of helpful numpy users over there. http://www.scipy.org/Mailing_Lists -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From rdsc-python at tigana.org Sat Feb 7 17:50:04 2009 From: rdsc-python at tigana.org (Randy Smith) Date: Sat, 7 Feb 2009 17:50:04 -0500 Subject: TkInter: Problem with propagation of resize events through geometry manager hierarchy? Message-ID: <6A117BEC-C653-4092-BC4B-D4FC3F0CB486@tigana.org> Hi! I'm looking for help with a Tkinter program's handling of resize. I'm trying to do a fairly simple widget that shows a cropped part of a larger image, and let's you navigate within the larger image through a variety of methods. The widget hierarchy is: root ImageWidget (my class) Label (contains the image) Horizontal Scroll Bar Vertical scroll bar The cropping and scrolling works fine. But when I try to add responding to resize events, I get into trouble. Specifically: * When I naively change the size of the image shown to be borderwidth less than the size indicated in the configure event, the size of the image shown grows gradually but inexorably when I start the test app. (Sorta scary, actually :-}) * When I fiddle a bit to figure out what the actual difference in size is between the Configure event and the image that can be displayed, I get a vibrating, jagged display of the image. Investigation suggests that multiple configure events are hitting the label in response to each user resize with different sizes. I'm guessing that when I resize the image in response to those different events, that creates new resize events propagating through the window manager hierarchy, which creates new configure events, which means my handler changes the image size, which ... you get the idea. However, everything seems to work fine if I leave out the scroll bars and just have a label in a frame inside the root window; the image resizes fine. If the scroll bars are in place but I don't have the image resize bound to the configure event, I get two sets of resize events propagaing through the system on startup; without, I just get one. Event lists and code included below. Any help would be appreciated. Thanks! -- Randy Smith -- Event list on startup with scroll bars: : width height root : 220 220 root : 1 1 iwidget : 220 220 root : 220 220 vscroll : 16 204 root : 16 204 hscroll : 204 16 root : 204 16 ilabel : 204 204 root : 204 204 vscroll : 15 205 root : 15 205 hscroll : 205 15 root : 205 15 ilabel : 205 205 root : 205 205 root : 219 219 ilabel : 205 205 root : 205 205 hscroll : 205 15 root : 205 15 vscroll : 15 205 root : 15 205 iwidget : 219 219 root : 219 219 vscroll : 15 204 root : 15 204 hscroll : 204 15 root : 204 15 ilabel : 204 204 root : 204 204 -- Event list on startup without scroll bars root : 204 204 root : 1 1 iwidget : 204 204 root : 204 204 ilabel : 204 204 root : 204 204 -- Code, without image resize. If you want to see the vibration, uncomment the line self.label.bind("", self.reconfigure, "+") To actually run it you'll need an image "test.tiff" in the current directory (any image of size > 200x200 will do) and access to the python imaging library (PIL), but I hope the code is pretty clear (other than the math transforming between various coordinate systems, which I don't believe is relevant; focus on reconfigure(), refresh, and __init__). #!/usr/bin/python import traceback from Tkinter import * from PIL import Image import ImageTk debug = 4 def display_args(*args): print "Args: ", args def display_event(event): print event.__dict__ def display_tag_and_size(tag, event): print tag, ": ", event.width, event.height class NotYetImplemented(Exception): pass def mapnum(x, fromrange, torange): assert fromrange[0] <= x < fromrange[1], (fromrange[0], x, fromrange[1]) assert torange[0] < torange[1], (torange[0], torange[1]) ## Need to force floating point x *= 1.0 return (x - fromrange[0]) / (fromrange[1] - fromrange[0]) * (torange[1] - torange[0]) + torange[0] class ImageWidget(Frame): def __init__(self, parent, gfunc, image_size, starting_zoom=1, starting_ul=(0,0), starting_size = None): """Create an Image Widget which will display an image based on the function passed. That function will be called with the arguments (zoom_factor, (xstart, xend), (ystart, yend)) and must return a TkInter PhotoImage object of size (xend-xstart, yend-ystart). IMAGE_SIZE describes the "base size" of the image being backed by gfunc. starting_* describes the starting window on the image.""" ## Default starting size to whole image if not starting_size: starting_size = image_size ## Init parent Frame.__init__(self, parent) self.bind("", lambda e, t="iwidget": display_tag_and_size(t, e)) ## Base image parameters self.generator_func = gfunc self.isize = image_size ## Modifier of base image size for coords currently working in self.zoom = starting_zoom ## Interval of augmented (zoomed) image currently shown ## Note that these must be integers; these map directly to pixels self.xint = [starting_ul[0], starting_ul[0] + starting_size[0]] self.yint = [starting_ul[1], starting_ul[1] + starting_size[1]] ## Widgets self.label = Label(self) print type(self.label["borderwidth"]) self.label.bind("", lambda e, t="ilabel": display_tag_and_size(t, e)) self.labelborderwidth = 4 # XXX: Constant because I can't manage # to get the value of # self.label["borderwidth"] as a number :-? self.hscroll = Scrollbar(self, orient = HORIZONTAL, command = lambda *args: self.scmd(False, *args)) self.hscroll.bind("", lambda e, t="hscroll": display_tag_and_size(t, e)) self.vscroll = Scrollbar(self, orient = VERTICAL, command = lambda *args: self.scmd(True, *args)) self.vscroll.bind("", lambda e, t="vscroll": display_tag_and_size(t, e)) # self.label.bind("", self.reconfigure, "+") ## Configure widgets self.label.grid(row = 0, column = 0, sticky=N+S+E+W) self.hscroll.grid(row = 1, column = 0, sticky=E+W) self.vscroll.grid(row = 0, column = 1, sticky=N+S) self.columnconfigure(0, weight=1) self.rowconfigure(0, weight=1) ## And display self.refresh() def refresh(self): """Bring the image in the frame and the scroll bars in line with the current values.""" self.image = self.generator_func(self.zoom, self.xint, self.yint) self.label["image"] = self.image ## Map x&y interval into unit interval for scroll bars. scroll_settings = ( (mapnum(self.xint[0], (0, self.isize[0] * self.zoom), (0, 1)), mapnum(self.xint[1], (0, self.isize[0] * self.zoom), (0, 1))), (mapnum(self.yint[0], (0, self.isize[1] * self.zoom), (0, 1)), mapnum(self.yint[1], (0, self.isize[1] * self.zoom), (0, 1)))) if debug > 5: print scroll_settings self.hscroll.set(*scroll_settings[0]) self.vscroll.set(*scroll_settings[1]) def reconfigure(self, event): print self.label["width"], self.label["height"], event.__dict__ self.xint[1] = min(self.xint[0]+event.width - self.labelborderwidth, int(self.isize[0]*self.zoom)) self.yint[1] = min(self.yint[0]+event.height - self.labelborderwidth, int(self.isize[1]*self.zoom)) self.refresh() def scmd(self, isy, type, num, what = None): """Takes input args, changes either xint or yint, and calls refresh to update the entire image.""" ## Figure out interval to modify and base image size to work off if isy: interval = self.yint int_range = self.isize[1] * self.zoom else: interval = self.xint int_range = self.isize[0] * self.zoom ## Figure out the width int_width = interval[1] - interval[0] ## Transform input num = float(num) if type == MOVETO: # num Describes the location of the low end of the slider interval[0] = mapnum(num, (0, 1), (0, int_range)) elif type == SCROLL: if what == "units": interval[0] += num else: assert what == "pages", what interval[0] += num * int_width if interval[0] < 0: interval[0] = 0 if interval[0] > int_range - int_width: interval[0] = int_range - int_width interval[0] = int(interval[0]) interval[1] = interval[0] + int_width assert type == MOVETO, type if debug > 5: print "yscroll" if isy else "xscroll", num, interval[0], interval[1] self.refresh() ## Room for optimization here; don't need to resize the whole image def gfunc_for_image(image, zoom, xint, yint): bbox = image.getbbox() isize = (bbox[2] - bbox[0], bbox[3] - bbox[1]) ssize = (isize[0] * zoom, isize[1] * zoom) if debug > 5: print zoom, xint, yint, isize, ssize ri = image.resize(ssize, Image.BILINEAR) ci = ri.crop((xint[0],yint[0],xint[1],yint[1])) return ImageTk.PhotoImage(ci) def IWFromFile(parent, file, starting_size = None): "Return an ImageWidget object based on an image on a file." baseimage = Image.open(file) (ulx, uly, lrx, lry) = baseimage.getbbox() return ImageWidget(parent, lambda z,xint,yint,i=baseimage: gfunc_for_image(i, z, xint, yint), (lrx - ulx, lry - uly), starting_size = starting_size) def IWFromImage(parent, img, starting_size = None): "Return an imageWidget object based on a PIL image passed in." (ulx, uly, lrx, lry) = img.getbbox() return ImageWidget(parent, lambda z,xint,yint,i=img: gfunc_for_image(i, z, xint, yint), (lrx - ulx, lry - uly), starting_size = starting_size) if __name__ == "__main__": root = Tk() root.resizable(True, True) root.bind("", lambda e, t="root": display_tag_and_size(t, e)) iw = IWFromFile(root, "test.tiff", starting_size = (200, 200)) print "Gridding iwidget." iw.grid(row=0,column=0,sticky=N+S+E+W) print "Configuring root row." root.rowconfigure(0, weight=1) print "Configuring root column." root.columnconfigure(0, weight=1) print "Mainlooping." iw.mainloop() From chohazel at gmail.com Sat Feb 7 18:03:07 2009 From: chohazel at gmail.com (chohazel at gmail.com) Date: Sat, 7 Feb 2009 15:03:07 -0800 (PST) Subject: MacPython 2.5 IDLE font size Message-ID: <541cb78b-52fd-4f71-9909-5649d4586558@v42g2000yqj.googlegroups.com> Hi, Is there a way to adjust the default font size in IDLE, in MacPython 2.5? The default now is too tiny. I have to use this version of MacPython. As far as I searched, I can't find how I do this. Thanks. From google at mrabarnett.plus.com Sat Feb 7 18:15:05 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 07 Feb 2009 23:15:05 +0000 Subject: Trouble with regular expressions In-Reply-To: References: Message-ID: <498E15F9.4050907@mrabarnett.plus.com> John Machin wrote: > On Feb 8, 1:37 am, MRAB wrote: >> LaundroMat wrote: >>> Hi, >>> I'm quite new to regular expressions, and I wonder if anyone here >>> could help me out. >>> I'm looking to split strings that ideally look like this: "Update: New >>> item (Household)" into a group. >>> This expression works ok: '^(Update:)?(.*)(\(.*\))$' - it returns >>> ("Update", "New item", "(Household)") >>> Some strings will look like this however: "Update: New item (item) >>> (Household)". The expression above still does its job, as it returns >>> ("Update", "New item (item)", "(Household)"). > > Not quite true; it actually returns > ('Update:', ' New item (item) ', '(Household)') > However ignoring the difference in whitespace, the OP's intention is > clear. Yours returns > ('Update:', ' New item ', '(item) (Household)') > The OP said it works OK, which I took to mean that the OP was OK with the extra whitespace, which can be easily stripped off. Close enough! > >>> It does not work however when there is no text in parentheses (eg >>> "Update: new item"). How can I get the expression to return a tuple >>> such as ("Update:", "new item", None)? >> You need to make the last group optional and also make the middle group >> lazy: r'^(Update:)?(.*?)(?:(\(.*\)))?$'. > > Why do you perpetuate the redundant ^ anchor? > The OP didn't say whether search() or match() was being used. With the ^ it doesn't matter. >> (?:...) is the non-capturing version of (...). > > Why do you use > (?:(subpattern))? > instead of just plain > (subpattern)? > ? > Oops, you're right. I was distracted by the \( and \)! :-) From vitaliyy at gmail.com Sat Feb 7 18:23:01 2009 From: vitaliyy at gmail.com (Vitaliy Yermolenko) Date: Sun, 8 Feb 2009 01:23:01 +0200 Subject: Python on TV-centric platforms Message-ID: Hi, Any chance to see Python to be ready for "Widget Development Kit (WDK) to third-party developers to create applications and services for viewing on TVs, or to move applications to the TV from the PC viewing environment" as on http://www.intelconsumerelectronics.com/Consumer-Electronics-3.0/Widget-Channel-Overview.aspx? Thoughts/ideas? WBR, Vitaliy. From sjmachin at lexicon.net Sat Feb 7 18:48:02 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 7 Feb 2009 15:48:02 -0800 (PST) Subject: Trouble with regular expressions References: Message-ID: <686660e5-b7a2-4529-9b92-ae1f73cd6663@z27g2000prd.googlegroups.com> On Feb 8, 10:15?am, MRAB wrote: > John Machin wrote: > > On Feb 8, 1:37 am, MRAB wrote: > >> LaundroMat wrote: > >>> Hi, > >>> I'm quite new to regular expressions, and I wonder if anyone here > >>> could help me out. > >>> I'm looking to split strings that ideally look like this: "Update: New > >>> item (Household)" into a group. > >>> This expression works ok: '^(Update:)?(.*)(\(.*\))$' - it returns > >>> ("Update", "New item", "(Household)") > >>> Some strings will look like this however: "Update: New item (item) > >>> (Household)". The expression above still does its job, as it returns > >>> ("Update", "New item (item)", "(Household)"). > > > Not quite true; it actually returns > > ? ? ('Update:', ' New item (item) ', '(Household)') > > However ignoring the difference in whitespace, the OP's intention is > > clear. Yours returns > > ? ? ('Update:', ' New item ', '(item) (Household)') > > The OP said it works OK, which I took to mean that the OP was OK with > the extra whitespace, which can be easily stripped off. Close enough! As I said, the whitespace difference [between what the OP said his regex did and what it actually does] is not the problem. The problem is that the OP's "works OK" included (item) in the 2nd group, whereas yours includes (item) in the 3rd group. > > >>> It does not work however when there is no text in parentheses (eg > >>> "Update: new item"). How can I get the expression to return a tuple > >>> such as ("Update:", "new item", None)? > >> You need to make the last group optional and also make the middle group > >> lazy: r'^(Update:)?(.*?)(?:(\(.*\)))?$'. > > > Why do you perpetuate the redundant ^ anchor? > > The OP didn't say whether search() or match() was being used. With the ^ > it doesn't matter. It *does* matter. re.search() is suboptimal; after failing at the first position, it's not smart enough to give up if the pattern has a front anchor. [win32, 2.6.1] C:\junk>\python26\python -mtimeit -s"import re;rx=re.compile ('^frobozz');txt=100 *'x'" "assert not rx.match(txt)" 1000000 loops, best of 3: 1.17 usec per loop C:\junk>\python26\python -mtimeit -s"import re;rx=re.compile ('^frobozz');txt=100 0*'x'" "assert not rx.match(txt)" 1000000 loops, best of 3: 1.17 usec per loop C:\junk>\python26\python -mtimeit -s"import re;rx=re.compile ('^frobozz');txt=100 *'x'" "assert not rx.search(txt)" 100000 loops, best of 3: 4.37 usec per loop C:\junk>\python26\python -mtimeit -s"import re;rx=re.compile ('^frobozz');txt=100 0*'x'" "assert not rx.search(txt)" 10000 loops, best of 3: 34.1 usec per loop Corresponding figures for 3.0 are 1.02, 1.02, 3.99, and 32.9 From nick at stinemates.org Sat Feb 7 18:56:45 2009 From: nick at stinemates.org (nick at stinemates.org) Date: Sat, 7 Feb 2009 15:56:45 -0800 Subject: Portable way to refer to the null device? In-Reply-To: References: Message-ID: <20090207235645.GA28442@beauTy.hsd1.ca.comcast.net> On Fri, Feb 06, 2009 at 07:32:20PM -0800, Roy Smith wrote: > I need to run a command using subprocess.Popen() and have stdin > connected to the null device. On unix, I would do: > > self.process = subprocess.Popen(argv, > env=new_env, > stdout=open(outfile, 'w'), > stderr=open(errfile, 'w'), > stdin=open('/dev/null') > ) > > but that's not portable to windows. Does Python have a portable way > to get a file object connected to the null device, regardless of what > operating system you're running on? I normally just implement my own object: class DevNull: def write(self, str): pass From nick at stinemates.org Sat Feb 7 19:09:48 2009 From: nick at stinemates.org (nick at stinemates.org) Date: Sat, 7 Feb 2009 16:09:48 -0800 Subject: simple web app, where to start In-Reply-To: <77e831100902062016q2d92ee3awb907baf47f477858@mail.gmail.com> References: <77e831100902062016q2d92ee3awb907baf47f477858@mail.gmail.com> Message-ID: <20090208000948.GB28442@beauTy.hsd1.ca.comcast.net> On Fri, Feb 06, 2009 at 09:16:02PM -0700, Vincent Davis wrote: > I have a simple script that takes a few input values and returns a csv file > and a few stats. If I wanted to host this on the web how would I. I have no > idea where to begin. If someone could point me in the right direction like > maybe a tutorial, tools I will need, functions..... I would appreciate it.I > know a little html but am not sure how to integrate python or know what > servers will handle it ..... > > Thanks > Vincent Davis I'd suggest CherryPy[1]. It's fairly welcoming to newbies, because the web server and the framework and bundled together. 1: http://www.cherrypy.org/ HTH, Nick From deets at nospam.web.de Sat Feb 7 19:32:00 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 08 Feb 2009 01:32:00 +0100 Subject: Python on TV-centric platforms In-Reply-To: References: Message-ID: <6v6ng1Fia9qkU1@mid.uni-berlin.de> Vitaliy Yermolenko schrieb: > Hi, > > Any chance to see Python to be ready for "Widget Development Kit (WDK) > to third-party developers to create applications and services for > viewing on TVs, or to move applications to the TV from the PC viewing > environment" as on > http://www.intelconsumerelectronics.com/Consumer-Electronics-3.0/Widget-Channel-Overview.aspx? > Thoughts/ideas? Given that the site shows not much more but marketing statements for otherwise technically unspecified systems (mentioning only a few buzzwords like JS & AJAX), I guess the answer is: sure python is ready. It is for example used in superkaramba, a widget-application even older than the OSX variant of the same concept. But unless you have a concrete system in mind, with a toolchain and actual WDK, the answer can't possibly be final. Diez From exarkun at divmod.com Sat Feb 7 19:34:04 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Sat, 7 Feb 2009 19:34:04 -0500 Subject: Portable way to refer to the null device? In-Reply-To: <20090207235645.GA28442@beauTy.hsd1.ca.comcast.net> Message-ID: <20090208003404.12853.378576398.divmod.quotient.7217@henry.divmod.com> On Sat, 7 Feb 2009 15:56:45 -0800, nick at stinemates.org wrote: >On Fri, Feb 06, 2009 at 07:32:20PM -0800, Roy Smith wrote: >> I need to run a command using subprocess.Popen() and have stdin >> connected to the null device. On unix, I would do: >> >> self.process = subprocess.Popen(argv, >> env=new_env, >> stdout=open(outfile, 'w'), >> stderr=open(errfile, 'w'), >> stdin=open('/dev/null') >> ) >> >> but that's not portable to windows. Does Python have a portable way >> to get a file object connected to the null device, regardless of what >> operating system you're running on? > >I normally just implement my own object: > >class DevNull: > def write(self, str): > pass I bet this won't work. It needs to be a "real" file - have a file descriptor or a handle or something. Instead, try opening os.devnull. Jean-Paul From terry.yinzhe at gmail.com Sat Feb 7 19:51:15 2009 From: terry.yinzhe at gmail.com (Terry) Date: Sat, 7 Feb 2009 16:51:15 -0800 (PST) Subject: Python3.0 has more duplication in source code than Python2.5 References: <498D3A04.60503@v.loewis.de> <6v58gpFi7nnvU1@mid.uni-berlin.de> Message-ID: On 2?8?, ??12?20?, Benjamin Peterson wrote: > Terry gmail.com> writes: > > > On 2?7?, ??7?10?, "Diez B. Roggisch" wrote: > > > Do you by any chance have a few examples of these? There is a lot of > > > idiomatic code in python to e.g. acquire and release the GIL or doing > > > refcount-stuff. If that happens to be done with rather generic names as > > > arguments, I can well imagine that as being the cause. > > Starting at line 5119 of D:\DOWNLOADS\Python-3.0\Python\Python-ast.c > > This isn't really fair because Python-ast.c is auto generated. ;) Oops! I don't know that! Then the analysis will not be valid, since too many duplications are from there. From terry.yinzhe at gmail.com Sat Feb 7 20:12:46 2009 From: terry.yinzhe at gmail.com (Terry) Date: Sat, 7 Feb 2009 17:12:46 -0800 (PST) Subject: Python3.0 has more duplication in source code than Python2.5 References: <498D3A04.60503@v.loewis.de> <6v58gpFi7nnvU1@mid.uni-berlin.de> Message-ID: On 2?8?, ??8?51?, Terry wrote: > On 2?8?, ??12?20?, Benjamin Peterson wrote: > > > Terry gmail.com> writes: > > > > On 2?7?, ??7?10?, "Diez B. Roggisch" wrote: > > > > Do you by any chance have a few examples of these? There is a lot of > > > > idiomatic code in python to e.g. acquire and release the GIL or doing > > > > refcount-stuff. If that happens to be done with rather generic names as > > > > arguments, I can well imagine that as being the cause. > > > Starting at line 5119 of D:\DOWNLOADS\Python-3.0\Python\Python-ast.c > > > This isn't really fair because Python-ast.c is auto generated. ;) > > Oops! I don't know that! Then the analysis will not be valid, since > too many duplications are from there. Hey! I have to say sorry because I found I made a mistake. Because Python- ast.c is auto-generated and shouldn't be counted here, the right duplication rate of Python3.0 is very small (5%). And I found the duplications are quite trivial, I wound not say that all of them are acceptable, but certainly not a strong enough evident for code quality. I have made the same analysis to some commercial source code, the dup60 rate is quite often significantly larger than 15%. From google at mrabarnett.plus.com Sat Feb 7 20:38:44 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sun, 08 Feb 2009 01:38:44 +0000 Subject: Trouble with regular expressions In-Reply-To: <686660e5-b7a2-4529-9b92-ae1f73cd6663@z27g2000prd.googlegroups.com> References: <686660e5-b7a2-4529-9b92-ae1f73cd6663@z27g2000prd.googlegroups.com> Message-ID: <498E37A4.5020400@mrabarnett.plus.com> John Machin wrote: > On Feb 8, 10:15 am, MRAB wrote: >> John Machin wrote: >>> On Feb 8, 1:37 am, MRAB wrote: >>>> LaundroMat wrote: >>>>> Hi, >>>>> I'm quite new to regular expressions, and I wonder if anyone here >>>>> could help me out. >>>>> I'm looking to split strings that ideally look like this: "Update: New >>>>> item (Household)" into a group. >>>>> This expression works ok: '^(Update:)?(.*)(\(.*\))$' - it returns >>>>> ("Update", "New item", "(Household)") >>>>> Some strings will look like this however: "Update: New item (item) >>>>> (Household)". The expression above still does its job, as it returns >>>>> ("Update", "New item (item)", "(Household)"). >>> Not quite true; it actually returns >>> ('Update:', ' New item (item) ', '(Household)') >>> However ignoring the difference in whitespace, the OP's intention is >>> clear. Yours returns >>> ('Update:', ' New item ', '(item) (Household)') >> The OP said it works OK, which I took to mean that the OP was OK with >> the extra whitespace, which can be easily stripped off. Close enough! > > As I said, the whitespace difference [between what the OP said his > regex did and what it actually does] is not the problem. The problem > is that the OP's "works OK" included (item) in the 2nd group, whereas > yours includes (item) in the 3rd group. > Ugh, right again! That just shows what happens when I try to post while debugging! :-) >>>>> It does not work however when there is no text in parentheses (eg >>>>> "Update: new item"). How can I get the expression to return a tuple >>>>> such as ("Update:", "new item", None)? >>>> You need to make the last group optional and also make the middle group >>>> lazy: r'^(Update:)?(.*?)(?:(\(.*\)))?$'. >>> Why do you perpetuate the redundant ^ anchor? >> The OP didn't say whether search() or match() was being used. With the ^ >> it doesn't matter. > > It *does* matter. re.search() is suboptimal; after failing at the > first position, it's not smart enough to give up if the pattern has a > front anchor. > > [win32, 2.6.1] > C:\junk>\python26\python -mtimeit -s"import re;rx=re.compile > ('^frobozz');txt=100 > *'x'" "assert not rx.match(txt)" > 1000000 loops, best of 3: 1.17 usec per loop > > C:\junk>\python26\python -mtimeit -s"import re;rx=re.compile > ('^frobozz');txt=100 > 0*'x'" "assert not rx.match(txt)" > 1000000 loops, best of 3: 1.17 usec per loop > > C:\junk>\python26\python -mtimeit -s"import re;rx=re.compile > ('^frobozz');txt=100 > *'x'" "assert not rx.search(txt)" > 100000 loops, best of 3: 4.37 usec per loop > > C:\junk>\python26\python -mtimeit -s"import re;rx=re.compile > ('^frobozz');txt=100 > 0*'x'" "assert not rx.search(txt)" > 10000 loops, best of 3: 34.1 usec per loop > > Corresponding figures for 3.0 are 1.02, 1.02, 3.99, and 32.9 > On my PC the numbers for Python 2.6 are: C:\Python26>python -mtimeit -s"import re;rx=re.compile('^frobozz');txt=100*'x'" "assert not rx.match(txt)" 1000000 loops, best of 3: 1.02 usec per loop C:\Python26>python -mtimeit -s"import re;rx=re.compile('^frobozz');txt=1000*'x'" "assert not rx.match(txt)" 1000000 loops, best of 3: 1.04 usec per loop C:\Python26>python -mtimeit -s"import re;rx=re.compile('^frobozz');txt=100*'x'" "assert not rx.search(txt)" 100000 loops, best of 3: 3.69 usec per loop C:\Python26>python -mtimeit -s"import re;rx=re.compile('^frobozz');txt=1000*'x'" "assert not rx.search(txt)" 10000 loops, best of 3: 28.6 usec per loop I'm currently working on the re module and I've fixed that problem: C:\Python27>python -mtimeit -s"import re;rx=re.compile('^frobozz');txt=100*'x'" "assert not rx.match(txt)" 1000000 loops, best of 3: 1.28 usec per loop C:\Python27>python -mtimeit -s"import re;rx=re.compile('^frobozz');txt=1000*'x'" "assert not rx.match(txt)" 1000000 loops, best of 3: 1.23 usec per loop C:\Python27>python -mtimeit -s"import re;rx=re.compile('^frobozz');txt=100*'x'" "assert not rx.search(txt)" 1000000 loops, best of 3: 1.21 usec per loop C:\Python27>python -mtimeit -s"import re;rx=re.compile('^frobozz');txt=1000*'x'" "assert not rx.search(txt)" 1000000 loops, best of 3: 1.21 usec per loop Hmm. Needs more tweaking... From yantao at telus.com Sat Feb 7 20:46:15 2009 From: yantao at telus.com (Peter Pei) Date: Sun, 08 Feb 2009 01:46:15 GMT Subject: sortable table in python 3.0 Message-ID: In one of my program, I used something called MultiColumnList, which is one of the sortable table widgets done in python. However 3.0 sort is different. I googled and found couple of other implementations, but all in python 3.0 -. Does anyone know any solution in 3.0? or anything that has already been upgraded to 3.0? Thanks. From vincent at vincentdavis.net Sat Feb 7 21:39:36 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Sat, 7 Feb 2009 19:39:36 -0700 Subject: simple web app, where to start In-Reply-To: <20090208000948.GB28442@beauTy.hsd1.ca.comcast.net> References: <77e831100902062016q2d92ee3awb907baf47f477858@mail.gmail.com> <20090208000948.GB28442@beauTy.hsd1.ca.comcast.net> Message-ID: <77e831100902071839r48806b22x26cff29781b412f1@mail.gmail.com> Thanks http://www.cherrypy.org/ looks like a good and simple option. Thanks Vincent Davis On Sat, Feb 7, 2009 at 5:09 PM, wrote: > On Fri, Feb 06, 2009 at 09:16:02PM -0700, Vincent Davis wrote: > > I have a simple script that takes a few input values and returns a csv > file > > and a few stats. If I wanted to host this on the web how would I. I have > no > > idea where to begin. If someone could point me in the right direction > like > > maybe a tutorial, tools I will need, functions..... I would appreciate > it.I > > know a little html but am not sure how to integrate python or know what > > servers will handle it ..... > > > > Thanks > > Vincent Davis > > I'd suggest CherryPy[1]. It's fairly welcoming to newbies, because the > web server and the framework and bundled together. > > 1: http://www.cherrypy.org/ > > HTH, > Nick > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From vincent at vincentdavis.net Sat Feb 7 21:45:10 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Sat, 7 Feb 2009 19:45:10 -0700 Subject: MacPython 2.5 IDLE font size In-Reply-To: <541cb78b-52fd-4f71-9909-5649d4586558@v42g2000yqj.googlegroups.com> References: <541cb78b-52fd-4f71-9909-5649d4586558@v42g2000yqj.googlegroups.com> Message-ID: <77e831100902071845n7f3524abh692ea6b5fa135ae4@mail.gmail.com> There is a option menu in idle but you may not be able to see it. Try launching idle via terminal. For me it was located /Library/Frameworks/Python/Versions/Current/bin/idle2.5 When I did this I had the option menu, I guess this is a known bug. I assume there is a font option once you get the menu. Vincent Davis On Sat, Feb 7, 2009 at 4:03 PM, wrote: > Hi, > Is there a way to adjust the default font size in IDLE, in MacPython > 2.5? The default now is too tiny. > I have to use this version of MacPython. As far as I searched, I can't > find how I do this. > Thanks. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From wuwei23 at gmail.com Sat Feb 7 22:15:28 2009 From: wuwei23 at gmail.com (alex23) Date: Sat, 7 Feb 2009 19:15:28 -0800 (PST) Subject: Python on TV-centric platforms References: Message-ID: On Feb 8, 9:23?am, Vitaliy Yermolenko wrote: > Any chance to see Python to be ready for "Widget Development Kit (WDK) > to third-party developers to create applications and services for > viewing on TVs [...] The excellent XBMC[1] has had Python support for years. 1: http://xbmc.org/ From rantingrick at gmail.com Sat Feb 7 22:58:41 2009 From: rantingrick at gmail.com (rantingrick) Date: Sat, 7 Feb 2009 19:58:41 -0800 (PST) Subject: Best 3d graphics kit for CAD program??? Message-ID: I want to build a 3D CAD visualization program with Python. Now before you say this is not possible with Python here me out :) I know OpenGL is probably my best bet BUT i want something a little higher level than that. I am not ready for OpenGL yet. I would like a kit that is just above OpenGL and abstracts away all the finer details, but not too much higher. VPython is a great kit but it is way too high level for what i want. Here is a list of kits i am currently looking at so if anybody can offer suggestions i would very much like the information. Most of these are dedicated game engines but this is all i can find Panda 3D OGRE Soya 3D VTK Cystal Space CG Kit SciPy Thanks Guy's From rNOSPAMon at flownet.com Sun Feb 8 02:08:29 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Sat, 07 Feb 2009 23:08:29 -0800 Subject: WebError documentation? References: <498de947$0$24412$426a74cc@news.free.fr> Message-ID: In article <498de947$0$24412$426a74cc at news.free.fr>, Bruno Desthuilliers wrote: > Ron Garret a ?crit : > > In article , > > Chris Rebert wrote: > > > >> On Thu, Feb 5, 2009 at 12:52 PM, Ron Garret wrote: > >>> Is there any? Where is it? Extensive Googling has proven fruitless. > >> It's not a standard Python exception. A third-party library you're > >> using must be raising it. Check the exception traceback. > > > > I see I did not make myself clear. > > Now *that* is an understatement... > > > I meant the Python software package > > called "weberror", not a generic web error. > > > > http://pypi.python.org/pypi/WebError > > Google is your friend: > http://bel-epa.com/docs/thirdparty/weberror/ Thanks! rg From henryar2 at gmail.com Sun Feb 8 04:10:12 2009 From: henryar2 at gmail.com (Henry Read) Date: Sun, 8 Feb 2009 17:10:12 +0800 Subject: Python3.0 has more duplication in source code than Python2.5 In-Reply-To: References: <498D3A04.60503@v.loewis.de> <6v58gpFi7nnvU1@mid.uni-berlin.de> Message-ID: I don't think code duplication rate has strong relationship towards code quality. On Sun, Feb 8, 2009 at 9:12 AM, Terry wrote: > On 2?8?, ??8?51?, Terry wrote: > > On 2?8?, ??12?20?, Benjamin Peterson wrote: > > > > > Terry gmail.com> writes: > > > > > > On 2?7?, ??7?10?, "Diez B. Roggisch" wrote: > > > > > Do you by any chance have a few examples of these? There is a lot > of > > > > > idiomatic code in python to e.g. acquire and release the GIL or > doing > > > > > refcount-stuff. If that happens to be done with rather generic > names as > > > > > arguments, I can well imagine that as being the cause. > > > > Starting at line 5119 of D:\DOWNLOADS\Python-3.0\Python\Python-ast.c > > > > > This isn't really fair because Python-ast.c is auto generated. ;) > > > > Oops! I don't know that! Then the analysis will not be valid, since > > too many duplications are from there. > > Hey! > > I have to say sorry because I found I made a mistake. Because Python- > ast.c is auto-generated and shouldn't be counted here, the right > duplication rate of Python3.0 is very small (5%). > And I found the duplications are quite trivial, I wound not say that > all of them are acceptable, but certainly not a strong enough evident > for code quality. > > I have made the same analysis to some commercial source code, the > dup60 rate is quite often significantly larger than 15%. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From zaheer.agadi at gmail.com Sun Feb 8 05:38:33 2009 From: zaheer.agadi at gmail.com (zaheer.agadi at gmail.com) Date: Sun, 8 Feb 2009 02:38:33 -0800 (PST) Subject: Internal Server error Message-ID: HI I am getting an internal server error while trying get response from a server following is my code def getDetails(self,username,password): urllib = urllib2.Request idurl="https://some.server.com/" port=8181 conn = httplib.HTTPSConnection("some.server.com/",8181); conn.debuglevel = 1 username = "userone" password = "aaaa" Auth = "Basic" + ecnodeURL(self,username, password) url= "https://some.network.com:8181/main/folder/persons/" + username + "/attributes/atrone" print url headers = {"Authorization": Auth,"Accept": "application/json"} conn.request("GET", url,{},headers) response = conn.getresponse() data = response.read() print response.reason print response. What I am getting as response https://some.server.com:8181/main/folder/persons/userone/attributes/atrone C:\Python26\lib\site-packages\httplib2\__init__.py:29: DeprecationWarning: the md5 module is deprecated; use hashlib instead import md5 C:\Python26\lib\site-packages\httplib2\__init__.py:44: DeprecationWarning: the sha module is deprecated; use the hashlib module instead import sha send: 'GET https://some.server.com:8181/main/folder/persons/userone/attributes/atrone HTTP/1.1\r\nHost: /some.server.com:8181\r\nAccept-Encoding: identity\r \nAccept: application/json\r\nAuthorization: BasicU3RvcmFnZUVncjA1OA== \r\n\r\n' reply: 'HTTP/1.1 500 Internal Server Error\r\n' header: Content-Type: text/html header: Content-Language: header: Content-Length: 1299 header: Date: Sun, 08 Feb 2009 10:25:52 GMT header: Connection: close Sun Java System Application Server 9.1_02 - Error report

HTTP Status 500 -

type Exception report

message

descriptionThe server encountered an internal error () that prevented it from fulfilling this request.

exception

java.util.NoSuchElementException

note The full stack traces of the exception and its root causes are available in the Sun Java System Application Server 9.1_02 logs.


Sun Java System Application Server 9.1_02

Internal Server Error Thanks alot From bblais at bryant.edu Sun Feb 8 05:42:28 2009 From: bblais at bryant.edu (Brian Blais) Date: Sun, 8 Feb 2009 05:42:28 -0500 Subject: MacPython 2.5 IDLE font size In-Reply-To: <77e831100902071845n7f3524abh692ea6b5fa135ae4@mail.gmail.com> References: <541cb78b-52fd-4f71-9909-5649d4586558@v42g2000yqj.googlegroups.com> <77e831100902071845n7f3524abh692ea6b5fa135ae4@mail.gmail.com> Message-ID: <01AD6DB2-2750-43CC-AD2B-BA798A11BA48@bryant.edu> Hello, > On Sat, Feb 7, 2009 at 4:03 PM, wrote: > Hi, > Is there a way to adjust the default font size in IDLE, in MacPython > 2.5? The default now is too tiny. > I have to use this version of MacPython. As far as I searched, I can't > find how I do this. It is indeed a bug that the options menu doesn't show. What I did was to manually edit the file: /Library/Frameworks/Python.framework/Versions/Current/lib/python2.5/ idlelib/config-main.def to include the lines: font= monaco font-size= 13 font-bold= 0 (can't remember what the default was). bb -- Brian Blais bblais at bryant.edu http://web.bryant.edu/~bblais -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at nospam.web.de Sun Feb 8 06:09:49 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 08 Feb 2009 12:09:49 +0100 Subject: Internal Server error In-Reply-To: References: Message-ID: <6v7srtFil09hU1@mid.uni-berlin.de> zaheer.agadi at gmail.com schrieb: > HI > I am getting an internal server error while trying get response from a > server following is my code > > > def getDetails(self,username,password): > urllib = urllib2.Request > idurl="https://some.server.com/" > port=8181 > conn = httplib.HTTPSConnection("some.server.com/",8181); > conn.debuglevel = 1 > username = "userone" > password = "aaaa" > Auth = "Basic" + ecnodeURL(self,username, password) > url= "https://some.network.com:8181/main/folder/persons/" + > username + "/attributes/atrone" > print url > headers = {"Authorization": Auth,"Accept": "application/json"} > conn.request("GET", url,{},headers) > response = conn.getresponse() > data = response.read() > print response.reason > print response. > > > What I am getting as response > > https://some.server.com:8181/main/folder/persons/userone/attributes/atrone > C:\Python26\lib\site-packages\httplib2\__init__.py:29: > DeprecationWarning: the md5 module is deprecated; use hashlib instead > import md5 > C:\Python26\lib\site-packages\httplib2\__init__.py:44: > DeprecationWarning: the sha module is deprecated; use the hashlib > module instead > import sha > send: 'GET https://some.server.com:8181/main/folder/persons/userone/attributes/atrone > HTTP/1.1\r\nHost: /some.server.com:8181\r\nAccept-Encoding: identity\r > \nAccept: application/json\r\nAuthorization: BasicU3RvcmFnZUVncjA1OA== > \r\n\r\n' > reply: 'HTTP/1.1 500 Internal Server Error\r\n' > header: Content-Type: text/html > header: Content-Language: > header: Content-Length: 1299 > header: Date: Sun, 08 Feb 2009 10:25:52 GMT > header: Connection: close > www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">Sun > Java System Application Server 9.1_02 - Error report

HTTP Status 500 - h1>

type Exception report

message p>

descriptionThe server encountered an internal error () > that prevented it from fulfilling this request.

exception >

java.util.NoSuchElementException

note The > full stack traces of the exception and its root causes are available > in the Sun Java System Application Server 9.1_02 logs.


>

Sun Java System Application Server 9.1_02

> Internal Server Error > What do you expect us to do about this? That has nothing todo with python, what you do is that you don't speak the right way with the server in question, producing a stacktrace. But nobody here knows *how* to talk to that machine. O Diez From mail at joaomoreno.com Sun Feb 8 06:18:05 2009 From: mail at joaomoreno.com (mail at joaomoreno.com) Date: Sun, 8 Feb 2009 03:18:05 -0800 (PST) Subject: BaseHTTPRequestHandler freezes while writing to self.wfile after installing Python 3.0 References: Message-ID: On Feb 7, 3:55?pm, m... at joaomoreno.com wrote: > Hey guys, > > I'm starting to lose my head with this one. > > I have a class that extends BaseHTTPRequestHandler. It works fine on > Python 2.5. And yesterday I was curious and decided to install Python > 3.0 on my Mac (I followed this tutorial, to be sure I wasn't messing > things up:http://farmdev.com/thoughts/66/python-3-0-on-mac-os-x-alongside-2-6-2... > ). I tried my application on Python 3.0 and the code just freezed on > this line: > > self.wfile.write(f.read()) > > I searched and got to this bughttp://bugs.python.org/issue3826. I > couldn't understand if there's already a fix for that. But, the > strangest thing was that, when I tried my application on 2.5, it > started freezing on the same spot! I then removed everything I > installed from 3.0, fixed the paths, and it still gives me the error. > I don't know what else to do. > > The app works fine on 2.5, because I tried it on another computer. > > Thanks for your help. I'm sorry, it seems to have been a weird setting between routers (mac <-> router <-> router <-> ISP) here at home. Small files ( < 100kB ) were served with no problem at all, but larger files got stuck. I found it out after formatting my mac, and realized that it was still happening. I tried to remove on of the routers out of the way and it sure works now. The real reason that caused it, and why it worked before and suddently stopped working after (coincidently, for sure) installing Python 3.0 is still incognito for me. From zaheer.agadi at gmail.com Sun Feb 8 06:20:09 2009 From: zaheer.agadi at gmail.com (zaheer.agadi at gmail.com) Date: Sun, 8 Feb 2009 03:20:09 -0800 (PST) Subject: Internal Server error References: <6v7srtFil09hU1@mid.uni-berlin.de> Message-ID: <4cb170df-2786-42fe-97e5-f243ce6401b0@o2g2000prl.googlegroups.com> On Feb 8, 4:09?pm, "Diez B. Roggisch" wrote: > zaheer.ag... at gmail.com schrieb: > > > > > HI > > I am getting an internal server error while trying get response from a > > server following is my code > > > ? ?def getDetails(self,username,password): > > ? ? urllib = urllib2.Request > > ? ? idurl="https://some.server.com/" > > ? ? port=8181 > > ? ? conn = httplib.HTTPSConnection("some.server.com/",8181); > > ? ? conn.debuglevel ?= 1 > > ? ? username = "userone" > > ? ? password = "aaaa" > > ? ? Auth = "Basic" + ecnodeURL(self,username, password) > > ? ? url= "https://some.network.com:8181/main/folder/persons/" + > > username + "/attributes/atrone" > > ? ? print url > > ? ? headers = {"Authorization": Auth,"Accept": "application/json"} > > ? ? conn.request("GET", url,{},headers) > > ? ? response = conn.getresponse() > > ? ? data = response.read() > > ? ? print response.reason > > ? ? print response. > > > What I am getting as response > > >https://some.server.com:8181/main/folder/persons/userone/attributes/a... > > C:\Python26\lib\site-packages\httplib2\__init__.py:29: > > DeprecationWarning: the md5 module is deprecated; use hashlib instead > > ? import md5 > > C:\Python26\lib\site-packages\httplib2\__init__.py:44: > > DeprecationWarning: the sha module is deprecated; use the hashlib > > module instead > > ? import sha > > send: 'GEThttps://some.server.com:8181/main/folder/persons/userone/attributes/a... > > HTTP/1.1\r\nHost: /some.server.com:8181\r\nAccept-Encoding: identity\r > > \nAccept: application/json\r\nAuthorization: BasicU3RvcmFnZUVncjA1OA== > > \r\n\r\n' > > reply: 'HTTP/1.1 500 Internal Server Error\r\n' > > header: Content-Type: text/html > > header: Content-Language: > > header: Content-Length: 1299 > > header: Date: Sun, 08 Feb 2009 10:25:52 GMT > > header: Connection: close > > >www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">Sun > > Java System Application Server 9.1_02 - Error report

HTTP Status 500 - > h1>

type Exception report

message > p>

descriptionThe server encountered an internal error () > > that prevented it from fulfilling this request.

exception > >

java.util.NoSuchElementException

note The > > full stack traces of the exception and its root causes are available > > in the Sun Java System Application Server 9.1_02 logs.


>>

Sun Java System Application Server 9.1_02

> > Internal Server Error > > > > What do you expect us to do about this? That has nothing todo with > python, what you do is that you don't speak the right way with the > server in question, producing a stacktrace. But nobody here knows *how* > to talk to that machine. O > > Diez Thanks, I know there is something on the wrong side, when it says java.util.NoSuchElementException i thought something wrong with setting values I just wanted you guys to point me out there is something wrong with the code I have written I am not very familiar with Python the same work for java works fine. I wanted to know if I am setting the headers correctly, getting the response correctly are there any better ways of encoding the url Over all Does the code look ok...? From jstroud at mbi.ucla.edu Sun Feb 8 06:27:37 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Sun, 08 Feb 2009 03:27:37 -0800 Subject: TkInter: Problem with propagation of resize events through geometry manager hierarchy? In-Reply-To: References: Message-ID: Randy Smith wrote: > The cropping and scrolling works fine. But when I try to add > responding to resize events, I get into trouble. Specifically: > * When I naively change the size of the image shown to be borderwidth > less than the size indicated in the configure event, the size of the > image shown grows gradually but inexorably when I start the test > app. (Sorta scary, actually :-}) > * When I fiddle a bit to figure out what the actual difference in size > is between the Configure event and the image that can be displayed, > I get a vibrating, jagged display of the image. > > Investigation suggests that multiple configure events are hitting the > label in response to each user resize with different sizes. I'm > guessing that when I resize the image in response to those different > events, that creates new resize events propagating through the window > manager hierarchy, which creates new configure events, which means my > handler changes the image size, which ... you get the idea. I can't test your code because I don't have the test image and for some reason it does not recognize a tiff of my own. But, just glancing at your code, it looks like a quick-fix would be to set self.zoom to a sentinel at the end of refresh() and return 'break' at the top of the methods that use self.zoom if it is said sentinel value (e.g. "if self.zoom == WHATEVER_SENTINEL: return 'break'). You may also want to return 'break' for event responders that should terminate the event chain. This is a general technique to stop a lot of unwanted event propagation. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com From nytrokiss at gmail.com Sun Feb 8 06:53:07 2009 From: nytrokiss at gmail.com (James Matthews) Date: Sun, 8 Feb 2009 13:53:07 +0200 Subject: simple web app, where to start In-Reply-To: <77e831100902062016q2d92ee3awb907baf47f477858@mail.gmail.com> References: <77e831100902062016q2d92ee3awb907baf47f477858@mail.gmail.com> Message-ID: <8a6b8e350902080353s51fc9d1bmc9b5e56f79509a7d@mail.gmail.com> I use Django for all simple apps and it works great! On Sat, Feb 7, 2009 at 6:16 AM, Vincent Davis wrote: > I have a simple script that takes a few input values and returns a csv file > and a few stats. If I wanted to host this on the web how would I. I have no > idea where to begin. If someone could point me in the right direction like > maybe a tutorial, tools I will need, functions..... I would appreciate it.I know a little html but am not sure how to integrate python or know what > servers will handle it ..... > > Thanks > Vincent Davis > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- http://www.goldwatches.com/ http://www.jewelerslounge.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From geert.discussions at gmail.com Sun Feb 8 07:07:40 2009 From: geert.discussions at gmail.com (Geert Vancompernolle) Date: Sun, 08 Feb 2009 13:07:40 +0100 Subject: Path question In-Reply-To: <6urjrhFgvif8U1@mid.uni-berlin.de> References: <6urjrhFgvif8U1@mid.uni-berlin.de> Message-ID: <498ECB0C.5050705@gmail.com> Diez B. Roggisch wrote: > Geert Vancompernolle schrieb: >> Hi, >> >> I have the following path construction: >> >> ./src/__init__.py >> /main.py >> /modules/__init__.py >> /application.py >> /ui/__init__.py >> /mainwindow/__init__.py >> /mainwindow.py >> >> Now I want to call the method 'MainWindow' in the module >> 'mainwindow', from the module 'application'. >> >> I'm having the following import statement in 'applications.py': >> >> from .. ui.mainwindow.mainwindow import MainWindow >> >> That doesn't work. I've also tried many other combinations like from >> ..ui.mainwindow... but none of them work. >> >> I always get the following error: >> >> "Attempted relative import beyond toplevel package" >> >> How can I import the method 'MainWindow' from 'mainwindow' into >> 'application', using the explicit relative import rules? >> >> Or is there a better way to do this? >> > > Rename "src" to "myapp", and start main.py from above that. That > should work. > > > > Diez > -- > http://mail.python.org/mailman/listinfo/python-list > That trick did it, thanks! But I have one more unclarity about relative import rules. Here , one can find an explanation about modules in the official Python 2.6.1 documentation. In that article, there's an example of importing relative packages (in the section "Packages"). I see the following examples: from . import echo from .. import formats from ..filters import equalizer Applying that mechanism on my application, I'm using the following construction (see my initial email): "from .. ui.mainwindow.mainwindow import MainWindow" But using "from ..ui.mainwindow.mainwindow import MainWindow" seems to be giving exactly the same result (mind the lacking space between ".." and "ui"). So, what's the difference (if there is one) between "from .. ui.mainwin..." and "from ..ui.mainwin..." (again, mind the difference in space)? I guess there's a difference, otherwise it would not be given as an example in the Python documentation. But then, why is the application (at first sight) behaving the same and also working fine? -- Best rgds, Geert ________________________________________________ *Use EcoCho : environmentally friendly search the internet!* From gil.shinar at gmail.com Sun Feb 8 07:22:25 2009 From: gil.shinar at gmail.com (gil.shinar at gmail.com) Date: Sun, 8 Feb 2009 04:22:25 -0800 (PST) Subject: Process crash with no reason References: <30c13ac1-0ad0-4825-8d5c-301d505e6b66@p2g2000prn.googlegroups.com> Message-ID: <6732e3c4-8fcc-45c8-8e62-aea7eb64d942@j1g2000yqi.googlegroups.com> On Jan 28, 7:37?pm, Philip Semanchuk wrote: > On Jan 28, 2009, at 12:12 PM, gil.shi... at gmail.com wrote: > > > On Jan 27, 5:59 pm, Philip Semanchuk wrote: > >> On Jan 27, 2009, at 10:34 AM, gil.shi... at gmail.com wrote: > >>> On Jan 27, 2:10 pm, Tim Golden wrote: > >>>> Then how are you interacting with Sybase? > > >>> I'm using python's functions to run sybase sql commands. > > >> Can you give a short code sample? I'm unaware of how one would use ? > >> the > >> standard Python library to talk to Sybase, unless Sybase has a raw > >> socket interface or some such. > > > First of all I have found the following python's import: > > > import Sybase > > This isn't part of the Python standard library. It's a 3rd party ? > module -- exactly what we were looking for. > > Personally, I think this (or another C++ or C-based 3rd party module ? > that you use heavily) is your prime suspect for the origin of the ? > crashes you're having. That's not because I think the people who wrote ? > or maintain it are bad or lazy coders. In fact, it's no reflection on ? > their skill at all. It's just that a lot more people have used and ? > exercised the Python standard library modules. A 3rd party module like ? > this one will be less well-used and therefore less well-tested and ? > therefore more likely to contain a bug that causes a crash. > > That said, I don't know how to advise you to proceed from here. You ? > could perhaps turn on logging at the database level. I know Postgres, ? > for instance, can write very detailed logs and so if you get a crash ? > at 9:33:22 you can look in the log and see what was happening at that ? > time. If you get several crashes and they all happen when a certain ? > SQL statement is being executed, that's probably the culprit. > > You could also alter the Sybase module to add logging using Python's ? > logging module. Who knows, it might already be there, waiting to be ? > turned on with a switch. > > But I'm jumping the gun a little. As I said, it could be this module ? > or another that's causing your problem. It's a lot easier to cause a ? > hard crash using C or C++ than it is using pure Python, so pure Python ? > modules would be lower on my list of suspects. Enumerate all of the ? > modules you're using and find out where they come from. Any of them ? > that are not in the standard library and are not written in pure ? > Python should top your list of suspects. > > Good luck > Philip Thanks a lot and sorry for the late response. My main suspect is the CherryPy. I'm still investigating it. Gil From loredana.pier at gmail.com Sun Feb 8 07:46:43 2009 From: loredana.pier at gmail.com (loredana.pier at gmail.com) Date: Sun, 8 Feb 2009 04:46:43 -0800 (PST) Subject: The fastest way to convert a long list of date Message-ID: If I want to convert a single date format I can do: import datetime, dateutil.parser d = dateutil.parser.parse('2008-09-26) print d.strftime('%A %d, %b %y' ) but if I want convert a long list of time how can do it in the fastest way? for example: from ['2008-09-26?, '2008-09-28?, '2008-09-29?,.............] to [?26 sep?,?28 sep?,?29 sep?,................] Thank you Loredana From Pat at junk.net Sun Feb 8 07:51:32 2009 From: Pat at junk.net (Pat) Date: Sun, 08 Feb 2009 07:51:32 -0500 Subject: len() References: <20090131201648.201b6ed5@usenot.de> Message-ID: Gabriel Genellina wrote: > En Wed, 04 Feb 2009 12:38:04 -0200, Pat escribi?: >> Andreas Waldenburger wrote: >>> On Sat, 31 Jan 2009 13:27:02 -0500 Pat wrote: >>>> Tobiah wrote: >>>>> Just out of curiosity, why was len() made to >>>>> be it's own function? I often find myself >>>>> typing things like my_list.len before I >>>>> catch myself. > >>>> I'm surprised that no one responded to that question. >>>> >>> Huh? Gabriel Genellina replied about 46 minutes after it was posted. >>> Might it be that your newsserver is a bit laggy? >> >> Might be laggy. Who knows. >> Why didn't you answer the len() question? > > Why should he? Why didn't you look for the answer yourself, after being > told that it existed? Why do you expect *us* to repeat ourselves again > and again? Don't be so lazy... > Why do *us* feel obligated to respond? Is there a gun pointed at your heads forcing to giving a bellicose responses? Who is this *us*? A secret society? An exclusive club? New rule: If you don't like a question or a post, simply ignore it. We don't enjoy your snarky repartee. From Pat at junk.net Sun Feb 8 07:54:13 2009 From: Pat at junk.net (Pat) Date: Sun, 08 Feb 2009 07:54:13 -0500 Subject: len() References: <20090131201648.201b6ed5@usenot.de> Message-ID: Terry Reedy wrote: > Pat wrote: >> Andreas Waldenburger wrote: >>> On Sat, 31 Jan 2009 13:27:02 -0500 Pat wrote: >>> >>>> Tobiah wrote: >>>>> Just out of curiosity, why was len() made to >>>>> be it's own function? I often find myself >>>>> typing things like my_list.len before I >>>>> catch myself. >>>>> >>>>> Thanks, >>>>> >>>>> Toby >>>> I'm surprised that no one responded to that question. >>>> >>> Huh? Gabriel Genellina replied about 46 minutes after it was posted. >>> Might it be that your newsserver is a bit laggy? >>> >>> regards >>> /W >>> >> >> Might be laggy. Who knows. >> >> Why didn't you answer the len() question? > > I didn't respond because it has been asked and answered before, so the > answer can be found in the google archives or even maybe the FAQ. Yes, you did respond. Aren't you the one who wrote "Might be laggy"? If you didn't feel like answering the question, why did you add an utterly worthless post? From clp2 at rebertia.com Sun Feb 8 08:05:33 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 8 Feb 2009 05:05:33 -0800 Subject: The fastest way to convert a long list of date In-Reply-To: References: Message-ID: <50697b2c0902080505x419ce59eq9db1a0df6381bdbc@mail.gmail.com> On Sun, Feb 8, 2009 at 4:46 AM, wrote: > If I want to convert a single date format I can do: > > import datetime, dateutil.parser > d = dateutil.parser.parse('2008-09-26) > print d.strftime('%A %d, %b %y' ) > > but if I want convert a long list of time how can do it in the fastest > way? > for example: > from ['2008-09-26', '2008-09-28', '2008-09-29',.............] > to ['26 sep','28 sep','29 sep',................] import datetime from dateutil.parser import parse orig_dates = ['2008-09-26', '2008-09-28', ...]#etc converted_dates = [parse(datestr).strftime('%A %d, %b %y' ) for datestr in orig_dates] Or if an iterator would be okay instead of a list, you can substitute the list comprehension for itertools.imap(): #setup same as before from itertools import imap converted_dates = imap(lambda datestr: parse(datestr).strftime('%A %d, %b %y' ), orig_dates) Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From peke at iki.fi Sun Feb 8 08:20:00 2009 From: peke at iki.fi (=?ISO-8859-1?Q?Pekka_Kl=E4rck?=) Date: Sun, 8 Feb 2009 15:20:00 +0200 Subject: Changing return of type(obj) In-Reply-To: References: Message-ID: <7dedbb6d0902080520i52f2ffcenb52f53ed3b0277e2@mail.gmail.com> 2009/2/6 Ken Elkabany : > > I am attempting to fully-simulate an 'int' object with a custom object type. > It is part of a library I am creating for python futures and promises. Is > there anyway such that type(my_object) can return ? If it's enough to change how the type looks like you can simply change its repr: >>> class X(type): ... def __repr__(self): ... return 'xxx' ... >>> class Y(object): ... __metaclass__ = X ... >>> type(Y()) xxx Cheers, .peke From digitig at gmail.com Sun Feb 8 08:24:12 2009 From: digitig at gmail.com (Tim Rowe) Date: Sun, 8 Feb 2009 13:24:12 +0000 Subject: "Weird" Indentation? (Or: is there a for...else construct?) In-Reply-To: References: <20090207152122.683de28e@usenot.de> <019d9052$0$20640$c3e8da3@news.astraweb.com> Message-ID: 2009/2/7 andrew cooke : > > there's a justification for this awful mess here - > http://mail.python.org/pipermail/python-3000/2006-March/000104.html > > i didn't know about this, and even after reading steven's broken (i > assume) example, managed to get it backwards. What's awful about it? Except in the sense of inspiring awe, of course. No, Steven's example isn't broken, it works as the epydoc authors intended. > (it's still in 3). Good. -- Tim Rowe From Ron.Barak at lsi.com Sun Feb 8 08:36:17 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Sun, 8 Feb 2009 13:36:17 +0000 Subject: How to copy an instance without its cStringIO.StringO item ? In-Reply-To: References: Message-ID: <7F0503CD69378F49BE0DC30661C6CCF60E68778F@enbmail01.lsi.com> Hi, I need to copy an instance of a class, where one of the items in the original is a cStringIO.StringO object. I do not need the cStringIO.StringO in the target object. The target instance is to be pickled. Googling made me devise the following plan: do a deepcopy from the original to the target, and then delete the cStringIO.StringO object from the target. However, trying to use copy.deepcopy produced: TypeError: object.__new__(cStringIO.StringO) is not safe, use cStringIO.StringO.__new__() Is there a way to create a copy of the instance, sans the cStringIO.StringO ? If I find no elegant way to do that, I thought of creating a "blank" target instance; then iterating over the __dict__ of the original, and manually copy the items to the target (while not copying the cStringIO.StringO to the target). Can you suggest a better way ? Thanks, Ron. Traceback (most recent call last): File "c:\Documents and Settings\rbarak\rbarak_devel\LogManager\./failover_pickle_demo02.py", line 388, in for_pickle_log_stream = copy.deepcopy(log_stream) File "c:\Python25\lib\copy.py", line 162, in deepcopy y = copier(x, memo) File "c:\Python25\lib\copy.py", line 291, in _deepcopy_inst state = deepcopy(state, memo) File "c:\Python25\lib\copy.py", line 162, in deepcopy y = copier(x, memo) File "c:\Python25\lib\copy.py", line 254, in _deepcopy_dict y[deepcopy(key, memo)] = deepcopy(value, memo) File "c:\Python25\lib\copy.py", line 189, in deepcopy y = _reconstruct(x, rv, 1, memo) File "c:\Python25\lib\copy.py", line 322, in _reconstruct y = callable(*args) File "c:\Python25\lib\copy_reg.py", line 92, in __newobj__ return cls.__new__(cls, *args) TypeError: object.__new__(cStringIO.StringO) is not safe, use cStringIO.StringO.__new__() -------------- next part -------------- An HTML attachment was scrubbed... URL: From bblais at bryant.edu Sun Feb 8 08:36:36 2009 From: bblais at bryant.edu (Brian Blais) Date: Sun, 8 Feb 2009 08:36:36 -0500 Subject: simple web app, where to start In-Reply-To: <77e831100902071839r48806b22x26cff29781b412f1@mail.gmail.com> References: <77e831100902062016q2d92ee3awb907baf47f477858@mail.gmail.com> <20090208000948.GB28442@beauTy.hsd1.ca.comcast.net> <77e831100902071839r48806b22x26cff29781b412f1@mail.gmail.com> Message-ID: <937E51FC-44E0-4268-9FF3-961B8ECBECF9@bryant.edu> On Feb 7, 2009, at 21:39 , Vincent Davis wrote: > Thanks http://www.cherrypy.org/ looks like a good and simple option. > it is a nice option, but I prefer www.webpy.org over cherrypy. It's a bit easier, and there is less magic. I've done really simple scripts, to semi-complex web apps with it. bb -- Brian Blais bblais at bryant.edu http://web.bryant.edu/~bblais -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Sun Feb 8 08:52:27 2009 From: __peter__ at web.de (Peter Otten) Date: Sun, 08 Feb 2009 14:52:27 +0100 Subject: The fastest way to convert a long list of date References: Message-ID: loredana.pier at gmail.com wrote: > If I want to convert a single date format I can do: > > import datetime, dateutil.parser > d = dateutil.parser.parse('2008-09-26) > print d.strftime('%A %d, %b %y' ) > > but if I want convert a long list of time how can do it in the fastest > way? > for example: > from ['2008-09-26?, '2008-09-28?, '2008-09-29?,.............] > to [?26 sep?,?28 sep?,?29 sep?,................] For large source lists the following should be quite fast... months = "jan feb mar apr may jun jul aug sep oct dec".split() lookup = dict(("%02d-%02d" % (mi+1, d), "%02d-%s" % (d, m)) for mi, m in enumerate(months) for d in range(1, 32)) source = ["2008-09-26", "2008-09-28", "2008-09-29"] print [lookup[d[-5:]] for d in source] ... but it is also very brittle. Various compromises are possible, but to find the best would require that you tell us a bit more about your use case. In my experience people are a bit too fast to demand "fast". Peter From lists at cheimes.de Sun Feb 8 09:01:04 2009 From: lists at cheimes.de (Christian Heimes) Date: Sun, 08 Feb 2009 15:01:04 +0100 Subject: How to copy an instance without its cStringIO.StringO item ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF60E68778F@enbmail01.lsi.com> References: <7F0503CD69378F49BE0DC30661C6CCF60E68778F@enbmail01.lsi.com> Message-ID: Barak, Ron schrieb: > Hi, > > I need to copy an instance of a class, where one of the items in the original is a cStringIO.StringO object. > I do not need the cStringIO.StringO in the target object. > The target instance is to be pickled. > > Googling made me devise the following plan: do a deepcopy from the original to the target, and then delete the cStringIO.StringO object from the target. > > However, trying to use copy.deepcopy produced: TypeError: object.__new__(cStringIO.StringO) is not safe, use cStringIO.StringO.__new__() > > Is there a way to create a copy of the instance, sans the cStringIO.StringO ? > > If I find no elegant way to do that, I thought of creating a "blank" target instance; then iterating over the __dict__ of the original, and manually copy the items to the target (while not copying the cStringIO.StringO to the target). > > Can you suggest a better way ? You can overwrite some functions in order to omit attributes from a pickle. It's all documented at http://docs.python.org/library/pickle.html#pickling-and-unpickling-normal-class-instances Christian From hall.jeff at gmail.com Sun Feb 8 09:04:29 2009 From: hall.jeff at gmail.com (hall.jeff at gmail.com) Date: Sun, 8 Feb 2009 06:04:29 -0800 (PST) Subject: easy_install Message-ID: <7f00694b-a956-440d-92f5-99db48925829@l1g2000yqj.googlegroups.com> For the life of me I can not figure out how to get easy_install to work. The syntax displayed on the web page does not appear to work properly. easy_install c:\MySQL_python-1.2.2-py2.4-win32.egg Is there a simpler way to install a python egg? Or am I missing something with easy_install? From detlev at die-offenbachs.de Sun Feb 8 09:05:08 2009 From: detlev at die-offenbachs.de (Detlev Offenbach) Date: Sun, 08 Feb 2009 15:05:08 +0100 Subject: ANN: eric 4.3.0 released Message-ID: Hi, this is to inform all of you about the immediate availability of the long awaited 4.3.0 release. It includes enhancements in nearly every area. Please see for yourself by downloading it from http://eric-ide.python-projects.org/index.html eric4 is a Python (and Ruby) IDE written using PyQt4 and QScintilla2. It comes with batteries included and is extensible via a built-in plug-in system. Plug-ins are available via the internet from the eric4 plugin repository. Please see the a.m. web site for more details. Regards, Detlev -- Detlev Offenbach detlev at die-offenbachs.de From elsjaako at gmail.com Sun Feb 8 09:11:36 2009 From: elsjaako at gmail.com (elsjaako) Date: Sun, 8 Feb 2009 06:11:36 -0800 (PST) Subject: receive and react to MIDI input References: <9bb30fb9-c929-4296-84c6-9ebc4932157f@i24g2000prf.googlegroups.com> Message-ID: <46da09d0-4392-43ce-b3e6-b962c82de371@x10g2000yqk.googlegroups.com> On Jan 29, 8:33?pm, elsjaako wrote: > Hi all. I want to write an application that reads midi notes and then > does something (specifically, play sound files, but that doesn't > really matter for this question). I'm on windows. > > Bart de Waal I got it working, quickly packed it up, and posted it to sourceforge. See http://sourceforge.net/projects/winpymidiin/. From deets at nospam.web.de Sun Feb 8 09:27:22 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 08 Feb 2009 15:27:22 +0100 Subject: easy_install References: <7f00694b-a956-440d-92f5-99db48925829@l1g2000yqj.googlegroups.com> Message-ID: <6v88eaFifbroU1@mid.uni-berlin.de> hall.jeff at gmail.com wrote: > For the life of me I can not figure out how to get easy_install to > work. The syntax displayed on the web page does not appear to work > properly. > > easy_install c:\MySQL_python-1.2.2-py2.4-win32.egg It usually works for me - so what does "not appear to work properly" actually mean? Diez From deets at nospam.web.de Sun Feb 8 09:45:33 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 08 Feb 2009 15:45:33 +0100 Subject: Internal Server error References: <6v7srtFil09hU1@mid.uni-berlin.de> <4cb170df-2786-42fe-97e5-f243ce6401b0@o2g2000prl.googlegroups.com> Message-ID: <6v89gdFiiagkU1@mid.uni-berlin.de> zaheer.agadi at gmail.com wrote: > On Feb 8, 4:09?pm, "Diez B. Roggisch" wrote: >> zaheer.ag... at gmail.com schrieb: >> >> >> >> > HI >> > I am getting an internal server error while trying get response from a >> > server following is my code >> >> > def getDetails(self,username,password): >> > urllib = urllib2.Request >> > idurl="https://some.server.com/" >> > port=8181 >> > conn = httplib.HTTPSConnection("some.server.com/",8181); >> > conn.debuglevel ?= 1 >> > username = "userone" >> > password = "aaaa" >> > Auth = "Basic" + ecnodeURL(self,username, password) >> > url= "https://some.network.com:8181/main/folder/persons/" + >> > username + "/attributes/atrone" >> > print url >> > headers = {"Authorization": Auth,"Accept": "application/json"} >> > conn.request("GET", url,{},headers) >> > response = conn.getresponse() >> > data = response.read() >> > print response.reason >> > print response. > Thanks, > > I know there is something on the wrong side, when it says > java.util.NoSuchElementException i thought something wrong with > setting values I just wanted you guys to point me out there is > something wrong with the code I have written I am not very familiar > with Python the same work for java works fine. Well, it's obviously not the same. Otherwise it *would* work fine as well. your code is a bit non-idiomatic: urllib = urllib2.Request is *very* misleading, aliasing a class-constructor with a well-known modulename. Not using username & password also isn't really making sense. "ecnodeURL" - what is that? Where does that come from - certainly not from the stdlib, that's got a better spelling correction. Instead of "string" + variable + "string" on usually uses string interpolation to build complicated strings: "some text %s some more text" % variable > > I wanted to know if I am setting the headers correctly, getting the > response correctly > are there any better ways of encoding the url Over all Does the code > look ok...? You seem to make the call correctly. Just not what the server expects. Diez From davidgshi at yahoo.co.uk Sun Feb 8 10:05:50 2009 From: davidgshi at yahoo.co.uk (David Shi) Date: Sun, 8 Feb 2009 15:05:50 +0000 (GMT) Subject: Dynamically updating sections of webpage Message-ID: <851179.67701.qm@web26306.mail.ukl.yahoo.com> I want to dynamically update sections of webpage, something like a div or table or frame. ? Where can I find best examples/demos for this?? Preferably with a generic loader. ? I would also like to find a best book on this.? It needs to be concise, well explained and can be applied universally. ? Is there a book or reference like "Accelerated DOM Scripting with Ajax, APIs and Libraries and Python"? ? Can anyone point me towards the right direction.? Please -- no over loaded websites. ? I like to read Newtonian style of text! ? Sincerely, ? David -------------- next part -------------- An HTML attachment was scrubbed... URL: From curiouserrandy at gmail.com Sun Feb 8 10:08:11 2009 From: curiouserrandy at gmail.com (curiouserrandy at gmail.com) Date: Sun, 8 Feb 2009 07:08:11 -0800 (PST) Subject: TkInter: Problem with propagation of resize events through geometry manager hierarchy? References: Message-ID: <35dc67a4-aa61-4e88-a79c-64118c1285e7@o11g2000yql.googlegroups.com> On Feb 8, 6:27?am, James Stroud wrote: > I can't test your code because I don't have the test image and for some > reason it does not recognize a tiff of my own. But, just glancing at > your code, it looks like a quick-fix would be to set self.zoom to a > sentinel at the end of refresh() and return 'break' at the top of the > methods that use self.zoom if it is said sentinel value (e.g. "if > self.zoom == WHATEVER_SENTINEL: return 'break'). You may also want to > return 'break' for event responders that should terminate the event > chain. This is a general technique to stop a lot of unwanted event > propagation. Thanks! I hadn't known about the "return 'break'" technique. But I don't follow your sentinel suggestion; how would that sentinel ever get reset? It seems as if the first time through the event chain it'd be set to the sentinel, and the routines that pay attention to it would never execute. What am I missing? I tried simply returning 'break' at the end of "refresh()" and that made no change in behavior. (Note that zoom should be constant at 1.0 for the life of this program; I put it in because I'm planning to put in expansion/ contraction of images after I get resize & scrolling working together. Eliminating all multiplications by self.zoom confirms this belief; no change in behavior). One thing I've been looking for (including in the source :-J) is a description of the precise process that the geometry manager goes through in figuring out and then setting sizes for the various widgets (on resize or, apparently, startup). I suspect with that + the "return 'break'" technique I could get this to work. But I haven't been having any luck finding that documentation. If you'd like me to send you the test.tiff image, I'm happy to, but it's nothing special; just a screen capture of a random google maps satellite view that I use for testing. -- Randy > > James > > -- > James Stroud > UCLA-DOE Institute for Genomics and Proteomics > Box 951570 > Los Angeles, CA 90095 > > http://www.jamesstroud.com From hall.jeff at gmail.com Sun Feb 8 10:21:30 2009 From: hall.jeff at gmail.com (hall.jeff at gmail.com) Date: Sun, 8 Feb 2009 07:21:30 -0800 (PST) Subject: easy_install References: <7f00694b-a956-440d-92f5-99db48925829@l1g2000yqj.googlegroups.com> <6v88eaFifbroU1@mid.uni-berlin.de> Message-ID: <4c020f9a-d179-4153-9815-9a32c54a7d2e@f3g2000yqf.googlegroups.com> On Feb 8, 9:27?am, "Diez B. Roggisch" wrote: > hall.j... at gmail.com wrote: > > For the life of me I can not figure out how to get easy_install to > > work. The syntax displayed on the web page does not appear to work > > properly. > > > easy_install c:\MySQL_python-1.2.2-py2.4-win32.egg > > It usually works for me - so what does "not appear to work properly" > actually mean? > > Diez http://peak.telecommunity.com/DevCenter/EasyInstall#downloading-and-installing-a-package seems to imply that after installation I can goto a command prompt and type easy_install c:\MySQL_python-1.2.2-py2.4-win32.egg I tried doing this in the python interpreter and on a straight "cmd" command prompt (the site doesn't really specify). I also tried "import easy_install" and then easy_install c:\MySQL_python-1.2.2-py2.4-win32.egg easy_install ("c:\MySQL_python-1.2.2-py2.4-win32.egg") and a couple other permutations and never got it to run (error messages for the first group were "invalid syntax" and were various flavors of "module not callable" for the second group). From apt.shansen at gmail.com Sun Feb 8 10:31:14 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sun, 8 Feb 2009 07:31:14 -0800 Subject: Process crash with no reason In-Reply-To: <6732e3c4-8fcc-45c8-8e62-aea7eb64d942@j1g2000yqi.googlegroups.com> References: <30c13ac1-0ad0-4825-8d5c-301d505e6b66@p2g2000prn.googlegroups.com> <6732e3c4-8fcc-45c8-8e62-aea7eb64d942@j1g2000yqi.googlegroups.com> Message-ID: <7a9c25c20902080731t616ea63diba1dff99d4a2779e@mail.gmail.com> > Thanks a lot and sorry for the late response. My main suspect is the > CherryPy. > I'm still investigating it. You're asking for advice but not listening to what people are saying here -- why is CherryPy on the top of your list? What version of CherryPy is it? 1 or 2? If its 2, then its pure python and there's a really, really low chance that its provoking a hard crash w/o a traceback printing before it dies out. A hard crash which isn't printing an error message is possible in pure Python I suppose, but I've never seen it. A "Bus error" for example will kill the interpreter before it can do any error handling. But I've only ever seen that when interfacing with third party libraries. If its 1, there is some C so you can bump it up ... and for that I'd probably attempt to run the application in a console or with stdout manually redirected instead of relying on the logging alone, to see if anything useful gets put out.. like "Bus error", at the time it exits. But why do you keep discarding the Sybase module? Its most definitely *not* written in python. What Philip and Tim were trying to tell you is you are *not* using "python's functions to run sybase sql commands" The Sybase module is a python wrapper around code written in C module which is interfacing with a third party library to talk to Sybase. Are you at the latest version of Sybase(0.39 if its the same module I'm aware of?) How about the library underneath it? FreeTDS or Sybase ASE (whatever that is) or whatever else is being used? A bug in /any/ of those C layers (notice its *multiple* layers) could propagate up and provoke a hard crash that Python doesn't catch. So if you look into those versions perhaps one has a new release that fixes bugs. --S From duncan.booth at invalid.invalid Sun Feb 8 10:34:03 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 8 Feb 2009 15:34:03 GMT Subject: easy_install References: <7f00694b-a956-440d-92f5-99db48925829@l1g2000yqj.googlegroups.com> <6v88eaFifbroU1@mid.uni-berlin.de> <4c020f9a-d179-4153-9815-9a32c54a7d2e@f3g2000yqf.googlegroups.com> Message-ID: hall.jeff at gmail.com wrote: > http://peak.telecommunity.com/DevCenter/EasyInstall#downloading-and-ins > talling-a-package > > seems to imply that after installation I can goto a command prompt and > type > > easy_install c:\MySQL_python-1.2.2-py2.4-win32.egg > > I tried doing this in the python interpreter and on a straight "cmd" > command prompt (the site doesn't really specify). Start a Windows command prompt. You probably don't have the directory containing easy_install on your path, so use the 'cd' command to change to the directory it was installed in: that will be the Scripts directory under the directory to which you installed Python. So since you seem to be using Python 2.4 that might be: C:\>cd C:\Python24\Scripts C:\Python24\Scripts>easy_install c:\MySQL_python-1.2.2-py2.4-win32.egg Alternatively in a single command: C:\>C:\Python24\Scripts\easy_install c:\MySQL_python-1.2.2-py2.4-win32.egg From xie.kenneth at gmail.com Sun Feb 8 10:45:15 2009 From: xie.kenneth at gmail.com (Ken) Date: Sun, 8 Feb 2009 23:45:15 +0800 Subject: Quetion about flags of socket.recv(bufsize, [flags]) Message-ID: <8af39e160902080745j13f4451dtcdf0f6007a57f188@mail.gmail.com> I want to receive 4 bytes from a connected socket, I code like this: data = sock.recv(4) There is a problem with above code. The recv method will not block until it get all 4 bytes. So I use the second param of recv method like this data = sock.recv(4, socket.MSG_WAITALL) This works fine on linux with python 2.5, while on windows, the interpreter tells me 'AttributeError: 'module' object has no attribute 'MSG_WAITALL''. How can I work this out, or there is another way to get certain bytes from a socket and block if it hasn't got enough bytes? :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Sun Feb 8 11:09:15 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 08 Feb 2009 11:09:15 -0500 Subject: Quetion about flags of socket.recv(bufsize, [flags]) In-Reply-To: <8af39e160902080745j13f4451dtcdf0f6007a57f188@mail.gmail.com> References: <8af39e160902080745j13f4451dtcdf0f6007a57f188@mail.gmail.com> Message-ID: Ken wrote: > I want to receive 4 bytes from a connected socket, I code like this: > > data = sock.recv(4) > > There is a problem with above code. The recv method will not block until > it get all 4 bytes. So I use the second param of recv method like this > > data = sock.recv(4, socket.MSG_WAITALL) > > This works fine on linux with python 2.5, while on windows, the > interpreter tells me 'AttributeError: 'module' object has no attribute > 'MSG_WAITALL''. How can I work this out, or there is another way to get > certain bytes from a socket and block if it hasn't got enough bytes? > If you *need* 4 bytes then the best way to receive them is simply to loop until you get them (assuming you are using blocking sockets): BLOCKSIZE = 4 buffer = "" while len(buffer) < BLOCKSIZE: data = sock.recv(BLOCKSIZE-len(buffer)) if not data: break # other end is closed! buffer += data regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From Ron.Barak at lsi.com Sun Feb 8 11:17:34 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Sun, 8 Feb 2009 16:17:34 +0000 Subject: How to copy an instance without its cStringIO.StringO item ? In-Reply-To: References: Message-ID: <7F0503CD69378F49BE0DC30661C6CCF60E68779F@enbmail01.lsi.com> Hi John, Maybe you encountered the below issue in your Python programming, and you may offer advise ? I need to copy an instance of a class, where one of the items in the original is a cStringIO.StringO object. I do not need the cStringIO.StringO in the target object. The target instance is to be pickled. Googling made me devise the following plan: do a copy/deepcopy from the original to the target, and then delete the cStringIO.StringO object from the target. However, trying to use copy.deepcopy produced (see full traceback below my signature): TypeError: object.__new__(cStringIO.StringO) is not safe, use cStringIO.StringO.__new__() Is there a way to create a copy of the instance, sans the cStringIO.StringO ? If I find no elegant way to do that, I thought of creating a "blank" target instance; then iterating over the __dict__ of the original, and manually copy the items to the target (while not copying the cStringIO.StringO to the target). Trying that, I did: for_pickle_log_stream = LogStream(sac_log_file) for key in log_stream.__dict__: if key != "input_file": for_pickle_log_stream[key] = log_stream[key] But that gave me: Traceback (most recent call last): File "c:\Documents and Settings\rbarak\rbarak_devel\LogManager\./failover_pickle_demo02.py", line 393, in for_pickle_log_stream[key] = log_stream[key] AttributeError: FailoverMatches instance has no attribute '__getitem__' Can you suggest a better way ? Another question: Do you have an example of creating a __getitem__ method for my class? The class includes the following: log_stream.__dict__: { 'db': [ { 'DPM': 'iSW-00-090', 'end_time': '2009 Dec 15 16:17:24', 'event': 'Volume failover', 'event_duration': 0L, 'first_line_pos': 12453, 'last_line_pos': 12871, 'rec_num': 0, 'start_time': '2009 Dec 15 16:17:24', 'volume_name': 'Domain 5:DVol1_1'}, { 'DPM': 'iSW-00-090', 'end_time': '2009 Dec 15 16:17:24', 'event': 'Volume failover', 'event_duration': 0L, 'first_line_pos': 13409, 'last_line_pos': 13827, 'rec_num': 1, 'start_time': '2009 Dec 15 16:17:24', 'volume_name': 'Domain 5:DVol1_2'}], 'end_timestamp': 1260886645L, 'file_pointer': 58180, 'filename_array': [ u'C:\\Documents and Settings\\rbarak\\rbarak_devel\\LogManager\\logs_3_vol\\sac.log.367lines.gz'], 'input_file': , 'last_line_offset': 58181, 'log_stream_array': []} (the red item is not needed in the target object). Thanks, Ron. Traceback (most recent call last): File "c:\Documents and Settings\rbarak\rbarak_devel\LogManager\./failover_pickle_demo02.py", line 388, in for_pickle_log_stream = copy.deepcopy(log_stream) File "c:\Python25\lib\copy.py", line 162, in deepcopy y = copier(x, memo) File "c:\Python25\lib\copy.py", line 291, in _deepcopy_inst state = deepcopy(state, memo) File "c:\Python25\lib\copy.py", line 162, in deepcopy y = copier(x, memo) File "c:\Python25\lib\copy.py", line 254, in _deepcopy_dict y[deepcopy(key, memo)] = deepcopy(value, memo) File "c:\Python25\lib\copy.py", line 189, in deepcopy y = _reconstruct(x, rv, 1, memo) File "c:\Python25\lib\copy.py", line 322, in _reconstruct y = callable(*args) File "c:\Python25\lib\copy_reg.py", line 92, in __newobj__ return cls.__new__(cls, *args) TypeError: object.__new__(cStringIO.StringO) is not safe, use cStringIO.StringO.__new__() -------------- next part -------------- An HTML attachment was scrubbed... URL: From loredana.pier at gmail.com Sun Feb 8 11:30:06 2009 From: loredana.pier at gmail.com (loredana.pier at gmail.com) Date: Sun, 8 Feb 2009 08:30:06 -0800 (PST) Subject: The fastest way to convert a long list of date References: Message-ID: First of all: Thanks for your reply My use case is the following: I perform a query to DB and the result of query is this; >>> print rows {?Label?: {'2009:01:30': 9, '2009:01:28': 13, '2009:01:29': 19, '2009:01:26': 1, '2009:01:27': 3, '2009:01:20': 86, '2009:01:22': 3, '2009:01:23': 12, '2009:02:07': 3, '2009:02:06': 12, '2009:02:05': 15, '2009:02:04': 12, '2009:02:02': 2}} I want to make a chart with this data using JSON format where: ? the key ?Label? is the title of chart, ? rows['Label'].keys() is x values, ? rows[?Label?].values() is the y values So my goal is: 1) to fill the bin of chart with no data (for example in this tupla.. [.., '2009:01:28: 9, '2009:01:30: 13,..].. the date '2009:01:29? is missing and I want to append the value ['2009:01:29?,0] to rows [?Label?]) 2) convert the date format (for example in '%A %d, %b %y') 3) transform rows dictionary in JSON code The point 3) is easy to implement but I?m wondering which is the best way to implement the point 1) and 2) ...considering it will be used for a web application (CherryPy)? thanks, Loredana From aahz at pythoncraft.com Sun Feb 8 11:32:05 2009 From: aahz at pythoncraft.com (Aahz) Date: 8 Feb 2009 08:32:05 -0800 Subject: ElementTree and clone element toot References: <4986bfd7$0$9385$ba4acef3@news.orange.fr> Message-ID: In article <4986bfd7$0$9385$ba4acef3 at news.orange.fr>, m.banaouas wrote: > >Working with the ElementTree module, I looked for clone element >function but not found such tool: Have you tried using copy.deepcopy()? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From geekmail at usenot.de Sun Feb 8 11:44:14 2009 From: geekmail at usenot.de (Andreas Waldenburger) Date: Sun, 8 Feb 2009 17:44:14 +0100 Subject: len() References: <20090131201648.201b6ed5@usenot.de> Message-ID: <20090208174414.4837b34c@usenot.de> On Sun, 08 Feb 2009 07:54:13 -0500 Pat wrote: > Terry Reedy wrote: > > Pat wrote: > >> Andreas Waldenburger wrote: > >>> On Sat, 31 Jan 2009 13:27:02 -0500 Pat wrote: > >>> > >>>> Tobiah wrote: > >>>>> Just out of curiosity, why was len() made to > >>>>> be it's own function? I often find myself > >>>>> typing things like my_list.len before I > >>>>> catch myself. > >>>>> > >>>>> Thanks, > >>>>> > >>>>> Toby > >>>> I'm surprised that no one responded to that question. > >>>> > >>> Huh? Gabriel Genellina replied about 46 minutes after it was > >>> posted. Might it be that your newsserver is a bit laggy? > >>> > >>> regards > >>> /W > >>> > >> > >> Might be laggy. Who knows. > >> > >> Why didn't you answer the len() question? > > > > I didn't respond because it has been asked and answered before, so > > the answer can be found in the google archives or even maybe the > > FAQ. > > Yes, you did respond. Aren't you the one who wrote "Might be laggy"? > No, I am. Pretty clear from the "From" header. ;) > If you didn't feel like answering the question, why did you add an > utterly worthless post? > There, there. Let's not get too excited, OK? I made an observation that I felt might be beneficial to you (even if only marginally so). I did not mean it as an insult. I'm sorry if it seemed that way. /W -- My real email address is constructed by swapping the domain with the recipient (local part). From steve at holdenweb.com Sun Feb 8 12:00:52 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 08 Feb 2009 12:00:52 -0500 Subject: len() In-Reply-To: <20090208174414.4837b34c@usenot.de> References: <20090131201648.201b6ed5@usenot.de> <20090208174414.4837b34c@usenot.de> Message-ID: Andreas Waldenburger wrote: > On Sun, 08 Feb 2009 07:54:13 -0500 Pat wrote: > >> Terry Reedy wrote: >>> Pat wrote: >>>> Andreas Waldenburger wrote: >>>>> On Sat, 31 Jan 2009 13:27:02 -0500 Pat wrote: >>>>> >>>>>> Tobiah wrote: >>>>>>> Just out of curiosity, why was len() made to >>>>>>> be it's own function? I often find myself >>>>>>> typing things like my_list.len before I >>>>>>> catch myself. >>>>>>> >>>>>>> Thanks, >>>>>>> >>>>>>> Toby >>>>>> I'm surprised that no one responded to that question. >>>>>> >>>>> Huh? Gabriel Genellina replied about 46 minutes after it was >>>>> posted. Might it be that your newsserver is a bit laggy? >>>>> >>>>> regards >>>>> /W >>>>> >>>> Might be laggy. Who knows. >>>> >>>> Why didn't you answer the len() question? >>> I didn't respond because it has been asked and answered before, so >>> the answer can be found in the google archives or even maybe the >>> FAQ. >> Yes, you did respond. Aren't you the one who wrote "Might be laggy"? >> > No, I am. Pretty clear from the "From" header. ;) > > >> If you didn't feel like answering the question, why did you add an >> utterly worthless post? >> > There, there. Let's not get too excited, OK? I made an observation that > I felt might be beneficial to you (even if only marginally so). I did > not mean it as an insult. I'm sorry if it seemed that way. Right, well let's *all* calm down, and resolve not to bother making posts that don't contribute something positive. It's not like this is a low-bandwidth group, there's always plenty going on. regards Steve who is still hoping that one day Xah Lee will post and *nobody* will reply ... -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From cjw at ncf.ca Sun Feb 8 12:18:32 2009 From: cjw at ncf.ca (Colin J. Williams) Date: Sun, 08 Feb 2009 12:18:32 -0500 Subject: easy_install In-Reply-To: <6v88eaFifbroU1@mid.uni-berlin.de> References: <7f00694b-a956-440d-92f5-99db48925829@l1g2000yqj.googlegroups.com> <6v88eaFifbroU1@mid.uni-berlin.de> Message-ID: <498F13E8.40501@ncf.ca> Diez B. Roggisch wrote: > hall.jeff at gmail.com wrote: > >> For the life of me I can not figure out how to get easy_install to >> work. The syntax displayed on the web page does not appear to work >> properly. >> >> easy_install c:\MySQL_python-1.2.2-py2.4-win32.egg > > It usually works for me - so what does "not appear to work properly" > actually mean? > > Diez I updated my easy_install, used the scripts directory, dropped the "c:\" and it gave the response below for me: C:\Documents and Settings\cjw\Desktop>c:\Python25\scripts\easy_install MySQL_python-1.2.2-py2.4-win32.egg Searching for MySQL-python-1.2.2-py2.4-win32.egg Reading http://pypi.python.org/simple/MySQL_python-1.2.2-py2.4-win32.egg/ Reading http://pypi.python.org/simple/MySQL-python-1.2.2-py2.4-win32.egg/ Couldn't find index page for 'MySQL_python-1.2.2-py2.4-win32.egg' (maybe misspelled?) Scanning index of all packages (this may take a while) Reading http://pypi.python.org/simple/ No local packages or download links found for MySQL-python-1.2.2-py2.4-win32.egg error: Could not find suitable distribution for Requirement.parse('MySQL-python-1.2.2-py2.4-win32.egg') C:\Documents and Settings\cjw\Desktop> I hope that this is of some help. Colin W. From benjamin.kaplan at case.edu Sun Feb 8 12:23:24 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 8 Feb 2009 12:23:24 -0500 Subject: easy_install In-Reply-To: <498F13E8.40501@ncf.ca> References: <7f00694b-a956-440d-92f5-99db48925829@l1g2000yqj.googlegroups.com> <6v88eaFifbroU1@mid.uni-berlin.de> <498F13E8.40501@ncf.ca> Message-ID: On Sun, Feb 8, 2009 at 12:18 PM, Colin J. Williams wrote: > Diez B. Roggisch wrote: > >> hall.jeff at gmail.com wrote: >> >> For the life of me I can not figure out how to get easy_install to >>> work. The syntax displayed on the web page does not appear to work >>> properly. >>> >>> easy_install c:\MySQL_python-1.2.2-py2.4-win32.egg >>> >> >> It usually works for me - so what does "not appear to work properly" >> actually mean? >> >> Diez >> > > I updated my easy_install, used the scripts directory, dropped the "c:\" > and it gave the response below for me: > > C:\Documents and Settings\cjw\Desktop>c:\Python25\scripts\easy_install > MySQL_python-1.2.2-py2.4-win32.egg > Searching for MySQL-python-1.2.2-py2.4-win32.egg > Reading http://pypi.python.org/simple/MySQL_python-1.2.2-py2.4-win32.egg/ > Reading http://pypi.python.org/simple/MySQL-python-1.2.2-py2.4-win32.egg/ > Couldn't find index page for 'MySQL_python-1.2.2-py2.4-win32.egg' (maybe > misspelled?) > Scanning index of all packages (this may take a while) > Reading http://pypi.python.org/simple/ > No local packages or download links found for > MySQL-python-1.2.2-py2.4-win32.egg > error: Could not find suitable distribution for > Requirement.parse('MySQL-python-1.2.2-py2.4-win32.egg') > > C:\Documents and Settings\cjw\Desktop> > > I hope that this is of some help. the py2.4 part of the egg implies that it was compiled for Python 2.4. You are trying to use Python 2.5. Try looking for MySQL-python-1.2.2-py2.5-win32.egg instead. > > > Colin W. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gherron at islandtraining.com Sun Feb 8 12:58:44 2009 From: gherron at islandtraining.com (Gary Herron) Date: Sun, 08 Feb 2009 09:58:44 -0800 Subject: Best 3d graphics kit for CAD program??? In-Reply-To: References: Message-ID: <498F1D54.9010509@islandtraining.com> An HTML attachment was scrubbed... URL: From apt.shansen at gmail.com Sun Feb 8 13:13:10 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sun, 8 Feb 2009 10:13:10 -0800 Subject: easy_install In-Reply-To: <498F13E8.40501@ncf.ca> References: <7f00694b-a956-440d-92f5-99db48925829@l1g2000yqj.googlegroups.com> <6v88eaFifbroU1@mid.uni-berlin.de> <498F13E8.40501@ncf.ca> Message-ID: <7a9c25c20902081013l74b7c839u3c6f8b839ad6b463@mail.gmail.com> > I updated my easy_install, used the scripts directory, dropped the "c:\" and > it gave the response below for me: That's kinda apples to oranges to what the OP's problem is. The OP appears to be trying to install an egg he downloaded previously. You're instructing easy_install (by dropping the c:\) to search PyPi for an egg that isn't provided. The problem you're having is that it can't find on the internet any packages that match that name (because if you wanted it to find something on the internet, you'd say "easy_install MySQL_python"). --S From martin at v.loewis.de Sun Feb 8 13:30:58 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 08 Feb 2009 19:30:58 +0100 Subject: sortable table in python 3.0 In-Reply-To: References: Message-ID: <498f24e2$0$3368$9b622d9e@news.freenet.de> Peter Pei wrote: > In one of my program, I used something called MultiColumnList, which is > one of the sortable table widgets done in python. However 3.0 sort is > different. I googled and found couple of other implementations, but all > in python 3.0 -. > > Does anyone know any solution in 3.0? or anything that has already been > upgraded to 3.0? Thanks. You need to use the key= argument to sort. Martin From seaworthyjeremy at gmail.com Sun Feb 8 13:42:02 2009 From: seaworthyjeremy at gmail.com (J) Date: Sun, 8 Feb 2009 10:42:02 -0800 (PST) Subject: Python Module: nift Message-ID: <9cb28036-7d5f-4b8a-9748-b26c5e9538b4@r15g2000prd.googlegroups.com> What are your thoughts on this module I created? ''' A Python Module created by a High School Student. Includes rev(), reet(), and leet(). Import nift Function: nift.rev() Description: Reverses a string Usage: nift.rev('string') Example: nift.rev('Testing function.') Output: '.noitcnuf gnitseT' Function: nift.reet() Description: Reverses a string and transforms to leet text. Usage: nift.reet('string') Example: nift.reet('Hello World!') Output: 'dlr0W 0ll3H' Function: nift.leet() Description: Transforms a string into leet text. Usage: nift.leet('string') Example: nift.leet('Hello there!') Output: 'H3ll0 7h3r3!' Setup: * Save to Python Directory\Lib\ as nift.py * Now you may import it by: from nift import function function() OR import nift nift.function() * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * This Module and its functions were created for my own fun, also * * contributing to Inter-Society. I don't mind if anyone modifies * * this module or adds on to it, as long as you attribute it to * * Myself. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ''' def rev(string): list = [] final = '' for letters in string: list.append(letters) list.reverse() for letters in list: final = final + letters return final def reet(string): list = [] final = '' for letters in string: list.append(letters) list.reverse() for letters in list: if letters == 'e' or letters == 'E': letters = '3' elif letters == 'a' or letters == 'A': letters = '4' elif letters == 'i' or letters == 'I': letters = '1' elif letters == 't' or letters == 'T': letters = '7' elif letters == 's' or letters == 'S': letters = '5' elif letters == 'o' or letters == 'O': letters = '0' elif letters == 'b' or letters == 'B': letters = '8' final = final + letters return final def leet(string): list = [] final = '' for letters in string: if letters == 'e' or letters == 'E': letters = '3' elif letters == 'a' or letters == 'A': letters = '4' elif letters == 'i' or letters == 'I': letters = '1' elif letters == 't' or letters == 'T': letters = '7' elif letters == 's' or letters == 'S': letters = '5' elif letters == 'o' or letters == 'O': letters = '0' elif letters == 'b' or letters == 'B': letters = '8' list.append(letters) for letters in list: final = final + letters return final From martin at v.loewis.de Sun Feb 8 13:43:01 2009 From: martin at v.loewis.de (=?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=) Date: Sun, 08 Feb 2009 19:43:01 +0100 Subject: easy_install In-Reply-To: References: <7f00694b-a956-440d-92f5-99db48925829@l1g2000yqj.googlegroups.com> <6v88eaFifbroU1@mid.uni-berlin.de> <498F13E8.40501@ncf.ca> Message-ID: <498f27b6$0$28732$9b622d9e@news.freenet.de> > That's kinda apples to oranges to what the OP's problem is. > > The OP appears to be trying to install an egg he downloaded > previously. I think he actually didn't - if you read his messages, nowhere he said that he actually downloaded the file, and that it actually exists in the root directory of c: Regards, Martin From martin at v.loewis.de Sun Feb 8 13:45:47 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 08 Feb 2009 19:45:47 +0100 Subject: easy_install In-Reply-To: <4c020f9a-d179-4153-9815-9a32c54a7d2e@f3g2000yqf.googlegroups.com> References: <7f00694b-a956-440d-92f5-99db48925829@l1g2000yqj.googlegroups.com> <6v88eaFifbroU1@mid.uni-berlin.de> <4c020f9a-d179-4153-9815-9a32c54a7d2e@f3g2000yqf.googlegroups.com> Message-ID: <498F285B.6060905@v.loewis.de> > http://peak.telecommunity.com/DevCenter/EasyInstall#downloading-and-installing-a-package > > seems to imply that after installation I can goto a command prompt and > type > > easy_install c:\MySQL_python-1.2.2-py2.4-win32.egg These instructions must have misled you. This command only works if you actually have a file c:\MySQL_python-1.2.2-py2.4-win32.egg on your disk, e.g. after downloading it, from http://pypi.python.org/pypi/MySQL-python/1.2.2 If you haven't downloaded it, you have two choices 1. download it, and then give the full filename to easy_install (*not* c:\MySQL_python-1.2.2-py2.4-win32.egg, unless you download to c:\) 2. ask easy_install to download first, with easy_install MySQL-python Regards, Martin From gagsl-py2 at yahoo.com.ar Sun Feb 8 13:48:24 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 08 Feb 2009 16:48:24 -0200 Subject: Lists implemented as integer-hashed Dictionaries? References: <775033410902061918l3a16c8fi82329b8f6f244daa@mail.gmail.com> Message-ID: En Sat, 07 Feb 2009 01:18:37 -0200, er escribi?: > Somebody much more intelligent than I said today that someone told him > that Python lists are just dictionaries with lists hashed by integers. In addition to all other responses you received, I'd add that lists and dictionaries share the same syntax a[x] and the same magic methods in Python code (__getitem__, __setitem__, __delitem__). But the similarity stops here. The CPython implementation has two different sets of methods, one for sequences and other for mappings, so when you override e.g. __getitem__ in Python code it replaces either sq_item or mp_subscript depending on which one is defined. Other implementations might choose to do different, but at least on standard PC hardware I can't imagine how to efficiently implement lists as dictionaries... -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Sun Feb 8 13:48:24 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 08 Feb 2009 16:48:24 -0200 Subject: Lists implemented as integer-hashed Dictionaries? References: <775033410902061918l3a16c8fi82329b8f6f244daa@mail.gmail.com> Message-ID: En Sat, 07 Feb 2009 01:18:37 -0200, er escribi?: > Somebody much more intelligent than I said today that someone told him > that Python lists are just dictionaries with lists hashed by integers. In addition to all other responses you received, I'd add that lists and dictionaries share the same syntax a[x] and the same magic methods in Python code (__getitem__, __setitem__, __delitem__). But the similarity stops here. The CPython implementation has two different sets of methods, one for sequences and other for mappings, so when you override e.g. __getitem__ in Python code it replaces either sq_item or mp_subscript depending on which one is defined. Other implementations might choose to do different, but at least on standard PC hardware I can't imagine how to efficiently implement lists as dictionaries... -- Gabriel Genellina From clp2 at rebertia.com Sun Feb 8 13:53:57 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 8 Feb 2009 10:53:57 -0800 Subject: Python Module: nift In-Reply-To: <9cb28036-7d5f-4b8a-9748-b26c5e9538b4@r15g2000prd.googlegroups.com> References: <9cb28036-7d5f-4b8a-9748-b26c5e9538b4@r15g2000prd.googlegroups.com> Message-ID: <50697b2c0902081053n492696f3n40f5896ced42db66@mail.gmail.com> On Sun, Feb 8, 2009 at 10:42 AM, J wrote: > What are your thoughts on this module I created? * You should probably use individual docstrings for each function rather than one giant module docstring * Don't use 'list' as a variable name; it shadows the name of the builtin list type * You can use the .lower() or .upper() method of strings to get rid of half the 'or'-s in leet() and reet(). Better yet, use a dict rather than a long if-elif chain. * To convert a list of strings to a single string, use ''.join(the_list) instead of: final = '' for letters in the_list: final = final + letters #also, += is preferred in cases like this * To convert a string to a list of characters, use list(string) instead of: the_list = [] final = '' for letters in string: the_list.append(letters) Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From Scott.Daniels at Acm.Org Sun Feb 8 14:07:46 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sun, 08 Feb 2009 11:07:46 -0800 Subject: MacPython 2.5 IDLE font size In-Reply-To: <541cb78b-52fd-4f71-9909-5649d4586558@v42g2000yqj.googlegroups.com> References: <541cb78b-52fd-4f71-9909-5649d4586558@v42g2000yqj.googlegroups.com> Message-ID: chohazel at gmail.com wrote: > Hi, > Is there a way to adjust the default font size in IDLE, in MacPython > 2.5? The default now is too tiny. > I have to use this version of MacPython. As far as I searched, I can't > find how I do this. > Thanks. If you can read what you have at all, try to go toHelp (on the top), then down in that menu to "Configure IDLE ..." There will be a possibly long delay. Then on the tab in the produced window, You can set the Base Editor Font and Size. I use Tahoma 14. Then go click "Ok". If the display doesn't get better, you might have to exit from Idle and restart it. If this diesn't work, get back to me and we can try something more drastic. --Scott David Daniels Scott.Daniels at Acm.Org From gagsl-py2 at yahoo.com.ar Sun Feb 8 14:09:51 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 08 Feb 2009 17:09:51 -0200 Subject: How to copy an instance without its cStringIO.StringO item ? References: <7F0503CD69378F49BE0DC30661C6CCF60E68779F@enbmail01.lsi.com> Message-ID: En Sun, 08 Feb 2009 14:17:34 -0200, Barak, Ron escribi?: > I need to copy an instance of a class, where one of the items in the > original is a cStringIO.StringO object. > I do not need the cStringIO.StringO in the target object. > The target instance is to be pickled. > [...] > for_pickle_log_stream = LogStream(sac_log_file) > for key in log_stream.__dict__: > if key != "input_file": > for_pickle_log_stream[key] = log_stream[key] Note that you're iterating over __dict__ keys, but the last line does not use __dict__. Either put __dict__ everywhere, or: setattr(for_pickle_log_stream, key, getattr(log_stream, key)) But if you want this copy just to pickle it, follow Christian Heimes advice and define __getstate__ / __setstate__. -- Gabriel Genellina From lists at cheimes.de Sun Feb 8 14:33:35 2009 From: lists at cheimes.de (Christian Heimes) Date: Sun, 08 Feb 2009 20:33:35 +0100 Subject: Lists implemented as integer-hashed Dictionaries? In-Reply-To: <775033410902061918l3a16c8fi82329b8f6f244daa@mail.gmail.com> References: <775033410902061918l3a16c8fi82329b8f6f244daa@mail.gmail.com> Message-ID: er schrieb: > Somebody much more intelligent than I said today that someone told him that > Python lists are just dictionaries with lists hashed by integers. Since he > said that someone else told him this, I piped up and said that I thought > that wasn't true. I looked at the source code for lists in python, and I > did not expressly remember seeing dictionaries. Unfortunately I am not > somewhere where I can easily look at the code right now (I'm logged into > Windows!), and I might not realize exactly what I'm looking at anyways, but > I'd like to extend an apology to the guy soon if I was wrong. So, can > anyone tell me if lists are really just dictionaries? Thanks! I like to add some technical information to the topic. In CPython (the most common implementation of Python in C89) lists are implemented as arrays of PyObject* pointers with a non linear growth rate. They are neither implemented as linked lists or as hash maps. The array based implementation makes the most common operations as fast as possible: creation of a list with a known size of elements, iteration, item access, appending and popping from the tail of a list. Iteration and item access (somelist[1]) is a O(1) op. The internal array grows non linear and is usually over-allocated. This makes appending to the end faster because the array doesn't need to be copied with every append(). Uncommon operations like inserts at the head of the lists are slower and require more memcopy ops. CPython has a deque implementation in the collections module with is optimized for both changing both ends of a list like object. Christian From lists at cheimes.de Sun Feb 8 14:38:25 2009 From: lists at cheimes.de (Christian Heimes) Date: Sun, 08 Feb 2009 20:38:25 +0100 Subject: Lists implemented as integer-hashed Dictionaries? In-Reply-To: <7a9c25c20902062047y8afacb8xd0ab1649d7ab843e@mail.gmail.com> References: <775033410902061918l3a16c8fi82329b8f6f244daa@mail.gmail.com> <50697b2c0902061925w36ed850bw796f6737c15e06af@mail.gmail.com> <775033410902061932g6f943500s267d07f68accef98@mail.gmail.com> <7a9c25c20902062047y8afacb8xd0ab1649d7ab843e@mail.gmail.com> Message-ID: Stephen Hansen schrieb: > Now, I believe Python sets *are* for all intents and purposes > dictionaries, but I think that's just because its the easiest and most > efficient way to implement their uniqueness properties; they took the > very-well-tuned dictionary implementation and cut out the stuff not > needed by sets and did some tweaks here or there. I /believe/. You are correct. The first set implementation in pure Python was using a dict as internal storage. The new set implementation is heavily based on the highly optimized dict code. Sets are basically dicts without values. from Objects/setobject.c set object implementation Written and maintained by Raymond D. Hettinger Derived from Lib/sets.py and Objects/dictobject.c. From bearophileHUGS at lycos.com Sun Feb 8 14:59:41 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Sun, 8 Feb 2009 11:59:41 -0800 (PST) Subject: Python Module: nift References: <9cb28036-7d5f-4b8a-9748-b26c5e9538b4@r15g2000prd.googlegroups.com> Message-ID: <1eb3e6de-2092-45f8-b270-81845cbe1ed2@h20g2000yqn.googlegroups.com> More suggestions for a real-world Python programmer: - There's code duplication, the original poster may express reet as a composition of the other functions. - A Python string/list/array can be inverted with [::-1] - I suggest to convert the examples of the main doscstring into doctests. - The main docstring looks too much heavy. - To convert many ASCII chars there's the str.translate method. - Generally I suggest to learn to code in the small, using as little code as possible. Bye, bearophile From david.birdsong at gmail.com Sun Feb 8 15:07:08 2009 From: david.birdsong at gmail.com (birdsong) Date: Sun, 8 Feb 2009 12:07:08 -0800 (PST) Subject: "Weird" Indentation? (Or: is there a for...else construct?) References: <20090207152122.683de28e@usenot.de> <019d9052$0$20640$c3e8da3@news.astraweb.com> <20090207153459.123c5706@usenot.de> Message-ID: <568da34b-0602-44d5-b5d3-496b3cd096cc@r15g2000prd.googlegroups.com> On Feb 7, 6:34?am, Andreas Waldenburger wrote: > On Sun, 08 Feb 2009 01:28:00 +1100 Steven D'Aprano > > wrote: > > Andreas Waldenburger wrote: > > > > It seems that there is a for...else construct. Replacing the inner > > > if with pass seems to confirm this. The else clause is still > > > executed. > > > Yes, there is a for...else construct. > > That's something. In 6+ years of Python programming I've never seen or > heard of this thing. This might be useful, apparently. > yeah, about 4 years for me and i've never noticed this feature. > > [snip] > > > > What's broken here: Python or my brain? > > > Perhaps we should not answer that question. > > I did phrase that rather provocatively, didn't I? > > Well thanks. I'll try to learn less noisily in the future. :) > > /W > > -- > My real email address is constructed by swapping the domain with the > recipient (local part). From gagsl-py2 at yahoo.com.ar Sun Feb 8 15:25:53 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 08 Feb 2009 18:25:53 -0200 Subject: Path question References: <6urjrhFgvif8U1@mid.uni-berlin.de> <498ECB0C.5050705@gmail.com> Message-ID: En Sun, 08 Feb 2009 10:07:40 -0200, Geert Vancompernolle escribi?: > Diez B. Roggisch wrote: >> Geert Vancompernolle schrieb: >>> Hi, >>> >>> I have the following path construction: >>> >>> ./src/__init__.py >>> /main.py >>> /modules/__init__.py >>> /application.py >>> /ui/__init__.py >>> /mainwindow/__init__.py >>> /mainwindow.py >>> >>> Now I want to call the method 'MainWindow' in the module 'mainwindow', >>> from the module 'application'. >>> >>> I'm having the following import statement in 'applications.py': >>> >>> from .. ui.mainwindow.mainwindow import MainWindow >>> >>> That doesn't work. I've also tried many other combinations like from >>> ..ui.mainwindow... but none of them work. >>> >>> I always get the following error: >>> >>> "Attempted relative import beyond toplevel package" >>> >>> How can I import the method 'MainWindow' from 'mainwindow' into >>> 'application', using the explicit relative import rules? >>> >>> Or is there a better way to do this? >>> >> >> Rename "src" to "myapp", and start main.py from above that. That should >> work. >> >> >> >> Diez >> -- http://mail.python.org/mailman/listinfo/python-list >> > That trick did it, thanks! > > But I have one more unclarity about relative import rules. Here > , one > can find an explanation about modules in the official Python 2.6.1 > documentation. > > In that article, there's an example of importing relative packages (in > the section "Packages"). > > I see the following examples: > > from . import echo > from .. import formats > from ..filters import equalizer > > > Applying that mechanism on my application, I'm using the following > construction (see my initial email): > > "from .. ui.mainwindow.mainwindow import MainWindow" > > But using "from ..ui.mainwindow.mainwindow import MainWindow" seems to > be giving exactly the same result (mind the lacking space between ".." > and "ui"). > > So, what's the difference (if there is one) between "from .. > ui.mainwin..." and "from ..ui.mainwin..." (again, mind the difference in > space)? There is none. It's the same as: from . . ui .mainwindow. mainwindow import mainWindow Whitespace is irrelevant here. The quoted examples mean: > from . import echo import the "echo" module/package from the current package > from .. import formats import the "formats" module/package from one level above the current package (if it is a package, it's a sibling directory; if it's a module, it's in the parent directory). > from ..filters import equalizer import only the name "equalizer" from the "filters" module/package, located one level above the current package (same note as previous) > I guess there's a difference, otherwise it would not be given as an > example in the Python documentation. Note that examples 1 and 2 don't have any name in the "from" part; they're like a plain "import echo" or "import formats" (but telling also *where* to search for them, so it's not the same thing). The target is a module/package, as with a plain "import foo". The third example only imports a name from another place (filters), also telling where to search for the module/package. When you eventually grasp the concept (and I'm sure you will), could you think of a better wording/examples to improve the documentation? (I cannot see the deficiencies, just because I *already* know what it means!) -- Gabriel Genellina From nick at stinemates.org Sun Feb 8 15:33:06 2009 From: nick at stinemates.org (nick at stinemates.org) Date: Sun, 8 Feb 2009 12:33:06 -0800 Subject: Best 3d graphics kit for CAD program??? In-Reply-To: <498F1D54.9010509@islandtraining.com> References: <498F1D54.9010509@islandtraining.com> Message-ID: <20090208203306.GA578@beauTy.hsd1.ca.comcast.net> Gary Your email client is set to HTML mode and looks terrible for those of us who prefer plain view. It also appears your client is not properly sending your message in text/plain encoding. From python-list at davidkra.net Sun Feb 8 15:38:22 2009 From: python-list at davidkra.net (David Kraeutmann) Date: Sun, 08 Feb 2009 21:38:22 +0100 Subject: Extracting bytecode out of frozen programs Message-ID: <498F42BE.4060608@davidkra.net> Hello, I need to extract the modules/packages out of a frozen script. It was compiled using Python 2.2.3 and the standard freeze.py. I managed to get a shell after execution using PYTHONINSPECT=y and find the start of a module/package using a hex editor (I got the sta, but these modules don't seem to be importable. Is there a way of extracting them so they are importable in a python shell? Regards, David Kraeutmann From gagsl-py2 at yahoo.com.ar Sun Feb 8 15:40:21 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 08 Feb 2009 18:40:21 -0200 Subject: py2exe and distutils References: <6v69nnFi8bmqU1@mid.individual.net> <6v69rkFi8bmqU2@mid.individual.net> Message-ID: En Sat, 07 Feb 2009 18:39:19 -0200, Thomas Heller escribi?: >> Maxim Demenko schrieb: >>> Hi, >>> i have installed Python 2.5.4 on WinXP, setuptools-0.6c9 and py2exe >>> 0.6.9 >>> Now i can't list installed modules, here is the stacktrace: > [...] >>> Any suggestion, how to fix this issue? >> > Thomas Heller schrieb: >> Looks like a setuptools problem to me. Here's the output on my system: > > Actually, I don't know where the problem is. Maybe pydoc? Yes, pydoc isn't robust enough in 2.5; see for a quick fix. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Sun Feb 8 15:55:13 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 08 Feb 2009 18:55:13 -0200 Subject: Python Module: nift References: <9cb28036-7d5f-4b8a-9748-b26c5e9538b4@r15g2000prd.googlegroups.com> <1eb3e6de-2092-45f8-b270-81845cbe1ed2@h20g2000yqn.googlegroups.com> Message-ID: En Sun, 08 Feb 2009 17:59:41 -0200, escribi?: > More suggestions for a real-world Python programmer: > - There's code duplication, the original poster may express reet as a > composition of the other functions. > - A Python string/list/array can be inverted with [::-1] > - I suggest to convert the examples of the main doscstring into > doctests. > - The main docstring looks too much heavy. > - To convert many ASCII chars there's the str.translate method. > - Generally I suggest to learn to code in the small, using as little > code as possible. I completely agree with all the above suggestions, except this last one. Ok, I think I know what you mean, but a beginner might understand this completely wrong. Readability is important, and trying to compress too much code into one single line should not be the ultimate goal. -- Gabriel Genellina From ptmcg at austin.rr.com Sun Feb 8 15:57:39 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Sun, 8 Feb 2009 12:57:39 -0800 (PST) Subject: Python Module: nift References: <9cb28036-7d5f-4b8a-9748-b26c5e9538b4@r15g2000prd.googlegroups.com> Message-ID: On Feb 8, 12:42?pm, J wrote: > What are your thoughts on this module I created? > Here are a few steps to illustrate some good basic Python idioms worth learning: Step 1: Replace many-branched if-elif with dict While translating characters in a string is a special case that usually warrants using str.translate, a more general-purpose technique to learn is to define a dict that captures the various branching options, and then use the selecting value as a key to access the desired branch. Here is a dict containing your branches: LEET_LETTERS = { "e" : "3", "E" : "3", "a" : "4", "A" : "4", "i" : "1", "I" : "1", "t" : "7", "T" : "7", "s" : "5", "S" : "5", "o" : "0", "O" : "0", "b" : "8", "B" : "8", } Now you can implement leet() using access to the LEET_LETTERS mapping. Here are 3 different versions, that illustrate the usual options when accessing entries from a map: 1. Look before you leet, uh, I mean "leap" (check for key existence before using) 2. Better to ask forgiveness than permission (just use the key and handle the exception that gets raised if the key is not found - an homage to Grace Hopper) 3. Slightly different strategy, using dict.get() method instead of key/ indexing into the dict def leet1(string): outlist = [] for letter in string: if letter in LEET_LETTERS: letter = LEET_LETTERS[letter] outlist.append(letter) return "".join(outlist) def leet2(string): outlist = [] for letter in string: try: letter = LEET_LETTERS[letter] except KeyError: pass outlist.append(letter) return "".join(outlist) def leet3(string): outlist = [] for letter in string: outlist.append( LEET_LETTERS.get(letter,letter) ) return "".join(outlist) You can test each in turn without changing your test code, just assign leet to each of these variants in turn: leet = leet1 print leet("Hello You Beautiful Sweet World!") I'm partial to option number 3, so let me show you a few other helpful tips. By the way, you can do this if you are doing any kind if if-elif, such as: if a=="0": fn_1() elif a=="1": fn_100() elif a=="7": fn_greater_than_five() ... Instead you would write: # note: values are the methods only, no ()'s fns = { "0" : fn_1, "1" : fn_100, "7" : fn_greater_than_five } if a in fns: # get desired function from fns map, and call it fns[a]() Step 2: dict construction instead of {} syntax LEET_LETTERS is so space-consuming, sometimes it is easier to use the dict constructor with a list expression of list comprehension. That is, instead of the built-in syntax P{}'s to define a dict, you can use the dict constructor and pass a list of (key,value) tuples. LEET_LETTERS = dict( [("E","3"), ("e","3"), ("A","4"), ("a","4"), ...] ) Well, my fingers are tired and I'm bored already, how about if we could just list the two strings of key and value characters, and some how build the tuples by pulling an item from each list one at a time. Fortunately, that is what Python's zip() function does: LEET_LETTERS = dict( zip("eEaAiItTsSoObB", "33441177550088") ) (I've listed the key-value pairs one above the other to illustrate how the mapping will work, but of course, that isn't required.) Now if I want to add another leet-speak letter (like "6" for "G"), I just add the two characters on the end of the two strings. Step 3: Use list comprehension instead of explicit list.appends using for loop As was already mentioned in another post, ''.join (list_of_characters_to_join_together) is preferred to final += next_letter_to_add_to_final. But there is also a nice short and clean way to build up the list besides explicitly calling append in a loop. Instead, use a list comprehension. To do this, you convert: outlist = [] for letter in string: outlist.append( LEET_LETTERS.get(letter,letter) ) to: outlist = [ LEET_LETTERS.get(letter,letter) for letter in string ] In fact, Python is so smart, you can skip the list entirely, and just pass that expression inside the brackets (called a generator expression) directly to ''.join: final = ''.join( LEET_LETTERS.get(letter,letter) for letter in string ) Just a "list" is not desired variable name since it masks the built-in list type, I avoid "string" as a name since there is a commonly-used string module. How about just plain "s"? Here is the final version of leet - we even got rid of the variable final, and just return the value that would have been assigned to it: LEET_LETTERS = dict( zip("eEaAiItTsSoObB", "33441177550088") ) def leet(s): return ''.join( LEET_LETTERS.get(c,c) for c in s ) Soon you'll be writing Python just like all the cool kids! -- Paul From blue.indigo at uatel.com.nospam.bogus.invalid.invalid.invalid Sun Feb 8 16:02:37 2009 From: blue.indigo at uatel.com.nospam.bogus.invalid.invalid.invalid (blue indigo) Date: Sun, 08 Feb 2009 16:02:37 -0500 Subject: programming by evolution? References: <42a2e3fc-ec2e-4c09-b456-95a5fc4ce5a2@g39g2000pri.googlegroups.com> <6uuc4eFhc1u1U1@mid.individual.net> <11809792-676f-4d95-87c1-26666cc46b3b@w24g2000prd.googlegroups.com> <03db1c69-828a-4961-914d-62fe10ed88fb@w39g2000prb.googlegroups.com> <6v2sf4Fhuh4mU1@mid.individual.net> Message-ID: On Fri, 06 Feb 2009 14:32:21 +0100, Pascal Costanza wrote: > Xah Lee wrote: >> Pascal Constanza is a Common Lisp fanatic. > > It's Costanza, not Constanza. > > > Thank you, > Pascal +-------------------+ .:\:\:/:/:. | PLEASE DO NOT | :.:\:\:/:/:.: | FEED THE TROLLS | :=.' - - '.=: | | '=(\ 9 9 /)=' | Thank you, | ( (_) ) | Management | /`-vvv-'\ +-------------------+ / \ | | @@@ / /|,,,,,|\ \ | | @@@ /_// /^\ \\_\ @x@@x@ | | |/ WW( ( ) )WW \||||/ | | \| __\,,\ /,,/__ \||/ | | | (______Y______) /\/\/\/\/\/\/\/\//\/\\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ ================================================================== (f'up set to comp.lang.lisp) -- blue indigo UA Telecom since 1987 From sjmachin at lexicon.net Sun Feb 8 16:03:52 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 8 Feb 2009 13:03:52 -0800 (PST) Subject: How to copy an instance without its cStringIO.StringO item ? References: <7F0503CD69378F49BE0DC30661C6CCF60E68778F@enbmail01.lsi.com> Message-ID: On Feb 9, 1:01?am, Christian Heimes wrote: > Barak, Ron schrieb: > > > Hi, > > > I need to copy an instance of a class, where one of the items in the original is a cStringIO.StringO object. > > I do not need the cStringIO.StringO in the target object. > > The target instance is to be pickled. > > > Googling made me devise the following plan: do a deepcopy from the original to the target, and then delete the cStringIO.StringO object from the target. > > > However, trying to use copy.deepcopy produced: TypeError: object.__new__(cStringIO.StringO) is not safe, use cStringIO.StringO.__new__() > > > Is there a way to create a copy of the instance, sans the cStringIO.StringO ? > > > If I find no elegant way to do that, I thought of creating a "blank" target instance; then iterating over the __dict__ of the original, and manually copy the items to the target (while not copying the cStringIO.StringO to the target). > > > Can you suggest a better way ? > > You can overwrite some functions in order to omit attributes from a > pickle. It's all documented athttp://docs.python.org/library/pickle.html#pickling-and-unpickling-no... If there is no chance that some other thread could be accessing the source object, can't the OP just do: temp = source.stringio del source.stringio # make a pickle from source source.stringio = temp ? From gagsl-py2 at yahoo.com.ar Sun Feb 8 16:14:08 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 08 Feb 2009 19:14:08 -0200 Subject: Python3.0 has more duplication in source code than Python2.5 References: <498D3A04.60503@v.loewis.de> <6v58gpFi7nnvU1@mid.uni-berlin.de> Message-ID: On Sun, Feb 8, 2009 at 9:12 AM, Terry wrote: >> I have made the same analysis to some commercial source code, the >> dup60 rate is quite often significantly larger than 15%. En Sun, 08 Feb 2009 07:10:12 -0200, Henry Read escribi?: > I don't think code duplication rate has strong relationship towards code > quality. Not directly; but large chunks of identical code repeated in many places aren't a good sign. I'd question myself if all of them are equally tested? What if someone fixes a bug - will the change be propagated everywhere? Should the code be refactored? -- Gabriel Genellina From martin at v.loewis.de Sun Feb 8 16:19:12 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 08 Feb 2009 22:19:12 +0100 Subject: Extracting bytecode out of frozen programs In-Reply-To: References: Message-ID: <498f4c50$0$30899$9b622d9e@news.freenet.de> > Is there a way of extracting them so they are importable in a python shell? Try imp.get_frozen_object. Regards, Martin From bearophileHUGS at lycos.com Sun Feb 8 16:24:42 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Sun, 8 Feb 2009 13:24:42 -0800 (PST) Subject: Python Module: nift References: <9cb28036-7d5f-4b8a-9748-b26c5e9538b4@r15g2000prd.googlegroups.com> Message-ID: Paul McGuire: > LEET_LETTERS = dict( zip("eEaAiItTsSoObB", "33441177550088") ) > def leet(s): > ? ? return ''.join( LEET_LETTERS.get(c,c) for c in s ) This may be better: from string import maketrans def leet(txt): leet_chars = maketrans("eEaAiItTsSoObB", "33441177550088") return txt.translate(leet_chars) Moving leet_chars outside the function increases speed a bit. Or for more expert Python programmers, you can add an attribute the object function, I don't know if you like this: from string import maketrans def leet(txt): return txt.translate(leet.chars) leet.chars = maketrans("eEaAiItTsSoObB", "33441177550088") It's executes maketrans once only and keeps the namespace tidy. So it's a bit like a static variable in other languages. Bye, bearophile From clp2 at rebertia.com Sun Feb 8 16:28:55 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 8 Feb 2009 13:28:55 -0800 Subject: Python Module: nift In-Reply-To: References: <9cb28036-7d5f-4b8a-9748-b26c5e9538b4@r15g2000prd.googlegroups.com> Message-ID: <50697b2c0902081328m143f6e45l8c6425022ed2b9bc@mail.gmail.com> On Sun, Feb 8, 2009 at 12:57 PM, Paul McGuire wrote: > On Feb 8, 12:42 pm, J wrote: >> What are your thoughts on this module I created? >> > Here are a few steps to illustrate some good basic Python idioms worth > learning: > > Step 1: Replace many-branched if-elif with dict > > While translating characters in a string is a special case that > usually warrants using str.translate, a more general-purpose technique > to learn is to define a dict that captures the various branching > options, and then use the selecting value as a key to access the > desired branch. > Here is a dict containing your branches: > > LEET_LETTERS = { > "e" : "3", > "E" : "3", > "a" : "4", > "A" : "4", > "i" : "1", > "I" : "1", > "t" : "7", > "T" : "7", > "s" : "5", > "S" : "5", > "o" : "0", > "O" : "0", > "b" : "8", > "B" : "8", > } > LEET_LETTERS is so space-consuming, sometimes it is easier to use the > dict constructor with a list expression of list comprehension. That > is, instead of the built-in syntax P{}'s to define a dict, you can use > the dict constructor and pass a list of (key,value) tuples. > > LEET_LETTERS = dict( [("E","3"), ("e","3"), ("A","4"), > ("a","4"), ...] ) > > Well, my fingers are tired and I'm bored already, how about if we > could just list the two strings of key and value characters, and some > how build the tuples by pulling an item from each list one at a time. > Fortunately, that is what Python's zip() function does: > > LEET_LETTERS = dict( zip("eEaAiItTsSoObB", > "33441177550088") ) > > (I've listed the key-value pairs one above the other to illustrate how > the mapping will work, but of course, that isn't required.) > > Now if I want to add another leet-speak letter (like "6" for "G"), I > just add the two characters on the end of the two strings. This I disagree with as being unnecessarily clever; the dict literal is just fine as-is and the zip() makes it less clear. However, I would definitely rewrite the dict to use less lines, which, after removing the capital dupes (as I mentioned in my post, just use .lower()), looks like: LEET_LETTERS = {"e" : "3", "a" : "4", "i" : "1", "t" : "7", "s" : "5", "o" : "0", "b" : "8"} which is better, IMHO. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From REMpeteOVE at CAPpetezilla.ITALSco.uk Sun Feb 8 16:32:53 2009 From: REMpeteOVE at CAPpetezilla.ITALSco.uk (Peter Chant) Date: Sun, 08 Feb 2009 21:32:53 +0000 Subject: Newbie SWMixer / numpy help - AssertionError References: Message-ID: <5lv366x8tf.ln2@phoenix.fire> Robert Kern wrote: > > snd = swmixer.Sound(data=tone_data) > > Well, sort of. You probably need to scale your data and convert it to > int16 format. It's currently in floating point format. Done and working, thanks. As "file" was not needed for file="test.wav" I assumed the data prefix for data was not essential. > > When asking about why something fails, it helps a lot if you specify > exactly how it fails and what you expected to happen. Copy-and-paste any > error messages exactly. OK > > If you need more help with SWMixer's API, I recommend asking the author. > It's not in widespread use, so he can probably give you better and faster > help than we can. > > If you need more help with numpy, specifically, you can ask on the > numpy-discussion mailing list. numpy *is* in widespread use, but there's a > higher concentration of helpful numpy users over there. > > http://www.scipy.org/Mailing_Lists > Most useful response, thanks. Pete -- http://www.petezilla.co.uk From bearophileHUGS at lycos.com Sun Feb 8 16:34:50 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Sun, 8 Feb 2009 13:34:50 -0800 (PST) Subject: Python Module: nift References: <9cb28036-7d5f-4b8a-9748-b26c5e9538b4@r15g2000prd.googlegroups.com> <1eb3e6de-2092-45f8-b270-81845cbe1ed2@h20g2000yqn.googlegroups.com> Message-ID: <838a342c-64e0-4c97-a0d0-9e2475696f74@z1g2000yqn.googlegroups.com> Gabriel Genellina: > bearophile: > > - Generally I suggest to learn to code in the small, using as little > > code as possible. > > I completely agree with all the above suggestions, except this last one. ? > Ok, I think I know what you mean, but a beginner might understand this ? > completely wrong. Readability is important, and trying to compress too ? > much code into one single line should not be the ultimate goal. What I meant is to use less code as possible, keeping readability and the original flexibility. I can't stress enough the importance of writing less code. Every new programmer has to learn how much important it is. Less code means less bugs, less lines to edit and debug, etc. Less code is usually more elegant, and often more readable (even if you take 3 times to read each line it may be good anyway if you have 1/10 of the lines of code. Recently in the "Java to Python" thread someone has posted some Java class that is scary, you can probably write the same thing in 1/10-1/20 of the lines of code). The sense for "elegance" in coding is of course (as in every other human activity) something you learn after many years of exercise, it's a matter of balance among many opposite things, a matter of compromises, and it's also tight related with your personal style of coding. Every programmer develops tastes and and one or more styles, that other people may not appreciate much. Bye, bearophile From gagsl-py2 at yahoo.com.ar Sun Feb 8 16:43:56 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 08 Feb 2009 19:43:56 -0200 Subject: Extracting bytecode out of frozen programs References: <498F42BE.4060608@davidkra.net> Message-ID: En Sun, 08 Feb 2009 18:38:22 -0200, David Kraeutmann escribi?: > Hello, > I need to extract the modules/packages out of a frozen script. It was > compiled using Python 2.2.3 and the standard freeze.py. > I managed to get a shell after execution using PYTHONINSPECT=y and find > the start of a module/package using a hex editor (I got the sta, but > these modules don't seem to be importable. > Is there a way of extracting them so they are importable in a python > shell? Those modules are exposed via the PyImport_FrozenModules array. The ctypes documentation has an example for accessing this array, see http://docs.python.org/library/ctypes#accessing-values-exported-from-dlls -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Sun Feb 8 17:12:44 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 08 Feb 2009 20:12:44 -0200 Subject: Extracting bytecode out of frozen programs References: <498f4c50$0$30899$9b622d9e@news.freenet.de> Message-ID: En Sun, 08 Feb 2009 19:19:12 -0200, Martin v. L?wis escribi?: >> Is there a way of extracting them so they are importable in a python >> shell? > > Try imp.get_frozen_object. Ouch... this looks better than using ctypes. get_frozen_object exists at least since 1.5.2, but has never been documented, and the source code says it's obsolete. Should be documented now? Any alternative? -- Gabriel Genellina From vitaliyy at gmail.com Sun Feb 8 17:32:13 2009 From: vitaliyy at gmail.com (Vitaliy Yermolenko) Date: Mon, 9 Feb 2009 00:32:13 +0200 Subject: Python on TV-centric platforms Message-ID: Hi, Thanks for thoughts. As I can see considering Yahoo Widgets (based on HTML/JavaScript/Flash), XML, AJAX and JavaScript (i. e. web components) on Figure 1 of http://www.intelconsumerelectronics.com/Consumer-Electronics-3.0/Widget-Channel-Overview.aspx, it seems, like Pyjamas is more close for Widget Channel integration, than XBMC Media Center. Another question is whether Framework API will be available for Python, and how deployment will be done? >On Feb 8, 9:23 am, Vitaliy Yermolenko wrote: >> Any chance to see Python to be ready for "Widget Development Kit (WDK) >> to third-party developers to create applications and services for >> viewing on TVs [...] > >The excellent XBMC[1] has had Python support for years. WBR, Vitaliy. From seaworthyjeremy at gmail.com Sun Feb 8 17:45:52 2009 From: seaworthyjeremy at gmail.com (J) Date: Sun, 8 Feb 2009 14:45:52 -0800 (PST) Subject: Python Module: nift References: <9cb28036-7d5f-4b8a-9748-b26c5e9538b4@r15g2000prd.googlegroups.com> Message-ID: Thanks for your answers, especially Chris Rebert and Paul McGuire's. I have a question: How far does Python go in the Game Development field? (Using Python only, no extensions) From clp2 at rebertia.com Sun Feb 8 17:55:53 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 8 Feb 2009 14:55:53 -0800 Subject: Python Module: nift In-Reply-To: References: <9cb28036-7d5f-4b8a-9748-b26c5e9538b4@r15g2000prd.googlegroups.com> Message-ID: <50697b2c0902081455w15408f4aof04fedd80ec862d7@mail.gmail.com> On Sun, Feb 8, 2009 at 2:45 PM, J wrote: > Thanks for your answers, especially Chris Rebert and Paul McGuire's. I > have a question: > How far does Python go in the Game Development field? (Using Python > only, no extensions) You pretty much need to integrate with some C(++) libraries in order to write fancier games. However, you yourself don't need to write any non-Python in order to utilize these libraries. Pygame (http://www.pygame.org/) is a popular collection of multimedia library bindings for Python. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From jstroud at mbi.ucla.edu Sun Feb 8 17:58:37 2009 From: jstroud at mbi.ucla.edu (James Stroud) Date: Sun, 08 Feb 2009 14:58:37 -0800 Subject: TkInter: Problem with propagation of resize events through geometry manager hierarchy? In-Reply-To: <35dc67a4-aa61-4e88-a79c-64118c1285e7@o11g2000yql.googlegroups.com> References: <35dc67a4-aa61-4e88-a79c-64118c1285e7@o11g2000yql.googlegroups.com> Message-ID: curiouserrandy at gmail.com wrote: > Thanks! I hadn't known about the "return 'break'" technique. But > I don't follow your sentinel suggestion; how would that sentinel > ever get reset? Presumably you would set it from some kind of input. Basically, if you don't need to zoom, you wouldn't bother scaling the image. It is the scaling step that is expanding your image. You might want to set any borders to 0. It seems as if the first time through the event > chain it'd be set to the sentinel, and the routines that pay > attention to it would never execute. What am I missing? > I tried simply returning 'break' at the end of "refresh()" and > that made no change in behavior. You will want to return 'break' at the end of callbacks, like display_tag_and_size() > One thing I've been looking for (including in the source :-J) is > a description of the precise process that the geometry manager > goes through in figuring out and then setting sizes for the > various widgets (on resize or, apparently, startup). I suspect > with that + the "return 'break'" technique I could get this to > work. But I haven't been having any luck finding that documentation. I've never found that either. I usually tweak things by trial and error. Tkinter (Tk) has some bad habits. Most of the time it is very hard to get the precise dimensions of widgets by asking them. The problem is exacerbated by platform specific modifications like TkAqua. Ive found the best approach is to tweak the math so that the sizing comes out consistent and then test and patch for every platform you support. Sometimes, if you experiment enough, you can figure out by inference what Tk is actually doing under the hood. The other, more sane option, is to attempt to make guis that don't rely on precise size information. Its less satisfying than the pixel level control one hopes for, but makes for a faster development process. Also, you might want to look into Pmw. It has scrolled canvas and scrolled frame widgets that might be helpful to you. There is no need to reinvent the wheel except for your own enlightenment. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com From martin at v.loewis.de Sun Feb 8 18:01:18 2009 From: martin at v.loewis.de (=?ISO-8859-15?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 09 Feb 2009 00:01:18 +0100 Subject: Extracting bytecode out of frozen programs In-Reply-To: References: <498f4c50$0$30899$9b622d9e@news.freenet.de> Message-ID: <498f643e$0$3360$9b622d9e@news.freenet.de> > get_frozen_object exists at least since 1.5.2, but has never been > documented, and the source code says it's obsolete. Should be documented > now? Any alternative? get_frozen_object has been marked obsolete in 1997. Whether it can be un-deprecated should be discussed on python-dev; I can't guess the rationale for deprecating it. Regards, Martin From rhamph at gmail.com Sun Feb 8 18:05:31 2009 From: rhamph at gmail.com (Rhamphoryncus) Date: Sun, 8 Feb 2009 15:05:31 -0800 (PST) Subject: Flattening lists References: <9a8af8a3-27fb-4f5b-90ea-ee0276c7e5e3@r15g2000prd.googlegroups.com> <9c2ed038-7a9b-4a35-adae-8b0df890040e@k36g2000pri.googlegroups.com> <76695d3b-bc74-4b72-b0ee-0c646d228b6f@t13g2000yqc.googlegroups.com> <20090207213917.24c8433a@gmx.net> <20090207230719.5bfd6022@gmx.net> Message-ID: On Feb 7, 3:07?pm, wrote: > On Sat, 7 Feb 2009 12:50:22 -0800 (PST) > Rhamphoryncus wrote: > > Can you explain this in a little more detail? > > In the application, there is one main numpy array of type "O". > Each element of the array corresponds to one cell in a grid. The user > may enter a Python expression into the grid cell. The input is > evaled and the result is stored in the numpy array (the actual process > is a bit more complicated). Therefore, the object inside a numpy array > element may be an inconsistent, nested, iterable type. > > The user now may access the result grid via __getitem__. When doing > this, a numpy array that is as flat as possible while comprising the > maximum possible data depth is returned, i.e.: > > 1. Non-string and non-unicode iterables of similar length for each of > the cells form extra dimensions. > > 2. In order to remove different container types, the result is > flattened, cast into a numpy.array and re-shaped. > > 3. Dimensions of length 1 are eliminated. > > Therefore, the user can conveniently use numpy ufuncs on the results. > > I am referring to the flatten operation in step 2 I'm afraid I still don't understand it, but I'm only minimally familiar with numpy, nevermind your spreadsheet app. From gdamjan at gmail.com Sun Feb 8 18:21:16 2009 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Mon, 09 Feb 2009 00:21:16 +0100 Subject: Python3.0 has more duplication in source code than Python2.5 References: <498D3A04.60503@v.loewis.de> <6v58gpFi7nnvU1@mid.uni-berlin.de> Message-ID: > I have made the same analysis to some commercial source code, the > dup60 rate is quite often significantly larger than 15%. commercial code sucks often .. that's why they hide it :) -- ?????? ( http://softver.org.mk/damjan/ ) Scarlett Johansson: You always see the glass half-empty. Woody Allen: No. I see the glass half-full, but of poison. From tdelaney at avaya.com Sun Feb 8 18:31:36 2009 From: tdelaney at avaya.com (Delaney, Timothy (Tim)) Date: Mon, 9 Feb 2009 07:31:36 +0800 Subject: Ordered dict by default In-Reply-To: <6f38e8bc-4ecd-4b9f-abef-b885cd16b375@p37g2000yqd.googlegroups.com> Message-ID: bearophileHUGS at lycos.com wrote: > I have missed another example: It may be possible to create a sorting > routine that's not stable but is faster than the current stable > timsort (for example in C++ STL you have both sorting routines, and > the unstable one is a variant of introsort that is faster than the > stable version). I think Python will keep the stable one, because even > if (in theory. In practice it may be quite difficult to write such > unstable sorter faster than timsort) it can be slower, it's safer and > more useful than an unstable sort. Python mandates a stable sort, so this will not change. Note that this used to not be the case - timsort was introduced in Python 2.3, and *because* it was *both* stable and blazingly fast, the requirement for a stable sort was back-dated to Python 2.3. If timsort had not been so overwhelmingly superior to every other option at the time (and in particular, without any known worst-case scenarios) then Python would likely still not be requiring a stable sort. But because it is so good, the extra performance gain from any future non-stable sort was considered unlikely to offset the benefits of a stable sort. Tim Delaney From spacebar265 at gmail.com Sun Feb 8 22:26:13 2009 From: spacebar265 at gmail.com (Spacebar265) Date: Sun, 8 Feb 2009 19:26:13 -0800 (PST) Subject: Scanning a file character by character References: Message-ID: <557daab0-504f-47f4-84a7-e98000e7c3b1@y1g2000pra.googlegroups.com> On Feb 7, 2:17?am, Jorgen Grahn wrote: > On Wed, 4 Feb 2009 22:48:13 -0800 (PST), Spacebar265 wrote: > > Hi. Does anyone know how to scan a filecharacterbycharacterand > > have eachcharacterso I can put it into a variable. I am attempting > > to make a chatbot and need this to read the saved input to look for > > spelling mistakes and further analysis of user input. > > That does not follow. To analyze a text, the worst possible starting > point is one variable for eachcharacter(what would you call them -- > character_1, character_2, ... character_65802 ?) > > /Jorgen > > -- > ? // Jorgen Grahn \X/ ? ? snipabacken.se> ? ? ? ? ?R'lyeh wgah'nagl fhtagn! How else would you check for spelling mistakes? Because input would be very unlikely to be lengthy paragraphs I wouldn't even need very many variables. If anyone could suggest an alternative method this would be much appreciated. From ptmcg at austin.rr.com Sun Feb 8 23:01:25 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Sun, 8 Feb 2009 20:01:25 -0800 (PST) Subject: Python Module: nift References: <9cb28036-7d5f-4b8a-9748-b26c5e9538b4@r15g2000prd.googlegroups.com> Message-ID: <947d4cef-e3f2-4e1b-91ff-5f98781f0518@t13g2000yqc.googlegroups.com> On Feb 8, 3:28?pm, Chris Rebert wrote: > This I disagree with as being unnecessarily clever; the dict literal > is just fine as-is and the zip() makes it less clear. However, I would > definitely rewrite the dict to use less lines, which, after removing > the capital dupes (as I mentioned in my post, just use .lower()), > looks like: > > LEET_LETTERS = {"e" : "3", "a" : "4", "i" : "1", "t" : "7", "s" : "5", > ? ? "o" : "0", "b" : "8"} > Maybe so, I was trying to illustrate zip() and maybe this was getting too far ahead for a new Python user. I *do* find that when initializing a list of characters (and for some reason a string wont do), then instead of this: vowels = ["A", "E", "I", "O", "U"] using the list constructor is much easier: vowels = list("AEIOU") Or more non-deterministically, sometimes = lambda s : [s] if random.random() > 0.5 else [] vowels = list("AEIOU") + sometimes("Y") -- Paul From kyrie at uh.cu Sun Feb 8 23:01:46 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Sun, 08 Feb 2009 23:01:46 -0500 Subject: Importing a file (not a module). Message-ID: <1234152106.498faaaa97f1d@mail.uh.cu> Is there any way to "import" a .py file that is not on sys.path? I'd like to 'import' a file that resides somewhere on my filesystem without having to add it's directory to sys.path. At first, I thought that something like my_module = __import__("path/to/file") would work, but I was mistaken. Ideally, the path would be specified as a relative path from the importer's module, and not from the CWD (that's another question, I guess). Related question: how could I change the sys.path for this_script.py without changing it much? I'd like to have this_script a few more directories on its pythonpath, but I don't want to clutter the begining of the script with "sys.path.append(...)"s, specially because I need to do that for several scripts. I thought of creating a modify_pythonpath.py and import it from all of them, but I don't want to keep that script on the global python path nor on any of the project folders (it is required by more than one). Currently I have a symlink from the original modify_pythonpath.py to each project directory, but that seems clumsy. -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie From gagsl-py2 at yahoo.com.ar Sun Feb 8 23:06:10 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 09 Feb 2009 02:06:10 -0200 Subject: [2.5.1] Comparing dates? References: <87bptl1a4l.fsf@benfinney.id.au> <5tkdo4l21dkm9kgv4ra4pftker89odebfu@4ax.com> Message-ID: En Wed, 04 Feb 2009 14:11:07 -0200, Gilles Ganault escribi?: > On Mon, 2 Feb 2009 22:00:53 +0100, Martin wrote: >> as suggested, the DBA should seriously think about defining the >> correct type of the column here, for intermediate use and getting >> stuff to work you could use a view and define some stored procedures >> on it so that inserting properly works... > > Right, but SQLite only has two types: Numeric or text, so I figured > it'd be better to turn dates into the usual YYYY-MM-DD before saving > data into an SQLite file. I'd use the built-in adapter/converter instead of rolling my own: http://docs.python.org/library/sqlite3.html#default-adapters-and-converters -- Gabriel Genellina From steve at holdenweb.com Sun Feb 8 23:13:08 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 08 Feb 2009 23:13:08 -0500 Subject: Scanning a file character by character In-Reply-To: <557daab0-504f-47f4-84a7-e98000e7c3b1@y1g2000pra.googlegroups.com> References: <557daab0-504f-47f4-84a7-e98000e7c3b1@y1g2000pra.googlegroups.com> Message-ID: Spacebar265 wrote: > On Feb 7, 2:17 am, Jorgen Grahn wrote: >> On Wed, 4 Feb 2009 22:48:13 -0800 (PST), Spacebar265 wrote: >>> Hi. Does anyone know how to scan a filecharacterbycharacterand >>> have eachcharacterso I can put it into a variable. I am attempting >>> to make a chatbot and need this to read the saved input to look for >>> spelling mistakes and further analysis of user input. >> That does not follow. To analyze a text, the worst possible starting >> point is one variable for eachcharacter(what would you call them -- >> character_1, character_2, ... character_65802 ?) >> I believe most people would read the input a line at a time and split the lines into words. It does depend whether you are attempting real-time spelling correction, though. That would be a different case. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sun Feb 8 23:24:51 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 08 Feb 2009 23:24:51 -0500 Subject: Importing a file (not a module). In-Reply-To: <1234152106.498faaaa97f1d@mail.uh.cu> References: <1234152106.498faaaa97f1d@mail.uh.cu> Message-ID: Luis Zarrabeitia wrote: > Is there any way to "import" a .py file that is not on sys.path? > I'd like to 'import' a file that resides somewhere on my filesystem without > having to add it's directory to sys.path. At first, I thought that something like > > my_module = __import__("path/to/file") > > would work, but I was mistaken. Ideally, the path would be specified as a > relative path from the importer's module, and not from the CWD (that's another > question, I guess). > > Related question: how could I change the sys.path for this_script.py without > changing it much? I'd like to have this_script a few more directories on its > pythonpath, but I don't want to clutter the begining of the script with > "sys.path.append(...)"s, specially because I need to do that for several > scripts. I thought of creating a modify_pythonpath.py and import it from all of > them, but I don't want to keep that script on the global python path nor on any > of the project folders (it is required by more than one). > > Currently I have a symlink from the original modify_pythonpath.py to each > project directory, but that seems clumsy. > Take a look at the imp module: >>> import imp >>> m = imp.load_source("mymodule", "doors.px") ['G', 'G', 'G'] [1, 1] [1, 1, 1] ['G', 'G', 'C'] [1, 1] [1, 1] ['G', 'C', 'G'] [1] [1, 1] ['G', 'C', 'C'] [1] [1] ['C', 'G', 'G'] [1] [1, 1] ['C', 'G', 'C'] [1] [1] ['C', 'C', 'G'] [] [1] ['C', 'C', 'C'] [] [] >>> m >>> import sys >>> sys.modules['mymodule'] >>> As you can see it works with non-standarde xtensions too. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From cptn.spoon at gmail.com Sun Feb 8 23:50:49 2009 From: cptn.spoon at gmail.com (cptn.spoon) Date: Sun, 8 Feb 2009 20:50:49 -0800 (PST) Subject: Simple question - stock market simulation Message-ID: <6d242a86-c0bc-4c1d-8c38-b263e128bd02@n33g2000pri.googlegroups.com> I'm trying to create an incredibly simple stock market simulator to be used in a childrens classroom and I'm wondering whether someone can point me in the right direction. I basically want to be able to have a stock struct as follows: StockName = "Test" StockPriceList = (12,13,12,10,10,8,10) StockRisk = 0.15 StockQty = 2000 And then have a StockMarket struct that can contain 1 to many Stocks. I then want to be able to iterate through the stocks to perform operations as such: for Stock in StockMarket: I'm not asking for tips on the program itself, I just can't figure out how to get the data structures in place. Would I use Classes or would I use dictionaries? Am I completely off the mark with this? Apologies for such a rudimentary question...I'm very new to all this. From http Sun Feb 8 23:58:54 2009 From: http (Paul Rubin) Date: 08 Feb 2009 20:58:54 -0800 Subject: Simple question - stock market simulation References: <6d242a86-c0bc-4c1d-8c38-b263e128bd02@n33g2000pri.googlegroups.com> Message-ID: <7xljsgyzn5.fsf@ruckus.brouhaha.com> "cptn.spoon" writes: > I'm not asking for tips on the program itself, I just can't figure out > how to get the data structures in place. Would I use Classes or would > I use dictionaries? Am I completely off the mark with this? Typically you would use a class for the multi-fielded data structure; a dictionary is intended more for lookup tables where you don't know ahead of time what the keys will be. Also, you'd typically use a list [1,2,3] rather than a tuple (1,2,3) to hold the price list. From cptn.spoon at gmail.com Mon Feb 9 00:10:54 2009 From: cptn.spoon at gmail.com (cptn.spoon) Date: Sun, 8 Feb 2009 21:10:54 -0800 (PST) Subject: Simple question - stock market simulation References: <6d242a86-c0bc-4c1d-8c38-b263e128bd02@n33g2000pri.googlegroups.com> <7xljsgyzn5.fsf@ruckus.brouhaha.com> Message-ID: <1c244978-3224-4a5c-a9d9-60cb2337660e@x6g2000pre.googlegroups.com> On Feb 9, 3:58?pm, Paul Rubin wrote: > "cptn.spoon" writes: > > I'm not asking for tips on the program itself, I just can't figure out > > how to get the data structures in place. Would I use Classes or would > > I use dictionaries? Am I completely off the mark with this? > > Typically you would use a class for the multi-fielded data structure; > a dictionary is intended more for lookup tables where you don't know > ahead of time what the keys will be. ?Also, you'd typically use a list > [1,2,3] rather than a tuple (1,2,3) to hold the price list. Thanks Paul! I thought this might be the case. So how would I get the StockMarket class instance to contain many Stock class instances and then be able to iterate through them? I'm guessing the basic structure would be as follows...but I think I'm wrong: class StockMarket: pass class Stock: def __init__(self, stockname, stockpricelist[], stockrisk, stockqty): self.stockname = stockname self.stockpricelist[] = stockpricelist[] self.stockrisk = stockrisk self.stockqty = stockqty Can you possibly point me in the right direction? Thanks Phil From gherron at islandtraining.com Mon Feb 9 00:44:28 2009 From: gherron at islandtraining.com (Gary Herron) Date: Sun, 08 Feb 2009 21:44:28 -0800 Subject: Best 3d graphics kit for CAD program??? In-Reply-To: <20090208203306.GA578@beauTy.hsd1.ca.comcast.net> References: <498F1D54.9010509@islandtraining.com> <20090208203306.GA578@beauTy.hsd1.ca.comcast.net> Message-ID: <498FC2BC.2070300@islandtraining.com> nick at stinemates.org wrote: > Gary > > Your email client is set to HTML mode and looks terrible for those of us > who prefer plain view. It also appears your client is not properly > sending your message in text/plain encoding. > > > -- > http://mail.python.org/mailman/listinfo/python-list > Understood. I too prefer text only, but mistakenly hit "HTML only" for that email. Once sent, though, there was no way to recall and fix it. From http Mon Feb 9 00:48:59 2009 From: http (Paul Rubin) Date: 08 Feb 2009 21:48:59 -0800 Subject: Simple question - stock market simulation References: <6d242a86-c0bc-4c1d-8c38-b263e128bd02@n33g2000pri.googlegroups.com> <7xljsgyzn5.fsf@ruckus.brouhaha.com> <1c244978-3224-4a5c-a9d9-60cb2337660e@x6g2000pre.googlegroups.com> Message-ID: <7x7i4017p0.fsf@ruckus.brouhaha.com> "cptn.spoon" writes: > def __init__(self, stockname, stockpricelist[], stockrisk, > stockqty): ... You would say just stockpricelist rather than stockpricelist[], but other than that your class def looks good. From tjreedy at udel.edu Mon Feb 9 01:29:02 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 09 Feb 2009 01:29:02 -0500 Subject: Python Module: nift In-Reply-To: <9cb28036-7d5f-4b8a-9748-b26c5e9538b4@r15g2000prd.googlegroups.com> References: <9cb28036-7d5f-4b8a-9748-b26c5e9538b4@r15g2000prd.googlegroups.com> Message-ID: J wrote: > What are your thoughts on this module I created? > > ''' > A Python Module created by a High School Student. > Includes rev(), reet(), and leet(). Gutsy of you to post this. > Setup: > * Save to Python Directory\Lib\ as nift.py Add-in modules and packages like this should better go in pythonxy/Lib/site-packages, which is there just for this purpose. One can then easily see what add-ons ore present or not, or delete them, or avoid deletion with uninstallation, or move to another version of Python. tjr From tjreedy at udel.edu Mon Feb 9 01:33:24 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 09 Feb 2009 01:33:24 -0500 Subject: Lists implemented as integer-hashed Dictionaries? In-Reply-To: References: <775033410902061918l3a16c8fi82329b8f6f244daa@mail.gmail.com> <50697b2c0902061925w36ed850bw796f6737c15e06af@mail.gmail.com> <775033410902061932g6f943500s267d07f68accef98@mail.gmail.com> <7a9c25c20902062047y8afacb8xd0ab1649d7ab843e@mail.gmail.com> Message-ID: Christian Heimes wrote: > > Sets are basically dicts without values. For CPython true, but abstractly, dicts are sets with values, and mappings are often viewed as sets of key,value pairs. From tjreedy at udel.edu Mon Feb 9 01:43:28 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 09 Feb 2009 01:43:28 -0500 Subject: Simple question - stock market simulation In-Reply-To: <1c244978-3224-4a5c-a9d9-60cb2337660e@x6g2000pre.googlegroups.com> References: <6d242a86-c0bc-4c1d-8c38-b263e128bd02@n33g2000pri.googlegroups.com> <7xljsgyzn5.fsf@ruckus.brouhaha.com> <1c244978-3224-4a5c-a9d9-60cb2337660e@x6g2000pre.googlegroups.com> Message-ID: cptn.spoon wrote: > On Feb 9, 3:58 pm, Paul Rubin wrote: >> "cptn.spoon" writes: >>> I'm not asking for tips on the program itself, I just can't figure out >>> how to get the data structures in place. Would I use Classes or would >>> I use dictionaries? Am I completely off the mark with this? >> Typically you would use a class for the multi-fielded data structure; >> a dictionary is intended more for lookup tables where you don't know >> ahead of time what the keys will be. Also, you'd typically use a list >> [1,2,3] rather than a tuple (1,2,3) to hold the price list. > > Thanks Paul! I thought this might be the case. So how would I get the > StockMarket class instance to contain many Stock class instances and > then be able to iterate through them? I'm guessing the basic structure > would be as follows...but I think I'm wrong: > > class StockMarket: > pass > I would start with using a list for StockMarket. > class Stock: > def __init__(self, stockname, stockpricelist[], stockrisk, > stockqty): > self.stockname = stockname > self.stockpricelist[] = stockpricelist[] > self.stockrisk = stockrisk > self.stockqty = stockqty I would remove the redundant 'stock' from all the parameter and attribute names. (And call 'qty' 'quantity'.) You will iterating like so: for stock in StockMarket: print(stock.name, stock.quantity,.... or whatever, and the iteration variable makes clear that a stock is a Stock. tjr From mail at johnohagan.com Mon Feb 9 01:45:39 2009 From: mail at johnohagan.com (John O'Hagan) Date: Mon, 9 Feb 2009 06:45:39 +0000 Subject: self-aware list of objects able to sense constituent member alterations? In-Reply-To: <6c42d5ee-7bd1-4741-8d80-51c611790699@z28g2000prd.googlegroups.com> References: <3043ae5c-0168-4249-8a21-63d0268b36f1@k36g2000pri.googlegroups.com> <6c42d5ee-7bd1-4741-8d80-51c611790699@z28g2000prd.googlegroups.com> Message-ID: <200902090645.40793.mail@johnohagan.com> On Fri, 6 Feb 2009, greywine at gmail.com wrote: > On Jan 28, 4:37?am, John O'Hagan wrote: > > On Tue, 27 Jan 2009, Reckoner wrote: > > > I'm not sure this is possible, but I would like to have > > > a list of ?objects > > > > > > A=[a,b,c,d,...,z] > > > > > > where, ?in the midst of a lot of processing I might do something like, > > > > > > A[0].do_something_which_changes_the_properties() > > > > > > which alter the properties of the object 'a'. > > > > > > The trick is that I would like A to be mysteriously aware that > > > something about the ?object 'a' has changed so that when I revisit A, > > > I will know that the other items in the list need to be refreshed to > > > reflect the changes in A as a result of changing 'a'. > > > > > > Even better would be to automatically percolate the subsequent changes > > > that resulted from altering 'a' for the rest of the items in the list. > > > > [...] > > > > Interesting question. > > > > Maybe this is too simple for your purpose (or maybe just wrong!), but > > could you subclass list and give it an "update" method which keeps a > > dictionary of the state of its members and/or calls another method that > > makes the appropriate changes in the other members when a change occurs, > > something like: > > > > class SelfAwareList(list): > > > > ? ? state_dict = {} > > > > ? ? def update(self): > > ? ? ? ? for i in self: > > ? ? ? ? ? ? if i.state == 'some_condition': > > ? ? ? ? ? ? ? ? self.do_stuff_to_other_members() > > ? ? ? ? ? ? self.state_dict[i] = i.state > > > > ? ? def do_stuff_to_other_members(self): > > ? ? ? ? print 'doing stuff...' > > > > ? > > > > You could manually call update() on the SelfAwareList instance after > > calling a method on a SelfAwareList member, or even build it into the > > members' methods so that it was automatic. > > > > HTH, > > > > John > > Hi Reckoner & John O'Hagan, > > Great thread, very interesting. > > John, I haven't seen anything like your class that uses list instead > of object and refers to state directly (i.state in self). Could you > elaborate? Here would be my implementation of your idea: > > class SelfAwareList2(object): > > def __init__(self, l): > self.l = l > self.changed = [False for element in l] > > def __str__(self): > return str(self.l) > > def update(self, index, value): > self.l[index] = value > self.changed[index] = True > > def do_stuff_to_other_members(self): > for i in self.changed: > if i==False: > self.l[i] += 1 > > Here you can print and whenever you update your list, self.changed > keeps track of what changed. Later on you can call do_stuff_to_others > which in this case adds 1 to each other element. > > I assume that your class replaces the awkwardness of l.update(0, 5) > with l[0] = 5, but I can't quite wrap my mind around it. I think my suggestion was much more simplistic than what the OP was after, which was far more thoroughly answered by others. But as far as my version goes, your implementation is fine as far as I can tell; although I (possibly mistakenly) interpreted the OP as wanting something which kept track of _how_ the items in the list changed, not just _if_ they changed. Trying to put together an example was (naturally) more complicated than I thought, but here's a silly one, with apologies to Steven D'Aprano among others for stealing the parrot theme: class Parrot(object): def __init__(self, name): self.color = 'red' self.name = name def __repr__(self): return self.name class SelfAwareListOfParrots(list): colors = ['red', 'blue', 'yellow', 'green', 'black', 'white'] state_dict = {} def update(self, changed=None): """Ensure no duplicate colors and record changes""" for parrot in self: used_colors = [parrot.color for parrot in self] available_colors = [color for color in self.colors if color not in used_colors] if (parrot is not changed and used_colors.count(parrot.color) > 1): parrot.color = available_colors[0] self.state_dict[parrot] = parrot.color def change(self, parrot, color): """Change color and update""" self[self.index(parrot)].color = color self.update(parrot) This list knows when a parrot has had its color changed by calling change() on the list, and makes sure no parrots are the same color by changing any parrots of duplicate color. It has a state_dict attribute (redundant in this example) which keeps track of the colors after an update. (My version of the update method updates the whole list). The trick is to have the method that changes the elements of the list defined in the list class definition, rather than that of the elements' class, that way it's easy for the list to know about changes to its elements. (If a parrots color is changed directly, update() will still ensure unique colors, but will not preserve the change unless that parrot is given as an argument.) For example: polly = Parrot('polly') molly = Parrot('molly') dolly = Parrot('dolly') salp = SelfAwareListOfParrots([polly, molly, dolly]) print salp.state_dict >>>{molly: 'yellow', polly: 'white', dolly: 'black'} salp.change(polly, 'black') print salp.state_dict >>>{molly: 'yellow', polly: 'black', dolly: 'white'} As for the subclassing of list, that allows you to create a class with all the methods of a list, to which you can add your own. (Although any list methods which return a new list will return a list, not an instance of your class, unless you define them to do so in your class definition). In my post quoted above, by "i.state" I was probably abusing the term "state" to signify "some arbitrary attribute" of i. I'm pretty new to this stuff, but there are plenty of tutorials on it out there, and I'm relying on others to correct any fallacies I may be unwittingly propagating here. :) Regards, John From aleksandr.goretoy at gmail.com Mon Feb 9 01:48:27 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Mon, 9 Feb 2009 00:48:27 -0600 Subject: GAE open() Message-ID: Hello, How to open binary file for writing into datastore. I'm trying to loop over listdir output of images directory, How to do this without using self.request.POST.get.file.read(), or rather how to loop this task in app engine file(os.curdir+"somefile").read() UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 14: ordinal not in range(128) but when I try to read binary with b, I get IOError. raise IOError('invalid mode: %s' % mode) IOError: invalid mode: b -Alex Goretoy http://www.alexgoretoy.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg.ewing at canterbury.ac.nz Mon Feb 9 01:51:46 2009 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Mon, 09 Feb 2009 19:51:46 +1300 Subject: Python binaries with VC++ 8.0? Message-ID: <6va201FijdteU1@mid.individual.net> Is there anywhere I can download a set of Python binaries, of any version, that have been built with Visual C++ 8.0? I'm trying to hook Python up to Sketchup 7 on Windows, and I think I'm having problems because Sketchup is linked with msvcr80.dll. -- Greg From Bornstub at gmail.com Mon Feb 9 01:52:05 2009 From: Bornstub at gmail.com (Victor Lin) Date: Sun, 8 Feb 2009 22:52:05 -0800 (PST) Subject: How to debug deadlock? Message-ID: Hi, I am developing a multi-threading application, I encounter a deadlock. I use Visual C++ Express 2008 to trace the program. Once the deadlock occurs, I just pause the program and trace. I found that when deadlock occurs, there will be two threads called python from my C++ extension. All of them use Queue in python code, so I guess the deadlock might caused by Queue. But however, once the extension goes into python code, I can't see nothing but asm code and binary from the VC++ debugger. I would like to know are there any way to dump the call stack of python code after I paused the program? And how can I know what lock are there in threads caused the deadlock? Thanks. Victor Lin. From r.warhekar at gmail.com Mon Feb 9 02:04:49 2009 From: r.warhekar at gmail.com (Rahul) Date: Sun, 8 Feb 2009 23:04:49 -0800 (PST) Subject: adodb has no attribute connect Message-ID: <2fb8b6ce-f18c-457e-8adc-492f6e83f8a8@q30g2000prq.googlegroups.com> Hello all, I have to access data from database using adodb so I did Import adodb Conn=adodb.NewADOConnection("odbc") Upto this it works properly but when I say Conn.Connect("","","") It gives error as [Attributrerror]: Object Nonetype has no attribute Connect. I have Red Hat Enterprise Linux 4 Python 2.5 Mod_python 3.3.1 The same is also not working from python console Please guide me through this. From pavlovevidence at gmail.com Mon Feb 9 02:14:52 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 8 Feb 2009 23:14:52 -0800 (PST) Subject: Python binaries with VC++ 8.0? References: <6va201FijdteU1@mid.individual.net> Message-ID: <17612b99-0756-47a1-ae4f-5e05e18813cd@r41g2000prr.googlegroups.com> On Feb 8, 10:51?pm, Greg Ewing wrote: > Is there anywhere I can download a set of Python > binaries, of any version, that have been built > with Visual C++ 8.0? > > I'm trying to hook Python up to Sketchup 7 on > Windows, and I think I'm having problems because > Sketchup is linked with msvcr80.dll. I'm pretty sure 2.6.1 is compiled with 8.0. However, I think the Visual C++ 8.0 uses msvcrt90.dll. Take a look at this bug report to see if it's related to your issue: http://bugs.python.org/issue4566 Carl Banks From stefan_ml at behnel.de Mon Feb 9 02:20:35 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 09 Feb 2009 08:20:35 +0100 Subject: ElementTree and clone element toot In-Reply-To: References: <4986bfd7$0$9385$ba4acef3@news.orange.fr> Message-ID: <498fd943$0$32667$9b4e6d93@newsspool2.arcor-online.net> Aahz wrote: > In article <4986bfd7$0$9385$ba4acef3 at news.orange.fr>, > m.banaouas wrote: >> Working with the ElementTree module, I looked for clone element >> function but not found such tool: > > Have you tried using copy.deepcopy()? While being the most obvious solution, calling deepcopy() on an Element is surprisingly slow in ElementTree. http://codespeak.net/lxml/performance.html#deepcopy It's actually multiple times faster to rebuild the tree manually through the API than to let deepcopy() do it. Fredrik also has written a little factory for mass reproduction of Element trees. http://effbot.python-hosting.com/file/stuff/sandbox/elementlib/clone.py Stefan From steven at REMOVE.THIS.cybersource.com.au Mon Feb 9 02:26:33 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 09 Feb 2009 07:26:33 GMT Subject: Python Module: nift References: <9cb28036-7d5f-4b8a-9748-b26c5e9538b4@r15g2000prd.googlegroups.com> <1eb3e6de-2092-45f8-b270-81845cbe1ed2@h20g2000yqn.googlegroups.com> <838a342c-64e0-4c97-a0d0-9e2475696f74@z1g2000yqn.googlegroups.com> Message-ID: On Sun, 08 Feb 2009 13:34:50 -0800, bearophileHUGS wrote: > Gabriel Genellina: >> bearophile: >> > - Generally I suggest to learn to code in the small, using as little >> > code as possible. >> >> I completely agree with all the above suggestions, except this last >> one. Ok, I think I know what you mean, but a beginner might understand >> this completely wrong. Readability is important, and trying to compress >> too much code into one single line should not be the ultimate goal. > > What I meant is to use less code as possible, keeping readability and > the original flexibility. I think a better description is, use as little code as you need, and no extra, but no less. As Einstein said about physics theories: "As simple as possible, but no simpler." > I can't stress enough the importance of writing less code. Every new > programmer has to learn how much important it is. Less code means less > bugs, less lines to edit and debug, etc. [pedant] There's less code, fewer bugs and lines. Less applies to continuous quantities, like weight and "amount of code", and fewer applies to countable quantities. Don't worry, I frequently get it wrong too, and I'm a native English speaker :) > Less code is usually more > elegant, and often more readable (even if you take 3 times to read each > line it may be good anyway if you have 1/10 of the lines of code. > Recently in the "Java to Python" thread someone has posted some Java > class that is scary, you can probably write the same thing in 1/10-1/20 > of the lines of code). Within reason, naturally. There's a reason why we write: for button in buttons: move(button, delta_x, delta_y) instead of for b in bs: mv(b, x, y) even though the second is significantly shorter. Keyword arguments versus positional arguments is another example where more verbose code is easier to read and maintain than shorter code. Also, I don't think there's much advantage in trying to push new programmers to reduce the amount of code. Until you're really comfortable with the language, you need training wheels and scaffolding in the form of verbose code. Sometimes you really don't appreciate Python's labour saving features until you've experienced how much labour there is to be saved. -- Steven From mail at microcorp.co.za Mon Feb 9 02:40:07 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Mon, 9 Feb 2009 09:40:07 +0200 Subject: Importing a file (not a module). References: <1234152106.498faaaa97f1d@mail.uh.cu> Message-ID: <000301c98a8c$c7d74c00$0d00a8c0@hendrik> "Luis Zarrabeitia" wrote: >Is there any way to "import" a .py file that is not on sys.path? >I'd like to 'import' a file that resides somewhere on my filesystem without >having to add it's directory to sys.path. At first, I thought that something like > >my_module = __import__("path/to/file") > >would work, but I was mistaken. Ideally, the path would be specified as a >relative path from the importer's module, and not from the CWD (that's another >question, I guess). I have used execfile(RelativeFromCWDOrAbsolutePathToTheFile) to do this sort of thing. But beware - it does not create a module, so it's a bit like: from something import * This may or may not be useful in your case. - Hendrik From cournape at gmail.com Mon Feb 9 02:48:12 2009 From: cournape at gmail.com (David Cournapeau) Date: Mon, 9 Feb 2009 16:48:12 +0900 Subject: Python binaries with VC++ 8.0? In-Reply-To: <17612b99-0756-47a1-ae4f-5e05e18813cd@r41g2000prr.googlegroups.com> References: <6va201FijdteU1@mid.individual.net> <17612b99-0756-47a1-ae4f-5e05e18813cd@r41g2000prr.googlegroups.com> Message-ID: <5b8d13220902082348h7b37c045veea3f678b814fe5f@mail.gmail.com> On Mon, Feb 9, 2009 at 4:14 PM, Carl Banks wrote: > On Feb 8, 10:51 pm, Greg Ewing wrote: >> Is there anywhere I can download a set of Python >> binaries, of any version, that have been built >> with Visual C++ 8.0? >> >> I'm trying to hook Python up to Sketchup 7 on >> Windows, and I think I'm having problems because >> Sketchup is linked with msvcr80.dll. > > I'm pretty sure 2.6.1 is compiled with 8.0. Hm, I have just run python to check: it is built with MSC v.1500, which corresponds to VS 2008, e.g. VS 9, at least on 32 bits. David From mail at microcorp.co.za Mon Feb 9 02:48:55 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Mon, 9 Feb 2009 09:48:55 +0200 Subject: Simple question - stock market simulation References: <6d242a86-c0bc-4c1d-8c38-b263e128bd02@n33g2000pri.googlegroups.com><7xljsgyzn5.fsf@ruckus.brouhaha.com> <1c244978-3224-4a5c-a9d9-60cb2337660e@x6g2000pre.googlegroups.com> Message-ID: <000401c98a8c$c86e5be0$0d00a8c0@hendrik> "cptn.spoon" wrote: On Feb 9, 3:58 pm, Paul Rubin wrote: >Thanks Paul! I thought this might be the case. So how would I get the >StockMarket class instance to contain many Stock class instances and >then be able to iterate through them? I'm guessing the basic structure >would be as follows...but I think I'm wrong: > >class StockMarket: > pass No. At this level, just use a list of instances of your Stock class. - Hendrik From rodmena.com at gmail.com Mon Feb 9 04:05:19 2009 From: rodmena.com at gmail.com (Farsheed Ashouri) Date: Mon, 9 Feb 2009 01:05:19 -0800 (PST) Subject: Local python web server problem Message-ID: <30b0923c-313d-4626-8df2-2f877ae9f47a@x9g2000yqk.googlegroups.com> Hi everyone. I have started to develop a web base software for renderfarm managing. I run the cherrypy hello world! example and when I visit 127.0.0.1:8080 on firefox, a nice "Hello World" appears. I am on ubuntu and my ip in local network is 192.168.100.18 but when I visit 192.168.100.18, there is another page: "It Works!". What is "It Works!"? and when I type 192.168.100.18:8080 in another local pc, the page didn't load? Sorry I am newbie in network area, so I have these two questions: 1- How can I serve my page in local network? 2- what is "It Works!" in 192.168.100.18? we have 192.168.100.<10-70> . no pc has this but mine!!! 3- Could you please explain me or at least point me to the right direction of making little local web server, localhost? 4- How can I access to the server that serves web page in 56566 port? I try 192.168.100.18:56566 but the page could not load. I can ping 192.168.100.18 but I can't load web pages from it. Why? Thanks and sorry for my bad English. From skippy.hammond at gmail.com Mon Feb 9 04:32:22 2009 From: skippy.hammond at gmail.com (Mark Hammond) Date: Mon, 09 Feb 2009 20:32:22 +1100 Subject: Python binaries with VC++ 8.0? In-Reply-To: <6va201FijdteU1@mid.individual.net> References: <6va201FijdteU1@mid.individual.net> Message-ID: <498FF826.50008@gmail.com> On 9/02/2009 5:51 PM, Greg Ewing wrote: > Is there anywhere I can download a set of Python > binaries, of any version, that have been built > with Visual C++ 8.0? IIRC, no. Python skipped that version of MSVC. I believe Python 2.5 builds easily with vc8 project files in svn though. > I'm trying to hook Python up to Sketchup 7 on > Windows, and I think I'm having problems because > Sketchup is linked with msvcr80.dll. What problems specifically? The only practical problems you should see will arise if you try and pass a "FILE *", or allocate memory you then ask python to free (or vice-versa) - both should be avoidable though... Mark From research at johnohagan.com Mon Feb 9 04:43:36 2009 From: research at johnohagan.com (John O'Hagan) Date: Mon, 9 Feb 2009 09:43:36 +0000 Subject: Small socket problem Message-ID: <200902090943.36445.research@johnohagan.com> Hi, I'm using the socket module (python 2.5) like this (where 'options' refers to an optparse object) to connect to the Fluidsynth program: host = "localhost" port = 9800 fluid = socket(AF_INET, SOCK_STREAM) try: fluid.connect((host, port)) #Connect if fluidsynth is running except BaseException: print "Connecting to fluidsynth..." #Or start fluidsynth soundfont = options.soundfont driver = options.driver Popen(["fluidsynth", "-i", "-s", "-g", "0.5", "-C", "1", "-R", "1", "-l", "-a", driver, "-j", soundfont]) timeout = 50 while 1: timeout -= 1 if timeout == 0: print "Problem with fluidsynth: switching to synth." play_method = "synth" break try: fluid.connect((host, port)) except BaseException: sleep(0.05) continue else: break (I'm using BaseException because I haven't been able to discover what exception class[es] socket uses). The problem is that this fails to connect ( the error is "111: Connection refused") the first time I run it after booting if fluidsynth is not already running, no matter how long the timeout is; after Ctrl-C'ing out of the program, all subsequent attempts succeed. Note that fluidsynth need not be running for a success to occur. I've also tried it without the while loop, simply sleeping for a few seconds to give fluidsynth time to start (not a preferred approach as I want a short startup), but the same thing happens. I am a long way from being a networking guru and am at a loss as to how to debug this. Maybe someone can point out some flaw in my use of socket. Thanks, John O'Hagan From Ron.Barak at lsi.com Mon Feb 9 04:51:45 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Mon, 9 Feb 2009 09:51:45 +0000 Subject: How to copy an instance without its cStringIO.StringO item ? In-Reply-To: References: <7F0503CD69378F49BE0DC30661C6CCF60E68778F@enbmail01.lsi.com> Message-ID: <7F0503CD69378F49BE0DC30661C6CCF60E6877F0@enbmail01.lsi.com> Hi John, Thanks for the suggestion. What I do now in preparation for pickling is: for_pickle_log_stream = LogStream(sac_log_file) for key in log_stream.__dict__: if key != "input_file": for_pickle_log_stream.__dict__[key] = log_stream.__dict__[key] del for_pickle_log_stream.__dict__["input_file"] (i.e., log_stream is the source instance, and for_pickle_log_stream is the target) So, it seems to be in agreement with your suggestion. Thanks and bye, Ron. -----Original Message----- From: John Machin [mailto:sjmachin at lexicon.net] Sent: Sunday, February 08, 2009 23:04 To: python-list at python.org Subject: Re: How to copy an instance without its cStringIO.StringO item ? On Feb 9, 1:01 am, Christian Heimes wrote: > Barak, Ron schrieb: > > > Hi, > > > I need to copy an instance of a class, where one of the items in the original is a cStringIO.StringO object. > > I do not need the cStringIO.StringO in the target object. > > The target instance is to be pickled. > > > Googling made me devise the following plan: do a deepcopy from the original to the target, and then delete the cStringIO.StringO object from the target. > > > However, trying to use copy.deepcopy produced: TypeError: > > object.__new__(cStringIO.StringO) is not safe, use > > cStringIO.StringO.__new__() > > > Is there a way to create a copy of the instance, sans the cStringIO.StringO ? > > > If I find no elegant way to do that, I thought of creating a "blank" target instance; then iterating over the __dict__ of the original, and manually copy the items to the target (while not copying the cStringIO.StringO to the target). > > > Can you suggest a better way ? > > You can overwrite some functions in order to omit attributes from a > pickle. It's all documented athttp://docs.python.org/library/pickle.html#pickling-and-unpickling-no... If there is no chance that some other thread could be accessing the source object, can't the OP just do: temp = source.stringio del source.stringio # make a pickle from source source.stringio = temp ? -------------- next part -------------- An HTML attachment was scrubbed... URL: From bearophileHUGS at lycos.com Mon Feb 9 04:57:56 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Mon, 9 Feb 2009 01:57:56 -0800 (PST) Subject: Python Module: nift References: <9cb28036-7d5f-4b8a-9748-b26c5e9538b4@r15g2000prd.googlegroups.com> <1eb3e6de-2092-45f8-b270-81845cbe1ed2@h20g2000yqn.googlegroups.com> <838a342c-64e0-4c97-a0d0-9e2475696f74@z1g2000yqn.googlegroups.com> Message-ID: Steven D'Aprano: > There's less code, fewer bugs and lines. Less applies to continuous > quantities, like weight and "amount of code", and fewer applies to > countable quantities. Thank you, I'll try to improve my use of the language. > Within reason, naturally. There's a reason why we write: > for button in buttons: > ? ? move(button, delta_x, delta_y) > instead of > for b in bs: mv(b, x, y) > even though the second is significantly shorter. Often Shortening names and packing more stuff in single lines that deserve to be two lines aren't good ways to shorten code. > Also, I don't think there's much advantage in trying to push new > programmers to reduce the amount of code. Until you're really comfortable > with the language, you need training wheels and scaffolding in the form > of verbose code. Sometimes you really don't appreciate Python's labour > saving features until you've experienced how much labour there is to be > saved. I don't agree. When you learn to code you also have to learn what does it mean to write "good code", you have to learn that there are several things that are important beside writing a correct output, like good comments, well thought out names, good indentation, good idioms, quick running time, small memory usage, writing clear and readable code, and later develop elegance, the power of composition, abstraction, indirection, meta programming, etc. Among such things there's the importance of writing short programs. All such things are the seeds that will develop into the personal style of the future programmer. Such things are also useful for another purpose: to help the student understand that code is craftsmanship, so she/he/shi can (and is supposed to) be proud of the code that writes. This helps the student understand that programming isn't just an ugly way to tell orders to a moronic CPU, that helps develop appreciation for the act of writing code, because it becomes something you do also for the sake of it, as you do art, beside for usefulness. So you have to teach and show such things from more or less the beginning. Bye, bearophile From clp2 at rebertia.com Mon Feb 9 05:13:00 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 9 Feb 2009 02:13:00 -0800 Subject: Variable + String Format In-Reply-To: <019ff536$0$20657$c3e8da3@news.astraweb.com> References: <019ff536$0$20657$c3e8da3@news.astraweb.com> Message-ID: <50697b2c0902090213s193576f5w58430c4a2e7ee07d@mail.gmail.com> On Tue, Feb 10, 2009 at 2:03 AM, Joel Ross wrote: > Hi all, > > I have this piece of code: > ######################################################################### > > wordList = "/tmp/Wordlist" > file = open(wordList, 'r+b') Why are you opening the file in binary mode? It's content is text! > > def readLines(): > > for line in file.read(): .read() reads the *entire* file into a string. When you iterate over a string, such as in a for-loop, you get *individual characters*, whereas you appear to want lines of text. To go line-by-line, use `for line in file` instead (note: `line` will include the trailing newline at the end of each line). And don't use `file` as a variable name; it shadows the name of the buitlin type. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From sjmachin at lexicon.net Mon Feb 9 05:28:17 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 09 Feb 2009 21:28:17 +1100 Subject: How to copy an instance without its cStringIO.StringO item ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF60E6877F0@enbmail01.lsi.com> References: <7F0503CD69378F49BE0DC30661C6CCF60E68778F@enbmail01.lsi.com> <7F0503CD69378F49BE0DC30661C6CCF60E6877F0@enbmail01.lsi.com> Message-ID: <49900541.6090509@lexicon.net> On 9/02/2009 8:51 PM, Barak, Ron wrote: > Hi John, > > Thanks for the suggestion. > > What I do now in preparation for pickling is: > > for_pickle_log_stream = LogStream(sac_log_file) > for key in log_stream.__dict__: > if key != "input_file": > for_pickle_log_stream.__dict__[key] = > log_stream.__dict__[key] > del for_pickle_log_stream.__dict__["input_file"] > > (i.e., log_stream is the source instance, and for_pickle_log_stream is > the target) > > So, it seems to be in agreement with your suggestion. which was """ If there is no chance that some other thread could be accessing the source object, can't the OP just do: temp = source.stringio del source.stringio # make a pickle from source source.stringio = temp """ which I regard as radically different to your approach; please explain what you mean by "in agreement with". From sjmachin at lexicon.net Mon Feb 9 05:47:03 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 9 Feb 2009 02:47:03 -0800 (PST) Subject: Variable + String Format References: <019ff536$0$20657$c3e8da3@news.astraweb.com> Message-ID: <2c44fc1d-54bc-40f9-9d7c-3c5031c4489d@a39g2000prl.googlegroups.com> On Feb 9, 9:13?pm, Chris Rebert wrote: > On Tue, Feb 10, 2009 at 2:03 AM, Joel Ross wrote: > > Hi all, > > > I have this piece of code: > > ######################################################################### > > > wordList = "/tmp/Wordlist" > > file = open(wordList, 'r+b') > > Why are you opening the file in binary mode? It's content is text! > > > > > def readLines(): > > > ? ? ? ?for line in file.read(): > > .read() reads the *entire* file into a string. When you iterate over a > string, such as in a for-loop, you get *individual characters*, > whereas you appear to want lines of text. To go line-by-line, use `for > line in file` instead (note: `line` will include the trailing newline > at the end of each line). > And don't use `file` as a variable name; it shadows the name of the > buitlin type. > Changed as suggested above, with further comments: wordList = "/tmp/Wordlist" f = open(wordList, 'r') def readLines(): ## There is no point in putting the next four lines ## inside a function if you are going to call the ## function (a) immediately and (b) once only. ## All it does is provide scope for unwanted complications. for line in f: line = line.rstrip('\n') print line + '.com ' ## Complications like this next line; why is it returning "line"?? ## And why is it indented like that? ## It will cause only the first line to be read. return line ## Maybe you you meant it to be here: return ## But then it's redundant because a function returns anyway ## when flow of control would fall off the bottom. readLines() f.close() HTH, John From pete.forman at westerngeco.com Mon Feb 9 06:45:34 2009 From: pete.forman at westerngeco.com (Pete Forman) Date: Mon, 09 Feb 2009 11:45:34 +0000 Subject: Tkinter w.pack()? References: <_Lghl.12218$D32.6047@flpi146.ffdc.sbc.com> Message-ID: "W. eWatson" writes: > MRAB wrote: >> W. eWatson wrote: > ... >>> I thought some months ago, I found Google commands that would >>> operate in the browser link window. Guess not. >>> >>> BTW, isn't there an O'Reilly book on Google hacks of this sort? >>> Where else does one find out about these Google tools? >>> >> Google? :-) >> http://www.google.com/support/websearch/bin/answer.py?hl=en&answer=136861 >> > Thanks. I may have that book marked from many, many months ago. If so, > I see why I'd never find it. The BM entry does not show "Google". It > does now. ;-) As well as the site: modifier check out inurl: and friends. http://www.google.com/help/operators.html -- Pete Forman -./\.- Disclaimer: This post is originated WesternGeco -./\.- by myself and does not represent pete.forman at westerngeco.com -./\.- the opinion of Schlumberger or http://petef.22web.net -./\.- WesternGeco. From psaffrey at googlemail.com Mon Feb 9 07:12:29 2009 From: psaffrey at googlemail.com (psaffrey at googlemail.com) Date: Mon, 9 Feb 2009 04:12:29 -0800 (PST) Subject: Which core am I running on? Message-ID: <2847e691-fbf6-433e-ae71-839dc708073f@t11g2000yqg.googlegroups.com> Is there some way I can get at this information at run-time? I'd like to use it to tag diagnostic output dumped during runs using Parallel Python. Peter From gh at ghaering.de Mon Feb 9 07:20:16 2009 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Mon, 09 Feb 2009 13:20:16 +0100 Subject: Local python web server problem In-Reply-To: <30b0923c-313d-4626-8df2-2f877ae9f47a@x9g2000yqk.googlegroups.com> References: <30b0923c-313d-4626-8df2-2f877ae9f47a@x9g2000yqk.googlegroups.com> Message-ID: Farsheed Ashouri wrote: > Hi everyone. I have started to develop a web base software for > renderfarm managing. > I run the cherrypy hello world! example and when I visit > 127.0.0.1:8080 > on firefox, a nice "Hello World" appears. I am on ubuntu and my ip in > local network is 192.168.100.18 > but when I visit 192.168.100.18, there is another page: "It Works!". > What is "It Works!"? and when I type 192.168.100.18:8080 in another > local pc, the page didn't load? [...] Services like HTTP servers "bind" not only to a port, but to a combination of IP address and port. The CherryPy tutorial configuration http://www.cherrypy.org/browser/trunk/cherrypy/tutorial/tutorial.conf binds to 127.0.0.1 and 8080. This means the application can only be accessed from the local machine. To bind to all network interfaces, (i. e. Ethernet etc., and not just the loopback device), you can change server.socket_host to "0.0.0.0". -- Gerhard From gh at ghaering.de Mon Feb 9 07:22:56 2009 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Mon, 09 Feb 2009 13:22:56 +0100 Subject: Which core am I running on? In-Reply-To: <2847e691-fbf6-433e-ae71-839dc708073f@t11g2000yqg.googlegroups.com> References: <2847e691-fbf6-433e-ae71-839dc708073f@t11g2000yqg.googlegroups.com> Message-ID: psaffrey at googlemail.com wrote: > Is there some way I can get at this information at run-time? I'd like > to use it to tag diagnostic output dumped during runs using Parallel > Python. There should be a way, but not with the Python standard library. It's also platform-specific. What are you using? Linux, MacOS X, FreeBSD, Solaris, or maybe Windows? -- Gerhard From gh at ghaering.de Mon Feb 9 07:24:23 2009 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Mon, 09 Feb 2009 13:24:23 +0100 Subject: Which core am I running on? In-Reply-To: <2847e691-fbf6-433e-ae71-839dc708073f@t11g2000yqg.googlegroups.com> References: <2847e691-fbf6-433e-ae71-839dc708073f@t11g2000yqg.googlegroups.com> Message-ID: psaffrey at googlemail.com wrote: > Is there some way I can get at this information at run-time? I'd like > to use it to tag diagnostic output dumped during runs using Parallel > Python. Looks like I have answered a similar question once, btw. ;-) http://objectmix.com/python/631346-parallel-python.html -- Gerhard From psaffrey at googlemail.com Mon Feb 9 08:04:59 2009 From: psaffrey at googlemail.com (psaffrey at googlemail.com) Date: Mon, 9 Feb 2009 05:04:59 -0800 (PST) Subject: Which core am I running on? References: <2847e691-fbf6-433e-ae71-839dc708073f@t11g2000yqg.googlegroups.com> Message-ID: <84742d3d-6cb5-434b-8a33-2e571e34be70@j1g2000yqi.googlegroups.com> On 9 Feb, 12:24, Gerhard H?ring wrote: > Looks like I have answered a similar question once, btw. ;-) > Ah, yes - thanks. I did Google for it, but obviously didn't have the right search term. Cheers, Peter From psaffrey at googlemail.com Mon Feb 9 08:11:23 2009 From: psaffrey at googlemail.com (psaffrey at googlemail.com) Date: Mon, 9 Feb 2009 05:11:23 -0800 (PST) Subject: Too many open files Message-ID: <7cb40acb-fbfe-420c-bc9e-be9765bc8d53@o11g2000yql.googlegroups.com> I'm building a pipeline involving a number of shell tools. In each case, I create a temporary file using tempfile.mkstmp() and invoke a command ("cmd < /tmp/tmpfile") on it using subprocess.Popen. At the end of each section, I call close() on the file handles and use os.remove() to delete them. Even so I build up file descriptors that eventually give me the "too many files" error message. Am I missing something here? Peter From lihang9999 at gmail.com Mon Feb 9 08:13:10 2009 From: lihang9999 at gmail.com (Li Han) Date: Mon, 9 Feb 2009 05:13:10 -0800 (PST) Subject: convert the ip packet to and from RS-232 packet Message-ID: <31cea4a8-5223-427b-b05d-41dd46508a04@p2g2000prf.googlegroups.com> Hi, I need to use radio to connect two local ip network, each local network has a server computer which connects to a radio with RS-232 interface. I need to write a program to convert the local ip packet into RS-232 packet, so the radio can send packetes to the remote radio. I don't want to reinvent the wheel, is there anyone could give me some suggestions? Thank you! Han From eckhardt at satorlaser.com Mon Feb 9 08:17:21 2009 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Mon, 09 Feb 2009 14:17:21 +0100 Subject: Too many open files References: <7cb40acb-fbfe-420c-bc9e-be9765bc8d53@o11g2000yql.googlegroups.com> Message-ID: <30n566-q6r.ln1@satorlaser.homedns.org> psaffrey at googlemail.com wrote: > I'm building a pipeline involving a number of shell tools. In each > case, I create a temporary file using tempfile.mkstmp() and invoke a > command ("cmd < /tmp/tmpfile") on it using subprocess.Popen. > > At the end of each section, I call close() on the file handles and use > os.remove() to delete them. Even so I build up file descriptors that > eventually give me the "too many files" error message. Am I missing > something here? There recently was a bug filed at bugs.python.org about leaked file descriptors. Maybe that is exactly what you are experiencing here. Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From pobega at gmail.com Mon Feb 9 08:23:21 2009 From: pobega at gmail.com (Michael Pobega) Date: Mon, 9 Feb 2009 08:23:21 -0500 Subject: wxPython vs Glade? Message-ID: <20090209132321.GA30754@greedo> I'm looking for opinions on the best toolkit for a beginner to use with wxPython. It doesn't necessarily need to be the most efficient toolkit, but something I can use for basic programs (a Twitter client, Wordpress blogging client, etc) just to learn Python. wxWidgets seems nice because it's portable, but I'm not sure how many of my libraries are portable (a lot of them seem to import os), while Glade seems extremely simple to make a UI (but does the program end up relying on Glade? Or can I build it directly into GTK+?) -- http://pobega.wordpress.com http://identica/pobega -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 204 bytes Desc: Digital signature URL: From steve at holdenweb.com Mon Feb 9 08:29:06 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 09 Feb 2009 08:29:06 -0500 Subject: convert the ip packet to and from RS-232 packet In-Reply-To: <31cea4a8-5223-427b-b05d-41dd46508a04@p2g2000prf.googlegroups.com> References: <31cea4a8-5223-427b-b05d-41dd46508a04@p2g2000prf.googlegroups.com> Message-ID: Li Han wrote: > Hi, I need to use radio to connect two local ip network, each local > network has a server computer which connects to a radio with RS-232 > interface. I need to write a program to convert the local ip packet > into RS-232 packet, so the radio can send packetes to the remote > radio. I don't want to reinvent the wheel, is there anyone could give > me some suggestions? > Thank you! There's a package called pyserial that's pretty good at handling RS-232 interfaces. Good luck! regards Steve (G3VEK) -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From benjamin.kaplan at case.edu Mon Feb 9 08:30:13 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 9 Feb 2009 08:30:13 -0500 Subject: wxPython vs Glade? In-Reply-To: <20090209132321.GA30754@greedo> References: <20090209132321.GA30754@greedo> Message-ID: On Mon, Feb 9, 2009 at 8:23 AM, Michael Pobega wrote: > I'm looking for opinions on the best toolkit for a beginner to use with > wxPython. It doesn't necessarily need to be the most efficient toolkit, > but something I can use for basic programs (a Twitter client, Wordpress > blogging client, etc) just to learn Python. > > wxWidgets seems nice because it's portable, but I'm not sure how many of > my libraries are portable (a lot of them seem to import os), while Glade > seems extremely simple to make a UI (but does the program end up relying > on Glade? Or can I build it directly into GTK+?) > wxPython is the toolkit. It provides Python wrappers for wxWidgets. I think you are looking at wxGlade, a UI designer for wx based off of the Gnome UI builder. It's not a toolkit.. > > -- > http://pobega.wordpress.com > http://identica/pobega > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.9 (GNU/Linux) > > iEYEARECAAYFAkmQLkkACgkQxgy5R7EobNd/vwCfeDdaeX6YyNxcCZ11pmbWMPZj > akwAn2LCb3Qz2lLKZLF3DG4j5lTBOQdd > =/Bfe > -----END PGP SIGNATURE----- > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Mon Feb 9 08:34:12 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 09 Feb 2009 08:34:12 -0500 Subject: wxPython vs Glade? In-Reply-To: <20090209132321.GA30754@greedo> References: <20090209132321.GA30754@greedo> Message-ID: Michael Pobega wrote: > I'm looking for opinions on the best toolkit for a beginner to use with > wxPython. It doesn't necessarily need to be the most efficient toolkit, > but something I can use for basic programs (a Twitter client, Wordpress > blogging client, etc) just to learn Python. > > wxWidgets seems nice because it's portable, but I'm not sure how many of > my libraries are portable (a lot of them seem to import os), while Glade > seems extremely simple to make a UI (but does the program end up relying > on Glade? Or can I build it directly into GTK+?) > There's something called PythonCard built on top of wxPython that's fairly newb-friendly, though it gets clunkier as your demands grow. You might also want to look at Dabo, which is a much more comprehensive framework that also hides much of wxPython's complexity. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From tim.wintle at teamrubber.com Mon Feb 9 08:47:18 2009 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Mon, 09 Feb 2009 13:47:18 +0000 Subject: thread. question Message-ID: <1234187238.7630.34.camel@tim-laptop> Hi, This is my first post here - google hasn't helped much but sorry if this has been asked before. I've been wondering about some of the technicalities of locks in python (2.4 and 2.5 mainly). I'm using the "old" thread module as (1) I prefer the methods and (2) It should be a tiny bit faster. As far as I can see, the thread module is fairly much a direct wrapper around "PyThread_allocate_lock" etc. - defined in "thread_pthread.h" (took me ages to find the definitions in a header file!), so as far as I can tell the implementation is very closely wrapped around the system's threading implementation. Does that mean that every python thread is actually a real separate thread (for some reason I thought they were implemented in the interpreter)? Does that also mean that there is very little extra interpreter-overhead to using locks (assuming they very infrequently block)? Since if you use the thread module direct the code doesn't seem to escape from C during the acquire() etc. or am I missing something important? Thanks, Tim Wintle From s.selvamsiva at gmail.com Mon Feb 9 08:48:48 2009 From: s.selvamsiva at gmail.com (S.Selvam Siva) Date: Mon, 9 Feb 2009 19:18:48 +0530 Subject: BeautifulSoup -converting unicode to numerical representaion Message-ID: Hi all, I need to parse feeds and post the data to SOLR.I want the special characters(Unicode char) to be posted as numerical representation, For eg, *'* --> ’ (for which HTML equivalent is ’) I used BeautifulSoup,which seems to be allowing conversion from "&#xxxx;"( numeric values )to unicode characters as follow, *hdes=str(BeautifulStoneSoup(strdesc, convertEntities=BeautifulStoneSoup.HTML_ENTITIES)) xdesc=str(BeautifulStoneSoup(hdes, convertEntities=BeautifulStoneSoup.XML_ENTITIES))* But i want *numerical representation of unicode characters.* I also want to convert html representation like ’ to its numeric equivalent ’ Thanks in advance. *Note:* The reason for the above requirement is i need a standard way to post to SOLR to avoid errors. -- Yours, S.Selvam -------------- next part -------------- An HTML attachment was scrubbed... URL: From psaffrey at googlemail.com Mon Feb 9 08:53:10 2009 From: psaffrey at googlemail.com (psaffrey at googlemail.com) Date: Mon, 9 Feb 2009 05:53:10 -0800 (PST) Subject: Which core am I running on? References: <2847e691-fbf6-433e-ae71-839dc708073f@t11g2000yqg.googlegroups.com> Message-ID: On 9 Feb, 12:24, Gerhard H?ring wrote: > http://objectmix.com/python/631346-parallel-python.html > Hmm. In fact, this doesn't seem to work for pp. When I run the code below, it says everything is running on the one core. import pp import random import time from string import lowercase ncpus = 3 def timedCharDump(waittime, char): time.sleep(waittime) mycore = open("/proc/%i/stat" % os.getpid()).read().split()[39] print "I'm doing stuff!", mycore, char return char job_server = pp.Server(ncpus, ppservers=()) jobdetails = [ (random.random(), letter) for letter in lowercase ] jobs = [ job_server.submit(timedCharDump,(jinput1, jinput2), (), ("os", "time",)) for jinput1, jinput2 in jobdetails ] for job in jobs: print job() Peter From tino at wildenhain.de Mon Feb 9 08:54:09 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Mon, 09 Feb 2009 14:54:09 +0100 Subject: convert the ip packet to and from RS-232 packet In-Reply-To: <31cea4a8-5223-427b-b05d-41dd46508a04@p2g2000prf.googlegroups.com> References: <31cea4a8-5223-427b-b05d-41dd46508a04@p2g2000prf.googlegroups.com> Message-ID: <49903581.70409@wildenhain.de> Hi, Li Han wrote: > Hi, I need to use radio to connect two local ip network, each local > network has a server computer which connects to a radio with RS-232 > interface. I need to write a program to convert the local ip packet > into RS-232 packet, so the radio can send packetes to the remote > radio. I don't want to reinvent the wheel, is there anyone could give > me some suggestions? You might want to check: http://en.wikipedia.org/wiki/Packet_radio some free OS already come with an interface implemention so all you need would be configuring that interface and routing appropriately. As such, not really a python topic. Regards Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From vzupka at volny.cz Mon Feb 9 09:05:01 2009 From: vzupka at volny.cz (=?WINDOWS-1252?Q?Vladim=EDr_=8Eupka?=) Date: Mon, 9 Feb 2009 15:05:01 +0100 Subject: cannot install Message-ID: <46EB146D-6A7F-4457-A35D-CB0C388C19DB@volny.cz> I have Mac OS X Leopard 10.5.6 and I downloaded and unpacked Python 3.0 into a folder (/Library/Frameworks/Python.framework) and ran commands: cd /Library/Frameworks/Python.framework/Python-3.0 python setup.py install and got the message reporting a syntax error: Macintosh:~ vzupka$ /bin/csh [Macintosh:~] vzupka% cd /Library/Frameworks/Python.framework/Python-3.0 [Macintosh:Frameworks/Python.framework/Python-3.0] vzupka% python setup.py install File "setup.py", line 232 except (CCompilerError, DistutilsError) as why: ^ SyntaxError: invalid syntax [Macintosh:Frameworks/Python.framework/Python-3.0] vzupka% What is the reason and how do I install? Regards, Vladim?r ?upka vzupka at volny.cz -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Mon Feb 9 09:10:13 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 09 Feb 2009 12:10:13 -0200 Subject: Small socket problem References: <200902090943.36445.research@johnohagan.com> Message-ID: En Mon, 09 Feb 2009 07:43:36 -0200, John O'Hagan escribi?: > I'm using the socket module (python 2.5) like this (where 'options' > refers to > an optparse object) to connect to the Fluidsynth program: > > host = "localhost" > port = 9800 > fluid = socket(AF_INET, SOCK_STREAM) > try: > fluid.connect((host, port)) #Connect if fluidsynth is > running > except BaseException: > print "Connecting to fluidsynth..." #Or start fluidsynth > soundfont = options.soundfont > driver = options.driver > Popen(["fluidsynth", "-i", "-s", "-g", "0.5", > "-C", "1", "-R", "1", "-l", "-a", driver, "-j", > soundfont]) > timeout = 50 > while 1: > timeout -= 1 > if timeout == 0: > print "Problem with fluidsynth: switching to > synth." > play_method = "synth" > break > try: > fluid.connect((host, port)) > except BaseException: > sleep(0.05) > continue > else: > break > > (I'm using BaseException because I haven't been able to discover what > exception class[es] socket uses). Usually socket.error, which is a subclass of IOError, but others might happen too I think. In any case, the most generic except clause you should use is try: except Exception: ... (because you usually don't want to catch KeyboardInterrupt nor SystemExit, that is, let Ctrl-C and sys.exit() do their work) > The problem is that this fails to connect ( the error is "111: Connection > refused") the first time I run it after booting if fluidsynth is not > already > running, no matter how long the timeout is; after Ctrl-C'ing out of the > program, all subsequent attempts succeed. Note that fluidsynth need not > be > running for a success to occur. Always the same exception? In both lines? -- Gabriel Genellina From pobega at gmail.com Mon Feb 9 09:26:55 2009 From: pobega at gmail.com (Michael Pobega) Date: Mon, 9 Feb 2009 09:26:55 -0500 Subject: wxPython vs Glade? In-Reply-To: References: <20090209132321.GA30754@greedo> Message-ID: <20090209142655.GA25349@greedo> On Mon, Feb 09, 2009 at 08:30:13AM -0500, Benjamin Kaplan wrote: > On Mon, Feb 9, 2009 at 8:23 AM, Michael Pobega wrote: > > > I'm looking for opinions on the best toolkit for a beginner to use with > > wxPython. It doesn't necessarily need to be the most efficient toolkit, > > but something I can use for basic programs (a Twitter client, Wordpress > > blogging client, etc) just to learn Python. > > > > wxWidgets seems nice because it's portable, but I'm not sure how many of > > my libraries are portable (a lot of them seem to import os), while Glade > > seems extremely simple to make a UI (but does the program end up relying > > on Glade? Or can I build it directly into GTK+?) > > > > wxPython is the toolkit. It provides Python wrappers for wxWidgets. I think > you are looking at wxGlade, a UI designer for wx based off of the Gnome UI > builder. It's not a toolkit.. > No, I'm not. You don't have to argue semantics with me; I'm talking about using wxPython directly (i.e. with Vim) or using Glade to build an interface; I'm wondering which makes for the easiest and best end result code. -- http://pobega.wordpress.com http://identica/pobega -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 204 bytes Desc: Digital signature URL: From Scott.Daniels at Acm.Org Mon Feb 9 09:30:29 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 09 Feb 2009 06:30:29 -0800 Subject: MacPython 2.5 IDLE font size In-Reply-To: References: <541cb78b-52fd-4f71-9909-5649d4586558@v42g2000yqj.googlegroups.com> Message-ID: I (Scott David Daniels) wrote: > chohazel at gmail.com wrote: >> Is there a way to adjust the default font size in IDLE, in MacPython >> 2.5? The default now is too tiny. >> I have to use this version of MacPython. As far as I searched, I can't >> find how I do this. > > If you can read what you have at all, try to go toHelp (on the top), > then down in that menu to "Configure IDLE ..." > There will be a possibly long delay. Then on the tab in the produced > window, You can set the Base Editor Font and Size. I use Tahoma 14. > Then go click "Ok". If the display doesn't get better, you might have > to exit from Idle and restart it. If this doesn't work, get back to me > and we can try something more drastic. Although the OP seems no longer interested, I'd now advise anyone interested yo read the entire section on installing VPython (v5) on OS/X. It has a very clear set of things to do to get Python 2.5 and IDLE working. You can simply skip the steps for downloading and installing VPython if you like. http://www.vpython.org/contents/download_mac.html As to why it is on vpython.org rather than python.org, VPython is used in physics courses at a number of universities, and they teach their classes (to people not necessarily programmers) using IDLE to interact with and program their physics demos (3-D images that you can mouse around to change your point of view). --Scott David Daniels Scott.Daniels at Acm.Org From gagsl-py2 at yahoo.com.ar Mon Feb 9 09:34:13 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 09 Feb 2009 12:34:13 -0200 Subject: Variable + String Format References: <019ff536$0$20657$c3e8da3@news.astraweb.com> Message-ID: En Tue, 10 Feb 2009 08:03:06 -0200, Joel Ross escribi?: > ######################################################################### > > wordList = "/tmp/Wordlist" > file = open(wordList, 'r+b') > > > def readLines(): > > for line in file.read(): > if not line: break > print line + '.com ' > return line > > > > readLines() > file.close() > > ########################################################################## > > It returns the results: > > t.com > > NOTE: Only returns the first letter of the first word on the first line > e.g. test would only print t and readline() does the same thing. This should print every line in the file, adding .com at the end: wordList = "/tmp/Wordlist" with open(wordList, 'r') as wl: for line in wl: print line.rstrip() + '.com ' Note that: - I iterate over the file self; files are their own line-iterators. - I've used the 'r' mode instead (I assume it's a text file because you read it line by line, and as you don't update it, the '+' isn't required) - the line read includes the end-of-line '\n' at the end; rstrip() removes it and any trailing whitespace. If you don't want this, use rstrip('\n') - I've used the with statement to ensure the file is closed at the end -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Mon Feb 9 09:34:14 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 09 Feb 2009 12:34:14 -0200 Subject: Variable + String Format References: <019ff536$0$20657$c3e8da3@news.astraweb.com> Message-ID: En Tue, 10 Feb 2009 08:03:06 -0200, Joel Ross escribi?: > ######################################################################### > > wordList = "/tmp/Wordlist" > file = open(wordList, 'r+b') > > > def readLines(): > > for line in file.read(): > if not line: break > print line + '.com ' > return line > > > > readLines() > file.close() > > ########################################################################## > > It returns the results: > > t.com > > NOTE: Only returns the first letter of the first word on the first line > e.g. test would only print t and readline() does the same thing. This should print every line in the file, adding .com at the end: wordList = "/tmp/Wordlist" with open(wordList, 'r') as wl: for line in wl: print line.rstrip() + '.com ' Note that: - I iterate over the file self; files are their own line-iterators. - I've used the 'r' mode instead (I assume it's a text file because you read it line by line, and as you don't update it, the '+' isn't required) - the line read includes the end-of-line '\n' at the end; rstrip() removes it and any trailing whitespace. If you don't want this, use rstrip('\n') - I've used the with statement to ensure the file is closed at the end -- Gabriel Genellina From icanbob at gmail.com Mon Feb 9 09:43:28 2009 From: icanbob at gmail.com (bobicanprogram) Date: Mon, 9 Feb 2009 06:43:28 -0800 (PST) Subject: convert the ip packet to and from RS-232 packet References: <31cea4a8-5223-427b-b05d-41dd46508a04@p2g2000prf.googlegroups.com> Message-ID: <4cc1a15a-9d20-4b85-ab04-2380cab5b23a@s20g2000yqh.googlegroups.com> On Feb 9, 8:13 am, Li Han wrote: > Hi, I need to use radio to connect two local ip network, each local > network has a server computer which connects to a radio with RS-232 > interface. I need to write a program to convert the local ip packet > into RS-232 packet, so the radio can send packetes to the remote > radio. I don't want to reinvent the wheel, is there anyone could give > me some suggestions? > Thank you! > Han You might want to check out the SIMPL toolkit. (http:// www.icanprogram.com/simpl). It come standard with an RS232 surrogate. This generic module will transparently transmit a SIMPL message via RS232 serial connection. Although this module is written in C, SIMPL itself fully supports Python as a language to create modules. bob From basu at archlinux.us Mon Feb 9 09:43:46 2009 From: basu at archlinux.us (member Basu) Date: Mon, 9 Feb 2009 09:43:46 -0500 Subject: Py2app Py2exe and losing extensibility Message-ID: I'm currently working on a project that allows users to write their own Python modules as simple extensions (basically output formatters). I would like to do a cross-platform release and so I'm using PyQt and will be trying to convert it to native builds using Py2app and Py2xe. I don't want users to have to install Qt and PyQt to run it. But if I do that, will I still be able to load Python modules dynamically as extensions ? (assuming that the user machine has Python installed separately). Thanks, Basu -------------- next part -------------- An HTML attachment was scrubbed... URL: From bieffe62 at gmail.com Mon Feb 9 09:54:49 2009 From: bieffe62 at gmail.com (bieffe62 at gmail.com) Date: Mon, 9 Feb 2009 06:54:49 -0800 (PST) Subject: thread. question References: Message-ID: On Feb 9, 2:47?pm, Tim Wintle wrote: > Hi, > This is my first post here - google hasn't helped much but sorry if this > has been asked before. > > I've been wondering about some of the technicalities of locks in python > (2.4 and 2.5 mainly). > > I'm using the "old" thread module as (1) I prefer the methods and (2) It > should be a tiny bit faster. > > As far as I can see, the thread module is fairly much a direct wrapper > around "PyThread_allocate_lock" etc. - defined in > "thread_pthread.h" (took me ages to find the definitions in a header > file!), so as far as I can tell the implementation is very closely > wrapped around the system's threading implementation. > > Does that mean that every python thread is actually a real separate > thread (for some reason I thought they were implemented in the > interpreter)? > I've hever seen the C implementation of python thread, but I know that python threads are real OS threads, not 'green threads' inside the interpreter. > Does that also mean that there is very little extra interpreter-overhead > to using locks (assuming they very infrequently block)? Since if you use > the thread module direct the code doesn't seem to escape from C during > the acquire() etc. or am I missing something important? > One significant difference with doing threads in lower level languages is that in Python the single interpreter instructions are atomic. This make things a bit safer but also less reactive. It is especially bad if you use C modules which have function calls which take long time (bit AFAIK most of IO standard modules have work around for it), because your program will not change thread until the C function returns. The reason - or one of the reasons - for this is that the python threads share the interpreter, which is locked by a thread before execution of a statement and released at the end ( this is the 'Global Interpreter Lock' or GIL of which you probably found many references if you googled for python threads ). Among the other things, this seem to mean that a multi-threaded python application cannot take full advantage of multi-core CPUs (but the detailed reason for that escapes me...). For these reasons, on this list, many suggest that if you have real- time requirements, probably you should consider using sub-processes instead of threads. Personally I have used threads a few times, although always with very soft real-time requirements, and I have never been bitten by the GIL (meaning that anyway I was able top meet my timing requirements). So, to add another achronym to my post, YMMV. > Thanks, > > Tim Wintle Ciao ---- FB From lists at cheimes.de Mon Feb 9 09:59:05 2009 From: lists at cheimes.de (Christian Heimes) Date: Mon, 09 Feb 2009 15:59:05 +0100 Subject: thread. question In-Reply-To: <1234187238.7630.34.camel@tim-laptop> References: <1234187238.7630.34.camel@tim-laptop> Message-ID: Tim Wintle schrieb: > Hi, > This is my first post here - google hasn't helped much but sorry if this > has been asked before. > > I've been wondering about some of the technicalities of locks in python > (2.4 and 2.5 mainly). > > I'm using the "old" thread module as (1) I prefer the methods and (2) It > should be a tiny bit faster. You shouldn't use the thread module directly. It's not meant to be used by a user. Please stick to the threading module. You won't notice a slowdown, trust me :) > As far as I can see, the thread module is fairly much a direct wrapper > around "PyThread_allocate_lock" etc. - defined in > "thread_pthread.h" (took me ages to find the definitions in a header > file!), so as far as I can tell the implementation is very closely > wrapped around the system's threading implementation. The header files Python/thread_*.h contain the interface to your system's threading libraries. One of the files is included conditionally depending on your OS. > Does that mean that every python thread is actually a real separate > thread (for some reason I thought they were implemented in the > interpreter)? Yes, Python uses native threads, not green threads. However Python pure code can't utilize more than one CPU per process. On order to use multiple CPUs you have to use multiple processes or use C code that doesn't use any Python API. Google for "GIL" if you are interested in more information. > Does that also mean that there is very little extra interpreter-overhead > to using locks (assuming they very infrequently block)? Since if you use > the thread module direct the code doesn't seem to escape from C during > the acquire() etc. or am I missing something important? You are correct. The overhead is minimal. Christian From exarkun at divmod.com Mon Feb 9 10:02:06 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Mon, 9 Feb 2009 10:02:06 -0500 Subject: convert the ip packet to and from RS-232 packet In-Reply-To: <31cea4a8-5223-427b-b05d-41dd46508a04@p2g2000prf.googlegroups.com> Message-ID: <20090209150206.12853.1379007984.divmod.quotient.7849@henry.divmod.com> On Mon, 9 Feb 2009 05:13:10 -0800 (PST), Li Han wrote: >Hi, I need to use radio to connect two local ip network, each local >network has a server computer which connects to a radio with RS-232 >interface. I need to write a program to convert the local ip packet >into RS-232 packet, so the radio can send packetes to the remote >radio. I don't want to reinvent the wheel, is there anyone could give >me some suggestions? You can proxy between any two kinds of connection pretty easily with Twisted (untested): from twisted.internet import serialport, protocol, reactor from twisted.protocols import portforward class SerialPortServer(portforward.Proxy): def connectionMade(self): # Stop the server, since only one thing can talk to the serial port # at a time. tcpPort.stopListening() # Hook up the proxy between this TCP connection and the serial port. self.peer = portforward.Proxy() self.peer.setPeer(self) self._serialPort = serialport.SerialPort(self.peer, '/dev/ttyS0', reactor) factory = protocol.ServerFactory() factory.protocol = SerialPortServer tcpPort = reactor.listenTCP(12345, factory) reactor.run() Jean-Paul From jasiu85 at gmail.com Mon Feb 9 10:02:28 2009 From: jasiu85 at gmail.com (Jasiu) Date: Mon, 9 Feb 2009 07:02:28 -0800 (PST) Subject: version in setup.cfg Message-ID: <0b778f9a-d811-4dcd-9678-26242a14c4bf@t11g2000yqg.googlegroups.com> Hi guys, I have a question about setup.py and setup.cfg: I work in a company and we use Subversion to keep our stuff. We have a post-commit rule that does the following: whenever there is a commit to /tags/ directory, a binary package is built automatically. The tag's name is the new version of the package, i.e. tag names are something like /tags/1.5.2, /tags/1.2.3 etc. We use setup.py to create packages. In setup.py we set the version of the package by specifying 'version' keyword argument to setup function. We have automated builds and our post-commit script does kind of ugly regexp hack and replaces string "version='...'" with version that is guessed from the tag name. And I wonder: It would be much cleaner if the version could be placed in the setup.cfg file. Is that possible? Thanks, Mike From gagsl-py2 at yahoo.com.ar Mon Feb 9 10:14:17 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 09 Feb 2009 13:14:17 -0200 Subject: Py2app Py2exe and losing extensibility References: Message-ID: En Mon, 09 Feb 2009 12:43:46 -0200, member Basu escribi?: > I'm currently working on a project that allows users to write their own > Python modules as simple extensions (basically output formatters). I > would > like to do a cross-platform release and so I'm using PyQt and will be > trying > to convert it to native builds using Py2app and Py2xe. I don't want > users to > have to install Qt and PyQt to run it. But if I do that, will I still be > able to load Python modules dynamically as extensions ? (assuming that > the > user machine has Python installed separately). I don't know about py2app but if you use py2exe your users still can provide their own modules. And they don't have to install Python separately (asuming that your "private" one contains all the library modules they want to use) I don't understand your concerns about installing Qt/PyQt. -- Gabriel Genellina From exarkun at divmod.com Mon Feb 9 10:24:47 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Mon, 9 Feb 2009 10:24:47 -0500 Subject: Small socket problem In-Reply-To: <200902090943.36445.research@johnohagan.com> Message-ID: <20090209152447.12853.1924354689.divmod.quotient.7857@henry.divmod.com> On Mon, 9 Feb 2009 09:43:36 +0000, John O'Hagan wrote: >Hi, > >I'm using the socket module (python 2.5) like this (where 'options' refers to >an optparse object) to connect to the Fluidsynth program: > > host = "localhost" > port = 9800 > fluid = socket(AF_INET, SOCK_STREAM) > try: > fluid.connect((host, port)) #Connect if fluidsynth is running > except BaseException: > print "Connecting to fluidsynth..." #Or start fluidsynth > soundfont = options.soundfont > driver = options.driver > Popen(["fluidsynth", "-i", "-s", "-g", "0.5", > "-C", "1", "-R", "1", "-l", "-a", driver, "-j", soundfont]) > timeout = 50 > while 1: > timeout -= 1 > if timeout == 0: > print "Problem with fluidsynth: switching to synth." > play_method = "synth" > break > try: > fluid.connect((host, port)) > except BaseException: > sleep(0.05) > continue > else: > break > >(I'm using BaseException because I haven't been able to discover what >exception class[es] socket uses). > >The problem is that this fails to connect ( the error is "111: Connection >refused") the first time I run it after booting if fluidsynth is not already >running, no matter how long the timeout is; after Ctrl-C'ing out of the >program, all subsequent attempts succeed. Note that fluidsynth need not be >running for a success to occur. The most obvious problem is that you're trying to re-use a socket on which a connection attempt has failed. This isn't allowed and will always fail. You must create a new socket for each connection attempt. You might also want to consider using a higher level socket library than the "socket" module. The socket module exposes you to lots of very low level details and platform-specific idiosyncrasies. You may find that a library like Twisted () will let you write programs with fewer bugs. Jean-Paul From tim.wintle at teamrubber.com Mon Feb 9 10:34:02 2009 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Mon, 09 Feb 2009 15:34:02 +0000 Subject: thread. question In-Reply-To: References: <1234187238.7630.34.camel@tim-laptop> Message-ID: <1234193642.7630.63.camel@tim-laptop> Thanks for both replies, On Mon, 2009-02-09 at 15:59 +0100, Christian Heimes wrote: > You shouldn't use the thread module directly. It's not meant to be used > by a user. Please stick to the threading module. You won't notice a > slowdown, trust me :) I'm aware that thread is being renamed to _thread in python 3.0, but is it being depricated or anything like that? This is for an app that has been running for quite a long time and it's now time for fairly heavy optimisations as load is increasing (Believe me, I wouldn't have been looking at the C otherwise) - so I'll see if I do notice any effect with threading. > Yes, Python uses native threads, not green threads. However Python pure > code can't utilize more than one CPU per process. On order to use > multiple CPUs you have to use multiple processes or use C code that > doesn't use any Python API. Google for "GIL" if you are interested in > more information. Thanks for the info - I'm very aware of the GIL, but had never looked at the implementation before and for some reason thought that python's threads were in userspace. I'm already using a multiple-process architecture overall, but using threads to avoid waiting when handling SQL and TCP. Tim From exarkun at divmod.com Mon Feb 9 10:42:16 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Mon, 9 Feb 2009 10:42:16 -0500 Subject: thread. question In-Reply-To: <1234193642.7630.63.camel@tim-laptop> Message-ID: <20090209154216.12853.415160543.divmod.quotient.7862@henry.divmod.com> On Mon, 09 Feb 2009 15:34:02 +0000, Tim Wintle wrote: >Thanks for both replies, > >On Mon, 2009-02-09 at 15:59 +0100, Christian Heimes wrote: >> You shouldn't use the thread module directly. It's not meant to be used >> by a user. Please stick to the threading module. You won't notice a >> slowdown, trust me :) >I'm aware that thread is being renamed to _thread in python 3.0, but is >it being depricated or anything like that? > >This is for an app that has been running for quite a long time and it's >now time for fairly heavy optimisations as load is increasing (Believe >me, I wouldn't have been looking at the C otherwise) - so I'll see if I >do notice any effect with threading. You may want to look into dropping the use of threads (where possible, eg for handling TCP connections) if you're trying to optimize the app. Threads come with a lot of overhead that can be avoided by using non- blocking operations instead. Jean-Paul From benjamin.kaplan at case.edu Mon Feb 9 10:56:14 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 9 Feb 2009 10:56:14 -0500 Subject: cannot install In-Reply-To: <46EB146D-6A7F-4457-A35D-CB0C388C19DB@volny.cz> References: <46EB146D-6A7F-4457-A35D-CB0C388C19DB@volny.cz> Message-ID: On Mon, Feb 9, 2009 at 9:05 AM, Vladim?r ?upka wrote: > I have Mac OS X Leopard 10.5.6 and I downloaded and unpacked Python 3.0 > into a folder (/Library/Frameworks/Python.framework) and ran commands: > > cd /Library/Frameworks/Python.framework/Python-3.0 > python setup.py install > > and got the message reporting a syntax error: > > Macintosh:~ vzupka$ /bin/csh > [Macintosh:~] vzupka% cd /Library/Frameworks/Python.framework/Python-3.0 > [Macintosh:Frameworks/Python.framework/Python-3.0] vzupka% python setup.py > install > File "setup.py", line 232 > except (CCompilerError, DistutilsError) as why: > ^ > SyntaxError: invalid syntax > [Macintosh:Frameworks/Python.framework/Python-3.0] vzupka% > > What is the reason and how do I install? > You can't use setup.py because the python 2.5 on your system (or 2.6 if you installed it) is incompatible with Python 3 modules. You need to compile Python 3 yourself. It will then automatically call setup.py to create all the extension modules. Just unpack the tarball anywhere and use the following commands Python 3 is automatically installed as python3.0, so you don't need to worry about overwriting the default python on the system. ./configure --enable-framework make sudo make install more complete instructions are in the Mac/README file, except substitute "Python 3.0" everywhere it says "MacPython 2.6". You will probably need to install a whole bunch of packages to compile it. configure will tell you about them. MacPorts (www.macports.org) and fink (www.finkproject.org) provide an easy way to get them. > Regards, > Vladim?r ?upka > vzupka at volny.cz > > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From anthra.norell at bluewin.ch Mon Feb 9 11:29:25 2009 From: anthra.norell at bluewin.ch (Anthra Norell) Date: Mon, 09 Feb 2009 17:29:25 +0100 Subject: Simple question - stock market simulation In-Reply-To: <6d242a86-c0bc-4c1d-8c38-b263e128bd02@n33g2000pri.googlegroups.com> References: <6d242a86-c0bc-4c1d-8c38-b263e128bd02@n33g2000pri.googlegroups.com> Message-ID: <499059E5.7000301@bluewin.ch> cptn.spoon wrote: > I'm trying to create an incredibly simple stock market simulator to be > used in a childrens classroom and I'm wondering whether someone can > point me in the right direction. > > I basically want to be able to have a stock struct as follows: > > StockName = "Test" > StockPriceList = (12,13,12,10,10,8,10) > StockRisk = 0.15 > StockQty = 2000 > > And then have a StockMarket struct that can contain 1 to many Stocks. > I then want to be able to iterate through the stocks to perform > operations as such: > > for Stock in StockMarket: > > I'm not asking for tips on the program itself, I just can't figure out > how to get the data structures in place. Would I use Classes or would > I use dictionaries? Am I completely off the mark with this? > > Apologies for such a rudimentary question...I'm very new to all this. > -- > http://mail.python.org/mailman/listinfo/python-list > > If the subject is investment performance, surely your best bet is to hand out piggy banks. Frederic From bdesth.quelquechose at free.quelquepart.fr Mon Feb 9 11:37:09 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Mon, 09 Feb 2009 17:37:09 +0100 Subject: wxPython vs Glade? In-Reply-To: References: Message-ID: <49906950$0$24811$426a34cc@news.free.fr> Michael Pobega a ?crit : > I'm looking for opinions on the best toolkit for a beginner to use with > wxPython. wxPython *is* a GUI toolkit (or, more exactly, a python binding for wxWidgets). > wxWidgets seems nice because it's portable, but I'm not sure how many of > my libraries are portable (a lot of them seem to import os), while Glade > seems extremely simple to make a UI Glade is a (graphical) GUI *builder* for the GTK+ toolkit - it' not a toolkit itself. So you're comparing apples to gorillas. FWIW, there is (was ???) a Glade-like graphical builder for wxWidgets named wxGlade. From Krzysztof.Retel at googlemail.com Mon Feb 9 11:39:08 2009 From: Krzysztof.Retel at googlemail.com (Krzysztof Retel) Date: Mon, 9 Feb 2009 08:39:08 -0800 (PST) Subject: Network packets processor advice Message-ID: <76830d52-9b0f-4e78-adc3-999bb125d472@p13g2000yqc.googlegroups.com> Hi, I am wrting a network packet processor. The processor listens on a specific port for incomming UDP or TCP packets. When the packet arrives it has to parse it, store in DB and if this succeed it has to acknowledge the packet to the client. Now the problem is that I want to have a control over possible failures of the system. For instance, if the DB is gone, the processor should stop working and restart when DB is back to live. So the questions are: 1. Which approach is the best for building such software? For instance using threads? 2. I can use the 'monit' tool for monitorig processes. However, not sure yet how to start a python script with a specific process id. Is it possible at all? 3. Any other suggestions? Cheers, K From remm1 at member.fsf.org Mon Feb 9 11:45:59 2009 From: remm1 at member.fsf.org (Rob) Date: Mon, 09 Feb 2009 10:45:59 -0600 Subject: Local python web server problem References: <30b0923c-313d-4626-8df2-2f877ae9f47a@x9g2000yqk.googlegroups.com> Message-ID: > I run the cherrypy hello world! example and when I visit > 127.0.0.1:8080 > on firefox, a nice "Hello World" appears. I am on ubuntu and my ip in > local network is 192.168.100.18 > but when I visit 192.168.100.18, there is another page: "It Works!". > What is "It Works!"? and when I type 192.168.100.18:8080 in another > local pc, the page didn't load? You need to have the server listen on 192.168.100.18 not 127.0.0.1. They are different. 127.0.0.1 is visible only locally. The 192.168.100.18 is visible both locally and from other hosts. I don't use cherrypy so don't know how you set this up. Are you using apache to host cherrypy or does it have it's own web server? If your using apache the IP address is selected with the Listen directive normally in the /etc/apache2/ports.conf file. > Thanks and sorry for my bad English. Your english is good. Rob From hall.jeff at gmail.com Mon Feb 9 11:52:03 2009 From: hall.jeff at gmail.com (hall.jeff at gmail.com) Date: Mon, 9 Feb 2009 08:52:03 -0800 (PST) Subject: easy_install References: <7f00694b-a956-440d-92f5-99db48925829@l1g2000yqj.googlegroups.com> <6v88eaFifbroU1@mid.uni-berlin.de> <4c020f9a-d179-4153-9815-9a32c54a7d2e@f3g2000yqf.googlegroups.com> <498F285B.6060905@v.loewis.de> Message-ID: I had it downloaded and sitting in the root c:\ but didn't get it to run because I didn't think about the \scripts folder not being in the Path. Problem solved and fixed. Thank you all for your help. On a side note, "easy_install MySQL-python" produced the following messages: Searching for MySQL-python Reading http://pypi.python.org/simple/MySQL_python/ Reading http://sourceforge.net/projects/mysql-python Reading http://sourceforge.net/projects/mysql-python/ Best match: MySQL-python 1.2.3b1 Downloading http://osdn.dl.sourceforge.net/sourceforge/mysql-python/MySQL-python-1.2.3b1.tar.gz Processing MySQL-python-1.2.3b1.tar.gz Running MySQL-python-1.2.3b1\setup.py -q bdist_egg --dist-dir c: \docume~1\jhall\locals~1\temp\easy_install-t_ph9k\MySQL- python-1.2.3b1\egg-dist-tmp-3gtuz9 error: The system cannot find the file specified installing from the hard drive worked fine, however. From xahlee at gmail.com Mon Feb 9 11:55:35 2009 From: xahlee at gmail.com (Xah Lee) Date: Mon, 9 Feb 2009 08:55:35 -0800 (PST) Subject: programming by evolution? References: <42a2e3fc-ec2e-4c09-b456-95a5fc4ce5a2@g39g2000pri.googlegroups.com> <6uuc4eFhc1u1U1@mid.individual.net> <11809792-676f-4d95-87c1-26666cc46b3b@w24g2000prd.googlegroups.com> <03db1c69-828a-4961-914d-62fe10ed88fb@w39g2000prb.googlegroups.com> Message-ID: Xah Lee wrote: > ... > if you want software engineering books, i suggest try some books that > are based on statistical survey, as opposed to some dignitary's > ?opinion? or current fashion & trends that comes with a jargon. These > type of books are a dime a dozen, every year, they come and go. The > stastical survey approach takes major understaking and cost. The > opinion type any motherfucking ?guru? can write. e.g. Paul Graham has > you buy into certain concept of ?hackers? fucker and claim they are > like ?painters?. Certain Gabriel wants you to believe in poetry and C > is the last language. (see Book Review: Patterns of > Software > http://xahlee.org/PageTwo_dir/Personal_dir/bookReviewRichardGabriel.html > ) et al. Certain Gosling wants you to believe Java is the last lang on > earth that'll wipe out Microsoft (circa 1998). > > ... > > ... what society overwhelmingly asks for is snake oil. Of course, the > snake oil has the most impressive names ?otherwise you would be > selling nothing? like ?Structured Analysis and Design?, ?Software > Engineering?, ?Maturity Models?, ?Management Information Systems?, > ?Integrated Project Support Environments? ?Object Orientation? and > ?Business Process Re-engineering? (the latter three being known as > IPSE, OO and BPR, respectively).? ? Edsger W Dijkstra (1930-2002), in > EWD 1175: The strengths of the academic enterprise. > > you want to be a good programer? Study math, the math of programing, > and master the langs and protocols and tools you use. You want to > climb the tech industry ladder? get better at people, learn politics. > You want to be rich? Study business. Chances are, you are a coding > geek, and at heart you dna is not geared to be interested in politics > or business, and you'll never be rich or big ceo just because of that. > > See also: > ? Why Software Suck > http://xahlee.org/UnixResource_dir/writ/why_software_suck.html > > looking at the eXtreme Programing fuckheads's traffic history: > http://groups.google.com/group/comp.software.extreme-programming/about > > for those who are not aware, it was one of the snake oil wildly > popular in around 2001. Today, i happened to run across a blog on the eXtreme Programing FUCK. http://www.yosefk.com/blog/extreme-programming-explained.html Great article! Xah ? http://xahlee.org/ ? From aahz at pythoncraft.com Mon Feb 9 12:02:58 2009 From: aahz at pythoncraft.com (Aahz) Date: 9 Feb 2009 09:02:58 -0800 Subject: Calling into Python from a C thread References: Message-ID: [posted & e-mailed] In article , Philip Semanchuk wrote: > >I'm trying call Python from inside of a C thread that's running in a >Python extension I've written and I am not having much luck. My C >thread function consists of simply this, and I get a segmentation >fault from Python: Because it's been a week without response, I suggest you try the capi mailing list. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From tn.pablo at gmail.com Mon Feb 9 12:07:07 2009 From: tn.pablo at gmail.com (ptn) Date: Mon, 9 Feb 2009 09:07:07 -0800 (PST) Subject: Flattening lists References: <873aesbzng.fsf@agentultra.com> Message-ID: On Feb 5, 2:07?pm, rdmur... at bitdance.com wrote: > Quoth J Kenneth King : > > > > > mk writes: > > > > Hello everybody, > > > > Any better solution than this? > > > > def flatten(x): > > > ? ? res = [] > > > ? ? for el in x: > > > ? ? ? ? if isinstance(el,list): > > > ? ? ? ? ? ? res.extend(flatten(el)) > > > ? ? ? ? else: > > > ? ? ? ? ? ? res.append(el) > > > ? ? return res > > > > a = [1, 2, 3, [4, 5, 6], [[7, 8], [9, 10]]] > > > print flatten(a) > > > > [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] > > > > Regards, > > > mk > > >http://mail.python.org/pipermail/python-list/2005-July/330367.html > > That's worth reading. ?I'm not sure why I'm finding this fun, but who > cares. ?I tried a couple of other functions after reading that article, > and it looks like a generator that scans the nested lists is actually > the winner, and also is in many ways the most elegant implementation. > Of course, as noted in the emails following above article, the test data > is really inadequate for proper optimization testing ;) > > ----------------------------------------------------------------- > from __future__ import print_function > from timeit import Timer > from itertools import chain > > # This is the one from the article quoted above. > def flatten6(seq): > ? ? i = 0 > ? ? while (i != len(seq)): > ? ? ? ? while hasattr(seq[i], '__iter__'): > ? ? ? ? ? ? seq[i:i+1] = seq[i] > ? ? ? ? i = i + 1 > ? ? return seq > > #This is my favorite from a readability standpoint out of > #all the things I tried. ?It also performs the best. > def flatten8(seq): > ? ? for x in seq: > ? ? ? ? if not hasattr(x, '__iter__'): yield x > ? ? ? ? else: > ? ? ? ? ? ? for y in flatten8(x): > ? ? ? ? ? ? ? ? yield y > > l = [[1, 2, 3], 5, [7, 8], 3, [9, [10, 11, 12], 4, [9, [10, 5, 7]], 1, [[[[[5, 4], 3], 4, 3], 3, 1, 45], 9], 10]] > > if __name__=="__main__": > ? ? print(l) > ? ? print('flatten6', flatten6(l)) > ? ? print('flatten8', list(flatten8(l))) > ? ? print('flatten6', Timer("flatten6(l)", "from temp3 import flatten6, l").timeit()) > ? ? print('flatten8', Timer("list(flatten8(l))", "from temp3 import flatten8, l").timeit()) > > ----------------------------------------------------------------- > > >src/python/Python-3.0/python temp3.py > > [[1, 2, 3], 5, [7, 8], 3, [9, [10, 11, 12], 4, [9, [10, 5, 7]], 1, [[[[[5, 4], 3], 4, 3], 3, 1, 45], 9], 10]] > flatten6 [1, 2, 3, 5, 7, 8, 3, 9, 10, 11, 12, 4, 9, 10, 5, 7, 1, 5, 4, 3, 4, 3, 3, 1, 45, 9, 10] > flatten8 [1, 2, 3, 5, 7, 8, 3, 9, 10, 11, 12, 4, 9, 10, 5, 7, 1, 5, 4, 3, 4, 3, 3, 1, 45, 9, 10] > flatten6 32.8386368752 > flatten8 30.7509689331 > > >python temp3.py > > [[1, 2, 3], 5, [7, 8], 3, [9, [10, 11, 12], 4, [9, [10, 5, 7]], 1, [[[[[5, 4], 3], 4, 3], 3, 1, 45], 9], 10]] > flatten6 [1, 2, 3, 5, 7, 8, 3, 9, 10, 11, 12, 4, 9, 10, 5, 7, 1, 5, 4, 3, 4, 3, 3, 1, 45, 9, 10] > flatten8 [1, 2, 3, 5, 7, 8, 3, 9, 10, 11, 12, 4, 9, 10, 5, 7, 1, 5, 4, 3, 4, 3, 3, 1, 45, 9, 10] > flatten6 34.730714798 > flatten8 32.3252940178 > > --RDM I think the generator is clearer with a try statement, like in Magnus Lie Hetland's solution from Beginning Python: def flatten(nested): try: # Don't iterate over string-like objs. try: nested + '' except TypeError: pass else: raise TypeError for sub in nested: for elem in flatten(sub): yield elem except TypeError: # The for doesn't work for single elements. yield nested You can't iterate over string-like objs because the all strings are built of infinite empty lists at the beginning, leading to infinite recursion. From aleksandr.goretoy at gmail.com Mon Feb 9 12:07:50 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Mon, 9 Feb 2009 11:07:50 -0600 Subject: GAE read binary file into db.BlobProperty() Message-ID: How to read Binary file into GAE(Google App Engine) db.BlobProperty() datastore? -Alex Goretoy http://www.goretoy.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From aahz at pythoncraft.com Mon Feb 9 12:10:04 2009 From: aahz at pythoncraft.com (Aahz) Date: 9 Feb 2009 09:10:04 -0800 Subject: Threading / Queue management References: Message-ID: In article , Power Button wrote: > >I wonder if anyone can help with the following. I have written a >script which polls a server and if it finds and pending orders, it >instantiates an new object (foo) - in a new thread and processes some >data. In the new object (foo), there are also some long running >processes so I am trying to create a thread pool/queue and to push >items onto the queue in the instantiated object (foo). Currently I am >creating the Queue in foo but this means I am starting up 5 new >threads every time I instantiate foo. What I want to be able to do is >create the Queue and start 5 (n) threads when my program starts and >then push items onto the queue in foo. Not sure what you're trying to do, but you meay find this sample code useful: http://www.pythoncraft.com/OSCON2001/index.html -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From remm1 at member.fsf.org Mon Feb 9 12:10:18 2009 From: remm1 at member.fsf.org (Rob) Date: Mon, 09 Feb 2009 11:10:18 -0600 Subject: global name 'sqrt' is not defined References: Message-ID: > Any ideas? If I do something like "import math" in the subfunction, > then the error changes to "global name 'math' is not defined". Presumably ipython does an import so you need to import it yourself something like: from math import sqrt at the top of your source file. I don't know why math would not be defined, it's built in -- probably a scoping logic problem in your code. Put the form/import statement at the top of your module file (as is usually done), not inside a function or other block. Rob From bdesth.quelquechose at free.quelquepart.fr Mon Feb 9 12:12:14 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Mon, 09 Feb 2009 18:12:14 +0100 Subject: Help needed to retrieve text from a text-file using RegEx In-Reply-To: <532dd150-9889-41d9-a926-adffa8934393@y1g2000pra.googlegroups.com> References: <532dd150-9889-41d9-a926-adffa8934393@y1g2000pra.googlegroups.com> Message-ID: <49907188$0$7875$426a34cc@news.free.fr> Oltmans a ?crit : > Here is the scenario: > > It's a command line program. I ask user for a input string. Based on > that input string I retrieve text from a text file. My text file looks > like following > > Text-file: > ------------- > AbcManager=C:\source\code\Modules\Code-AbcManager\ > AbcTest=C:\source\code\Modules\Code-AbcTest\ > DecConnector=C:\source\code\Modules\Code-DecConnector\ > GHIManager=C:\source\code\Modules\Code-GHIManager\ > JKLConnector=C:\source\code\Modules\Code-JKLConnector > > ------------- > > So now if I run the program and user enters > > DecConnector > > Then I'm supposed to show them this text "C:\source\code\Modules\Code- > DecConnector" from the text-file. Right now I'm retrieving using the > following code which seems quite ineffecient and inelegant at the same > time > > with open('MyTextFile.txt') This will lookup for MyFile.txt in the system's current working directory - which is not necessarily in the script's directory. > as file: this shadows the builtin's 'file' symbol. > for line in file: > > if mName in line: #mName is the string that > contains user input > > Path =str(line).strip('\n') 'line' is already a string. > tempStr=Path > > Path=tempStr.replace(mName+'=',"",1) You don't need the temporary variable here. Also, you may want to use str.split instead: # NB : renaming for conformity to # Python's official naming conventions # 'name' => what the user looks for # 'path_to_file' => fully qualified path to the 'database' file target = "%s=" % name # what we are really looking for with open(path_to_file) as the_file: for line in the_file: # special bonus : handles empty lines and 'comment' lines # feel free to comment out the thre following lines if # you're sure you don't need them !-) line = line.strip() if not line or line.startswith('#') or line.startswith(';'): continue # faster and simpler than a regexp if line.startswith(target): # since the '=' is in target, we can safely assume # that line.split('=') will return at least a # 2-elements list path = line.split('=')[1] # no need to look further break else: # target not found... path = None > I was wondering if using RegEx will make this look better. I don't think so. Really. From rolf.oltmans at gmail.com Mon Feb 9 12:22:32 2009 From: rolf.oltmans at gmail.com (Oltmans) Date: Mon, 9 Feb 2009 09:22:32 -0800 (PST) Subject: Help needed to retrieve text from a text-file using RegEx Message-ID: <532dd150-9889-41d9-a926-adffa8934393@y1g2000pra.googlegroups.com> Here is the scenario: It's a command line program. I ask user for a input string. Based on that input string I retrieve text from a text file. My text file looks like following Text-file: ------------- AbcManager=C:\source\code\Modules\Code-AbcManager\ AbcTest=C:\source\code\Modules\Code-AbcTest\ DecConnector=C:\source\code\Modules\Code-DecConnector\ GHIManager=C:\source\code\Modules\Code-GHIManager\ JKLConnector=C:\source\code\Modules\Code-JKLConnector ------------- So now if I run the program and user enters DecConnector Then I'm supposed to show them this text "C:\source\code\Modules\Code- DecConnector" from the text-file. Right now I'm retrieving using the following code which seems quite ineffecient and inelegant at the same time with open('MyTextFile.txt') as file: for line in file: if mName in line: #mName is the string that contains user input Path =str(line).strip('\n') tempStr=Path Path=tempStr.replace(mName+'=',"",1) I was wondering if using RegEx will make this look better. If so, can you please suggest a Regular Expression for this? Any help is highly appreciated. Thank you. From gabriel.rossetti at arimaz.com Mon Feb 9 12:24:12 2009 From: gabriel.rossetti at arimaz.com (Gabriel Rossetti) Date: Mon, 09 Feb 2009 18:24:12 +0100 Subject: poplib Message-ID: <499066BC.6020900@arimaz.com> Hello, I am using poplib and I noticed that calls to top() don't return the msg info (2nd index in the returned list, e.g. email.top(1,0)[1]) in the same order, by that I mean the date could be email.top(1,0)[1][2] or email.top(1,0)[1][5], etc. Is there a reason for that other than that may be how the server is sending them? Why not re-order them and send back a list that always had the date as element n or even better a dict? Thank you, Gabriel From philip at semanchuk.com Mon Feb 9 12:28:50 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 9 Feb 2009 12:28:50 -0500 Subject: Calling into Python from a C thread In-Reply-To: <20090209170259.1D4C78FDE0@panix3.panix.com> References: <20090209170259.1D4C78FDE0@panix3.panix.com> Message-ID: On Feb 9, 2009, at 12:02 PM, Aahz wrote: > [posted & e-mailed] > > In article , > Philip Semanchuk wrote: >> >> I'm trying call Python from inside of a C thread that's running in a >> Python extension I've written and I am not having much luck. My C >> thread function consists of simply this, and I get a segmentation >> fault from Python: > > Because it's been a week without response, I suggest you try the capi > mailing list. I didn't know there *was* such a thing. Thanks for the tip! For those who might be interested, the list is here: http://mail.python.org/mailman/listinfo/capi-sig FYI, I got my code working and it is in the latest release of posix_ipc: http://semanchuk.com/philip/posix_ipc/ The function MessageQueue_request_notification() does some necessary setup and the function process_notification() does the rest of the work. Cheers Philip From jonathan.wright at gmail.com Mon Feb 9 12:36:48 2009 From: jonathan.wright at gmail.com (Jon) Date: Mon, 9 Feb 2009 09:36:48 -0800 (PST) Subject: How to use buildout with a scripts directory? Message-ID: <8e1e9045-593d-4e99-8f8f-05353ef96879@o36g2000yqh.googlegroups.com> Hello, I am trying to use buildout and am having trouble to figure out how to get it to install the scripts that come with a package. They are present inside the egg which is installed by buildout, but they don't end up in the bin directory. After running buildout my bin directory is empty, but I can find: .\eggs\imaged11-1.2.3-py2.5-win32.egg\EGG-INFO\scripts\peaksearch.py In the package I have a directory (ImageD11) with the library stuff in it and a directory named "scripts" with the scripts. When I use distutils or setuptools it does what I expected: setup.py: ... setup(name='ImageD11', ..., packages = ["ImageD11"], package_dir = {"ImageD11":"ImageD11"}, scripts = [ "scripts/peaksearch.py", "scripts/bgmaker.py", ...] ) c:\testImageD11distutils\> python setup.py install ... Installing peaksearch.py script to c:\python25\Scripts Installing bgmaker.py script to c:\python25\Scripts Now I am wondering how to persuade "buildout" to do the same thing, but place those scripts into it's own little area. In buildout.cfg I have: ================== [buildout] parts = ImageD11 [ImageD11] recipe = zc.recipe.egg:scripts scripts = scripts/peaksearch.py eggs = ImageD11 version = 1.2.3 It seems to acknowledge that scripts/peaksearch.py is requested, but doesn't seem to do anything about it. My scripts mostly just map command line arguments to function calls, something like this: if __name__=="__main__": import ImageD11.something, sys ImageD11.something.do_something_interesting( sys.argv[1], sys.argv [2] ) I've read the documentation at http://pypi.python.org/pypi/zc.buildout several times but I still can't figure out how to make these scripts part of the build. There seems to be a lot of talk about entry_points, but I'm blocked on those as to what is the entry point for an if __name__=="__main__": idiom? Thanks in advance for any help! Jon From clp2 at rebertia.com Mon Feb 9 12:40:57 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 9 Feb 2009 09:40:57 -0800 Subject: Help needed to retrieve text from a text-file using RegEx In-Reply-To: <532dd150-9889-41d9-a926-adffa8934393@y1g2000pra.googlegroups.com> References: <532dd150-9889-41d9-a926-adffa8934393@y1g2000pra.googlegroups.com> Message-ID: <50697b2c0902090940o462ee90er978adddbdeb5983d@mail.gmail.com> On Mon, Feb 9, 2009 at 9:22 AM, Oltmans wrote: > Here is the scenario: > > It's a command line program. I ask user for a input string. Based on > that input string I retrieve text from a text file. My text file looks > like following > > Text-file: > ------------- > AbcManager=C:\source\code\Modules\Code-AbcManager\ > AbcTest=C:\source\code\Modules\Code-AbcTest\ > DecConnector=C:\source\code\Modules\Code-DecConnector\ > GHIManager=C:\source\code\Modules\Code-GHIManager\ > JKLConnector=C:\source\code\Modules\Code-JKLConnector > > ------------- > > So now if I run the program and user enters > > DecConnector > > Then I'm supposed to show them this text "C:\source\code\Modules\Code- > DecConnector" from the text-file. Right now I'm retrieving using the > following code which seems quite ineffecient and inelegant at the same > time > > with open('MyTextFile.txt') as file: > > for line in file: > > if mName in line: #mName is the string that > contains user input > > Path =str(line).strip('\n') > > tempStr=Path > > Path=tempStr.replace(mName+'=',"",1) > > I was wondering if using RegEx will make this look better. If so, can > you please suggest a Regular Expression for this? Any help is highly > appreciated. Thank you. If I might repeat Jamie Zawinski's immortal quote: Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems. If you add one section header (e.g. "[main]") to the top of the file, you'll have a valid INI-format file which can be parsed by the ConfigParser module -- http://docs.python.org/library/configparser.html Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From castironpi at gmail.com Mon Feb 9 12:46:26 2009 From: castironpi at gmail.com (Aaron Brady) Date: Mon, 9 Feb 2009 09:46:26 -0800 (PST) Subject: generator object or 'send' method? Message-ID: <929da031-95be-4cda-89ea-560e52435243@e1g2000pra.googlegroups.com> Hello, I am writing a generator to return a sequence of numbers with some variation. The parameters of the variation can be changed by the caller, even after the generator is started. My question is, is it better to wrap the generator in an object, so that the parameters can be changed just by an attribute access? Or keep the generator clear, and modify parameters with a 'send' call? P.S. It would receive the 'send' from a different point in control flow than its usual 'next'. Should it repeat a value if it receives a 'send'? Or should I wrap it in a secondary 'trap_send_and_repeat' generator? Thanks sincerely as always. From todpose at hotmail.com Mon Feb 9 13:09:26 2009 From: todpose at hotmail.com (todpose at hotmail.com) Date: Mon, 9 Feb 2009 10:09:26 -0800 Subject: Putting asterisks around text Message-ID: I'm trying to write a program that puts asterisks around the input text using while loop. I can do this without using while loop, but how can you do that using while loop?Example:Enter a string: Hello world***********Hello world*********** _________________________________________________________________ So many new options, so little time. Windows Live Messenger. http://www.microsoft.com/windows/windowslive/messenger.aspx -------------- next part -------------- An HTML attachment was scrubbed... URL: From darcy at druid.net Mon Feb 9 13:20:46 2009 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Mon, 9 Feb 2009 13:20:46 -0500 Subject: Putting asterisks around text In-Reply-To: References: Message-ID: <20090209132046.091f5b8a.darcy@druid.net> On Mon, 9 Feb 2009 10:09:26 -0800 "todpose at hotmail.com" wrote: > I'm trying to write a program that puts asterisks around the input text using while loop. > I can do this without using while loop, but how can you do that using while loop?Example:Enter a string: Hello world***********Hello world*********** while understand_problem is False: study("textbook") complete("homework") if want_help is True: study("http://www.catb.org/~esr/faqs/smart-questions.html") -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From google at mrabarnett.plus.com Mon Feb 9 13:40:05 2009 From: google at mrabarnett.plus.com (MRAB) Date: Mon, 09 Feb 2009 18:40:05 +0000 Subject: Putting asterisks around text In-Reply-To: <20090209132046.091f5b8a.darcy@druid.net> References: <20090209132046.091f5b8a.darcy@druid.net> Message-ID: <49907885.2000902@mrabarnett.plus.com> D'Arcy J.M. Cain wrote: > On Mon, 9 Feb 2009 10:09:26 -0800 > "todpose at hotmail.com" wrote: >> I'm trying to write a program that puts asterisks around the input text using while loop. >> I can do this without using while loop, but how can you do that using while loop?Example:Enter a string: Hello world***********Hello world*********** > > while understand_problem is False: > study("textbook") > > complete("homework") > > if want_help is True: > study("http://www.catb.org/~esr/faqs/smart-questions.html") > That's not Pythonic, and you shouldn't use "is" except when checking for identity. The recommended style is: while not understand_problem: study("textbook") complete("homework") if want_help: study("http://www.catb.org/~esr/faqs/smart-questions.html") See how much clearer that is? ;-) From rdmurray at bitdance.com Mon Feb 9 13:51:07 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Mon, 9 Feb 2009 18:51:07 +0000 (UTC) Subject: Help needed to retrieve text from a text-file using RegEx References: <532dd150-9889-41d9-a926-adffa8934393@y1g2000pra.googlegroups.com> Message-ID: Oltmans wrote: > Here is the scenario: > > It's a command line program. I ask user for a input string. Based on > that input string I retrieve text from a text file. My text file looks > like following > > Text-file: > ------------- > AbcManager=C:\source\code\Modules\Code-AbcManager\ > AbcTest=C:\source\code\Modules\Code-AbcTest\ > DecConnector=C:\source\code\Modules\Code-DecConnector\ > GHIManager=C:\source\code\Modules\Code-GHIManager\ > JKLConnector=C:\source\code\Modules\Code-JKLConnector > > ------------- > > So now if I run the program and user enters > > DecConnector > > Then I'm supposed to show them this text "C:\source\code\Modules\Code- > DecConnector" from the text-file. Right now I'm retrieving using the > following code which seems quite ineffecient and inelegant at the same > time > > with open('MyTextFile.txt') as file: > for line in file: > if mName in line: #mName is the string that contains user input > Path =str(line).strip('\n') > tempStr=Path > Path=tempStr.replace(mName+'=',"",1) I've normalized your indentation and spacing, for clarity. > I was wondering if using RegEx will make this look better. If so, can > you please suggest a Regular Expression for this? Any help is highly > appreciated. Thank you. This smells like it might be homework, but I'm hoping you'll learn some useful python from what follows regardless of whether it is or not. Since your complaint is that the above code is inelegant and inefficient, let's clean it up. The first three lines that open the file and set up your loop are good, and I think you will agree that they are pretty clean. So, I'm just going to help you clean up the loop body. 'line' is already a string, since it was read from a file. No need to wrap it in 'str': Path = line.strip('\n') tempStr=Path Path=tempStr.replace(mName+'=',"",1) 'strip' removes characters from _both_ ends of the string. If you are trying to make sure that you _only_ strip a trailing newline, then you should be using rstrip. If, on the other hand, you just want to get rid of any leading or trailing whitespace, you could just call 'strip()'. Since your goal is to print the text from after the '=', I'll assume that stripping whitespace is desirable: Path = line.strip() tempStr=Path Path=tempStr.replace(mName+'=',"",1) The statement 'tempStr=Path' doesn't do what you think it does. It just creates an alternate name for the string pointed to by Path. Further, there is no need to have an intermediate variable to hold a value during transformation. The right hand side is computed, using the current values of any variables mentioned, and _then_ the left hand side is rebound to point to the result of the computation. So we can just drop that line entirely, and use 'Path' in the 'replace' statement: Path = line.strip() Path = Path.replace(mName+'=',"",1) However, you can also chain method calls, so really there's no need for two statements here, since both calls are simple: Path = line.strip().replace(mName+'=',"",1) To make things even simpler, Python has a 'split' function. Given the syntax of your input file I think we can assume that '=' never appears in a variable name. split returns a list of strings constructed by breaking the input string at the split character, and it has an optional argument that gives the maximum number of splits to make. So by doing 'split('=', 1), we will get back a list consisting of the variable name and the remainder of the line. The remainder of the line is exactly what you are looking for, and that will be the second element of the returned list. So now your loop body is: Path = line.strip().split('=', 1)[1] and your whole loop looks like this: with open('MyTextFile.txt') as file: for line in file: if mName in line: Path = line.strip().split('=', 1)[1] I think that looks pretty elegant. Oh, and you might want to add a 'break' statement to the loop, and also an 'else:' clause (to the for loop) so you can issue a 'not found' message to the user if they type in a name that does not appear in the input file. --RDM From ptmcg at austin.rr.com Mon Feb 9 13:59:22 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Mon, 9 Feb 2009 10:59:22 -0800 (PST) Subject: Help needed to retrieve text from a text-file using RegEx References: <532dd150-9889-41d9-a926-adffa8934393@y1g2000pra.googlegroups.com> Message-ID: <6a0e4184-26c1-4ea1-bd81-452c7332abbf@i38g2000yqd.googlegroups.com> On Feb 9, 11:22?am, Oltmans wrote: > Here is the scenario: > > It's a command line program. I ask user for a input string. Based on > that input string I retrieve text from a text file. My text file looks > like following > > Text-file: > ------------- > AbcManager=C:\source\code\Modules\Code-AbcManager\ > AbcTest=C:\source\code\Modules\Code-AbcTest\ > DecConnector=C:\source\code\Modules\Code-DecConnector\ > GHIManager=C:\source\code\Modules\Code-GHIManager\ > JKLConnector=C:\source\code\Modules\Code-JKLConnector > Assuming the text-file is in the under-30Mb size, I would just read the whole thing into a dict at startup, and then use the dict over and over. data = file(filename).read() lookup = dict( line.split('=',1) for line in data.splitlines() if line ) # now no further need to access text file, just use lookup variable while True: user_entry = raw_input("Lookup key: ").strip() if not user_entry: break if user_entry in lookup: print lookup[user_entry] else: print "No entry for '%s'" % user_entry From rodmena.com at gmail.com Mon Feb 9 14:01:08 2009 From: rodmena.com at gmail.com (Farsheed Ashouri) Date: Mon, 9 Feb 2009 11:01:08 -0800 (PST) Subject: Local python web server problem References: <30b0923c-313d-4626-8df2-2f877ae9f47a@x9g2000yqk.googlegroups.com> Message-ID: Thanks guys, Really appreciate your help. I am trying to solve the problem and will keep you posted when I found a solution. Farsheed Ashouri, Tehran, Iran From todpose at hotmail.com Mon Feb 9 14:09:49 2009 From: todpose at hotmail.com (todpose at hotmail.com) Date: Mon, 9 Feb 2009 11:09:49 -0800 Subject: Putting asterisks around text Message-ID: From: todpose at hotmail.comTo: python-list at python.orgSubject: Putting asterisks around textDate: Mon, 9 Feb 2009 10:09:26 -0800 I'm trying to write a program that puts asterisks around the input text using while loop.I can do this without using while loop, but how can you do that using while loop?Example:Enter a string: Hello world***********Hello world*********** I'm not necessarily asking for an answer. A hint would be grateful as well. _________________________________________________________________ So many new options, so little time. Windows Live Messenger. http://www.microsoft.com/windows/windowslive/messenger.aspx -------------- next part -------------- An HTML attachment was scrubbed... URL: From digitig at gmail.com Mon Feb 9 14:18:19 2009 From: digitig at gmail.com (Tim Rowe) Date: Mon, 9 Feb 2009 19:18:19 +0000 Subject: Putting asterisks around text In-Reply-To: References: Message-ID: 2009/2/9 todpose at hotmail.com : > I'm not necessarily asking for an answer. A hint would be grateful as well. Great. Well, first you need to read: http://www.catb.org/~esr/faqs/smart-questions.html Especially the section on "Before you ask". Then you should be able to give us a question that shows that you've tried and aren't just wanting us to do your work for you, and that gives us a clear idea of where your sticking point is so we can address the sticking point instead of the whole assignment. Like: How fo you do it without using a while loop? (Yes, *I* know how to do it without using a while loop, but to help you we need to know what *you* know). Like: do you understand what a while loop does? And so on. We're a pretty friendly bunch in here, but most of us believe in "tough love" (http://en.wikipedia.org/wiki/Tough_love). -- Tim Rowe From python.list at tim.thechases.com Mon Feb 9 14:22:25 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 09 Feb 2009 13:22:25 -0600 Subject: Putting asterisks around text In-Reply-To: <20090209132046.091f5b8a.darcy@druid.net> References: <20090209132046.091f5b8a.darcy@druid.net> Message-ID: <49908271.9020703@tim.thechases.com> D'Arcy J.M. Cain wrote: > On Mon, 9 Feb 2009 10:09:26 -0800 > "todpose at hotmail.com" wrote: >> I'm trying to write a program that puts asterisks around the >> input text using while loop. >> I can do this without using while loop, but how can you do >> that using while loop? >> Example:Enter a string: Hello world***********Hello world*********** > > while understand_problem is False: > study("textbook") > complete("homework") This implies global state is changed, and that it holds a literal False rather than a False-ish value. It also doesn't make _good_ use of c.l.p so I'd recommend smart_qs = "http://www.catb.org/~esr/faqs/smart-questions.html" todpose = Newb() todpose.study(textbook) code = todpose.make_coding_attempt() works = test(code) while not (todpose.understand_problem() and works): if works: todpose.study([code, textbook]) else: try: while not passes(todpose.question, smart_qs): todpose.study([ smart_qs, textbook, "www.google.com", "docs.python.org", ]) # Note: consult_clp() expects a valid # code object and a smart-question consult_clp(code, todpose.question) except EpiphanyException: code = todpose.make_coding_attempt() works = test(code) continue todpose.hand_in(teacher, code) -tkc From tjreedy at udel.edu Mon Feb 9 14:22:52 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 09 Feb 2009 14:22:52 -0500 Subject: generator object or 'send' method? In-Reply-To: <929da031-95be-4cda-89ea-560e52435243@e1g2000pra.googlegroups.com> References: <929da031-95be-4cda-89ea-560e52435243@e1g2000pra.googlegroups.com> Message-ID: Aaron Brady wrote: > Hello, > > I am writing a generator to return a sequence of numbers with some > variation. The parameters of the variation can be changed by the > caller, even after the generator is started. My question is, is it > better to wrap the generator in an object, so that the parameters can > be changed just by an attribute access? Rather than wrap a generator, I would just write an iterator class. A generator function is basically an abbreviated class statement. (The abbreviation is the removal of boilerplate code.) > Or keep the generator clear, and modify parameters with a 'send' call? If I were modifying a single parameter and wanted the next value returned immediately upon sending, I would do this. > P.S. It would receive the 'send' from a different point in control > flow than its usual 'next'. Should it repeat a value if it receives a > 'send'? Or should I wrap it in a secondary 'trap_send_and_repeat' > generator? But for this I would go with the class. Pretty foolproof. tjr From stef.mientki at gmail.com Mon Feb 9 14:29:30 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Mon, 09 Feb 2009 20:29:30 +0100 Subject: wxPython vs Glade? In-Reply-To: <20090209132321.GA30754@greedo> References: <20090209132321.GA30754@greedo> Message-ID: <4990841A.8070507@gmail.com> Michael Pobega wrote: > I'm looking for opinions on the best toolkit for a beginner to use with > wxPython. It doesn't necessarily need to be the most efficient toolkit, > but something I can use for basic programs (a Twitter client, Wordpress > blogging client, etc) just to learn Python. > > wxWidgets seems nice because it's portable, but I'm not sure how many of > my libraries are portable (a lot of them seem to import os), while Glade > seems extremely simple to make a UI (but does the program end up relying > on Glade? Or can I build it directly into GTK+?) > > there's XRC and something even easier: http://mientki.ruhosting.nl/data_www/pylab_works/pw_gui_support.html cheers, Stef From stef.mientki at gmail.com Mon Feb 9 14:31:25 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Mon, 09 Feb 2009 20:31:25 +0100 Subject: Best 3d graphics kit for CAD program??? In-Reply-To: <498F1D54.9010509@islandtraining.com> References: <498F1D54.9010509@islandtraining.com> Message-ID: <4990848D.7030505@gmail.com> Gary Herron wrote: > rantingrick wrote: >> I want to build a 3D CAD visualization program with Python. Now before >> you say this is not possible with Python here me out :) >> >> I know OpenGL is probably my best bet BUT i want something a little >> higher level than that. I am not ready for OpenGL yet. I would like a >> kit that is just above OpenGL and abstracts away all the finer >> details, but not too much higher. VPython is a great kit but it is way >> too high level for what i want. Here is a list of kits i am currently >> looking at so if anybody can offer suggestions i would very much like >> the information. Most of these are dedicated game engines but this is >> all i can find >> >> Panda 3D >> OGRE >> Soya 3D >> VTK >> Cystal Space >> CG Kit >> SciPy >> > Maya ? Blender ? cheers, Stef From stef.mientki at gmail.com Mon Feb 9 14:33:57 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Mon, 09 Feb 2009 20:33:57 +0100 Subject: Best 3d graphics kit for CAD program??? In-Reply-To: <498F1D54.9010509@islandtraining.com> References: <498F1D54.9010509@islandtraining.com> Message-ID: <49908525.7070203@gmail.com> Gary Herron wrote: > rantingrick wrote: >> I want to build a 3D CAD visualization program with Python. Now before >> you say this is not possible with Python here me out :) >> >> I know OpenGL is probably my best bet BUT i want something a little >> higher level than that. I am not ready for OpenGL yet. I would like a >> kit that is just above OpenGL and abstracts away all the finer >> details, but not too much higher. VPython is a great kit but it is way >> too high level for what i want. Here is a list of kits i am currently >> looking at so if anybody can offer suggestions i would very much like >> the information. Most of these are dedicated game engines but this is >> all i can find >> >> Panda 3D >> OGRE >> Soya 3D >> VTK >> Cystal Space >> CG Kit >> SciPy >> > I forgot: pySoy Intensity cheers, Stef From lists at cheimes.de Mon Feb 9 14:35:14 2009 From: lists at cheimes.de (Christian Heimes) Date: Mon, 09 Feb 2009 20:35:14 +0100 Subject: Calling into Python from a C thread In-Reply-To: References: <20090209170259.1D4C78FDE0@panix3.panix.com> Message-ID: Philip Semanchuk wrote: > I didn't know there *was* such a thing. Thanks for the tip! For those > who might be interested, the list is here: > http://mail.python.org/mailman/listinfo/capi-sig > > > FYI, I got my code working and it is in the latest release of posix_ipc: > http://semanchuk.com/philip/posix_ipc/ > > The function MessageQueue_request_notification() does some necessary > setup and the function process_notification() does the rest of the work. Let me guess. You either forgot to start Python's threading system or you didn't register you thread with Python. You need to deal with PyThread_init_thread(), PyEval_InitThreads(), PyThreadState_New(), PyThreadState_Clear() and PyThreadState_DeleteCurrent(). The module Modules/threadmodule.c contains some examples. Christian From kyosohma at gmail.com Mon Feb 9 14:38:50 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Mon, 9 Feb 2009 11:38:50 -0800 (PST) Subject: wxPython vs Glade? References: Message-ID: <1f2f07c0-fc91-42b1-8d3b-b9fa7e0c37e6@f3g2000yqf.googlegroups.com> On Feb 9, 7:23?am, Michael Pobega wrote: > I'm looking for opinions on the best toolkit for a beginner to use with > wxPython. It doesn't necessarily need to be the most efficient toolkit, > but something I can use for basic programs (a Twitter client, Wordpress > blogging client, etc) just to learn Python. > > wxWidgets seems nice because it's portable, but I'm not sure how many of > my libraries are portable (a lot of them seem to import os), while Glade > seems extremely simple to make a UI (but does the program end up relying > on Glade? Or can I build it directly into GTK+?) > > -- > ? ? ? ? ? ? ? ? ?http://pobega.wordpress.com > ? ? ? ? ? ? ? ? ? ?http://identica/pobega > > ?signature.asc > < 1KViewDownload I usually just hand-code my apps in IDLE or Wing IDE. I recommend joining the official wxPython mailing list regardless of what you pick though as you'll likely pick up a LOT of helpful tips and tricks there. Mike From mdemenko at gmail.com Mon Feb 9 14:43:42 2009 From: mdemenko at gmail.com (Maxim Demenko) Date: Mon, 09 Feb 2009 20:43:42 +0100 Subject: py2exe and distutils In-Reply-To: References: <6v69nnFi8bmqU1@mid.individual.net> <6v69rkFi8bmqU2@mid.individual.net> Message-ID: <4990876E.5080800@gmail.com> Gabriel Genellina schrieb: > En Sat, 07 Feb 2009 18:39:19 -0200, Thomas Heller > escribi?: > >>> Maxim Demenko schrieb: >>>> Hi, >>>> i have installed Python 2.5.4 on WinXP, setuptools-0.6c9 and py2exe >>>> 0.6.9 >>>> Now i can't list installed modules, here is the stacktrace: >> [...] >>>> Any suggestion, how to fix this issue? >>> >> Thomas Heller schrieb: >>> Looks like a setuptools problem to me. Here's the output on my system: >> >> Actually, I don't know where the problem is. Maybe pydoc? > > Yes, pydoc isn't robust enough in 2.5; see > > for a quick fix. > Thank you Gabriel, that works nicely. Best regards Maxim From mdemenko at gmail.com Mon Feb 9 14:43:42 2009 From: mdemenko at gmail.com (Maxim Demenko) Date: Mon, 09 Feb 2009 20:43:42 +0100 Subject: py2exe and distutils In-Reply-To: References: <6v69nnFi8bmqU1@mid.individual.net> <6v69rkFi8bmqU2@mid.individual.net> Message-ID: <4990876E.5080800@gmail.com> Gabriel Genellina schrieb: > En Sat, 07 Feb 2009 18:39:19 -0200, Thomas Heller > escribi?: > >>> Maxim Demenko schrieb: >>>> Hi, >>>> i have installed Python 2.5.4 on WinXP, setuptools-0.6c9 and py2exe >>>> 0.6.9 >>>> Now i can't list installed modules, here is the stacktrace: >> [...] >>>> Any suggestion, how to fix this issue? >>> >> Thomas Heller schrieb: >>> Looks like a setuptools problem to me. Here's the output on my system: >> >> Actually, I don't know where the problem is. Maybe pydoc? > > Yes, pydoc isn't robust enough in 2.5; see > > for a quick fix. > Thank you Gabriel, that works nicely. Best regards Maxim From deets at nospam.web.de Mon Feb 9 14:59:16 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 09 Feb 2009 20:59:16 +0100 Subject: version in setup.cfg In-Reply-To: <0b778f9a-d811-4dcd-9678-26242a14c4bf@t11g2000yqg.googlegroups.com> References: <0b778f9a-d811-4dcd-9678-26242a14c4bf@t11g2000yqg.googlegroups.com> Message-ID: <6vbg8kFj8k12U1@mid.uni-berlin.de> Jasiu schrieb: > Hi guys, > > I have a question about setup.py and setup.cfg: > > I work in a company and we use Subversion to keep our stuff. We have a > post-commit rule that does the following: whenever there is a commit > to /tags/ directory, a binary package is built automatically. The > tag's name is the new version of the package, i.e. tag names are > something like /tags/1.5.2, /tags/1.2.3 etc. We use setup.py to create > packages. In setup.py we set the version of the package by specifying > 'version' keyword argument to setup function. We have automated builds > and our post-commit script does kind of ugly regexp hack and replaces > string "version='...'" with version that is guessed from the tag name. > And I wonder: It would be much cleaner if the version could be placed > in the setup.cfg file. Is that possible? I don't think so. But there are several other options: - install pysvn & use that in setup.py to extract the tag from the working-copy, making it part of version - instead of the dirty hack, use an a little bit less ugly hack to write that version to a file in the WC, and open & read that within setup.py Diez From lists at cheimes.de Mon Feb 9 15:02:01 2009 From: lists at cheimes.de (Christian Heimes) Date: Mon, 09 Feb 2009 21:02:01 +0100 Subject: thread. question In-Reply-To: <1234193642.7630.63.camel@tim-laptop> References: <1234187238.7630.34.camel@tim-laptop> <1234193642.7630.63.camel@tim-laptop> Message-ID: Tim Wintle schrieb: > Thanks for both replies, > > On Mon, 2009-02-09 at 15:59 +0100, Christian Heimes wrote: >> You shouldn't use the thread module directly. It's not meant to be used >> by a user. Please stick to the threading module. You won't notice a >> slowdown, trust me :) > I'm aware that thread is being renamed to _thread in python 3.0, but is > it being depricated or anything like that? > > This is for an app that has been running for quite a long time and it's > now time for fairly heavy optimisations as load is increasing (Believe > me, I wouldn't have been looking at the C otherwise) - so I'll see if I > do notice any effect with threading. [snip] > Thanks for the info - I'm very aware of the GIL, but had never looked at > the implementation before and for some reason thought that python's > threads were in userspace. > > I'm already using a multiple-process architecture overall, but using > threads to avoid waiting when handling SQL and TCP. The module was renamed to _thread to stop people from using it directly. The extension module is the interface to some low level types and functions. Especially the usage of thread.start_new_thread is problematic, since it bypasses Python's high level threading API. For the rest I have to agree with Jean-Paul. If you need performance don't use threads! Threads and performance are orthogonal -- sometimes they are even contradictorily. From andrew at acooke.org Mon Feb 9 15:07:41 2009 From: andrew at acooke.org (andrew cooke) Date: Mon, 9 Feb 2009 17:07:41 -0300 (CLST) Subject: generator object or 'send' method? In-Reply-To: <929da031-95be-4cda-89ea-560e52435243@e1g2000pra.googlegroups.com> References: <929da031-95be-4cda-89ea-560e52435243@e1g2000pra.googlegroups.com> Message-ID: If I were experimenting with Python to see just how far I could push coroutines at the moment, I would use .send() and look at how I could factor things into a small library (containing, for example, your trap-and-response secondary generator). But if this was paid work, I would write a class with a __next__ method and do things explicitly. In answer to your PS, via a roundabout route: I've done something similar recently by using .throw() to raise an exception in the body of the generator. This was done with a reset() function. So, for example: mygen = ... a = next(mygen) b = next(mygen) reset(mygen) c = next(mygen) And in the generator: while True: try: ... yield ... catch ResetException: yield # discarded by the reset function And finally: def reset(gen): gen.throw(ResetException()) In that case, I needed an extra "yield" that did nothing. Andrew Aaron Brady wrote: > Hello, > > I am writing a generator to return a sequence of numbers with some > variation. The parameters of the variation can be changed by the > caller, even after the generator is started. My question is, is it > better to wrap the generator in an object, so that the parameters can > be changed just by an attribute access? Or keep the generator clear, > and modify parameters with a 'send' call? > > P.S. It would receive the 'send' from a different point in control > flow than its usual 'next'. Should it repeat a value if it receives a > 'send'? Or should I wrap it in a secondary 'trap_send_and_repeat' > generator? > > Thanks sincerely as always. > -- > http://mail.python.org/mailman/listinfo/python-list > > From rt8396 at gmail.com Mon Feb 9 15:08:17 2009 From: rt8396 at gmail.com (r) Date: Mon, 9 Feb 2009 12:08:17 -0800 (PST) Subject: Best 3d graphics kit for CAD program??? References: <498F1D54.9010509@islandtraining.com> Message-ID: On Feb 9, 1:33?pm, Stef Mientki wrote: > Maya ? > Blender ? > I forgot: > pySoy > Intensity Thanks Stef, I actually got OpenGL to install(finally) and now i am thinking ? maybe? i should just go with OpenGL using the wxglcanvas. I have been also "messing" around with Bender but i think i want a stand alone application here. I don't know anything about Maya however? Thanks for the info and feel free to offer more. From philip at semanchuk.com Mon Feb 9 15:38:17 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 9 Feb 2009 15:38:17 -0500 Subject: Calling into Python from a C thread In-Reply-To: References: <20090209170259.1D4C78FDE0@panix3.panix.com> Message-ID: On Feb 9, 2009, at 2:35 PM, Christian Heimes wrote: > Philip Semanchuk wrote: >> I didn't know there *was* such a thing. Thanks for the tip! For those >> who might be interested, the list is here: >> http://mail.python.org/mailman/listinfo/capi-sig >> >> >> FYI, I got my code working and it is in the latest release of >> posix_ipc: >> http://semanchuk.com/philip/posix_ipc/ >> >> The function MessageQueue_request_notification() does some necessary >> setup and the function process_notification() does the rest of the >> work. > > Let me guess. You either forgot to start Python's threading system or > you didn't register you thread with Python. You need to deal with > PyThread_init_thread(), PyEval_InitThreads(), PyThreadState_New(), > PyThreadState_Clear() and PyThreadState_DeleteCurrent(). The module > Modules/threadmodule.c contains some examples. Yes, that's accurate except for the word "forgot". To forget something one must first know it. =) I found the threading API documentation difficult to follow, but I suppose that what I'm doing is a little unusual so if it is not well-documented territory, that's what I get for wandering off the map. From denis.spir at free.fr Mon Feb 9 15:43:31 2009 From: denis.spir at free.fr (spir) Date: Mon, 9 Feb 2009 21:43:31 +0100 Subject: compound regex Message-ID: <20090209214331.7e3c0662@o> Hello, (new here) Below an extension to standard module re. The point is to allow writing and testing sub-expressions individually, then nest them into a super-expression. More or less like using a parser generator -- but keeping regex grammar and power. I used the format {sub_expr_name}: as in standard regexes {} are only used to express repetition number, a pair of curly braces nesting an identifier should not conflict. The extension is new, very few tested. I would enjoy comments, critics, etc. I would like to know if you find such a feature useful. You will probably find the code simple enough ;-) Denis ------ la vida e estranya =============== # coding: utf-8 ''' super_regex Define & check sub-patterns individually, then include them in global super-pattern. uses format {name} for inclusion: sub1 = Regex(...) sub2 = Regex(...) super_format = "...{sub1}...{sub2}..." # final regex object: super_regex = superRegex(super_format) ''' from re import compile as Regex # sub-pattern inclusion format sub_pattern = Regex(r"{[a-zA-Z_][a-zA-Z_0-9]*}") # sub-pattern expander def sub_pattern_expansion(inclusion, dic=None): name = inclusion.group()[1:-1] ### namespace dict may be specified -- else globals() if dic is None: dic = globals() if name not in dic: raise NameError("Cannot find sub-pattern '%s'." % name) return dic[name].pattern # super-pattern generator def superRegex(format): expanded_format = sub_pattern.sub(sub_pattern_expansion, format) return Regex(expanded_format) if __name__ == "__main__": # purely artificial example use # pattern time = Regex(r"\d\d:\d\d:\d\d") # hh:mm:ss code = Regex(r"\S{5}") # non-whitespace x 5 desc = Regex(r"[\w\s]+$") # alphanum|space --> EOL ref_format = "^ref: {time} #{code} --- {desc}" ref_regex = superRegex(ref_format) # output print 'super pattern:\n"%s" ==>\n"%s"\n' % (ref_format,ref_regex.pattern) text = "ref: 12:04:59 #%+.?% --- foo 987 bar" result = ref_regex.match(text) print 'text: "%s" ==>\n"%s"' %(text,result.group()) From fredbasset1000 at gmail.com Mon Feb 9 15:53:45 2009 From: fredbasset1000 at gmail.com (fredbasset1000 at gmail.com) Date: Mon, 9 Feb 2009 12:53:45 -0800 (PST) Subject: problem with import path on a python C extension Message-ID: Hi All, I've written a simple Python extension module in C, but Python is having problems trying to locate it when I import it into an existing Python file. In my example, I wrote a C extension called "diomodule" which exists in the directory : /root/project/drivers/dio/ diomodule.c. It has compiled fine and I end up with a diomodule.so file in that same directory. I have problems when trying to import it into another Python file however, e.g. in a file /root/project/daemon/ daemon.py I tried to import it with "import project.drivers.dio.diomodule". Python throws an error however when I try to call one of the functions: File "/root/project/daemon/daemon.py", line 115, in ? diomodule.init () NameError: name 'diomodule' is not defined I can only get it to work if I copy the .so file to the directory where daemon.py is and change the import to "import diomodule". So my question is why can't Python locate the new extension module when I try to import it with "import project.drivers.dio.diomodule"? Thanks for any responses, Fred From rantingrick at gmail.com Mon Feb 9 15:58:44 2009 From: rantingrick at gmail.com (rantingrick) Date: Mon, 9 Feb 2009 12:58:44 -0800 (PST) Subject: Python 3D CAD -- need collaborators, or just brave souls :) Message-ID: Hello all, It has long been my dream to create an open source 3D CAD program and i am starting to crawl my way into the first steps. I now believe i am ready to start this endeavor and i am currently looking for fellow Python programmers (no matter what skill level) to get started brainstorming this design. I have a real good idea of the UI design and at this point i just want to start simple and build this thing. I figure this will be a good learning experience for myself and others and in the process i can realize my dream. And if all this turns out to be is a learning experience, well nobody lost. Of course Python will limit the speed here, but at this point i want to get a template up and running. Speed does not matter at this point, and optimizations can come along later as i am sure a few complete re- writes are inevitable :) My initial start will cover a very simple user interface something like VPython but much more usable as a CAD modeler. From the start just a few simple primitives (faces, lines-segments) that will be the building blocks for more complex models like (arcs, rectangles, circles, polygons, cubes, spheres, etc..). There will need to be mouse picking as i see this application as a very interactive environment. Of course in the beginning all interaction will most likely be in a command line type manner until the functionality can be worked out. There will need to be a hierarchy of instancing and grouping within the model to facilitate easy transformation of entities within the model. I am not too worried about any sort of texturing at this point. I want to squeeze as much speed as possible and prettiness will come in due course. I also have no plans for layering, or multiple scenes at this time. Simple functionality is the end game here. Once the UI is there and the modeling work flow is worked out, everything should be a component add-on from there. So the main points are... #-- Entities --# face line-segment #-- Hierarchy --# Entity (one face, or line-segment) Group (contained of multiple entities that can be translated, rotated, scaled as one) Instance (component definition) #-- Tools --# line rect circle arc select rotation translation scale extrusion along path measurement So there it is. Any takers? :) From lists at cheimes.de Mon Feb 9 15:59:32 2009 From: lists at cheimes.de (Christian Heimes) Date: Mon, 09 Feb 2009 21:59:32 +0100 Subject: Calling into Python from a C thread In-Reply-To: References: <20090209170259.1D4C78FDE0@panix3.panix.com> Message-ID: Philip Semanchuk wrote: > Yes, that's accurate except for the word "forgot". To forget something > one must first know it. =) I found the threading API documentation > difficult to follow, but I suppose that what I'm doing is a little > unusual so if it is not well-documented territory, that's what I get for > wandering off the map. I see. Apparently the threading and embedding docs don't cover your case. The docs at http://docs.python.org/c-api/init.html#thread-state-and-the-global-interpreter-lock and http://docs.python.org/extending/embedding.html should explain how and when to initialize Python threads. Please report a documentation bug at http://bugs.python.org/. Christian PS: I know a great way to learn more about Python's internal threading CAPI: fix your code, test it and attach a doc patch to your bug report. *hint* :) From carsten.haese at gmail.com Mon Feb 9 16:02:22 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Mon, 09 Feb 2009 16:02:22 -0500 Subject: problem with import path on a python C extension In-Reply-To: References: Message-ID: fredbasset1000 at gmail.com wrote: > [...] > So my question is why can't Python locate the new extension module > when I try to import it with "import project.drivers.dio.diomodule"? This import statement binds the module to the name "project.drivers.dio.diomodule". It does not bind anything to the name "diomodule", which is the name you want to use to refer to the module. To bind the "diomodule" name to this module, you can do one of two things: 1: from project.drivers.dio import diomodule 2: import project.drivers.dio.diomodule diomodule = project.drivers.dio.diomodule Hope this helps, -- Carsten Haese http://informixdb.sourceforge.net From carsten.haese at gmail.com Mon Feb 9 16:08:46 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Mon, 09 Feb 2009 16:08:46 -0500 Subject: problem with import path on a python C extension In-Reply-To: References: Message-ID: fredbasset1000 at gmail.com wrote: > I can only get it to work if I copy the .so file to the directory > where daemon.py is and change the import to "import diomodule". And to supplement my previous reply, another solution is to make sure that /root/project/drivers/dio is in your PYTHONPATH. Then you can simply "import diomodule" and refer to the module by the name "diomodule". HTH, -- Carsten Haese http://informixdb.sourceforge.net From martin at marcher.name Mon Feb 9 17:13:57 2009 From: martin at marcher.name (Martin) Date: Mon, 9 Feb 2009 23:13:57 +0100 Subject: Putting asterisks around text In-Reply-To: References: Message-ID: <5fa6c12e0902091413s182c07c6jc5c3a3f9b6b0c15c@mail.gmail.com> Hi, 2009/2/9 todpose at hotmail.com : > I'm trying to write a program that puts asterisks around the input text > using while loop. > I can do this without using while loop, but how can you do that using while > loop? > > Example: > > Enter a string: Hello world > > ********** > *Hello world* > ********** Since others have posted so helpful answer I'm just going to rant: 1) http://docs.python.org/ <- first part (make sure you read the docs -- and tutorial -- for the python version you installed 2) After you know how to store user input in a variable think about what other facts you know (by examining the content of the variable) 2) Think again hard what you need to output and which parts of the output need to match the information you already have (by doing point 2) That shouldn't be too hard hth Martin -- http://soup.alt.delete.co.at http://www.xing.com/profile/Martin_Marcher http://www.linkedin.com/in/martinmarcher You are not free to read this message, by doing so, you have violated my licence and are required to urinate publicly. Thank you. Please avoid sending me Word or PowerPoint attachments. See http://www.gnu.org/philosophy/no-word-attachments.html From duane.kaufman at gmail.com Mon Feb 9 17:49:45 2009 From: duane.kaufman at gmail.com (TheSeeker) Date: Mon, 9 Feb 2009 14:49:45 -0800 (PST) Subject: Best 3d graphics kit for CAD program??? References: <498F1D54.9010509@islandtraining.com> Message-ID: <63721531-a4de-4103-92a8-b87933df3b22@o2g2000prl.googlegroups.com> On Feb 9, 2:08?pm, r wrote: > On Feb 9, 1:33?pm, Stef Mientki wrote: > > > Maya ? > > Blender ? > > I forgot: > > pySoy > > Intensity > > Thanks Stef, > I actually got OpenGL to install(finally) and now i am thinking ? > maybe? i should just go with OpenGL using the wxglcanvas. I have been > also "messing" around with Bender but i think i want a stand alone > application here. I don't know anything about Maya however? > > Thanks for the info and feel free to offer more. Hi, Have you considered OpenCascade: http://www.opencascade.org/ Along with its python bindings, it might be a good alternative: http://www.pythonocc.org/ Just a thought, Duane From cptn.spoon at gmail.com Mon Feb 9 17:52:16 2009 From: cptn.spoon at gmail.com (cptn.spoon) Date: Mon, 9 Feb 2009 14:52:16 -0800 (PST) Subject: Simple question - stock market simulation References: <6d242a86-c0bc-4c1d-8c38-b263e128bd02@n33g2000pri.googlegroups.com> Message-ID: <746e5493-17c0-4f95-84bf-154bf8655a0c@w39g2000prb.googlegroups.com> On Feb 10, 3:29?am, Anthra Norell wrote: > cptn.spoon wrote: > > I'm trying to create an incredibly simple stock market simulator to be > > used in a childrens classroom and I'm wondering whether someone can > > point me in the right direction. > > > I basically want to be able to have a stock struct as follows: > > > StockName = "Test" > > StockPriceList = (12,13,12,10,10,8,10) > > StockRisk = 0.15 > > StockQty = 2000 > > > And then have a StockMarket struct that can contain 1 to many Stocks. > > I then want to be able to iterate through the stocks to perform > > operations as such: > > > for Stock in StockMarket: > > > I'm not asking for tips on the program itself, I just can't figure out > > how to get the data structures in place. Would I use Classes or would > > I use dictionaries? Am I completely off the mark with this? > > > Apologies for such a rudimentary question...I'm very new to all this. > > -- > >http://mail.python.org/mailman/listinfo/python-list > > If the subject is investment performance, surely your best bet is to > hand out piggy banks. > > Frederic Thank you all for your advice. It's been most helpful! Frederic: Haha, it's more to encourage behaviour and risk management but I agree with your sentiment! From cptn.spoon at gmail.com Mon Feb 9 18:10:39 2009 From: cptn.spoon at gmail.com (cptn.spoon) Date: Mon, 9 Feb 2009 15:10:39 -0800 (PST) Subject: Simple question - stock market simulation References: <6d242a86-c0bc-4c1d-8c38-b263e128bd02@n33g2000pri.googlegroups.com><7xljsgyzn5.fsf@ruckus.brouhaha.com> <1c244978-3224-4a5c-a9d9-60cb2337660e@x6g2000pre.googlegroups.com> Message-ID: <3781c7ab-9801-4680-909c-3d264b80a17f@a12g2000pro.googlegroups.com> On Feb 9, 6:48?pm, "Hendrik van Rooyen" wrote: > "cptn.spoon" wrote: > > On Feb 9, 3:58 pm, Paul Rubin wrote: > > >Thanks Paul! I thought this might be the case. So how would I get the > >StockMarket class instance to contain many Stock class instances and > >then be able to iterate through them? I'm guessing the basic structure > >would be as follows...but I think I'm wrong: > > >class StockMarket: > > ?pass > > No. > At this level, just use a list of instances of your Stock class. > > - Hendrik How do I get a list of instances of a particular class? Is there a way to do this dynamically? Also, what would be the way of dynamically creating an instance of a class based on user input (ie a user wants to create a new instance of the Stock class via shell input)? I'm not sure if I have the wrong mindset here. Thanks for any help ~Phil From lionel.keene at gmail.com Mon Feb 9 18:20:05 2009 From: lionel.keene at gmail.com (Lionel) Date: Mon, 9 Feb 2009 15:20:05 -0800 (PST) Subject: "Super()" confusion Message-ID: Hello. I've been scouring the web looking for something to clear up a little confusion about the use of "super()" but haven't found anything that really helps. Here's my simple example: class Parent: def __init__(self, filePath): . . Do some processing with "filePath" . . class Child(Parent): def __init__(self, filePath): super(Child,self).__init__(filePath) . . Do some additional Child-specific processing on filePath . . As I understand it, "super()" will invoke the initializer of the base class. There must be something wrong with the above syntax since I'm getting: "super(Child,self).__init__(filePath) TypeError: super() argument 1 must be type, not classobj" What have I done wrong? Thanks in advance for any help. L From robert.kern at gmail.com Mon Feb 9 18:26:09 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 09 Feb 2009 17:26:09 -0600 Subject: Simple question - stock market simulation In-Reply-To: <3781c7ab-9801-4680-909c-3d264b80a17f@a12g2000pro.googlegroups.com> References: <6d242a86-c0bc-4c1d-8c38-b263e128bd02@n33g2000pri.googlegroups.com><7xljsgyzn5.fsf@ruckus.brouhaha.com> <1c244978-3224-4a5c-a9d9-60cb2337660e@x6g2000pre.googlegroups.com> <3781c7ab-9801-4680-909c-3d264b80a17f@a12g2000pro.googlegroups.com> Message-ID: On 2009-02-09 17:10, cptn.spoon wrote: > On Feb 9, 6:48 pm, "Hendrik van Rooyen" wrote: >> "cptn.spoon" wrote: >> >> On Feb 9, 3:58 pm, Paul Rubin wrote: >> >>> Thanks Paul! I thought this might be the case. So how would I get the >>> StockMarket class instance to contain many Stock class instances and >>> then be able to iterate through them? I'm guessing the basic structure >>> would be as follows...but I think I'm wrong: >>> class StockMarket: >>> pass >> No. >> At this level, just use a list of instances of your Stock class. >> >> - Hendrik > > How do I get a list of instances of a particular class? Is there a way > to do this dynamically? You *can*, but I highly recommend that you don't. Instead, just keep your own list of instances. When you make a new instance, just append it to the list (see below). all_stocks = [] > Also, what would be the way of dynamically creating an instance of a > class based on user input (ie a user wants to create a new instance of > the Stock class via shell input)? Define an __init__ method on your class to initialize it from given values. Use raw_input() to query the user for information. Convert the text input to whatever objects your class needs (e.g. if the user entered "10" on the prompt, x=raw_input() will return the string '10', so you would do int(x) to get the integer 10). Now, instantiate your class with the arguments: the_stock = Stock(name, risk, initial_price) And append it to your list of stocks. all_stocks.append(the_stock) -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From robert.kern at gmail.com Mon Feb 9 18:27:18 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 09 Feb 2009 17:27:18 -0600 Subject: "Super()" confusion In-Reply-To: References: Message-ID: On 2009-02-09 17:20, Lionel wrote: > Hello. I've been scouring the web looking for something to clear up a > little confusion about the use of "super()" but haven't found anything > that really helps. Here's my simple example: > > > class Parent: > def __init__(self, filePath): > . > . > Do some processing with "filePath" > . > . > > class Child(Parent): > def __init__(self, filePath): > super(Child,self).__init__(filePath) > . > . > Do some additional Child-specific processing on filePath > . > . > > As I understand it, "super()" will invoke the initializer of the base > class. There must be something wrong with the above syntax since I'm > getting: > > "super(Child,self).__init__(filePath) > TypeError: super() argument 1 must be type, not classobj" > > What have I done wrong? Thanks in advance for any help. super() only works on the "new-style" classes introduced in Python 2.2. You need to make Parent subclass from object: class Parent(object): ... -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From Scott.Daniels at Acm.Org Mon Feb 9 18:58:32 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 09 Feb 2009 15:58:32 -0800 Subject: "Super()" confusion In-Reply-To: References: Message-ID: Lionel wrote: > Hello. I've been scouring the web looking for something to clear up a > little confusion about the use of "super()" but haven't found anything > that really helps. Here's my simple example: > > > class Parent: > def __init__(self, filePath):... > > class Child(Parent): > def __init__(self, filePath): > super(Child,self).__init__(filePath) > .... > As I understand it, "super()" will invoke the initializer of the base > class. There must be something wrong with the above syntax since I'm > getting: > "super(Child,self).__init__(filePath) > TypeError: super() argument 1 must be type, not classobj" > > What have I done wrong? Thanks in advance for any help. To use super, you must work with descendants of "object". So, just change your first line to: class Parent(object): and you should find your world back in place. --Scott David Daniels Scott.Daniels at Acm.Org From deets at nospam.web.de Mon Feb 9 19:01:59 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 10 Feb 2009 01:01:59 +0100 Subject: adodb has no attribute connect In-Reply-To: <2fb8b6ce-f18c-457e-8adc-492f6e83f8a8@q30g2000prq.googlegroups.com> References: <2fb8b6ce-f18c-457e-8adc-492f6e83f8a8@q30g2000prq.googlegroups.com> Message-ID: <6vbufnFj957sU1@mid.uni-berlin.de> Rahul schrieb: > Hello all, > > I have to access data from database using adodb so I did > > Import adodb > Conn=adodb.NewADOConnection("odbc") > > Upto this it works properly but when I say It does not. It returns None, thus the following error you see. > Conn.Connect("","","") > > It gives error as > > [Attributrerror]: Object Nonetype has no attribute Connect. > > I have Red Hat Enterprise Linux 4 > Python 2.5 > Mod_python 3.3.1 According to the docs on the (very old and seemingly not actively developed adodb-site), "odbc" needs the Python windows extensions. As you are on redheat, I have difficulties believing you make these work. Maybe mxodbc works? Or even better, ditch that ado-stuff and connect directly to your database. Python's DB-API is better I guess, no need for this attempt at mimicking windows APIs. Diez From exarkun at divmod.com Mon Feb 9 19:04:05 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Mon, 9 Feb 2009 19:04:05 -0500 Subject: "Super()" confusion In-Reply-To: Message-ID: <20090210000405.12853.971581682.divmod.quotient.8036@henry.divmod.com> On Mon, 9 Feb 2009 15:20:05 -0800 (PST), Lionel wrote: >Hello. I've been scouring the web looking for something to clear up a >little confusion about the use of "super()" but haven't found anything >that really helps. Here's my simple example: > > [snip] > >"super(Child,self).__init__(filePath) >TypeError: super() argument 1 must be type, not classobj" > >What have I done wrong? Thanks in advance for any help. Consider whether you really need to use super(). http://fuhm.net/super-harmful/ Jean-Paul From torriem at gmail.com Mon Feb 9 19:08:45 2009 From: torriem at gmail.com (Michael Torrie) Date: Mon, 09 Feb 2009 17:08:45 -0700 Subject: wxPython vs Glade? In-Reply-To: <20090209132321.GA30754@greedo> References: <20090209132321.GA30754@greedo> Message-ID: <4990C58D.5070808@gmail.com> Michael Pobega wrote: > I'm looking for opinions on the best toolkit for a beginner to use with > wxPython. It doesn't necessarily need to be the most efficient toolkit, > but something I can use for basic programs (a Twitter client, Wordpress > blogging client, etc) just to learn Python. > > wxWidgets seems nice because it's portable, but I'm not sure how many of > my libraries are portable (a lot of them seem to import os), while Glade > seems extremely simple to make a UI (but does the program end up relying > on Glade? Or can I build it directly into GTK+?) Glade is very nice for generating GTK guis. If you save in the newer format, then GTK has a built-in api called GtkBuilder for importing the GUI, creating it, and setting up the callbacks. To be clear, glade-generated ui files work only with GTK, not wxPython. If you ever find yourself coding PyQT, the QT Designer is one of the best GUI builders on the planet. From lionel.keene at gmail.com Mon Feb 9 19:18:34 2009 From: lionel.keene at gmail.com (Lionel) Date: Mon, 9 Feb 2009 16:18:34 -0800 (PST) Subject: "Super()" confusion References: mailman.9184.1234224249.3487.python-list@python.org Message-ID: <884a646e-3ad0-4033-a665-8eb3e7eb566e@f40g2000pri.googlegroups.com> On Feb 9, 4:04?pm, Jean-Paul Calderone wrote: > On Mon, 9 Feb 2009 15:20:05 -0800 (PST), Lionel wrote: > >Hello. I've been scouring the web looking for something to clear up a > >little confusion about the use of "super()" but haven't found anything > >that really helps. Here's my simple example: > > > [snip] > > >"super(Child,self).__init__(filePath) > >TypeError: super() argument 1 must be type, not classobj" > > >What have I done wrong? Thanks in advance for any help. > > Consider whether you really need to use super(). > > http://fuhm.net/super-harmful/ > > Jean-Paul Yes, I came across that essay...and it scared me. Will my base class initializer always get called regardless of whether or not I use super ()? If so, does this occur prior to any code in my derived class initializer being executed (in other words, if I don't explicitly call "super()" in my derived class, am I guaranteed that the base class "__init__" has executed completely)? If so, then I guess I can forego the use of "super()" From clp2 at rebertia.com Mon Feb 9 19:25:49 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 9 Feb 2009 16:25:49 -0800 Subject: "Super()" confusion In-Reply-To: <884a646e-3ad0-4033-a665-8eb3e7eb566e@f40g2000pri.googlegroups.com> References: <884a646e-3ad0-4033-a665-8eb3e7eb566e@f40g2000pri.googlegroups.com> Message-ID: <50697b2c0902091625x46eb2a4ejeecb8a9e8c616fb1@mail.gmail.com> On Mon, Feb 9, 2009 at 4:18 PM, Lionel wrote: > On Feb 9, 4:04 pm, Jean-Paul Calderone wrote: >> On Mon, 9 Feb 2009 15:20:05 -0800 (PST), Lionel wrote: >> >Hello. I've been scouring the web looking for something to clear up a >> >little confusion about the use of "super()" but haven't found anything >> >that really helps. Here's my simple example: >> >> > [snip] >> >> >"super(Child,self).__init__(filePath) >> >TypeError: super() argument 1 must be type, not classobj" >> >> >What have I done wrong? Thanks in advance for any help. >> >> Consider whether you really need to use super(). >> >> http://fuhm.net/super-harmful/ >> >> Jean-Paul > > Yes, I came across that essay...and it scared me. Will my base class > initializer always get called regardless of whether or not I use super > ()? No, it is not called unless you /explicitly/ call it (either using super() or manually via BaseClassName.__init__(self, other, args, here)) in your subclass' __init__ or you don't define an __init__ for your subclass (and it inherits __init__ from its first superclass). Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From exarkun at divmod.com Mon Feb 9 19:31:37 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Mon, 9 Feb 2009 19:31:37 -0500 Subject: "Super()" confusion In-Reply-To: <884a646e-3ad0-4033-a665-8eb3e7eb566e@f40g2000pri.googlegroups.com> Message-ID: <20090210003137.12853.1758503199.divmod.quotient.8052@henry.divmod.com> On Mon, 9 Feb 2009 16:18:34 -0800 (PST), Lionel wrote: >On Feb 9, 4:04?pm, Jean-Paul Calderone wrote: >> On Mon, 9 Feb 2009 15:20:05 -0800 (PST), Lionel wrote: >> >Hello. I've been scouring the web looking for something to clear up a >> >little confusion about the use of "super()" but haven't found anything >> >that really helps. Here's my simple example: >> >> > [snip] >> >> >"super(Child,self).__init__(filePath) >> >TypeError: super() argument 1 must be type, not classobj" >> >> >What have I done wrong? Thanks in advance for any help. >> >> Consider whether you really need to use super(). >> >> http://fuhm.net/super-harmful/ >> >> Jean-Paul > >Yes, I came across that essay...and it scared me. Will my base class >initializer always get called regardless of whether or not I use super >()? If so, does this occur prior to any code in my derived class >initializer being executed (in other words, if I don't explicitly call >"super()" in my derived class, am I guaranteed that the base class >"__init__" has executed completely)? If so, then I guess I can forego >the use of "super()" Neither the use nor disuse of super can guarantee any of these things. Old-style base method calling (ie, "Foo.bar(self, ...)" - as opposed to using super) is just as capable of causing these things to happen as is super *except* in the case of diamond inheritance. If you use either correctly, it will do what you want. It's just that using super correctly is a lot harder most of the time. Jean-Paul From contactatishay at gmail.com Mon Feb 9 19:40:40 2009 From: contactatishay at gmail.com (Atishay) Date: Mon, 9 Feb 2009 16:40:40 -0800 (PST) Subject: how to find out vesion of a python module Message-ID: <083dcd2f-c225-471c-8c78-c6570a08d659@v38g2000yqb.googlegroups.com> I have Python Image Library installed. I do not know how to find out its version. How can I do that? Secondly, I get error if I say "import ImageFont" ImportError: The _imaging C module is not installed I have _imaging module though [bash]# file PIL/_imaging.so PIL/_imaging.so: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), not stripped How could I fix this? From cptn.spoon at gmail.com Mon Feb 9 19:46:33 2009 From: cptn.spoon at gmail.com (cptn.spoon) Date: Mon, 9 Feb 2009 16:46:33 -0800 (PST) Subject: Simple question - stock market simulation References: <6d242a86-c0bc-4c1d-8c38-b263e128bd02@n33g2000pri.googlegroups.com><7xljsgyzn5.fsf@ruckus.brouhaha.com> <1c244978-3224-4a5c-a9d9-60cb2337660e@x6g2000pre.googlegroups.com> <3781c7ab-9801-4680-909c-3d264b80a17f@a12g2000pro.googlegroups.com> Message-ID: On Feb 10, 10:26?am, Robert Kern wrote: > On 2009-02-09 17:10, cptn.spoon wrote: > > > > > On Feb 9, 6:48 pm, "Hendrik van Rooyen" ?wrote: > >> "cptn.spoon" ?wrote: > > >> On Feb 9, 3:58 pm, Paul Rubin ?wrote: > > >>> Thanks Paul! I thought this might be the case. So how would I get the > >>> StockMarket class instance to contain many Stock class instances and > >>> then be able to iterate through them? I'm guessing the basic structure > >>> would be as follows...but I think I'm wrong: > >>> class StockMarket: > >>> ? pass > >> No. > >> At this level, just use a list of instances of your Stock class. > > >> - Hendrik > > > How do I get a list of instances of a particular class? Is there a way > > to do this dynamically? > > You *can*, but I highly recommend that you don't. Instead, just keep your own > list of instances. When you make a new instance, just append it to the list (see > below). > > ? ?all_stocks = [] > > > Also, what would be the way of dynamically creating an instance of a > > class based on user input (ie a user wants to create a new instance of > > the Stock class via shell input)? > > Define an __init__ method on your class to initialize it from given values. Use > raw_input() to query the user for information. Convert the text input to > whatever objects your class needs (e.g. if the user entered "10" on the prompt, > x=raw_input() will return the string '10', so you would do int(x) to get the > integer 10). Now, instantiate your class with the arguments: > > ? ?the_stock = Stock(name, risk, initial_price) > > And append it to your list of stocks. > > ? ?all_stocks.append(the_stock) > > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless enigma > ? that is made terrible by our own mad attempt to interpret it as though it had > ? an underlying truth." > ? ?-- Umberto Eco That's exactly what I was after. Thanks Robert! From greg.ewing at canterbury.ac.nz Mon Feb 9 19:47:03 2009 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Tue, 10 Feb 2009 13:47:03 +1300 Subject: ANN: SuPy 1.0 for Windows Message-ID: SuPy 1.0 - Windows ------------------ I have created a Windows binary of SuPy. http://www.cosc.canterbury.ac.nz/greg.ewing/SuPy/ Currently only Python 2.3 is supported. (I'm working on a Python 2.5 version, but there are problems.) It has only been tested with Sketchup 7, although there's a chance it might work with Sketchup 6 as well. I'm not sure how stable this version will be. There is some dodgy mixing of runtime library versions going on. All I can say right now is that it runs the included example without crashing on my test machine. What is SuPy? ------------- SuPy is a plugin for the Sketchup 3D modelling application that lets you script it in Python. This is a first version and is highly experimental. Let me know if it works for you and whether you have any problems. -- Greg Ewing greg.ewing at canterbury.ac.nz From pauljefferson at gmail.com Mon Feb 9 19:51:59 2009 From: pauljefferson at gmail.com (PJ) Date: Mon, 9 Feb 2009 16:51:59 -0800 (PST) Subject: AJAX Post requests Message-ID: <3d4fc3a0-671f-4635-b113-80669c9e6e6d@o11g2000yql.googlegroups.com> Hi, I have a simple web server using BaseHTTPServer, and the def do_POST (self) function works fine for regular forms that are submitted to it, but when I send an AJAX POST to it it does nothing (I've tried to just get it to print to check it's nothing else but it doesn't even do that, although it does for a regular POST request. The post function is def do_POST(self): global rootnode try: ctype, pdict = cgi.parse_header(self.headers.getheader ('content-type')) if ctype == 'multipart/form-data': query=cgi.parse_multipart(self.rfile, pdict) self.send_response(301) self.end_headers() print(query.get('data')) print('test') h = codecs.open ("log.txt", "a", encoding="utf8") h.write("test") h.close() except : pass The AJAX post is appearing in the command prompt as any other post and I can't see any reason why it shouldn't go to this function, particularly if it works for a regular (non-AJAX) post, so any help would be appreciated, Paul From gherron at islandtraining.com Mon Feb 9 20:07:10 2009 From: gherron at islandtraining.com (Gary Herron) Date: Mon, 09 Feb 2009 17:07:10 -0800 Subject: how to find out vesion of a python module In-Reply-To: <083dcd2f-c225-471c-8c78-c6570a08d659@v38g2000yqb.googlegroups.com> References: <083dcd2f-c225-471c-8c78-c6570a08d659@v38g2000yqb.googlegroups.com> Message-ID: <4990D33E.2060003@islandtraining.com> Atishay wrote: > I have Python Image Library installed. I do not know how to find out > its version. How can I do that? > There is no standard way. However many module authors do include soch information, usually in an attribute named version or __version__, or VERSION. PIL uses the VERSION import Image print Image.VERSION > Secondly, I get error if I say "import ImageFont" > > ImportError: The _imaging C module is not installed > > I have _imaging module though > > [bash]# file PIL/_imaging.so > > PIL/_imaging.so: ELF 32-bit LSB shared object, Intel 80386, version 1 > (SYSV), not stripped > > How could I fix this? > It looks like you have it installed incorrectly, How did you install it. What platform/system are you on? PIL usually uses a PIL.pth file. Does that exist? Where? And what are its contents? Gary Herron > -- > http://mail.python.org/mailman/listinfo/python-list > From fetchinson at googlemail.com Mon Feb 9 20:19:41 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Mon, 9 Feb 2009 17:19:41 -0800 Subject: "Super()" confusion In-Reply-To: <20090210000405.12853.971581682.divmod.quotient.8036@henry.divmod.com> References: <20090210000405.12853.971581682.divmod.quotient.8036@henry.divmod.com> Message-ID: >>Hello. I've been scouring the web looking for something to clear up a >>little confusion about the use of "super()" but haven't found anything >>that really helps. Here's my simple example: >> >> [snip] >> >>"super(Child,self).__init__(filePath) >>TypeError: super() argument 1 must be type, not classobj" >> >>What have I done wrong? Thanks in advance for any help. > > Consider whether you really need to use super(). > > http://fuhm.net/super-harmful/ Did you actually read that article, understood it, went through the tons of responses from python-dev team members, including Guido, or simply read its title, did absolutely no serious thinking about it and go on throwing it around as if it would prove anything? I can't believe this "super( ) is harmful" BS is still alive, it grew to be a mature internet meme like the dancing hamster or star wars kid :) See (among tons of other writings): http://mail.python.org/pipermail/python-dev/2005-January/thread.html Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From jacob.kaplanmoss at gmail.com Mon Feb 9 20:26:32 2009 From: jacob.kaplanmoss at gmail.com (Jacob Kaplan-Moss) Date: Mon, 9 Feb 2009 17:26:32 -0800 (PST) Subject: PyCon 2009: Call for sprint projects Message-ID: Python-related projects: join the PyCon Development Sprints! The development sprints are a key part of PyCon, a chance for the contributors to open-source projects to get together face-to-face for up to four days of intensive learning and development. Newbies sit at the same table as the gurus, go out for lunch and dinner together, and have a great time while advancing their project. Sprints are one of the best parts of PyCon; in 2008 over 250 sprinters came for at least one day! If your project would like to sprint at PyCon, now is the time to let us know. We'll collect your info and publish it so that participants will have time to make plans. We'll need to get the word out early so that folks who want to sprint have time to make travel arrangements. In the past, some have been reluctant to commit to sprinting: some may not know what sprinting is all about; others may think that they're not "qualified" to sprint. We're on an ongoing mission to change that perception: * We'll help promote your sprint. The PyCon website, the PyCon blog, the PyCon podcast, and press releases will be there for you. * PyCon attendees will be asked to commit to sprints on the registration form, which will include a list of sprints with links to further info. * We will be featuring a "How To Sprint" session on Sunday afternoon, followed by sprint-related tutorials, all for free. This is a great opportunity to introduce your project to prospective contributors. We'll have more details about this later. * Some sponsors are helping out with the sprints as well. There's also cost. Although the sprinting itself is free, sprints have associated time and hotel costs. We can't do anything about the time cost, but we may have some complimentary rooms and funding available for sprinters. We will have more to say on financial aid later. Those who want to lead a sprint should send the following information to pycon-organizers at python.org: * Project/sprint name * Project URL * The name and contact info (email and/or telephone) for the sprint leader(s) and other contributors who will attend the sprint * Instructions for accessing the project's code repository and documentation (or a URL) * Pointers to new contributor information (setup, etc.) * Any special requirements (projector? whiteboard? flux capacitor?) We will add this information to the PyCon website and set up a wiki page for you (or we can link to yours). Projects should provide a list of goals (bugs to fix, features to add, docs to write, etc.), especially some goals for beginners, to attract new sprinters. The more detail you put there, the more prepared your sprinters will be, and the more results you'll get. In 2008 there were sprints for Python, TurboGears, Pylons, Django, Jython, WSGI, PyGame, Bazaar, Trac, PyCon-Tech, OLPC, Orbited, PyPy, Grok, and many others. We would like to see all these and more! Sprints will start with an introductory session on Sunday, March 29; this session will begin immedately after PyCon's scheduled portion ends. The sprints themselves will run from Monday, March 30 through Thursday, April 2, 2009. You can find all these details and more at http://us.pycon.org/2009/sprints/. If you have any questions, feel free to contact me directly. Thank you very much, and happy coding! Jacob Kaplan-Moss From exarkun at divmod.com Mon Feb 9 20:27:39 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Mon, 9 Feb 2009 20:27:39 -0500 Subject: "Super()" confusion In-Reply-To: Message-ID: <20090210012739.12853.653428988.divmod.quotient.8083@henry.divmod.com> On Mon, 9 Feb 2009 17:19:41 -0800, Daniel Fetchinson wrote: >>>Hello. I've been scouring the web looking for something to clear up a >>>little confusion about the use of "super()" but haven't found anything >>>that really helps. Here's my simple example: >>> >>> [snip] >>> >>>"super(Child,self).__init__(filePath) >>>TypeError: super() argument 1 must be type, not classobj" >>> >>>What have I done wrong? Thanks in advance for any help. >> >> Consider whether you really need to use super(). >> >> http://fuhm.net/super-harmful/ > >Did you actually read that article, understood it, went through the >tons of responses from python-dev team members, including Guido Yes. Why the knee-jerk reaction? I simply pointed out a resource which might be helpful to someone trying to learn to use super. Jean-Paul From fetchinson at googlemail.com Mon Feb 9 20:34:05 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Mon, 9 Feb 2009 17:34:05 -0800 Subject: "Super()" confusion In-Reply-To: <20090210012739.12853.653428988.divmod.quotient.8083@henry.divmod.com> References: <20090210012739.12853.653428988.divmod.quotient.8083@henry.divmod.com> Message-ID: >>>>Hello. I've been scouring the web looking for something to clear up a >>>>little confusion about the use of "super()" but haven't found anything >>>>that really helps. Here's my simple example: >>>> >>>> [snip] >>>> >>>>"super(Child,self).__init__(filePath) >>>>TypeError: super() argument 1 must be type, not classobj" >>>> >>>>What have I done wrong? Thanks in advance for any help. >>> >>> Consider whether you really need to use super(). >>> >>> http://fuhm.net/super-harmful/ >> >>Did you actually read that article, understood it, went through the >>tons of responses from python-dev team members, including Guido > > Yes. Why the knee-jerk reaction? Because throwing around that link carries about the same amount of information as "perl is better than python", "my IDE is better than yours", "vim rulez!", "emacs is cooler than vim", etc, etc. > I simply pointed out a resource which > might be helpful to someone trying to learn to use super. It will certainly not be helpful to anyone trying to learn the usage of super. The person who wrote that essay is simply misunderstanding the concept, as has been explained countless times by the python dev team. Hence, it only increases confusion, adds to the noise and spreads false alarm. Honestly, I don't understand how this thing got so much out of control. If anyone starts an intelligent question or remark about super, this essay is thrown in no matter what. Anyone can explain why? Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From cs at zip.com.au Mon Feb 9 20:38:06 2009 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 10 Feb 2009 12:38:06 +1100 Subject: wsdl2py/ZSI and complex types with arrays In-Reply-To: <4989ba74$0$24592$da0feed9@news.zen.co.uk> Message-ID: <20090210013806.GA29349@cskk.homeip.net> On 04Feb2009 15:55, eviljonny wrote: | I have been trying to write a web service using ZSI with wsdl2py. I have | read 'The Zolera Soap Infrastructure User?s Guide Release 2.0.0' and some | older guides (a guide by Nortel called Using ZSI with wsdl2py) and am | unable to find any working examples of how to use arrays in complex | types. I have a Request method which takes an array as an argument and | responds with an array. [...] | Can anyone provide me an example (or a link to an example) of how to | populate the arrays in complex types? Even pointing me in the right | direction would be wonderful. I am by no means a ZSI expert. You may do better to join this list: https://lists.sourceforge.net/lists/listinfo/pywebsvcs-talk and ask there. Glancing at some code using ZSI-2.1-a1 here I've got code like this: # MR refers to a complex type with a component, # and that contains a list of elements LRL = MR._loginResultList = MR.new_loginResultList() LRL._item = [] for LI in RQ.get_element_LoginList(): class item: ... fill in some class attributes ... LRL._item.append(item) thus populating the with elements. ("item" is only a class for the convenience of having _foo attributes easy to assign to). Cheers, -- Cameron Simpson DoD#743 From contactatishay at gmail.com Mon Feb 9 20:50:25 2009 From: contactatishay at gmail.com (Atishay) Date: Mon, 9 Feb 2009 17:50:25 -0800 (PST) Subject: how to find out vesion of a python module References: <083dcd2f-c225-471c-8c78-c6570a08d659@v38g2000yqb.googlegroups.com> Message-ID: <90ab16f0-bc7f-4489-afbf-6bcfae3061f3@j8g2000yql.googlegroups.com> > > There is no standard way. ?However many module authors do include soch > information, usually in an attribute named version or __version__, or > VERSION. ?PIL uses the VERSION > > import Image > print Image.VERSION Thank you very much. This works > > > Secondly, I get error if I say "import ImageFont" > > > ImportError: The _imaging C module is not installed > > > I have _imaging module though > > > [bash]# file PIL/_imaging.so > > > PIL/_imaging.so: ELF 32-bit LSB shared object, Intel 80386, version 1 > > (SYSV), not stripped > > > How could I fix this? > > It looks like you have it installed incorrectly, ? How did you install > it. ?What platform/system are you on? > PIL usually uses a PIL.pth file. ?Does that exist? ?Where? And what are > its contents? I think it is installed correctly. Here is why. If I do export LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH" now if I run python and say "import ImageFont", it works correctly. contents of PIL.pth [bash]#cat PIL.pth PIL [atishay at borel site-packages]$ ls PIL.pth PIL.pth [atishay at borel site-packages]$ ls -d PIL PIL Now the point is, how do I avoid setting LD_LIBRARY_PATH everytime for python? I know I can write a bash script, but I am sure python would have some feature that I can tweak to make it work. Regards Atishay > > Gary Herron > > > -- > >http://mail.python.org/mailman/listinfo/python-list > > From exarkun at divmod.com Mon Feb 9 20:59:36 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Mon, 9 Feb 2009 20:59:36 -0500 Subject: "Super()" confusion In-Reply-To: Message-ID: <20090210015936.12853.1154494242.divmod.quotient.8101@henry.divmod.com> On Mon, 9 Feb 2009 17:34:05 -0800, Daniel Fetchinson wrote: >>>>>Hello. I've been scouring the web looking for something to clear up a >>>>>little confusion about the use of "super()" but haven't found anything >>>>>that really helps. Here's my simple example: >>>>> >>>>> [snip] >>>>> >>>>>"super(Child,self).__init__(filePath) >>>>>TypeError: super() argument 1 must be type, not classobj" >>>>> >>>>>What have I done wrong? Thanks in advance for any help. >>>> >>>> Consider whether you really need to use super(). >>>> >>>> http://fuhm.net/super-harmful/ >>> >>>Did you actually read that article, understood it, went through the >>>tons of responses from python-dev team members, including Guido >> >> Yes. Why the knee-jerk reaction? > >Because throwing around that link carries about the same amount of >information as "perl is better than python", "my IDE is better than >yours", "vim rulez!", "emacs is cooler than vim", etc, etc. That's not true. The page contains lots of information. >> I simply pointed out a resource which >> might be helpful to someone trying to learn to use super. > >It will certainly not be helpful to anyone trying to learn the usage >of super. The person who wrote that essay is simply misunderstanding >the concept, as has been explained countless times by the python dev >team. Hence, it only increases confusion, adds to the noise and >spreads false alarm. Quoting Guido, in whom you seem to place a lot of faith: Super is intended for use that are designed with method cooperation in mind, so I agree with the best practices in James's Conclusion: """ * Use it consistently, and document that you use it, as it is part of the external interface for your class, like it or not. * Never call super with anything but the exact arguments you received, unless you really know what you're doing. * When you use it on methods whose acceptable arguments can be altered on a subclass via addition of more optional arguments, always accept *args, **kw, and call super like "super(MyClass, self).currentmethod(alltheargsideclared, *args, **kwargs)". If you don't do this, forbid addition of optional arguments in subclasses. * Never use positional arguments in __init__ or __new__. Always use keyword args, and always call them as keywords, and always pass all keywords on to super. """ The original poster's code did not use it consistently, did not document its use, and used positional arguments in __init__. So according to Guido, the OP was misusing super. Why are you complaining that I pointed this out? >Honestly, I don't understand how this thing got so much out of >control. If anyone starts an intelligent question or remark about >super, this essay is thrown in no matter what. Anyone can explain why? You're seriously overreacting. Jean-Paul From benjamin at python.org Mon Feb 9 21:02:43 2009 From: benjamin at python.org (Benjamin Peterson) Date: Tue, 10 Feb 2009 02:02:43 +0000 (UTC) Subject: "Super()" confusion References: <20090210000405.12853.971581682.divmod.quotient.8036@henry.divmod.com> Message-ID: Jean-Paul Calderone divmod.com> writes: > Consider whether you really need to use super(). > > http://fuhm.net/super-harmful/ This article chiefly deals with super()'s harm in multiple inteheritance situations. For the simple case, though, like that presented by the OP, I believe super() is perfect. From samslists at gmail.com Mon Feb 9 21:19:10 2009 From: samslists at gmail.com (Sam) Date: Mon, 9 Feb 2009 18:19:10 -0800 (PST) Subject: codecs.open and buffering modes... Message-ID: <56a55b5c-ca64-4c84-a8a8-3912af384e4c@f40g2000pri.googlegroups.com> codecs.open defaults to line buffering. But open defaults to using the system buffer size. Why the discrepancy? Is it different for a reason? How do these choices affect performance? (Particularly under Linux). Thanks From danielzhou86 at gmail.com Mon Feb 9 21:54:46 2009 From: danielzhou86 at gmail.com (Daniel Zhou) Date: Tue, 10 Feb 2009 10:54:46 +0800 Subject: python-list Message-ID: <8bd9daa20902091854y318a09axe118ebda838b17da@mail.gmail.com> python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From joe at socallinuxexpo.org Mon Feb 9 21:55:54 2009 From: joe at socallinuxexpo.org (joe at socallinuxexpo.org) Date: Mon, 9 Feb 2009 18:55:54 -0800 (PST) Subject: Python at the SoCal Linux Expo Message-ID: <48917.75.19.166.49.1234234554.squirrel@socallinuxexpo.org> Hey guys, The Southern California Linux Expo, a community run conference taking place in Los Angeles on February 20th to 22nd, is offering a 50% discount to the Python community. When you go to register[1], just enter the promo code: PYTHN. If you have any questions, please let me know. Thanks! Joe Smith Southern California Linux Expo [1] https://socallinuxexpo.org/reg7/ From spacebar265 at gmail.com Mon Feb 9 22:10:28 2009 From: spacebar265 at gmail.com (Spacebar265) Date: Mon, 9 Feb 2009 19:10:28 -0800 (PST) Subject: Scanning a file character by character References: <557daab0-504f-47f4-84a7-e98000e7c3b1@y1g2000pra.googlegroups.com> Message-ID: <203f699b-de30-422a-aa7d-97eb62d6ebba@a12g2000pro.googlegroups.com> On Feb 9, 5:13?pm, Steve Holden wrote: > Spacebar265 wrote: > > On Feb 7, 2:17 am, Jorgen Grahn wrote: > >> On Wed, 4 Feb 2009 22:48:13 -0800 (PST), Spacebar265 wrote: > >>> Hi. Does anyone know how to scan a filecharacterbycharacterand > >>> have eachcharacterso I can put it into a variable. I am attempting > >>> to make a chatbot and need this to read the saved input to look for > >>> spelling mistakes and further analysis of user input. > >> That does not follow. To analyze a text, the worst possible starting > >> point is one variable for eachcharacter(what would you call them -- > >> character_1, character_2, ... character_65802 ?) > > I believe most people would read the input a line at a time and split > the lines into words. It does depend whether you are attempting > real-time spelling correction, though. That would be a different case. > > regards > ?Steve > -- > Steve Holden ? ? ? ?+1 571 484 6266 ? +1 800 494 3119 > Holden Web LLC ? ? ? ? ? ? ?http://www.holdenweb.com/ Thanks. How would I do separate lines into words without scanning one character at a time? From kp8 at mac.com Mon Feb 9 22:26:56 2009 From: kp8 at mac.com (kpp9c) Date: Mon, 9 Feb 2009 19:26:56 -0800 (PST) Subject: Python Launcher.app on OS X Message-ID: <2caa16ad-bc2c-4ade-ba1b-d39103066cbd@33g2000yqm.googlegroups.com> I am very confused about the current state of Python on OS X 10.5. Looks like Apple ships with 2.5.1 and that is also the latest installer for OS 10.5. The notes on the wiki page found here: http://wiki.python.org/moin/MacPython/Leopard Say: Mac OS X 10.5.x (Leopard) comes with the 2.5.1 Python distribution pre- installed, with an integrated Python Launcher.app [...] It is recommended that you delete the newly installed Python Launcher.app, because it is already present inside the system Python.framework. If you have installed Apple's developer tools (Xcode et al), it is recommended that you delete the newly installed Build Applet.app, because it is already present in /Developer/Applications/ Utilities/MacPython 2.5. okay... for the life of me i do not see any Python Launcher.app and i just installed OS X 10.5 (running 10.5.6 on intel) .... and i also installed the dev kit. Where the heck is this application? best, kp From gagsl-py2 at yahoo.com.ar Mon Feb 9 22:29:42 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 10 Feb 2009 01:29:42 -0200 Subject: "Super()" confusion References: <20090210012739.12853.653428988.divmod.quotient.8083@henry.divmod.com> Message-ID: En Mon, 09 Feb 2009 23:34:05 -0200, Daniel Fetchinson escribi?: >>>>> Hello. I've been scouring the web looking for something to clear up a >>>>> little confusion about the use of "super()" but haven't found >>>>> anything >>>>> that really helps. Here's my simple example: >>>>> >>>>> [snip] >>>>> >>>>> "super(Child,self).__init__(filePath) >>>>> TypeError: super() argument 1 must be type, not classobj" >>>>> >>>>> What have I done wrong? Thanks in advance for any help. >>>> >>>> Consider whether you really need to use super(). >>>> >>>> http://fuhm.net/super-harmful/ >>> >>> Did you actually read that article, understood it, went through the >>> tons of responses from python-dev team members, including Guido >> >> Yes. Why the knee-jerk reaction? > > Because throwing around that link carries about the same amount of > information as "perl is better than python", "my IDE is better than > yours", "vim rulez!", "emacs is cooler than vim", etc, etc. Not at all. It contains accurate and valuable information that isn't available elsewhere. >> I simply pointed out a resource which >> might be helpful to someone trying to learn to use super. > > It will certainly not be helpful to anyone trying to learn the usage > of super. The person who wrote that essay is simply misunderstanding > the concept, as has been explained countless times by the python dev > team. Hence, it only increases confusion, adds to the noise and > spreads false alarm. AFAIK, all facts appearing in said article are still true (except for 3.x which uses a shorter form). If super usage had been clearly documented in the first place, this had not happened. Perhaps you could point us to some resource explaining how is super supposed to be used correctly? And of those giving explanations in python-dev, nobody cared to add a single word to the Python documentation for years. > Honestly, I don't understand how this thing got so much out of > control. If anyone starts an intelligent question or remark about > super, this essay is thrown in no matter what. Anyone can explain why? Because for a very loooooong time (seven years, 2001-2008) super was almost undocumented. The Library Reference -before release 2.6- only had a short paragraph, the online documentation referred (and still does) to the original essay by Guido introducing descriptors, which is inaccurate and outdated, and then the "... harmful" article was the only source of information available. Worse was the fate of packages and how they're imported: nobody "could be bothered to spell that out" (sic); or how import works in general, still barely documented (one has to dig into the PEP collection, trying to guess what parts are truly implemented and what parts are only a wish...) -- Gabriel Genellina From steven at REMOVE.THIS.cybersource.com.au Mon Feb 9 22:46:52 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 10 Feb 2009 03:46:52 GMT Subject: "Super()" confusion References: <20090210012739.12853.653428988.divmod.quotient.8083@henry.divmod.com> Message-ID: On Mon, 09 Feb 2009 17:34:05 -0800, Daniel Fetchinson wrote: ... >>>> Consider whether you really need to use super(). >>>> >>>> http://fuhm.net/super-harmful/ >>> >>>Did you actually read that article, understood it, went through the >>>tons of responses from python-dev team members, including Guido "Tons" of responses? I count 16, about a third of which are written by James Knight himself (the author of the page you are ranting against), and of the remaining, about half are low-to-zero information content, e.g. Tim Peter's joke about renaming the page for better marketing value. It's especially telling that even Guido, the most vocal critic of the article, is critical of the *title* but not the content. In his first post, he says: "I agree with the best practices in James's Conclusion...", and suggested that if the article was called "Multiple Inheritance Pitfalls in Python" he'd be much happier. >> Yes. Why the knee-jerk reaction? > > Because throwing around that link carries about the same amount of > information as "perl is better than python", "my IDE is better than > yours", "vim rulez!", "emacs is cooler than vim", etc, etc. This is clearly not the case when even the most vocal critic agrees with the article's recommendations. >> I simply pointed out a resource which might be helpful to someone >> trying to learn to use super. > > It will certainly not be helpful to anyone trying to learn the usage of > super. I've read it, and found it very useful. > The person who wrote that essay is simply misunderstanding the > concept, as has been explained countless times by the python dev team. "Countless". Is that more or less than the "tons of responses" above? > Hence, it only increases confusion, adds to the noise and spreads false > alarm. So you say. > Honestly, I don't understand how this thing got so much out of control. > If anyone starts an intelligent question or remark about super, this > essay is thrown in no matter what. Anyone can explain why? Because inheritance is potentially confusing. Multiple inheritance is even more confusing. Multiple inheritance with diamond diagrams even more so, and multiple inheritance with diamond diagrams and non-cooperative classes are simply impossible to get right. Because there are many pitfalls to inheritance in Python, and they aren't obvious: who on earth would imagine that calling __init__ or __new__ with positional arguments could be dangerous? James Knight's article is a well- written, understandable description of some of them, in one place and with a catchy title. Of course people are going to link to it. And finally, because people do wrongly get the impression that using super will magically make those problems go away. I know this, because I was one of them. (I went through the anger period, sure that Knight must be full of it. How could anyone suggest that Guido made a super that isn't perfect? I got past that once I realised just how complex inheritance actually is. Currently I'm in denial, writing code with super and hoping that it will Just Work but not pushing it too hard in case it doesn't.) -- Steven From steven at REMOVE.THIS.cybersource.com.au Mon Feb 9 22:49:03 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 10 Feb 2009 03:49:03 GMT Subject: Scanning a file character by character References: <557daab0-504f-47f4-84a7-e98000e7c3b1@y1g2000pra.googlegroups.com> <203f699b-de30-422a-aa7d-97eb62d6ebba@a12g2000pro.googlegroups.com> Message-ID: On Mon, 09 Feb 2009 19:10:28 -0800, Spacebar265 wrote: > How would I do separate lines into words without scanning one character > at a time? Scan a line at a time, then split each line into words. for line in open('myfile.txt'): words = line.split() should work for a particularly simple-minded idea of words. -- Steven From rt8396 at gmail.com Tue Feb 10 00:05:28 2009 From: rt8396 at gmail.com (r) Date: Mon, 9 Feb 2009 21:05:28 -0800 (PST) Subject: Best 3d graphics kit for CAD program??? References: <498F1D54.9010509@islandtraining.com> <63721531-a4de-4103-92a8-b87933df3b22@o2g2000prl.googlegroups.com> Message-ID: <0a805ebf-0b8e-44ea-9e87-579960466623@x9g2000yqk.googlegroups.com> OpenCascade looks promising. I had look at this before a while back and forgot about it. For now i am taking the OpenGL plunge and I will see where that takes me...? Thanks Duane From research at johnohagan.com Tue Feb 10 00:14:19 2009 From: research at johnohagan.com (John O'Hagan) Date: Tue, 10 Feb 2009 05:14:19 +0000 Subject: Small socket problem In-Reply-To: References: <200902090943.36445.research@johnohagan.com> Message-ID: <200902100514.19632.research@johnohagan.com> On Mon, 9 Feb 2009, Gabriel Genellina wrote: > En Mon, 09 Feb 2009 07:43:36 -0200, John O'Hagan > > escribi?: > > I'm using the socket module (python 2.5) like this (where 'options' > > refers to > > an optparse object) to connect to the Fluidsynth program: > > > > host = "localhost" > > port = 9800 > > fluid = socket(AF_INET, SOCK_STREAM) > > try: > > fluid.connect((host, port)) #Connect if fluidsynth is > > running > > except BaseException: > > print "Connecting to fluidsynth..." #Or start fluidsynth > > soundfont = options.soundfont > > driver = options.driver > > Popen(["fluidsynth", "-i", "-s", "-g", "0.5", > > "-C", "1", "-R", "1", "-l", "-a", driver, "-j", > > soundfont]) > > timeout = 50 > > while 1: > > timeout -= 1 > > if timeout == 0: > > print "Problem with fluidsynth: switching to > > synth." > > play_method = "synth" > > break > > try: > > fluid.connect((host, port)) > > except BaseException: > > sleep(0.05) > > continue > > else: > > break > > > > (I'm using BaseException because I haven't been able to discover what > > exception class[es] socket uses). > > Usually socket.error, which is a subclass of IOError, but others might > happen too I think. In any case, the most generic except clause you should > use is > try: > except Exception: ... > (because you usually don't want to catch KeyboardInterrupt nor SystemExit, > that is, let Ctrl-C and sys.exit() do their work) Thanks, I had been doing "from socket import foo, bar" without importing "error", that now works. I think I should use that specific exception in the try clause for now so I can see any other exceptions that may occur, a good idea? > > > The problem is that this fails to connect ( the error is "111: Connection > > refused") the first time I run it after booting if fluidsynth is not > > already > > running, no matter how long the timeout is; after Ctrl-C'ing out of the > > program, all subsequent attempts succeed. Note that fluidsynth need not > > be > > running for a success to occur. > > Always the same exception? In both lines? Yes; I'm sure this is obvious, but just for clarity: if fluidsynth is not running I expect that error at the first line where connection is attempted, and at the second line during the loop while fluidsynth is loading (this takes 0.5-5 seconds depending on the size of the soundfont it's using). But I don't understand why the connection is still refused once fluidsynth has finished loading. I received an off-list reply to this post to the effect that attempting to reuse a socket on which a connection attempt has failed, will fail, and that I needed to create a new socket for each attempt. It seemed very plausible, so I tried inserting a fresh fluid = socket(AF_INET, SOCK_STREAM) before the second fluid.connect() in the loop; but this still behaved the same way. Is that the way to do it? Annoyingly, I've so far only been able reproduce the problem by rebooting. Regards, John From r.warhekar at gmail.com Tue Feb 10 00:24:13 2009 From: r.warhekar at gmail.com (Rahul) Date: Mon, 9 Feb 2009 21:24:13 -0800 (PST) Subject: adodb has no attribute connect References: <2fb8b6ce-f18c-457e-8adc-492f6e83f8a8@q30g2000prq.googlegroups.com> <6vbufnFj957sU1@mid.uni-berlin.de> Message-ID: On Feb 10, 5:01?am, "Diez B. Roggisch" wrote: > Rahul schrieb: > > > Hello all, > > > I have to access data from database usingadodbso I did > > > Importadodb > > Conn=adodb.NewADOConnection("odbc") > > > Upto this it works properly but when I say > > It does not. It returns None, thus the following error you see. > > > Conn.Connect("","","") > > > It gives error as > > > [Attributrerror]: Object Nonetype has no attribute Connect. > > > I have Red Hat Enterprise Linux 4 > > Python 2.5 > > Mod_python 3.3.1 > > According to the docs on the (very old and seemingly not actively > developedadodb-site), "odbc" needs the Python windows extensions. As > you are on redheat, I have difficulties believing you make these work. > > Maybe mxodbc works? Or even better, ditch that ado-stuff and connect > directly to your database. Python's DB-API is better I guess, no need > for this attempt at mimicking windows APIs. > > Diez Thank you Diez I think this is very useful for me to change my mind and get shifted to DB-API. I will try to work on it. Rahul From michele.simionato at gmail.com Tue Feb 10 00:26:20 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Mon, 9 Feb 2009 21:26:20 -0800 (PST) Subject: "Super()" confusion References: <20090210012739.12853.653428988.divmod.quotient.8083@henry.divmod.com> Message-ID: <2e105a22-dc21-4e69-b25d-522666c1db1c@u13g2000yqg.googlegroups.com> On Feb 10, 4:29?am, "Gabriel Genellina" > AFAIK, all facts appearing in said article are still true (except for 3.x ? > which uses a shorter form). If super usage had been clearly documented in ? > the first place, this had not happened. > Perhaps you could point us to some resource explaining how is super ? > supposed to be used correctly? > And of those giving explanations in python-dev, nobody cared to add a ? > single word to the Python documentation for years. > > > Honestly, I don't understand how this thing got so much out of > > control. If anyone starts an intelligent question or remark about > > super, this essay is thrown in no matter what. Anyone can explain why? > > Because for a very loooooong time (seven years, 2001-2008) super was ? > almost undocumented. The Library Reference -before release 2.6- only had a ? > short paragraph, the online documentation referred (and still does) to the ? > original essay by Guido introducing descriptors, which is inaccurate and ? > outdated, and then the "... harmful" article was the only source of ? > information available. All right. This is way I made the effort of writing a comprehensive collection of all the tricky points about super I knew: http://www.artima.com/weblogs/viewpost.jsp?thread=236275 http://www.artima.com/weblogs/viewpost.jsp?thread=236278 http://www.artima.com/weblogs/viewpost.jsp?thread=237121 Also see this thread on python-dev about the issue of super documentation: http://www.gossamer-threads.com/lists/python/dev/673833 Michele Simionato From research at johnohagan.com Tue Feb 10 00:28:26 2009 From: research at johnohagan.com (John O'Hagan) Date: Tue, 10 Feb 2009 05:28:26 +0000 Subject: generator object or 'send' method? In-Reply-To: <929da031-95be-4cda-89ea-560e52435243@e1g2000pra.googlegroups.com> References: <929da031-95be-4cda-89ea-560e52435243@e1g2000pra.googlegroups.com> Message-ID: <200902100528.27070.research@johnohagan.com> On Mon, 9 Feb 2009, Aaron Brady wrote: > Hello, > > I am writing a generator to return a sequence of numbers with some > variation. The parameters of the variation can be changed by the > caller, even after the generator is started. [...] I would love to see a simple code example of this if you have one; I've been wanting to do this but couldn't even get started. Regards, John From steven at REMOVE.THIS.cybersource.com.au Tue Feb 10 01:04:16 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 10 Feb 2009 06:04:16 GMT Subject: generator object or 'send' method? References: <929da031-95be-4cda-89ea-560e52435243@e1g2000pra.googlegroups.com> Message-ID: On Tue, 10 Feb 2009 05:28:26 +0000, John O'Hagan wrote: > On Mon, 9 Feb 2009, Aaron Brady wrote: >> Hello, >> >> I am writing a generator to return a sequence of numbers with some >> variation. The parameters of the variation can be changed by the >> caller, even after the generator is started. > [...] > > I would love to see a simple code example of this if you have one; I've > been wanting to do this but couldn't even get started. Is this too simple? >>> def gen(n): ... while True: ... obj = yield n ... if obj is not None: n = obj ... >>> g = gen(5) >>> g.next() 5 >>> g.next() 5 >>> g.send(12) 12 >>> g.next() 12 -- Steven From xie.kenneth at gmail.com Tue Feb 10 01:11:31 2009 From: xie.kenneth at gmail.com (Ken) Date: Tue, 10 Feb 2009 14:11:31 +0800 Subject: select error 10093 on winxp Message-ID: <8af39e160902092211r7aa5a156s5a22d12cf0179e8e@mail.gmail.com> I was testing select on windows xp with python 2.6.1, the code is simple: import sys import select def testSelect(): r = select.select([sys.stdin], [], [], 5.0) print r if __name__ == "__main__": try: testSelect() except select.error, e: print e While an error raised like this: (10093, '\xd3\xa6\xd3\xc3\xb3\xcc\xd0\xf2\xc3\xbb\xd3\xd0\xb5\xf7\xd3\xc3 WSAStartup\xa3\xac\xbb\xf2\xd5\xdf WSAStartup') What is this about? Thanks in adv. -------------- next part -------------- An HTML attachment was scrubbed... URL: From lepto.python at gmail.com Tue Feb 10 01:28:15 2009 From: lepto.python at gmail.com (oyster) Date: Tue, 10 Feb 2009 14:28:15 +0800 Subject: can multi-core improve single funciton? Message-ID: <6a4f17690902092228i31fd1661n41c61c4037a289df@mail.gmail.com> I mean this [code] def fib(n): if n<=1: return 1 return fib(n-1)+fib(n-2) useCore(1) timeit(fib(500)) #this show 20 seconds useCore(2) timeit(fib(500)) #this show 10 seconds [/code] Is it possible? and more, can threads/multi-processors/clusters be used to improve fib? thanx From clp2 at rebertia.com Tue Feb 10 01:43:50 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 9 Feb 2009 22:43:50 -0800 Subject: can multi-core improve single funciton? In-Reply-To: <6a4f17690902092228i31fd1661n41c61c4037a289df@mail.gmail.com> References: <6a4f17690902092228i31fd1661n41c61c4037a289df@mail.gmail.com> Message-ID: <50697b2c0902092243r36b5f0d9lcb41fea1b94fe42b@mail.gmail.com> On Mon, Feb 9, 2009 at 10:28 PM, oyster wrote: > I mean this > [code] > def fib(n): > if n<=1: > return 1 > return fib(n-1)+fib(n-2) > > useCore(1) > timeit(fib(500)) #this show 20 seconds > > useCore(2) > timeit(fib(500)) #this show 10 seconds > [/code] > > Is it possible? > > and more, can threads/multi-processors/clusters be used to improve fib? Considering the GIL, I highly doubt it so. Also, the algorithm is fundamentally linear -- each result depends on previous results -- so I don't think you can easily parallelize it (if at all). You'd probably get greater speedup using memoization. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From greg at cosc.canterbury.ac.nz Tue Feb 10 01:58:08 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Tue, 10 Feb 2009 19:58:08 +1300 Subject: 'Import sys' succeeds in C++ embedded code, but module is not fully visible In-Reply-To: <965ac14d-3a1d-4a00-bc94-6d09f2490d67@v42g2000yqv.googlegroups.com> References: <8ddcc387-cc11-4401-8c07-f0ee26983a58@a29g2000pra.googlegroups.com> <965ac14d-3a1d-4a00-bc94-6d09f2490d67@v42g2000yqv.googlegroups.com> Message-ID: <49912580.1000002@cosc.canterbury.ac.nz> Ben Sizer wrote: > Yes, this seems to fix it, thanks. But why? Can some Python guru > explain why these two dictionaries must be the same? (Or what steps we > must take if we want them to be separate?) What's happening is that the import statement is binding the name 'sys' in the locals, not the globals. You don't notice this in the top-level code, since both are in scope there. But inside the function you can only see the top-level globals plus the function's own locals. > I had hoped to be able to clear out the locals dictionary > while leaving useful functions intact in the globals dictionary, but > it would appear that is not practical. You can probably do that by using global statements in the top-level code for the things you want to preserve, e.g. global sys import sys my_local_var = 42 global f def f(): print "This function is in globals and can see sys.path" print sys.path def g(): print "This function is in locals and can't see sys.path" Now clearing the locals will remove g and my_local_var while leaving the rest in globals. The only restriction is that anything you want to refer to from a function will have to be in the globals. This includes other functions -- i.e. f() won't be able to call g() in the example above. -- Greg From mail at microcorp.co.za Tue Feb 10 01:59:54 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Tue, 10 Feb 2009 08:59:54 +0200 Subject: wxPython vs Glade? References: <20090209132321.GA30754@greedo> Message-ID: <002601c98b4d$2e0e46c0$0d00a8c0@hendrik> "Steve Holden" wrote: > There's something called PythonCard built on top of wxPython that's > fairly newb-friendly, though it gets clunkier as your demands grow. > > You might also want to look at Dabo, which is a much more comprehensive > framework that also hides much of wxPython's complexity. > There is also Boa Constructor, that is a RAD tool that I have been quite impressed by, after having been forced to use it in anger. It handles all the GUI stuff for you, and what is there, seems solid and bug free. - Hendrik From gagsl-py2 at yahoo.com.ar Tue Feb 10 02:00:49 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 10 Feb 2009 05:00:49 -0200 Subject: select error 10093 on winxp References: <8af39e160902092211r7aa5a156s5a22d12cf0179e8e@mail.gmail.com> Message-ID: En Tue, 10 Feb 2009 04:11:31 -0200, Ken escribi?: > I was testing select on windows xp with python 2.6.1, the code is simple: See the note in the documentation of module select: http://docs.python.org/library/select.html#select.select "Note: File objects on Windows are not acceptable, but sockets are. On Windows, the underlying select function is provided by the WinSock library, and does not handle file descriptors that don't originate from WinSock." -- Gabriel Genellina From could.net at gmail.com Tue Feb 10 02:13:24 2009 From: could.net at gmail.com (Frank Potter) Date: Mon, 9 Feb 2009 23:13:24 -0800 (PST) Subject: What's wrong with my python? I can't use string Message-ID: <9f2ccdc9-fdf8-4964-b13c-8db673c4f342@y1g2000pra.googlegroups.com> I have a xxx.py which has code as below: import string print dir(string) print string.printable when I run it, I got the strange error: "\n" "\n" "##result##\n" "##msg##\n" "##pass_no##\n" "##pot_num##\n" "##pots_mashed##\n" "##yb_used##\n" "##right##\n" "\n" ['__builtins__', '__doc__', '__file__', '__name__', 'str'] Traceback (most recent call last): File "del2.py", line 4, in ? print string.printable AttributeError: 'module' object has no attribute 'printable' It seems that I did not import the right string module I want. Can someone give me a clue, please? From clp2 at rebertia.com Tue Feb 10 02:20:35 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 9 Feb 2009 23:20:35 -0800 Subject: What's wrong with my python? I can't use string In-Reply-To: <9f2ccdc9-fdf8-4964-b13c-8db673c4f342@y1g2000pra.googlegroups.com> References: <9f2ccdc9-fdf8-4964-b13c-8db673c4f342@y1g2000pra.googlegroups.com> Message-ID: <50697b2c0902092320r3cc5beb8lfda96d030bef9ad1@mail.gmail.com> On Mon, Feb 9, 2009 at 11:13 PM, Frank Potter wrote: > I have a xxx.py which has code as below: > > import string > > print dir(string) > print string.printable > > > when I run it, I got the strange error: > > "\n" > "\n" > "##result##\n" > "##msg##\n" > "##pass_no##\n" > "##pot_num##\n" > "##pots_mashed##\n" > "##yb_used##\n" > "##right##\n" > "\n" > ['__builtins__', '__doc__', '__file__', '__name__', 'str'] > Traceback (most recent call last): > File "del2.py", line 4, in ? > print string.printable > AttributeError: 'module' object has no attribute 'printable' > > It seems that I did not import the right string module I want. Can > someone give me a clue, please? Sounds like the wrong `string` module is being imported. What's the output of `print string.__file__`? Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From mail at microcorp.co.za Tue Feb 10 02:22:20 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Tue, 10 Feb 2009 09:22:20 +0200 Subject: Python 3D CAD -- need collaborators, or just brave souls :) References: Message-ID: <015101c98b57$8bbe7420$0d00a8c0@hendrik> "rantingrick" wrote 8< ----------------- dreams, goals and tentative spec ----------------- Have you looked at Pycad ? - it started off with a similar rush some time ago. Maybe there is something there that you can use and/or salvage. - Hendrik From could.net at gmail.com Tue Feb 10 02:26:52 2009 From: could.net at gmail.com (Frank Potter) Date: Mon, 9 Feb 2009 23:26:52 -0800 (PST) Subject: What's wrong with my python? I can't use string References: <9f2ccdc9-fdf8-4964-b13c-8db673c4f342@y1g2000pra.googlegroups.com> Message-ID: On Feb 10, 3:20?pm, Chris Rebert wrote: > On Mon, Feb 9, 2009 at 11:13 PM, Frank Potter wrote: > > I have a xxx.py which has code as below: > > > import string > > > print dir(string) > > print string.printable > > > when I run it, I got the strange error: > > > "\n" > > "\n" > > "##result##\n" > > "##msg##\n" > > "##pass_no##\n" > > "##pot_num##\n" > > "##pots_mashed##\n" > > "##yb_used##\n" > > "##right##\n" > > "\n" > > ['__builtins__', '__doc__', '__file__', '__name__', 'str'] > > Traceback (most recent call last): > > ?File "del2.py", line 4, in ? > > ? ?print string.printable > > AttributeError: 'module' object has no attribute 'printable' > > > It seems that I did not import the right string module I want. Can > > someone give me a clue, please? > > Sounds like the wrong `string` module is being imported. What's the > output of `print string.__file__`? > > Cheers, > Chris > > -- > Follow the path of the Iguana...http://rebertia.com Thank you so much ~ I got it. I have a string.py in the same directory:( and when I output string.__file__ as you told me, I know it. From timr at probo.com Tue Feb 10 02:34:02 2009 From: timr at probo.com (Tim Roberts) Date: Tue, 10 Feb 2009 07:34:02 GMT Subject: Python binaries with VC++ 8.0? References: <6va201FijdteU1@mid.individual.net> <17612b99-0756-47a1-ae4f-5e05e18813cd@r41g2000prr.googlegroups.com> Message-ID: <38b2p4d6g521bi0rtjiat686pamkvke3i3@4ax.com> Carl Banks wrote: > >I'm pretty sure 2.6.1 is compiled with 8.0. However, I think the >Visual C++ 8.0 uses msvcrt90.dll. No, the two digits of the DLL match the version number of C++. The confusion arises because the product is called "Visual Studio 2008", but it includes Visual C++ 9.0, and hence msvcrt90.dll. People say "VC8" when they really mean Visual Studio 2008. Visual Studio 98 - VC++ 6.0 Visual Studio 2002 - VC++ 7.0 Visual Studio 2003 - VC++ 7.1 Visual Studio 2005 - VC++ 8.0 Visual Studio 2008 - VC++ 9.0 -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From steven at REMOVE.THIS.cybersource.com.au Tue Feb 10 02:34:54 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 10 Feb 2009 07:34:54 GMT Subject: can multi-core improve single funciton? References: Message-ID: On Tue, 10 Feb 2009 14:28:15 +0800, oyster wrote: > I mean this > [code] > def fib(n): > if n<=1: > return 1 > return fib(n-1)+fib(n-2) > > useCore(1) > timeit(fib(500)) #this show 20 seconds > > useCore(2) > timeit(fib(500)) #this show 10 seconds [/code] > > Is it possible? What does useCore(n) mean? > and more, can threads/multi-processors/clusters be used to improve fib? No. The best way to improve fib is to improve fib, not to try running it on faster hardware. Your algorithm makes *many* recursive calls to fib() for each call: fib(1) => 1 function call fib(2) => 3 function calls fib(3) => 5 function calls fib(4) => 9 function calls fib(5) => 15 function calls fib(6) => 25 function calls fib(7) => 41 function calls fib(8) => 67 function calls fib(9) => 109 function calls ... fib(34) => 18454929 function calls fib(35) => 29860703 function calls fib(36) => 48315633 function calls ... fib(498) => 1.723e+104 function calls fib(499) => 2.788e+104 function calls fib(500) => 4.511e+104 function calls Calling fib(500) the way you do will make more than 450 thousand billion billion billion billion billion billion billion billion billion billion billion function calls. You claim that you calculated it in just 20 seconds. On my PC, it takes over a minute to calculate fib(38). I estimate it would take over five hours to calculate fib(50), and fib(100) would probably take 16 million years. I call shenanigans. -- Steven From nick.feinberg at gmail.com Tue Feb 10 02:36:36 2009 From: nick.feinberg at gmail.com (Nicholas Feinberg) Date: Mon, 9 Feb 2009 23:36:36 -0800 Subject: Problem with Tkinter's scale function. Message-ID: <97c1d5380902092336x2289dfcyebf38ba933a53b81@mail.gmail.com> Not the widget, the function in Canvas. So far as I can tell, integer values for scale work fine; you can scale something to a factor of 2, 3, 17, etc. Float values for scale - such as you might use if you were, say, trying to scale a rectangle to half its current size - also work, insofar as the targets of the scale-function are resized. The problem is that, in addition to this resizing, they're sent hurtling off the canvas with remarkable speed; rightwards if there's a float for the x-scale, downwards if there's a float for the y-scale, bottom-rightwards if both are floats. It's entertaining, but rather unhelpful. Code that caused the problem (unlikely to be helpful, but no reason not to include it): self.canvas.scale(self.body,self.radius/(self.radius-.5),self.radius/(self.radius-.05),0,0)#radius is greater than .5 Running Python 2.6 on Vista. -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Tue Feb 10 02:37:12 2009 From: timr at probo.com (Tim Roberts) Date: Tue, 10 Feb 2009 07:37:12 GMT Subject: AJAX Post requests References: <3d4fc3a0-671f-4635-b113-80669c9e6e6d@o11g2000yql.googlegroups.com> Message-ID: <7ib2p4lrhmlhr4gr0ifmvgdi24sp2dm309@4ax.com> PJ wrote: > >I have a simple web server using BaseHTTPServer, and the def do_POST >(self) function works fine for regular forms that are submitted to it, >but when I send an AJAX POST to it it does nothing (I've tried to just >get it to print to check it's nothing else but it doesn't even do >that, although it does for a regular POST request. Are you absolutely sure your AJAX request is being sent with Content-Type multipart/form-data? Your code would explode silently if it didn't, because "query" would not exist when you got to "print(query.get('data'))", and your blanket "except" would hide the error. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From ptmcg at austin.rr.com Tue Feb 10 02:38:01 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Mon, 9 Feb 2009 23:38:01 -0800 (PST) Subject: can multi-core improve single funciton? References: <6a4f17690902092228i31fd1661n41c61c4037a289df@mail.gmail.com> Message-ID: On Feb 10, 12:43?am, Chris Rebert wrote: > Considering the GIL, I highly doubt it so. Also, the algorithm is > fundamentally linear -- each result depends on previous results -- so > I don't think you can easily parallelize it (if at all). You'd > probably get greater speedup using memoization. > Even worse than linear, the function is recursive, which as I understand it, is inherently a no-no when looking for code that is parallel-friendly. If you want multi-core to have some benefit, then your program must have a way for separate parts of the problem to be processed independently. Many matrix processing problems fall into this camp, since the various cells of the matrix can be worked on separately from all others. Prime number searchers break up a problem by having separate processes scan different number ranges independently, or have multiple processes perform rough pass prime filters, who write possible primes to another queue to be more exhaustively checked. This saves the expensive/exhaustive check from being done on every number. Fractal graphics generators (Mandelbrot set plots) can break up the graphics range among different processors, or keep a "queue" of pixels to generate, and each calculator process pulls from the queue until all pixels are computed (some pixels take longer to compute than others). -- Paul From http Tue Feb 10 02:48:44 2009 From: http (Paul Rubin) Date: 09 Feb 2009 23:48:44 -0800 Subject: Python binaries with VC++ 8.0? References: <6va201FijdteU1@mid.individual.net> <17612b99-0756-47a1-ae4f-5e05e18813cd@r41g2000prr.googlegroups.com> <38b2p4d6g521bi0rtjiat686pamkvke3i3@4ax.com> Message-ID: <7xwsby7mw3.fsf@ruckus.brouhaha.com> In case anyone is interested: Gideon Smeding of the University of Utrecht has written a masters' thesis titled "An executable operational semantics for Python". It is actually a formal semantics for a Python subset called minpy. Per the blurb, the semantics are described in literate Haskell that is compiled to an interpreter as well as a formal specification. Somehow there has to be a a reference about "unless you're Dutch" to be made about this ;-). Further info is at: http://gideon.smdng.nl/2009/01/an-executable-operational-semantics-for-python/ I found this link via the Haskell Weekly News, http://sequence.complete.org . From mail at microcorp.co.za Tue Feb 10 02:48:53 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Tue, 10 Feb 2009 09:48:53 +0200 Subject: Simple question - stock market simulation References: <6d242a86-c0bc-4c1d-8c38-b263e128bd02@n33g2000pri.googlegroups.com><7xljsgyzn5.fsf@ruckus.brouhaha.com><1c244978-3224-4a5c-a9d9-60cb2337660e@x6g2000pre.googlegroups.com> <3781c7ab-9801-4680-909c-3d264b80a17f@a12g2000pro.googlegroups.com> Message-ID: <015201c98b57$8c4c5c40$0d00a8c0@hendrik> "cptn.spoon" wrote: On Feb 9, 6:48 pm, "Hendrik van Rooyen" wrote: >> No. >> At this level, just use a list of instances of your Stock class. >> >> - Hendrik > >How do I get a list of instances of a particular class? Is there a way >to do this dynamically? Yes there is. First make an empty list: stock_market = [] Now when you create the instance: stuff = GetStuffFromTheUserIfNecessary() stock_market.append(Stock(stuff)) This leaves the new instance in the last position in the list. When you have done that as many times as you wanted, to create the stocks in the market, you can do: for stock in stock_market: DoThingsWithThisOneStock(stock) > >Also, what would be the way of dynamically creating an instance of a >class based on user input (ie a user wants to create a new instance of >the Stock class via shell input)? This means your program must be looking for that input. Either look at thread and threading, or write a simple loop that gets input, appends a stock, gets more input if required, does something with all the stocks, and either loops or terminates. Or some variation of that like first building the market and then manipulating it. > >I'm not sure if I have the wrong mindset here. > I honestly cannot tell if your mindset is right or wrong - I suppose it depends on your definitions of the two terms. :-) - Hendrik From mail at microcorp.co.za Tue Feb 10 03:07:56 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Tue, 10 Feb 2009 10:07:56 +0200 Subject: Scanning a file character by character References: <557daab0-504f-47f4-84a7-e98000e7c3b1@y1g2000pra.googlegroups.com> <203f699b-de30-422a-aa7d-97eb62d6ebba@a12g2000pro.googlegroups.com> Message-ID: <015301c98b57$8cec93e0$0d00a8c0@hendrik> "Spacebar265" wrote: >Thanks. How would I do separate lines into words without scanning one >character at a time? Type the following at the interactive prompt and see what happens: s = "This is a string composed of a few words and a newline\n" help(s.split) help(s.rstrip) help(s.strip) dir(s) - Hendrik From steven at REMOVE.THIS.cybersource.com.au Tue Feb 10 03:12:30 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 10 Feb 2009 08:12:30 GMT Subject: Variable + String Format References: <019ff536$0$20657$c3e8da3@news.astraweb.com> <01a1281b$0$7503$c3e8da3@news.astraweb.com> Message-ID: On Wed, 11 Feb 2009 18:52:40 +1100, Joel Ross wrote: > Thanks for the quick response guys. Help me out a alot. I'm a newbie to > python and your replies help me understand a bit more about python!! Joel, unless you have Guido's time machine and are actually posting from the future, the clock, or possibly the time zone, on your PC is set wrong. -- Steven From gweis at gmx.at Tue Feb 10 03:18:23 2009 From: gweis at gmx.at (Gerhard Weis) Date: Tue, 10 Feb 2009 18:18:23 +1000 Subject: can multi-core improve single funciton? References: Message-ID: <01a12e1d$0$30497$c3e8da3@news.astraweb.com> Once I have seen Haskell code, that ran fibonacci on a 4 core system. The algorithm itself basically used an extra granularity paramet until which new threads will be sparked. e.g. fib(40, 36) means, calculate fib(40) and spark threads until n=36. 1. divide: fib(n-1), fib(n-2) 2. divide: fib(n-2), fib(n-3) 3. divide: fib(n-3), fib(n-4) We tried this code on a 4 core machine using only 1 core and all 4 cores. 1 core wallclock: ~10s 4 core wallclock: ~3s So there is a signifcant speedup, but I guess, this only works with Haskell out of the box. I have not tried it, but I think you can simulate Haskell's behaviour, by caching the results of fib(n). (We tried the same algorithm in Java. While it utilized all 4 cores, there was no speedup. This is why I think, that result caching is the only way to speedup fibonacci. cheers Gerhard On 2009-02-10 17:34:54 +1000, Steven D'Aprano said: > On Tue, 10 Feb 2009 14:28:15 +0800, oyster wrote: > >> I mean this >> [code] >> def fib(n): >> if n<=1: >> return 1 >> return fib(n-1)+fib(n-2) >> >> useCore(1) >> timeit(fib(500)) #this show 20 seconds >> >> useCore(2) >> timeit(fib(500)) #this show 10 seconds [/code] >> >> Is it possible? > > What does useCore(n) mean? > > >> and more, can threads/multi-processors/clusters be used to improve fib? > > No. The best way to improve fib is to improve fib, not to try running it > on faster hardware. > > Your algorithm makes *many* recursive calls to fib() for each call: > > fib(1) => 1 function call > fib(2) => 3 function calls > fib(3) => 5 function calls > fib(4) => 9 function calls > fib(5) => 15 function calls > fib(6) => 25 function calls > fib(7) => 41 function calls > fib(8) => 67 function calls > fib(9) => 109 function calls > ... > fib(34) => 18454929 function calls > fib(35) => 29860703 function calls > fib(36) => 48315633 function calls > ... > fib(498) => 1.723e+104 function calls > fib(499) => 2.788e+104 function calls > fib(500) => 4.511e+104 function calls > > Calling fib(500) the way you do will make more than 450 thousand billion > billion billion billion billion billion billion billion billion billion > billion function calls. You claim that you calculated it in just 20 > seconds. On my PC, it takes over a minute to calculate fib(38). I > estimate it would take over five hours to calculate fib(50), and fib(100) > would probably take 16 million years. I call shenanigans. From gagsl-py2 at yahoo.com.ar Tue Feb 10 03:19:18 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 10 Feb 2009 06:19:18 -0200 Subject: "Super()" confusion References: <20090210012739.12853.653428988.divmod.quotient.8083@henry.divmod.com> <2e105a22-dc21-4e69-b25d-522666c1db1c@u13g2000yqg.googlegroups.com> Message-ID: En Tue, 10 Feb 2009 03:26:20 -0200, Michele Simionato escribi?: > On Feb 10, 4:29?am, "Gabriel Genellina" >> > Honestly, I don't understand how this thing got so much out of >> > control. If anyone starts an intelligent question or remark about >> > super, this essay is thrown in no matter what. Anyone can explain why? >> >> Because for a very loooooong time (seven years, 2001-2008) super was ? >> almost undocumented. The Library Reference -before release 2.6- only >> had a ? >> short paragraph, the online documentation referred (and still does) to >> the ? >> original essay by Guido introducing descriptors, which is inaccurate >> and ? >> outdated, and then the "... harmful" article was the only source of ? >> information available. > > All right. This is way I made the effort of writing a comprehensive > collection of all the tricky points about super > I knew: > > http://www.artima.com/weblogs/viewpost.jsp?thread=236275 > http://www.artima.com/weblogs/viewpost.jsp?thread=236278 > http://www.artima.com/weblogs/viewpost.jsp?thread=237121 You really should push them to be included in python.org, even in their unfinished form. (At least a link in the wiki pages). Their visibility is almost null now. They're very clearly written - I wish you had published them years ago! > Also see this thread on python-dev about the issue of super > documentation: http://www.gossamer-threads.com/lists/python/dev/673833 Apart from a few remarks in the first posts, there is little criticism of your articles themselves. Looks like adding a section about Python 3 is the only important pending issue - again, you really should publish the series in a more prominent place. -- Gabriel Genellina From jef.mangelschots at gmail.com Tue Feb 10 03:40:15 2009 From: jef.mangelschots at gmail.com (jefm) Date: Tue, 10 Feb 2009 00:40:15 -0800 (PST) Subject: import wx works interactive but not from script Message-ID: <549b9ca1-90f4-403e-b30d-679957f36992@a12g2000pro.googlegroups.com> when I call "import wx" from the interactive console, it works (i.e. it doesn't complain). But when I call the same from a script, it complains that it can not find the wx module. ------------works for interactive---------------------------- Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import wx >>> ------------does not work frm script-------------------------- Traceback (most recent call last): File "c:\temp\myscript.py", line 4, in import wx ImportError: No module named wx I run Vista Home premium 64bit. Python 2.6.1 (the 32-bit version). I installed the latest 32-bit ANSI version of wxpython. (http:// downloads.sourceforge.net/wxpython/wxPython2.8-win32-ansi-2.8.9.1- py26.exe) In the folder C:\Python26\Lib\site-packages, I find a wx.pth file with a single line in there: "wx-2.8-msw-ansi" in that same directory is a folder named "wx-2.8-msw-ansi" and it contains a subdirectory called "wx" with what appears to be the regular wx libary stuff, including __init__.py My PATH starts with C:\Python26;C:\Python26\Scripts;C:\Python26\lib; any idea's ? From steven at REMOVE.THIS.cybersource.com.au Tue Feb 10 03:45:37 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 10 Feb 2009 08:45:37 GMT Subject: can multi-core improve single funciton? References: <01a12e1d$0$30497$c3e8da3@news.astraweb.com> Message-ID: On Tue, 10 Feb 2009 18:18:23 +1000, Gerhard Weis wrote: > Once I have seen Haskell code, that ran fibonacci on a 4 core system. > > The algorithm itself basically used an extra granularity paramet until > which new threads will be sparked. e.g. fib(40, 36) means, calculate > fib(40) and spark threads until n=36. 1. divide: fib(n-1), fib(n-2) > 2. divide: fib(n-2), fib(n-3) > 3. divide: fib(n-3), fib(n-4) > > We tried this code on a 4 core machine using only 1 core and all 4 > cores. 1 core wallclock: ~10s > 4 core wallclock: ~3s Three seconds to calculate fib(40) is terrible. Well, it's a great saving over ten seconds, but it's still horribly, horribly slow. Check this out, on a two-core 2.2 GHz system: >>> import timeit >>> timeit.Timer('fib(40)', 'from __main__ import fib').timeit(1) 7.2956085205078125e-05 That's five orders of magnitude faster. How did I do it? I used a better algorithm. def fib(n, a=1, b=1): if n==0: return a elif n==1: return b return fib(n-1, b, a+b) And for the record: >>> fib(500) 225591516161936330872512695036072072046011324913758190588638866418474627738686883405015987052796968498626L >>> timeit.Timer('fib(500)', 'from __main__ import fib').timeit(1) 0.00083398818969726562 Less than a millisecond, versus millions of years for the OP's algorithm. I know which I would choose. Faster hardware can only go so far in hiding the effect of poor algorithms. -- Steven From mail at microcorp.co.za Tue Feb 10 03:47:32 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Tue, 10 Feb 2009 10:47:32 +0200 Subject: Problem with Tkinter's scale function. References: <97c1d5380902092336x2289dfcyebf38ba933a53b81@mail.gmail.com> Message-ID: <01a301c98b5d$0708b3c0$0d00a8c0@hendrik> Nicholas Feinberg wrote: >Code that caused the problem (unlikely to be helpful, but no reason not to include it): >self.canvas.scale(self.body,self.radius/(self.radius-.5),self.radius/(self.radi us-.05),0,0)#radius is greater than .5 scale's arguments are: scale(TagOrID,xorigen,yorigen,xscale,yscale) You seem to be moving the thing and scaling it to zero... - Hendrik From mail at timgolden.me.uk Tue Feb 10 04:10:18 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 10 Feb 2009 09:10:18 +0000 Subject: import wx works interactive but not from script In-Reply-To: <549b9ca1-90f4-403e-b30d-679957f36992@a12g2000pro.googlegroups.com> References: <549b9ca1-90f4-403e-b30d-679957f36992@a12g2000pro.googlegroups.com> Message-ID: <4991447A.9030801@timgolden.me.uk> jefm wrote: > when I call "import wx" from the interactive console, it works (i.e. > it doesn't complain). > But when I call the same from a script, it complains that it can not > find the wx module. > > ------------works for interactive---------------------------- > Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> import wx >>>> > > ------------does not work frm script-------------------------- > Traceback (most recent call last): > File "c:\temp\myscript.py", line 4, in > import wx > ImportError: No module named wx Do you have only the one version of Python on this machine? Did you upgrade from, eg, Python2.5? And are you running this script by, eg, double-clicking on it / running it from the command prompt with the script name alone? If so, check that ftype python.file shows that .py files are associated with the version of Python you expect. TJG From phillip.oldham at gmail.com Tue Feb 10 04:26:46 2009 From: phillip.oldham at gmail.com (Phillip B Oldham) Date: Tue, 10 Feb 2009 01:26:46 -0800 (PST) Subject: Convert date/time to unix timestamp? Message-ID: Is there a simple way to set a date/time and convert it to a unix timestamp? After some googling I found the following: t = datetime.time(7,0,0) starttime = time.mktime(t.timetuple())+1e-6*t.microsecond That seems like very long-winded. Is there an easier way? I've read the docs on the datetime and time modules, but nothing's jumping out at me. From gagsl-py2 at yahoo.com.ar Tue Feb 10 04:32:35 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 10 Feb 2009 07:32:35 -0200 Subject: can multi-core improve single funciton? References: <01a12e1d$0$30497$c3e8da3@news.astraweb.com> Message-ID: En Tue, 10 Feb 2009 06:45:37 -0200, Steven D'Aprano escribi?: > On Tue, 10 Feb 2009 18:18:23 +1000, Gerhard Weis wrote: > >> We tried this code on a 4 core machine using only 1 core and all 4 >> cores. 1 core wallclock: ~10s >> 4 core wallclock: ~3s > > Three seconds to calculate fib(40) is terrible. Well, it's a great saving > over ten seconds, but it's still horribly, horribly slow. > > Check this out, on a two-core 2.2 GHz system: > > >>>> import timeit >>>> timeit.Timer('fib(40)', 'from __main__ import fib').timeit(1) > 7.2956085205078125e-05 > > That's five orders of magnitude faster. How did I do it? I used a better > algorithm. > > > def fib(n, a=1, b=1): > if n==0: > return a > elif n==1: > return b > return fib(n-1, b, a+b) I agree with your comment, but this is not the right way to write it in Python. This style is fine in a language with tail-call optimization -- but fib(1000) raises `RuntimeError: maximum recursion depth exceeded` The same thing after removing recursion can compute the 2089 digits of fib(10000) without problems: def fib(n): a = b = 1 while n: n, a, b = n-1, b, a+b return a > Less than a millisecond, versus millions of years for the OP's algorithm. > I know which I would choose. Faster hardware can only go so far in hiding > the effect of poor algorithms. Completely agree! -- Gabriel Genellina From bj_666 at gmx.net Tue Feb 10 04:42:57 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 10 Feb 2009 09:42:57 GMT Subject: "Super()" confusion References: <20090210000405.12853.971581682.divmod.quotient.8036@henry.divmod.com> Message-ID: <6vd0h1Fjele5U1@mid.uni-berlin.de> On Tue, 10 Feb 2009 02:02:43 +0000, Benjamin Peterson wrote: > Jean-Paul Calderone divmod.com> writes: >> Consider whether you really need to use super(). >> >> http://fuhm.net/super-harmful/ > > This article chiefly deals with super()'s harm in multiple inteheritance > situations. For the simple case, though, like that presented by the OP, > I believe super() is perfect. But for the simple cases it is unnecessary because it was invented to deal with multiple inheritance problems. Ciao, Marc 'BlackJack' Rintsch From clp2 at rebertia.com Tue Feb 10 04:43:20 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 10 Feb 2009 01:43:20 -0800 Subject: can multi-core improve single funciton? In-Reply-To: References: <01a12e1d$0$30497$c3e8da3@news.astraweb.com> Message-ID: <50697b2c0902100143s3289ca44g2a9a84f3192f6aa@mail.gmail.com> On Tue, Feb 10, 2009 at 12:45 AM, Steven D'Aprano wrote: > On Tue, 10 Feb 2009 18:18:23 +1000, Gerhard Weis wrote: > >> Once I have seen Haskell code, that ran fibonacci on a 4 core system. >> >> The algorithm itself basically used an extra granularity paramet until >> which new threads will be sparked. e.g. fib(40, 36) means, calculate >> fib(40) and spark threads until n=36. 1. divide: fib(n-1), fib(n-2) >> 2. divide: fib(n-2), fib(n-3) >> 3. divide: fib(n-3), fib(n-4) >> >> We tried this code on a 4 core machine using only 1 core and all 4 >> cores. 1 core wallclock: ~10s >> 4 core wallclock: ~3s > > Three seconds to calculate fib(40) is terrible. Well, it's a great saving > over ten seconds, but it's still horribly, horribly slow. > > Check this out, on a two-core 2.2 GHz system: > > >>>> import timeit >>>> timeit.Timer('fib(40)', 'from __main__ import fib').timeit(1) > 7.2956085205078125e-05 > > That's five orders of magnitude faster. How did I do it? I used a better > algorithm. > > > def fib(n, a=1, b=1): > if n==0: > return a > elif n==1: > return b > return fib(n-1, b, a+b) > > > And for the record: > >>>> fib(500) > 225591516161936330872512695036072072046011324913758190588638866418474627738686883405015987052796968498626L >>>> timeit.Timer('fib(500)', 'from __main__ import fib').timeit(1) > 0.00083398818969726562 > > Less than a millisecond, versus millions of years for the OP's algorithm. > I know which I would choose. Faster hardware can only go so far in hiding > the effect of poor algorithms. Indeed. And apparently memoization can hide it also: $ #memoization added to OP's code $ python -m timeit -s 'from memoized_naive_recursive_version import fib' 'fib(40)' 1000000 loops, best of 3: 0.639 usec per loop $ #your code $ python -m timeit -s 'from your_version import fib' 'fib(40)' 100000 loops, best of 3: 15.4 usec per loop $ cat memoized_naive_recursive_version.py def memoize(func): cache = {} def memoized(*args): if args in cache: return cache[args] else: result = func(*args) cache[args] = result return result return memoized @memoize def fib(n): if n <= 1: return 1 else: return fib(n-1) + fib(n-2) However, the naive recursive version fails by exceeding the maximum recursion depth if N is too large, whereas your version continues to succeed for a much higher limit of N. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From gh at ghaering.de Tue Feb 10 04:47:17 2009 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Tue, 10 Feb 2009 10:47:17 +0100 Subject: Which core am I running on? In-Reply-To: References: <2847e691-fbf6-433e-ae71-839dc708073f@t11g2000yqg.googlegroups.com> Message-ID: psaffrey at googlemail.com wrote: > On 9 Feb, 12:24, Gerhard H?ring wrote: >> http://objectmix.com/python/631346-parallel-python.html >> > > Hmm. In fact, this doesn't seem to work for pp. When I run the code > below, it says everything is running on the one core. > > import pp > import random > import time > from string import lowercase > > ncpus = 3 > > def timedCharDump(waittime, char): > time.sleep(waittime) > mycore = open("/proc/%i/stat" % os.getpid()).read().split()[39] > print "I'm doing stuff!", mycore, char > return char > > job_server = pp.Server(ncpus, ppservers=()) > > jobdetails = [ (random.random(), letter) for letter in lowercase ] > > jobs = [ job_server.submit(timedCharDump,(jinput1, jinput2), (), > ("os", "time",)) for jinput1, jinput2 in jobdetails ] > > for job in jobs: > print job() Quick look again found this: http://brokestream.com/procstat.html I guess I counted wrong and it's actually column 38, not 39. -- Gerhard From joelc at cognyx.com Tue Feb 10 05:03:06 2009 From: joelc at cognyx.com (Joel Ross) Date: Tue, 10 Feb 2009 21:03:06 +1100 Subject: Variable + String Format Message-ID: <019ff536$0$20657$c3e8da3@news.astraweb.com> Hi all, I have this piece of code: ######################################################################### wordList = "/tmp/Wordlist" file = open(wordList, 'r+b') def readLines(): for line in file.read(): if not line: break print line + '.com ' return line readLines() file.close() ########################################################################## It returns the results: t.com NOTE: Only returns the first letter of the first word on the first line e.g. test would only print t and readline() does the same thing. I have also tried readlines() which gives me the result: test .com The file Wordlist has one word on each line for example test test1 test2 I need it to loop though the Wordlist file and print/return the results test.com test1.com test2.com I'm just looking for a point in the right direction. Much Thanks JOelC From ringogarcia at gmail.com Tue Feb 10 05:03:09 2009 From: ringogarcia at gmail.com (Nacho) Date: Tue, 10 Feb 2009 02:03:09 -0800 (PST) Subject: Setting DNS using win32com Message-ID: <394007a3-d85b-4d6c-9825-a4db2add8df3@f20g2000yqg.googlegroups.com> I am trying to make a small python application to change DNS servers in a small LAN. I am trying this code but I don't manage it to work, I only get the values removed. My code is this: import win32com.client objWMIService = win32com.client.GetObject("winmgmts: {impersonationLevel=impersonate}!\\\\" + strComputer + "\\root\ \cimv2") nicList = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True") for nic in nicList: nic.DNSServerSearchOrder = (u'1.2.3.4', u'2.3.4.5') nic.SetDNSServerSearchOrder nic.SetDNSServerSearchOrder returns 0 so it is supposed to have been done correctly, but no DNS Server is found in the Network Properties. I don't know what I am doing wrong so any hint or any documentation about this would be appreciated. Thank you by now. From niklas.norrthon at hotmail.com Tue Feb 10 05:05:35 2009 From: niklas.norrthon at hotmail.com (Niklas Norrthon) Date: Tue, 10 Feb 2009 02:05:35 -0800 (PST) Subject: can multi-core improve single funciton? References: <01a12e1d$0$30497$c3e8da3@news.astraweb.com> Message-ID: <2d09213e-8095-43d2-a067-6c2b301fa41a@x9g2000yqk.googlegroups.com> On 10 Feb, 09:45, Steven D'Aprano wrote: > On Tue, 10 Feb 2009 18:18:23 +1000, Gerhard Weis wrote: > > Once I have seen Haskell code, that ran fibonacci on a 4 core system. > > > The algorithm itself basically used an extra granularity paramet until > > which new threads will be sparked. e.g. fib(40, 36) means, calculate > > fib(40) and spark threads until n=36. 1. divide: fib(n-1), fib(n-2) > > 2. divide: fib(n-2), fib(n-3) > > 3. divide: fib(n-3), fib(n-4) > > > We tried this code on a 4 core machine using only 1 core and all 4 > > cores. 1 core wallclock: ~10s > > 4 core wallclock: ~3s > > Three seconds to calculate fib(40) is terrible. Well, it's a great saving > over ten seconds, but it's still horribly, horribly slow. > > Check this out, on a two-core 2.2 GHz system: > > >>> import timeit > >>> timeit.Timer('fib(40)', 'from __main__ import fib').timeit(1) > > 7.2956085205078125e-05 > > That's five orders of magnitude faster. How did I do it? I used a better > algorithm. > > def fib(n, a=1, b=1): > ? ? if n==0: > ? ? ? ? return a > ? ? elif n==1: > ? ? ? ? return b > ? ? return fib(n-1, b, a+b) > > And for the record: > > >>> fib(500) > > 225591516161936330872512695036072072046011324913758190588638866418474627738686883405015987052796968498626L According to the common definition of fibonacci numbers fib(0) = 0, fib (1) = 1 and fib(n) = fib(n-1) + fib(n-2) for n > 1. So the number above is fib(501). >>> timeit.Timer('fib(500)', 'from __main__ import fib').timeit(1) > > 0.00083398818969726562 And now for my version (which admitedly isn't really mine, and returns slightly incorrect fib(n) for large values of n, due to the limited floating point precision). >>> import math >>> sqrt5 = math.sqrt(5) >>> golden_section = (sqrt5 + 1) / 2 >>> def fib(n): return int(golden_section ** n / sqrt5 + 0.5) >>> fib(501) 225591516161940121919323945317755919750165306733355143970858461525064153963081278412888159063487104942080L >>> timeit.Timer('fib(501)', 'from __main__ import fib').timeit(1) 1.9555558083084179e-05 > > Less than a millisecond, versus millions of years for the OP's algorithm. > I know which I would choose. Faster hardware can only go so far in hiding > the effect of poor algorithms. > I agree 100% /Niklas Norrthon From michele.simionato at gmail.com Tue Feb 10 05:11:10 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Tue, 10 Feb 2009 02:11:10 -0800 (PST) Subject: "Super()" confusion References: <20090210000405.12853.971581682.divmod.quotient.8036@henry.divmod.com> <6vd0h1Fjele5U1@mid.uni-berlin.de> Message-ID: <34d373ad-52d2-4d38-94b7-d566a5a5dd58@s20g2000yqh.googlegroups.com> On Feb 10, 10:42?am, Marc 'BlackJack' Rintsch wrote: > On Tue, 10 Feb 2009 02:02:43 +0000, Benjamin Peterson wrote: > > Jean-Paul Calderone divmod.com> writes: > >> Consider whether you really need to use super(). > > >>http://fuhm.net/super-harmful/ > > > This article chiefly deals with super()'s harm in multiple inteheritance > > situations. For the simple case, though, like that presented by the OP, > > I believe super() is perfect. > > But for the simple cases it is unnecessary because it was invented to > deal with multiple inheritance problems. > > Ciao, > ? ? ? ? Marc 'BlackJack' Rintsch Unfortunately there is no good solution. If you have a single inheritance hierarchy and you do not use super, you make it impossible for users of your hierarchy to subclass it by using multiple inheritance in a cooperative way (this is not polite). OTOH, if you user super, your users must know about it, to avoid unexpected cooperation. It is all explained in the "super harmful" paper, which is a must read even if you only use single inheritance. From greg at cosc.canterbury.ac.nz Tue Feb 10 05:57:51 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Tue, 10 Feb 2009 23:57:51 +1300 Subject: Python binaries with VC++ 8.0? In-Reply-To: References: <6va201FijdteU1@mid.individual.net> Message-ID: <49915DAF.9080901@cosc.canterbury.ac.nz> Mark Hammond wrote: > What problems specifically? The only practical problems you should see > will arise if you try and pass a "FILE *", or allocate memory you then > ask python to free (or vice-versa) - both should be avoidable though... It concerns a Ruby plugin for Sketchup that embeds a Python interpreter and acts as a bridge between Ruby and Python. I'm using Sketchup 7 which uses msvcrt80.dll, and includes a Ruby dll which is presumably also linked against that crt. I've made some progress on the issue. One problem turned out to be a result of allocating something with ruby_xmalloc() and freeing it with free(), which was easy to fix. Another one seemed to be something to do with trying to use a global var that points to the current Ruby stack frame. I don't really know what was happening, but I found another way of doing things that sidestepped the issue. I've now got it working, at first sight anyhow, using Python 2.3. But it doesn't work properly with Python 2.5. The problem appears to be related to compiling .py files to .pyc. The first time I run it and try to import a module, a .pyc is generated, but then a crash occurs when trying to call one of the functions imported from it. If I run it a second time, with the previously generated .pyc in place, it runs successfully. Which makes me think it may be some kind of FILE * problem, but I'm not sure what, since all the stdio operations on the files concerned should be getting done by Python. To add insult to injury, it's proving to be very difficult to debug, because Sketchup seems to crash all on its own when run under gdb on Windows, even when I don't load any of my code. So I can't get a traceback of where the crash is occurring. There's one possibility I just thought of -- Python may be trying to write something to stdout or stderr, in which case it will probably be using the wrong crt to do it. Something to look into after I've got some sleep... -- Greg From crculver at christopherculver.com Tue Feb 10 06:33:35 2009 From: crculver at christopherculver.com (Christopher Culver) Date: Tue, 10 Feb 2009 13:33:35 +0200 Subject: Converting timestamps across timezones Message-ID: <87tz72wmpc.fsf@christopherculver.com> A script that I'm writing pulls the system time off of an iPod connected to the computer. The iPod's time is represented as a Unix timestamp (seconds since the epoch), but this timestamp does not represent UTC time, but rather the local timezone of the owner. I need to convert this local time timestamp into a UTC timestamp by referring to the timezone specified by /etc/localtime on the computer. I've read through the docs, but I'm rather lost on how to pull this particular operation off. Any advice would be appreciated. From duncan.booth at invalid.invalid Tue Feb 10 07:06:06 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 10 Feb 2009 12:06:06 GMT Subject: Scanning a file character by character References: <557daab0-504f-47f4-84a7-e98000e7c3b1@y1g2000pra.googlegroups.com> <203f699b-de30-422a-aa7d-97eb62d6ebba@a12g2000pro.googlegroups.com> Message-ID: Steven D'Aprano wrote: > On Mon, 09 Feb 2009 19:10:28 -0800, Spacebar265 wrote: > >> How would I do separate lines into words without scanning one character >> at a time? > > Scan a line at a time, then split each line into words. > > > for line in open('myfile.txt'): > words = line.split() > > > should work for a particularly simple-minded idea of words. > Or for a slightly less simple minded splitting you could try re.split: >>> re.split("(\w+)", "The quick brown fox jumps, and falls over.")[1::2] ['The', 'quick', 'brown', 'fox', 'jumps', 'and', 'falls', 'over'] -- Duncan Booth http://kupuguy.blogspot.com From pauljefferson at gmail.com Tue Feb 10 07:27:51 2009 From: pauljefferson at gmail.com (Paul) Date: Tue, 10 Feb 2009 04:27:51 -0800 (PST) Subject: AJAX Post requests References: <3d4fc3a0-671f-4635-b113-80669c9e6e6d@o11g2000yql.googlegroups.com> <7ib2p4lrhmlhr4gr0ifmvgdi24sp2dm309@4ax.com> Message-ID: On Feb 10, 7:37?am, Tim Roberts wrote: > PJ wrote: > > >I have a simple web server using ?BaseHTTPServer, and the def do_POST > >(self) function works fine for regular forms that are submitted to it, > >but when I send anAJAXPOST to it it does nothing (I've tried to just > >get it to print to check it's nothing else but it doesn't even do > >that, although it does for a regular POST request. > > Are you absolutely sure yourAJAXrequest is being sent with Content-Type > multipart/form-data? ?Your code would explode silently if it didn't, > because "query" would not exist when you got to "print(query.get('data'))", > and your blanket "except" would hide the error. > -- > Tim Roberts, t... at probo.com > Providenza & Boekelheide, Inc. Thankyou for that - you're right - I'm new to AJAX so it's taking me a bit of time to get used to it - its an application data type being submitted From bearophileHUGS at lycos.com Tue Feb 10 07:29:07 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Tue, 10 Feb 2009 04:29:07 -0800 (PST) Subject: Python binaries with VC++ 8.0? References: <6va201FijdteU1@mid.individual.net> <17612b99-0756-47a1-ae4f-5e05e18813cd@r41g2000prr.googlegroups.com> <38b2p4d6g521bi0rtjiat686pamkvke3i3@4ax.com> <7xwsby7mw3.fsf@ruckus.brouhaha.com> Message-ID: <1732ba01-6096-4d38-a09d-fe1fbe75b435@l1g2000yqj.googlegroups.com> Paul Rubin: > Gideon Smeding of the University of > Utrecht has written a masters' thesis titled "An executable > operational semantics for Python". A significant part of Computer Science is a waste of time and money. Bye, bearophile From durumdara at gmail.com Tue Feb 10 07:29:50 2009 From: durumdara at gmail.com (durumdara) Date: Tue, 10 Feb 2009 13:29:50 +0100 Subject: STMP, mail, sender-from, to-bcc-addr Message-ID: <4991733E.4040608@gmail.com> Hi! I wanna ask that have anyone some experience with email.msg and smtplib? The email message and smtp.send already have "sender/from" and "recip/addr to". Possible the smtp components does not uses the email tags if I not define them only in the message? Can I do same thing as in GMAIL that the mail does not have TO, only BCC tags/recipients, and no one of the recipients who knows about the each others? Thanks: dd From andrew at acooke.org Tue Feb 10 07:30:05 2009 From: andrew at acooke.org (andrew cooke) Date: Tue, 10 Feb 2009 09:30:05 -0300 (CLST) Subject: generator object or 'send' method? In-Reply-To: References: <929da031-95be-4cda-89ea-560e52435243@e1g2000pra.googlegroups.com> Message-ID: <996d9fdfe31fb995b8c616e90a6eff79.squirrel@acooke.dyndns.org> steven probably knows this, but to flag the issue for people who are looking at generators/coroutines for the first time: there's a little "gotcha" about exactly how the two sides of the conversation are synchronized. in simple terms: send also receives. unfortunately the example steven gave doesn't really show this, so i've modified it below. you can now see that the first next() after .send() receives 2, not 1. note that i am using python 3, so the .next() method is .__next__() (the asymmetry between next and send seems odd to me, but there you go). (in a sense this is completely logical, but if you're used to the asynchronous way the internet works, it can seem unintuitive) how to handle this was one of the things the original post was asking about (if i understood correctly). >>> def gen(n): ... while True: ... obj = yield n ... n += 1 ... if obj is not None: n = obj ... >>> g = gen(5) >>> next(g) 5 >>> g.__next__() 6 >>> g.send(1) 1 >>> next(g) 2 andrew Steven D'Aprano wrote: > On Tue, 10 Feb 2009 05:28:26 +0000, John O'Hagan wrote: >> I would love to see a simple code example of this if you have one; I've >> been wanting to do this but couldn't even get started. > > Is this too simple? > >>>> def gen(n): > ... while True: > ... obj = yield n > ... if obj is not None: n = obj > ... >>>> g = gen(5) >>>> g.next() > 5 >>>> g.next() > 5 >>>> g.send(12) > 12 >>>> g.next() > 12 From joelc at cognyx.com Tue Feb 10 07:35:33 2009 From: joelc at cognyx.com (Joel Ross) Date: Tue, 10 Feb 2009 23:35:33 +1100 Subject: Variable + String Format In-Reply-To: <019ff536$0$20657$c3e8da3@news.astraweb.com> References: <019ff536$0$20657$c3e8da3@news.astraweb.com> Message-ID: <01a16a69$0$7503$c3e8da3@news.astraweb.com> Joel Ross wrote: > Hi all, > > I have this piece of code: > ######################################################################### > > wordList = "/tmp/Wordlist" > file = open(wordList, 'r+b') > > > def readLines(): > > for line in file.read(): > if not line: break > print line + '.com ' > return line > > > > readLines() > file.close() > > ########################################################################## > > It returns the results: > > t.com > > NOTE: Only returns the first letter of the first word on the first line > e.g. test would only print t and readline() does the same thing. > > I have also tried readlines() which gives me the result: > > test > .com > > The file Wordlist has one word on each line for example > > test > test1 > test2 > > I need it to loop though the Wordlist file and print/return the results > > test.com > test1.com > test2.com > > I'm just looking for a point in the right direction. > > Much Thanks > > JOelC THAT'S BETTER!!! :) From gerhard at proclos.com Tue Feb 10 07:41:25 2009 From: gerhard at proclos.com (Gerhard Weis) Date: Tue, 10 Feb 2009 22:41:25 +1000 Subject: can multi-core improve single funciton? References: <01a12e1d$0$30497$c3e8da3@news.astraweb.com> Message-ID: <01a16bc0$0$20660$c3e8da3@news.astraweb.com> > def fib(n, a=1, b=1): > if n==0: > return a > elif n==1: > return b > return fib(n-1, b, a+b) > > > And for the record: > >>>> fib(500) > 225591516161936330872512695036072072046011324913758190588638866418474627738686883405015987052796968498626L timeit.Timer('fib(500)', > >>>> 'from __main__ import fib').timeit(1) > 0.00083398818969726562 > Less than a millisecond, versus millions of years for the OP's algorithm. > I know which I would choose. Faster hardware can only go so far in hiding > the effect of poor algorithms. I agree to 100% to this. btw. the timeings are not that different for the naive recursion in OP's version and yours. fib(500) on my machine: OP's: 0.00116 (far away from millions of years) This here: 0.000583 Gabriel's while loop: 0.000246 The fastest algorithm I've found does fib(1000000) in .25seconds on my machine. However, I have not found a way to parallelize this algorithm and I think it is not possible. To come back to the original question. Yes it is possible; however there are quite some restrictions about it. In case of the naive recursion it was possible to get a speedup of more than 3 times on a 4 core machine. With the highly optimised version mentioned above, I had no success in utilizing more than one core. As conclusion I would say, Yes, a single function can profit from multiple cores, but sometimes a better algorithm delivers better results than using more cores. However, it is possible that a slower but parallelizable algorithm might outperform the best serial algorithm, with enough cores :). Gerhard From thomas.kraus at merz-akademie.de Tue Feb 10 07:42:17 2009 From: thomas.kraus at merz-akademie.de (Thomas Kraus) Date: Tue, 10 Feb 2009 13:42:17 +0100 Subject: Convert date/time to unix timestamp? In-Reply-To: References: Message-ID: Phillip B Oldham schrieb: > Is there a simple way to set a date/time and convert it to a unix > timestamp? After some googling I found the following: > > t = datetime.time(7,0,0) > starttime = time.mktime(t.timetuple())+1e-6*t.microsecond > > That seems like very long-winded. Is there an easier way? I've read > the docs on the datetime and time modules, but nothing's jumping out > at me. The built-in function time.localtime() returns a 9-item tuple, e.g. (2009, 2, 10, 13, 29, 7, 1, 41, 0). time.mktime() converts this tuple to the seconds since the Epoch as a floating point number, int() converts it to an integer. int(time.mktime(time.localtime())) -- Thomas From lie.1296 at gmail.com Tue Feb 10 07:43:20 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 10 Feb 2009 12:43:20 +0000 (UTC) Subject: can multi-core improve single funciton? References: <6a4f17690902092228i31fd1661n41c61c4037a289df@mail.gmail.com> Message-ID: On Tue, 10 Feb 2009 14:28:15 +0800, oyster wrote: > I mean this > [code] > def fib(n): > if n<=1: > return 1 > return fib(n-1)+fib(n-2) > > useCore(1) > timeit(fib(500)) #this show 20 seconds > > useCore(2) > timeit(fib(500)) #this show 10 seconds [/code] > > Is it possible? > > and more, can threads/multi-processors/clusters be used to improve fib? > > thanx Of course multi-core processor can improve single function using multiprocessing, as long as the function is parallelizable. The Fibonacci function is not a parallelizable function though. However, there are ways to improve your fibonacci function. Either put off the recursion or implement a memoization. An imperative fibonacci is much faster than a naive recursion one because a naive recursive fibonacci function is O(2**n) while the imperative one O(n). Memoization must be used to help recursive fibonacci to become O(n). From andrew at acooke.org Tue Feb 10 08:00:37 2009 From: andrew at acooke.org (andrew cooke) Date: Tue, 10 Feb 2009 10:00:37 -0300 (CLST) Subject: Convert date/time to unix timestamp? In-Reply-To: References: Message-ID: <07563d777dbc68c9315b2c3d32d98e43.squirrel@localhost> the python routines are a bit basic - you really have to think quite hard about what you are doing to get the right answer. in your case, you need to be clear what the timezone is for the datetime you are using. timezone info is optional (see the datetime documentation, where it talks about "naive" and "aware" objects). anyway, ignoring that, i think you need the very useful, but oddly located, calendar.timegm(). andrew Phillip B Oldham wrote: > Is there a simple way to set a date/time and convert it to a unix > timestamp? After some googling I found the following: > > t = datetime.time(7,0,0) > starttime = time.mktime(t.timetuple())+1e-6*t.microsecond > > That seems like very long-winded. Is there an easier way? I've read > the docs on the datetime and time modules, but nothing's jumping out > at me. > -- > http://mail.python.org/mailman/listinfo/python-list > > From lie.1296 at gmail.com Tue Feb 10 08:03:41 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 10 Feb 2009 13:03:41 +0000 (UTC) Subject: Import without executing module References: <7a9c25c20902012319i2d217644k12bc926400f630c2@mail.gmail.com> <14edd870-74d4-4d7a-a363-a4bc3515a071@s9g2000prg.googlegroups.com> <0ad1a5c0-0605-49fe-8a97-1159fc274d30@a39g2000prl.googlegroups.com> <45e5daf1-108c-499e-82a9-10e67eac33e2@z27g2000prd.googlegroups.com> <5a64441e-bee9-4466-b613-3e83fce2e8fb@r15g2000prd.googlegroups.com> <7a9c25c20902032008u1e745eb0x2d30b45844a74c5d@mail.gmail.com> Message-ID: On Tue, 03 Feb 2009 20:08:34 -0800, Stephen Hansen wrote: > There is no need to try to make sure something is > executed/compiled only once in Python like you may want to do in C. > Every module is only ever compiled once: if you import it ten times in > ten different places only the first will compile and execute the code, > the rest of the calls will return that original module again. If you import a module, it will be recompiled only if the module changes from the precompiled .pyc/.pyo. OTOH, if you run a module, it will be recompiled every time even if there is no change. From jldunn2000 at googlemail.com Tue Feb 10 08:06:18 2009 From: jldunn2000 at googlemail.com (loial) Date: Tue, 10 Feb 2009 05:06:18 -0800 (PST) Subject: python ssh and Tetia SSH server Message-ID: <20381e4c-fe5d-49c8-9326-5b74e10e63f6@t11g2000yqg.googlegroups.com> Anyone out there any experience of using python ssh modules to connect to the Tetia SSH server from SSH (ssh.com)? From ferdinandsousa at gmail.com Tue Feb 10 08:22:24 2009 From: ferdinandsousa at gmail.com (Ferdinand Sousa) Date: Tue, 10 Feb 2009 18:52:24 +0530 Subject: COM and threading, "CoInitialize"? Message-ID: Greetings to list members, I am trying to use an Acrobat COM object in a class that is subclassed from threading.Thread. Since threading.Thread is subclassed, the __init__ method of the inheriting class must explicitly call the threading.Thread.__init__ method of the parent. I guess I'm missing something similar for the COM object. Threading code and traceback below. Any pointers? CODE: ================================= class process_file(threading.Thread): def __init__(self,connection): threading.Thread.__init__(self) self.connection=connection def run(self): #### irrelevant code here #### # Acrobat COM starts AVD = win32com.client.Dispatch('AcroExch.AVDoc') # Traceback refers to this line (89) pdfname=pdfname.replace('.pdf',PDFNAME_SUFFIX) AVD.Open(pdf.name, pdfname) # //////// print 'opened avdoc' ================================== TRACEBACK: ================================== Exception in thread Thread-1: Traceback (most recent call last): File "C:\Python25\lib\threading.py", line 486, in __bootstrap_inner self.run() File "D:\Ferdinand\#Storage\Ferdi-python\Acrobat Automation\temp testing.py", line 89, in run AVD = win32com.client.Dispatch('AcroExch.AVDoc') File "C:\Python25\Lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx) File "C:\Python25\Lib\site-packages\win32com\client\dynamic.py", line 98, in _GetGoodDispatchAndUserName return (_GetGoodDispatch(IDispatch, clsctx), userName) File "C:\Python25\Lib\site-packages\win32com\client\dynamic.py", line 78, in _GetGoodDispatch IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch) com_error: (-2147221008, 'CoInitialize has not been called.', None, None) ================================== TIA. Best regards, Ferdi -------------- next part -------------- An HTML attachment was scrubbed... URL: From mal at egenix.com Tue Feb 10 08:25:56 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Tue, 10 Feb 2009 14:25:56 +0100 Subject: Convert date/time to unix timestamp? In-Reply-To: References: Message-ID: <49918064.4030201@egenix.com> On 2009-02-10 10:26, Phillip B Oldham wrote: > Is there a simple way to set a date/time and convert it to a unix > timestamp? After some googling I found the following: > > t = datetime.time(7,0,0) > starttime = time.mktime(t.timetuple())+1e-6*t.microsecond > > That seems like very long-winded. Is there an easier way? I've read > the docs on the datetime and time modules, but nothing's jumping out > at me. >>> from mx.DateTime import DateTime >>> DateTime(2009,10,2,7,0,0).ticks() 1254459600.0 http://www.egenix.com/products/python/mxBase/mxDateTime/ -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Feb 10 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From tino at wildenhain.de Tue Feb 10 08:30:11 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Tue, 10 Feb 2009 14:30:11 +0100 Subject: python ssh and Tetia SSH server In-Reply-To: <20381e4c-fe5d-49c8-9326-5b74e10e63f6@t11g2000yqg.googlegroups.com> References: <20381e4c-fe5d-49c8-9326-5b74e10e63f6@t11g2000yqg.googlegroups.com> Message-ID: <49918163.7020002@wildenhain.de> loial wrote: > Anyone out there any experience of using python ssh modules to connect > to the Tetia SSH server from SSH (ssh.com)? Did you call their support? Personally I see no reason why paramiko http://www.lag.net/paramiko/ should not work, given that openssh ssh client also worked in the past with ssh.com ssh. Maybe you can get a test version and just try it out. Regards Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From durumdara at gmail.com Tue Feb 10 08:44:25 2009 From: durumdara at gmail.com (durumdara) Date: Tue, 10 Feb 2009 14:44:25 +0100 Subject: Cheetah and hungarian charset... In-Reply-To: <498B03F9.3040109@gmail.com> References: <498B03F9.3040109@gmail.com> Message-ID: <499184B9.7070903@gmail.com> Hi! Ok, I forget to set encodings. from Cheetah.Template import Template d = {'a' : 'alm?s'} tp = Template("# encoding: iso-8859-2\nhello world ???? ${d['a']}!", searchList = {'d': d}) print tp sys.exit() This code is working for me in Windows. dd 2009.02.05. 16:21 keltez?ssel, durumdara ?rta: > Hi! > > I wanna ask that have anyone some exp. with Cheetah and the non-ascii > chars? > > I have a site. The html template documents are saved in ansi format, > psp liked them. > But the cheetah parser makes ParseError on hungarian characters, like > "?", "?", "?", etc. When I remove them, I got good result, but I don't > want to remove them all... > > I cannot parse them. Please help me, how to force cheetah to eat them > all? > > Thanks for your help: > dd > From stephane at tinyerp.com Tue Feb 10 09:05:45 2009 From: stephane at tinyerp.com (Stephane Wirtel) Date: Tue, 10 Feb 2009 15:05:45 +0100 Subject: OpenERP 5.0 - Fully developed with Python Message-ID: <499189B9.1050902@tinyerp.com> OpenERP 5.0 is out ! ==================== Why do I talk about OpenERP on this mailing list ? Because OpenERP is fully developed with Python That major enhancement of Open ERP can now answer to all the needs of a business. Open ERP V5 not only provides management functions, but also all functionalities necessary to a SMB, like : a process management by modules, a wiki, a webmail, a Business Intelligence (Cube OLAP), a Document Management System, an eCommerce, an idea box, etc. Emphasis was placed on an extreme simplification of the software for the new users, a carefully designed ergonomy of the web client with, amongst others, drag&drop, Gantt graph, editable processes, etc., and more then 350 modules for specific sectors and big companies. This new version comes with a full review of the web site giving access to more then 1500 pages of documentations on business management and a reorganization of the community sources build upon the Open Object framework. Free cycles of conferences are planned with the version 5.0 release of Open ERP. Thanks to its huge community, Open Object produce more then 20 modules a month. The Open Object community it is more then 1000 contributors, 126 development branches in parallel, an average of 400 new functinalities or bugfix per month, one commit every 5 minutes and functional and technical experts specialized by activity and working in teams. The rise of Open Object and the diversity of the projects makes it an unmatched framework composed of more then 400 modules installable in a few clicks to cover all kinds of need or to simply start, with a simple module, to answer a simple need. Then, you can install other functionalities to come to a fully integrated and automaized system. Open ERP v5 is characterized by the appearance of many functionalities far beyond the perimeter of traditional management. One can underline the following innovations: * A integrated wiki. * An integrated document management system. * A Business Intelligence (BI) using a OLAP database. * An integrated BPM (management of process). * A web portal for clients and suppliers. * Improvement of translations (1 translation file by language and module). * A touchscreen point of sale. * A full Ajax webmail . * A shared calendar. * Plugins for Outlook, OpenOffice, ms. Office, Thunderbird. * An integrated eCommerce, etc This new release offers 3 user interfaces : * the rich application client for a day to day advanced use, * the web interface allowing a remote access and an easy deployment, * the QT client that perfectly fits in a KDE environment. Numerous improvements have been added to the client interfaces, like : * dynamic graphs and dashboards, * really ergonomic calendar views, * dynamic Gantt graphs for planning, * workflows editors, * a fully integrated documentation, * a dynamic process view used for the end-user training, * etc. The web version of Open ERP includes numerous functions to modify or create your own application : * an visual view editor, * an object editor, * a workflow (process) editor, * an Open Office integrated report editor * a statistics engine (BI cube), * etc. URL: http://www.openerp.com URL: http://www.openobject.com DOC: http://doc.openerp.com Screencast: http://www.openerp.tv LaunchPad Project: http://launchpad.net/openobject -- Stephane Wirtel - "As OpenERP is OpenSource, please feel free to contribute." Developper - Technical Instructor OpenERP OpenERP - Tiny SPRL Chaussee de Namur, 40 B-1367 Gerompont Tel: +32.81.81.37.00 Web: http://www.tiny.be Web: http://www.openerp.com Planet: http://www.openerp.com/planet/ Blog: http://stephane-wirtel-at-tiny.blogspot.com -------------- next part -------------- A non-text attachment was scrubbed... Name: stephane.vcf Type: text/x-vcard Size: 443 bytes Desc: not available URL: From mail at timgolden.me.uk Tue Feb 10 09:14:51 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 10 Feb 2009 14:14:51 +0000 Subject: COM and threading, "CoInitialize"? In-Reply-To: References: Message-ID: <49918BDB.6020600@timgolden.me.uk> Ferdinand Sousa wrote: > Greetings to list members, > > I am trying to use an Acrobat COM object in a class that is subclassed from > threading.Thread. > Since threading.Thread is subclassed, the __init__ method of the inheriting > class must explicitly call the threading.Thread.__init__ method of the > parent. I guess I'm missing something similar for the COM object. Threading > code and traceback below. Any pointers? [... snip lots of code and traceback ...] > com_error: (-2147221008, 'CoInitialize has not been called.', None, None) > ================================== Well, much as I may grumble about opaque error messages, you're not going to find one much more explicit than this. Try calling CoInitialize, once per thread, eg before your Dispatch line. You'll have to import pythoncom and then just call pythoncom.CoInitialize () TJG From jldunn2000 at googlemail.com Tue Feb 10 09:21:46 2009 From: jldunn2000 at googlemail.com (loial) Date: Tue, 10 Feb 2009 06:21:46 -0800 (PST) Subject: Using paramiko rsa key Message-ID: I want to connect via ssh from a python script on windows to an AIX server running openSSH using rsa keys rather than a password. Can anyone provide me with /point me at a simple tutuorial on the steps I need to go though in terms of geneerating the key, installing on the server and connecting in my python code? Thanks in advance. From philip at semanchuk.com Tue Feb 10 10:06:50 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 10 Feb 2009 10:06:50 -0500 Subject: Python Launcher.app on OS X In-Reply-To: <2caa16ad-bc2c-4ade-ba1b-d39103066cbd@33g2000yqm.googlegroups.com> References: <2caa16ad-bc2c-4ade-ba1b-d39103066cbd@33g2000yqm.googlegroups.com> Message-ID: <2C317868-F9B0-4EFA-8FF8-88232C20E301@semanchuk.com> On Feb 9, 2009, at 10:26 PM, kpp9c wrote: > okay... for the life of me i do not see any Python Launcher.app and i > just installed OS X 10.5 (running 10.5.6 on intel) .... and i also > installed the dev kit. > > Where the heck is this application? Hi kp, I don't seem to have any such beast on my system except for the one in /Applications/MacPython 2.5/. Perhaps the documentation is mistaken? From tino at wildenhain.de Tue Feb 10 10:11:12 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Tue, 10 Feb 2009 16:11:12 +0100 Subject: Using paramiko rsa key In-Reply-To: References: Message-ID: <49919910.50303@wildenhain.de> loial wrote: > I want to connect via ssh from a python script on windows to an AIX > server running openSSH using rsa keys rather than a password. > > Can anyone provide me with /point me at a simple tutuorial on the > steps I need to go though in terms of geneerating the key, installing > on the server and connecting in my python code? Sure, where can we send the invoice too? Regards Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From philip at semanchuk.com Tue Feb 10 10:11:32 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 10 Feb 2009 10:11:32 -0500 Subject: STMP, mail, sender-from, to-bcc-addr In-Reply-To: <4991733E.4040608@gmail.com> References: <4991733E.4040608@gmail.com> Message-ID: <34E7920F-9155-4846-BC0F-8BFDEA3931B9@semanchuk.com> On Feb 10, 2009, at 7:29 AM, durumdara wrote: > Hi! > > I wanna ask that have anyone some experience with email.msg and > smtplib? > > The email message and smtp.send already have "sender/from" and > "recip/addr to". > Possible the smtp components does not uses the email tags if I not > define them only in the message? > > Can I do same thing as in GMAIL that the mail does not have TO, only > BCC tags/recipients, and no one of the recipients who knows about > the each others? Hi dd, I'm not exactly sure what you're asking, but my memories of implementing BCC are that there is no BCC tag. It's your job as the programmer building the application that sends the message to send the mail to everyone on the BCC list. Something like this: for recipient in bcc: send_mail(to=recipient) Hope this helps Philip From philip at semanchuk.com Tue Feb 10 10:29:15 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 10 Feb 2009 10:29:15 -0500 Subject: Calling into Python from a C thread In-Reply-To: References: <20090209170259.1D4C78FDE0@panix3.panix.com> Message-ID: <57C5AC52-6B7B-4B35-87FD-C1E065AD850E@semanchuk.com> On Feb 9, 2009, at 3:59 PM, Christian Heimes wrote: > Philip Semanchuk wrote: >> Yes, that's accurate except for the word "forgot". To forget >> something >> one must first know it. =) I found the threading API documentation >> difficult to follow, but I suppose that what I'm doing is a little >> unusual so if it is not well-documented territory, that's what I >> get for >> wandering off the map. > > I see. Apparently the threading and embedding docs don't cover your > case. The docs at > http://docs.python.org/c-api/init.html#thread-state-and-the-global-interpreter-lock > and http://docs.python.org/extending/embedding.html should explain how > and when to initialize Python threads. Please report a documentation > bug at > http://bugs.python.org/. I read that several times and eventually got my code working. I wouldn't say that the documentation didn't cover my case (implementing a callback). I'd say that it doesn't cover *any* cases in particular. It's more like a list of tools for manipulating the GIL and thread state and an explanation of the need for them rather than a tutorial on how to use them. The latter is what I needed, but as I said, what I'm doing is atypical and I think it is reasonable to expect thin documentation on atypical situations. > PS: I know a great way to learn more about Python's internal threading > CAPI: fix your code, test it and attach a doc patch to your bug > report. > *hint* :) I will file a bug on a least one specific point which is that PyGILState_Ensure() acquires the GIL and PyGILState_Release() appears to release it; the latter point is undocumented. Cheers Philip From rodmena.com at gmail.com Tue Feb 10 10:38:37 2009 From: rodmena.com at gmail.com (Farsheed Ashouri) Date: Tue, 10 Feb 2009 07:38:37 -0800 (PST) Subject: Uploading big files wit cherrypy Message-ID: <366595b2-226c-48e4-961d-85bd0ce4bd9a@h16g2000yqj.googlegroups.com> I use this code to upload using cherrypy: #========Code Start========== class NoteServer(object): _cp_config = { 'tools.sessions.on': True } def index(self): return """
filename:

Pars Studios, 2009

""" #~ return compose().run() index.exposed = True def upload(self, myFile): out = """ myFile length: %s
myFile filename: %s
myFile mime-type: %s """ # Although this just counts the file length, it demonstrates # how to read large files in chunks instead of all at once. # CherryPy uses Python's cgi module to read the uploaded file # into a temporary file; myFile.file.read reads from that. size = 0 allData='' while True: data = myFile.file.read(8192) allData+=data if not data: break size += len(data) savedFile=open(myFile.filename, 'wb') savedFile.write(allData) savedFile.close() return out % (size, myFile.filename, myFile.type) #~ return allData upload.exposed = True #========Code End============ But I couldn't upload files bigger than 100Mb. Why and what is workaround? Thanks in advanced. From rschroev_nospam_ml at fastmail.fm Tue Feb 10 10:39:56 2009 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Tue, 10 Feb 2009 16:39:56 +0100 Subject: STMP, mail, sender-from, to-bcc-addr In-Reply-To: References: Message-ID: durumdara schreef: > Hi! > > I wanna ask that have anyone some experience with email.msg and smtplib? > > The email message and smtp.send already have "sender/from" and > "recip/addr to". > Possible the smtp components does not uses the email tags if I not > define them only in the message? smtplib.SMTP.sendmail() does not look in the message to find the sender or recipients; it only uses the parameters you pass. > Can I do same thing as in GMAIL that the mail does not have TO, only BCC > tags/recipients, and no one of the recipients who knows about the each > others? Include the BCC-recipients in the call to sendmail(), but don't put them in the email message itself. Include TO-recipients in both. In other words, what you put in the TO-header is what all recipients will see; what you pass to sendmail() is what recipients the mail will be send to. Simple example (not tested): from_addr = 'foo at example.com' to_addr = ['bar at example.com', 'xyzzy at example.com'] bcc_addr = ['spam at example.com', 'eggs at example.com'] msg = """From: %s To: %s Subject: test hello """ % (from_addr, ', '.join(to_addr)) smtp = smtplib.SMTP(...) smtp.sendmail(from_addr, to_addr + bcc_addr, msg) -- The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom. -- Isaac Asimov Roel Schroeven From bj_666 at gmx.net Tue Feb 10 10:47:57 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 10 Feb 2009 15:47:57 GMT Subject: "Super()" confusion References: <20090210000405.12853.971581682.divmod.quotient.8036@henry.divmod.com> <6vd0h1Fjele5U1@mid.uni-berlin.de> <34d373ad-52d2-4d38-94b7-d566a5a5dd58@s20g2000yqh.googlegroups.com> Message-ID: <6vdltdFjele5U2@mid.uni-berlin.de> On Tue, 10 Feb 2009 02:11:10 -0800, Michele Simionato wrote: > Unfortunately there is no good solution. If you have a single > inheritance hierarchy and you do not use super, you make it impossible > for users of your hierarchy to subclass it by using multiple > inheritance in a cooperative way (this is not polite). So I'm impolite. :-) I'm using multiple inheritance only for mixin classes and even that quite seldom. No `super()` in my code. Ciao, Marc 'BlackJack' Rintsch From jldunn2000 at googlemail.com Tue Feb 10 10:48:46 2009 From: jldunn2000 at googlemail.com (loial) Date: Tue, 10 Feb 2009 07:48:46 -0800 (PST) Subject: Using paramiko rsa key References: Message-ID: <41ed4335-66f9-4ff9-9901-77c30be07a82@v19g2000yqn.googlegroups.com> Can anyone be a little more helpful than Tino? I have generated the key file as follows on windows and ftp'd the id_rsa.pub file to the .ssh directory on the server and renamed to authorized_keys import paramiko key = paramiko.RSAKey.generate(2048) key.write_private_key_file('Z:/id_rsa') file = open('Z:/id_rsa.pub','w') file.write("ssh-rsa " +key.get_base64()) file.close() But when I try to connect as follows I get an authentication failed error. import paramiko paramiko.util.log_to_file('demo_sftp.log') try: try: key = paramiko.RSAKey.from_private_key_file("Z:/id_rsa") #the generated private key except Exception, e: print str(e) t = paramiko.Transport(('10.5.1.15', 22)) print "here" t.start_client() t.auth_publickey('prod2',key) if t.is_authenticated(): print "Got it!" sftp = paramiko.SFTPClient.from_transport(t) dirlist = sftp.listdir('.') print "Dirlist:", dirlist t.close() except Exception, e: print str(e) t.close() From martin at marcher.name Tue Feb 10 10:58:40 2009 From: martin at marcher.name (Martin) Date: Tue, 10 Feb 2009 16:58:40 +0100 Subject: how to find out vesion of a python module In-Reply-To: <90ab16f0-bc7f-4489-afbf-6bcfae3061f3@j8g2000yql.googlegroups.com> References: <083dcd2f-c225-471c-8c78-c6570a08d659@v38g2000yqb.googlegroups.com> <90ab16f0-bc7f-4489-afbf-6bcfae3061f3@j8g2000yql.googlegroups.com> Message-ID: <5fa6c12e0902100758t510b6c89q379f87f3ca59f6e5@mail.gmail.com> Hi, 2009/2/10 Atishay : > Now the point is, how do I avoid setting LD_LIBRARY_PATH everytime for > python? I know I can write a bash script, but I am sure python would > have some feature that I can tweak to make it work. On debian you can modify * /etc/ld.so.conf and/or * /etc/ld.so.conf.d/.... to include the path you need. hth martin -- http://soup.alt.delete.co.at http://www.xing.com/profile/Martin_Marcher http://www.linkedin.com/in/martinmarcher You are not free to read this message, by doing so, you have violated my licence and are required to urinate publicly. Thank you. Please avoid sending me Word or PowerPoint attachments. See http://www.gnu.org/philosophy/no-word-attachments.html From bob.uuca at gmail.com Tue Feb 10 11:07:30 2009 From: bob.uuca at gmail.com (Mac) Date: Tue, 10 Feb 2009 08:07:30 -0800 (PST) Subject: Change in cgi handling of POST requests Message-ID: We just upgraded Python to 2.6 on some of our servers and a number of our CGI scripts broke because the cgi module has changed the way it handles POST requests. When the 'action' attribute was not present in the form element on an HTML page the module behaved as if the value of the attribute was the URL which brought the user to the page with the form, but without the query (?x=y...) part. Now FieldStorage.getvalue () is giving the script a list of two copies of the value for some of the parameters (folding in the parameters from the previous request) instead of the single string it used to return for each. I searched this newsgroup looking for a discussion of the proposal to impose this change of behavior, and perhaps I wasn't using the right phrases in my search, but I didn't find anything. I see that Perl still behaves the way pre-2.6 Python used to (not that I view that as a reason for anything). We'll work around the breakage by explicitly setting the 'action' attribute everywhere, of course, but I usually see some discussion (often heated) of the impact of behavior changes on existing software when something like this is in the works. Did I miss it? I also noted that the module is making some deprecated use of the BaseException class. Cheers. From rdmurray at bitdance.com Tue Feb 10 11:13:47 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Tue, 10 Feb 2009 16:13:47 +0000 (UTC) Subject: Import without executing module References: <7a9c25c20902012319i2d217644k12bc926400f630c2@mail.gmail.com> <14edd870-74d4-4d7a-a363-a4bc3515a071@s9g2000prg.googlegroups.com> <0ad1a5c0-0605-49fe-8a97-1159fc274d30@a39g2000prl.googlegroups.com> <45e5daf1-108c-499e-82a9-10e67eac33e2@z27g2000prd.googlegroups.com> <5a64441e-bee9-4466-b613-3e83fce2e8fb@r15g2000prd.googlegroups.com> <7a9c25c20902032008u1e745eb0x2d30b45844a74c5d@mail.gmail.com> Message-ID: Lie Ryan wrote: > On Tue, 03 Feb 2009 20:08:34 -0800, Stephen Hansen wrote: > > > There is no need to try to make sure something is > > executed/compiled only once in Python like you may want to do in C. > > Every module is only ever compiled once: if you import it ten times in > > ten different places only the first will compile and execute the code, > > the rest of the calls will return that original module again. > > > If you import a module, it will be recompiled only if the module changes > from the precompiled .pyc/.pyo. OTOH, if you run a module, it will be > recompiled every time even if there is no change. > As long as we are nitpicking, and trying to clarify things for a new Python user....let me give it a try. By doing this I get to find out if I really understand it as well as I think I do :) If a file is run as a script ('python somefile.py', or shebang magic on unix or the equivalent on other OSes), then the code is compiled/executed each time that is done. If a module is imported (or something is imported from a module), then the _first time_ during a given run of the python interpreter that such an import is done, the timestamp of the .py file (if it exists) is compared to the timestamp of the .pyc/.pyo file, and if the .py is newer, the .py file is compiled to byte code, the resulting byte code is written to the .pyc (or .pyo), and the byte code is executed. If the .py file is older, then the saved byte code is loaded and executed. It is the execution of the byte code that creates the module's namespace (a collection of names pointing to objects). This namespace is registered in sys.modules under the module's name. During the remainder of that run of the python interpreter, any import statement that draws from that module simply loads a pointer to the module's namespace (or to objects referenced by the module's namespace if it is a 'import from') into the local namespace. --RDM From jasiu85 at gmail.com Tue Feb 10 11:23:45 2009 From: jasiu85 at gmail.com (Jasiu) Date: Tue, 10 Feb 2009 08:23:45 -0800 (PST) Subject: version in setup.cfg References: <0b778f9a-d811-4dcd-9678-26242a14c4bf@t11g2000yqg.googlegroups.com> <6vbg8kFj8k12U1@mid.uni-berlin.de> Message-ID: > I don't think so. But there are several other options: I was afraid of that. Thanks anyway! Mike From jef.mangelschots at gmail.com Tue Feb 10 11:26:42 2009 From: jef.mangelschots at gmail.com (jefm) Date: Tue, 10 Feb 2009 08:26:42 -0800 (PST) Subject: import wx works interactive but not from script References: <549b9ca1-90f4-403e-b30d-679957f36992@a12g2000pro.googlegroups.com> Message-ID: <35efb288-f6eb-4077-8414-93fa673c6878@t26g2000prh.googlegroups.com> I ran the script from a command line, so it is not a file association thing. I do have multiple versions of Python installed on that machine. I will uninstall them all and install a single version from clean. Thanks for the suggestion From mail at timgolden.me.uk Tue Feb 10 11:39:29 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 10 Feb 2009 16:39:29 +0000 Subject: import wx works interactive but not from script In-Reply-To: <35efb288-f6eb-4077-8414-93fa673c6878@t26g2000prh.googlegroups.com> References: <549b9ca1-90f4-403e-b30d-679957f36992@a12g2000pro.googlegroups.com> <35efb288-f6eb-4077-8414-93fa673c6878@t26g2000prh.googlegroups.com> Message-ID: <4991ADC1.3040200@timgolden.me.uk> jefm wrote: > I ran the script from a command line, so it is not a file association > thing. Ummm... if you ran it by just typing the script name -- c:\test\whatever.py rather than c:\pythonxx\python c:\test\whatever.py -- then it certainly could be a file association issue. > I do have multiple versions of Python installed on that machine. I > will uninstall them all and install a single version from clean. > Thanks for the suggestion Hope it helps. Let us know how it turns out. TJG From olivierbourdon38 at gmail.com Tue Feb 10 11:42:04 2009 From: olivierbourdon38 at gmail.com (olivierbourdon38 at gmail.com) Date: Tue, 10 Feb 2009 08:42:04 -0800 (PST) Subject: Tricky question about native extension packaging Message-ID: <07cf55ac-b832-422e-aec0-12756e27ced9@t3g2000yqa.googlegroups.com> let's assume I (almost) have and extension available as a C file and the setup.py and I want to generate from this single c file 2 .so files using cc -DOPTION1 x.c to produce x_1.so cc -DOPTION2 x.c to produce x_2.so and at runtime depending of my OS version either load x_1 or x_2 any (easy) way to do that and deliver the result as a single .egg file ? What should the setup.py look like ? Thanks for any insight From quian.xu at stud.tu-ilmenau.de Tue Feb 10 11:48:39 2009 From: quian.xu at stud.tu-ilmenau.de (Qian Xu) Date: Tue, 10 Feb 2009 17:48:39 +0100 Subject: UnitTest break on failure Message-ID: Hi All, i am writing unit tests and have got a problem: I want to test some code sequence like: self.assertEquals(testMethod1(), expected_value1); self.assertEquals(testMethod2(), expected_value2); However, if the first test item is failed, no more tests will be executed. Can I tell Python, 1. go ahead, if a failure is occurred. 2. stop, if an error is occurred? Best regards, Qian Xu From benjamin.kaplan at case.edu Tue Feb 10 11:49:59 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 10 Feb 2009 11:49:59 -0500 Subject: Python Launcher.app on OS X In-Reply-To: <2C317868-F9B0-4EFA-8FF8-88232C20E301@semanchuk.com> References: <2caa16ad-bc2c-4ade-ba1b-d39103066cbd@33g2000yqm.googlegroups.com> <2C317868-F9B0-4EFA-8FF8-88232C20E301@semanchuk.com> Message-ID: On Tue, Feb 10, 2009 at 10:06 AM, Philip Semanchuk wrote: > > On Feb 9, 2009, at 10:26 PM, kpp9c wrote: > > okay... for the life of me i do not see any Python Launcher.app and i >> just installed OS X 10.5 (running 10.5.6 on intel) .... and i also >> installed the dev kit. >> >> Where the heck is this application? >> > > Hi kp, > I don't seem to have any such beast on my system except for the one in > /Applications/MacPython 2.5/. Perhaps the documentation is mistaken? It should be in there. It's in the Python framework folder instead of the normal applications folder, and spotlight doesn't find it. Try checking /System/Library/Frameworks/Python.framework/versions/2.5/Resources. > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From philip at semanchuk.com Tue Feb 10 12:03:02 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 10 Feb 2009 12:03:02 -0500 Subject: Python Launcher.app on OS X In-Reply-To: References: <2caa16ad-bc2c-4ade-ba1b-d39103066cbd@33g2000yqm.googlegroups.com> <2C317868-F9B0-4EFA-8FF8-88232C20E301@semanchuk.com> Message-ID: <3EDA106D-B8EA-4AD9-8F92-EC222973D159@semanchuk.com> On Feb 10, 2009, at 11:49 AM, Benjamin Kaplan wrote: > On Tue, Feb 10, 2009 at 10:06 AM, Philip Semanchuk >wrote: > >> >> On Feb 9, 2009, at 10:26 PM, kpp9c wrote: >> >> okay... for the life of me i do not see any Python Launcher.app and i >>> just installed OS X 10.5 (running 10.5.6 on intel) .... and i also >>> installed the dev kit. >>> >>> Where the heck is this application? >>> >> >> Hi kp, >> I don't seem to have any such beast on my system except for the one >> in >> /Applications/MacPython 2.5/. Perhaps the documentation is mistaken? > > > > It should be in there. It's in the Python framework folder instead > of the > normal applications folder, and spotlight doesn't find it. Try > checking > /System/Library/Frameworks/Python.framework/versions/2.5/Resources. Good call, you are 100% correct, with the footnote that Versions in that path should be capitalized. /System/Library/Frameworks/Python.framework/Versions/2.5/Resources From martin.hellwig at dcuktec.org Tue Feb 10 12:08:38 2009 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Tue, 10 Feb 2009 17:08:38 +0000 Subject: Using paramiko rsa key In-Reply-To: <41ed4335-66f9-4ff9-9901-77c30be07a82@v19g2000yqn.googlegroups.com> References: <41ed4335-66f9-4ff9-9901-77c30be07a82@v19g2000yqn.googlegroups.com> Message-ID: <4991b496$0$188$e4fe514c@news.xs4all.nl> loial wrote: > Can anyone be a little more helpful than Tino? I'll do some freebie hints :-) What I would do is try first whether key authentication works at all, for example following a tutorial like http://the.earth.li/~sgtatham/putty/0.53b/htmldoc/Chapter8.html And if that works translate it to the relevant python code. -- mph From aahz at pythoncraft.com Tue Feb 10 12:14:21 2009 From: aahz at pythoncraft.com (Aahz) Date: 10 Feb 2009 09:14:21 -0800 Subject: what IDE is the best to write python? References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> Message-ID: In article , wrote: >Quoth aahz at pythoncraft.com (Aahz): >> In article , >> Thorsten Kampe wrote: >>>* Aahz (2 Feb 2009 09:29:43 -0800) >>>> >>>> Polarized sunglasses don't work too well with LCD monitors >>> >>>Well, the answer to your issue with syntax highlighting is to use a >>>/decent/ highlighting colour scheme. Don't use that all >>>purple/red/green/yellow/blue one. That's for psychedelic trips. >>> >>>Use a decent colour scheme for adults and you will see that you will >>>benefit from syntax highlighting. >> >> Then I have the problem of copying around the syntax highlighting >> configuration to every computer I use. > >Well, _that's_ easy to fix. I have a little bash script called >'synchome' that uses rsync to update the home directory on any of the >remote machines on which I work. I've had to install rsync on one or >two of the boxes, but that's a useful thing to do anyway. > >(Granted, I still have a couple bugs to work out, where I haven't taken >the time to conditionalize things properly for some of the more exotic >machine configurations, but hey, if I spend more time on those machines >I'll get around to it...) The need to conditionalize for different environments is the main reason I haven't bothered, combined with the need to spend time working out a decent color scheme I'm happy with. I've been working this way (plain vi) for more than twenty years and I don't see much point fixing what ain't b0rken. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From aquil.abdullah at gmail.com Tue Feb 10 12:50:27 2009 From: aquil.abdullah at gmail.com (aha) Date: Tue, 10 Feb 2009 09:50:27 -0800 (PST) Subject: Logging in Python Message-ID: <958a7679-6116-44e0-b448-fec34d36c486@v13g2000yqm.googlegroups.com> Hello All, I have an application where logging may need to be configured in multiple places. I've used the Python Logging Framework for sometime, but I'm still not sure how to test if logging has configured. For example, I have modules A, B, and C. Below is some pseudo code... moduleA class A(object): def __init__(self): ... startLogging(config): # Configure logging # global logger ... moduleB import moduleA from myconfig import MyConfig class B(object): def __init__(self): # self.config = MyConfig() # if logging has started [HOW DO YOU DO THIS?] # self.logger = logging.getLogger("moduleB") # else # self.logger = moduleA.startLogging(self.config) # moduleA.startLogging ... Where I need help is determining if a logger has already been configured. Any advice? Aquil From cosmo_general at yahoo.com Tue Feb 10 12:55:32 2009 From: cosmo_general at yahoo.com (Muddy Coder) Date: Tue, 10 Feb 2009 09:55:32 -0800 (PST) Subject: Can urllib check path exists on server? Message-ID: <7abd3c00-e77e-47b8-8b2d-436bc6919760@h16g2000yqj.googlegroups.com> Hi Folks, urllib bridges up a client to a server, it works fine. I wonder: is there a method that can check the existence of a file in the server side? We can check such an existence on local filesystem by using os.path.exists(), can I do such a check on server? For example, http://somedomain.com/foo/bar.jpg is residing in a hosting server, can I use urllib to check if bar.jpg file existing or not? Thanks! Muddy Coder From mcfletch at vrplumber.com Tue Feb 10 13:07:50 2009 From: mcfletch at vrplumber.com (Mike C. Fletcher) Date: Tue, 10 Feb 2009 13:07:50 -0500 Subject: Python 3D CAD -- need collaborators, or just brave souls :) In-Reply-To: References: Message-ID: <4991C276.5020602@vrplumber.com> rantingrick wrote: ... > It has long been my dream to create an open source 3D CAD program and > i am starting to crawl my way into the first steps. I now believe i am > ready to start this endeavor and i am currently looking for fellow > Python programmers (no matter what skill level) to get started > brainstorming this design. > I'm certainly willing to help with brainstorming... > Of course Python will limit the speed here, but at this point i want > to get a template up and running. Speed does not matter at this point, > and optimizations can come along later as i am sure a few complete re- > writes are inevitable :) > Simple CAD systems without shading/texturing shouldn't have any real performance issues under Python. We had 3D CAD back in 1993 sufficient to build reasonably complex environments when I was in architecture. Python's only about 10x slower than C, and if you dump large C-level arrays into the graphics card your performance can be quite reasonable. If you have a visit @ every face/line for every refresh you'll spend all your time in the scenegraph traversal. > There will need to be mouse picking as i see this application as a > very interactive environment. Of course in the beginning all > interaction will most likely be in a command line type manner until > the functionality can be worked out. > Mouse picking is pretty easy, you can either use simple ray-intersection on your bounding-box hierarchy (easiest/fastest for CAD-type structures) or render-pass based stuff (if you have lots of organic shapes that will show through each other a lot and you want to be able to click on the thing "peeking through" behind another thing. Both are very well documented and easy/fast to implement if/when your scenegraph is tracking bounding volumes. > There will need to be a hierarchy of instancing and grouping within > the model to facilitate easy transformation of entities within the > model. > Transform and Group nodes are definitely a good idea, as are "USE" nodes. > I am not too worried about any sort of texturing at this point. I want > to squeeze as much speed as possible and prettiness will come in due > course. I also have no plans for layering, or multiple scenes at this > time. Simple functionality is the end game here. > Fair enough. > #-- Entities --# > face > line-segment > That's pretty low-level. You may want to work with "meshes" or the like, so that you select the mesh, then modify the faces/vertices/edges (a-la 3DSMax/Maya), particularly where you want faces to share coordinates. Just a thought. > #-- Hierarchy --# > Entity (one face, or line-segment) > Again, seems like you'd want something a little less soup-of-lines-ish, but then that's a 3D Modeler bias, rather than a CAD bias (where often it really is just a soup of lines). > Group (contained of multiple entities that can be translated, > rotated, scaled as one) > Transform node. > Instance (component definition) > Node with DEF + USE's node instance. Or, if you mean a reusable, parameterized node, a PROTO definition and PROTO-using nodes. > #-- Tools --# > line > rect > circle > arc > You'll want mechanisms to define the current coordinate system as well (think AutoCAD "UCS") so that you can precisely align the work you are doing without needing to calculate cos/sin/tan for everything. That is, your rotation/translation/scale should allow you to draw *within* the resulting Transform. You'll likely also want to be able to translate objects to/from Transform spaces (i.e. reparent without moving). Also (from my many-year-old recollection of doing CAD in architecture): * tan (when you want to draw lines tangential to a circle/arc and then trim) * chamfer/fillet (easy to code and pretty darn useful for a lot of detail drawings) * copy * align * delete/erase * hide/show hidden edges * mirror/mirror3d (used it all the time) * text (pretty important for CAD work) * snap control (critically important IMO) * polyline/polygon (or tools to combine lines/arcs into polygons and close the result for e.g. extrusion) * splines/nurbs or other high-order surfaces (eventually) * boolean operators (eventually, use a library for this unless you really want to learn, and even then, do it yourself and then use a library) > select > Critical to get that right to make it usable. > rotation > translation > scale > I'd suggest a Maya-like control for this as far as the GUI goes, put snaps on it, but make a single widget that lets you rotate/translate/scale. You'll also want such things as scale-this-line-to-be-this-size rescales (scale, pick two points, pick two other points, scale is the relative length of the two points)... > extrusion along path > Available in GLE extensions (nodes available too). Also want "revolve" (extrude around a path, which may be a point). Depending on your model, you may want to allow for converting extrusions to faces in order to allow tweaking the resulting extrusion. You'll want/need a UI to "open" the extrusion and change the backbone and sweep shapes. > measurement > measurement == dimensioning (dim*)? Or just on-screen measurement (dist). Both are useful. > So there it is. Any takers? :) > I can't even begin to commit any real time to another project (I barely have time to work on the ones I already have), but if you need feedback, feel free to email me. Most of the graphics stuff sounds like stuff you could build on top of OpenGLContext or COIN or any of the generic scenegraph libraries. They aren't really CAD-focused, but they've already got the ability to draw the things you're wanting to work on, and have the Transforms and similar support to make the coding a reasonable task. However, they're closer to a Maya/3DSMax model than AutoCAD, so maybe you'll decide you want to go your own way. You may want to check out PythonCAD as well, which IIRC does 2D-only CAD. Anyway, hope this was some help. Good luck, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From rdmurray at bitdance.com Tue Feb 10 13:08:25 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Tue, 10 Feb 2009 18:08:25 +0000 (UTC) Subject: Can urllib check path exists on server? References: <7abd3c00-e77e-47b8-8b2d-436bc6919760@h16g2000yqj.googlegroups.com> Message-ID: Muddy Coder wrote: > urllib bridges up a client to a server, it works fine. I wonder: is > there a method that can check the existence of a file in the server > side? We can check such an existence on local filesystem by using > os.path.exists(), can I do such a check on server? For example, > http://somedomain.com/foo/bar.jpg is residing in a hosting server, can > I use urllib to check if bar.jpg file existing or not? Thanks! urllib implements the http protocol for http URLs, so you can only do what the http protocol allows. Thus if http://somedomain.com/foo/bar.jpg is a valid URL on that server, you can do a urlopen, and then check the 'getcode' method on the returned object to see if you got a '404' (not found) code back. --RDM From rdmurray at bitdance.com Tue Feb 10 13:20:02 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Tue, 10 Feb 2009 18:20:02 +0000 (UTC) Subject: what IDE is the best to write python? References: <0adc6dcd-0c3e-4241-a25e-e3fe28b8e541@z28g2000prd.googlegroups.com> Message-ID: aahz at pythoncraft.com (Aahz) wrote: > In article , > wrote: > >Quoth aahz at pythoncraft.com (Aahz): > >> Then I have the problem of copying around the syntax highlighting > >> configuration to every computer I use. > > > >Well, _that's_ easy to fix. I have a little bash script called > >'synchome' that uses rsync to update the home directory on any of the > >remote machines on which I work. I've had to install rsync on one or > >two of the boxes, but that's a useful thing to do anyway. > > > >(Granted, I still have a couple bugs to work out, where I haven't taken > >the time to conditionalize things properly for some of the more exotic > >machine configurations, but hey, if I spend more time on those machines > >I'll get around to it...) > > The need to conditionalize for different environments is the main reason > I haven't bothered, combined with the need to spend time working out a > decent color scheme I'm happy with. I've been working this way (plain > vi) for more than twenty years and I don't see much point fixing what > ain't b0rken. I did the conditionalization bit by bit, and there isn't much of it since I can install my "standard environment" (zsh, screen, vim) on almost all the boxes on which I work. I was as you are on colorization until about three months ago. Then I figured out how to get 256 colors in my xterms and found 'desert.vim', which works for me (nice gentle colors). Now I'm a happy user of colorization, and have even written a colorizor for a file whose syntax I defined, that helps me avoid making stupid typos in said file, that I used to make far too often. In other words, the benefits tipped over into outweighing the costs for me just recently... --RDM From pythonsky at sky.com Tue Feb 10 13:22:36 2009 From: pythonsky at sky.com (Gary Wood) Date: Tue, 10 Feb 2009 18:22:36 -0000 Subject: python3 tutorial for newbie Message-ID: <920577A6E319438A9397A41B74AE9913@Woodygar> Can someone recommend a good tutorial for Python 3, ideally that has tasks or assignments at the end of each chapter. Please, -------------- next part -------------- An HTML attachment was scrubbed... URL: From castironpi at gmail.com Tue Feb 10 13:39:59 2009 From: castironpi at gmail.com (Aaron Brady) Date: Tue, 10 Feb 2009 10:39:59 -0800 (PST) Subject: generator object or 'send' method? References: <929da031-95be-4cda-89ea-560e52435243@e1g2000pra.googlegroups.com> Message-ID: On Feb 10, 6:30?am, "andrew cooke" wrote: > steven probably knows this, but to flag the issue for people who are > looking at generators/coroutines for the first time: there's a little > "gotcha" about exactly how the two sides of the conversation are > synchronized. ?in simple terms: send also receives. > > unfortunately the example steven gave doesn't really show this, so i've > modified it below. ?you can now see that the first next() after .send() > receives 2, not 1. ?note that i am using python 3, so the .next() method > is .__next__() (the asymmetry between next and send seems odd to me, but > there you go). > > (in a sense this is completely logical, but if you're used to the > asynchronous way the internet works, it can seem unintuitive) > > how to handle this was one of the things the original post was asking > about (if i understood correctly). > > >>> def gen(n): > > ... ? while True: > ... ? ? obj = yield n > ... ? ? n += 1 > ... ? ? if obj is not None: n = obj > ...>>> g = gen(5) > >>> next(g) > 5 > >>> g.__next__() > 6 > >>> g.send(1) > 1 > >>> next(g) > > 2 > > andrew > > Steven D'Aprano wrote: > > On Tue, 10 Feb 2009 05:28:26 +0000, John O'Hagan wrote: > >> I would love to see a simple code example of this if you have one; I've > >> been wanting to do this but couldn't even get started. > > > Is this too simple? > > >>>> def gen(n): > > ... ? ? while True: > > ... ? ? ? ? ? ? obj = yield n > > ... ? ? ? ? ? ? if obj is not None: n = obj > > ... > >>>> g = gen(5) > >>>> g.next() > > 5 > >>>> g.next() > > 5 > >>>> g.send(12) > > 12 > >>>> g.next() > > 12 > > I guess a generator that counts, but skips K numbers, where K can be varied. For instance, you initialize it with N, the starting number, and K, the jump size. Then, you can change either one later on. (Unproduced.) >>> j= jumper( N= 1, K= 1 ) >>> next( j ) 1 >>> next( j ) 2 >>> j.send( K= 3 ) 5 >>> next( j ) 8 However, if in the caller, the 'send' and 'next' come from two different places, then your 'send' "eats" one of your 'next's, and the 'next' code just receives 1..2..8. The above code isn't legal (or practical), due to the 'K=3' in send. You could do 'j.send( dict( K= 3 ) )', but you can't do 'locals ().update( result )' in your generator, unfortunately. So you have a big switch statement there. One solution: You could always query a dictionary for your variables, and do 'my_locals.update( result )', and 'my_locals[ "K" ]' for a variable. Then you just need some sort of collector generator to go around the first one, and duplicate the value 'send' returns, before going back to 'next'. (Unproduced.) >>> j= repeat_on_send( jumper( N= 1, K= 1 ) ) >>> next( j ) 1 >>> next( j ) 2 >>> j.send( dict( K= 3 ) ) 5 >>> next( j ) 5 >>> next( j ) 8 Two solution (er, solution two), would be to give a generator object access. Unfortunately, generators have no 'gi_dict' attribute, so arbitrary attributes aren't possible. So you have to be clever. (Unproduced.) >>> @gen_dict >>> def jumper... ... >>> j= jumper( N= 1, K= 1 ) >>> next( j ) 1 >>> next( j ) 2 >>> j.K= 3 >>> next( j ) 5 >>> next( j ) 8 This gets two birds with one stone, but is it possible? From jldunn2000 at googlemail.com Tue Feb 10 13:41:07 2009 From: jldunn2000 at googlemail.com (loial) Date: Tue, 10 Feb 2009 10:41:07 -0800 (PST) Subject: Using paramiko rsa key References: <41ed4335-66f9-4ff9-9901-77c30be07a82@v19g2000yqn.googlegroups.com> <4991b496$0$188$e4fe514c@news.xs4all.nl> Message-ID: On 10 Feb, 17:08, "Martin P. Hellwig" wrote: > loial wrote: > > Can anyone be a little more helpful than Tino? > > > I'll do some freebie hints :-) > What I would do is try first whether key authentication works at all, > for example following a tutorial likehttp://the.earth.li/~sgtatham/putty/0.53b/htmldoc/Chapter8.html > > And if that works translate it to the relevant python code. > > -- > mph Thanks..I'll try that first From goon12 at gmail.com Tue Feb 10 14:07:55 2009 From: goon12 at gmail.com (Joe Riopel) Date: Tue, 10 Feb 2009 14:07:55 -0500 Subject: UnitTest break on failure In-Reply-To: References: Message-ID: <6a2ccd190902101107l793f7b7ei2ef5c51cdfde3659@mail.gmail.com> On Tue, Feb 10, 2009 at 11:48 AM, Qian Xu wrote: > self.assertEquals(testMethod1(), expected_value1); > self.assertEquals(testMethod2(), expected_value2); > > However, if the first test item is failed, no more tests will be executed. > Can I tell Python, > 1. go ahead, if a failure is occurred. > 2. stop, if an error is occurred? Typically you would have a different test for two different methods, one for each method. From josh.dukes at microvu.com Tue Feb 10 14:15:14 2009 From: josh.dukes at microvu.com (Josh Dukes) Date: Tue, 10 Feb 2009 11:15:14 -0800 Subject: bool evaluations of generators vs lists Message-ID: <20090210111514.07e0480a@microvu.com> quite simply...what??? In [108]: bool([ x for x in range(10) if False ]) Out[108]: False In [109]: bool( x for x in range(10) if False ) Out[109]: True Why do these two evaluate differently? I was expecting that they would evaluate the same but the generator would return true *as soon as the first value is detected*. I'd really expect it to act more like... def has_values(g): for i in g: return True return False So what's going on here? Am I using the wrong function or is this actually just a bug? -- Josh Dukes MicroVu IT Department From ntwrkd at gmail.com Tue Feb 10 14:16:23 2009 From: ntwrkd at gmail.com (Matthew Sacks) Date: Tue, 10 Feb 2009 11:16:23 -0800 Subject: getopt index out of range Message-ID: Hi List, I am getting an index out of range error when trying to parse with getopt. Probably something simple. Any suggestions are appreciated optlist, args = getopt.getopt(sys.argv[1:], 'h', ['connectPassword=', 'adminServerURL=', 'action=', 'targets=', 'appDir=']) #Assign Opts connectPassword = optlist[0][1] adminServerURL = optlist[1][1] action = optlist[2][1] targets = optlist[3][1] appDir = optlist[4][1] #this statement never gets executed print "Args: " + connectPassword + " " + adminServerURL + " " + action + " " + targets + " " + appDir File "/home/msacks/untitled4.py", line 23, in ? IndexError: index out of range: 0 TIA From aahz at pythoncraft.com Tue Feb 10 14:18:11 2009 From: aahz at pythoncraft.com (Aahz) Date: 10 Feb 2009 11:18:11 -0800 Subject: subprocess.Popen - file like object from stdout=PIPE References: <49895e45$0$2860$ba620e4c@news.skynet.be> <4989864F.50700@skynet.be> <49899185$0$2861$ba620e4c@news.skynet.be> Message-ID: In article <49899185$0$2861$ba620e4c at news.skynet.be>, Helmut Jarausch wrote: > >These pipes are exposed as file-like objects which can be accessed via >the stdin, stdout or stderr (resp.) attributes of an object of class >subprocess.Popen . Please file a doc request at bugs.python.org -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From space.captain.face at gmail.com Tue Feb 10 14:27:36 2009 From: space.captain.face at gmail.com (Kalibr) Date: Tue, 10 Feb 2009 11:27:36 -0800 (PST) Subject: Using TK and the canvas. Message-ID: <28740c97-58fa-4fa7-9321-28c05d5520b8@n33g2000pri.googlegroups.com> Hi all. I'm experimenting with making a UI for a little (well, not quite) script that basically draws up a tech tree to some skills from my favorite game. What I'm aiming for looks a little like this site here:(apologies if I'm not supposed to direct link) http://www.anderkoo.com/uploads/271/605/NewTechTree.jpg. Anyway, I made a script which reads data from several files and saves the data into an array of skill objects, here's what it looks like: #define the class class skill: def __init__(self, name, description, a1, a2, rank, prereq): self.name = name #string (example is "Anchoring") self.desc = description #string (example is "blah blah blah") self.a1 = a1 #string with attributes affecting the skill (Example is "Int") self.a2 = a2 #string self.rank = rank #how hard it is to train (example is "5") (too lazy to convert to int self.prereq = prereq #any prerequsites (an array of ["skill", "levelrequired"]) #the trained level already self.skillowned = "0" #we change this later on when we access another file :) Finally, I set up a class which accepts a parent (normally root), and the skill in question. here it is: class SkillInfo: def __init__(self, parent, skill): container = Frame(parent) container.pack() #we make this the top frame for some reason labelcontainer = Frame(container, height=50, width=50) labelcontainer.pack(side=LEFT, fill=BOTH, expand=YES) desccont = Frame(container, height=50, width=50) #the description content desccont.pack(side=LEFT, fill=BOTH, expand=YES) #make a name label Label(labelcontainer, text=skill.name, wraplength=100).pack (side=TOP, anchor=W) #print the level buttons for i in range(1, 6): button = Button(labelcontainer) button["text"] = "Level", i if int(skill.skillowned) >= i: button["background"] = "green" button["width"] = 10 else: button["background"] = "red" button["width"] = 10 button.pack(anchor=W) Label(desccont, text=("\n"+skill.desc), wraplength=100).pack() Now I know all I have to do is set the SkillInfos parent to a canvas, but how would I arrange and draw the lines? Thanks all :) From Scott.Daniels at Acm.Org Tue Feb 10 14:27:57 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 10 Feb 2009 11:27:57 -0800 Subject: UnitTest break on failure In-Reply-To: References: Message-ID: Qian Xu wrote: > i am writing unit tests and have got a problem: > I want to test some code sequence like: > > self.assertEquals(testMethod1(), expected_value1); > self.assertEquals(testMethod2(), expected_value2); > > However, if the first test item is failed, no more tests will be executed. > Can I tell Python, > 1. go ahead, if a failure is occurred. > 2. stop, if an error is occurred? Well, each test should be independent, so generally you are talking about multiple tests. If you really want a test to see if you get through a sequence in a single test: import unittest ... class MyTest(unittest.TestCase): def test_multi_step(self): expectations = [(expected_value1, testMethod1), (expected_value2, testMethod2), (final_expected, another_test, arg1, arg2)] try: for step, ops in enumerate(expectations): self.assertEquals(ops[0], ops[1](*ops[2:])) except Exception, why: raise ValueError('Step %s Failed: %s' % (step, why)) # here the test passed. ... if __name__ == '__main__': unittest.main() Note this gives you less information (the traceback doesn't go down to the actual error), but it shows you what step failed. --Scott David Daniels Scott.Daniels at Acm.Org From geert.discussions at gmail.com Tue Feb 10 14:29:10 2009 From: geert.discussions at gmail.com (Geert Vancompernolle) Date: Tue, 10 Feb 2009 20:29:10 +0100 Subject: Python DLL's for C++? Message-ID: <4991D586.6090600@gmail.com> Hi, Is it possible to write DLL's in Python for applications that only provide C++ interfaces? Example: NotePad++ is extendible by writing C++ DLL's which can call the NotePad++ interfaces. I wonder if those DLL's also can be written in Python, which in the end calls the C++ interfaces of NotePad++... -- Best rgds, Geert ________________________________________________ *Use EcoCho : environmentally friendly search the internet!* From steve at holdenweb.com Tue Feb 10 14:34:16 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 10 Feb 2009 14:34:16 -0500 Subject: Introduction to Python, Washington DC, March 3-5 Message-ID: <4991D6B8.2050002@holdenweb.com> Holden Web is pleased to announce its next public introductory Python class in the Washington, DC area on March 3-5. To enroll, or to learn more about the class please visit: http://holdenweb.com/py/training/ If you have multiple students requiring training you may be interested to know that this course can also be presented on-site. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From rgruet at free dot fr Tue Feb 10 14:38:24 2009 From: rgruet at free dot fr (Richard Gruet) Date: Tue, 10 Feb 2009 20:38:24 +0100 Subject: ANN: Python 2.6 Quick Reference available Message-ID: <4991d7b0$0$4785$426a34cc@news.free.fr> The Python 2.6 Quick Reference is available in HTML and PDF formats at http://rgruet.free.fr/#QuickRef. This time I was helped by Josh Stone for the update. As usual, your feedback is welcome (pqr at rgruet.net). Cheers, Richard Gruet From clp2 at rebertia.com Tue Feb 10 14:38:42 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 10 Feb 2009 11:38:42 -0800 Subject: bool evaluations of generators vs lists In-Reply-To: <20090210111514.07e0480a@microvu.com> References: <20090210111514.07e0480a@microvu.com> Message-ID: <50697b2c0902101138v2072f95fj19d94dba0714abb3@mail.gmail.com> On Tue, Feb 10, 2009 at 11:15 AM, Josh Dukes wrote: > quite simply...what??? > > In [108]: bool([ x for x in range(10) if False ]) > Out[108]: False This evaluates the list comprehension and creates an empty list, which is considered boolean False by Python. > In [109]: bool( x for x in range(10) if False ) > Out[109]: True Whereas this creates a /generator object/, whose inner expression is *not evaluated until specifically required* (e.g. by for-looping over the generator object). Generators don't have a specially defined truthiness critera (it's impossible to define generally -- consider something like `x for x in all_integers if f(x)`, for a complicated f(x), which would require a solution to the halting problem to know in advance if it will have a non-zero length), so they end up using the default behavior for objects with otherwise undefined boolean truth, which is to consider them True. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From marduk at letterboxes.org Tue Feb 10 14:39:30 2009 From: marduk at letterboxes.org (Albert Hopkins) Date: Tue, 10 Feb 2009 14:39:30 -0500 Subject: bool evaluations of generators vs lists In-Reply-To: <20090210111514.07e0480a@microvu.com> References: <20090210111514.07e0480a@microvu.com> Message-ID: <1234294770.8528.14.camel@localhost.localdomain> On Tue, 2009-02-10 at 11:15 -0800, Josh Dukes wrote: > quite simply...what??? > > In [108]: bool([ x for x in range(10) if False ]) > Out[108]: False > > In [109]: bool( x for x in range(10) if False ) > Out[109]: True > > Why do these two evaluate differently? I was expecting that they would > evaluate the same but the generator would return true *as soon as the > first value is detected*. I'd really expect it to act more like... The first example is a list. A list of length 0 evaluates to False. The second example returns a generator object. A generator object apparently evaluates to true. Your example is not iterating of their values of the generator, but evaluating bool(generator_object) itself. My feeling is that bool(generator_object) is ambiguous so shouldn't be used to begin with. In both examples, bool() doesn't actually iterate over the arguments. Maybe that's what confused you. Instead look at this: >>> type([x for x in range(10) if False ]) >>> type((x for x in range(10) if False )) > def has_values(g): > for i in g: > return True > return False > > So what's going on here? Am I using the wrong function or is this > actually just a bug? bool != has_values. Check python.org for how Python determines the "truthiness" of an object. Generally speaking the following evaluate to False: * None * False * zero of any numeric type, for example, 0, 0L, 0.0, 0j. * any empty sequence, for example, '', (), []. * any empty mapping, for example, {}. * instances of user-defined classes, if the class defines a __nonzero__() or __len__() method, when that method returns the integer zero or bool value False. All other values are considered true -- so objects of many types are always true. From benjamin at python.org Tue Feb 10 14:40:56 2009 From: benjamin at python.org (Benjamin Peterson) Date: Tue, 10 Feb 2009 19:40:56 +0000 (UTC) Subject: "Super()" confusion References: <20090210000405.12853.971581682.divmod.quotient.8036@henry.divmod.com> <6vd0h1Fjele5U1@mid.uni-berlin.de> Message-ID: Marc 'BlackJack' Rintsch gmx.net> writes: > > On Tue, 10 Feb 2009 02:02:43 +0000, Benjamin Peterson wrote: > > > Jean-Paul Calderone divmod.com> writes: > >> Consider whether you really need to use super(). > >> > >> http://fuhm.net/super-harmful/ > > > > This article chiefly deals with super()'s harm in multiple inteheritance > > situations. For the simple case, though, like that presented by the OP, > > I believe super() is perfect. > > But for the simple cases it is unnecessary because it was invented to > deal with multiple inheritance problems. super() is great for single inheritance because it furthers the DRY principle (base classes are not scattered through the code), and rather ugly use of unbound methods. From exarkun at divmod.com Tue Feb 10 14:45:23 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Tue, 10 Feb 2009 14:45:23 -0500 Subject: "Super()" confusion In-Reply-To: Message-ID: <20090210194523.12853.2081273672.divmod.quotient.8354@henry.divmod.com> On Tue, 10 Feb 2009 19:40:56 +0000 (UTC), Benjamin Peterson wrote: >Marc 'BlackJack' Rintsch gmx.net> writes: > >> >> On Tue, 10 Feb 2009 02:02:43 +0000, Benjamin Peterson wrote: >> >> > Jean-Paul Calderone divmod.com> writes: >> >> Consider whether you really need to use super(). >> >> >> >> http://fuhm.net/super-harmful/ >> > >> > This article chiefly deals with super()'s harm in multiple inteheritance >> > situations. For the simple case, though, like that presented by the OP, >> > I believe super() is perfect. >> >> But for the simple cases it is unnecessary because it was invented to >> deal with multiple inheritance problems. > >super() is great for single inheritance because it furthers the DRY principle >(base classes are not scattered through the code), and rather ugly use of >unbound methods. It replaces one kind of repetition with another. I think each kind is about as unpleasant. Has anyone gathered any data on the frequency of changes of base classes as compared to the frequency of classes being renamed? I don't think either happens very often, but it might be interesting to see some numbers. Jean-Paul From clp2 at rebertia.com Tue Feb 10 14:46:24 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 10 Feb 2009 11:46:24 -0800 Subject: Tricky question about native extension packaging In-Reply-To: <07cf55ac-b832-422e-aec0-12756e27ced9@t3g2000yqa.googlegroups.com> References: <07cf55ac-b832-422e-aec0-12756e27ced9@t3g2000yqa.googlegroups.com> Message-ID: <50697b2c0902101146u1c3a36eav91654b02ddc4d897@mail.gmail.com> On Tue, Feb 10, 2009 at 8:42 AM, wrote: > let's assume I (almost) have and extension available as a C file and > the setup.py and I want to generate from this single c file 2 .so > files using > > cc -DOPTION1 x.c to produce x_1.so > cc -DOPTION2 x.c to produce x_2.so > > and at runtime depending of my OS version either load x_1 or x_2 I don't know about the setup.py part of your question, but as for choosing between 2 modules at runtime: #file foo.py #assuming 'foo' is the desired name of the module from sys import platform SUN = 'sunos5' LINUX = 'linux2' WIN = 'win32' if platform == SUN: from x_1 import * elif platform == LINUX: from x_2 import * elif platform == WIN: from x_1 import * else: raise RuntimeError, "Unknown/unsupported platform" Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From version5 at gmail.com Tue Feb 10 14:46:54 2009 From: version5 at gmail.com (nnp) Date: Tue, 10 Feb 2009 19:46:54 +0000 Subject: Working with propositional formulae in Python Message-ID: <28749c0e0902101146i4bc3e69ds898ebe8527f904b8@mail.gmail.com> Hey, I'm currently working with propositional boolean formulae of the type 'A & (b -> c)' (for example). I was wondering if anybody knows of a Python library to create parse trees and convert such formulae to conjunctive, disjunctive and Tseitin normal forms? Cheers, nnp -- http://www.unprotectedhex.com http://www.smashthestack.org From rt8396 at gmail.com Tue Feb 10 14:51:07 2009 From: rt8396 at gmail.com (r) Date: Tue, 10 Feb 2009 11:51:07 -0800 (PST) Subject: Using TK and the canvas. References: <28740c97-58fa-4fa7-9321-28c05d5520b8@n33g2000pri.googlegroups.com> Message-ID: <41c83165-d6ec-429f-ac27-7d103e0d2d2b@u13g2000yqg.googlegroups.com> On Feb 10, 1:27?pm, Kalibr wrote: [snip] > Now I know all I have to do is set the SkillInfos parent to a canvas, > but how would I arrange and draw the lines? Thanks all :) You should really check out wxPython, there is support for just this type of thing. of course you could do this with Tkinter, but just thinking about it makes my head hurt :). From fetchinson at googlemail.com Tue Feb 10 15:01:53 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 10 Feb 2009 12:01:53 -0800 Subject: "Super()" confusion In-Reply-To: References: <20090210012739.12853.653428988.divmod.quotient.8083@henry.divmod.com> Message-ID: On 2/9/09, Gabriel Genellina wrote: > En Mon, 09 Feb 2009 23:34:05 -0200, Daniel Fetchinson > escribi?: > >>>>>> Hello. I've been scouring the web looking for something to clear up a >>>>>> little confusion about the use of "super()" but haven't found >>>>>> anything >>>>>> that really helps. Here's my simple example: >>>>>> >>>>>> [snip] >>>>>> >>>>>> "super(Child,self).__init__(filePath) >>>>>> TypeError: super() argument 1 must be type, not classobj" >>>>>> >>>>>> What have I done wrong? Thanks in advance for any help. >>>>> >>>>> Consider whether you really need to use super(). >>>>> >>>>> http://fuhm.net/super-harmful/ >>>> >>>> Did you actually read that article, understood it, went through the >>>> tons of responses from python-dev team members, including Guido >>> >>> Yes. Why the knee-jerk reaction? >> >> Because throwing around that link carries about the same amount of >> information as "perl is better than python", "my IDE is better than >> yours", "vim rulez!", "emacs is cooler than vim", etc, etc. > > Not at all. It contains accurate and valuable information that isn't > available elsewhere. But does not contain other valuable information which would demystify super. If only this source is shown to a person who wants to learn the proper usage of super, the impression he/she gets will be distorted. Example: 1. somebody asks about threading 2. reply comes: there is a GIL! you can't do real threading. Now this reply might be technically more-or-less correct, it is misleading and does not help the poster. An informed discussion of the various solutions that does not involve a rant about the GIL would be very useful though. >>> I simply pointed out a resource which >>> might be helpful to someone trying to learn to use super. >> >> It will certainly not be helpful to anyone trying to learn the usage >> of super. The person who wrote that essay is simply misunderstanding >> the concept, as has been explained countless times by the python dev >> team. Hence, it only increases confusion, adds to the noise and >> spreads false alarm. > > AFAIK, all facts appearing in said article are still true (except for 3.x > which uses a shorter form). If super usage had been clearly documented in > the first place, this had not happened. > Perhaps you could point us to some resource explaining how is super > supposed to be used correctly? > And of those giving explanations in python-dev, nobody cared to add a > single word to the Python documentation for years. You might want to start with http://www.artima.com/weblogs/viewpost.jsp?thread=236275 You are right, it's not in the documentation. But if somebody asks on c.l.p the appropriate answer, I think, is to point to information such as the one above, and not the misleading "harmful" essay. >> Honestly, I don't understand how this thing got so much out of >> control. If anyone starts an intelligent question or remark about >> super, this essay is thrown in no matter what. Anyone can explain why? > > Because for a very loooooong time (seven years, 2001-2008) super was > almost undocumented. The Library Reference -before release 2.6- only had a > short paragraph, the online documentation referred (and still does) to the > original essay by Guido introducing descriptors, which is inaccurate and > outdated, and then the "... harmful" article was the only source of > information available. > Worse was the fate of packages and how they're imported: nobody "could be > bothered to spell that out" (sic); or how import works in general, still > barely documented (one has to dig into the PEP collection, trying to guess > what parts are truly implemented and what parts are only a wish...) You are right, the documentation needs some work in this regard. But again, just because some sources are not in the documentation doesn't mean that the most opinionated essay is the best source. A little search turns up much more useful ones. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From fetchinson at googlemail.com Tue Feb 10 15:03:18 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 10 Feb 2009 12:03:18 -0800 Subject: "Super()" confusion In-Reply-To: References: <20090210012739.12853.653428988.divmod.quotient.8083@henry.divmod.com> Message-ID: >>>>> Consider whether you really need to use super(). >>>>> >>>>> http://fuhm.net/super-harmful/ >>>> >>>>Did you actually read that article, understood it, went through the >>>>tons of responses from python-dev team members, including Guido > > "Tons" of responses? This was mentioned already, but just to repeat: one good source, for example, apart from the python-dev list: http://www.artima.com/weblogs/viewpost.jsp?thread=236275 > I count 16, about a third of which are written by James Knight himself > (the author of the page you are ranting against), and of the remaining, > about half are low-to-zero information content, e.g. Tim Peter's joke > about renaming the page for better marketing value. > > It's especially telling that even Guido, the most vocal critic of the > article, is critical of the *title* but not the content. In his first > post, he says: "I agree with the best practices in James's > Conclusion...", and suggested that if the article was called "Multiple > Inheritance Pitfalls in Python" he'd be much happier. > > >>> Yes. Why the knee-jerk reaction? >> >> Because throwing around that link carries about the same amount of >> information as "perl is better than python", "my IDE is better than >> yours", "vim rulez!", "emacs is cooler than vim", etc, etc. > > This is clearly not the case when even the most vocal critic agrees with > the article's recommendations. > > >>> I simply pointed out a resource which might be helpful to someone >>> trying to learn to use super. >> >> It will certainly not be helpful to anyone trying to learn the usage of >> super. > > I've read it, and found it very useful. > > >> The person who wrote that essay is simply misunderstanding the >> concept, as has been explained countless times by the python dev team. > > "Countless". Is that more or less than the "tons of responses" above? > > >> Hence, it only increases confusion, adds to the noise and spreads false >> alarm. > > So you say. > > >> Honestly, I don't understand how this thing got so much out of control. >> If anyone starts an intelligent question or remark about super, this >> essay is thrown in no matter what. Anyone can explain why? > > Because inheritance is potentially confusing. Multiple inheritance is > even more confusing. Multiple inheritance with diamond diagrams even more > so, and multiple inheritance with diamond diagrams and non-cooperative > classes are simply impossible to get right. > > Because there are many pitfalls to inheritance in Python, and they aren't > obvious: who on earth would imagine that calling __init__ or __new__ with > positional arguments could be dangerous? James Knight's article is a well- > written, understandable description of some of them, in one place and > with a catchy title. Of course people are going to link to it. > > And finally, because people do wrongly get the impression that using > super will magically make those problems go away. I know this, because I > was one of them. > > (I went through the anger period, sure that Knight must be full of it. > How could anyone suggest that Guido made a super that isn't perfect? I > got past that once I realised just how complex inheritance actually is. > Currently I'm in denial, writing code with super and hoping that it will > Just Work but not pushing it too hard in case it doesn't.) > > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list > -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From robert.kern at gmail.com Tue Feb 10 15:18:55 2009 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 10 Feb 2009 14:18:55 -0600 Subject: Logging in Python In-Reply-To: <958a7679-6116-44e0-b448-fec34d36c486@v13g2000yqm.googlegroups.com> References: <958a7679-6116-44e0-b448-fec34d36c486@v13g2000yqm.googlegroups.com> Message-ID: On 2009-02-10 11:50, aha wrote: > Hello All, > > I have an application where logging may need to be configured in > multiple places. I've used the Python Logging Framework for sometime, > but I'm still not sure how to test if logging has configured. For > example, I have modules A, B, and C. > > Below is some pseudo code... > moduleA > > class A(object): > def __init__(self): > ... > > startLogging(config): > # Configure logging > # global logger > ... > > moduleB > import moduleA > from myconfig import MyConfig > class B(object): > def __init__(self): > # self.config = MyConfig() > # if logging has started [HOW DO YOU DO THIS?] > # self.logger = logging.getLogger("moduleB") > # else > # self.logger = moduleA.startLogging(self.config) > # moduleA.startLogging > ... > > Where I need help is determining if a logger has already been > configured. Any advice? I just do this in every module in which I'm doing logging: import logging logger = logging.getLogger(__name__) I configure my logging only in my main() function(s). -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From martin at v.loewis.de Tue Feb 10 15:19:28 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 10 Feb 2009 21:19:28 +0100 Subject: Python DLL's for C++? In-Reply-To: References: Message-ID: <4991e150$0$30918$9b622d9e@news.freenet.de> > Is it possible to write DLL's in Python for applications that only > provide C++ interfaces? Example: NotePad++ is extendible by writing C++ > DLL's which can call the NotePad++ interfaces. Not directly, no. You have to write a C++ DLL which then can delegate all calls to it to some Python function, and likewise expose Notepad++ API to Python. > I wonder if those DLL's also can be written in Python, which in the end > calls the C++ interfaces of NotePad++... The actual logic can be in Python, but you do need a C++ wrapper module. OTOH, if Notepad++ would also support COM/ActiveX plugins, then those could directly be written in Python (assuming the COM interfaces supported automation). Regards, Martin From bkline at rksystems.com Tue Feb 10 15:19:59 2009 From: bkline at rksystems.com (Bob Kline) Date: Tue, 10 Feb 2009 15:19:59 -0500 Subject: Change in cgi module's handling of POST requests Message-ID: <4991E16F.3010407@rksystems.com> [Didn't realize the mirror didn't work both ways] We just upgraded Python to 2.6 on some of our servers and a number of our CGI scripts broke because the cgi module has changed the way it handles POST requests. When the 'action' attribute was not present in the form element on an HTML page the module behaved as if the value of the attribute was the URL which brought the user to the page with the form, but without the query (?x=y...) part. Now FieldStorage.getvalue () is giving the script a list of two copies of the value for some of the parameters (folding in the parameters from the previous request) instead of the single string it used to return for each. I searched this newsgroup looking for a discussion of the proposal to impose this change of behavior, and perhaps I wasn't using the right phrases in my search, but I didn't find anything. I see that Perl still behaves the way pre-2.6 Python used to (not that I view that as a reason for anything). We'll work around the breakage by explicitly setting the 'action' attribute everywhere, of course, but I usually see some discussion (often heated) of the impact of behavior changes on existing software when something like this is in the works. Did I miss it? I also noted that the module is making some deprecated use of the BaseException class. Cheers. From cosmo_general at yahoo.com Tue Feb 10 15:21:19 2009 From: cosmo_general at yahoo.com (Muddy Coder) Date: Tue, 10 Feb 2009 12:21:19 -0800 (PST) Subject: How to get a return from Button? Message-ID: <5ec5a074-9eaa-49e2-a64c-7a63f28d3743@k19g2000yqg.googlegroups.com> Hi Folks, I want to use a Button to trigger askopenfilename() dialog, then I can select a file. My short code is below: def select_file(): filenam = askopenfilename(title='Get the file:') return filenam root = Tk() Button(root, text='Select a file', command=select_file).pack() root.mainloop() My goal is to get the path of filenam, but the function select_file() has nowhere to return what it selected. Can anybody help me out? I consulted the book of Programming Python, but found no demo in this regard. If the function has no return, command=blabla will work nicely. I am lost in the scope. Thanks! Muddy Coder From vinay_sajip at yahoo.co.uk Tue Feb 10 15:21:42 2009 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Tue, 10 Feb 2009 12:21:42 -0800 (PST) Subject: Logging in Python References: <958a7679-6116-44e0-b448-fec34d36c486@v13g2000yqm.googlegroups.com> Message-ID: On Feb 10, 5:50 pm, aha wrote: > Hello All, > > I have an application whereloggingmay need to be configured in > multiple places. I've used the PythonLoggingFramework for sometime, > but I'm still not sure how to test iflogginghas configured. For > example, I have modules A, B, and C. > > Below is some pseudo code... > moduleA > > class A(object): > def __init__(self): > ... > > startLogging(config): > # Configurelogging > # global logger > ... > > moduleB > import moduleA > from myconfig import MyConfig > class B(object): > def __init__(self): > # self.config = MyConfig() > # iflogginghas started [HOW DO YOU DO THIS?] > # self.logger =logging.getLogger("moduleB") > # else > # self.logger = moduleA.startLogging(self.config) > # moduleA.startLogging > ... > > Where I need help is determining if a logger has already been > configured. Any advice? > > Aquil It depends upon how complicated your logging requirements are. For example, each module can have the following code in it: import logging logging.basicConfig(level=logging.DEBUG, filename="/tmp/myapp.log", filemode="w") # An example logger = logging.getLogger(__name__) ... your code, involving logger.debug(...) statements basicConfig() attaches a FileLogger to the root logger, so all logging output would be routed to the file "/tmp/myapp.log" in the example. However, basicConfig() does nothing if the root logger already has handlers, so calling it in each module shouldn't cause problems. It's also nice to use the module name (__name__) as the logger name. Another pattern is to configure logging in your main module, if there is one, and then the other modules just assume logging is configured and log away. If there isn't a main module, have all the modules import a common module which, when imported, configures logging how you want it. Under normal circumstances, the import code will only run once, so your logging only gets configured the first time the module gets imported by any of the others. Regards, Vinay Sajip From aioe.org at technicalbloke.com Tue Feb 10 15:28:00 2009 From: aioe.org at technicalbloke.com (r0g) Date: Tue, 10 Feb 2009 15:28:00 -0500 Subject: Functional schmunctional... Message-ID: I remember being forced to do a bit of functional programming in ML back at Uni in the mid 90, the lecturers were all in a froth about it and I must admit the code was elegant to look at. The problem was the dog slow performance for anything half practical, especially with recursion being the technique de jour. The HP workstations we were using were really quite beefy for their time yet simple ML stuff would just murder the CPU and RAM. Added to that, recursive stuff could be extremely confusing to debug so I wrote it off as a nice idea in concept but a waste of my time for anything practical. So fast forward 15 years to this very afternoon... I needed a routine to convert IP address strings to INET numbers and vice-versa and I remember writing one a couple of years back when I first picked up Python. So I went and dug it out. Looking back at old code can be a bit dispiriting though and this was no exception... def inet2ip(n): p = (n/16777216) q = ((n-(p*16777216))/65536) r = ((n-((p*16777216)+(q*65536)))/256) s = ((n-((p*16777216)+(q*65536)+(r*256)))) return str(p)+"."+str(q)+"."+str(r)+"."+str(s) def ip2in(a): li = a.split('.') assert len(li) == 4 a = int(li[0])*16777216 b = int(li[1])*65536 c = int(li[2])*256 d = int(li[3]) return a+b+c+d I thought "OMG, how naive and inelegant that looks, I can do far better than that, after all I know things like list comprehensions and map/reduce now!". I had also noticed over the last year or two a lot of chatter about functional programming especially in conjunction with python. It seems to me that procedural programming has taken quite a kicking against the more OO and functional methodologies over the last few years and given my nothing-but-positive experience with OO of late I was reconsidering the strength of my old opinions on FP. Maybe it was, as my lecturers thought, the paradigm of the future and I was being a crotchety old stick in the mud by spurning it as slow and confusing. With this in mind I set about applying my hard won Python knowledge and wisdom to the rewriting of these functions, not for any particularly practical reasons, just to see what improvements I could wreak on them several years down the line. The IP string to INET number was first and I decided to throw list comprehensions at it... def ip2inet(a): li = a.split('.') assert len(li) == 4 or len(li) == 6 return reduce(add,[int(li[e])*(256**((len(li)-1)-e)) for e in xrange(0,len(li))]) Now, that did made it completely unreadable but I thought, "it's pretty much all one line now so I've gained some conciseness and at least it should run a little faster". After all list comprehensions are often fast aren't they? Well actually no, It runs at less than half the speed of the previous function and now it's entirely lexically impenetrable. Shit :-( So far so bad... As inauspicious as these beginnings were I figured I'd plug on anyway and try a functional approach to the INET number to IP string function - the above experience having reinforced in me the notion that clarity is paramount. Functional programming is all about the clarity and elegance right? I figured it might be worth trading a few cycles for at least, especially as the machine I'm using here in 2009 has more RAM and CPU grunt than whole Uni computer department did back in 1994. Not only that I would only need to do 4 or 6 recursions in this algorithm and so I shouldn't need to worry about the exponential inefficiency problems of yore... def inet2ip(n, l=[], c=4): if c==0: return ".".join(l) p = 256**( c-1 ) l.append( str(n/p) ) return inet2ip( n-(n/p)*p, l, c-1 ) The thing is, that's not really any clearer though is it? I'd wager if you didn't know already it would take you longer to figure out this version than it would the original. Still, "at least" I thought "it's more concise than the last one and it scales to IPv6 far more elegantly". I figured as long as the performance wasn't too lousy I would keep it and so I quickly ran a little benchmark to see how much of a performance hit I would be taking by doing so. The results for 10000 iterations of each were as follows... 0.113744974136 seconds for old INET->IP method 27.7441999912 seconds for new INET->IP method :-/ FFS! It just goes to show that... 1) Thinking you're a smart arse and actually being a smart arse are two quite different things. 2) You should always take received wisdom with a good pinch of salt. 3) People aren't exaggerating when they say Python function calls are expensive are they! Roger Heathcote. From clp2 at rebertia.com Tue Feb 10 15:30:01 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 10 Feb 2009 12:30:01 -0800 Subject: How to get a return from Button? In-Reply-To: <5ec5a074-9eaa-49e2-a64c-7a63f28d3743@k19g2000yqg.googlegroups.com> References: <5ec5a074-9eaa-49e2-a64c-7a63f28d3743@k19g2000yqg.googlegroups.com> Message-ID: <50697b2c0902101230s1d943a5co1811e2dae6bd48dd@mail.gmail.com> On Tue, Feb 10, 2009 at 12:21 PM, Muddy Coder wrote: > Hi Folks, > > I want to use a Button to trigger askopenfilename() dialog, then I can > select a file. My short code is below: > > > def select_file(): > filenam = askopenfilename(title='Get the file:') > return filenam > > root = Tk() > Button(root, text='Select a file', command=select_file).pack() > root.mainloop() > > My goal is to get the path of filenam, but the function select_file() > has nowhere to return what it selected. Can anybody help me out? I > consulted the book of Programming Python, but found no demo in this > regard. If the function has no return, command=blabla will work > nicely. I am lost in the scope. The function has nowhere to return its value to (except somewhere in the innards of Tkinter, where it's discarded), so indeed it should *not* return. You instead need to modify some program state to hold the would-be return value. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From josh.dukes at microvu.com Tue Feb 10 15:50:02 2009 From: josh.dukes at microvu.com (Josh Dukes) Date: Tue, 10 Feb 2009 12:50:02 -0800 Subject: bool evaluations of generators vs lists In-Reply-To: <1234294770.8528.14.camel@localhost.localdomain> References: <20090210111514.07e0480a@microvu.com> <1234294770.8528.14.camel@localhost.localdomain> Message-ID: <20090210125002.1f6d8597@microvu.com> > The first example is a list. A list of length 0 evaluates to False. > > The second example returns a generator object. A generator object > apparently evaluates to true. Your example is not iterating of their > values of the generator, but evaluating bool(generator_object) itself. > My feeling is that bool(generator_object) is ambiguous so shouldn't be > used to begin with. I was actually aware of that (thank you, though, for trying to help). What I was not clear on was if the boolean evaluation is a method of an object that can be modified via operatior overloading (in the same way + is actually .__add__()) or not. Clearly __nonzero__ is the operator I was curious about. Thanks for that info. > bool != has_values. Check python.org for how Python determines the > "truthiness" of an object. Generally speaking the following evaluate > to False: > > * None > * False > * zero of any numeric type, for example, 0, 0L, 0.0, 0j. > * any empty sequence, for example, '', (), []. > * any empty mapping, for example, {}. > * instances of user-defined classes, if the class defines a > __nonzero__() or __len__() method, when that method returns > the integer zero or bool value False. > > All other values are considered true -- so objects of many types are > always true. The thing I don't understand is why a generator that has no iterable values is different from an empty list. Why shouldn't bool == has_value?? Technically a list, a tuple, and a string are also objects but if they lack values they're evaluated as False. It seems to me that a generator is an object that intends to replace lists where lazy evaluation would be more efficent. Here is one place where that's definitely true. The main reason I'm interested in this is that it improves performance immensely over boolean evaluation of large lists (as the attached code shows). It seems to me if I could use find a good use for it in my experimentation that someone else might also want to do the same thing in real-world code. Is there another list I should be asking these questions on? -- Josh Dukes MicroVu IT Department -------------- next part -------------- A non-text attachment was scrubbed... Name: prime.py Type: text/x-python Size: 485 bytes Desc: not available URL: From http Tue Feb 10 15:50:38 2009 From: http (Paul Rubin) Date: 10 Feb 2009 12:50:38 -0800 Subject: Functional schmunctional... References: Message-ID: <7xr626ow2p.fsf@ruckus.brouhaha.com> r0g writes: > def inet2ip(n): > p = (n/16777216) > q = ((n-(p*16777216))/65536) > r = ((n-((p*16777216)+(q*65536)))/256) > s = ((n-((p*16777216)+(q*65536)+(r*256)))) > return str(p)+"."+str(q)+"."+str(r)+"."+str(s) from struct import pack def inet2ip(n): xs = pack('L',n) return '.'.join(str(ord(x)) for x in xs) From namire at gmail.com Tue Feb 10 15:54:14 2009 From: namire at gmail.com (namire) Date: Tue, 10 Feb 2009 12:54:14 -0800 (PST) Subject: Replace unknow string varible in file. Message-ID: <7ec460c5-b625-47e5-88c9-15156533c7da@t13g2000yqc.googlegroups.com> Hey .python first time poster here. I'm pretty good with python so far, but I keep needed a function in my program but not knowing how to build it. =( Here's the problem: Imagine a html file full of 100's of these strings all mooshed together onto many lines; ITEM
Where the word 'MARKER' is a constant, it stay the same in each string and the word 'ITEM' is a random combination of ascii characters of an unknown length. So for example a: CATFISH

Text text textSPAM
and so on... What I need to do it replace each instance of the random letter with a constant and/or delete them. The file is a html file so the stuff inside of is ok to keep and I need that data to identify where the strings are in the file (it's full of other stuff too). I'm tired making a bruteforcer but with unknown length and 26 letters of the alphabet I gave up because it would take too long (it was something like; read file; if '@@MARKER@@; id="'+str(gen_string)+'"-- >"+sr(gen_string)+'
' in file then replace with '', but I'm paraphrasing code and it's not the best solution anyway). Just as a comparison in the Windows OS this seems easy to do when managing files, say for the file a-blah-b-blah.tmp where blah is an unknown you can use: del a-*-b-*.tmp to get rid of that file. But for python and a string in text file I don't have a clue. @_@ could someone please help me? From andrew at acooke.org Tue Feb 10 15:54:51 2009 From: andrew at acooke.org (andrew cooke) Date: Tue, 10 Feb 2009 17:54:51 -0300 (CLST) Subject: Functional schmunctional... In-Reply-To: References: Message-ID: r0g wrote: > def ip2inet(a): > li = a.split('.') > assert len(li) == 4 or len(li) == 6 > return reduce(add,[int(li[e])*(256**((len(li)-1)-e)) for e in > xrange(0,len(li))]) what a mess. i don't use this extreme a functional style in python (it's not really how the language is intended to be used), but i think you can do better than that. how about: from itertools import count def ip2inet(a): blocks = a.split('.') assert len(blocks) in (4, 6) return sum(map(lambda (i, n): int(i) * 256**n, zip(reversed(blocks), count(0)))) i haven't looked at the other function, but as a general comment it sounds me like you are in such a hurry to point out fp is bad that you haven't bothered to master it first. andrew From aioe.org at technicalbloke.com Tue Feb 10 15:55:03 2009 From: aioe.org at technicalbloke.com (r0g) Date: Tue, 10 Feb 2009 15:55:03 -0500 Subject: Python Module: nift References: <9cb28036-7d5f-4b8a-9748-b26c5e9538b4@r15g2000prd.googlegroups.com> Message-ID: J wrote: > Thanks for your answers, especially Chris Rebert and Paul McGuire's. I > have a question: > How far does Python go in the Game Development field? (Using Python > only, no extensions) Hey J, Python's all about the libraries (extensions), you won't be able to do much without them but that's no big whoop. AFAIK most python libs are released under LGPL or BSD style licenses so there's pretty much no restriction on what you can use them for. A lot of games are written in C for performance reasons but most python gaming libs are just wrappers round C gaming libs and share the same names and methods so your knowledge should travel with you. As for which libs to use... There's PyGame which is a a good mature library for 2D stuff. Pyglet seem to be the most popular OpenGL lib for 3D stuff. You might also want to look at the "Blender Game Engine" and the free game "Yo Frankie", they use C for the heavy lifting and Python for scripting levels and stuff, it might be a good way to test the waters. Regards, Roger Heathcote. From travis+ml-python at subspacefield.org Tue Feb 10 15:57:39 2009 From: travis+ml-python at subspacefield.org (Travis) Date: Tue, 10 Feb 2009 14:57:39 -0600 Subject: zlib interface semi-broken Message-ID: <20090210205739.GT6522@subspacefield.org> Hello all, The zlib interface does not indicate when you've hit the end of a compressed stream. The underlying zlib functionality provides for this. With python's zlib, you have to read past the compressed data and into the uncompressed, which gets stored in Decompress.unused_data. As a result, if you've got a network protocol which mixes compressed and non-compressed output, you may find a compressed block ending with no uncompressed data following until you send another command -- which a synchronous (non-pipelined) client will not send, because it is waiting for the [compressed] data from the previous command to be finished. As a result, you get a protocol deadlock. A simple way to fix this would be to add a finished attribute to the Decompress object. However, perhaps this would be a good time to discuss how this library works; it is somewhat awkward and perhaps there are other changes which would make it cleaner. What does the python community think? -- Crypto ergo sum. http://www.subspacefield.org/~travis/ Do unto other faiths as you would have them do unto yours. If you are a spammer, please email john at subspacefield.org to get blacklisted. From ntwrkd at gmail.com Tue Feb 10 16:06:50 2009 From: ntwrkd at gmail.com (Matthew Sacks) Date: Tue, 10 Feb 2009 13:06:50 -0800 Subject: optparse versus getopt Message-ID: does anyone have any arguments against optparse vs getopt From bmaschino at gmail.com Tue Feb 10 16:14:02 2009 From: bmaschino at gmail.com (bmaschino at gmail.com) Date: Tue, 10 Feb 2009 13:14:02 -0800 (PST) Subject: pySerial help please! Message-ID: Hello all, I am very new to Python and I am using it because I needed an easy language to control a piece of equipment that connects to my computer via a serial cable. I am running Python 2.6 with pySerial 2.4 under Windows. I can get Python to create a serial port on COM1, but when I try to write to the device, nothing happens. Here is an example: import serial ser = serial.Serial(0) ser.write("otpm 2 16 0") ser.close() If I connect to the device in Hyperterminal the device will behave as expected when I give it the command 'otpm 2 16 0' but not in Python. I have confirmed Python is actually controlling the port because Hyperterminal will not open the port while Python has it open, although I have not been able to try a loopback connector as of yet. Any suggestions out there? Thanks in advance! Cheers, Bryce From robert.kern at gmail.com Tue Feb 10 16:19:45 2009 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 10 Feb 2009 15:19:45 -0600 Subject: optparse versus getopt In-Reply-To: References: Message-ID: On 2009-02-10 15:06, Matthew Sacks wrote: > does anyone have any arguments against optparse vs getopt As the getopt docs say: "A more convenient, flexible, and powerful alternative is the optparse module." I have found all three statements to be true. But I've found argparse to be even better. The main reason is that argparse will help you parse, verify and generate help text for positional arguments in addition to --options. http://argparse.python-hosting.com/ http://argparse.python-hosting.com/wiki/ArgparseVsOptparse -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From Scott.Daniels at Acm.Org Tue Feb 10 16:19:57 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 10 Feb 2009 13:19:57 -0800 Subject: Functional schmunctional... In-Reply-To: References: Message-ID: For expressiveness, try something like: def ip2in(dotted_ip_addr): result = 0 assert dotted_ip_addr.count('.') in (3, 7) for chunk in dotted_ip_addr.split('.'): result = (result << 8) + int(chunk) return result def inet2ip(ip_number): assert 0 < ip_number < 1 << 48 bytes = [] while ip_number: bytes.append(ip_number & 255) ip_number >>= 8 assert len(bytes) in (4, 6) return '.'.join(str(n) for n in reversed(bytes)) --Scott David Daniels Scott.Daniels at Acm.Org From vlastimil.brom at gmail.com Tue Feb 10 16:22:37 2009 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Tue, 10 Feb 2009 22:22:37 +0100 Subject: Replace unknow string varible in file. In-Reply-To: <7ec460c5-b625-47e5-88c9-15156533c7da@t13g2000yqc.googlegroups.com> References: <7ec460c5-b625-47e5-88c9-15156533c7da@t13g2000yqc.googlegroups.com> Message-ID: <9fdb569a0902101322y60a6410bs67d513877dad0f06@mail.gmail.com> 2009/2/10 namire : > Hey .python first time poster here. I'm pretty good with python so > far, but I keep needed a function in my program but not knowing how to > build it. =( Here's the problem: > > Imagine a html file full of 100's of these strings all mooshed > together onto many lines; > ITEM
> Where the word 'MARKER' is a constant, it stay the same in each string > and the word 'ITEM' is a random combination of ascii characters of an > unknown length. So for example a: > CATFISH

Text text text h1>SPAM
and so on... > > What I need to do it replace each instance of the random letter with a > constant and/or delete them. >... > Just as a comparison in the Windows OS this seems easy to do when > managing files, say for the file a-blah-b-blah.tmp where blah is an > unknown you can use: del a-*-b-*.tmp to get rid of that file. But for > python and a string in text file I don't have a clue. @_@ could > someone please help me? > -- > http://mail.python.org/mailman/listinfo/python-list > Hi, It is not quite clear to me, what should be achieved with the given file, but an example with wildcard characters in windows implies, that the regular expressions can be of some use here (given the file is as regular as the samples, especially without nesting the comments etc.) the segments in examples can be matched eg. with the expression>: \1
the ITEM, CATFISH, SPAM ... elements are captured in the parethesised group and can be used foe matching or replacing. check the re module in the python library: http://docs.python.org/library/re.html hth vbr From marduk at letterboxes.org Tue Feb 10 16:25:47 2009 From: marduk at letterboxes.org (Albert Hopkins) Date: Tue, 10 Feb 2009 16:25:47 -0500 Subject: bool evaluations of generators vs lists In-Reply-To: <20090210125002.1f6d8597@microvu.com> References: <20090210111514.07e0480a@microvu.com> <1234294770.8528.14.camel@localhost.localdomain> <20090210125002.1f6d8597@microvu.com> Message-ID: <1234301147.8528.47.camel@localhost.localdomain> On Tue, 2009-02-10 at 12:50 -0800, Josh Dukes wrote: > The thing I don't understand is why a generator that has no iterable > values is different from an empty list. Why shouldn't bool == > has_value?? Technically a list, a tuple, and a string are also objects > but if they lack values they're evaluated as False. It seems to me that > a generator is an object that intends to replace lists where lazy > evaluation would be more efficent. Here is one place where that's > definitely true. Well, I did not implement generators in python, but my guess would be that lists and tuples can be checked with len() to see if it is non-empty. Generators don't have length. You would at least need to call .next() which "changes" the generator so every time you'd want to evaluate the boolean of the generator you'd potentially lose the next item. Generators are meant to replace lists where you don't want/can't put the entire "list" in memory or for which there is no (known) end to the list. You don't know the next value a generator will return (if any) until you evaluate it. Don't think of generators as containers like lists, tuples and strings are. Generators don't "contain" values. Generators are objects that return the "next" value. It has no idea how many values it contains (it's not a container). It only knows the ".next()" value when it's called. It forgets the value once it's returned. And it has no idea how far it is in the iteration until it's finished (StopIteration). > The main reason I'm interested in this is that it improves performance > immensely over boolean evaluation of large lists (as the attached code > shows). It seems to me if I could use find a good use for it in my > experimentation that someone else might also want to do the same thing > in real-world code. I don't understand what you mean by this. But if you really want to know if a generator is "non-empty": def non_empty(virgin_generator): try: virgin_generator.next() # note you just lost the first value return True except StopIteration: return False The only way to get around this is to put all the values of a generator inside a container (e.g. a list): l = list(generator_object) but in doing so you've (obviously) lost the advantages of the generator. > Is there another list I should be asking these questions on? I don't know. Sorry I wasn't able to help you. -a From Scott.Daniels at Acm.Org Tue Feb 10 16:36:21 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 10 Feb 2009 13:36:21 -0800 Subject: zlib interface semi-broken In-Reply-To: References: Message-ID: Travis wrote: > The zlib interface does not indicate when you've hit the > end of a compressed stream.... > The underlying zlib functionality provides for this. > > With python's zlib, you have to read past the compressed data and into > the uncompressed, which gets stored in Decompress.unused_data. > ... [good explanation of why this is problematic] ... > A simple way to fix this would be to add a finished attribute to the > Decompress object. Perhaps you could submit a patch with such a change? > However, perhaps this would be a good time to discuss how this library > works; it is somewhat awkward and perhaps there are other changes which > would make it cleaner. Well, it might be improvable, I haven't really looked. I personally would like it and bz2 to get closer to each other in interface, rather than to spread out. SO if you are really opening up a can of worms, I vote for two cans. --Scott David Daniels Scott.Daniels at Acm.Org From aquil.abdullah at gmail.com Tue Feb 10 16:38:19 2009 From: aquil.abdullah at gmail.com (aha) Date: Tue, 10 Feb 2009 13:38:19 -0800 (PST) Subject: Logging in Python References: <958a7679-6116-44e0-b448-fec34d36c486@v13g2000yqm.googlegroups.com> Message-ID: Thanks for your suggestions. I've also figured that I can test if logging.RootLogger.manager.loggerDict has any items in it. Or if it has a logger for the module that I wish to start. I like basicLogger idea though as it seems like the cleanest implementation. On Feb 10, 3:21?pm, Vinay Sajip wrote: > On Feb 10, 5:50 pm, aha wrote: > > > > > Hello All, > > > I have an application whereloggingmay need to be configured in > > multiple places. ?I've used the PythonLoggingFramework for sometime, > > but I'm still not sure how to test iflogginghas configured. ?For > > example, I have modules A, B, and C. > > > Below is some pseudo code... > > moduleA > > > class A(object): > > ? def __init__(self): > > ? ? ... > > > startLogging(config): > > ? # Configurelogging > > ? # global logger > > ? ... > > > moduleB > > import moduleA > > from myconfig import MyConfig > > class B(object): > > ? def __init__(self): > > ? ? # self.config = MyConfig() > > ? ? # iflogginghas started [HOW DO YOU DO THIS?] > > ? ? # ? self.logger =logging.getLogger("moduleB") > > ? ? # else > > ? ? # ? self.logger = moduleA.startLogging(self.config) > > ? ? # moduleA.startLogging > > ? ? ... > > > Where I need help is determining if a logger has already been > > configured. ?Any advice? > > > Aquil > > It depends upon how complicated your logging requirements are. For > example, each module can have the following code in it: > > import logging > > logging.basicConfig(level=logging.DEBUG, filename="/tmp/myapp.log", > filemode="w") # An example > > logger = logging.getLogger(__name__) > > ... your code, involving logger.debug(...) statements > > basicConfig() attaches a FileLogger to the root logger, so all logging > output would be routed to the file "/tmp/myapp.log" in the example. > However, basicConfig() does nothing if the root logger already has > handlers, so calling it in each module shouldn't cause problems. It's > also nice to use the module name (__name__) as the logger name. > > Another pattern is to configure logging in your main module, if there > is one, and then the other modules just assume logging is configured > and log away. If there isn't a main module, have all the modules > import a common module which, when imported, configures logging how > you want it. Under normal circumstances, the import code will only run > once, so your logging only gets configured the first time the module > gets imported by any of the others. > > Regards, > > Vinay Sajip From python.list at tim.thechases.com Tue Feb 10 16:38:35 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 10 Feb 2009 15:38:35 -0600 Subject: optparse versus getopt In-Reply-To: References: Message-ID: <4991F3DB.5000802@tim.thechases.com> Matthew Sacks wrote: > does anyone have any arguments against optparse vs getopt I've found that the optparse module beats getopt on *every* aspect except in the event that you have experience with the C getopt libraries *and* just want something that behaves like those libraries. Optparse is easy to learn, easy to read, and part of the Python stdlib. -tkc From ntwrkd at gmail.com Tue Feb 10 16:42:38 2009 From: ntwrkd at gmail.com (Matthew Sacks) Date: Tue, 10 Feb 2009 13:42:38 -0800 Subject: optparse versus getopt In-Reply-To: <4991F3DB.5000802@tim.thechases.com> References: <4991F3DB.5000802@tim.thechases.com> Message-ID: it seems as if optparse isn't in my standard library. is there a way to add a lib like ruby gems? On Tue, Feb 10, 2009 at 1:38 PM, Tim Chase wrote: > Matthew Sacks wrote: >> >> does anyone have any arguments against optparse vs getopt > > I've found that the optparse module beats getopt on *every* aspect except in > the event that you have experience with the C getopt libraries *and* just > want something that behaves like those libraries. Optparse is easy to > learn, easy to read, and part of the Python stdlib. > > -tkc > > > > > From bkaplan1 at gmail.com Tue Feb 10 16:44:37 2009 From: bkaplan1 at gmail.com (Brian Kaplan) Date: Tue, 10 Feb 2009 16:44:37 -0500 Subject: Cannot get python to read a CAP file link in an ATOM feed Message-ID: Hi List, I'm trying to get python to parse a CAP file in an ATOM feed from the National Weather Service. Here's one states ATOM feed. http://www.weather.gov/alerts-beta/ky.php?x=0. If you view the source of this file, there is a reference to another web feed. For instance, href="http://www.weather.gov/alerts-beta/wwacapget.php?x=KY20090210210200ILNNPWILNHighWindWarning20090212100000KY" (note, this latter file changes hourly). I can retrieve and parse the first file but cannot get the second file read or parsed as an xml. I am able to read it into memory using urlopen. Can python read and parse as an xml or do I need to read it into memory. If it is in memory, is there a similar parsing function. Thanks Brian Kaplan From space.captain.face at gmail.com Tue Feb 10 16:46:20 2009 From: space.captain.face at gmail.com (Kalibr) Date: Tue, 10 Feb 2009 13:46:20 -0800 (PST) Subject: Using TK and the canvas. References: <28740c97-58fa-4fa7-9321-28c05d5520b8@n33g2000pri.googlegroups.com> <41c83165-d6ec-429f-ac27-7d103e0d2d2b@u13g2000yqg.googlegroups.com> Message-ID: <06c439f8-e010-4709-9f4d-890977ac7558@w24g2000prd.googlegroups.com> On Feb 11, 5:51?am, r wrote: > On Feb 10, 1:27?pm, Kalibr wrote: > [snip] > > You should really check out wxPython, there is support for just this > type of thing. of course you could do this with Tkinter, but just > thinking about it makes my head hurt :). Alright, I shall investigate. Thank you. From robert.kern at gmail.com Tue Feb 10 16:48:04 2009 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 10 Feb 2009 15:48:04 -0600 Subject: optparse versus getopt In-Reply-To: References: <4991F3DB.5000802@tim.thechases.com> Message-ID: On 2009-02-10 15:42, Matthew Sacks wrote: > it seems as if optparse isn't in my standard library. How did you install your Python? It has been part of the standard library for a very long time. > is there a way to add a lib like ruby gems? http://docs.python.org/install/index.html But optparse (named Optik when it was a separate package) has not been distributed separately from Python for a long time. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From http Tue Feb 10 16:51:58 2009 From: http (Paul Rubin) Date: 10 Feb 2009 13:51:58 -0800 Subject: zlib interface semi-broken References: Message-ID: <7x63jiez9d.fsf@ruckus.brouhaha.com> Travis writes: > However, perhaps this would be a good time to discuss how this library > works; it is somewhat awkward and perhaps there are other changes which > would make it cleaner. > > What does the python community think? It is missing some other features too, like the ability to preload a dictionary. I'd support extending the interface. From bearophileHUGS at lycos.com Tue Feb 10 16:52:11 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Tue, 10 Feb 2009 13:52:11 -0800 (PST) Subject: Functional schmunctional... References: Message-ID: Here a small benchmark: def ip2inet01(a): # can't be used with 6 li = a.split('.') assert len(li) == 4 a = int(li[0])*16777216 b = int(li[1])*65536 c = int(li[2])*256 d = int(li[3]) return a+b+c+d from itertools import count def ip2inet02(a): blocks = a.split('.') assert len(blocks) in (4, 6) return sum(map(lambda (i, n): int(i) * 256**n, zip(reversed (blocks), count(0)))) def ip2inet03(iptxt): bytes = map(int, iptxt.strip().split("."))[::-1] assert len(bytes) in (4, 6) return sum(by * 256**po for po, by in enumerate(bytes)) def ip2inet04(iptxt): bytes = map(int, reversed(iptxt.strip().split("."))) assert len(bytes) in (4, 6) powers256 = [1, 256, 65536, 16777216, 4294967296, 1099511627776] return sum(by * powers256[po] for po, by in enumerate(bytes)) def ip2inet05(iptxt): bytes = (int(by) for by in reversed(iptxt.strip().split("."))) parts = [by * ip2inet05.powers256[po] for po, by in enumerate (bytes)] assert len(parts) in (4, 6) return sum(parts) ip2inet05.powers256 = [1, 256, 65536, 16777216, 4294967296, 1099511627776] def ip2inet06(a): li = a.split('.') n = len(li) assert n == 4 or n == 6 if n == 4: return (int(li[0]) * 16777216 + int(li[1]) * 65536 + int(li[2]) * 256 + int(li[3])) else: return (int(li[0]) * 1099511627776 + int(li[1]) * 4294967296 + int(li[2]) * 16777216 + int(li[3]) * 65536 + int(li[4]) * 256 + int(li[5])) def ip2inet07(iptxt): bytes = map(int, iptxt.strip().split("."))[::-1] assert len(bytes) in (4, 6) return sum(by * ip2inet07.pows[po] for po, by in enumerate(bytes)) ip2inet07.pows = [1, 256, 65536, 16777216, 4294967296, 1099511627776] from struct import pack def ip2inet08(n): # error xs = pack('L', n) return '.'.join(str(ord(x)) for x in xs) def ip2inet09(iptxt): # short and readable bytes = map(int, iptxt.strip().split("."))[::-1] assert len(bytes) in (4, 6) return sum(by << (8*po) for po, by in enumerate(bytes)) def ip2inet10(iptxt): count = 0 result = 0 for byte in iptxt.strip().split("."): result <<= 8 result += int(byte) count += 1 assert count in (4, 6) return result def ip2inet11(iptxt): bytes = iptxt.strip().split(".") assert len(bytes) in (4, 6) result = 0 for byte in bytes: result <<= 8 result += int(byte) return result def ip2inet12(iptxt): bytes = iptxt.strip().split(".") assert len(bytes) in (4, 6) result = 0 for byte in bytes: result = (result << 8) + int(byte) return result def ip2inet13(a): # fastest and readable li = a.split('.') n = len(li) assert n == 4 or n == 6 if n == 4: return ((int(li[0]) << 24) + (int(li[1]) << 16) + (int(li[2]) << 8) + int(li[3])) else: return ((int(li[0]) << 40) + (int(li[1]) << 32) + (int(li[2]) << 24) + (int(li[3]) << 16) + (int(li[4]) << 8) + int(li[5])) def main(): from timeit import default_timer as clock ip4 = "155.16.187.87" ip6 = "7.155.16.187.87.255" algos = [ip2inet02, ip2inet03, ip2inet04, ip2inet05, ip2inet06, ip2inet07, ip2inet09, ip2inet10, ip2inet11, ip2inet12, ip2inet13] for algo in algos: assert algo(ip4) == 2601565015 and algo(ip6) == 8362582038527 t0 = clock() for i in xrange(10000): algo(ip4) algo(ip6) print algo.__name__, round(clock() - t0, 2), "s" import psyco; psyco.full() print "With Psyco:" for algo in algos: t0 = clock() for i in xrange(10000): algo(ip4) algo(ip6) print algo.__name__, round(clock() - t0, 2), "s" main() ip2inet02 2.68 s ip2inet03 1.79 s ip2inet04 1.72 s ip2inet05 1.88 s ip2inet06 0.98 s ip2inet07 1.57 s ip2inet09 1.5 s ip2inet10 1.07 s ip2inet11 1.07 s ip2inet12 1.03 s ip2inet13 0.95 s With Psyco (indipendent run! Not normally successive): ip2inet02 2.66 s ip2inet03 1.66 s ip2inet04 1.97 s ip2inet05 1.66 s ip2inet06 0.57 s ip2inet07 1.5 s ip2inet09 1.54 s ip2inet10 0.53 s ip2inet11 0.76 s ip2inet12 0.52 s ip2inet13 0.8 s So if you need speed you the version #13 is better, if you want short and readable code (but not too much slow) you can use #9, and if you want code easy to understand by every one and easy to translate to other languages then you can use #12. Bye, bearophile From aleksandr.goretoy at gmail.com Tue Feb 10 16:53:26 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Tue, 10 Feb 2009 15:53:26 -0600 Subject: GAE read binary file into db.BlobProperty() In-Reply-To: References: Message-ID: was not able to use open to open a binary file.... so what I did was use urlfetch to fetch the image for me and read the content into BlobProperty() Not sure why it took me so long to figure this out. Hope it helps someone. thx def post(self,key): k=db.get(key) img=images.Image(urlfetch.Fetch("http://www.example.com/ "+k.image).content) img.rotate(90) jpg_data= img.execute_transforms(images.JPEG) k.image_blob=jpg_data k.put() -Alex Goretoy http://www.goretoy.com On Mon, Feb 9, 2009 at 11:07 AM, alex goretoy wrote: > How to read Binary file into GAE(Google App Engine) db.BlobProperty() > datastore? > > -Alex Goretoy > http://www.goretoy.com > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steven at REMOVE.THIS.cybersource.com.au Tue Feb 10 16:57:56 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 10 Feb 2009 21:57:56 GMT Subject: bool evaluations of generators vs lists References: <20090210111514.07e0480a@microvu.com> <1234294770.8528.14.camel@localhost.localdomain> Message-ID: On Tue, 10 Feb 2009 12:50:02 -0800, Josh Dukes wrote: > The thing I don't understand is why a generator that has no iterable > values is different from an empty list. How do you know it has no iterable values until you call next() on it and get StopIteration? By the way, your "has_values" function is just a slower version of the built-in any(). -- Steven From steven at REMOVE.THIS.cybersource.com.au Tue Feb 10 16:58:36 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 10 Feb 2009 21:58:36 GMT Subject: can multi-core improve single funciton? References: <6a4f17690902092228i31fd1661n41c61c4037a289df@mail.gmail.com> Message-ID: On Tue, 10 Feb 2009 12:43:20 +0000, Lie Ryan wrote: > Of course multi-core processor can improve single function using > multiprocessing, as long as the function is parallelizable. The > Fibonacci function is not a parallelizable function though. As I understand it, there's very little benefit to multi-cores in Python due to the GIL. -- Steven. From aioe.org at technicalbloke.com Tue Feb 10 17:00:44 2009 From: aioe.org at technicalbloke.com (r0g) Date: Tue, 10 Feb 2009 17:00:44 -0500 Subject: Replace unknow string varible in file. References: <7ec460c5-b625-47e5-88c9-15156533c7da@t13g2000yqc.googlegroups.com> Message-ID: namire wrote: > Just as a comparison in the Windows OS this seems easy to do when > managing files, say for the file a-blah-b-blah.tmp where blah is an > unknown you can use: del a-*-b-*.tmp to get rid of that file. But for > python and a string in text file I don't have a clue. @_@ could > someone please help me? Hi Namire, The equivalent thing in programming languages is "Regular Expressions", also known as "regex". It's like a small pattern matching sub-language. There quite a lot more to it than the odd "*" so it might take a bit of googling around and study to really understand it but the principle is the same. In python you need to import the 're' module. Have a look at this, the replace method is called 'sub'... http://www.amk.ca/python/howto/regex/regex.html Take your time with it though, it can be confusing until you get used to it and when you're building an expression don't try and do it all at once, start small and build it up a little at a time. Roger Heathcote. From steven at REMOVE.THIS.cybersource.com.au Tue Feb 10 17:01:29 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 10 Feb 2009 22:01:29 GMT Subject: can multi-core improve single funciton? References: <01a12e1d$0$30497$c3e8da3@news.astraweb.com> <01a16bc0$0$20660$c3e8da3@news.astraweb.com> Message-ID: On Tue, 10 Feb 2009 22:41:25 +1000, Gerhard Weis wrote: > btw. the timeings are not that different for the naive recursion in OP's > version and yours. > fib(500) on my machine: > OP's: 0.00116 (far away from millions of years) > This here: 0.000583 I don't believe those timings are credible. On my machine, it took a minute to calculate fib(38), and while my machine isn't exactly the fastest box possible, nor is it especially slow. I don't wish to imply that you are deliberately lying, but your result of 0.00116 seconds for the naive version of fib(500) is so unrealistic in my experience that I believe you must be confused. Perhaps you've timed a less naive fib() but thought it was the naive version. Unless somebody can point out an error in my analysis, I'm sticking to my earlier claim that the naive version of fib(500) requires an unbelievably huge number of function calls: significantly more than the value of fib (500) itself. See my earlier post in this thread for details. -- Steven From tjreedy at udel.edu Tue Feb 10 17:02:44 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 10 Feb 2009 17:02:44 -0500 Subject: generator object or 'send' method? In-Reply-To: References: <929da031-95be-4cda-89ea-560e52435243@e1g2000pra.googlegroups.com> Message-ID: Aaron Brady wrote: > I guess a generator that counts, but skips K numbers, where K can be > varied. For instance, you initialize it with N, the starting number, > and K, the jump size. Then, you can change either one later on. This specification is incomplete as to the timing of when changes to N take effect and when variable K is applied. > This gets two birds with one stone, but is it possible? If you write an iterator class instead of trying to stretch the abbreviated form beyond its intention, and the specification is coherent, it should be trivial. From steven at REMOVE.THIS.cybersource.com.au Tue Feb 10 17:02:57 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 10 Feb 2009 22:02:57 GMT Subject: Scanning a file character by character References: <557daab0-504f-47f4-84a7-e98000e7c3b1@y1g2000pra.googlegroups.com> <203f699b-de30-422a-aa7d-97eb62d6ebba@a12g2000pro.googlegroups.com> Message-ID: On Tue, 10 Feb 2009 12:06:06 +0000, Duncan Booth wrote: > Steven D'Aprano wrote: > >> On Mon, 09 Feb 2009 19:10:28 -0800, Spacebar265 wrote: >> >>> How would I do separate lines into words without scanning one >>> character at a time? >> >> Scan a line at a time, then split each line into words. >> >> >> for line in open('myfile.txt'): >> words = line.split() >> >> >> should work for a particularly simple-minded idea of words. >> > Or for a slightly less simple minded splitting you could try re.split: > >>>> re.split("(\w+)", "The quick brown fox jumps, and falls over.")[1::2] > ['The', 'quick', 'brown', 'fox', 'jumps', 'and', 'falls', 'over'] Perhaps I'm missing something, but the above regex does the exact same thing as line.split() except it is significantly slower and harder to read. Neither deal with quoted text, apostrophes, hyphens, punctuation or any other details of real-world text. That's what I mean by "simple-minded". -- Steven From clp2 at rebertia.com Tue Feb 10 17:05:19 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 10 Feb 2009 14:05:19 -0800 Subject: bool evaluations of generators vs lists In-Reply-To: References: <20090210111514.07e0480a@microvu.com> <1234294770.8528.14.camel@localhost.localdomain> Message-ID: <50697b2c0902101405w70c08991o85fabf5f08dabebf@mail.gmail.com> On Tue, Feb 10, 2009 at 1:57 PM, Steven D'Aprano wrote: > On Tue, 10 Feb 2009 12:50:02 -0800, Josh Dukes wrote: > >> The thing I don't understand is why a generator that has no iterable >> values is different from an empty list. > > How do you know it has no iterable values until you call next() on it and > get StopIteration? > > By the way, your "has_values" function is just a slower version of the > built-in any(). Not quite: if the generator produces one or more elements but those elements happen to be boolean false according to Python, then any() will be false but has_values() will be true. The functions serve different purposes (produces at least 1 value vs. has at least one true value). Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From josh.dukes at microvu.com Tue Feb 10 17:09:48 2009 From: josh.dukes at microvu.com (Josh Dukes) Date: Tue, 10 Feb 2009 14:09:48 -0800 Subject: bool evaluations of generators vs lists In-Reply-To: References: <20090210111514.07e0480a@microvu.com> <1234294770.8528.14.camel@localhost.localdomain> Message-ID: <20090210140948.6a362143@microvu.com> ahhh any! ok, yeah, I guess that's what I was looking for. Thanks. On 10 Feb 2009 21:57:56 GMT Steven D'Aprano wrote: > On Tue, 10 Feb 2009 12:50:02 -0800, Josh Dukes wrote: > > > The thing I don't understand is why a generator that has no iterable > > values is different from an empty list. > > How do you know it has no iterable values until you call next() on it > and get StopIteration? > > By the way, your "has_values" function is just a slower version of > the built-in any(). > > -- Josh Dukes MicroVu IT Department From vinay_sajip at yahoo.co.uk Tue Feb 10 17:21:03 2009 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Tue, 10 Feb 2009 14:21:03 -0800 (PST) Subject: Logging in Python References: <958a7679-6116-44e0-b448-fec34d36c486@v13g2000yqm.googlegroups.com> Message-ID: On Feb 10, 9:38 pm, aha wrote: > Thanks for your suggestions. I've also figured that I can test iflogging.RootLogger.manager.loggerDict has any items in it. Or if it > has a logger for the module that I wish to start. I like basicLogger > idea though as it seems like the cleanest implementation. > It's best not to dig into the implementation details, as these might change across versions of Python. Any of the suggestions that Robert and I made should be able to solve your problem in the right way. Best regards, Vinay Sajip From kp8 at mac.com Tue Feb 10 17:22:35 2009 From: kp8 at mac.com (kpp9c) Date: Tue, 10 Feb 2009 14:22:35 -0800 (PST) Subject: Python Launcher.app on OS X References: <2caa16ad-bc2c-4ade-ba1b-d39103066cbd@33g2000yqm.googlegroups.com> <2C317868-F9B0-4EFA-8FF8-88232C20E301@semanchuk.com> Message-ID: <3e505dfe-7df5-4ace-87c8-1eab7d451ea7@u13g2000yqg.googlegroups.com> So how does this effect the install instructions found on the link: http://wiki.python.org/moin/MacPython/Leopard do you trash that when you do an install on OS X? I am so hesitant to delete anything that resides in /System From steven at REMOVE.THIS.cybersource.com.au Tue Feb 10 17:26:39 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 10 Feb 2009 22:26:39 GMT Subject: can multi-core improve single funciton? References: <01a12e1d$0$30497$c3e8da3@news.astraweb.com> <2d09213e-8095-43d2-a067-6c2b301fa41a@x9g2000yqk.googlegroups.com> Message-ID: On Tue, 10 Feb 2009 02:05:35 -0800, Niklas Norrthon wrote: > According to the common definition of fibonacci numbers fib(0) = 0, fib > (1) = 1 and fib(n) = fib(n-1) + fib(n-2) for n > 1. So the number above > is fib(501). So it is. Oops, off by one error! Or, if you prefer, it's the right algorithm for a Lucas sequence with first two values 1 and 1 instead of 0 and 1. :) >>>> timeit.Timer('fib(500)', 'from __main__ import fib').timeit(1) >> >> 0.00083398818969726562 > > And now for my version (which admitedly isn't really mine, and returns > slightly incorrect fib(n) for large values of n, due to the limited > floating point precision). The floating point version is nice, but it starts giving incorrect answers relatively early, from n=71. But if you don't need accurate results (a relative error of 3e-15 for n=71), it is very fast. -- Steven From tjreedy at udel.edu Tue Feb 10 17:29:23 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 10 Feb 2009 17:29:23 -0500 Subject: bool evaluations of generators vs lists In-Reply-To: <20090210125002.1f6d8597@microvu.com> References: <20090210111514.07e0480a@microvu.com> <1234294770.8528.14.camel@localhost.localdomain> <20090210125002.1f6d8597@microvu.com> Message-ID: Josh Dukes wrote: > > I was actually aware of that (thank you, though, for trying to help). > What I was not clear on was if the boolean evaluation is a method of an > object that can be modified via operatior overloading (in the same way > + is actually .__add__()) or not. Clearly __nonzero__ is the operator I > was curious about. Thanks for that info. .__bool__ in 3.0. > The thing I don't understand is why a generator that has no iterable > values is different from an empty list. Why shouldn't bool == > has_value?? Technically a list, a tuple, and a string are also objects > but if they lack values they're evaluated as False. It seems to me that > a generator is an object that intends to replace lists where lazy > evaluation would be more efficent. Here is one place where that's > definitely true. Generator functions are abbreviated iterator classes. If you want iterators with more functionality, write an iterator class. In particular, you can add a .__bool__ method for empty or not or even a .__len__ method if you can accurately calculate the number of items remaining. > The main reason I'm interested in this is that it improves performance > immensely over boolean evaluation of large lists (as the attached code > shows). It seems to me if I could use find a good use for it in my > experimentation that someone else might also want to do the same thing > in real-world code. Terry Jan Reedy From tdelaney at avaya.com Tue Feb 10 17:31:33 2009 From: tdelaney at avaya.com (Delaney, Timothy (Tim)) Date: Wed, 11 Feb 2009 06:31:33 +0800 Subject: Python binaries with VC++ 8.0? In-Reply-To: <1732ba01-6096-4d38-a09d-fe1fbe75b435@l1g2000yqj.googlegroups.com> Message-ID: bearophileHUGS at lycos.com wrote: > Paul Rubin: >> Gideon Smeding of the University of >> Utrecht has written a masters' thesis titled "An executable >> operational semantics for Python". > > A significant part of Computer Science is a waste of time and money. The same can be said for any research. Can you predict ahead of time which research will be useful, and which won't? If so (and you can prove it) why aren't you making unbelievable amounts of money? Tim Delaney From gweis at gmx.at Tue Feb 10 17:31:46 2009 From: gweis at gmx.at (Gerhard Weis) Date: Wed, 11 Feb 2009 08:31:46 +1000 Subject: can multi-core improve single funciton? References: <01a12e1d$0$30497$c3e8da3@news.astraweb.com> <01a16bc0$0$20660$c3e8da3@news.astraweb.com> Message-ID: <01a1f61a$0$21875$c3e8da3@news.astraweb.com> On 2009-02-11 08:01:29 +1000, Steven D'Aprano said: > On Tue, 10 Feb 2009 22:41:25 +1000, Gerhard Weis wrote: > >> btw. the timeings are not that different for the naive recursion in OP's >> version and yours. >> fib(500) on my machine: >> OP's: 0.00116 (far away from millions of years) >> This here: 0.000583 > > I don't believe those timings are credible. On my machine, it took a > minute to calculate fib(38), and while my machine isn't exactly the > fastest box possible, nor is it especially slow. > > I don't wish to imply that you are deliberately lying, but your result of > 0.00116 seconds for the naive version of fib(500) is so unrealistic in my > experience that I believe you must be confused. Perhaps you've timed a > less naive fib() but thought it was the naive version. > > Unless somebody can point out an error in my analysis, I'm sticking to my > earlier claim that the naive version of fib(500) requires an unbelievably > huge number of function calls: significantly more than the value of fib > (500) itself. See my earlier post in this thread for details. I am sorry for the wrong timing, I mixed up the function names. The naive version used partly your version and partly the naive recursion. So less naive is a good description :) after fixing it: naive fib(38): ~40seconds From tjreedy at udel.edu Tue Feb 10 17:33:06 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 10 Feb 2009 17:33:06 -0500 Subject: Working with propositional formulae in Python In-Reply-To: <28749c0e0902101146i4bc3e69ds898ebe8527f904b8@mail.gmail.com> References: <28749c0e0902101146i4bc3e69ds898ebe8527f904b8@mail.gmail.com> Message-ID: nnp wrote: > Hey, > > I'm currently working with propositional boolean formulae of the type > 'A & (b -> c)' (for example). I was wondering if anybody knows of a > Python library to create parse trees and convert such formulae to > conjunctive, disjunctive and Tseitin normal forms? You would probably do better with Google. "Python conjunctive normal form" gave some potentially interesting hits. From Scott.Daniels at Acm.Org Tue Feb 10 17:33:35 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 10 Feb 2009 14:33:35 -0800 Subject: zlib interface semi-broken In-Reply-To: <7x63jiez9d.fsf@ruckus.brouhaha.com> References: <7x63jiez9d.fsf@ruckus.brouhaha.com> Message-ID: <8K6dneXdHIranQ_UnZ2dnUVZ_u2dnZ2d@pdx.net> Paul Rubin wrote: > Travis writes: >> However, perhaps this would be a good time to discuss how [zlib] works... > It is missing some other features too, like the ability to preload > a dictionary. I'd support extending the interface. The trick to defining a preload interface is avoiding creating a brittle interface -- the saved preload should be usable across machines and versions. I suspect that is why such an interface never came up (If you can clone states, then you can say: "compress this, then use the resultant state to compress/decompress others." Suddenly there is no nasty problem guessing what to parameterize and what to fix in stone. --Scott David Daniels Scott.Daniels at Acm.Org From google at mrabarnett.plus.com Tue Feb 10 17:39:48 2009 From: google at mrabarnett.plus.com (MRAB) Date: Tue, 10 Feb 2009 22:39:48 +0000 Subject: pySerial help please! In-Reply-To: References: Message-ID: <49920234.90009@mrabarnett.plus.com> bmaschino at gmail.com wrote: > Hello all, > > I am very new to Python and I am using it because I needed an easy > language to control a piece of equipment that connects to my computer > via a serial cable. I am running Python 2.6 with pySerial 2.4 under > Windows. I can get Python to create a serial port on COM1, but when I > try to write to the device, nothing happens. Here is an example: > > import serial > ser = serial.Serial(0) > ser.write("otpm 2 16 0") > ser.close() > > If I connect to the device in Hyperterminal the device will behave as > expected when I give it the command 'otpm 2 16 0' but not in Python. I > have confirmed Python is actually controlling the port because > Hyperterminal will not open the port while Python has it open, > although I have not been able to try a loopback connector as of yet. > Any suggestions out there? Thanks in advance! > Have you checked that the baud rate, parity, etc, are the same as in Hyperterminal? From deets at nospam.web.de Tue Feb 10 17:41:09 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 10 Feb 2009 23:41:09 +0100 Subject: pySerial help please! In-Reply-To: References: Message-ID: <6vee48FjmnodU1@mid.uni-berlin.de> bmaschino at gmail.com schrieb: > Hello all, > > I am very new to Python and I am using it because I needed an easy > language to control a piece of equipment that connects to my computer > via a serial cable. I am running Python 2.6 with pySerial 2.4 under > Windows. I can get Python to create a serial port on COM1, but when I > try to write to the device, nothing happens. Here is an example: > > import serial > ser = serial.Serial(0) > ser.write("otpm 2 16 0") > ser.close() > > If I connect to the device in Hyperterminal the device will behave as > expected when I give it the command 'otpm 2 16 0' but not in Python. I > have confirmed Python is actually controlling the port because > Hyperterminal will not open the port while Python has it open, > although I have not been able to try a loopback connector as of yet. > Any suggestions out there? Thanks in advance! You need to give a newline, you press return on the terminal as well, don't you? Diez From python.list at tim.thechases.com Tue Feb 10 17:46:30 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 10 Feb 2009 16:46:30 -0600 Subject: Scanning a file character by character In-Reply-To: References: <557daab0-504f-47f4-84a7-e98000e7c3b1@y1g2000pra.googlegroups.com> <203f699b-de30-422a-aa7d-97eb62d6ebba@a12g2000pro.googlegroups.com> Message-ID: <499203C6.9070501@tim.thechases.com> >> Or for a slightly less simple minded splitting you could try re.split: >> >>>>> re.split("(\w+)", "The quick brown fox jumps, and falls over.")[1::2] >> ['The', 'quick', 'brown', 'fox', 'jumps', 'and', 'falls', 'over'] > > > Perhaps I'm missing something, but the above regex does the exact same > thing as line.split() except it is significantly slower and harder to > read. > > Neither deal with quoted text, apostrophes, hyphens, punctuation or any > other details of real-world text. That's what I mean by "simple-minded". >>> s = "The quick brown fox jumps, and falls over." >>> import re >>> re.split(r"(\w+)", s)[1::2] ['The', 'quick', 'brown', 'fox', 'jumps', 'and', 'falls', 'over'] >>> s.split() ['The', 'quick', 'brown', 'fox', 'jumps,', 'and', 'falls', 'over.'] Note the difference in "jumps" vs. "jumps," (extra comma in the string.split() version) and likewise the period after "over". Thus not quite "the exact same thing as line.split()". I think an easier-to-read variant would be >>> re.findall(r"\w+", s) ['The', 'quick', 'brown', 'fox', 'jumps', 'and', 'falls', 'over'] which just finds words. One could also just limit it to letters with re.findall("[a-zA-Z]", s) as "\w" is a little more encompassing (letters and underscores) if that's a problem. -tkc From rhodri at wildebst.demon.co.uk Tue Feb 10 17:47:07 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 10 Feb 2009 22:47:07 -0000 Subject: Scanning a file character by character In-Reply-To: References: <557daab0-504f-47f4-84a7-e98000e7c3b1@y1g2000pra.googlegroups.com> <203f699b-de30-422a-aa7d-97eb62d6ebba@a12g2000pro.googlegroups.com> Message-ID: On Tue, 10 Feb 2009 22:02:57 -0000, Steven D'Aprano wrote: > On Tue, 10 Feb 2009 12:06:06 +0000, Duncan Booth wrote: > >> Steven D'Aprano wrote: >> >>> On Mon, 09 Feb 2009 19:10:28 -0800, Spacebar265 wrote: >>> >>>> How would I do separate lines into words without scanning one >>>> character at a time? >>> >>> Scan a line at a time, then split each line into words. >>> >>> >>> for line in open('myfile.txt'): >>> words = line.split() >>> >>> >>> should work for a particularly simple-minded idea of words. >>> >> Or for a slightly less simple minded splitting you could try re.split: >> >>>>> re.split("(\w+)", "The quick brown fox jumps, and falls over.")[1::2] >> ['The', 'quick', 'brown', 'fox', 'jumps', 'and', 'falls', 'over'] > > > Perhaps I'm missing something, but the above regex does the exact same > thing as line.split() except it is significantly slower and harder to > read. > > Neither deal with quoted text, apostrophes, hyphens, punctuation or any > other details of real-world text. That's what I mean by "simple-minded". You're missing something :-) Specifically, the punctuation gets swept up with the whitespace, and the extended slice skips it. Apostrophes (and possibly hyphenation) are still a bit moot, though. -- Rhodri James *-* Wildebeeste Herder to the Masses From tjreedy at udel.edu Tue Feb 10 17:57:54 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 10 Feb 2009 17:57:54 -0500 Subject: Functional schmunctional... In-Reply-To: References: Message-ID: r0g wrote: > > def inet2ip(n): > p = (n/16777216) > q = ((n-(p*16777216))/65536) > r = ((n-((p*16777216)+(q*65536)))/256) > s = ((n-((p*16777216)+(q*65536)+(r*256)))) > return str(p)+"."+str(q)+"."+str(r)+"."+str(s) Beyond what other wrote: To future-proof code, use // instead of / for integer division. To get both quotient and remainder, use divmod(num,den) For future reading (and generalization) documenting magic constants helps. In 3.0: def inet2ip(n): p = (n//16777216) q = ((n-(p*16777216))//65536) r = ((n-((p*16777216)+(q*65536)))//256) s = ((n-((p*16777216)+(q*65536)+(r*256)))) return str(p)+"."+str(q)+"."+str(r)+"."+str(s) def inet2ip2(n): p,n=divmod(n,16777216) # 1<<24 q,n=divmod(n,65536) # 1<<16 r,s=divmod(n,256) # 1<<8 return str(p)+"."+str(q)+"."+str(r)+"."+str(s) print(inet2ip(1000000000), inet2ip2(1000000000)) >>> 59.154.202.0 59.154.202.0 From paul at boddie.org.uk Tue Feb 10 17:59:35 2009 From: paul at boddie.org.uk (Paul Boddie) Date: Tue, 10 Feb 2009 14:59:35 -0800 (PST) Subject: "Super()" confusion References: Message-ID: On 10 Feb, 20:45, Jean-Paul Calderone wrote: > > It replaces one kind of repetition with another. I think each kind is > about as unpleasant. Has anyone gathered any data on the frequency of > changes of base classes as compared to the frequency of classes being > renamed? I don't think either happens very often, but it might be > interesting to see some numbers. Base class changes are less important than common derived class functionality. For example, I have employed the following style of class hierarchy in at least one system: class ResourceUsingClass: """ Stuff using some resource, like a file. Should we close the file when we're finished with it? Is that rude? Best not do it! """ def close(self): pass # Don't close anything! class SelfContainedResourceUsingClass(ResourceUsingClass): """ We don't care about keeping the resource open in this class. The user of the class should just need to call the close method. """ def close(self): ResourceUsingClass.close(self) # Now close the resource! I know that there would be other ways of solving this problem, but in this case, for every class we want to subclass and provide such functionality, we need to write a specific close method. With super, we can avoid being specific about the superclass, but we still need to write the method unless we define it in a mix-in which appears before the superclass in the method resolution order. I think this is the only real use I've found for super, mostly because, as you say, in most other situations it doesn't actually save anyone very much effort. Paul From tjreedy at udel.edu Tue Feb 10 18:03:35 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 10 Feb 2009 18:03:35 -0500 Subject: Replace unknow string varible in file. In-Reply-To: <7ec460c5-b625-47e5-88c9-15156533c7da@t13g2000yqc.googlegroups.com> References: <7ec460c5-b625-47e5-88c9-15156533c7da@t13g2000yqc.googlegroups.com> Message-ID: namire wrote: > Hey .python first time poster here. I'm pretty good with python so > far, but I keep needed a function in my program but not knowing how to > build it. =( Here's the problem: > > Imagine a html file full of 100's of these strings all mooshed > together onto many lines; > ITEM
> Where the word 'MARKER' is a constant, it stay the same in each string > and the word 'ITEM' is a random combination of ascii characters of an > unknown length. So for example a: > CATFISH

Text text text h1>SPAM
and so on... > > What I need to do it replace each instance of the random letter with a > constant and/or delete them. The file is a html file so the stuff > inside of is ok to keep I cannot understand what you want to do where. The last phrase implies 'leave the comments alone' but you only talked about random letters within the comments. I suggest a minimal but complete example of possible input and desired output. > and I need that data to identify > where the strings are in the file (it's full of other stuff too). I'm > tired making a bruteforcer but with unknown length and 26 letters of > the alphabet I gave up because it would take too long (it was > something like; read file; if '@@MARKER@@; id="'+str(gen_string)+'"-- >> "+sr(gen_string)+'
' in file then replace with '', but I'm > paraphrasing code and it's not the best solution anyway). > > Just as a comparison in the Windows OS this seems easy to do when > managing files, say for the file a-blah-b-blah.tmp where blah is an > unknown you can use: del a-*-b-*.tmp to get rid of that file. But for > python and a string in text file I don't have a clue. @_@ could > someone please help me? > -- > http://mail.python.org/mailman/listinfo/python-list > From steven at REMOVE.THIS.cybersource.com.au Tue Feb 10 18:11:10 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 10 Feb 2009 23:11:10 GMT Subject: Scanning a file character by character References: <557daab0-504f-47f4-84a7-e98000e7c3b1@y1g2000pra.googlegroups.com> <203f699b-de30-422a-aa7d-97eb62d6ebba@a12g2000pro.googlegroups.com> Message-ID: On Tue, 10 Feb 2009 16:46:30 -0600, Tim Chase wrote: >>> Or for a slightly less simple minded splitting you could try re.split: >>> >>>>>> re.split("(\w+)", "The quick brown fox jumps, and falls >>>>>> over.")[1::2] >>> ['The', 'quick', 'brown', 'fox', 'jumps', 'and', 'falls', 'over'] >> >> >> Perhaps I'm missing something, but the above regex does the exact same >> thing as line.split() except it is significantly slower and harder to >> read. ... > Note the difference in "jumps" vs. "jumps," (extra comma in the > string.split() version) and likewise the period after "over". Thus not > quite "the exact same thing as line.split()". Um... yes. I'll just slink away quietly now... nothing to see here... -- Steven From travis+ml-python at subspacefield.org Tue Feb 10 18:12:15 2009 From: travis+ml-python at subspacefield.org (Travis) Date: Tue, 10 Feb 2009 17:12:15 -0600 Subject: zlib interface semi-broken In-Reply-To: References: Message-ID: <20090210231215.GU6522@subspacefield.org> On Tue, Feb 10, 2009 at 01:36:21PM -0800, Scott David Daniels wrote: > >A simple way to fix this would be to add a finished attribute to the > >Decompress object. > Perhaps you could submit a patch with such a change? Yes, I will try and get to that this week. > >However, perhaps this would be a good time to discuss how this library > >works; it is somewhat awkward and perhaps there are other changes which > >would make it cleaner. > Well, it might be improvable, I haven't really looked. I personally > would like it and bz2 to get closer to each other in interface, rather > than to spread out. SO if you are really opening up a can of worms, > I vote for two cans. Well, I like this idea; perhaps this is a good time to discuss the equivalent of some "abstract base classes", or "interfaces", for compression. As I see it, the fundamental abstractions are the stream-oriented de/compression routines. Given those, one should easily be able to implement one-shot de/compression of strings. In fact, that is the way that zlib is implemented; the base functions are the stream-oriented ones and there is a layer on top of convenience functions that do one-shot compression and decompression. After examining the bz2 module, I notice that it has a file-like interface called bz2file, which is roughly analogous to the gzip module. That file interface could form a third API, and basically conform to what python expects of files. So what I suggest is a common framework of three APIs; a sequential compression/decompression API for streams, a layer (potentially generic) on top of those for strings/buffers, and a third API for file-like access. Presumably the file-like access can be implemented on top of the sequential API as well. If the sequential de/compression routines are indeed primitive, and sufficient for the implementation of the other two APIs, then that gives us the option of implementing the other "upper" two layers in pure python, potentially simplifying the amount of extension code that has to be written. I see that as desirable, since it gives us options for writing the upper two layers; in pure python, or by writing extensions to the C code where available. I seem to recall a number of ancilliary functions in zlib, such as those for loading a compression dictionary. There are also options such as flushing the compression in order to be able to resynchronize should part of the archive become garbled. Where these functions are available, they could be implemented, though it would be desirable to give them the same name in each module to allow client code to test for their existence in a compression-agnostic way. For what it's worth, I would rather see a pythonic interface to the libraries than a simple-as-can-be wrapper around the C functions. I personally find it annoying to have to drop down to non-OOP styles in a python program in order to use a C library. It doesn't matter to me whether the OOP layer is added atop the C library in pure python or in the C-to-python binding; that is an implementation detail to me, and I suspect to most python programmers. They don't care, they just want it easy to use from python. If performance turns out to matter, and the underlying compression library supports an "upper layer" in C, then we have the option for using that code. So my suggestion is that we (the python users) brainstorm on how we want the API to look, and not focus on the underlying library except insofar as it informs our discussion of the proper APIs - for example, features such as flushing state, setting compression levels/windows, or for resynchronization points. My further suggestion is that we start with the sequential de/compression, since it seems like a fundamental primitive. De/compressing strings will be trivial, and the file-like interface is already described by Python. So my first suggestion on the stream de/compression API thread is: The sequential de/compression needs to be capable of returning more than just the de/compressed data. It should at least be capable of returning end-of-stream conditions and possibly other states as well. I see a few ways of implementing this: 1) The de/compression object holds state in various members such as data input buffers, data output buffers, and a state for indicating states such as synchronization points or end-of-stream states. Member functions are called and primarily manipulate the data members of the object. 2) The de/compression object has routines for reading de/compressed data and states such as end-of-stream or resynchronization points as exceptions, much like the file class can throw EOFError. My problem with this is that client code has to be cognizant of the possible exceptions that might be thrown, and so one cannot easily add new exceptions should the need arise. For example, if we add an exception to indicate a possible resynchronization point, client code may not be capable of handling it as a non-fatal exception. Thoughts? -- Crypto ergo sum. http://www.subspacefield.org/~travis/ Do unto other faiths as you would have them do unto yours. If you are a spammer, please email john at subspacefield.org to get blacklisted. From google at mrabarnett.plus.com Tue Feb 10 18:20:05 2009 From: google at mrabarnett.plus.com (MRAB) Date: Tue, 10 Feb 2009 23:20:05 +0000 Subject: Scanning a file character by character In-Reply-To: References: <557daab0-504f-47f4-84a7-e98000e7c3b1@y1g2000pra.googlegroups.com> <203f699b-de30-422a-aa7d-97eb62d6ebba@a12g2000pro.googlegroups.com> Message-ID: <49920BA5.5010008@mrabarnett.plus.com> Steven D'Aprano wrote: > On Tue, 10 Feb 2009 16:46:30 -0600, Tim Chase wrote: > >>>> Or for a slightly less simple minded splitting you could try re.split: >>>> >>>>>>> re.split("(\w+)", "The quick brown fox jumps, and falls >>>>>>> over.")[1::2] >>>> ['The', 'quick', 'brown', 'fox', 'jumps', 'and', 'falls', 'over'] >>> >>> Perhaps I'm missing something, but the above regex does the exact same >>> thing as line.split() except it is significantly slower and harder to >>> read. > > ... > >> Note the difference in "jumps" vs. "jumps," (extra comma in the >> string.split() version) and likewise the period after "over". Thus not >> quite "the exact same thing as line.split()". > > Um... yes. I'll just slink away quietly now... nothing to see here... > You could've used str.translate to strip out the unwanted characters. From dchandran1 at tinkercell.com Tue Feb 10 18:21:57 2009 From: dchandran1 at tinkercell.com (Deepak Chandran) Date: Tue, 10 Feb 2009 15:21:57 -0800 Subject: embedding Python in a shared library Message-ID: <5dfe78f40902101521o443684fdje8450f19ed881060@mail.gmail.com> I have embedded Python in a shared library. This works fine in Windows (dll), but I get the following error is Ubuntu when I try to load modules: /usr/lib/python2.5/lib-dynload/*time.so*: error: symbol lookup error: * undefined* symbol: PyExc_ValueError I found many postings on this issue on the internet, but I was not able to find a solution that worked. I tried to load libpython2.5.so.1 into my program using dlopen, but that crashed the program for some reason. I tried building my library using the libpython2.5.a, but the same error was there. I am sure someone has a solution to this, since it seems like a general issue. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ntwrkd at gmail.com Tue Feb 10 18:32:28 2009 From: ntwrkd at gmail.com (Matthew Sacks) Date: Tue, 10 Feb 2009 15:32:28 -0800 Subject: optparse versus getopt In-Reply-To: References: <4991F3DB.5000802@tim.thechases.com> Message-ID: its a debian package. 2.5 importing optparse works with interactive python, but not through the jython interpreter i an using. is there some way i can force the import based on the the absolute path to the module? On Tue, Feb 10, 2009 at 1:48 PM, Robert Kern wrote: > On 2009-02-10 15:42, Matthew Sacks wrote: >> >> it seems as if optparse isn't in my standard library. > > How did you install your Python? It has been part of the standard library > for a very long time. > >> is there a way to add a lib like ruby gems? > > http://docs.python.org/install/index.html > > But optparse (named Optik when it was a separate package) has not been > distributed separately from Python for a long time. > > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless enigma > that is made terrible by our own mad attempt to interpret it as though it > had > an underlying truth." > -- Umberto Eco > > -- > http://mail.python.org/mailman/listinfo/python-list > From aioe.org at technicalbloke.com Tue Feb 10 18:38:20 2009 From: aioe.org at technicalbloke.com (r0g) Date: Tue, 10 Feb 2009 18:38:20 -0500 Subject: Functional schmunctional... References: Message-ID: bearophileHUGS at lycos.com wrote: > Here a small benchmark: > > def ip2inet01(a): # can't be used with 6 > li = a.split('.') Wow, thanks everybody for all the suggestions, v.interesting esp as I didn't even ask for any suggestions! This is a fantastically didactic newsgroup: you start off just musing about functional programming, you end up learning python has a rich set of augmented assignment operators, brilliant :-) Roger Heathcote. From robert.kern at gmail.com Tue Feb 10 18:39:48 2009 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 10 Feb 2009 17:39:48 -0600 Subject: optparse versus getopt In-Reply-To: References: <4991F3DB.5000802@tim.thechases.com> Message-ID: On 2009-02-10 17:32, Matthew Sacks wrote: > its a debian package. 2.5 > > importing optparse works with interactive python, but not through the > jython interpreter i an using. Ah, yes. The current version of Jython is still based off of Python 2.2 whereas optparse was introduced in Python 2.3. > is there some way i can force the import based on the the absolute > path to the module? Better would be for you to copy the optparse.py module onto your Jython's import path. I'm not particularly familiar with the details of Jython, so you will need to consult with the Jython documentation unless if a Jython expert can jump in here. Here is one message describing this procedure: http://osdir.com/ml/lang.jython.user/2004-01/msg00086.html You may want to ask Jython specific questions on the Jython mailing list. You will probably get more on-target answers faster there. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From http Tue Feb 10 18:51:08 2009 From: http (Paul Rubin) Date: 10 Feb 2009 15:51:08 -0800 Subject: zlib interface semi-broken References: <7x63jiez9d.fsf@ruckus.brouhaha.com> <8K6dneXdHIranQ_UnZ2dnUVZ_u2dnZ2d@pdx.net> Message-ID: <7xd4dpsvf7.fsf@ruckus.brouhaha.com> Scott David Daniels writes: > I suspect that is why such an interface never came up (If > you can clone states, then you can say: "compress this, then use the > resultant state to compress/decompress others." The zlib C interface supports something like that. It is just not exported to the python application. It should be. From aioe.org at technicalbloke.com Tue Feb 10 18:55:17 2009 From: aioe.org at technicalbloke.com (r0g) Date: Tue, 10 Feb 2009 18:55:17 -0500 Subject: Escaping my own chroot... Message-ID: I'm writing a linux remastering script in python where I need to chroot into a folder, run some system commands and then come out and do some tidying up, un-mounting proc & sys etc. I got in there with os.chroot() and I tried using that to get back out but that didn't work so... is my script trapped in there forever now or is there an un-hacky way to escape? If it is an OS restriction rather than my ignorance of python is there a canonical way of dealing with it? Should I maybe fork a process, have it do the chroot and wait for it to terminate before continuing? Apologies if this turn out to be OT! Roger. From bmaschino at gmail.com Tue Feb 10 19:02:40 2009 From: bmaschino at gmail.com (bmaschino at gmail.com) Date: Tue, 10 Feb 2009 16:02:40 -0800 (PST) Subject: pySerial help please! References: <6vee48FjmnodU1@mid.uni-berlin.de> Message-ID: <047322d9-9311-42b8-a1cf-f17830606e27@s20g2000yqh.googlegroups.com> On Feb 10, 5:41?pm, "Diez B. Roggisch" wrote: > bmasch... at gmail.com schrieb: > > > > > > > Hello all, > > > I am very new to Python and I am using it because I needed an easy > > language to control a piece of equipment that connects to my computer > > via a serial cable. I am running Python 2.6 with pySerial 2.4 under > > Windows. I can get Python to create a serial port on COM1, but when I > > try to write to the device, nothing happens. Here is an example: > > > import serial > > ser = serial.Serial(0) > > ser.write("otpm 2 16 0") > > ser.close() > > > If I connect to the device in Hyperterminal the device will behave as > > expected when I give it the command 'otpm 2 16 0' but not in Python. I > > have confirmed Python is actually controlling the port because > > Hyperterminal will not open the port while Python has it open, > > although I have not been able to try a loopback connector as of yet. > > Any suggestions out there? Thanks in advance! > > You need to give a newline, you press return on the terminal as well, > don't you? > > Diez- Hide quoted text - > > - Show quoted text - Yes! That was exactly the problem. I replaced ser.write("otpm x x x") to ("otpm x x x\n") and it WORKS!! Thank you! From aahz at pythoncraft.com Tue Feb 10 19:08:20 2009 From: aahz at pythoncraft.com (Aahz) Date: 10 Feb 2009 16:08:20 -0800 Subject: re.sub and named groups References: <4c7158d2-5663-46b9-b950-be81bd79964c@z6g2000pre.googlegroups.com> Message-ID: In article <4c7158d2-5663-46b9-b950-be81bd79964c at z6g2000pre.googlegroups.com>, Emanuele D'Arrigo wrote: > >I'm having a ball with the power of regular expression but I stumbled >on something I don't quite understand: Book recommendation: _Mastering Regular Expressions_, Jeffrey Friedl -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From gagsl-py2 at yahoo.com.ar Tue Feb 10 19:28:46 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 10 Feb 2009 22:28:46 -0200 Subject: "Super()" confusion References: <20090210012739.12853.653428988.divmod.quotient.8083@henry.divmod.com> Message-ID: En Tue, 10 Feb 2009 18:01:53 -0200, Daniel Fetchinson escribi?: > On 2/9/09, Gabriel Genellina wrote: >> En Mon, 09 Feb 2009 23:34:05 -0200, Daniel Fetchinson >> escribi?: >> >>>>>> Consider whether you really need to use super(). >>>>>> http://fuhm.net/super-harmful/ >>> >>> Because throwing around that link carries about the same amount of >>> information as "perl is better than python", "my IDE is better than >>> yours", "vim rulez!", "emacs is cooler than vim", etc, etc. >> >> Not at all. It contains accurate and valuable information that isn't >> available elsewhere. > > But does not contain other valuable information which would demystify > super. If only this source is shown to a person who wants to learn the > proper usage of super, the impression he/she gets will be distorted. Why so? At the end there is a "best practices" recipe that pretty much summarizes the proper usage of super, and AFAIK it's the right way to use it. Don't you agree with any of the conclusions? > Example: 1. somebody asks about threading 2. reply comes: there is a > GIL! you can't do real threading. Now this reply might be technically > more-or-less correct, it is misleading and does not help the poster. > An informed discussion of the various solutions that does not involve > a rant about the GIL would be very useful though. As I said, the article presents a "recipe" for super() usage, and I'd consider it very helpful. It's far from just saying "super s*cks!", or "the GIL s*cks!" or something like that. > You might want to start with > > http://www.artima.com/weblogs/viewpost.jsp?thread=236275 ...which, although the author says it was written a long time ago, was not published until less than six months ago, and has very low visibility. > You are right, it's not in the documentation. But if somebody asks on > c.l.p the appropriate answer, I think, is to point to information such > as the one above, and not the misleading "harmful" essay. According to Google, nobody has menctioned the "harmful" essay in this group since April 2008 [1], months before Simionato's article were available... So this is the *first* time the reference to the former essay could have been replaced by M.S.' one... don't be so strict! Anyway, the right thing to do, IMHO, is to publish correct and accurate documentation in the main Python site. Not everybody knows about this group existence, nor has the time/experience/interest on subscribe here, post a question and wait for an answer. I've seen some posts in python-dev saying something like "this is confusing, we should evangelize people on c.l.p. on the right way to do it" and I completely disagree; the right place for such things is the product documentation, or -to a much lesser degree because it's online only- some article collection linked from the main site (like the "Other resources" left bar, already present). >>> Honestly, I don't understand how this thing got so much out of >>> control. If anyone starts an intelligent question or remark about >>> super, this essay is thrown in no matter what. Anyone can explain why? >> >> Because for a very loooooong time (seven years, 2001-2008) super was >> almost undocumented. The Library Reference -before release 2.6- only >> had a short paragraph, the [...] > > You are right, the documentation needs some work in this regard. But > again, just because some sources are not in the documentation doesn't > mean that the most opinionated essay is the best source. A little > search turns up much more useful ones. (not according to Google [2]: I get the "harmful" article in the top, the thread in python-dev, a couple threads in c.l.p including posts by M.S., his article in artima, and nothing more relevant than "Monty Python Super Star" up to the 3rd page) *Now* that *I* am aware of the recent article series by M.S., the next time someone asks *me* about super(), probably I'll refer her to both M.S. and J.K.'s articles. Last time I checked (perhaps one or two years ago), the "harmful" article was almost the only relevant source of info about super(). [1] http://groups.google.com/group/comp.lang.python/search?q=super+harmful&start=0&scoring=d& [2] http://www.google.com/search?q=python+super -- Gabriel Genellina From evanstimk at gmail.com Tue Feb 10 19:56:43 2009 From: evanstimk at gmail.com (tkevans) Date: Tue, 10 Feb 2009 16:56:43 -0800 (PST) Subject: relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC Message-ID: <74d2b9c1-be68-4585-bb92-36815ca2b759@w35g2000yqm.googlegroups.com> Found a couple of references to this in the newsgroup, but no solutions. I'm trying to build libsbml-3.3.0 with python 2.5.4 support on RHEL 5.3. This RedHat distro has python 2.4.5, and libsbml builds ok with that release. After building 2.5.4 (./configure CFLAGS=-fPIC , as the error message suggests), ld still croaks here: g++ -L../../ -L/usr/local/lib/python2.5/config -shared -o _libsbml.so libsbml_wrap.o -lsbml -lpython2.5 -lxml2 -lz -lm -lm -lz -lbz2 /usr/bin/ld: /usr/local/lib/python2.5/config/libpython2.5.a (abstract.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC /usr/local/lib/python2.5/config/libpython2.5.a: could not read symbols: Bad value collect2: ld returned 1 exit status Help appreciated From noama at answers.com Tue Feb 10 20:02:00 2009 From: noama at answers.com (Noam Aigerman) Date: Wed, 11 Feb 2009 03:02:00 +0200 Subject: Propagating function calls Message-ID: <749CACF29BDFB64E9F80189ECD77868804C01024@jermail1.atomant.net> Suppose I have a python object X, which holds inside it a python object Y. How can I propagate each function call to X so the same function call in Y will be called, i.e: X.doThatFunkyFunk() Would cause Y.doThatFunkyFunk() Thanks, Noam -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Tue Feb 10 20:03:41 2009 From: python at bdurham.com (python at bdurham.com) Date: Tue, 10 Feb 2009 20:03:41 -0500 Subject: Functional schmunctional... In-Reply-To: References: Message-ID: <1234314221.16319.1299684607@webmail.messagingengine.com> > This is a fantastically didactic newsgroup: you start off just musing about , you end up learning python has , brilliant :-) +1 !! Malcolm From clp2 at rebertia.com Tue Feb 10 20:10:40 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 10 Feb 2009 17:10:40 -0800 Subject: Propagating function calls In-Reply-To: <749CACF29BDFB64E9F80189ECD77868804C01024@jermail1.atomant.net> References: <749CACF29BDFB64E9F80189ECD77868804C01024@jermail1.atomant.net> Message-ID: <50697b2c0902101710t54130e57h3c2472ab9d57999b@mail.gmail.com> On Tue, Feb 10, 2009 at 5:02 PM, Noam Aigerman wrote: > Suppose I have a python object X, which holds inside it a python object Y. > How can I propagate each function call to X so the same function call in Y That'd be a method call actually, not a function call. > will be called, i.e: > > X.doThatFunkyFunk() > > Would cause > > Y.doThatFunkyFunk() Use a simple proxy (this will forward attribute accesses too, but that doesn't usually matter and can be worked around if necessary): class Delegator(object): def __init__(self, delegate): self.delegate = delegate def __getattr__(self, attr): return getattr(self.delegate, attr) Example: >>> a=Delegator([]) >>> a.append(5) >>> a.delegate [5] Note that this won't forward the operator special methods (e.g. __add__). Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From ntwrkd at gmail.com Tue Feb 10 20:12:46 2009 From: ntwrkd at gmail.com (Matthew Sacks) Date: Tue, 10 Feb 2009 17:12:46 -0800 Subject: getopt Message-ID: if anyone can have a look at this code and offer suggestions i would appreciate it. i am forced to use getopt, so i cant use something good like optparse passedArgs = sys.argv[1:] optlist, args = getopt.getopt(str(passedArgs), ["connectPassword=", "adminServerURL=", "action=", "targets=", "appDir="]) for some reason this does not work in assigning args to opts. i want to take all of the command line options and assign them to strings here is how i am currently going about it for o,a in optlist: if o == "--connectPassword": connectPassword = a print "Connect password assigned as " + a continue elif o == "--adminServerURL": adminServerURL = a print "adminServerURL " + a continue else: print "No connection Arguments Specified" TIV From prologic at shortcircuit.net.au Tue Feb 10 20:24:49 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 11 Feb 2009 11:24:49 +1000 Subject: Propagating function calls In-Reply-To: <749CACF29BDFB64E9F80189ECD77868804C01024@jermail1.atomant.net> References: <749CACF29BDFB64E9F80189ECD77868804C01024@jermail1.atomant.net> Message-ID: On Wed, Feb 11, 2009 at 11:02 AM, Noam Aigerman wrote: > Suppose I have a python object X, which holds inside it a python object Y. > How can I propagate each function call to X so the same function call in Y > will be called, i.e: > > X.doThatFunkyFunk() > > Would cause > > Y.doThatFunkyFunk() Noam, using circuits [1] you could do this: ---- from circuits import Event, Component, Manager class X(Component): def doThatFunkyFunk(self): ... class Y(Component): def doThatFunkyFunk(self): ... manager = Manager() manager += X() manager += Y() manager.send(Event(), "doThatFunkyFunk") ---- cheers James [1] http://pypi.python.org/pypi/circuits/ From sjmachin at lexicon.net Tue Feb 10 20:25:44 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 10 Feb 2009 17:25:44 -0800 (PST) Subject: getopt References: Message-ID: On Feb 11, 12:12?pm, Matthew Sacks wrote: > if anyone can have a look at this code and offer suggestions i would > appreciate it. > i am forced to use getopt, so i cant use something good like optparse > > passedArgs = sys.argv[1:] > optlist, args = getopt.getopt(str(passedArgs), ["connectPassword=", Dunno where you acquired the str() ... just lose it. Consider checking with the documentation when something "does not work". > "adminServerURL=", "action=", "targets=", "appDir="]) > > for some reason this does not work in assigning args to opts. > From aahz at pythoncraft.com Tue Feb 10 20:28:57 2009 From: aahz at pythoncraft.com (Aahz) Date: 10 Feb 2009 17:28:57 -0800 Subject: Upgrade 2.6 to 3.0 References: <669c42cc-4f4d-40be-b842-6f778959d391@f40g2000pri.googlegroups.com> <2ba4f763-79fa-423e-b082-f9de829ae964@i20g2000prf.googlegroups.com> Message-ID: In article <2ba4f763-79fa-423e-b082-f9de829ae964 at i20g2000prf.googlegroups.com>, Giampaolo Rodola' wrote: > >Just out of curiosity, am I the only one who think that switching to >3.x right now is not a good idea? Hardly. I certainly wouldn't consider it for production software, but installing it to play with probably is a Good Idea -- it's the future, after all. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From steven at REMOVE.THIS.cybersource.com.au Tue Feb 10 20:58:07 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 11 Feb 2009 01:58:07 GMT Subject: Avoiding argument checking in recursive calls Message-ID: I sometimes write recursive functions like this simple factorial: def fact(n): if n < 0: raise ValueError if n = 0: return 1 return fact(n-1)*n At the risk of premature optimization, I wonder if there is an idiom for avoiding the unnecessary test for n <= 0 in the subsequent recursive calls? For the sake of the argument, let's pretend the test is expensive and I have a good reason for wanting to avoid it on subsequent calls :) I've done this: def _fact(n): if n = 0: return 1 return _fact(n-1)*n def fact(n): if n < 0: raise ValueError return _fact(n) but that's ugly. What else can I do? -- Steven From fetchinson at googlemail.com Tue Feb 10 21:25:57 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 10 Feb 2009 18:25:57 -0800 Subject: "Super()" confusion In-Reply-To: References: <20090210012739.12853.653428988.divmod.quotient.8083@henry.divmod.com> Message-ID: >>>>>>> Consider whether you really need to use super(). >>>>>>> http://fuhm.net/super-harmful/ >>>> >>>> Because throwing around that link carries about the same amount of >>>> information as "perl is better than python", "my IDE is better than >>>> yours", "vim rulez!", "emacs is cooler than vim", etc, etc. >>> >>> Not at all. It contains accurate and valuable information that isn't >>> available elsewhere. >> >> But does not contain other valuable information which would demystify >> super. If only this source is shown to a person who wants to learn the >> proper usage of super, the impression he/she gets will be distorted. > > Why so? At the end there is a "best practices" recipe that pretty much > summarizes the proper usage of super, and AFAIK it's the right way to use > it. Don't you agree with any of the conclusions? > >> Example: 1. somebody asks about threading 2. reply comes: there is a >> GIL! you can't do real threading. Now this reply might be technically >> more-or-less correct, it is misleading and does not help the poster. >> An informed discussion of the various solutions that does not involve >> a rant about the GIL would be very useful though. > > As I said, the article presents a "recipe" for super() usage, and I'd > consider it very helpful. It's far from just saying "super s*cks!", or > "the GIL s*cks!" or something like that. > >> You might want to start with >> >> http://www.artima.com/weblogs/viewpost.jsp?thread=236275 > > ...which, although the author says it was written a long time ago, was not > published until less than six months ago, and has very low visibility. > >> You are right, it's not in the documentation. But if somebody asks on >> c.l.p the appropriate answer, I think, is to point to information such >> as the one above, and not the misleading "harmful" essay. > > According to Google, nobody has menctioned the "harmful" essay in this > group since April 2008 [1], months before Simionato's article were > available... So this is the *first* time the reference to the former essay > could have been replaced by M.S.' one... don't be so strict! > > Anyway, the right thing to do, IMHO, is to publish correct and accurate > documentation in the main Python site. Not everybody knows about this > group existence, nor has the time/experience/interest on subscribe here, > post a question and wait for an answer. I've seen some posts in python-dev > saying something like "this is confusing, we should evangelize people on > c.l.p. on the right way to do it" and I completely disagree; the right > place for such things is the product documentation, or -to a much lesser > degree because it's online only- some article collection linked from the > main site (like the "Other resources" left bar, already present). > >>>> Honestly, I don't understand how this thing got so much out of >>>> control. If anyone starts an intelligent question or remark about >>>> super, this essay is thrown in no matter what. Anyone can explain why? >>> >>> Because for a very loooooong time (seven years, 2001-2008) super was >>> almost undocumented. The Library Reference -before release 2.6- only >>> had a short paragraph, the [...] >> >> You are right, the documentation needs some work in this regard. But >> again, just because some sources are not in the documentation doesn't >> mean that the most opinionated essay is the best source. A little >> search turns up much more useful ones. > > (not according to Google [2]: I get the "harmful" article in the top, the > thread in python-dev, a couple threads in c.l.p including posts by M.S., > his article in artima, and nothing more relevant than "Monty Python Super > Star" up to the 3rd page) > > *Now* that *I* am aware of the recent article series by M.S., the next > time someone asks *me* about super(), probably I'll refer her to both M.S. > and J.K.'s articles. Last time I checked (perhaps one or two years ago), > the "harmful" article was almost the only relevant source of info about > super(). > > [1] > http://groups.google.com/group/comp.lang.python/search?q=super+harmful&start=0&scoring=d& > [2] http://www.google.com/search?q=python+super Okay, I think we converged to a common denominator. I agree with you that the documentation needs additions about super and I also agree with you that referring to both MS and JK articles is appropriate when a question about super comes up. It's good to have a discussion when views actually converge and not diverge at the end :) Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From benjamin.kaplan at case.edu Tue Feb 10 21:31:06 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 10 Feb 2009 21:31:06 -0500 Subject: "Super()" confusion In-Reply-To: References: <20090210012739.12853.653428988.divmod.quotient.8083@henry.divmod.com> Message-ID: On Tue, Feb 10, 2009 at 9:25 PM, Daniel Fetchinson < fetchinson at googlemail.com> wrote: > >>>>>>> Consider whether you really need to use super(). > >>>>>>> http://fuhm.net/super-harmful/ > >>>> > >>>> Because throwing around that link carries about the same amount of > >>>> information as "perl is better than python", "my IDE is better than > >>>> yours", "vim rulez!", "emacs is cooler than vim", etc, etc. > >>> > >>> Not at all. It contains accurate and valuable information that isn't > >>> available elsewhere. > >> > >> But does not contain other valuable information which would demystify > >> super. If only this source is shown to a person who wants to learn the > >> proper usage of super, the impression he/she gets will be distorted. > > > > Why so? At the end there is a "best practices" recipe that pretty much > > summarizes the proper usage of super, and AFAIK it's the right way to use > > it. Don't you agree with any of the conclusions? > > > >> Example: 1. somebody asks about threading 2. reply comes: there is a > >> GIL! you can't do real threading. Now this reply might be technically > >> more-or-less correct, it is misleading and does not help the poster. > >> An informed discussion of the various solutions that does not involve > >> a rant about the GIL would be very useful though. > > > > As I said, the article presents a "recipe" for super() usage, and I'd > > consider it very helpful. It's far from just saying "super s*cks!", or > > "the GIL s*cks!" or something like that. > > > >> You might want to start with > >> > >> http://www.artima.com/weblogs/viewpost.jsp?thread=236275 > > > > ...which, although the author says it was written a long time ago, was > not > > published until less than six months ago, and has very low visibility. > > > >> You are right, it's not in the documentation. But if somebody asks on > >> c.l.p the appropriate answer, I think, is to point to information such > >> as the one above, and not the misleading "harmful" essay. > > > > According to Google, nobody has menctioned the "harmful" essay in this > > group since April 2008 [1], months before Simionato's article were > > available... So this is the *first* time the reference to the former > essay > > could have been replaced by M.S.' one... don't be so strict! > > > > Anyway, the right thing to do, IMHO, is to publish correct and accurate > > documentation in the main Python site. Not everybody knows about this > > group existence, nor has the time/experience/interest on subscribe here, > > post a question and wait for an answer. I've seen some posts in > python-dev > > saying something like "this is confusing, we should evangelize people on > > c.l.p. on the right way to do it" and I completely disagree; the right > > place for such things is the product documentation, or -to a much lesser > > degree because it's online only- some article collection linked from the > > main site (like the "Other resources" left bar, already present). > > > >>>> Honestly, I don't understand how this thing got so much out of > >>>> control. If anyone starts an intelligent question or remark about > >>>> super, this essay is thrown in no matter what. Anyone can explain why? > >>> > >>> Because for a very loooooong time (seven years, 2001-2008) super was > >>> almost undocumented. The Library Reference -before release 2.6- only > >>> had a short paragraph, the [...] > >> > >> You are right, the documentation needs some work in this regard. But > >> again, just because some sources are not in the documentation doesn't > >> mean that the most opinionated essay is the best source. A little > >> search turns up much more useful ones. > > > > (not according to Google [2]: I get the "harmful" article in the top, the > > thread in python-dev, a couple threads in c.l.p including posts by M.S., > > his article in artima, and nothing more relevant than "Monty Python Super > > Star" up to the 3rd page) > > > > *Now* that *I* am aware of the recent article series by M.S., the next > > time someone asks *me* about super(), probably I'll refer her to both > M.S. > > and J.K.'s articles. Last time I checked (perhaps one or two years ago), > > the "harmful" article was almost the only relevant source of info about > > super(). > > > > [1] > > > http://groups.google.com/group/comp.lang.python/search?q=super+harmful&start=0&scoring=d& > > [2] http://www.google.com/search?q=python+super > > Okay, I think we converged to a common denominator. I agree with you > that the documentation needs additions about super and I also agree > with you that referring to both MS and JK articles is appropriate when > a question about super comes up. > > It's good to have a discussion when views actually converge and not > diverge at the end :) Wait, that's not supposed to happen. This is Usenet after all. Quick, someone comment on the GIL! -- > Psss, psss, put it down! - http://www.cafepress.com/putitdown > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mark.seagoe at gmail.com Tue Feb 10 21:31:26 2009 From: mark.seagoe at gmail.com (mark.seagoe at gmail.com) Date: Tue, 10 Feb 2009 18:31:26 -0800 (PST) Subject: Iterable Ctypes Struct Message-ID: <99d4c7ae-27ae-4f3a-8475-a58f1c4e6925@t26g2000prh.googlegroups.com> I like the ability to access elements of a struct such as with ctypes Structure: >>>myStruct.elementName1 4 What I like about it is there are no quotes needed. What I don't like about it is that it's not iterable: >>>for n in myStruct: <== gives error >>> print n I don't want to force the end user to have preknowledge of the element names. Has anyone subclassed ctypes Structure based class to be iterable? Before a noob starts trying to do this, is it possible? How to approach it? Thx, Mark From grante at visi.com Tue Feb 10 21:45:09 2009 From: grante at visi.com (Grant Edwards) Date: Tue, 10 Feb 2009 20:45:09 -0600 Subject: pySerial help please! References: Message-ID: On 2009-02-10, bmaschino at gmail.com wrote: > Hello all, > > I am very new to Python and I am using it because I needed an > easy language to control a piece of equipment that connects to > my computer via a serial cable. I am running Python 2.6 with > pySerial 2.4 under Windows. I can get Python to create a > serial port on COM1, but when I try to write to the device, > nothing happens. Here is an example: > > import serial > ser = serial.Serial(0) > ser.write("otpm 2 16 0") > ser.close() Are you sure you don't need some sort of line-terminator (e.g \r or \n) to tell the device to go ahead and execute the command? > If I connect to the device in Hyperterminal the device will > behave as expected when I give it the command 'otpm 2 16 0' > but not in Python. In Hyperterminal did you have to press [enter] to get the command to execute? If you close the port immediately after calling write(), it's possible that the data never actually got sent. You should probably wait until the data has been sent before closing the port. If you're running on Unix, I you should be able to call ser.flush() to wait until the output buffer has been sent. However, I wouldn't count too heavily on the underlying Unix serial driver properly implimenting the tcdrain call. And, I think the flush() call on Windows is a noop. So, putting an appropriate delay between the write and the close is probably the safest thing to do. -- Grant From jervisau at gmail.com Tue Feb 10 21:48:09 2009 From: jervisau at gmail.com (Jervis Whitley) Date: Wed, 11 Feb 2009 13:48:09 +1100 Subject: Avoiding argument checking in recursive calls In-Reply-To: References: Message-ID: <8e63a5ce0902101848k3e5be249n1892ba6c12588d4b@mail.gmail.com> > I've done this: > > def _fact(n): > if n = 0: return 1 > return _fact(n-1)*n > > def fact(n): > if n < 0: raise ValueError > return _fact(n) > > but that's ugly. What else can I do? > > Hello, an idea is optional keyword arguments. def fact(n, check=False): if not check: if n < 0: raise ValueError if n == 0: return 1 return fact(n - 1, check=True) * n essentially hiding an expensive check with a cheap one. It saves you duplicating code in a separate function like in your example. From gagsl-py2 at yahoo.com.ar Tue Feb 10 21:57:27 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 11 Feb 2009 00:57:27 -0200 Subject: "Super()" confusion References: <20090210012739.12853.653428988.divmod.quotient.8083@henry.divmod.com> Message-ID: En Wed, 11 Feb 2009 00:31:06 -0200, Benjamin Kaplan escribi?: > On Tue, Feb 10, 2009 at 9:25 PM, Daniel Fetchinson < > fetchinson at googlemail.com> wrote: > >> Okay, I think we converged to a common denominator. I agree with you >> that the documentation needs additions about super and I also agree >> with you that referring to both MS and JK articles is appropriate when >> a question about super comes up. >> >> It's good to have a discussion when views actually converge and not >> diverge at the end :) > > Wait, that's not supposed to happen. This is Usenet after all. Quick, > someone comment on the GIL! Our resident trolls are sleeping, it seems... -- Gabriel Genellina From python at bdurham.com Tue Feb 10 22:38:49 2009 From: python at bdurham.com (python at bdurham.com) Date: Tue, 10 Feb 2009 22:38:49 -0500 Subject: Difference between vars() and locals() and use case for vars() Message-ID: <1234323529.11589.1299703567@webmail.messagingengine.com> Can someone explain the difference between vars() and locals()? I'm also trying to figure out what the use case is for vars(), eg. when does it make sense to use vars() in a program? Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Tue Feb 10 23:04:47 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 11 Feb 2009 02:04:47 -0200 Subject: Difference between vars() and locals() and use case for vars() References: <1234323529.11589.1299703567@webmail.messagingengine.com> Message-ID: En Wed, 11 Feb 2009 01:38:49 -0200, escribi?: > Can someone explain the difference between vars() and locals()? > I'm also trying to figure out what the use case is for vars(), > eg. when does it make sense to use vars() in a program? Without arguments, vars() returns the current namespace -- same as locals() inside a function, same as locals() *and* globals() outside any function (i.e., in a module or running in the interactive interpreter) With an argument (that is, vars(x)) it returns the names defined by the object itself; for "normal" class instances, that means its __dict__ It's useful in the interactive interpreter, to examine some object's contents. Maybe in other special cases. Certainly not in everyday's programming. -- Gabriel Genellina From python at bdurham.com Tue Feb 10 23:10:35 2009 From: python at bdurham.com (python at bdurham.com) Date: Tue, 10 Feb 2009 23:10:35 -0500 Subject: Difference between vars() and locals() and use case for vars() In-Reply-To: References: <1234323529.11589.1299703567@webmail.messagingengine.com> Message-ID: <1234325435.17704.1299707517@webmail.messagingengine.com> Thank you Gabriel! Malcolm ----- Original message ----- From: "Gabriel Genellina" To: python-list at python.org Date: Wed, 11 Feb 2009 02:04:47 -0200 Subject: Re: Difference between vars() and locals() and use case for vars() En Wed, 11 Feb 2009 01:38:49 -0200, escribi?: > Can someone explain the difference between vars() and locals()? > I'm also trying to figure out what the use case is for vars(), > eg. when does it make sense to use vars() in a program? Without arguments, vars() returns the current namespace -- same as locals() inside a function, same as locals() *and* globals() outside any function (i.e., in a module or running in the interactive interpreter) With an argument (that is, vars(x)) it returns the names defined by the object itself; for "normal" class instances, that means its __dict__ It's useful in the interactive interpreter, to examine some object's contents. Maybe in other special cases. Certainly not in everyday's programming. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list From lepto.python at gmail.com Tue Feb 10 23:21:12 2009 From: lepto.python at gmail.com (oyster) Date: Wed, 11 Feb 2009 12:21:12 +0800 Subject: can multi-core improve single funciton? Message-ID: <6a4f17690902102021g76f680cdve2cf20f16af5d8ab@mail.gmail.com> Hi, guys, my fib(xx) is just an example to show "what is a single function" and "what is the effect I expect to see when enable multi-core". My real purpose is to know "whether multi-core can help to improve the speed of a common function". But I know definitely that the answer is NO. From gagsl-py2 at yahoo.com.ar Tue Feb 10 23:31:16 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 11 Feb 2009 02:31:16 -0200 Subject: Avoiding argument checking in recursive calls References: Message-ID: En Tue, 10 Feb 2009 23:58:07 -0200, Steven D'Aprano escribi?: > I sometimes write recursive functions like this simple factorial: > > > def fact(n): > if n < 0: raise ValueError > if n = 0: return 1 > return fact(n-1)*n > > At the risk of premature optimization, I wonder if there is an idiom for > avoiding the unnecessary test for n <= 0 in the subsequent recursive > calls? For the sake of the argument, let's pretend the test is expensive > and I have a good reason for wanting to avoid it on subsequent calls :) > > > > I've done this: > > def _fact(n): > if n = 0: return 1 > return _fact(n-1)*n > > def fact(n): > if n < 0: raise ValueError > return _fact(n) > > but that's ugly. What else can I do? I don't think it's ugly; you have an implementation (_fact) and its public interfase (fact). In 'fact' you could check that n is actually an integer (an implicit precondition, your algorithm doesn't finish in other case) and whatever validation is also required. Perhaps its arguments come from user input and you need stricter tests, or convert from other type (like float->int). On the other hand, '_fact' is private and you can assume their arguments are exactly what you require. In Pascal I would have used a nested _fact function; in Python it isn't as efficient so I'd write it as your own example. This is a rather used idiom - in the Python C API, by example, usually you see a public function PyFoo_DoSomething(PyObject* obj) and a private one _PyFoo_DoSomething(double x) (assume a function like sqrt, number -> float). The public one takes a generic Python object, checks its type, converts it to a C "double" value, and if all went OK, finally calls the private implementation passing that value. -- Gabriel Genellina From afriere at yahoo.co.uk Tue Feb 10 23:42:47 2009 From: afriere at yahoo.co.uk (afriere at yahoo.co.uk) Date: Tue, 10 Feb 2009 20:42:47 -0800 (PST) Subject: Avoiding argument checking in recursive calls References: Message-ID: On Feb 11, 1:48?pm, Jervis Whitley wrote: > Hello, an idea is optional keyword arguments. > > def fact(n, check=False): > ? if not check: > ? ? if n < 0: raise ValueError > ? if n == 0: return 1 > ? return fact(n - 1, check=True) * n > > essentially hiding an expensive check with a cheap one. It saves you > duplicating code in a separate function like in your example. Given the original read: def fact(n): if n < 0: raise ValueError if n = 0: return 1 return fact(n-1)*n You've merely replaced the 'test n<0' with 'not check' at the expense of an additional parameter that has to be passed each time (and the additional test 'n<0' for the first iteration). From michele.simionato at gmail.com Tue Feb 10 23:52:37 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Tue, 10 Feb 2009 20:52:37 -0800 (PST) Subject: "Super()" confusion References: <20090210012739.12853.653428988.divmod.quotient.8083@henry.divmod.com> <2e105a22-dc21-4e69-b25d-522666c1db1c@u13g2000yqg.googlegroups.com> Message-ID: <5175fb80-f01d-448f-99c7-ebbb60aa0011@a12g2000yqm.googlegroups.com> On Feb 10, 9:19?am, "Gabriel Genellina" wrote: > You really should push them to be included in python.org, even in their ? > unfinished form. (At least a link in the wiki pages). Their visibility is ? > almost null now. It looks like I made an unfortunate choice with the title ("Things to Know about Super"). I have just changed it to "Things to Know about *Python* Super" so that now googling for "python super" should hopefully find them. I agree that the real solution would be to publish on python.org, but for that I have to write yet another paper about Python 3.0 super, cut things about old version/bugs of Python, re-read the whole beast, and convince the core developers to publish it (which is not automatic). That is some work, and I have many other projects going on right now. Truth is, discussions about super do not come out so often, and most people don't care. > They're very clearly written - I wish you had published them years ago! Me too, but you know what happens when working for free and without deadlines ;) > again, you really should publish the ? > series in a more prominent place. Soon or later I will go back to super in Python 3.0, but now I am working on my Scheme series, I have yet to translate two articles of my "Mixins considered harmful" series, and I have at least two other articles which has been waiting publication for more than one year. Plus, I have a full time job ;) But if you and others keep bugging me something may happen ... Michele Simionato From prologic at shortcircuit.net.au Tue Feb 10 23:57:26 2009 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 11 Feb 2009 14:57:26 +1000 Subject: can multi-core improve single funciton? In-Reply-To: <6a4f17690902102021g76f680cdve2cf20f16af5d8ab@mail.gmail.com> References: <6a4f17690902102021g76f680cdve2cf20f16af5d8ab@mail.gmail.com> Message-ID: On Wed, Feb 11, 2009 at 2:21 PM, oyster wrote: > My real purpose is to know "whether multi-core can help to improve the > speed of a common function". But I know definitely that the answer is > NO. As stated by others, and even myself, it is not possible to just "automagically" improve the execution speed of a single function - let alone an application. Your problem must be capable of being divided up into work units that can be parallelized. If this is not possible, multiple cores (no matter how many you have) -will not- help you. cheers James From clp2 at rebertia.com Wed Feb 11 00:01:53 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 10 Feb 2009 21:01:53 -0800 Subject: can multi-core improve single funciton? In-Reply-To: References: <6a4f17690902102021g76f680cdve2cf20f16af5d8ab@mail.gmail.com> Message-ID: <50697b2c0902102101n4ff52d0fq8a6db73b9cbfb387@mail.gmail.com> On Tue, Feb 10, 2009 at 8:57 PM, James Mills wrote: > On Wed, Feb 11, 2009 at 2:21 PM, oyster wrote: >> My real purpose is to know "whether multi-core can help to improve the >> speed of a common function". But I know definitely that the answer is >> NO. > > As stated by others, and even myself, > it is not possible to just "automagically" > improve the execution speed of a single > function - let alone an application. > > Your problem must be capable of being divided up > into work units that can be parallelized. If this is not > possible, multiple cores (no matter how many you have) > -will not- help you. See also Amdahl's Law -- http://en.wikipedia.org/wiki/Amdahl%27s_law Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From gagsl-py2 at yahoo.com.ar Wed Feb 11 00:07:31 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 11 Feb 2009 03:07:31 -0200 Subject: bool evaluations of generators vs lists References: <20090210111514.07e0480a@microvu.com> <1234294770.8528.14.camel@localhost.localdomain> <20090210125002.1f6d8597@microvu.com> <1234301147.8528.47.camel@localhost.localdomain> Message-ID: On Tue, 2009-02-10 at 12:50 -0800, Josh Dukes wrote: >> The thing I don't understand is why a generator that has no iterable >> values is different from an empty list. Why shouldn't bool == >> has_value?? Technically a list, a tuple, and a string are also objects >> but if they lack values they're evaluated as False. It seems to me that >> a generator is an object that intends to replace lists where lazy >> evaluation would be more efficent. Here is one place where that's >> definitely true. Just in case it's not perfectly clear: until you call next() there is no way to know whether the generator will yield any value or not -- and once it does, it's lost until you explicitely save it. This generator doesn't yield any value - but you have to wait for a while if you call .next() on it, until eventually raises StopIteration: (x for x in xrange(2000000000) if x>100000000000) En Tue, 10 Feb 2009 19:25:47 -0200, Albert Hopkins escribi?: >> The main reason I'm interested in this is that it improves performance >> immensely over boolean evaluation of large lists (as the attached code >> shows). It seems to me if I could use find a good use for it in my >> experimentation that someone else might also want to do the same thing >> in real-world code. > > I don't understand what you mean by this. But if you really want to > know if a generator is "non-empty": > > def non_empty(virgin_generator): > try: > virgin_generator.next() # note you just lost the first value > return True > except StopIteration: > return False > > The only way to get around this is to put all the values of a generator > inside a container (e.g. a list): For a long generator you may not want to do that, also you may not want to lose the next element. A variation of your function above is useful in such cases: py> def end_of_gen(g): ... """returns (False, next_element) when it exists or (True, None) when it's empty""" ... try: return False, g.next() ... except StopIteration: return True, None ... py> g = (c for c in "Python" if c in "aeiou") py> eog, c = end_of_gen(g) py> eog False py> c 'o' py> eog, c = end_of_gen(g) py> eog True py> c -- Gabriel Genellina From ntwrkd at gmail.com Wed Feb 11 00:36:00 2009 From: ntwrkd at gmail.com (Matthew Sacks) Date: Tue, 10 Feb 2009 21:36:00 -0800 Subject: getopt In-Reply-To: References: Message-ID: The documentation leaves lack for want, especially the examples. On Tue, Feb 10, 2009 at 5:25 PM, John Machin wrote: > On Feb 11, 12:12 pm, Matthew Sacks wrote: >> if anyone can have a look at this code and offer suggestions i would >> appreciate it. >> i am forced to use getopt, so i cant use something good like optparse >> >> passedArgs = sys.argv[1:] >> optlist, args = getopt.getopt(str(passedArgs), ["connectPassword=", > > Dunno where you acquired the str() ... just lose it. Consider checking > with the documentation when something "does not work". > >> "adminServerURL=", "action=", "targets=", "appDir="]) >> >> for some reason this does not work in assigning args to opts. >> > -- > http://mail.python.org/mailman/listinfo/python-list > From http Wed Feb 11 00:51:00 2009 From: http (Paul Rubin) Date: 10 Feb 2009 21:51:00 -0800 Subject: can multi-core improve single funciton? References: Message-ID: <7xhc31o723.fsf@ruckus.brouhaha.com> oyster writes: > Hi, guys, my fib(xx) is just an example to show "what is a single > function" and "what is the effect I expect to see when enable > multi-core". > > My real purpose is to know "whether multi-core can help to improve > the speed of a common function". But I know definitely that the > answer is NO. Well, it depends on the implementation. Python isn't at the moment designed for using multicores but as it evolves that may change. The blog post http://cgi.cse.unsw.edu.au/~dons/blog/2007/11/29 may be of interest re parallelizing that fibonacci function. From gagsl-py2 at yahoo.com.ar Wed Feb 11 00:52:56 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 11 Feb 2009 03:52:56 -0200 Subject: Iterable Ctypes Struct References: <99d4c7ae-27ae-4f3a-8475-a58f1c4e6925@t26g2000prh.googlegroups.com> Message-ID: En Wed, 11 Feb 2009 00:31:26 -0200, escribi?: > I like the ability to access elements of a struct such as with ctypes > Structure: >>>> myStruct.elementName1 > 4 > > What I like about it is there are no quotes needed. > > What I don't like about it is that it's not iterable: >>>> for n in myStruct: <== gives error >>>> print n > > I don't want to force the end user to have preknowledge of the element > names. Note that those names are available as the _fields_ class attribute > Has anyone subclassed ctypes Structure based class to be iterable? > Before a noob starts trying to do this, is it possible? How to > approach it? The easiest way would be to define __getitem__ accepting index 0, 1, 2... until the last defined field. See http://docs.python.org/reference/datamodel.html#object.__getitem__ from ctypes import Structure class IterableStructure(Structure): def __getitem__(self, i): if not isinstance(i, int): raise TypeError('subindices must be integers: %r' % i) return getattr(self, self._fields_[i][0]) This was tested as much as you see here: py> from ctypes import c_int py> py> class POINT(IterableStructure): ... _fields_ = [("x", c_int), ... ("y", c_int)] ... py> point = POINT(10, 20) py> print point.x, point.y 10 20 py> for field in point: ... print field ... 10 20 py> print list(point) [10, 20] -- Gabriel Genellina From sjmachin at lexicon.net Wed Feb 11 00:54:25 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 10 Feb 2009 21:54:25 -0800 (PST) Subject: getopt References: Message-ID: <531416d0-9396-4804-a5be-184c224edb60@d36g2000prf.googlegroups.com> On Feb 11, 12:25?pm, John Machin wrote: > On Feb 11, 12:12?pm, Matthew Sacks wrote: > > > if anyone can have a look at this code and offer suggestions i would > > appreciate it. > > i am forced to use getopt, so i cant use something good like optparse > > > passedArgs = sys.argv[1:] > > optlist, args = getopt.getopt(str(passedArgs), ["connectPassword=", > > Dunno where you acquired the str() ... just lose it. Consider checking > with the documentation when something "does not work". Rule 2: read further in the documentation than you think you need to :-) You have omitted the second arg, the one that defines short options. As for the second part of your question, assigning to locals is tedious as you have found. The classical solution is to jam the options into an object that acts like a 'record' or a 'struct'. Another possibility is the newfangled 'named tuple'. The following illustrates working code for getting your optlist going, and using the 'record' idea. Keep on going (next step: add a function for each arg that will convert the value from str to int/float/bool/etc as/if appropriate) and you will have rewritten optparse. HTH, John ================ C:\junk>type getopt_demo.py import getopt, sys long_arg_defns = { # sets up defaults "cp": None, "asu": "xyzzy", "act": "do_nothing", "tgts":"", "ad": 1.23, } long_arg_list = [x + '=' for x in long_arg_defns.keys()] passedArgs = sys.argv[1:] print 'passedArgs', passedArgs print '\nattempt 1' try: optlist, args = getopt.getopt(str(passedArgs), long_arg_list) print optlist, args except Exception, e: print "%s: %s" % (e.__class__.__name__, e) print '\nattempt 2' try: optlist, args = getopt.getopt(passedArgs, long_arg_list) print optlist, args except Exception, e: print "%s: %s" % (e.__class__.__name__, e) print '\nattempt 3' try: optlist, args = getopt.getopt(passedArgs, '', long_arg_list) print optlist, args except Exception, e: print "%s: %s" % (e.__class__.__name__, e) class Record(object): def __init__(self, initial_dict, optlist): for attr, default in initial_dict.items(): setattr(self, attr, default) for attr, value in optlist: setattr(self, attr.lstrip('-'), value) def __str__(self): return "" % self.__dict__ r = Record(long_arg_defns, optlist) print print r print print r.cp, r.act, r.ad C:\junk>getopt_demo.py --cp xxxcp --ad yyyyyad extra1 extra2 passedArgs ['--cp', 'xxxcp', '--ad', 'yyyyyad', 'extra1', 'extra2'] attempt 1 [] ['--cp', 'xxxcp', '--ad', 'yyyyyad', 'extra1', 'extra2'] attempt 2 GetoptError: option --cp not recognized attempt 3 [('--cp', 'xxxcp'), ('--ad', 'yyyyyad')] ['extra1', 'extra2'] xxxcp do_nothing yyyyyad C:\junk> From gagsl-py2 at yahoo.com.ar Wed Feb 11 01:09:50 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 11 Feb 2009 04:09:50 -0200 Subject: python3 tutorial for newbie References: <920577A6E319438A9397A41B74AE9913@Woodygar> Message-ID: En Tue, 10 Feb 2009 16:22:36 -0200, Gary Wood escribi?: > Can someone recommend a good tutorial for Python 3, ideally that has > tasks or assignments at the end of each chapter. I don't know of any specifically targetted to Python 3, except the official one at http://www.python.org/doc/3.0/ For the most part, any Python tutorial should be fine. Perhaps the only visible change (at the tutorial level) is that "print" became a function: # 2.x syntax: print "Hello", "world!" # 3.x syntax: print("Hello", "world!") That said, Python 3.0 is so recent that isn't widely used yet, and many third party libraries aren't available for 3.0 at this moment. This certainly will change in the future, but in the meantime, perhaps you should stick to Python 2.6 for a while. -- Gabriel Genellina From sjmachin at lexicon.net Wed Feb 11 01:36:40 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 10 Feb 2009 22:36:40 -0800 (PST) Subject: getopt References: Message-ID: <3997cad4-e578-4e58-9c93-4c134b1d6d1a@v5g2000pre.googlegroups.com> On Feb 11, 4:36?pm, Matthew Sacks wrote: > The documentation leaves lack for want, especially the examples. You had two problems: (1) str(passedArgs): The docs make it plain that "args" is a list, not a str instance: """args is the argument list to be parsed, without the leading reference to the running program. Typically, this means sys.argv[1:]""". The 1st and 2nd examples spell out the same story; here's the 2nd: """ Using long option names is equally easy: >>> s = '--condition=foo --testing --output-file abc.def -x a1 a2' >>> args = s.split() >>> args ['--condition=foo', '--testing', '--output-file', 'abc.def', '-x', 'a1', 'a2'] """ (2) omitting the *required* options arg: (a) it's not wrapped in [] so it's required (b) the docs say """To accept only long options, options should be an empty string.""" IOW, it may "leave lack for want", but not in the areas causing you a bother. From kamath86 at gmail.com Wed Feb 11 01:37:37 2009 From: kamath86 at gmail.com (kamath86 at gmail.com) Date: Tue, 10 Feb 2009 22:37:37 -0800 (PST) Subject: Browse Dialog Message-ID: <435cced2-53bc-47a1-86a9-b8ac9bb7415a@p13g2000yqc.googlegroups.com> Hi , I am using TKinter for creating a GUI. As of now i am using tkFileDialog module for selection of file/directory.But i see that i can use either of these at one go.Is there a way i can select a file or a directory through a single dialog box?? From arunasunil at gmail.com Wed Feb 11 01:43:24 2009 From: arunasunil at gmail.com (arunasunil at gmail.com) Date: Tue, 10 Feb 2009 22:43:24 -0800 (PST) Subject: Programmatically changing network proxy settings on the Mac Message-ID: Hi, Anybody have suggestions of how network proxy settings can be changed programmatically on the Mac, Tiger and Leopard. Are there any helpful python api's that can be used. Thanks Sunil From akitada at gmail.com Wed Feb 11 01:46:44 2009 From: akitada at gmail.com (Akira Kitada) Date: Wed, 11 Feb 2009 15:46:44 +0900 Subject: python3 tutorial for newbie In-Reply-To: <920577A6E319438A9397A41B74AE9913@Woodygar> References: <920577A6E319438A9397A41B74AE9913@Woodygar> Message-ID: <90bb445a0902102246n65d1d33ej3f2ff0a1867253dc@mail.gmail.com> http://wiki.python.org/moin/Python3.0Tutorials On Wed, Feb 11, 2009 at 3:22 AM, Gary Wood wrote: > Can someone recommend a good tutorial for Python 3, ideally that has tasks > or assignments at the end of each chapter. > Please, > > -- > http://mail.python.org/mailman/listinfo/python-list > > From ntwrkd at gmail.com Wed Feb 11 01:46:48 2009 From: ntwrkd at gmail.com (Matthew Sacks) Date: Tue, 10 Feb 2009 22:46:48 -0800 Subject: getopt In-Reply-To: <3997cad4-e578-4e58-9c93-4c134b1d6d1a@v5g2000pre.googlegroups.com> References: <3997cad4-e578-4e58-9c93-4c134b1d6d1a@v5g2000pre.googlegroups.com> Message-ID: I didn't realize that the no-value arguments, -b, -h, etc are required? This seems to make things a bit more difficult considering unless I use the GNU style getopt all arguments are required to be passed? I could be mistaken. I will have a look at what you have posted here and report my results. I appreciate the response. M On Tue, Feb 10, 2009 at 10:36 PM, John Machin wrote: > On Feb 11, 4:36 pm, Matthew Sacks wrote: >> The documentation leaves lack for want, especially the examples. > > You had two problems: > > (1) str(passedArgs): The docs make it plain that "args" is a list, not > a str instance: """args is the argument list to be parsed, without the > leading reference to the running program. Typically, this means > sys.argv[1:]""". The 1st and 2nd examples spell out the same story; > here's the 2nd: > """ > Using long option names is equally easy: > >>> s = '--condition=foo --testing --output-file abc.def -x a1 a2' > >>> args = s.split() > >>> args > ['--condition=foo', '--testing', '--output-file', 'abc.def', '-x', > 'a1', 'a2'] > """ > > (2) omitting the *required* options arg: (a) it's not wrapped in [] so > it's required (b) the docs say """To accept only long options, options > should be an empty string.""" > > IOW, it may "leave lack for want", but not in the areas causing you a > bother. > -- > http://mail.python.org/mailman/listinfo/python-list > From Scott.Daniels at Acm.Org Wed Feb 11 01:57:18 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 10 Feb 2009 22:57:18 -0800 Subject: Avoiding argument checking in recursive calls In-Reply-To: References: Message-ID: Steven D'Aprano wrote: > I sometimes write recursive functions like this simple factorial: > def fact(n): > if n < 0: raise ValueError > if n = 0: return 1 > return fact(n-1)*n > > At the risk of premature optimization, I wonder if there is an idiom for > avoiding the unnecessary test for n <= 0 in the subsequent recursive > calls? For the sake of the argument, let's pretend the test is expensive > and I have a good reason for wanting to avoid it on subsequent calls :) How about: def fact(n): if n < 2: if n < 0: raise ValueError return 1 return fact(n - 1) * n But really, iteration is the solution to this, and avoiding the right answer is a mistake. I couldn't resist fixing your test so you do one less layer of recursion. --Scott David Daniels Scott.Daniels at Acm.Org From http Wed Feb 11 02:41:18 2009 From: http (Paul Rubin) Date: 10 Feb 2009 23:41:18 -0800 Subject: Avoiding argument checking in recursive calls References: Message-ID: <7xeiy52zfl.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > def fact(n): > if n < 0: raise ValueError > if n = 0: return 1 > return fact(n-1)*n > > At the risk of premature optimization, I wonder if there is an idiom for > avoiding the unnecessary test for n <= 0 in the subsequent recursive > calls? I'd write nested functions: def fact(n): if n < 0: raise ValueError def f1(n): return 1 if n==0 else n*f1(n-1) return f1(n) If the language implementation supports tail recursion optimization there's an accumulation-parameter style that takes a little getting used to but is familiar in functional programming: def fact(n): if n < 0: raise ValueError def f1(k,n): return k if n==0 else f1(k*n, n-1) return f1(1, n) This won't do any good in CPython but maybe PyPy or Pyrex or whatever can make use of it. In this case the nested function is already there, and the n<0 check naturally lifts out of it. From http Wed Feb 11 02:50:43 2009 From: http (Paul Rubin) Date: 10 Feb 2009 23:50:43 -0800 Subject: Avoiding argument checking in recursive calls References: <7xeiy52zfl.fsf@ruckus.brouhaha.com> Message-ID: <7xbpt9h0oc.fsf@ruckus.brouhaha.com> Paul Rubin writes: > I'd write nested functions: > > def fact(n): > if n < 0: raise ValueError > def f1(n): > return 1 if n==0 else n*f1(n-1) > return f1(n) I forgot to add: all these versions except your original one should add a type check if you are trying to program defensively. Otherwise they can recurse infinitely if you give a positive non-integer arg like fact(3.5). From joelc at cognyx.com Wed Feb 11 02:52:40 2009 From: joelc at cognyx.com (Joel Ross) Date: Wed, 11 Feb 2009 18:52:40 +1100 Subject: Variable + String Format In-Reply-To: <019ff536$0$20657$c3e8da3@news.astraweb.com> References: <019ff536$0$20657$c3e8da3@news.astraweb.com> Message-ID: <01a1281b$0$7503$c3e8da3@news.astraweb.com> Joel Ross wrote: > Hi all, > > I have this piece of code: > ######################################################################### > > wordList = "/tmp/Wordlist" > file = open(wordList, 'r+b') > > > def readLines(): > > for line in file.read(): > if not line: break > print line + '.com ' > return line > > > > readLines() > file.close() > > ########################################################################## > > It returns the results: > > t.com > > NOTE: Only returns the first letter of the first word on the first line > e.g. test would only print t and readline() does the same thing. > > I have also tried readlines() which gives me the result: > > test > .com > > The file Wordlist has one word on each line for example > > test > test1 > test2 > > I need it to loop though the Wordlist file and print/return the results > > test.com > test1.com > test2.com > > I'm just looking for a point in the right direction. > > Much Thanks > > JOelC Thanks for the quick response guys. Help me out a alot. I'm a newbie to python and your replies help me understand a bit more about python!! Thank You From Ron.Barak at lsi.com Wed Feb 11 02:58:59 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Wed, 11 Feb 2009 07:58:59 +0000 Subject: Putting asterisks around text In-Reply-To: <20090209132046.091f5b8a.darcy@druid.net> References: <20090209132046.091f5b8a.darcy@druid.net> Message-ID: <7F0503CD69378F49BE0DC30661C6CCF60E687981@enbmail01.lsi.com> [http://www.emofaces.com/en/emoticons/t/thumbs-up-emoticon.gif] -----Original Message----- From: D'Arcy J.M. Cain [mailto:darcy at druid.net] Sent: Monday, February 09, 2009 20:21 To: todpose at hotmail.com Cc: python-list at python.org Subject: Re: Putting asterisks around text On Mon, 9 Feb 2009 10:09:26 -0800 "todpose at hotmail.com" wrote: > I'm trying to write a program that puts asterisks around the input text using while loop. > I can do this without using while loop, but how can you do that using > while loop?Example:Enter a string: Hello world***********Hello > world*********** while understand_problem is False: study("textbook") complete("homework") if want_help is True: study("http://www.catb.org/~esr/faqs/smart-questions.html") -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: thumbs-up-emoticon.gif Type: image/gif Size: 3693 bytes Desc: thumbs-up-emoticon.gif URL: From greg.ewing at canterbury.ac.nz Wed Feb 11 03:10:04 2009 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Wed, 11 Feb 2009 21:10:04 +1300 Subject: ANN: SuPy for Python 2.5 on Windows Message-ID: SuPy 1.0 - Windows ------------------ A Windows build for Python 2.5 is now available. http://www.cosc.canterbury.ac.nz/greg.ewing/SuPy/ What is SuPy? ------------- SuPy is a plugin for the Sketchup 3D modelling application that lets you script it in Python. This is a first version and is highly experimental. Let me know if it works for you and whether you have any problems. -- Greg Ewing greg.ewing at canterbury.ac.nz From sjmachin at lexicon.net Wed Feb 11 03:13:33 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 11 Feb 2009 00:13:33 -0800 (PST) Subject: getopt References: <3997cad4-e578-4e58-9c93-4c134b1d6d1a@v5g2000pre.googlegroups.com> Message-ID: <6f4e83b3-7c0f-4572-868f-7dafd769a3d3@r15g2000prd.googlegroups.com> On Feb 11, 5:46?pm, Matthew Sacks wrote: > I didn't realize that the no-value arguments, -b, -h, etc are required? required sense 1: the 2nd arg of the function is required; if there are to be no short options, the 2nd arg should be an empty string. required sense 2: you are required to specify *all* short options that you will accept, whether they are no-value or value options; otherwise you would have to do your own checking for unacceptable options > This seems to make things a bit more difficult considering unless I > use the GNU style getopt all arguments are required to be passed? What does "all arguments are required to be passed" mean? The user is not required to supply an arg corresponding to any option. Options are optional! GNU? Change getopt.getopt to getopt.gnu_getopt and you still get an exception like "GetoptError: option -b not recognized" if -b is not defined in the 2nd arg of [gnu_]getopt. AFAICT the GNU difference is only the documented different treatment of an arg string like "-a1 -b bvalue stray -c -d" ... non-Gnu treats -c and -d the same as stray. > I will have a look at what you have posted here and report my results. Just bear in mind that it was written under the assumption that you weren't plannning to use short options at all; your examples left lack for want. Cheers, John From lists at cheimes.de Wed Feb 11 03:26:31 2009 From: lists at cheimes.de (Christian Heimes) Date: Wed, 11 Feb 2009 09:26:31 +0100 Subject: Escaping my own chroot... In-Reply-To: References: Message-ID: <49928BB7.2020406@cheimes.de> Dennis Lee Bieber schrieb: > That's the whole purpose of chroot()... As far as the process is > concerned, the chroot() path is now the top of the file system, so there > is no where above it you can get to... Yes, you can get with some hacks. > chroot() is meant for cases where one may be running a server or such > that should not permit any outside hacks from reaching above its level. > Typically one creates a minimal environment of just those commands and > programs needed by users of the server -- you remove anything that > offers privileged ability. > > chdir() would be used to change the current directory of the process, so > any spawned commands would operate in the new directory by default chroot() must not be understood as a security mechanism like BSD's jail. A process can still access resources outside the chroot. Unless the process drops it's root privileges with setuid() ASAP the process can escape the chroot'ed environment, too. chroot() can help with increasing security but it's not bullet proof. By the way it's a bad idea to mount proc and sys inside a chroot ... Christian From castironpi at gmail.com Wed Feb 11 03:41:39 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 11 Feb 2009 00:41:39 -0800 (PST) Subject: Avoiding argument checking in recursive calls References: Message-ID: On Feb 10, 7:58?pm, Steven D'Aprano wrote: > I sometimes write recursive functions like this simple factorial: > > def fact(n): > ? ? if n < 0: raise ValueError > ? ? if n = 0: return 1 > ? ? return fact(n-1)*n > > At the risk of premature optimization, I wonder if there is an idiom for > avoiding the unnecessary test for n <= 0 in the subsequent recursive > calls? For the sake of the argument, let's pretend the test is expensive > and I have a good reason for wanting to avoid it on subsequent calls :) > > I've done this: > > def _fact(n): > ? ? if n = 0: return 1 > ? ? return _fact(n-1)*n > > def fact(n): > ? ? if n < 0: raise ValueError > ? ? return _fact(n) > > but that's ugly. What else can I do? > > -- > Steven Build a list of function calls, and just replace the base case with a terminating call. >>> def f( n ): ... def rec( i ): ... return i* funcs[ i- 1 ]( i- 1 ) ... def base( i ): ... return 1 ... funcs= [ rec ]* n ... funcs[ 0 ]= base ... return rec( n ) ... >>> f( 5 ) 120 >>> f( 6 ) 720 >>> f( 1 ) 1 From ksterling at mindspring.com Wed Feb 11 04:10:31 2009 From: ksterling at mindspring.com (Ken) Date: Wed, 11 Feb 2009 04:10:31 -0500 Subject: python3 tutorial for newbie References: <920577A6E319438A9397A41B74AE9913@Woodygar> Message-ID: <9f-dnVeRM-SVCw_UnZ2dnUVZ_v7inZ2d@earthlink.com> "Gabriel Genellina" wrote in message news:mailman.9312.1234332608.3487.python-list at python.org... > En Tue, 10 Feb 2009 16:22:36 -0200, Gary Wood > escribi?: > >> Can someone recommend a good tutorial for Python 3, ideally that has >> tasks or assignments at the end of each chapter. > > I don't know of any specifically targetted to Python 3, except the > official one at http://www.python.org/doc/3.0/ > > For the most part, any Python tutorial should be fine. Perhaps the only > visible change (at the tutorial level) is that "print" became a function: > > # 2.x syntax: > print "Hello", "world!" > > # 3.x syntax: > print("Hello", "world!") > > That said, Python 3.0 is so recent that isn't widely used yet, and many > third party libraries aren't available for 3.0 at this moment. This > certainly will change in the future, but in the meantime, perhaps you > should stick to Python 2.6 for a while. > > -- > Gabriel Genellina Several links here: http://wiki.python.org/moin/Python3.0Tutorials > From jef.mangelschots at gmail.com Wed Feb 11 04:24:17 2009 From: jef.mangelschots at gmail.com (jefm) Date: Wed, 11 Feb 2009 01:24:17 -0800 (PST) Subject: import wx works interactive but not from script References: <549b9ca1-90f4-403e-b30d-679957f36992@a12g2000pro.googlegroups.com> <35efb288-f6eb-4077-8414-93fa673c6878@t26g2000prh.googlegroups.com> Message-ID: <0a313a42-bfd9-4f2e-b16c-ffb82d3ae2a1@o2g2000prl.googlegroups.com> ok, sorry for the long wait. I tried this on both my work (XP) and home PC (Vista64) and they are both consistent. I had both Python2.6 and Python 3.0 installed. wxPython didn't like that. As soon as I uninstalled Python3.0, my wxPython started running again. Must be some kind of registry thing. Thanks for the suggestion. From tjreedy at udel.edu Wed Feb 11 04:31:10 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 11 Feb 2009 04:31:10 -0500 Subject: Avoiding argument checking in recursive calls In-Reply-To: <7xeiy52zfl.fsf@ruckus.brouhaha.com> References: <7xeiy52zfl.fsf@ruckus.brouhaha.com> Message-ID: > Steven D'Aprano writes: >> def fact(n): >> if n < 0: raise ValueError >> if n = 0: return 1 >> return fact(n-1)*n >> >> At the risk of premature optimization, I wonder if there is an idiom for >> avoiding the unnecessary test for n <= 0 in the subsequent recursive >> calls? Reverse the test order def fact(n): if n > 0: return fact(n-1)*n if n == 0: return 1 raise ValueError You must test recursive versus terminal case every call in any case. Nearly always, the first test passes and second is not done. You only test n==0 once, either to terminate or raise exception. This works for any integral value and catches non-integral values. (There is some delay for that, but only bad calls are penalized.) Terry Jan Reedy From jervisau at gmail.com Wed Feb 11 04:31:25 2009 From: jervisau at gmail.com (Jervis Whitley) Date: Wed, 11 Feb 2009 20:31:25 +1100 Subject: Avoiding argument checking in recursive calls In-Reply-To: References: Message-ID: <8e63a5ce0902110131m78a996f0l62df13e602489cd0@mail.gmail.com> > You've merely replaced the 'test n<0' with 'not check' at the expense > of an additional parameter that has to be passed each time (and the > additional test 'n<0' for the first iteration). > -- > http://mail.python.org/mailman/listinfo/python-list > I think you have missed the point. The OP stated that n<0 could stand for an expensive operation, this replaces an expensive check every time with a cheaper one every time. I like the idea of the interface that was in the original post. Cheers, From jervisau at gmail.com Wed Feb 11 04:32:44 2009 From: jervisau at gmail.com (Jervis Whitley) Date: Wed, 11 Feb 2009 20:32:44 +1100 Subject: Avoiding argument checking in recursive calls In-Reply-To: References: Message-ID: <8e63a5ce0902110132l6c092d1eyc4068e381f3c0069@mail.gmail.com> > > You've merely replaced the 'test n<0' with 'not check' at the expense > of an additional parameter that has to be passed each time (and the > additional test 'n<0' for the first iteration). > -- > http://mail.python.org/mailman/listinfo/python-list > I think you have missed the point. The OP stated that n<0 could stand for an expensive operation, this replaces an expensive check every time with a cheaper one every time. I like the idea of the interface that was in the original post. Cheers, From Scott.Daniels at Acm.Org Wed Feb 11 04:43:43 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 11 Feb 2009 01:43:43 -0800 Subject: zlib interface semi-broken In-Reply-To: References: Message-ID: Travis wrote: > On Tue, Feb 10, 2009 at 01:36:21PM -0800, Scott David Daniels wrote: >> .... I personally would like it and bz2 to get closer to each other... > > Well, I like this idea; perhaps this is a good time to discuss the > equivalent of some "abstract base classes", or "interfaces", for > compression. > > As I see it, the fundamental abstractions are the stream-oriented > de/compression routines. Given those, one should easily be able to > implement one-shot de/compression of strings. In fact, that is the > way that zlib is implemented; the base functions are the > stream-oriented ones and there is a layer on top of convenience > functions that do one-shot compression and decompression. There are a couple of things here to think about. I've wanted to do some low-level (C-coded) search w/o bothering to create strings until a match. I've no idea how to push this down in, but I may be looking for a nice low-level spot to fit. Characteristics for that could be read-only access to small expansion parts w/o copying them out. Also, in case of a match, a (relatively quick) way to mark points as we proceed and a (possibly slower) way to resrore from one or more marked points. Also, another programmer wants to parallelize _large_ bzip file expansion by expanding independent blocks in separate threads (we know how to find safe start points). To get such code to work, we need to find big chunks of computation, and (at least optionally) surround them with GIL release points. > So what I suggest is a common framework of three APIs; a sequential > compression/decompression API for streams, a layer (potentially > generic) on top of those for strings/buffers, and a third API for > file-like access. Presumably the file-like access can be implemented > on top of the sequential API as well. If we have to be able to start from arbitrary points in bzip files, they have one nasty characteristic: they are bit-serial, and we'll need to start them at arbitrary _bit_ points (not simply byte boundaries). One structure I have used for searching is a result iterator fed by a source iterator, so rather than a read w/ inconvenient boundaries the input side of the thing calls the 'next' method of the provided source. > ... I would rather see a pythonic interface to the libraries than a > simple-as-can-be wrapper around the C functions.... I'm on board with you here. > My further suggestion is that we start with the sequential > de/compression, since it seems like a fundamental primitive. > De/compressing strings will be trivial, and the file-like interface is > already described by Python. Well, to be explicit, are we talking about Decompresion and Compression simultaneously or do we want to start with one of them first? > 2) The de/compression object has routines for reading de/compressed > data and states such as end-of-stream or resynchronization points as > exceptions, much like the file class can throw EOFError. My problem > with this is that client code has to be cognizant of the possible > exceptions that might be thrown, and so one cannot easily add new > exceptions should the need arise. For example, if we add an exception > to indicate a possible resynchronization point, client code may not > be capable of handling it as a non-fatal exception. Seems like we may want to say things like, "synchronization points are too be silently ignored." --Scott David Daniels Scott.Daniels at Acm.Org From robince at gmail.com Wed Feb 11 04:50:04 2009 From: robince at gmail.com (Robin) Date: Wed, 11 Feb 2009 01:50:04 -0800 (PST) Subject: best way to serve wsgi with multiple processes Message-ID: <2d705579-6c7e-46b1-a9f7-4be4c3af487a@t13g2000yqc.googlegroups.com> Hi, I am building some computational web services using soaplib. This creates a WSGI application. However, since some of these services are computationally intensive, and may be long running, I was looking for a way to use multiple processes. I thought about using multiprocessing.Process manually in the service, but I was a bit worried about how that might interact with a threaded server (I was hoping the thread serving that request could just wait until the child is finished). Also it would be good to keep the services as simple as possible so it's easier for people to write them. I have at the moment the following WSGI structure: TransLogger(URLMap(URLParser(soaplib objects))) although presumably, due to the beauty of WSGI, this shouldn't matter. As I've found with all web-related Python stuff, I'm overwhelmed by the choice and number of alternatives. I've so far been using cherrypy and ajp-wsgi for my testing, but am aware of Spawning, twisted etc. What would be the simplest [quickest to setup and fewest details of the server required - ideally with a simple example] and most reliable [this will eventually be 'in production' as part of a large scientific project] way to host this sort of WSGI with a process-per-request style? Thanks! Robin From thorsten at thorstenkampe.de Wed Feb 11 04:55:01 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Wed, 11 Feb 2009 10:55:01 +0100 Subject: ANN: Python 2.6 Quick Reference available References: <4991d7b0$0$4785$426a34cc@news.free.fr> Message-ID: * Richard Gruet (Tue, 10 Feb 2009 20:38:24 +0100) > The Python 2.6 Quick Reference is available in HTML and PDF formats at > http://rgruet.free.fr/#QuickRef. THANK YOU! Thorsten From ramesh.nrk at gmail.com Wed Feb 11 04:56:19 2009 From: ramesh.nrk at gmail.com (nRk) Date: Wed, 11 Feb 2009 01:56:19 -0800 (PST) Subject: urllib2.Request:: http Request sending successfully, but Response contains in valid data. Message-ID: <6119b5e5-a500-48f4-9e9d-51a0974c2c66@n33g2000pri.googlegroups.com> Hi I am trying to send Data to a website through "http" using "urllib.request" library using the bellow code. Response status code contains. 200 (OK) but Response contains nothing... With same data When I test using C# it working fine.. Response having.. some data in xml format. But I am using below python code i am getting response only "". Is there any in my code.. req = urllib2.Request(url) // url is valid url req.add_header('Authorization','AuthSub token="xxxxxxxxxxxxx"') req.add_header('Content-Type','application/atom+xml') req.data=data // data is having valid xml data r = urllib2.urlopen(req) print(r.code) // output 200 print(r.msg) // output OK print(r.read()) // From andrew at acooke.org Wed Feb 11 04:58:54 2009 From: andrew at acooke.org (andrew cooke) Date: Wed, 11 Feb 2009 06:58:54 -0300 (CLST) Subject: Avoiding argument checking in recursive calls In-Reply-To: References: <7xeiy52zfl.fsf@ruckus.brouhaha.com> Message-ID: <1f1aebe9287c2339bc670a6347d65440.squirrel@acooke.dyndns.org> Terry Reedy wrote: > Reverse the test order > > def fact(n): > if n > 0: return fact(n-1)*n > if n == 0: return 1 > raise ValueError sweet! but is this generally possible? ie: did you think this up for this question or is it an idiom that you find yourself using often? andrew From piet at cs.uu.nl Wed Feb 11 05:12:06 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Wed, 11 Feb 2009 11:12:06 +0100 Subject: Distributing simple tasks In-Reply-To: <749CACF29BDFB64E9F80189ECD77868804C00A8C@jermail1.atomant.net> References: <749CACF29BDFB64E9F80189ECD77868804C00A8C@jermail1.atomant.net> Message-ID: Noam Aigerman wrote: > Hi, > > Suppose I have an array of functions which I execute in threads (each > thread get a slice of the array, iterates over it and executes each > function in it?s slice one after the other). Now I want to distribute > these tasks between two machines, i.e give each machine half of the > slices and let it run them in threads as described above. Is there an > easy way, or an article on this matter you can point me to? Have a look at MapReduce (google for MapReduce Python). -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From http Wed Feb 11 05:17:20 2009 From: http (Paul Rubin) Date: 11 Feb 2009 02:17:20 -0800 Subject: zlib interface semi-broken References: Message-ID: <7xskml9t1r.fsf@ruckus.brouhaha.com> Scott David Daniels writes: > Seems like we may want to say things like, "synchronization points are > too be silently ignored." That would completely break some useful possible applications, so should be avoided. From greg at cosc.canterbury.ac.nz Wed Feb 11 05:41:22 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Wed, 11 Feb 2009 23:41:22 +1300 Subject: generator object or 'send' method? In-Reply-To: <929da031-95be-4cda-89ea-560e52435243@e1g2000pra.googlegroups.com> References: <929da031-95be-4cda-89ea-560e52435243@e1g2000pra.googlegroups.com> Message-ID: <6vfo6kFjlnteU1@mid.individual.net> Aaron Brady wrote: > It would receive the 'send' from a different point in control > flow than its usual 'next'. Should it repeat a value if it receives a > 'send'? No. This requirement clearly indicates that send() is the wrong tool for the job. I would use a class with a generator as a method, e.g. class Multiples: m = 1 def set_multiplier(self, m): self.m = m def generate(self, limit): for i in xrange(limit): yield i * self.m g = Multiples() for x in g.generate(10): print x if x == 3: g.set_multiplier(42) produces 0 1 2 3 168 210 252 294 336 378 -- Greg From christopher.saunter at durham.ac.uk Wed Feb 11 06:06:31 2009 From: christopher.saunter at durham.ac.uk (c d saunter) Date: Wed, 11 Feb 2009 11:06:31 +0000 (UTC) Subject: Unexpected string behaviour: txt = 'this' ' works' Message-ID: I did a double take when debugging an error the other day. My problem was missing out a comma when building a list of strings. Much to my surprise the offending code still executed to cause problems later on: >>> txt = 'this', 'works' >>> print txt ('this', 'works') # As expected >>> txt = 'this' 'works' >>> print txt thisworks # Eh? I have never seen this behaviour before, but it works in Python 2.2.1 and 2.5.4 so I guess it's meant to be there. I assume it is a feature of the compiler. Any thoughts? Regards Chris From qgallet at gmail.com Wed Feb 11 06:21:29 2009 From: qgallet at gmail.com (Quentin Gallet-Gilles) Date: Wed, 11 Feb 2009 12:21:29 +0100 Subject: Unexpected string behaviour: txt = 'this' ' works' In-Reply-To: References: Message-ID: <8b943f2b0902110321t40b44567l8050968534787955@mail.gmail.com> *Literal* string concatenation has always been a part of Python : http://docs.python.org/reference/lexical_analysis.html#string-literal-concatenation On Wed, Feb 11, 2009 at 12:06 PM, c d saunter < christopher.saunter at durham.ac.uk> wrote: > I did a double take when debugging an error the other day. My > problem was missing out a comma when building a list of strings. > > Much to my surprise the offending code still executed to cause > problems later on: > > >>> txt = 'this', 'works' > >>> print txt > ('this', 'works') > # As expected > >>> txt = 'this' 'works' > >>> print txt > thisworks > # Eh? > > I have never seen this behaviour before, but it works in Python 2.2.1 > and 2.5.4 so I guess it's meant to be there. I assume it is a feature > of the compiler. > > Any thoughts? > Regards > Chris > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg at cosc.canterbury.ac.nz Wed Feb 11 06:23:39 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Thu, 12 Feb 2009 00:23:39 +1300 Subject: python is great In-Reply-To: <495fd1f5$0$18383$ba4acef3@news.orange.fr> References: <14fa3ad88c5cff33fb4e81deb89ba835@dizum.com> <495fd1f5$0$18383$ba4acef3@news.orange.fr> Message-ID: <6vfqlqFjnknkU1@mid.individual.net> >> python is great. > > No. > > Python is VERY GREAT !!!!!!! All right now, everyone... Every Python's sacred, every Python's great, If any Python's wasted, Guido gets irate! -- Greg From bruno.42.desthuilliers at websiteburo.invalid Wed Feb 11 06:23:57 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 11 Feb 2009 12:23:57 +0100 Subject: Unexpected string behaviour: txt = 'this' ' works' In-Reply-To: References: Message-ID: <4992b53f$0$3507$426a74cc@news.free.fr> c d saunter a ?crit : > I did a double take when debugging an error the other day. My > problem was missing out a comma when building a list of strings. > > Much to my surprise the offending code still executed to cause > problems later on: > >>>> txt = 'this', 'works' >>>> print txt > ('this', 'works') > # As expected >>>> txt = 'this' 'works' >>>> print txt > thisworks > # Eh? > > I have never seen this behaviour before, but it works in Python 2.2.1 > and 2.5.4 so I guess it's meant to be there. I assume it is a feature > of the compiler. > > Any thoughts? http://docs.python.org/reference/lexical_analysis.html#string-literal-concatenation From christopher.saunter at durham.ac.uk Wed Feb 11 06:26:36 2009 From: christopher.saunter at durham.ac.uk (c d saunter) Date: Wed, 11 Feb 2009 11:26:36 +0000 (UTC) Subject: Unexpected string behaviour: txt = 'this' ' works' References: <4992b53f$0$3507$426a74cc@news.free.fr> Message-ID: Bruno Desthuilliers (bruno.42.desthuilliers at websiteburo.invalid) wrote: : c d saunter a ?crit : : > I did a double take when debugging an error the other day. My : > problem was missing out a comma when building a list of strings. : > : > Much to my surprise the offending code still executed to cause : > problems later on: : > : >>>> txt = 'this', 'works' : >>>> print txt : > ('this', 'works') : > # As expected : >>>> txt = 'this' 'works' : >>>> print txt : > thisworks : > # Eh? : > : > I have never seen this behaviour before, but it works in Python 2.2.1 : > and 2.5.4 so I guess it's meant to be there. I assume it is a feature : > of the compiler. : > : > Any thoughts? : http://docs.python.org/reference/lexical_analysis.html#string-literal-concatenation Ahh. Thanks. Chris From robin at reportlab.com Wed Feb 11 07:10:47 2009 From: robin at reportlab.com (Robin Becker) Date: Wed, 11 Feb 2009 12:10:47 +0000 Subject: best way to serve wsgi with multiple processes In-Reply-To: <2d705579-6c7e-46b1-a9f7-4be4c3af487a@t13g2000yqc.googlegroups.com> References: <2d705579-6c7e-46b1-a9f7-4be4c3af487a@t13g2000yqc.googlegroups.com> Message-ID: <4992C047.3060306@chamonix.reportlab.co.uk> Robin wrote: > Hi, > > I am building some computational web services using soaplib. This > creates a WSGI application. > > However, since some of these services are computationally intensive, > and may be long running, I was looking for a way to use multiple > processes. I thought about using multiprocessing.Process manually in > the service, but I was a bit worried about how that might interact > with a threaded server (I was hoping the thread serving that request > could just wait until the child is finished). Also it would be good to > keep the services as simple as possible so it's easier for people to > write them. > > I have at the moment the following WSGI structure: > TransLogger(URLMap(URLParser(soaplib objects))) > although presumably, due to the beauty of WSGI, this shouldn't matter. > > As I've found with all web-related Python stuff, I'm overwhelmed by > the choice and number of alternatives. I've so far been using cherrypy > and ajp-wsgi for my testing, but am aware of Spawning, twisted etc. > What would be the simplest [quickest to setup and fewest details of > the server required - ideally with a simple example] and most reliable > [this will eventually be 'in production' as part of a large scientific > project] way to host this sort of WSGI with a process-per-request > style? > >...... We've used forked fastcgi (flup) with success as that decouples the wsgi process (in our case django) from the main server (in our case apache). Our reasons for doing that were to allow the backend to use modern pythons without having to upgrade the server (which is required if using say mod_python). The wsgi process runs as an ordinary user which eases some tasks. A disadvantage of our scheme is that long running processes may cause problems eg timeouts. In practice since there are no guarantees for how long an http connection will hold up (because of proxies etc etc) we decided to work around this problem. Basically long running jobs go into a task queue on the server and the response is used to reconnect to the long running job peridically for status querying/results etc etc. -- Robin Becker From bearophileHUGS at lycos.com Wed Feb 11 07:16:03 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Wed, 11 Feb 2009 04:16:03 -0800 (PST) Subject: Unexpected string behaviour: txt = 'this' ' works' References: Message-ID: christopher.saun... at durham.ac.uk (c d saunter): >I assume it is a feature of the compiler.< Yes it's a bug-prone antifeature that's probably a relic from C that doesn't have a concatenation operator among strings as Python does (+). So in Python it saves you to use + at the cost of possible bugs. Bye, bearophile From joelc at cognyx.com Wed Feb 11 07:32:16 2009 From: joelc at cognyx.com (Joel Ross) Date: Wed, 11 Feb 2009 23:32:16 +1100 Subject: Variable + String Format In-Reply-To: References: <019ff536$0$20657$c3e8da3@news.astraweb.com> <01a1281b$0$7503$c3e8da3@news.astraweb.com> Message-ID: <01a169a2$0$23675$c3e8da3@news.astraweb.com> Steven D'Aprano wrote: > On Wed, 11 Feb 2009 18:52:40 +1100, Joel Ross wrote: > >> Thanks for the quick response guys. Help me out a alot. I'm a newbie to >> python and your replies help me understand a bit more about python!! > > Joel, unless you have Guido's time machine and are actually posting from > the future, the clock, or possibly the time zone, on your PC is set > wrong. > > I'm from the distant future. Too protect and Serve humankind!!! lol thanks dude. I'm a day ahead of myself. I had my linux box running off UTC and it didn't include daylight savings so I adjusted it myself, must have accidentally changed the day as well :). From benjamin.kaplan at case.edu Wed Feb 11 08:23:41 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 11 Feb 2009 08:23:41 -0500 Subject: cannot install In-Reply-To: <9B4AFD7B-F159-44C5-95D5-A6FCC04548C7@volny.cz> References: <46EB146D-6A7F-4457-A35D-CB0C388C19DB@volny.cz> <5929AA4E-C3C7-42FE-93B0-6D1F11932B73@volny.cz> <9B4AFD7B-F159-44C5-95D5-A6FCC04548C7@volny.cz> Message-ID: 2009/2/11 administrator > I tried as admin with Python-3.0 in my home directory but no success yet. > Is there another help? > > Macintosh:~ admin$ export > PATH=/opt/local/bin:/opt/local/sbin:/Developer/usr/bin:$PATH > Macintosh:~ admin$ echo $PATH > > /opt/local/bin:/opt/local/sbin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/admin:/usr/local/bin:/usr/X11/bin > Macintosh:~ admin$ cd ~/Python-3.0 > Macintosh:Python-3.0 admin$ pwd > /Users/admin/Python-3.0 > Macintosh:Python-3.0 admin$ sudo ./configure --enable-framework > checking for --with-universal-archs... 32-bit > checking MACHDEP... darwin > checking machine type as reported by uname -m... i386 > checking for --without-gcc... no > checking for gcc... gcc > checking for C compiler default output file name... > *configure: error: C compiler cannot create executables* > See `config.log' for more details. > Macintosh:Python-3.0 admin$ > What does config.log say? > > > Regards, Vladimir Zupka > > On 10.2.2009, at 14:35, Benjamin Kaplan wrote: > > > > On Tue, Feb 10, 2009 at 4:07 AM, Vladim?r ?upka wrote: > >> I tried this: >> PATH=$PATH:/Developer/usr/bin >> echo $PATH >> cd /Python-3.0 >> ./configure --enable-framework >> make >> sudo make install >> >> and the result is: >> >> Macintosh:~ vzupka$ /Users/vzupka/Desktop/Python.sh ; exit; >> >> /Library/Frameworks/Python.framework/Versions/Current/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Developer/usr/bin >> checking for --with-universal-archs... 32-bit >> checking MACHDEP... darwin >> checking machine type as reported by uname -m... i386 >> checking for --without-gcc... no >> checking for gcc... gcc >> checking for C compiler default output file name... >> *configure: error: C compiler cannot create executables* >> *See `config.log' for more details.* >> make: *** No targets specified and no makefile found. Stop. >> >> WARNING: Improper use of the sudo command could lead to data loss >> or the deletion of important system files. Please double-check your >> typing when using sudo. Type "man sudo" for more information. >> >> To proceed, enter your password, or type Ctrl-C to abort. >> >> Password: >> logout >> >> [Process completed] >> >> What is wrong with C compiler? Where do I find the 'config.log'? >> > > > config.log should be in Python-3.0. I believe that you have a permissions > problem. ./configure needs to generate the makefiles that tell the compiler > what to do and then the make command will create the executables. Since > you're not in your home directory, you (as a standard user) don't have > permission to write to that directory. Either move Python-3.0 to somewhere > that you have write permissions or use sudo for the whole script. > > > > Vladimir Zupka >> >> On 9.2.2009, at 16:56, Benjamin Kaplan wrote: >> >> >> >> On Mon, Feb 9, 2009 at 9:05 AM, Vladim?r ?upka wrote: >> >>> I have Mac OS X Leopard 10.5.6 and I downloaded and unpacked Python 3.0 >>> into a folder (/Library/Frameworks/Python.framework) and ran commands: >>> >>> cd /Library/Frameworks/Python.framework/Python-3.0 >>> python setup.py install >>> >>> and got the message reporting a syntax error: >>> >>> Macintosh:~ vzupka$ /bin/csh >>> [Macintosh:~] vzupka% cd /Library/Frameworks/Python.framework/Python-3.0 >>> [Macintosh:Frameworks/Python.framework/Python-3.0] vzupka% python >>> setup.py install >>> File "setup.py", line 232 >>> except (CCompilerError, DistutilsError) as why: >>> ^ >>> SyntaxError: invalid syntax >>> [Macintosh:Frameworks/Python.framework/Python-3.0] vzupka% >>> >>> >>> >> >> You can't use setup.py because the python 2.5 on your system (or 2.6 if >> you installed it) is incompatible with Python 3 modules. You need to compile >> Python 3 yourself. It will then automatically call setup.py to create all >> the extension modules. >> >> Just unpack the tarball anywhere and use the following commands Python 3 >> is automatically installed as python3.0, so you don't need to worry about >> overwriting the default python on the system. >> >> ./configure --enable-framework >> make >> sudo make install >> >> more complete instructions are in the Mac/README file, except substitute >> "Python 3.0" everywhere it says "MacPython 2.6". You will probably need to >> install a whole bunch of packages to compile it. configure will tell you >> about them. MacPorts (www.macports.org) and fink (www.finkproject.org) >> provide an easy way to get them. >> >> >>> Regards, >>> Vladim?r ?upka >>> vzupka at volny.cz >>> >>> >>> >>> >>> >>> >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >>> >>> >> >> Vladim?r ?upka >> vzupka at volny.cz >> >> >> >> >> >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From robince at gmail.com Wed Feb 11 08:28:01 2009 From: robince at gmail.com (Robin) Date: Wed, 11 Feb 2009 05:28:01 -0800 (PST) Subject: best way to serve wsgi with multiple processes References: <2d705579-6c7e-46b1-a9f7-4be4c3af487a@t13g2000yqc.googlegroups.com> Message-ID: On Feb 11, 12:10?pm, Robin Becker wrote: > We've used forked fastcgi (flup) with success as that decouples the wsgi process > (in our case django) from the main server (in our case apache). Our reasons for > doing that were to allow the backend to use modern pythons without having to > upgrade the server (which is required if using say mod_python). The wsgi process > runs as an ordinary user which eases some tasks. Yes - I've done something very similar with ajp-wsgi (from the author of flup; and which incidently performs very well works really nicely) to go from apache -> wsgi. But the issue I'm asking about here is to have multiple WSGI processes - ie to allow concurrent execution of more than one web service at the time (since these are long running computational soap web services). ajp-wsgi embeds a single python interpreter so multiple running services would be effected by the GIL - I imagine flup is similar (a single process on the python side). So I'm not worried about decoupling from the web server - I'm happy to use pure python server (which I guess is easier to setup) - but I want the web server to dispatch requests to different processes running the wsgi app. I've looked at Spawning, but couldn't get it to work and it seems a little bit 'beta' for my taste (doesn't exit cleanly, leaves worker processes running etc.) Cheers Robin From pete.forman at westerngeco.com Wed Feb 11 08:42:26 2009 From: pete.forman at westerngeco.com (Pete Forman) Date: Wed, 11 Feb 2009 13:42:26 +0000 Subject: optparse versus getopt References: <4991F3DB.5000802@tim.thechases.com> Message-ID: <63jhum2l.fsf@wgmail2.gatwick.eur.slb.com> Robert Kern writes: >> is there some way i can force the import based on the the absolute >> path to the module? > > Better would be for you to copy the optparse.py module onto your > Jython's import path. I'm not particularly familiar with the details > of Jython, so you will need to consult with the Jython documentation > unless if a Jython expert can jump in here. Here is one message > describing this procedure: > > http://osdir.com/ml/lang.jython.user/2004-01/msg00086.html Here are notes from some of my code which can run on Jython. You might also like to check out Jython 2.5 which is in beta. Jython 2.2 needs optparse.py and textwrap.py. These can be copied from Python 2.3 or Optik 1.4.1 or later. May also need gettext.py and locale.py. -- Pete Forman -./\.- Disclaimer: This post is originated WesternGeco -./\.- by myself and does not represent pete.forman at westerngeco.com -./\.- the opinion of Schlumberger or http://petef.22web.net -./\.- WesternGeco. From steve at holdenweb.com Wed Feb 11 09:26:38 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 11 Feb 2009 09:26:38 -0500 Subject: getopt index out of range In-Reply-To: References: Message-ID: Matthew Sacks wrote: > Hi List, > I am getting an index out of range error when trying to parse with getopt. > Probably something simple. Any suggestions are appreciated > > optlist, args = getopt.getopt(sys.argv[1:], 'h', ['connectPassword=', > 'adminServerURL=', 'action=', 'targets=', 'appDir=']) > > > #Assign Opts > connectPassword = optlist[0][1] > adminServerURL = optlist[1][1] > action = optlist[2][1] > targets = optlist[3][1] > appDir = optlist[4][1] > > #this statement never gets executed > print "Args: " + connectPassword + " " + adminServerURL + " " + action > + " " + targets + " " + appDir > > File "/home/msacks/untitled4.py", line 23, in ? > IndexError: index out of range: 0 > It might help a little if you made it more obvious which was line 23 ... The real problem, though, is a misunderstanding of what getopt.getopt() returns. The (option, value) pairs are only returned for options found in the command line, so you can't guarantee there'll be four. Set your values to defaults, then adjust for those for which an option is found in the list, as in the "typical usage" example in the Fine Manual. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Wed Feb 11 09:42:45 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 11 Feb 2009 09:42:45 -0500 Subject: Functional schmunctional... In-Reply-To: References: Message-ID: Terry Reedy wrote: > r0g wrote: > >> >> def inet2ip(n): >> p = (n/16777216) >> q = ((n-(p*16777216))/65536) >> r = ((n-((p*16777216)+(q*65536)))/256) >> s = ((n-((p*16777216)+(q*65536)+(r*256)))) >> return str(p)+"."+str(q)+"."+str(r)+"."+str(s) > > Beyond what other wrote: > To future-proof code, use // instead of / for integer division. > To get both quotient and remainder, use divmod(num,den) > For future reading (and generalization) documenting magic constants helps. > > In 3.0: > > def inet2ip(n): > p = (n//16777216) > q = ((n-(p*16777216))//65536) > r = ((n-((p*16777216)+(q*65536)))//256) > s = ((n-((p*16777216)+(q*65536)+(r*256)))) > return str(p)+"."+str(q)+"."+str(r)+"."+str(s) > > def inet2ip2(n): > p,n=divmod(n,16777216) # 1<<24 > q,n=divmod(n,65536) # 1<<16 > r,s=divmod(n,256) # 1<<8 > return str(p)+"."+str(q)+"."+str(r)+"."+str(s) > > print(inet2ip(1000000000), inet2ip2(1000000000)) > >>>> > 59.154.202.0 59.154.202.0 > Jeez, doesn't anyone read the fine manual any more? I hope this was just an academic exercise. >>> socket.inet_ntoa(struct.pack("!l", 1000000000)) '59.154.202.0' >>> Holden's rule: when it looks simple enough to be worth including in the standard library it may well already *be* in the standard library. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From jonathan.chacon at telefonica.net Wed Feb 11 09:44:45 2009 From: jonathan.chacon at telefonica.net (=?iso-8859-1?Q?Jonathan_Chac=F3n?=) Date: Wed, 11 Feb 2009 15:44:45 +0100 Subject: Get an image from a webcam in macOS Message-ID: Hello, I can get an Image from a webcam in windows but I don't know how can I get an image from the webcam in a macbook in leopard. How can I do this? thanks and regards Jonathan Chac?n -------------- next part -------------- An HTML attachment was scrubbed... URL: From google at mrabarnett.plus.com Wed Feb 11 10:11:24 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 11 Feb 2009 15:11:24 +0000 Subject: getopt index out of range In-Reply-To: References: Message-ID: <4992EA9C.4010207@mrabarnett.plus.com> Steve Holden wrote: > Matthew Sacks wrote: >> Hi List, >> I am getting an index out of range error when trying to parse with getopt. >> Probably something simple. Any suggestions are appreciated >> >> optlist, args = getopt.getopt(sys.argv[1:], 'h', ['connectPassword=', >> 'adminServerURL=', 'action=', 'targets=', 'appDir=']) >> >> >> #Assign Opts >> connectPassword = optlist[0][1] >> adminServerURL = optlist[1][1] >> action = optlist[2][1] >> targets = optlist[3][1] >> appDir = optlist[4][1] >> >> #this statement never gets executed >> print "Args: " + connectPassword + " " + adminServerURL + " " + action >> + " " + targets + " " + appDir >> >> File "/home/msacks/untitled4.py", line 23, in ? >> IndexError: index out of range: 0 >> > It might help a little if you made it more obvious which was line 23 ... > It a guess I'd say it was: connectPassword = optlist[0][1] because the traceback says the index is 0 and there's only one line with a 0 in it! > The real problem, though, is a misunderstanding of what getopt.getopt() > returns. The (option, value) pairs are only returned for options found > in the command line, so you can't guarantee there'll be four. > > Set your values to defaults, then adjust for those for which an option > is found in the list, as in the "typical usage" example in the Fine Manual. > From robince at gmail.com Wed Feb 11 10:12:43 2009 From: robince at gmail.com (Robin) Date: Wed, 11 Feb 2009 07:12:43 -0800 (PST) Subject: best way to serve wsgi with multiple processes References: <2d705579-6c7e-46b1-a9f7-4be4c3af487a@t13g2000yqc.googlegroups.com> Message-ID: On Feb 11, 1:28?pm, Robin wrote: > On Feb 11, 12:10?pm, Robin Becker wrote: > > > We've used forked fastcgi (flup) with success as that decouples the wsgi process > > (in our case django) from the main server (in our case apache). Our reasons for > > doing that were to allow the backend to use modern pythons without having to > > upgrade the server (which is required if using say mod_python). The wsgi process > > runs as an ordinary user which eases some tasks. I'm sorry - I originally missed the worked 'forked' and hence the whole point of your message I think. I looked at flup before but had forgotten about the forked version. Having revisited it I think the forked version does keep a process pool so each request is processed by a seperate process, which is exactly what I wanted. Cheers Robin From jaywgraves at gmail.com Wed Feb 11 10:13:13 2009 From: jaywgraves at gmail.com (jay graves) Date: Wed, 11 Feb 2009 07:13:13 -0800 (PST) Subject: Pycon 2009 Hotel? Message-ID: <3bb02ed2-bb89-4092-bfea-b9356f214fc6@i18g2000prf.googlegroups.com> I'm attending Pycon this year and for the first time I have to pay for myself. (All training/conference budgets have been zeroed out at my company.) I would like to take the cheaper option by staying at the Crowne Plaza but as I understand it, the part of the conference I'll be attending will be held at the Hyatt Regency. I don't mind the walk but I also don't want to miss out on the open spaces in the evening. Is anyone else similarly on the fence? I'd like to save $130 ((153 - 100) * 3) but since I'm not staying for the sprints and alot of my enjoyment of the conference is the open spaces. From deets at nospam.web.de Wed Feb 11 10:16:43 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 11 Feb 2009 16:16:43 +0100 Subject: best way to serve wsgi with multiple processes References: <2d705579-6c7e-46b1-a9f7-4be4c3af487a@t13g2000yqc.googlegroups.com> Message-ID: <6vg8erFjrh7aU1@mid.uni-berlin.de> Robin wrote: > On Feb 11, 1:28?pm, Robin wrote: >> On Feb 11, 12:10?pm, Robin Becker wrote: >> >> > We've used forked fastcgi (flup) with success as that decouples the >> > wsgi process (in our case django) from the main server (in our case >> > apache). Our reasons for doing that were to allow the backend to use >> > modern pythons without having to upgrade the server (which is required >> > if using say mod_python). The wsgi process runs as an ordinary user >> > which eases some tasks. > > I'm sorry - I originally missed the worked 'forked' and hence the > whole point of your message I think. > > I looked at flup before but had forgotten about the forked version. > Having revisited it I think the forked version does keep a process > pool so each request is processed by a seperate process, which is > exactly what I wanted. You can have that with mod_wsgi & daemon mode as well, with presumably less setup hassle. Diez From jaywgraves at gmail.com Wed Feb 11 10:17:38 2009 From: jaywgraves at gmail.com (jay graves) Date: Wed, 11 Feb 2009 07:17:38 -0800 (PST) Subject: Pycon 2009 Hotel? References: <3bb02ed2-bb89-4092-bfea-b9356f214fc6@i18g2000prf.googlegroups.com> Message-ID: <770f9939-2623-4562-84cf-ad419b7fbcbf@r15g2000prd.googlegroups.com> On Feb 11, 9:13?am, jay graves wrote: > I'm attending Pycon this year and for the first time I have to pay for > myself. ?(All training/conference budgets have been zeroed out at my > company.) > > I would like to take the cheaper option by staying at the Crowne Plaza > but as I understand it, the part of the conference I'll be attending > will be held at the Hyatt Regency. ?I don't mind the walk but I also > don't want to miss out on the open spaces in the evening. > > Is anyone else similarly on the fence? ?I'd like to save $130 ((153 - > 100) * 3) but since I'm not staying for the sprints and alot of my > enjoyment of the conference is the open spaces. (Sorry. i hit 'Send' too quickly.) I'm wondering if I'm being 'penny-wise and pound-foolish'? I'd hate to spend all that money to get there and then not enjoy it because I was at the 'other' hotel. ... Jay Graves From michele.simionato at gmail.com Wed Feb 11 10:18:53 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Wed, 11 Feb 2009 07:18:53 -0800 (PST) Subject: Functional schmunctional... References: Message-ID: On Feb 10, 9:28?pm, r0g wrote: > def ip2inet(a): > ? li = a.split('.') > ? assert len(li) == 4 or len(li) == 6 > ? return reduce(add,[int(li[e])*(256**((len(li)-1)-e)) for e in > xrange(0,len(li))]) Aagh! Notice that functional programming is not about filter, map, reduce and other unreadable constructs: it is much more about avoiding mutation. Your problem has been already solved by using the standard library; however, if you want to know more about functional programming, I could as well advertise my own series of "Adventures of a Pythonista in Schemeland" which is facing exactly that topic right now: http://www.artima.com/weblogs/viewpost.jsp?thread=248953 From nick at craig-wood.com Wed Feb 11 10:31:56 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Wed, 11 Feb 2009 09:31:56 -0600 Subject: Escaping my own chroot... References: Message-ID: r0g wrote: > I'm writing a linux remastering script in python where I need to chroot > into a folder, run some system commands and then come out and do some > tidying up, un-mounting proc & sys etc. > > I got in there with os.chroot() and I tried using that to get back out > but that didn't work so... is my script trapped in there forever now or > is there an un-hacky way to escape? No! > If it is an OS restriction rather than my ignorance of python is there a > canonical way of dealing with it? Should I maybe fork a process, have it > do the chroot and wait for it to terminate before continuing? That is the only way... However this is a solved problem if you use schroot (which works very well in my experience) http://packages.debian.org/sid/schroot http://www.debian-administration.org/articles/566 There are definitely debian, ubuntu and centos packages for it if you look! -- Nick Craig-Wood -- http://www.craig-wood.com/nick From meshko at gmail.com Wed Feb 11 10:33:29 2009 From: meshko at gmail.com (mk) Date: Wed, 11 Feb 2009 07:33:29 -0800 (PST) Subject: SOAP client Message-ID: Hi, I'm trying to consume a SOAP web service using Python. So far I have found two libraries: SOAPpy and ZSI. Both of them rely on PyXML which is no longer maintained (and there is no build for 64bit Windows and the setup.py doesn't seem to know how to build it on Windows). Is there a live SOAP library for Python? I'm sort of surprised that a common standard like SOAP is not more actively supported in Python. I'm probably missing something? Thanks, m From kmmcdonald at medicine.wisc.edu Wed Feb 11 10:43:22 2009 From: kmmcdonald at medicine.wisc.edu (Ken McDonald) Date: Wed, 11 Feb 2009 09:43:22 -0600 Subject: access to MS Access password-protected database? Message-ID: <494C99A4-E73E-47C1-B51D-AE8C29E63687@medicine.wisc.edu> Can anyone direct me towards a code snippet showing how to use Python to insert data into a password-protected MS Access database? My google searches have been uninformative for dbs that are password-protected. Thanks, Ken From joaorabelo at gmail.com Wed Feb 11 10:44:27 2009 From: joaorabelo at gmail.com (=?ISO-8859-1?Q?Jo=E3o_Rabelo?=) Date: Wed, 11 Feb 2009 13:44:27 -0200 Subject: No subject Message-ID: <21d3d9990902110744r2033d4b2w68bf93ce26997c58@mail.gmail.com> -------------- next part -------------- An HTML attachment was scrubbed... URL: From robin at reportlab.com Wed Feb 11 10:46:45 2009 From: robin at reportlab.com (Robin Becker) Date: Wed, 11 Feb 2009 15:46:45 +0000 Subject: best way to serve wsgi with multiple processes In-Reply-To: References: <2d705579-6c7e-46b1-a9f7-4be4c3af487a@t13g2000yqc.googlegroups.com> Message-ID: <4992F2E5.1000002@chamonix.reportlab.co.uk> Robin wrote: .......... > > Yes - I've done something very similar with ajp-wsgi (from the author > of flup; and which incidently performs very well works really nicely) > to go from apache -> wsgi. But the issue I'm asking about here is to > have multiple WSGI processes - ie to allow concurrent execution of > more than one web service at the time (since these are long running > computational soap web services). ajp-wsgi embeds a single python > interpreter so multiple running services would be effected by the GIL > - I imagine flup is similar (a single process on the python side). > > So I'm not worried about decoupling from the web server - I'm happy to > use pure python server (which I guess is easier to setup) - but I want > the web server to dispatch requests to different processes running the > wsgi app. I've looked at Spawning, but couldn't get it to work and it > seems a little bit 'beta' for my taste (doesn't exit cleanly, leaves > worker processes running etc.) well the flup server for fast cgi supports forking if the server is declared as an external process in apache. Then the top level of the flup process handles each request and passes it off to a forked worker. I cannot recall exactly, but I believe that apache mod_fastcgi does the right thing when it comes to internally declared fastcgi handlers. For apache at least I think the threading issues are handled properly. I think the preforkserver.py code handles all the threading issues for you (assuming it's not win32). -- Robin Becker From tino at wildenhain.de Wed Feb 11 10:47:56 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Wed, 11 Feb 2009 16:47:56 +0100 Subject: urllib2.Request:: http Request sending successfully, but Response contains in valid data. In-Reply-To: <6119b5e5-a500-48f4-9e9d-51a0974c2c66@n33g2000pri.googlegroups.com> References: <6119b5e5-a500-48f4-9e9d-51a0974c2c66@n33g2000pri.googlegroups.com> Message-ID: <4992F32C.3050402@wildenhain.de> Hi, nRk wrote: > Hi > > I am trying to send Data to a website through "http" using > "urllib.request" library using the bellow code. > Response status code contains. 200 (OK) but Response contains > nothing... > > With same data When I test using C# it working fine.. Response > having.. some data in xml format. > But I am using below python code i am getting response only " HTML>". This does not mean you are doing it identical to C# here, doesn't it? Also you might be looking at the defaults in the calls within C# and some weird expectations on server side. Also you are requesting XML by sending a payload of XML data, so you need to make sure you actually use POST and not GET. I'd start by watching your working application with strace or wireshark and compare with the data to and fro from your python application. Also I believe there should be example code for reading RSS feeds from python. > Is there any in my code.. > > req = urllib2.Request(url) // url is valid url > req.add_header('Authorization','AuthSub token="xxxxxxxxxxxxx"') > req.add_header('Content-Type','application/atom+xml') > req.data=data // data is having valid xml data > r = urllib2.urlopen(req) > print(r.code) // output 200 > print(r.msg) // output OK > print(r.read()) // Regards Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From mal at egenix.com Wed Feb 11 10:48:31 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Wed, 11 Feb 2009 16:48:31 +0100 Subject: best way to serve wsgi with multiple processes In-Reply-To: <6vg8erFjrh7aU1@mid.uni-berlin.de> References: <2d705579-6c7e-46b1-a9f7-4be4c3af487a@t13g2000yqc.googlegroups.com> <6vg8erFjrh7aU1@mid.uni-berlin.de> Message-ID: <4992F34F.2040306@egenix.com> On 2009-02-11 16:16, Diez B. Roggisch wrote: > Robin wrote: > >> On Feb 11, 1:28 pm, Robin wrote: >>> On Feb 11, 12:10 pm, Robin Becker wrote: >>> >>>> We've used forked fastcgi (flup) with success as that decouples the >>>> wsgi process (in our case django) from the main server (in our case >>>> apache). Our reasons for doing that were to allow the backend to use >>>> modern pythons without having to upgrade the server (which is required >>>> if using say mod_python). The wsgi process runs as an ordinary user >>>> which eases some tasks. >> I'm sorry - I originally missed the worked 'forked' and hence the >> whole point of your message I think. >> >> I looked at flup before but had forgotten about the forked version. >> Having revisited it I think the forked version does keep a process >> pool so each request is processed by a seperate process, which is >> exactly what I wanted. > > You can have that with mod_wsgi & daemon mode as well, with presumably less > setup hassle. Another option that works well on Unix and even Windows is SCGI which deals with the forking and piping of data for you: http://www.mems-exchange.org/software/scgi/ http://python.ca/scgi/ Lighttpd even ships with a mod_scgi module built-in. More on the protocol used by SCGI (basically net-strings): http://python.ca/scgi/protocol.txt Unlike FastCGI, it's very easy to setup. Since SCGI provides standard CGI on the Python side, it's easy to wrap this up as WSGI interface (using e.g. the code from PEP 333). -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Feb 11 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From mail at timgolden.me.uk Wed Feb 11 11:17:40 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 11 Feb 2009 16:17:40 +0000 Subject: access to MS Access password-protected database? In-Reply-To: <494C99A4-E73E-47C1-B51D-AE8C29E63687@medicine.wisc.edu> References: <494C99A4-E73E-47C1-B51D-AE8C29E63687@medicine.wisc.edu> Message-ID: <4992FA24.50601@timgolden.me.uk> Ken McDonald wrote: > Can anyone direct me towards a code snippet showing how to use Python to > insert data into a password-protected MS Access database? My google > searches have been uninformative for dbs that are password-protected. Caveat: I've never done it and I have no Access db to hand, but in a spirit of being helpful... According to this snippet: http://www.vb-helper.com/howto_ado_use_access_password.html it can be done via ADO. You can either roll your own, or you can use the adodbapi module from the pywin32 extensions. TJG From gil.shinar at gmail.com Wed Feb 11 11:18:58 2009 From: gil.shinar at gmail.com (gil.shinar at gmail.com) Date: Wed, 11 Feb 2009 08:18:58 -0800 (PST) Subject: Process crash with no reason References: <30c13ac1-0ad0-4825-8d5c-301d505e6b66@p2g2000prn.googlegroups.com> <6732e3c4-8fcc-45c8-8e62-aea7eb64d942@j1g2000yqi.googlegroups.com> Message-ID: On Feb 8, 5:31?pm, Stephen Hansen wrote: > > Thanks a lot and sorry for the late response. My main suspect is the > > CherryPy. > > I'm still investigating it. > > You're asking for advice but not listening to what people are saying > here -- why is CherryPy on the top of your list? > > What version of CherryPy is it? 1 or 2? > > If its 2, then its pure python and there's a really, really low chance > that its provoking a hard crash w/o a traceback printing before it > dies out. A hard crash which isn't printing an error message is > possible in pure Python I suppose, but I've never seen it. A "Bus > error" for example will kill the interpreter before it can do any > error handling. But I've only ever seen that when interfacing with > third party libraries. > > If its 1, there is some C so you can bump it up ... and for that I'd > probably attempt to run the application in a console or with stdout > manually redirected instead of relying on the logging alone, to see if > anything useful gets put out.. like "Bus error", at the time it exits. > > But why do you keep discarding the Sybase module? > > Its most definitely *not* written in python. What Philip and Tim were > trying to tell you is you are *not* using "python's functions to run > sybase sql commands" > > The Sybase module is a python wrapper around code written in C module > which is interfacing with a third party library to talk to Sybase. Are > you at the latest version of Sybase(0.39 if its the same module I'm > aware of?) How about the library underneath it? FreeTDS or Sybase ASE > (whatever that is) or whatever else is being used? A bug in /any/ of > those C layers (notice its *multiple* layers) could propagate up and > provoke a hard crash that Python doesn't catch. So if you look into > those versions perhaps one has a new release that fixes bugs. > > --S Hi, After farther investigation and some help from other developers, we got to the conclusion that the python process does not crash but the program exits because cherrypy freezes and the python program has nothing to do when the web service is not responding. My cherrypy version is 3.0.1 Can any of you help me with cherrypy or should I ask in cherrypy group? Thanks Gil From robince at gmail.com Wed Feb 11 11:19:05 2009 From: robince at gmail.com (Robin) Date: Wed, 11 Feb 2009 08:19:05 -0800 (PST) Subject: best way to serve wsgi with multiple processes References: <2d705579-6c7e-46b1-a9f7-4be4c3af487a@t13g2000yqc.googlegroups.com> Message-ID: <79153440-e1ae-4703-990c-9c69cd85ee6c@k19g2000yqg.googlegroups.com> On Feb 11, 3:46?pm, Robin Becker wrote: > well the flup server for fast cgi supports forking if the server is declared as > an external process in apache. Then the top level of the flup process handles > each request and passes it off to a forked worker. I cannot recall exactly, but > I believe that apache mod_fastcgi does the right thing when it comes to > internally declared fastcgi handlers. For apache at least I think the threading > issues are handled properly. > > I think the preforkserver.py code handles all the threading issues for you > (assuming it's not win32). Thanks - I think if I go the flup route I would use AJP though - since its very easy to setup with apache (1 proxy line) and mod_ajp comes as standard. And then everything is very much seperated from the apache process. From robince at gmail.com Wed Feb 11 11:20:23 2009 From: robince at gmail.com (Robin) Date: Wed, 11 Feb 2009 08:20:23 -0800 (PST) Subject: SOAP client References: Message-ID: <9670bb81-a879-43cc-8abf-040e7b18c59d@q9g2000yqc.googlegroups.com> On Feb 11, 3:33?pm, mk wrote: > Hi, > > I'm trying to consume a SOAP web service using Python. ?So far I have > found two libraries: SOAPpy and ZSI. ?Both of them rely on PyXML which > is no longer maintained (and there is no build for 64bit Windows and > the setup.py doesn't seem to know how to build it on Windows). ?Is > there a live SOAP library for Python? ?I'm sort of surprised that a > common standard like SOAP is not more actively supported in Python. > I'm probably missing something? > > Thanks, > m For consuming services, I've found suds to be the best client: https://fedorahosted.org/suds/ For creating them, I've been using soaplib: http://trac.optio.webfactional.com/ HTH, Robin From kyosohma at gmail.com Wed Feb 11 11:26:39 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Wed, 11 Feb 2009 08:26:39 -0800 (PST) Subject: Pycon 2009 Hotel? References: <3bb02ed2-bb89-4092-bfea-b9356f214fc6@i18g2000prf.googlegroups.com> <770f9939-2623-4562-84cf-ad419b7fbcbf@r15g2000prd.googlegroups.com> Message-ID: <773f47dc-3bab-407d-a752-b09bc3aaf06f@p13g2000yqc.googlegroups.com> On Feb 11, 9:17?am, jay graves wrote: > On Feb 11, 9:13?am, jay graves wrote: > > > I'm attending Pycon this year and for the first time I have to pay for > > myself. ?(All training/conference budgets have been zeroed out at my > > company.) > > > I would like to take the cheaper option by staying at the Crowne Plaza > > but as I understand it, the part of the conference I'll be attending > > will be held at the Hyatt Regency. ?I don't mind the walk but I also > > don't want to miss out on the open spaces in the evening. > > > Is anyone else similarly on the fence? ?I'd like to save $130 ((153 - > > 100) * 3) but since I'm not staying for the sprints and alot of my > > enjoyment of the conference is the open spaces. > > (Sorry. i hit 'Send' too quickly.) > > I'm wondering if I'm being 'penny-wise and pound-foolish'? ?I'd hate > to spend all that money to get there and then not enjoy it because I > was at the 'other' hotel. > > ... > Jay Graves As I understand it, the hotels are connected via a skywalk, so I don't think it will be a big deal either way. It just means a little extra walking. Mike From notvalid2 at sbcglobal.net Wed Feb 11 11:28:01 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Wed, 11 Feb 2009 08:28:01 -0800 Subject: Who's on First, IDLE or pythonWin? Dialog Problem? Message-ID: My program in IDLE bombed with: ============== Exception in Tkinter callback Traceback (most recent call last): File "C:\Python25\lib\lib-tk\Tkinter.py", line 1403, in __call__ return self.func(*args) File "C:\Sandia_Meteors\New_Sentinel_Development\Sentuser_Utilities_Related\sentuser\sentuserNC25-Dev4.py", line 552, in OperationalSettings dialog = OperationalSettingsDialog( self.master, set_loc_dict ) File "C:\Sandia_Meteors\New_Sentinel_Development\Sentuser_Utilities_Related\sentuser\sentuserNC25-Dev4.py", line 81, in __init__ tkSimpleDialog.Dialog.__init__(self, parent) File "C:\Python25\lib\lib-tk\tkSimpleDialog.py", line 69, in __init__ self.wait_visibility() # window needs to be visible for the grab File "C:\Python25\lib\lib-tk\Tkinter.py", line 415, in wait_visibility self.tk.call('tkwait', 'visibility', window._w) TclError: window ".34672232" was deleted before its visibility changed =============== It runs fine in pythonWin performing the same entry operation. Open a menu, select an item to open a dialog, select a select button in the dialog, press OK to leave the dialog. Boom, as above. (This does not mean pythonWin doesn't have problems of its own. ) If I just execute the code (double click on the py file, the console shows no problems. IDLE is unhappy. Another side to this is that I use WinMerge to find differences between my last saved copy and the current copy. I found the current copy had two lines where a abc.get() was changed to abc.get. This was undoubtedly from briefly using the pyWin editor, when I mis-hit some keys. Yet pyWin had no trouble executing the program. My guess is that while briefly editing there, I hit some odd combination of keys that produced, perhaps, an invisible character that pyWin ignores. Not the 34672232 window is a dialog that I closed by pressing OK. I would again guess, that, if there is a problem, it occurs in the code that destroys the dialog. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From robin at reportlab.com Wed Feb 11 11:32:42 2009 From: robin at reportlab.com (Robin Becker) Date: Wed, 11 Feb 2009 16:32:42 +0000 Subject: best way to serve wsgi with multiple processes In-Reply-To: <79153440-e1ae-4703-990c-9c69cd85ee6c@k19g2000yqg.googlegroups.com> References: <2d705579-6c7e-46b1-a9f7-4be4c3af487a@t13g2000yqc.googlegroups.com> <79153440-e1ae-4703-990c-9c69cd85ee6c@k19g2000yqg.googlegroups.com> Message-ID: <4992FDAA.8090908@chamonix.reportlab.co.uk> Robin wrote: > On Feb 11, 3:46 pm, Robin Becker wrote: >> well the flup server for fast cgi supports forking if the server is declared as >> an external process in apache. Then the top level of the flup process handles >> each request and passes it off to a forked worker. I cannot recall exactly, but >> I believe that apache mod_fastcgi does the right thing when it comes to >> internally declared fastcgi handlers. For apache at least I think the threading >> issues are handled properly. >> >> I think the preforkserver.py code handles all the threading issues for you >> (assuming it's not win32). > > Thanks - I think if I go the flup route I would use AJP though - since > its very easy to setup with apache (1 proxy line) and mod_ajp comes as > standard. And then everything is very much seperated from the apache > process. ....... that's right and very easy to control. The only problem I recall is that the socket needs to be made readable by www. You can do that with a sudo chown or by setting up the mask at the ajp server start. -- Robin Becker From exarkun at divmod.com Wed Feb 11 11:35:32 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Wed, 11 Feb 2009 11:35:32 -0500 Subject: Escaping my own chroot... In-Reply-To: Message-ID: <20090211163532.12853.310274003.divmod.quotient.8899@henry.divmod.com> On Wed, 11 Feb 2009 09:31:56 -0600, Nick Craig-Wood wrote: >r0g wrote: >> I'm writing a linux remastering script in python where I need to chroot >> into a folder, run some system commands and then come out and do some >> tidying up, un-mounting proc & sys etc. >> >> I got in there with os.chroot() and I tried using that to get back out >> but that didn't work so... is my script trapped in there forever now or >> is there an un-hacky way to escape? > >No! > If you still have root in the chroot (and you need root to get in there, so it's not implausible that you will), then you can get out. Googling for "escape chroot" turns up lots of hits. This page contains a fairly simple, explicit description of how to get out of a chroot: http://www.bpfh.net/simes/computing/chroot-break.html See the bulleted list in the "Breaking chroot()" section. Since you also control the process before the chroot happens, breaking out is even simpler in your case (just open / before you chroot in the first place). forking before doing the chroot may still be a good idea, but it's not the only solution. Jean-Paul From kyosohma at gmail.com Wed Feb 11 11:44:55 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Wed, 11 Feb 2009 08:44:55 -0800 (PST) Subject: Who's on First, IDLE or pythonWin? Dialog Problem? References: Message-ID: On Feb 11, 10:28?am, "W. eWatson" wrote: > My program in IDLE bombed with: > ============== > Exception in Tkinter callback > Traceback (most recent call last): > ? ?File "C:\Python25\lib\lib-tk\Tkinter.py", line 1403, in __call__ > ? ? ?return self.func(*args) > ? ?File > "C:\Sandia_Meteors\New_Sentinel_Development\Sentuser_Utilities_Related\sentuser\sentuserNC25-Dev4.py", > line 552, in OperationalSettings > ? ? ?dialog = OperationalSettingsDialog( self.master, set_loc_dict ) > ? ?File > "C:\Sandia_Meteors\New_Sentinel_Development\Sentuser_Utilities_Related\sentuser\sentuserNC25-Dev4.py", > line 81, in __init__ > ? ? ?tkSimpleDialog.Dialog.__init__(self, parent) > ? ?File "C:\Python25\lib\lib-tk\tkSimpleDialog.py", line 69, in __init__ > ? ? ?self.wait_visibility() # window needs to be visible for the grab > ? ?File "C:\Python25\lib\lib-tk\Tkinter.py", line 415, in wait_visibility > ? ? ?self.tk.call('tkwait', 'visibility', window._w) > TclError: window ".34672232" was deleted before its visibility changed > =============== > It runs fine in pythonWin performing the same entry operation. Open a menu, > ? select an item to open a dialog, select a select button in the dialog, > press OK to leave the dialog. Boom, as above. > > (This does not mean pythonWin doesn't have problems of its own. ) If I just > execute the code (double click on the py file, the console shows no > problems. IDLE is unhappy. > > Another side to this is that I use WinMerge to find differences between my > last saved copy and the current copy. I found the current copy had two lines > where a abc.get() was changed to abc.get. This was undoubtedly from briefly > using the pyWin editor, when I mis-hit some keys. Yet pyWin had no trouble > executing the program. My guess is that while briefly editing there, I hit > some odd combination of keys that produced, perhaps, an invisible character > that pyWin ignores. > > Not the 34672232 window is a dialog that I closed by pressing OK. I would > again guess, that, if there is a problem, it occurs in the code that > destroys the dialog. > > -- > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? W. eWatson > > ? ? ? ? ? ? ? (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) > ? ? ? ? ? ? ? ?Obz Site: ?39? 15' 7" N, 121? 2' 32" W, 2700 feet > > ? ? ? ? ? ? ? ? ? ? ?Web Page: You don't really say what your code does or if it uses a GUI toolkit and if so, which one. But my guess is that you are using some kind of GUI and its GUI and IDLE's are clashing somehow. I see this sort of thing with some of my wxPython programs from time to time, although IDLE usually just crashes with no error message. I would recommend using the command line or something that can open it in a completely separate process, such as Wingware's IDE. Mike From steve at holdenweb.com Wed Feb 11 11:48:49 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 11 Feb 2009 11:48:49 -0500 Subject: Who's on First, IDLE or pythonWin? Dialog Problem? In-Reply-To: References: Message-ID: W. eWatson wrote: > My program in IDLE bombed with: > ============== > Exception in Tkinter callback > Traceback (most recent call last): > File "C:\Python25\lib\lib-tk\Tkinter.py", line 1403, in __call__ > return self.func(*args) > File > "C:\Sandia_Meteors\New_Sentinel_Development\Sentuser_Utilities_Related\sentuser\sentuserNC25-Dev4.py", > line 552, in OperationalSettings > dialog = OperationalSettingsDialog( self.master, set_loc_dict ) > File > "C:\Sandia_Meteors\New_Sentinel_Development\Sentuser_Utilities_Related\sentuser\sentuserNC25-Dev4.py", > line 81, in __init__ > tkSimpleDialog.Dialog.__init__(self, parent) > File "C:\Python25\lib\lib-tk\tkSimpleDialog.py", line 69, in __init__ > self.wait_visibility() # window needs to be visible for the grab > File "C:\Python25\lib\lib-tk\Tkinter.py", line 415, in wait_visibility > self.tk.call('tkwait', 'visibility', window._w) > TclError: window ".34672232" was deleted before its visibility changed > =============== > It runs fine in pythonWin performing the same entry operation. Open a > menu, select an item to open a dialog, select a select button in the > dialog, press OK to leave the dialog. Boom, as above. > > (This does not mean pythonWin doesn't have problems of its own. ) If I > just execute the code (double click on the py file, the console shows no > problems. IDLE is unhappy. > > Another side to this is that I use WinMerge to find differences between > my last saved copy and the current copy. I found the current copy had > two lines where a abc.get() was changed to abc.get. This was undoubtedly > from briefly using the pyWin editor, when I mis-hit some keys. Yet pyWin > had no trouble executing the program. My guess is that while briefly > editing there, I hit some odd combination of keys that produced, > perhaps, an invisible character that pyWin ignores. > > Not the 34672232 window is a dialog that I closed by pressing OK. I > would again guess, that, if there is a problem, it occurs in the code > that destroys the dialog. > > Well you have to remember that you are trying to run a windowed GUI under the control of another windows GUI, so it isn't surprising that you hit trouble. With IDLE the issue will be that IDLE already created a main window before your program started running. With PythonWin you are using two different toolkits, so it isn't really surprising that breaks down - there will be two entirely separate main loops competing with each other. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From ivanov.maxim at gmail.com Wed Feb 11 12:01:06 2009 From: ivanov.maxim at gmail.com (redbaron) Date: Wed, 11 Feb 2009 09:01:06 -0800 (PST) Subject: Could you recommend job schedulling solution? Message-ID: I've sinlge 8-way node dedicated for executing long running tasks. To be able to execute multiple tasks on this node it shoud spawn each task in another process. At the same time it should accept network connection with new tasks without blocking of client and put it on job queue. What is "task" ? Executing just ordinary python function will be enough. If solution contain some client library which allow easy task submit it will be great. From mark.seagoe at gmail.com Wed Feb 11 12:01:19 2009 From: mark.seagoe at gmail.com (mark.seagoe at gmail.com) Date: Wed, 11 Feb 2009 09:01:19 -0800 (PST) Subject: Iterable Ctypes Struct References: <99d4c7ae-27ae-4f3a-8475-a58f1c4e6925@t26g2000prh.googlegroups.com> Message-ID: <002f91bd-a30a-4fbf-a757-d496cd381dbf@p23g2000prp.googlegroups.com> On Feb 10, 9:52?pm, "Gabriel Genellina" wrote: > En Wed, 11 Feb 2009 00:31:26 -0200, escribi?: > > > I like the ability to access elements of a struct such as with ctypes > > Structure: > >>>> myStruct.elementName1 > > 4 > > > What I like about it is there are no quotes needed. > > > What I don't like about it is that it's not iterable: > >>>> for n in myStruct: ?<== gives error > >>>> ? ?print n > > > I don't want to force the end user to have preknowledge of the element > > names. > > Note that those names are available as the _fields_ class attribute > > > Has anyone subclassed ctypes Structure based class to be iterable? > > Before a noob starts trying to do this, is it possible? ?How to > > approach it? > > The easiest way would be to define __getitem__ accepting index 0, 1, 2... ? > until the last defined field. > Seehttp://docs.python.org/reference/datamodel.html#object.__getitem__ > > > ?from ctypes import Structure > > class IterableStructure(Structure): > ? ?def __getitem__(self, i): > ? ? ?if not isinstance(i, int): > ? ? ? ?raise TypeError('subindices must be integers: %r' % i) > ? ? ?return getattr(self, self._fields_[i][0]) > > > > This was tested as much as you see here: > > py> from ctypes import c_int > py> > py> class POINT(IterableStructure): > ... ? ? _fields_ = [("x", c_int), > ... ? ? ? ? ? ? ? ? ("y", c_int)] > ... > py> point = POINT(10, 20) > py> print point.x, point.y > 10 20 > py> for field in point: > ... ? print field > ... > 10 > 20 > py> print list(point) > [10, 20] > > -- > Gabriel Genellina Thanks very much, Gabriel. This is very good start for me. This works for predefined class. How about a situation where the fields are added dynamically (as from reading in from an xml file). For example, if I were to now add another element: >>> point.z = 30 >>> print list(point) [10, 20] >>> dir(point) ['__class__', '__ctypes_from_outparam__', '__delattr__', '__ dict__', '__doc__', '__getattribute__', '__getitem__', '__ha sh__', '__init__', '__module__', '__new__', '__reduce__', '_ _reduce_ex__', '__repr__', '__setattr__', '__str__', '__weak ref__', '_b_base_', '_b_needsfree_', '_fields_', '_objects', 'x', 'y', 'z'] I don't know why the iterator (where ever it is) didn't get incremented. Thanks for any insight. Mark From castironpi at gmail.com Wed Feb 11 12:17:11 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 11 Feb 2009 09:17:11 -0800 (PST) Subject: generator object or 'send' method? References: <929da031-95be-4cda-89ea-560e52435243@e1g2000pra.googlegroups.com> <6vfo6kFjlnteU1@mid.individual.net> Message-ID: <61cb6320-3b37-4307-bf3e-8f58593d54b2@k1g2000prb.googlegroups.com> On Feb 11, 4:41?am, greg wrote: > Aaron Brady wrote: > > It would receive the 'send' from a different point in control > > flow than its usual 'next'. ?Should it repeat a value if it receives a > > 'send'? > > No. This requirement clearly indicates that send() is > the wrong tool for the job. > > I would use a class with a generator as a method, e.g. > > ? ?class Multiples: > > ? ? ?m = 1 > > ? ? ?def set_multiplier(self, m): > ? ? ? ?self.m = m > > ? ? ?def generate(self, limit): > ? ? ? ?for i in xrange(limit): > ? ? ? ? ?yield i * self.m > > ? ?g = Multiples() > ? ?for x in g.generate(10): > ? ? ?print x > ? ? ?if x == 3: > ? ? ? ?g.set_multiplier(42) > > produces > > 0 > 1 > 2 > 3 > 168 > 210 > 252 > 294 > 336 > 378 > > -- > Greg Alright, but you don't have to go so far as to create an entire class. It's alright to use a formula. Here's a way to add a dictionary to a generator instance. def gen_dict( fun ): def inner( *ar, **kw ): self.gen= fun( self, *ar, **kw ) return self class GenWrapper: def __iter__( self ): return self def __next__( self, *ar, **kw ): return self.gen.__next__ ( *ar, **kw ) self= GenWrapper() return inner It's a shame that you can't set 'self.__next__= self.gen.__next__'. It costs an entire level of call depth. On the other hand, I'm not sure a pure delegate class is possible. The decorator just puts the generator object in a 'gen' attribute, and adds itself to the '__init__' argument list. So the generator has a 'self' argument, which is of type 'instance', and allows dynamic attributes. @gen_dict def jumper( self, N= 1, K= 1 ): self.N, self.K= N, K while 1: yield self.N self.N+= self.K j= jumper() print( next( j ) ) j.K= 4 print( next( j ) ) It might need some touch-ups to run in Python 2. Neat mix. It's a cool hybrid between Terry's and Greg's idea, and a bare generator. Unfortunately, if you want 'self' to have any methods, you'll probably need a class... though maybe it could inherit from 'GenWrapper'. What do you think? P.S. Here's a slightly simpler version. def gen_dict( fun ): class GenWrapper: def __init__( self, *ar, **kw ): self.gen= fun( self, *ar, **kw ) def __iter__( self ): return self def __next__( self, *ar, **kw ): return self.gen.__next__ ( *ar, **kw ) return GenWrapper P.P.S. Simpler, but a line longer. class GenWrapper: def __init__( self, fun ): self.fun= fun def __call__( self, *ar, **kw ): self.gen= self.fun( self, *ar, **kw ) return self def __iter__( self ): return self def __next__( self, *ar, **kw ): return self.gen.__next__( *ar, **kw ) From bedouglas at earthlink.net Wed Feb 11 12:26:50 2009 From: bedouglas at earthlink.net (bruce) Date: Wed, 11 Feb 2009 09:26:50 -0800 Subject: Could you recommend job schedulling solution? In-Reply-To: Message-ID: <348b01c98c6d$ee610770$0301a8c0@tmesa.com> hi... not sure exactly what you're looking for, but "condor" has a robust job scheduling architecture for dealing with grid/distributed setups over multiple systems.. give us more information, and there might be other suggestions! -----Original Message----- From: python-list-bounces+bedouglas=earthlink.net at python.org [mailto:python-list-bounces+bedouglas=earthlink.net at python.org]On Behalf Of redbaron Sent: Wednesday, February 11, 2009 9:01 AM To: python-list at python.org Subject: Could you recommend job schedulling solution? I've sinlge 8-way node dedicated for executing long running tasks. To be able to execute multiple tasks on this node it shoud spawn each task in another process. At the same time it should accept network connection with new tasks without blocking of client and put it on job queue. What is "task" ? Executing just ordinary python function will be enough. If solution contain some client library which allow easy task submit it will be great. -- http://mail.python.org/mailman/listinfo/python-list From wilson at afn.org Wed Feb 11 12:56:18 2009 From: wilson at afn.org (JBW) Date: Wed, 11 Feb 2009 17:56:18 GMT Subject: SOAP client References: Message-ID: On Wed, 11 Feb 2009 07:33:29 -0800, mk wrote: > I'm trying to consume a SOAP web service using Python. Suds (ibid) -- accept no substitute! From imageguy1206 at gmail.com Wed Feb 11 13:01:37 2009 From: imageguy1206 at gmail.com (imageguy) Date: Wed, 11 Feb 2009 10:01:37 -0800 (PST) Subject: access to MS Access password-protected database? References: Message-ID: <1ed39fa1-5996-4e62-8d81-155a2597cec3@f40g2000pri.googlegroups.com> On Feb 11, 10:43?am, Ken McDonald wrote: > Can anyone direct me towards a code snippet showing how to use Python ? > to insert data into a password-protected MS Access database? My google ? > searches have been uninformative for dbs that are password-protected. > > Thanks, > Ken You post is a little vague on specifics - do you actually have access to the db ? - can you open it with access ? - can you currently read records using python ? I am assuming you don't have access to the db through python, once you do the rest is straight forward. I use DSN-less connections. This link below is quite helpful http://www.carlprothman.net/Default.aspx?tabid=90#ODBCDriverForAccess If you aren't using the adodbapi (part of the pywin32 package), you need to do something like this, assuming you access db is MS-Access 2000 and above. import win32com cnx = win32com.client.Dispatch('ADODB.connection') parms = {} parms['driver'] = '{Microsoft Access Driver (*.mdb)}' parms['dbase'] = path_to_mdb parms['sys_mdw'] = path_to_workgroup_security parms['uid'] = userid_defined_in_mdw parhs['pwd'] = pwd_for_uid_in_mdw cnxtr = 'Driver=%(driver)s; DBQ=%(dbase)s; SYSTEMDB=%(sys_mdw)s; UID=% (uid)s; PWD=%(pwd)s; ' % parms cnx.ConnectionString = cnxstr cnx.Open() once you have an ADO Connection, execute SQL directly on the connection like this cnx.Execute('INSERT INTO tablename (col1, col2) VALUES ('val1, val2);') Or alternatively you should create RecordSets and manipulate these. IF you need help understanding ADO I would recommend; http://www.w3schools.com/ado/default.asp The examples are translateable to Python. You create recordsets via; rs = win32com.client.Dispatch('ADO.RecordSet') If you don't have/weren't given the passwords to the DB, but you do have access to the workgroup file ('*.MDW') file that stores the uid/ pwds and permission, then there are several third party tools that will recover these for you. Google is your friend. If you don't have access to the original .mdw ... well, I can't help you and I don't think anyone can. Good luck. From mark.seagoe at gmail.com Wed Feb 11 13:32:41 2009 From: mark.seagoe at gmail.com (mark.seagoe at gmail.com) Date: Wed, 11 Feb 2009 10:32:41 -0800 (PST) Subject: Iterable Ctypes Struct References: <99d4c7ae-27ae-4f3a-8475-a58f1c4e6925@t26g2000prh.googlegroups.com> <002f91bd-a30a-4fbf-a757-d496cd381dbf@p23g2000prp.googlegroups.com> Message-ID: <9d48e184-5bae-4c3a-b500-d49c38913b39@r41g2000prr.googlegroups.com> On Feb 11, 9:01?am, mark.sea... at gmail.com wrote: > On Feb 10, 9:52?pm, "Gabriel Genellina" > wrote: > > > > > > > En Wed, 11 Feb 2009 00:31:26 -0200, escribi?: > > > > I like the ability to access elements of a struct such as with ctypes > > > Structure: > > >>>> myStruct.elementName1 > > > 4 > > > > What I like about it is there are no quotes needed. > > > > What I don't like about it is that it's not iterable: > > >>>> for n in myStruct: ?<== gives error > > >>>> ? ?print n > > > > I don't want to force the end user to have preknowledge of the element > > > names. > > > Note that those names are available as the _fields_ class attribute > > > > Has anyone subclassed ctypes Structure based class to be iterable? > > > Before a noob starts trying to do this, is it possible? ?How to > > > approach it? > > > The easiest way would be to define __getitem__ accepting index 0, 1, 2... ? > > until the last defined field. > > Seehttp://docs.python.org/reference/datamodel.html#object.__getitem__ > > > > > ?from ctypes import Structure > > > class IterableStructure(Structure): > > ? ?def __getitem__(self, i): > > ? ? ?if not isinstance(i, int): > > ? ? ? ?raise TypeError('subindices must be integers: %r' % i) > > ? ? ?return getattr(self, self._fields_[i][0]) > > > > > > This was tested as much as you see here: > > > py> from ctypes import c_int > > py> > > py> class POINT(IterableStructure): > > ... ? ? _fields_ = [("x", c_int), > > ... ? ? ? ? ? ? ? ? ("y", c_int)] > > ... > > py> point = POINT(10, 20) > > py> print point.x, point.y > > 10 20 > > py> for field in point: > > ... ? print field > > ... > > 10 > > 20 > > py> print list(point) > > [10, 20] > > > -- > > Gabriel Genellina > > Thanks very much, Gabriel. ?This is very good start for me. > This works for predefined class. ?How about a situation where the > fields are added dynamically (as from reading in from an xml file). > For example, if I were to now add another element: > > >>> point.z = 30 > >>> print list(point) > [10, 20] > >>> dir(point) > > ['__class__', '__ctypes_from_outparam__', '__delattr__', '__ > dict__', '__doc__', '__getattribute__', '__getitem__', '__ha > sh__', '__init__', '__module__', '__new__', '__reduce__', '_ > _reduce_ex__', '__repr__', '__setattr__', '__str__', '__weak > ref__', '_b_base_', '_b_needsfree_', '_fields_', '_objects', > ?'x', 'y', 'z'] > > I don't know why the iterator (where ever it is) didn't get > incremented. ?Thanks for any insight. > > Mark- Hide quoted text - > > - Show quoted text - I tinkered with it and think I have viable solution. I need to append a new member to _fields_ before writing it, then it seems to work. >>> p._fields_.append(('z', c_int)) >>> point.z = 30 >>> print 'List:', list(p) List: [10, 20, 30] Awesome. Thanks! From jeffgemail at gmail.com Wed Feb 11 13:35:35 2009 From: jeffgemail at gmail.com (jeffg) Date: Wed, 11 Feb 2009 10:35:35 -0800 (PST) Subject: Unicode issue on Windows cmd line Message-ID: <5827412b-5637-4005-9410-972b7f1f18ca@h20g2000yqn.googlegroups.com> Having issue on Windows cmd. > Python.exe >>>a = u'\xf0' >>>print a This gives a unicode error. Works fine in IDLE, PythonWin, and my Macbook but I need to run this from a windows batch. Character should look like this "?". Please help! From mark.seagoe at gmail.com Wed Feb 11 13:35:36 2009 From: mark.seagoe at gmail.com (mark.seagoe at gmail.com) Date: Wed, 11 Feb 2009 10:35:36 -0800 (PST) Subject: Iterable Ctypes Struct References: <99d4c7ae-27ae-4f3a-8475-a58f1c4e6925@t26g2000prh.googlegroups.com> <002f91bd-a30a-4fbf-a757-d496cd381dbf@p23g2000prp.googlegroups.com> <9d48e184-5bae-4c3a-b500-d49c38913b39@r41g2000prr.googlegroups.com> Message-ID: In last post, I mixed code w/ 'p' and 'point'. Should be: >>> point._fields_.append(('z', c_int)) >>> point.z = 30 >>> print 'List:', list(point) List: [10, 20, 30] From ivanov.maxim at gmail.com Wed Feb 11 13:48:00 2009 From: ivanov.maxim at gmail.com (redbaron) Date: Wed, 11 Feb 2009 10:48:00 -0800 (PST) Subject: Could you recommend job schedulling solution? References: Message-ID: <090e3273-e017-4cb7-b1dd-4e25ca628ed2@13g2000yql.googlegroups.com> On 11 ???, 20:26, "bruce" wrote: > hi... > > not sure exactly what you're looking for, but "condor" has a robust job > scheduling architecture for dealing with grid/distributed setups over > multiple systems.. > > give us more information, and there might be other suggestions! Condor, Globus or any other grid system looks like serious overkill for me. I need some sort of job manager, which accepts jobs from clients as pickled python functions and queues/executes them. Client side should be able to ask status of submitted job, their return value, ask to cancel job etc. From ntwrkd at gmail.com Wed Feb 11 13:58:56 2009 From: ntwrkd at gmail.com (Matthew Sacks) Date: Wed, 11 Feb 2009 10:58:56 -0800 Subject: getopt index out of range In-Reply-To: <4992EA9C.4010207@mrabarnett.plus.com> References: <4992EA9C.4010207@mrabarnett.plus.com> Message-ID: >because the traceback says the index is 0 and there's only one line with a 0 in it! Indeed. Thank you. On Wed, Feb 11, 2009 at 7:11 AM, MRAB wrote: > Steve Holden wrote: >> >> Matthew Sacks wrote: >>> >>> Hi List, >>> I am getting an index out of range error when trying to parse with >>> getopt. >>> Probably something simple. Any suggestions are appreciated >>> >>> optlist, args = getopt.getopt(sys.argv[1:], 'h', ['connectPassword=', >>> 'adminServerURL=', 'action=', 'targets=', 'appDir=']) >>> >>> >>> #Assign Opts >>> connectPassword = optlist[0][1] >>> adminServerURL = optlist[1][1] >>> action = optlist[2][1] >>> targets = optlist[3][1] >>> appDir = optlist[4][1] >>> >>> #this statement never gets executed >>> print "Args: " + connectPassword + " " + adminServerURL + " " + action >>> + " " + targets + " " + appDir >>> >>> File "/home/msacks/untitled4.py", line 23, in ? >>> IndexError: index out of range: 0 >>> >> It might help a little if you made it more obvious which was line 23 ... >> > It a guess I'd say it was: > > connectPassword = optlist[0][1] > > because the traceback says the index is 0 and there's only one line with a 0 > in it! > >> The real problem, though, is a misunderstanding of what getopt.getopt() >> returns. The (option, value) pairs are only returned for options found >> in the command line, so you can't guarantee there'll be four. >> >> Set your values to defaults, then adjust for those for which an option >> is found in the list, as in the "typical usage" example in the Fine >> Manual. >> > -- > http://mail.python.org/mailman/listinfo/python-list > From wolfram.hinderer at googlemail.com Wed Feb 11 14:24:22 2009 From: wolfram.hinderer at googlemail.com (wolfram.hinderer at googlemail.com) Date: Wed, 11 Feb 2009 11:24:22 -0800 (PST) Subject: Functional schmunctional... References: Message-ID: <6262e755-412d-401b-9ddf-e9fb2bba617c@p20g2000yqi.googlegroups.com> On 10 Feb., 21:28, r0g wrote: > def inet2ip(n, l=[], c=4): > ? if c==0: return ".".join(l) > ? p = 256**( c-1 ) > ? l.append( str(n/p) ) > ? return inet2ip( n-(n/p)*p, l, c-1 ) > The results for 10000 > iterations of each were as follows... > > 0.113744974136 seconds for old INET->IP method > 27.7441999912 seconds for new INET->IP method > > :-/ That's probably because your new function is broken: >>> def inet2ip(n, l=[], c=4): if c==0: return ".".join(l) p = 256**( c-1 ) l.append( str(n/p) ) return inet2ip( n-(n/p)*p, l, c-1 ) >>> inet2ip(0) '0.0.0.0' >>> inet2ip(0) '0.0.0.0.0.0.0.0' >>> inet2ip(0) '0.0.0.0.0.0.0.0.0.0.0.0' From Scott.Daniels at Acm.Org Wed Feb 11 14:31:40 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 11 Feb 2009 11:31:40 -0800 Subject: zlib interface semi-broken In-Reply-To: <7xskml9t1r.fsf@ruckus.brouhaha.com> References: <7xskml9t1r.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Scott David Daniels writes: >> Seems like we may want to say things like, "synchronization points are >> too be silently ignored." > > That would completely break some useful possible applications, so should > be avoided. No, I mean that we, _the_users_of_the_interface_, may want to say, .... That is, I'd like that behavior as an option. -Scott David Daniels Scott.Daniels at Acm.Org From Scott.Daniels at Acm.Org Wed Feb 11 14:34:46 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 11 Feb 2009 11:34:46 -0800 Subject: zlib interface semi-broken In-Reply-To: <7xd4dpsvf7.fsf@ruckus.brouhaha.com> References: <7x63jiez9d.fsf@ruckus.brouhaha.com> <8K6dneXdHIranQ_UnZ2dnUVZ_u2dnZ2d@pdx.net> <7xd4dpsvf7.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Scott David Daniels writes: >> I suspect that is why such an interface never came up (If >> you can clone states, then you can say: "compress this, then use the >> resultant state to compress/decompress others." > > The zlib C interface supports something like that. It is just not > exported to the python application. It should be. Right, we are gathering ideas we'd like to see available to the Python programmer in the new zlib / bz2 agglomeration that we are thinking of building / proposing. --Scott David Daniels Scott.Daniels at Acm.Org From marduk at letterboxes.org Wed Feb 11 14:35:56 2009 From: marduk at letterboxes.org (Albert Hopkins) Date: Wed, 11 Feb 2009 14:35:56 -0500 Subject: Unicode issue on Windows cmd line In-Reply-To: <5827412b-5637-4005-9410-972b7f1f18ca@h20g2000yqn.googlegroups.com> References: <5827412b-5637-4005-9410-972b7f1f18ca@h20g2000yqn.googlegroups.com> Message-ID: <1234380956.18084.0.camel@localhost.localdomain> On Wed, 2009-02-11 at 10:35 -0800, jeffg wrote: > Having issue on Windows cmd. > > Python.exe > >>>a = u'\xf0' > >>>print a > > This gives a unicode error. > > Works fine in IDLE, PythonWin, and my Macbook but I need to run this > from a windows batch. > > Character should look like this "?". > > Please help! You forgot to paste the error. From Scott.Daniels at Acm.Org Wed Feb 11 14:36:59 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 11 Feb 2009 11:36:59 -0800 Subject: zlib interface semi-broken In-Reply-To: References: Message-ID: Scott David Daniels wrote: > ... I've wanted to do some low-level (C-coded) search w/o bothering > to create strings until a match.... Here's a more common use case: signature gathering on the contents. --Scott David Daniels Scott.Daniels at Acm.Org From notvalid2 at sbcglobal.net Wed Feb 11 14:38:04 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Wed, 11 Feb 2009 11:38:04 -0800 Subject: Who's on First, IDLE or pythonWin? Dialog Problem? In-Reply-To: References: Message-ID: <_NFkl.10312$hc1.10101@flpi150.ffdc.sbc.com> Mike Driscoll wrote: > On Feb 11, 10:28 am, "W. eWatson" wrote: >> My program in IDLE bombed with: >> ============== >> Exception in Tkinter callback >> Traceback (most recent call last): >> File "C:\Python25\lib\lib-tk\Tkinter.py", line 1403, in __call__ >> return self.func(*args) >> File >> "C:\Sandia_Meteors\New_Sentinel_Development\Sentuser_Utilities_Related\sentuser\sentuserNC25-Dev4.py", >> line 552, in OperationalSettings >> dialog = OperationalSettingsDialog( self.master, set_loc_dict ) >> File >> "C:\Sandia_Meteors\New_Sentinel_Development\Sentuser_Utilities_Related\sentuser\sentuserNC25-Dev4.py", >> line 81, in __init__ >> tkSimpleDialog.Dialog.__init__(self, parent) >> File "C:\Python25\lib\lib-tk\tkSimpleDialog.py", line 69, in __init__ >> self.wait_visibility() # window needs to be visible for the grab >> File "C:\Python25\lib\lib-tk\Tkinter.py", line 415, in wait_visibility >> self.tk.call('tkwait', 'visibility', window._w) >> TclError: window ".34672232" was deleted before its visibility changed >> =============== >> It runs fine in pythonWin performing the same entry operation. Open a menu, >> select an item to open a dialog, select a select button in the dialog, >> press OK to leave the dialog. Boom, as above. >> >> (This does not mean pythonWin doesn't have problems of its own. ) If I just >> execute the code (double click on the py file, the console shows no >> problems. IDLE is unhappy. >> >> Another side to this is that I use WinMerge to find differences between my >> last saved copy and the current copy. I found the current copy had two lines >> where a abc.get() was changed to abc.get. This was undoubtedly from briefly >> using the pyWin editor, when I mis-hit some keys. Yet pyWin had no trouble >> executing the program. My guess is that while briefly editing there, I hit >> some odd combination of keys that produced, perhaps, an invisible character >> that pyWin ignores. >> >> Note the 34672232 window is a dialog that I closed by pressing OK. I would >> again guess, that, if there is a problem, it occurs in the code that >> destroys the dialog. > > You don't really say what your code does or if it uses a GUI toolkit > and if so, which one. But my guess is that you are using some kind of > GUI and its GUI and IDLE's are clashing somehow. I see this sort of > thing with some of my wxPython programs from time to time, although > IDLE usually just crashes with no error message. > > I would recommend using the command line or something that can open it > in a completely separate process, such as Wingware's IDE. > > Mike Tkinter. Isn't just clicking on the py file enough to side step either of the two? I did it and it worked fine. The code is for a GUI that has five or so menus on the main window bar, and manipulates video that is downloaded to it from a video camera. The problem occurs in a dialog in which a user enters configuration values, like the time to start/stop the camera. As soon as I press OK on the dialog the program dies as above. It wasn't doing that at all for days despite some heavy editing. A WinMerge shows its quite faithful to it's last working predecessor. That's how I found the get problem. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From notvalid2 at sbcglobal.net Wed Feb 11 14:39:29 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Wed, 11 Feb 2009 11:39:29 -0800 Subject: Who's on First, IDLE or pythonWin? Dialog Problem? In-Reply-To: References: Message-ID: Steve Holden wrote: > W. eWatson wrote: >> My program in IDLE bombed with: >> ============== >> Exception in Tkinter callback >> Traceback (most recent call last): >> File "C:\Python25\lib\lib-tk\Tkinter.py", line 1403, in __call__ >> return self.func(*args) >> File >> "C:\Sandia_Meteors\New_Sentinel_Development\Sentuser_Utilities_Related\sentuser\sentuserNC25-Dev4.py", >> line 552, in OperationalSettings >> dialog = OperationalSettingsDialog( self.master, set_loc_dict ) >> File >> "C:\Sandia_Meteors\New_Sentinel_Development\Sentuser_Utilities_Related\sentuser\sentuserNC25-Dev4.py", >> line 81, in __init__ >> tkSimpleDialog.Dialog.__init__(self, parent) >> File "C:\Python25\lib\lib-tk\tkSimpleDialog.py", line 69, in __init__ >> self.wait_visibility() # window needs to be visible for the grab >> File "C:\Python25\lib\lib-tk\Tkinter.py", line 415, in wait_visibility >> self.tk.call('tkwait', 'visibility', window._w) >> TclError: window ".34672232" was deleted before its visibility changed >> =============== >> It runs fine in pythonWin performing the same entry operation. Open a >> menu, select an item to open a dialog, select a select button in the >> dialog, press OK to leave the dialog. Boom, as above. >> >> (This does not mean pythonWin doesn't have problems of its own. ) If I >> just execute the code (double click on the py file, the console shows no >> problems. IDLE is unhappy. >> >> Another side to this is that I use WinMerge to find differences between >> my last saved copy and the current copy. I found the current copy had >> two lines where a abc.get() was changed to abc.get. This was undoubtedly >> from briefly using the pyWin editor, when I mis-hit some keys. Yet pyWin >> had no trouble executing the program. My guess is that while briefly >> editing there, I hit some odd combination of keys that produced, >> perhaps, an invisible character that pyWin ignores. >> >> Not the 34672232 window is a dialog that I closed by pressing OK. I >> would again guess, that, if there is a problem, it occurs in the code >> that destroys the dialog. >> >> > Well you have to remember that you are trying to run a windowed GUI > under the control of another windows GUI, so it isn't surprising that > you hit trouble. > > With IDLE the issue will be that IDLE already created a main window > before your program started running. With PythonWin you are using two > different toolkits, so it isn't really surprising that breaks down - > there will be two entirely separate main loops competing with each other. > > regards > Steve Not quite. I take down IDLE when I run pyWin, and vice versa. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From namire at gmail.com Wed Feb 11 14:44:25 2009 From: namire at gmail.com (namire) Date: Wed, 11 Feb 2009 11:44:25 -0800 (PST) Subject: Replace unknow string varible in file. References: <7ec460c5-b625-47e5-88c9-15156533c7da@t13g2000yqc.googlegroups.com> Message-ID: Thanks to Vlastimil Brom for his example and r0g for his helpful attitude and hyperlinks I was able to made program do what was needed. Terry the comments in the html are not important I was just saying that if I could cover the undesired strings in html comment tags then they would not should up on a web browser viewing the file, lucky I get then erased also so the comments is not needed. I anyone wants I can post a pastebin the the full code that uses the regex's. From jfabiani at yolo.com Wed Feb 11 14:44:25 2009 From: jfabiani at yolo.com (John Fabiani) Date: Wed, 11 Feb 2009 11:44:25 -0800 Subject: openOffic, windows, and Python 2.5 Message-ID: Hi, OpenOffice 3 on windows uses python 2.3.x (I have no idea why). Does anyone know where I can get whatever is needed to get python 2.5 working. I don't want to learn how recompile openoffice because it has a steep learning curve and is just to much when I can just use M$ word. BTW using the openSUSE update to install openOffice3 uses my installed python. Maybe someone has already done the compile and is willing to share? Thanks in advance Johnf From jeffgemail at gmail.com Wed Feb 11 14:50:32 2009 From: jeffgemail at gmail.com (jeffg) Date: Wed, 11 Feb 2009 11:50:32 -0800 (PST) Subject: Unicode issue on Windows cmd line References: <5827412b-5637-4005-9410-972b7f1f18ca@h20g2000yqn.googlegroups.com> Message-ID: <53cca468-4d7a-47b5-ac94-5b63042fff2c@g3g2000pre.googlegroups.com> On Feb 11, 2:35?pm, Albert Hopkins wrote: > On Wed, 2009-02-11 at 10:35 -0800, jeffg wrote: > > Having issue on Windows cmd. > > > Python.exe > > >>>a = u'\xf0' > > >>>print a > > > This gives a unicode error. > > > Works fine in IDLE, PythonWin, and my Macbook but I need to run this > > from a windows batch. > > > Character should look like this "?". > > > Please help! > > You forgot to paste the error. The error looks like this: File " File "C:\python25\lib\encodings\cp437.py", line 12, in encode return codecs.charmap_encode(input,errors,encoding_map) UnicodeEncodeError: 'charmap' codec can't encode character u'\xf0' in position 0 : character maps to Running Python 2.5.4 on Windows XP From steve at holdenweb.com Wed Feb 11 14:51:50 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 11 Feb 2009 14:51:50 -0500 Subject: Who's on First, IDLE or pythonWin? Dialog Problem? In-Reply-To: References: Message-ID: W. eWatson wrote: > Steve Holden wrote: >> W. eWatson wrote: >>> My program in IDLE bombed with: >>> ============== >>> Exception in Tkinter callback >>> Traceback (most recent call last): >>> File "C:\Python25\lib\lib-tk\Tkinter.py", line 1403, in __call__ >>> return self.func(*args) >>> File >>> "C:\Sandia_Meteors\New_Sentinel_Development\Sentuser_Utilities_Related\sentuser\sentuserNC25-Dev4.py", >>> >>> line 552, in OperationalSettings >>> dialog = OperationalSettingsDialog( self.master, set_loc_dict ) >>> File >>> "C:\Sandia_Meteors\New_Sentinel_Development\Sentuser_Utilities_Related\sentuser\sentuserNC25-Dev4.py", >>> >>> line 81, in __init__ >>> tkSimpleDialog.Dialog.__init__(self, parent) >>> File "C:\Python25\lib\lib-tk\tkSimpleDialog.py", line 69, in __init__ >>> self.wait_visibility() # window needs to be visible for the grab >>> File "C:\Python25\lib\lib-tk\Tkinter.py", line 415, in wait_visibility >>> self.tk.call('tkwait', 'visibility', window._w) >>> TclError: window ".34672232" was deleted before its visibility changed >>> =============== >>> It runs fine in pythonWin performing the same entry operation. Open a >>> menu, select an item to open a dialog, select a select button in the >>> dialog, press OK to leave the dialog. Boom, as above. >>> >>> (This does not mean pythonWin doesn't have problems of its own. ) If I >>> just execute the code (double click on the py file, the console shows no >>> problems. IDLE is unhappy. >>> >>> Another side to this is that I use WinMerge to find differences between >>> my last saved copy and the current copy. I found the current copy had >>> two lines where a abc.get() was changed to abc.get. This was undoubtedly >>> from briefly using the pyWin editor, when I mis-hit some keys. Yet pyWin >>> had no trouble executing the program. My guess is that while briefly >>> editing there, I hit some odd combination of keys that produced, >>> perhaps, an invisible character that pyWin ignores. >>> >>> Not the 34672232 window is a dialog that I closed by pressing OK. I >>> would again guess, that, if there is a problem, it occurs in the code >>> that destroys the dialog. >>> >>> >> Well you have to remember that you are trying to run a windowed GUI >> under the control of another windows GUI, so it isn't surprising that >> you hit trouble. >> >> With IDLE the issue will be that IDLE already created a main window >> before your program started running. With PythonWin you are using two >> different toolkits, so it isn't really surprising that breaks down - >> there will be two entirely separate main loops competing with each other. >> > Not quite. I take down IDLE when I run pyWin, and vice versa. > The two separate loops being PyWin (which uses MFC) and your program (which uses Tkinter). You just can't mix GUIs in the same process like that, sorry. regards Stedve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From Shawn at Milochik.com Wed Feb 11 14:55:14 2009 From: Shawn at Milochik.com (Shawn Milochik) Date: Wed, 11 Feb 2009 14:55:14 -0500 Subject: re.sub and named groups In-Reply-To: References: <4c7158d2-5663-46b9-b950-be81bd79964c@z6g2000pre.googlegroups.com> Message-ID: <2dc0c81b0902111155r3bf37a03j86023099a9ce1a00@mail.gmail.com> > > Book recommendation: _Mastering Regular Expressions_, Jeffrey Friedl > -- > Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ I wholeheartedly second this! The third edition is out now. From stef.mientki at gmail.com Wed Feb 11 14:58:39 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Wed, 11 Feb 2009 20:58:39 +0100 Subject: hpw to convert a linux python script ? Message-ID: <49932DEF.3000102@gmail.com> hello, I've a python script, written for some Linux version, now I want to run it under windows. It complains of not finding files in /usr/share/tinybldLin/ .... where .... is the directory where the script is located and started from. As there are a whole lot of these lines, in a whole lot of files, I wonder if there's a simple trick to point /usr/share/tinybldLin/ to my directory ? thanks, Stef From http Wed Feb 11 14:58:45 2009 From: http (Paul Rubin) Date: 11 Feb 2009 11:58:45 -0800 Subject: zlib interface semi-broken References: <7xskml9t1r.fsf@ruckus.brouhaha.com> Message-ID: <7xtz70agp6.fsf@ruckus.brouhaha.com> Scott David Daniels writes: > >> Seems like we may want to say things like, "synchronization points are > >> too be silently ignored." > No, I mean that we, _the_users_of_the_interface_, may want to say, .... > That is, I'd like that behavior as an option. I don't see any reason to want that (rather than letting the application handle it) but I'll take your word for it. From Graham.Dumpleton at gmail.com Wed Feb 11 14:59:33 2009 From: Graham.Dumpleton at gmail.com (Graham Dumpleton) Date: Wed, 11 Feb 2009 11:59:33 -0800 (PST) Subject: best way to serve wsgi with multiple processes References: <2d705579-6c7e-46b1-a9f7-4be4c3af487a@t13g2000yqc.googlegroups.com> Message-ID: <470f306f-a887-4ee5-952c-d01a66eec411@w39g2000prb.googlegroups.com> On Feb 11, 8:50?pm, Robin wrote: > Hi, > > I am building some computational web services using soaplib. This > creates a WSGI application. > > However, since some of these services are computationally intensive, > and may be long running, I was looking for a way to use multiple > processes. I thought about using multiprocessing.Process manually in > the service, but I was a bit worried about how that might interact > with a threaded server (I was hoping the thread serving that request > could just wait until the child is finished). Also it would be good to > keep the services as simple as possible so it's easier for people to > write them. > > I have at the moment the following WSGI structure: > TransLogger(URLMap(URLParser(soaplib objects))) > although presumably, due to the beauty of WSGI, this shouldn't matter. > > As I've found with all web-related Python stuff, I'm overwhelmed by > the choice and number of alternatives. I've so far been using cherrypy > and ajp-wsgi for my testing, but am aware of Spawning, twisted etc. > What would be the simplest [quickest to setup and fewest details of > the server required - ideally with a simple example] and most reliable > [this will eventually be 'in production' as part of a large scientific > project] way to host this sort of WSGI with a process-per-request > style? In this sort of situation one wouldn't normally do the work in the main web server, but have a separarte long running daemon process embedding mini web server that understands XML-RPC. The main web server would then make XML-RPC requests against the backend daemon process, which would use threading and or queueing to handle the requests. If the work is indeed long running, the backend process would normally just acknowledge the request and not wait. The web page would return and it would be up to user to then somehow occassionally poll web server, manually or by AJAX, to see how progres is going. That is, further XML-RPC requests from main server to backend daemon process asking about progress. I do't believe the suggestions about fastcgi/scgi/ajp/flup or mod_wsgi are really appropriate as you don't want this done in web server processes as then you are at mercy of web server processes being killed or dying when part way through something. Some of these systems will do this if requests take too long. Thus better to offload real work to another process. Graham From martin at marcher.name Wed Feb 11 15:00:32 2009 From: martin at marcher.name (Martin) Date: Wed, 11 Feb 2009 21:00:32 +0100 Subject: Could you recommend job schedulling solution? In-Reply-To: References: Message-ID: <5fa6c12e0902111200t5c29d6bbpefbfe1bfd29b987e@mail.gmail.com> Hi, 2009/2/11 redbaron : > should accept network > connection with new tasks without blocking of client and put it on job > queue. > > What is "task" ? Executing just ordinary python function will be > enough. If solution contain some client library which allow easy task > submit it will be great. I think parallel python will take of that for you (http://www.parallelpython.com/) -- http://soup.alt.delete.co.at http://www.xing.com/profile/Martin_Marcher http://www.linkedin.com/in/martinmarcher You are not free to read this message, by doing so, you have violated my licence and are required to urinate publicly. Thank you. Please avoid sending me Word or PowerPoint attachments. See http://www.gnu.org/philosophy/no-word-attachments.html From benjamin.kaplan at case.edu Wed Feb 11 15:08:50 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 11 Feb 2009 15:08:50 -0500 Subject: Unicode issue on Windows cmd line In-Reply-To: <53cca468-4d7a-47b5-ac94-5b63042fff2c@g3g2000pre.googlegroups.com> References: <5827412b-5637-4005-9410-972b7f1f18ca@h20g2000yqn.googlegroups.com> <53cca468-4d7a-47b5-ac94-5b63042fff2c@g3g2000pre.googlegroups.com> Message-ID: On Wed, Feb 11, 2009 at 2:50 PM, jeffg wrote: > On Feb 11, 2:35 pm, Albert Hopkins wrote: > > On Wed, 2009-02-11 at 10:35 -0800, jeffg wrote: > > > Having issue on Windows cmd. > > > > Python.exe > > > >>>a = u'\xf0' > > > >>>print a > > > > > This gives a unicode error. > > > > > Works fine in IDLE, PythonWin, and my Macbook but I need to run this > > > from a windows batch. > > > > > Character should look like this "?". > > > > > Please help! > > > > You forgot to paste the error. > > The error looks like this: > File " > File "C:\python25\lib\encodings\cp437.py", line 12, in encode > return codecs.charmap_encode(input,errors,encoding_map) > UnicodeEncodeError: 'charmap' codec can't encode character u'\xf0' in > position 0 > : character maps to > > > Running Python 2.5.4 on Windows XP That isn't a python problem, it's a Windows problem. For "compatibility reasons", Microsoft never added Unicode support to cmd. When you do print u'', python tries to convert the characters to the console encoding (the really old cp437, not even the Windows standard cp1252), it messes up. AFAIK, you'll have to use the chcp command to switch to an encoding that has the character and then print u'\xf0'.encode(the_encoding) to get it to display. There isn't any way around it- we've tried. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tenax.raccoon at gmail.com Wed Feb 11 15:09:57 2009 From: tenax.raccoon at gmail.com (Jason) Date: Wed, 11 Feb 2009 12:09:57 -0800 (PST) Subject: Unexpected string behaviour: txt = 'this' ' works' References: Message-ID: On Feb 11, 5:16?am, bearophileH... at lycos.com wrote: > christopher.saun... at durham.ac.uk (c d saunter): > > >I assume it is a feature of the compiler.< > > Yes it's a bug-prone antifeature that's probably a relic from C that > doesn't have a concatenation operator among strings as Python does > (+). So in Python it saves you to use + at the cost of possible bugs. > > Bye, > bearophile I've used this feature in C and Python when I want to wrap strings without having a newlines in the strings... grouping the whole bunch with a set of parenthesis to make the concatenation explicit. Admittedly, I wouldn't be broken up if this feature became deprecated, as It does do a minor optimization in Python and most C compilers. The two string constants are concatenated when the code is parsed, rather than when the code is executed. >>> from dis import dis >>> def f(): ... return 'This is ' 'an example.' ... >>> dis(f) 2 0 LOAD_CONST 1 ('This is an example.') 3 RETURN_VALUE >>> It's such a minor optimization, that you probably wouldn't see any effect on your program. --Jason From kmtracey at gmail.com Wed Feb 11 15:16:05 2009 From: kmtracey at gmail.com (Karen Tracey) Date: Wed, 11 Feb 2009 15:16:05 -0500 Subject: Unicode issue on Windows cmd line In-Reply-To: <53cca468-4d7a-47b5-ac94-5b63042fff2c@g3g2000pre.googlegroups.com> References: <5827412b-5637-4005-9410-972b7f1f18ca@h20g2000yqn.googlegroups.com> <53cca468-4d7a-47b5-ac94-5b63042fff2c@g3g2000pre.googlegroups.com> Message-ID: On Wed, Feb 11, 2009 at 2:50 PM, jeffg wrote: > On Feb 11, 2:35 pm, Albert Hopkins wrote: > > On Wed, 2009-02-11 at 10:35 -0800, jeffg wrote: > > > Having issue on Windows cmd. > > > > Python.exe > > > >>>a = u'\xf0' > > > >>>print a > > > > > This gives a unicode error. > > > > > Works fine in IDLE, PythonWin, and my Macbook but I need to run this > > > from a windows batch. > > > > > Character should look like this "?". > > > > > Please help! > > > > You forgot to paste the error. > > The error looks like this: > File " > File "C:\python25\lib\encodings\cp437.py", line 12, in encode > return codecs.charmap_encode(input,errors,encoding_map) > UnicodeEncodeError: 'charmap' codec can't encode character u'\xf0' in > position 0 > : character maps to > > > Running Python 2.5.4 on Windows XP > First, you may need to change your command prompt Properties->Font to use Lucida Console rather than raster fonts. Then you'll need to change the code page using chcp to something that has a mapping for the character you want. E.g.: D:\>chcp Active code page: 437 D:\>python Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> a = u'\xf0' >>> print a Traceback (most recent call last): File "", line 1, in File "D:\bin\Python2.5.2\lib\encodings\cp437.py", line 12, in encode return codecs.charmap_encode(input,errors,encoding_map) UnicodeEncodeError: 'charmap' codec can't encode character u'\xf0' in position 0: character maps to >>> quit() D:\>chcp 1252 Active code page: 1252 D:\>python Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> a = u'\xf0' >>> print a ? >>> quit() D:\> (Just changing the code page works to avoid the UnicodeEncodeError, but with raster fonts that character displays as thee horizontal bars.) Karen -------------- next part -------------- An HTML attachment was scrubbed... URL: From kenneth.m.mcdonald at sbcglobal.net Wed Feb 11 15:24:40 2009 From: kenneth.m.mcdonald at sbcglobal.net (Kenneth McDonald) Date: Wed, 11 Feb 2009 14:24:40 -0600 Subject: access to MS Access password-protected database? In-Reply-To: <1ed39fa1-5996-4e62-8d81-155a2597cec3@f40g2000pri.googlegroups.com> References: <1ed39fa1-5996-4e62-8d81-155a2597cec3@f40g2000pri.googlegroups.com> Message-ID: <12ABC69A-8E0D-4ED2-A941-471725DCBA55@sbcglobal.net> Sorry for the vagueness. I do have access to the file and can open it using Access. I haven't yet done anything involving Python and Access (or Python and Win interfacing, for that matter.) Thanks, Ken On Feb 11, 2009, at 12:01 PM, imageguy wrote: > On Feb 11, 10:43 am, Ken McDonald > wrote: >> Can anyone direct me towards a code snippet showing how to use Python >> to insert data into a password-protected MS Access database? My >> google >> searches have been uninformative for dbs that are password-protected. >> >> Thanks, >> Ken > > You post is a little vague on specifics > - do you actually have access to the db ? > - can you open it with access ? > - can you currently read records using python ? > > I am assuming you don't have access to the db through python, once you > do the rest is straight forward. > > I use DSN-less connections. This link below is quite helpful > http://www.carlprothman.net/Default.aspx?tabid=90#ODBCDriverForAccess > > If you aren't using the adodbapi (part of the pywin32 package), you > need to do something like this, assuming you access db is MS-Access > 2000 and above. > > > import win32com > cnx = win32com.client.Dispatch('ADODB.connection') > > parms = {} > parms['driver'] = '{Microsoft Access Driver (*.mdb)}' > parms['dbase'] = path_to_mdb > parms['sys_mdw'] = path_to_workgroup_security > parms['uid'] = userid_defined_in_mdw > parhs['pwd'] = pwd_for_uid_in_mdw > > cnxtr = 'Driver=%(driver)s; DBQ=%(dbase)s; SYSTEMDB=%(sys_mdw)s; UID=% > (uid)s; PWD=%(pwd)s; ' % parms > cnx.ConnectionString = cnxstr > cnx.Open() > > > once you have an ADO Connection, execute SQL directly on the > connection like this > > cnx.Execute('INSERT INTO tablename (col1, col2) VALUES ('val1, > val2);') > > Or alternatively you should create RecordSets and manipulate these. > > IF you need help understanding ADO I would recommend; > http://www.w3schools.com/ado/default.asp > > The examples are translateable to Python. > You create recordsets via; > rs = win32com.client.Dispatch('ADO.RecordSet') > > > If you don't have/weren't given the passwords to the DB, but you do > have access to the workgroup file ('*.MDW') file that stores the uid/ > pwds and permission, then there are several third party tools that > will recover these for you. Google is your friend. > > If you don't have access to the original .mdw ... well, I can't help > you and I don't think anyone can. > > Good luck. > -- > http://mail.python.org/mailman/listinfo/python-list From stojek at part-gmbh.de Wed Feb 11 15:28:58 2009 From: stojek at part-gmbh.de (MarcusD) Date: Wed, 11 Feb 2009 21:28:58 +0100 Subject: Clearing the keyboard buffer (wxPython) Message-ID: Platform: MSW (XP) Python 2.5 wxPython 2.8 Topic: Clear Keyboard buffer Hi, I hope I am not off topic asking a wxpython question. I'm writing a Score counter for Dart games. The software shows graphical output on a Canvas and accepts keyboard input (no buttons, no widgest). A stripped version looks like that: self.Bind(wx.EVT_CHAR,OnKeyEvent) . . #-------------- def OnKeyEvent(self, event): k =event.GetKeyCode() try: z=chr(k) except: return if (z in ["0","1","2","3","4","5","6","7","8","9",.."\r"..]: self.keystr +=z score=self.CalculateScore(self.keystr) self.DisplayScore(score) . . if z== "\r" #enter self.SayScore(score) self.NextPlayer() #-------------- def SayScore(self,number): if number > 100: a=os.path.join(self.wavpath,"100.wav") b=os.path.join(self.wavpath,"%i.wav"%(number-100)) else: a=os.path.join(self.wavpath,"%i.wav"%(number)) b="" sound1 = wx.Sound(a) sound2 = wx.Sound(b) sound1.Play(wx.SOUND_SYNC) if b: sound2.HurryupandPlay(wx.SOUND_SYNC) #-------------- The problem is, that during the voice output all keystrokes are buffered somewhere and are processed when SayScore is finished. So I have to clear the keyboard buffer at the end of SayScore. Something like: evt=MagicFetchPendingKeyEventFunction() while evt: evt=MagicFetchPendingKeyEventFunction() I was thinking about threading (maybe using delayedresults), but this might be a little oversized for my problem. Playing the sound ASYNC doesn't work here. Any ideas? Thanks in advance Marcus From aleksandr.goretoy at gmail.com Wed Feb 11 15:35:52 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Wed, 11 Feb 2009 14:35:52 -0600 Subject: best way to serve wsgi with multiple processes In-Reply-To: <470f306f-a887-4ee5-952c-d01a66eec411@w39g2000prb.googlegroups.com> References: <2d705579-6c7e-46b1-a9f7-4be4c3af487a@t13g2000yqc.googlegroups.com> <470f306f-a887-4ee5-952c-d01a66eec411@w39g2000prb.googlegroups.com> Message-ID: GAE (Google App Engine) uses WSGI for webapps. You don't have to overhead of managing a server and all it's services this way as well. Just manage dns entries. Although, there are limitations depending on your project needs of what libs you need to use. appengine.google.com -Alex Goretoy http://www.goretoy.com On Wed, Feb 11, 2009 at 1:59 PM, Graham Dumpleton < Graham.Dumpleton at gmail.com> wrote: > On Feb 11, 8:50 pm, Robin wrote: > > Hi, > > > > I am building some computational web services using soaplib. This > > creates a WSGI application. > > > > However, since some of these services are computationally intensive, > > and may be long running, I was looking for a way to use multiple > > processes. I thought about using multiprocessing.Process manually in > > the service, but I was a bit worried about how that might interact > > with a threaded server (I was hoping the thread serving that request > > could just wait until the child is finished). Also it would be good to > > keep the services as simple as possible so it's easier for people to > > write them. > > > > I have at the moment the following WSGI structure: > > TransLogger(URLMap(URLParser(soaplib objects))) > > although presumably, due to the beauty of WSGI, this shouldn't matter. > > > > As I've found with all web-related Python stuff, I'm overwhelmed by > > the choice and number of alternatives. I've so far been using cherrypy > > and ajp-wsgi for my testing, but am aware of Spawning, twisted etc. > > What would be the simplest [quickest to setup and fewest details of > > the server required - ideally with a simple example] and most reliable > > [this will eventually be 'in production' as part of a large scientific > > project] way to host this sort of WSGI with a process-per-request > > style? > > In this sort of situation one wouldn't normally do the work in the > main web server, but have a separarte long running daemon process > embedding mini web server that understands XML-RPC. The main web > server would then make XML-RPC requests against the backend daemon > process, which would use threading and or queueing to handle the > requests. > > If the work is indeed long running, the backend process would normally > just acknowledge the request and not wait. The web page would return > and it would be up to user to then somehow occassionally poll web > server, manually or by AJAX, to see how progres is going. That is, > further XML-RPC requests from main server to backend daemon process > asking about progress. > > I do't believe the suggestions about fastcgi/scgi/ajp/flup or mod_wsgi > are really appropriate as you don't want this done in web server > processes as then you are at mercy of web server processes being > killed or dying when part way through something. Some of these systems > will do this if requests take too long. Thus better to offload real > work to another process. > > Graham > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From johannalecschueler at googlemail.com Wed Feb 11 15:37:05 2009 From: johannalecschueler at googlemail.com (Alec Schueler) Date: Wed, 11 Feb 2009 12:37:05 -0800 (PST) Subject: hpw to convert a linux python script ? References: Message-ID: <8848a16f-83db-4acf-a1cc-46653869f27c@z1g2000yqn.googlegroups.com> On Feb 11, 7:58?pm, Stef Mientki wrote: > As there are a whole lot of these lines, in a whole lot of files, > I wonder if there's a simple trick to point > ? /usr/share/tinybldLin/ > to my directory ? > > thanks, > Stef Find and replace? From kyosohma at gmail.com Wed Feb 11 15:45:56 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Wed, 11 Feb 2009 12:45:56 -0800 (PST) Subject: Clearing the keyboard buffer (wxPython) References: Message-ID: On Feb 11, 2:28?pm, "MarcusD" wrote: > Platform: MSW (XP) Python 2.5 wxPython 2.8 > Topic: Clear Keyboard buffer > > Hi, > I hope I am not off topic asking a wxpython question. > I'm writing a Score counter for Dart games. The software > shows graphical output on a Canvas and accepts keyboard > input (no buttons, no widgest). A stripped version looks > like that: > > self.Bind(wx.EVT_CHAR,OnKeyEvent) > . > . > #-------------- > ? ? def OnKeyEvent(self, event): > ? ? ? k =event.GetKeyCode() > ? ? ? try: > ? ? ? ? z=chr(k) > ? ? ? except: > ? ? ? ? return > ? ? ? if (z in ["0","1","2","3","4","5","6","7","8","9",.."\r"..]: > ? ? ? ? self.keystr +=z > ? ? ? ? score=self.CalculateScore(self.keystr) > ? ? ? ? self.DisplayScore(score) > ? ? ? ? . > ? ? ? ? . > ? ? ? if z== "\r" #enter > ? ? ? ? self.SayScore(score) > ? ? ? ? self.NextPlayer() > #-------------- > ? ? def SayScore(self,number): > ? ? ? if number > 100: > ? ? ? ? a=os.path.join(self.wavpath,"100.wav") > ? ? ? ? b=os.path.join(self.wavpath,"%i.wav"%(number-100)) > ? ? ? else: > ? ? ? ? a=os.path.join(self.wavpath,"%i.wav"%(number)) > ? ? ? ? b="" > ? ? ? sound1 = wx.Sound(a) > ? ? ? sound2 = wx.Sound(b) > ? ? ? sound1.Play(wx.SOUND_SYNC) > ? ? ? if b: > ? ? ? ? sound2.HurryupandPlay(wx.SOUND_SYNC) > #-------------- > > The problem is, that during the voice output all keystrokes > are buffered somewhere and are processed when SayScore is > finished. So I have to clear the keyboard buffer at the end > of SayScore. Something like: > > ? evt=MagicFetchPendingKeyEventFunction() > ? while evt: > ? ? evt=MagicFetchPendingKeyEventFunction() > > I was thinking about threading (maybe using delayedresults), but > this might be a little oversized for my problem. > Playing the sound ASYNC doesn't work here. > > Any ideas? > Thanks in advance > Marcus It's fine to post here with wxPython questions, but I would recommend the official wxPython mailing list in most cases as it has lots of experienced users and developers on it: http://wxpython.org/maillist.php I've never done this sort of thing with wxPython, but you may be able to use wx.Yield somehow. There are various tips and tricks in the wiki about working around long running processes that block the GUI's mainloop here: http://wiki.wxpython.org/LongRunningTasks Other than that, I would recommend doing this with pygame or pyglet as they might be easier to use for this use-case. Here are their sites: http://www.pyglet.org/ http://www.pygame.org/news.html HTH Mike From stef.mientki at gmail.com Wed Feb 11 15:48:14 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Wed, 11 Feb 2009 21:48:14 +0100 Subject: hpw to convert a linux python script ? In-Reply-To: <8848a16f-83db-4acf-a1cc-46653869f27c@z1g2000yqn.googlegroups.com> References: <8848a16f-83db-4acf-a1cc-46653869f27c@z1g2000yqn.googlegroups.com> Message-ID: <4993398E.1040909@gmail.com> Alec Schueler wrote: > On Feb 11, 7:58 pm, Stef Mientki wrote: > >> As there are a whole lot of these lines, in a whole lot of files, >> I wonder if there's a simple trick to point >> /usr/share/tinybldLin/ >> to my directory ? >> >> thanks, >> Stef >> > > Find and replace? > well I was thinking of a more elegant way, so the scripts remains, or better become multi-platform. anyway thanks, Stef > -- > http://mail.python.org/mailman/listinfo/python-list > From stojek at part-gmbh.de Wed Feb 11 15:54:55 2009 From: stojek at part-gmbh.de (MarcusD) Date: Wed, 11 Feb 2009 21:54:55 +0100 Subject: Clearing the keyboard buffer (wxPython) References: Message-ID: Whow. Thanks for the fast and comprehensive answer. To be honest I would have posted to wxpython.org but the server seems to be down for the last couple of days. I'll check this wx.Yield thing that I never heard of. And let's see what else we get here. Thanks again marcus From martin at v.loewis.de Wed Feb 11 15:57:26 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 11 Feb 2009 21:57:26 +0100 Subject: Unicode issue on Windows cmd line In-Reply-To: <5827412b-5637-4005-9410-972b7f1f18ca@h20g2000yqn.googlegroups.com> References: <5827412b-5637-4005-9410-972b7f1f18ca@h20g2000yqn.googlegroups.com> Message-ID: <49933bb6$0$3304$9b622d9e@news.freenet.de> > Having issue on Windows cmd. >> Python.exe >>>> a = u'\xf0' >>>> print a > > This gives a unicode error. > > Works fine in IDLE, PythonWin, and my Macbook but I need to run this > from a windows batch. > > Character should look like this "?". > > Please help! Well, your terminal just cannot display this character by default; you need to use a different terminal program, or reconfigure your terminal. For example, do chcp 1252 and select Lucida Console as the terminal font, then try again. Of course, this will cause *different* characters to become non-displayable. Regards, Martin From bearophileHUGS at lycos.com Wed Feb 11 15:57:31 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Wed, 11 Feb 2009 12:57:31 -0800 (PST) Subject: Unexpected string behaviour: txt = 'this' ' works' References: Message-ID: <71e3e031-de35-4f7b-91e9-1c14436d36f1@j38g2000yqa.googlegroups.com> Jason: > It's such a minor optimization, that you probably wouldn't see any > effect on your program. >>> from dis import dis >>> def f(): ... return 'This is ' + 'an example.' ... >>> dis(f) 2 0 LOAD_CONST 3 ('This is an example.') 3 RETURN_VALUE Bye, bearophile From gervaz at gmail.com Wed Feb 11 16:01:26 2009 From: gervaz at gmail.com (mattia) Date: 11 Feb 2009 21:01:26 GMT Subject: Library similar to UserAgent (perl) Message-ID: <49933ca6$0$1125$4fafbaef@reader1.news.tin.it> Hi everybody, I'm looking for an easy way to put data in a form, then click the button and follow the redirect. Also I need to use cookies. I read that using perl this can be done using the UserAgent lib, that also provide th browser functionality to let the site believe that you are getting the pages from a normali browser like ff. Any suggestion? I think that the main concen is to easilly put the data in the numerous textlabel provided and then magically simulate the 'click me' button. From rdmurray at bitdance.com Wed Feb 11 16:05:00 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Wed, 11 Feb 2009 21:05:00 +0000 (UTC) Subject: hpw to convert a linux python script ? References: <8848a16f-83db-4acf-a1cc-46653869f27c@z1g2000yqn.googlegroups.com> <4993398E.1040909@gmail.com> Message-ID: Stef Mientki wrote: > Alec Schueler wrote: > > On Feb 11, 7:58 pm, Stef Mientki wrote: > > > >> As there are a whole lot of these lines, in a whole lot of files, > >> I wonder if there's a simple trick to point > >> /usr/share/tinybldLin/ > >> to my directory ? > >> > >> thanks, > >> Stef > >> > > > > Find and replace? > > > well I was thinking of a more elegant way, > so the scripts remains, or better become multi-platform. > > anyway thanks, Well, you'll have to rewrite the script so that it doesn't make assumptions about path names, and we can't help you with that without seeing some of the script code. There _might_ be easy fixes, but if the path is hardcoded in many places in the script...then you will just have to go through and un-hard-code it. --RDM From ptmcg at austin.rr.com Wed Feb 11 16:05:53 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Wed, 11 Feb 2009 13:05:53 -0800 (PST) Subject: re.sub and named groups References: <4c7158d2-5663-46b9-b950-be81bd79964c@z6g2000pre.googlegroups.com> Message-ID: On Feb 4, 10:51?am, "Emanuele D'Arrigo" wrote: > Hi everybody, > > I'm having a ball with the power of regular expression Don't forget the ball you can have with the power of ordinary Python strings, string methods, and string interpolation! originalString = "spam:%(first)s ham:%(second)s" print originalString % { "first" : "foo" , "second" : "" } prints spam:foo ham: with far fewer surprises and false steps. (Note: Py3K supports this same feature, but with different interpolation syntax, which I have not learned yet.) Book recommendation: Text Processing in Python, by David Mertz (free online - http://gnosis.cx/TPiP/), in which David advises against dragging out the RE heavy artillery until you've at least thought about using ordinary string methods. -- Paul From kyosohma at gmail.com Wed Feb 11 16:05:57 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Wed, 11 Feb 2009 13:05:57 -0800 (PST) Subject: Clearing the keyboard buffer (wxPython) References: Message-ID: On Feb 11, 2:54?pm, "MarcusD" wrote: > Whow. Thanks for the fast and comprehensive answer. To be honest I would > have posted to wxpython.org but the server seems to be down for the last > couple of days. > > I'll check this wx.Yield thing that I never heard of. And let's see what > else we get here. > Thanks again > marcus Is it? I wondered why I had suddenly stopped getting emails from them, but my company recently had some email config changes that blocked a ton of stuff and I just figured that was part of the problem. Hopefully Robin Dunn can put the smack down on his web hosts... Mike From benjamin.kaplan at case.edu Wed Feb 11 16:06:43 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 11 Feb 2009 16:06:43 -0500 Subject: hpw to convert a linux python script ? In-Reply-To: <4993398E.1040909@gmail.com> References: <8848a16f-83db-4acf-a1cc-46653869f27c@z1g2000yqn.googlegroups.com> <4993398E.1040909@gmail.com> Message-ID: On Wed, Feb 11, 2009 at 3:48 PM, Stef Mientki wrote: > Alec Schueler wrote: > >> On Feb 11, 7:58 pm, Stef Mientki wrote: >> >> >>> As there are a whole lot of these lines, in a whole lot of files, >>> I wonder if there's a simple trick to point >>> /usr/share/tinybldLin/ >>> to my directory ? >>> >>> thanks, >>> Stef >>> >>> >> >> Find and replace? >> >> > well I was thinking of a more elegant way, > so the scripts remains, or better become multi-platform. That's the problem with using external files- unless you can get to the file by some combination of os and os.path functions, you're pretty much stuck checking os.name and/or sys.platform and choosing filenames based on that. -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.kaplan at case.edu Wed Feb 11 16:10:43 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 11 Feb 2009 16:10:43 -0500 Subject: Unicode issue on Windows cmd line In-Reply-To: <49933bb6$0$3304$9b622d9e@news.freenet.de> References: <5827412b-5637-4005-9410-972b7f1f18ca@h20g2000yqn.googlegroups.com> <49933bb6$0$3304$9b622d9e@news.freenet.de> Message-ID: On Wed, Feb 11, 2009 at 3:57 PM, "Martin v. L?wis" wrote: > > Having issue on Windows cmd. > >> Python.exe > >>>> a = u'\xf0' > >>>> print a > > > > This gives a unicode error. > > > > Works fine in IDLE, PythonWin, and my Macbook but I need to run this > > from a windows batch. > > > > Character should look like this "?". > > > > Please help! > > Well, your terminal just cannot display this character by default; you > need to use a different terminal program, or reconfigure your terminal. > > For example, do > > chcp 1252 > > and select Lucida Console as the terminal font, then try again. > > Of course, this will cause *different* characters to become > non-displayable. Well, > > > Regards, > Martin > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.kaplan at case.edu Wed Feb 11 16:13:22 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 11 Feb 2009 16:13:22 -0500 Subject: Unicode issue on Windows cmd line In-Reply-To: References: <5827412b-5637-4005-9410-972b7f1f18ca@h20g2000yqn.googlegroups.com> <49933bb6$0$3304$9b622d9e@news.freenet.de> Message-ID: On Wed, Feb 11, 2009 at 4:10 PM, Benjamin Kaplan wrote: > > > On Wed, Feb 11, 2009 at 3:57 PM, "Martin v. L?wis" wrote: > >> > Having issue on Windows cmd. >> >> Python.exe >> >>>> a = u'\xf0' >> >>>> print a >> > >> > This gives a unicode error. >> > >> > Works fine in IDLE, PythonWin, and my Macbook but I need to run this >> > from a windows batch. >> > >> > Character should look like this "?". >> > >> > Please help! >> >> Well, your terminal just cannot display this character by default; you >> need to use a different terminal program, or reconfigure your terminal. >> >> For example, do >> >> chcp 1252 >> >> and select Lucida Console as the terminal font, then try again. >> >> Of course, this will cause *different* characters to become >> non-displayable. > > > Well, > Whoops. Didn't mean to hit send there. I was going to say, you can't have everything when Microsoft is only willing to break the programs that average people are going to use on a daily basis. I mean, why would they do something nice for the international community at the expense of breaking some 20 year old batch scripts? Those were the only things that still worked when Vista first came out. >> >> Regards, >> Martin >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Wed Feb 11 16:22:25 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 11 Feb 2009 16:22:25 -0500 Subject: Avoiding argument checking in recursive calls In-Reply-To: <1f1aebe9287c2339bc670a6347d65440.squirrel@acooke.dyndns.org> References: <7xeiy52zfl.fsf@ruckus.brouhaha.com> <1f1aebe9287c2339bc670a6347d65440.squirrel@acooke.dyndns.org> Message-ID: andrew cooke wrote: > Terry Reedy wrote: >> Reverse the test order >> >> def fact(n): >> if n > 0: return fact(n-1)*n >> if n == 0: return 1 >> raise ValueError > > sweet! but is this generally possible? I believe so, for some meaning of 'generally'. > ie: did you think this up for > this question or is it an idiom that you find yourself using often? It is an idiom I developed for an algorithm book-in-progress that will include detailed comparisons of 'body' recursive (my term for 'not tail recursive", such as fact() above), tail recursive, and iterative versions of algorithms. Here are written-for-didactic-purposes tail and iterative versions of fact that are computationally equivalent to the above in that they compute the same expression, (...((1*1)*2)*....*n), without commutative or associative transformation, and raise the same error (expanded). def fact_tail(n, i=0, res=1): if i < n: return fact_tail(n, i+1, res*(i+1)) if i == n: return res raise ValueError("Input negative or non-integral") def fact_iter(n, i=0, res=1): while i < n: i,res = i+1, res*(i+1) if i == n: return res raise ValueError("Input negative or non-integral") My original reason for writing the tail recursion in the same reversed order was to make the conversion to iteration as obvious as possible. But I them noticed that it also made possible 'test once for bad input without a separate function." Terry Jan Reedy From sjmachin at lexicon.net Wed Feb 11 16:25:07 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 11 Feb 2009 13:25:07 -0800 (PST) Subject: hpw to convert a linux python script ? References: <8848a16f-83db-4acf-a1cc-46653869f27c@z1g2000yqn.googlegroups.com> Message-ID: <1ac73184-be09-4b56-8ad1-7cd4896e0f7c@z6g2000pre.googlegroups.com> On Feb 12, 7:48?am, Stef Mientki wrote: > Alec Schueler wrote: > > On Feb 11, 7:58 pm, Stef Mientki wrote: > > >> As there are a whole lot of these lines, in a whole lot of files, > >> I wonder if there's a simple trick to point > >> ? /usr/share/tinybldLin/ > >> to my directory ? > > >> thanks, > >> Stef > > > Find and replace? > > well I was thinking of a more elegant way, > so the scripts remains, or better become multi-platform. Your current setup is not even single-platform portable ... consider the scenario where some Linux admin wants your gear to live in some directory other than /usr/share/tinybldLin/ The standard technique for ensuring that kind of portability involves: 1. Find the directory in which your script lives. Inspect sys.argv[0], use some os.path.some_functionality() to extract the directory, name it (say) home_base. 2. When you want to open a data file in the script's directory, do this: the_path = os.path.join(home_base, 'stef1.dat') f = open(the_path, .....) NOTE: Use os.path.join() instead of some DIY technique; it knows better than you what the path separator is on the OS it's being run on. In fact, read the whole of the os.path manual carefully before you jump in to changing your code. If you prefer to have the data files in (say) .../script_locn/data instead of .../script_locn, the adjustment should be obvious. Unfortunately, you are still going to need use find and replace to fix your script. Code in haste, repent at leisure :-) HTH, John From sevillad at gmail.com Wed Feb 11 16:27:07 2009 From: sevillad at gmail.com (David Sevilla) Date: Wed, 11 Feb 2009 13:27:07 -0800 (PST) Subject: Locating python References: <3eb685e5-dc80-41d0-acc2-2cafe0cb65c5@e18g2000yqo.googlegroups.com> Message-ID: <604aa733-8e19-4e07-8dde-277d38dde1be@v39g2000yqm.googlegroups.com> > On Feb 3, 7:30?pm, andrew cooke wrote: > > > the exact details of what you are reporting seem a bit odd, but i have > > seen a similar error because i have tried to use my own account to > > install the package, instead of using root. > > > what i believe happens is that easy_install first tries to create the > > "test" file, and then checks it is there. ?if it is not there, you get > > an error. ?normally the error explains that you need to run as root, > > but i assume in your case it doesn't - that seems odd, but it seemed > > worth mentioning anyway. > > > so if you have not done so, instead of > > > ? python setup.py install > > > do > > > ? sudo python setup.py install > > > more generally, i have used opensuse 11.0 and 11.1, and generally > > things work just fine, so i would check you are following all the > > instructions correctly. > > > good luck, > > andrew Well, finally it worked. I even uninstalled python and all related stuff with yast2, installed it all again, then wget http://peak.telecommunity.com/dist/ez_setup.py su /path/to/python ez_setup.py and I got the same error: a certain file could not be created, and /usr/local/lib/python2.5/site-packages/ does not exist. Well, I just created them manually (/usr/local/lib was empty) and it worked. When I tried to use easy_install for mnemosyne, I got the same error _but_ this time I was told about running as root (I did it from another terminal). Now I got it installed (still not working, something called qt) but the python installation problem is solved. Thank you very much to all those who contributed. Regards, David From notvalid2 at sbcglobal.net Wed Feb 11 16:27:24 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Wed, 11 Feb 2009 13:27:24 -0800 Subject: Who's on First, IDLE or pythonWin? Dialog Problem? In-Reply-To: References: Message-ID: Steve Holden wrote: > W. eWatson wrote: >> Steve Holden wrote: >>> W. eWatson wrote: >>>> My program in IDLE bombed with: >>>> ============== >>>> Exception in Tkinter callback >>>> Traceback (most recent call last): >>>> File "C:\Python25\lib\lib-tk\Tkinter.py", line 1403, in __call__ >>>> return self.func(*args) >>>> File >>>> "C:\Sandia_Meteors\New_Sentinel_Development\Sentuser_Utilities_Related\sentuser\sentuserNC25-Dev4.py", >>>> >>>> line 552, in OperationalSettings >>>> dialog = OperationalSettingsDialog( self.master, set_loc_dict ) >>>> File >>>> "C:\Sandia_Meteors\New_Sentinel_Development\Sentuser_Utilities_Related\sentuser\sentuserNC25-Dev4.py", >>>> >>>> line 81, in __init__ >>>> tkSimpleDialog.Dialog.__init__(self, parent) >>>> File "C:\Python25\lib\lib-tk\tkSimpleDialog.py", line 69, in __init__ >>>> self.wait_visibility() # window needs to be visible for the grab >>>> File "C:\Python25\lib\lib-tk\Tkinter.py", line 415, in wait_visibility >>>> self.tk.call('tkwait', 'visibility', window._w) >>>> TclError: window ".34672232" was deleted before its visibility changed >>>> =============== >>>> It runs fine in pythonWin performing the same entry operation. Open a >>>> menu, select an item to open a dialog, select a select button in the >>>> dialog, press OK to leave the dialog. Boom, as above. >>>> >>>> (This does not mean pythonWin doesn't have problems of its own. ) If I >>>> just execute the code (double click on the py file, the console shows no >>>> problems. IDLE is unhappy. >>>> >>>> Another side to this is that I use WinMerge to find differences between >>>> my last saved copy and the current copy. I found the current copy had >>>> two lines where a abc.get() was changed to abc.get. This was undoubtedly >>>> from briefly using the pyWin editor, when I mis-hit some keys. Yet pyWin >>>> had no trouble executing the program. My guess is that while briefly >>>> editing there, I hit some odd combination of keys that produced, >>>> perhaps, an invisible character that pyWin ignores. >>>> >>>> Not the 34672232 window is a dialog that I closed by pressing OK. I >>>> would again guess, that, if there is a problem, it occurs in the code >>>> that destroys the dialog. >>>> >>>> >>> Well you have to remember that you are trying to run a windowed GUI >>> under the control of another windows GUI, so it isn't surprising that >>> you hit trouble. >>> >>> With IDLE the issue will be that IDLE already created a main window >>> before your program started running. With PythonWin you are using two >>> different toolkits, so it isn't really surprising that breaks down - >>> there will be two entirely separate main loops competing with each other. >>> >> Not quite. I take down IDLE when I run pyWin, and vice versa. >> > The two separate loops being PyWin (which uses MFC) and your program > (which uses Tkinter). You just can't mix GUIs in the same process like > that, sorry. > > regards > Stedve I have no idea what MFC is or how it relates to Tkinter. Neither IDLE and pyWin are being run together. Assume neither is running. a. run IDLE, and execute program b. close IDLE script, and interactive window. Kill py program result: boom c. run pyWin and execute program d. do same as b for pyWin resulst: all OK e. repeat a and b. Result: boom Repeat the above and you get the same results. I had running IDLE successfully w/o using Pywin, and IDLE goofed, as above. I switched to it to see if it work there. It did. I double clicked on the py file, and it worked fine. Can you explain this? -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From shandy.b at gmail.com Wed Feb 11 16:30:30 2009 From: shandy.b at gmail.com (sjbrown) Date: Wed, 11 Feb 2009 13:30:30 -0800 (PST) Subject: CPython loading modules into memory Message-ID: Can someone describe the details of how Python loads modules into memory? I assume once the .py file is compiled to .pyc that it is mmap'ed in. But that assumption is very naive. Maybe it uses an anonymous mapping? Maybe it does other special magic? This is all very alien to me, so if someone could explain it in terms that a person who never usually worries about memory could understand, that would be much appreciated. Follow up: is this process different if the modules are loaded from a zipfile? If there is a link that covers this info, that'd be great too. From graham.dumpleton at gmail.com Wed Feb 11 16:32:36 2009 From: graham.dumpleton at gmail.com (Graham Dumpleton) Date: Thu, 12 Feb 2009 08:32:36 +1100 Subject: best way to serve wsgi with multiple processes In-Reply-To: References: <2d705579-6c7e-46b1-a9f7-4be4c3af487a@t13g2000yqc.googlegroups.com> <470f306f-a887-4ee5-952c-d01a66eec411@w39g2000prb.googlegroups.com> Message-ID: <88e286470902111332t50a60708g8bba776b0c7f5b69@mail.gmail.com> 2009/2/12 alex goretoy : > GAE (Google App Engine) uses WSGI for webapps. You don't have to overhead of > managing a server and all it's services this way as well. Just manage dns > entries. Although, there are limitations depending on your project needs of > what libs you need to use. GAE is not suitable as they kill off any requests that take more than a set time. That time isn't that long, so can't support long running requests. Graham > appengine.google.com > > -Alex Goretoy > http://www.goretoy.com > > > > On Wed, Feb 11, 2009 at 1:59 PM, Graham Dumpleton > wrote: >> >> On Feb 11, 8:50 pm, Robin wrote: >> > Hi, >> > >> > I am building some computational web services using soaplib. This >> > creates a WSGI application. >> > >> > However, since some of these services are computationally intensive, >> > and may be long running, I was looking for a way to use multiple >> > processes. I thought about using multiprocessing.Process manually in >> > the service, but I was a bit worried about how that might interact >> > with a threaded server (I was hoping the thread serving that request >> > could just wait until the child is finished). Also it would be good to >> > keep the services as simple as possible so it's easier for people to >> > write them. >> > >> > I have at the moment the following WSGI structure: >> > TransLogger(URLMap(URLParser(soaplib objects))) >> > although presumably, due to the beauty of WSGI, this shouldn't matter. >> > >> > As I've found with all web-related Python stuff, I'm overwhelmed by >> > the choice and number of alternatives. I've so far been using cherrypy >> > and ajp-wsgi for my testing, but am aware of Spawning, twisted etc. >> > What would be the simplest [quickest to setup and fewest details of >> > the server required - ideally with a simple example] and most reliable >> > [this will eventually be 'in production' as part of a large scientific >> > project] way to host this sort of WSGI with a process-per-request >> > style? >> >> In this sort of situation one wouldn't normally do the work in the >> main web server, but have a separarte long running daemon process >> embedding mini web server that understands XML-RPC. The main web >> server would then make XML-RPC requests against the backend daemon >> process, which would use threading and or queueing to handle the >> requests. >> >> If the work is indeed long running, the backend process would normally >> just acknowledge the request and not wait. The web page would return >> and it would be up to user to then somehow occassionally poll web >> server, manually or by AJAX, to see how progres is going. That is, >> further XML-RPC requests from main server to backend daemon process >> asking about progress. >> >> I do't believe the suggestions about fastcgi/scgi/ajp/flup or mod_wsgi >> are really appropriate as you don't want this done in web server >> processes as then you are at mercy of web server processes being >> killed or dying when part way through something. Some of these systems >> will do this if requests take too long. Thus better to offload real >> work to another process. >> >> Graham >> -- >> http://mail.python.org/mailman/listinfo/python-list > > From kyosohma at gmail.com Wed Feb 11 16:33:26 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Wed, 11 Feb 2009 13:33:26 -0800 (PST) Subject: Who's on First, IDLE or pythonWin? Dialog Problem? References: Message-ID: <5230d343-6a67-4bc9-af10-8d68ffdc8339@s20g2000yqh.googlegroups.com> On Feb 11, 3:27?pm, "W. eWatson" wrote: > Steve Holden wrote: > > W. eWatson wrote: > >> Steve Holden wrote: > >>> W. eWatson wrote: > >>>> My program in IDLE bombed with: > >>>> ============== > >>>> Exception in Tkinter callback > >>>> Traceback (most recent call last): > >>>> ? File "C:\Python25\lib\lib-tk\Tkinter.py", line 1403, in __call__ > >>>> ? ? return self.func(*args) > >>>> ? File > >>>> "C:\Sandia_Meteors\New_Sentinel_Development\Sentuser_Utilities_Related\sentuser\sentuserNC25-Dev4.py", > > >>>> line 552, in OperationalSettings > >>>> ? ? dialog = OperationalSettingsDialog( self.master, set_loc_dict ) > >>>> ? File > >>>> "C:\Sandia_Meteors\New_Sentinel_Development\Sentuser_Utilities_Related\sentuser\sentuserNC25-Dev4.py", > > >>>> line 81, in __init__ > >>>> ? ? tkSimpleDialog.Dialog.__init__(self, parent) > >>>> ? File "C:\Python25\lib\lib-tk\tkSimpleDialog.py", line 69, in __init__ > >>>> ? ? self.wait_visibility() # window needs to be visible for the grab > >>>> ? File "C:\Python25\lib\lib-tk\Tkinter.py", line 415, in wait_visibility > >>>> ? ? self.tk.call('tkwait', 'visibility', window._w) > >>>> TclError: window ".34672232" was deleted before its visibility changed > >>>> =============== > >>>> It runs fine in pythonWin performing the same entry operation. Open a > >>>> menu, ?select an item to open a dialog, select a select button in the > >>>> dialog, press OK to leave the dialog. Boom, as above. > > >>>> (This does not mean pythonWin doesn't have problems of its own. ) If I > >>>> just execute the code (double click on the py file, the console shows no > >>>> problems. IDLE is unhappy. > > >>>> Another side to this is that I use WinMerge to find differences between > >>>> my last saved copy and the current copy. I found the current copy had > >>>> two lines where a abc.get() was changed to abc.get. This was undoubtedly > >>>> from briefly using the pyWin editor, when I mis-hit some keys. Yet pyWin > >>>> had no trouble executing the program. My guess is that while briefly > >>>> editing there, I hit some odd combination of keys that produced, > >>>> perhaps, an invisible character that pyWin ignores. > > >>>> Not the 34672232 window is a dialog that I closed by pressing OK. I > >>>> would again guess, that, if there is a problem, it occurs in the code > >>>> that destroys the dialog. > > >>> Well you have to remember that you are trying to run a windowed GUI > >>> under the control of another windows GUI, so it isn't surprising that > >>> you hit trouble. > > >>> With IDLE the issue will be that IDLE already created a main window > >>> before your program started running. With PythonWin you are using two > >>> different toolkits, so it isn't really surprising that breaks down - > >>> there will be two entirely separate main loops competing with each other. > > >> Not quite. I take down IDLE when I run pyWin, and vice versa. > > > The two separate loops being PyWin (which uses MFC) and your program > > (which uses Tkinter). You just can't mix GUIs in the same process like > > that, sorry. > > > regards > > ?Stedve > > I have no idea what MFC is or how it relates to Tkinter. Neither IDLE and > pyWin are being run together. > > Assume neither is running. > a. run IDLE, and execute program > b. close IDLE script, and interactive window. Kill py program > result: boom > c. run pyWin and execute program > d. do same as b for pyWin > resulst: all OK > e. repeat a and b. > Result: boom > > Repeat the above and you get the same results. > > I had running IDLE successfully w/o using Pywin, and IDLE goofed, as above. > I switched to it to see if it work there. It did. I double clicked on the py > file, and it worked fine. Can you explain this? > > -- > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? W. eWatson > > ? ? ? ? ? ? ? (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) > ? ? ? ? ? ? ? ?Obz Site: ?39? 15' 7" N, 121? 2' 32" W, 2700 feet > > ? ? ? ? ? ? ? ? ? ? ?Web Page: What Steve (and I) are saying is that IDLE has it's own mainloop and your program has a mainloop too as it sounds like it is running a Tkinter app. Sometimes when you run a Tk app from another Tk app, the two mainloops clash and have weird issue like this one. If you just double-click it or run it from the command line, you only have one mainloop (i.e. the one that's part of your app). Thus, no conflicts. Mike From google at mrabarnett.plus.com Wed Feb 11 16:34:59 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 11 Feb 2009 21:34:59 +0000 Subject: Unicode issue on Windows cmd line In-Reply-To: References: <5827412b-5637-4005-9410-972b7f1f18ca@h20g2000yqn.googlegroups.com> <49933bb6$0$3304$9b622d9e@news.freenet.de> Message-ID: <49934483.3010000@mrabarnett.plus.com> Benjamin Kaplan wrote: [snip] > Whoops. Didn't mean to hit send there. I was going to say, you can't > have everything when Microsoft is only willing to break the programs > that average people are going to use on a daily basis. I mean, why > would they do something nice for the international community at the > expense of breaking some 20 year old batch scripts? Those were the > only things that still worked when Vista first came out. > I remember when I had to use MS-Access but it could be either of 2 versions. The newer version couldn't open a database from the older version unless I let it convert it first, after which point I wouldn't be able to open it in the older version... :-( From tjreedy at udel.edu Wed Feb 11 16:44:12 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 11 Feb 2009 16:44:12 -0500 Subject: openOffic, windows, and Python 2.5 In-Reply-To: References: Message-ID: John Fabiani wrote: > Hi, > OpenOffice 3 on windows uses python 2.3.x (I have no idea why). I presume because no one has volunteered to do the update for the Py-UNO bridge. In any case, why do you consider that to be a problem. It is common for apps to include the Python they are known to work with. tjr From robert.kern at gmail.com Wed Feb 11 16:45:25 2009 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 11 Feb 2009 15:45:25 -0600 Subject: CPython loading modules into memory In-Reply-To: References: Message-ID: On 2009-02-11 15:30, sjbrown wrote: > Can someone describe the details of how Python loads modules into > memory? I assume once the .py file is compiled to .pyc that it is > mmap'ed in. But that assumption is very naive. Maybe it uses an > anonymous mapping? Maybe it does other special magic? This is all > very alien to me, so if someone could explain it in terms that a > person who never usually worries about memory could understand, that > would be much appreciated. Python will read the .py file and compile into bytecode. This bytecode will be written out to a .pyc file as a caching mechanism; if the .pyc exists and has a newer timestamp than the .py file, the .py file will not be read or compiled. The bytecode will simply be read from the .pyc file. The .pyc file is not really a map of a memory structure, per se. It is simply a disk representation of the bytecode. This bytecode is *executed* by the Python VM to populate a module's namespace (which is just a dict) in memory. I believe it is then discarded. > Follow up: is this process different if the modules are loaded from a > zipfile? Only in that the .py or .pyc will be extracted from the zipfile instead of being read directly from disk. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From sjmachin at lexicon.net Wed Feb 11 16:48:58 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 11 Feb 2009 13:48:58 -0800 (PST) Subject: getopt index out of range References: Message-ID: <3de24dce-1ee5-4f3f-9ef9-fcc2d28f372e@v5g2000pre.googlegroups.com> On Feb 11, 6:16?am, Matthew Sacks wrote: > Hi List, > I am getting an index out of range error when trying to parse with getopt. > Probably something simple. Any suggestions are appreciated > > optlist, args = getopt.getopt(sys.argv[1:], 'h', ['connectPassword=', > 'adminServerURL=', 'action=', 'targets=', 'appDir=']) > > #Assign Opts > connectPassword = optlist[0][1] > adminServerURL = optlist[1][1] > action = optlist[2][1] > targets = optlist[3][1] > appDir = optlist[4][1] As you have been told, it is blowing up on index 0. That is because optlist is empty (in this case). optlist can contain anything from 0 items to as many as your user cares to type in. It is NOT limited to the number of different options specified in the getopt call; consider the case where the arg string is "--action add --action del". Further, the contents of optlist are presented in the order they are typed in by the user. Consequently any attempt to give meaningful names to option values using constant subscripting of optlist is prima facie an utter nonsense. It is a mind-bogglingly astonishing utter nonsense given the lengthy conversation about getopt that we had in another thread yesterday. What on earth are you doing??? From martin at v.loewis.de Wed Feb 11 17:00:24 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 11 Feb 2009 23:00:24 +0100 Subject: CPython loading modules into memory In-Reply-To: References: Message-ID: <49934A78.10309@v.loewis.de> > Can someone describe the details of how Python loads modules into > memory? I assume once the .py file is compiled to .pyc that it is > mmap'ed in. But that assumption is very naive. Maybe it uses an > anonymous mapping? Maybe it does other special magic? This is all > very alien to me, so if someone could explain it in terms that a > person who never usually worries about memory could understand, that > would be much appreciated. There is no magic whatsoever. Python opens a sequential file descriptor for the .pyc file, and then reads it in small chunks, "unmarshalling" it (indeed, the marshal module is used to restore Python objects). The marshal format is an object serialization in a type-value encoding (sometimes type-length-value), with type codes for: - None, True, False - 32-bit ints, 64-bit ints (unmarshalled into int/long) - floats, complex - arbitrary-sized longs - strings, unicode - tuples (length + marshal data of values) - lists - dicts - code objects - a few others Result of unmarshalling is typically a code object. > Follow up: is this process different if the modules are loaded from a > zipfile? No; it uncompresses into memory, and then unmarshals from there ( compressed block for compressed block) > If there is a link that covers this info, that'd be great too. See the description of the marshal module. HTH, Martin From gagsl-py2 at yahoo.com.ar Wed Feb 11 17:09:20 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 11 Feb 2009 20:09:20 -0200 Subject: Iterable Ctypes Struct References: <99d4c7ae-27ae-4f3a-8475-a58f1c4e6925@t26g2000prh.googlegroups.com> <002f91bd-a30a-4fbf-a757-d496cd381dbf@p23g2000prp.googlegroups.com> <9d48e184-5bae-4c3a-b500-d49c38913b39@r41g2000prr.googlegroups.com> Message-ID: En Wed, 11 Feb 2009 16:32:41 -0200, escribi?: > On Feb 11, 9:01?am, mark.sea... at gmail.com wrote: >> On Feb 10, 9:52?pm, "Gabriel Genellina" >> wrote: >> > En Wed, 11 Feb 2009 00:31:26 -0200, escribi?: >> >> > > I like the ability to access elements of a struct such as with > > >> ctypes >> > > Structure: >> > > What I don't like about it is that it's not iterable: >> > > I don't want to force the end user to have preknowledge of the > > >> element >> > > names. [recipe using _fields_] >> Thanks very much, Gabriel. ?This is very good start for me. >> This works for predefined class. ?How about a situation where the >> fields are added dynamically (as from reading in from an xml file). > I tinkered with it and think I have viable solution. > I need to append a new member to _fields_ before writing it, > then it seems to work. > >>>> p._fields_.append(('z', c_int)) >>>> point.z = 30 >>>> print 'List:', list(p) > List: [10, 20, 30] Yes, that's the way to add a new field -- but you have to do that before creating the first instance. Anywy, this is somewhat strange for a ctypes Structure. Usually its memory layout is fixed and mandated by the library/format/whatever you're trying to bind to. You are not using it as a generic attribute container, are you? There are better alternatives in that case. -- Gabriel Genellina From jeffgemail at gmail.com Wed Feb 11 17:10:50 2009 From: jeffgemail at gmail.com (jeffg) Date: Wed, 11 Feb 2009 14:10:50 -0800 (PST) Subject: Unicode issue on Windows cmd line References: <5827412b-5637-4005-9410-972b7f1f18ca@h20g2000yqn.googlegroups.com> <49933bb6$0$3304$9b622d9e@news.freenet.de> Message-ID: <173b3dc8-4c7d-4049-979f-492ac8d6fb17@i20g2000prf.googlegroups.com> On Feb 11, 3:57?pm, "Martin v. L?wis" wrote: > > Having issue on Windows cmd. > >> Python.exe > >>>> a = u'\xf0' > >>>> print a > > > This gives a unicode error. > > > Works fine in IDLE, PythonWin, and my Macbook but I need to run this > > from a windows batch. > > > Character should look like this "?". > > > Please help! > > Well, your terminal just cannot display this character by default; you > need to use a different terminal program, or reconfigure your terminal. > > For example, do > > chcp 1252 > > and select Lucida Console as the terminal font, then try again. > > Of course, this will cause *different* characters to become > non-displayable. > > Regards, > Martin Thanks, I ended up using encode('iso-8859-15', "replace") Perhaps more up to date than cp1252...?? It still didn't print correctly, but it did write correctly, which was my main problem. From robince at gmail.com Wed Feb 11 17:19:45 2009 From: robince at gmail.com (Robin) Date: Wed, 11 Feb 2009 14:19:45 -0800 (PST) Subject: best way to serve wsgi with multiple processes References: <2d705579-6c7e-46b1-a9f7-4be4c3af487a@t13g2000yqc.googlegroups.com> <470f306f-a887-4ee5-952c-d01a66eec411@w39g2000prb.googlegroups.com> Message-ID: <93a73522-66d6-4276-aa5c-4dc913de6adb@13g2000yql.googlegroups.com> On Feb 11, 7:59?pm, Graham Dumpleton wrote: > On Feb 11, 8:50?pm, Robin wrote: > > > > > Hi, > > > I am building some computational web services using soaplib. This > > creates a WSGI application. > > > However, since some of these services are computationally intensive, > > and may be long running, I was looking for a way to use multiple > > processes. I thought about using multiprocessing.Process manually in > > the service, but I was a bit worried about how that might interact > > with a threaded server (I was hoping the thread serving that request > > could just wait until the child is finished). Also it would be good to > > keep the services as simple as possible so it's easier for people to > > write them. > > > I have at the moment the following WSGI structure: > > TransLogger(URLMap(URLParser(soaplib objects))) > > although presumably, due to the beauty of WSGI, this shouldn't matter. > > > As I've found with all web-related Python stuff, I'm overwhelmed by > > the choice and number of alternatives. I've so far been using cherrypy > > and ajp-wsgi for my testing, but am aware of Spawning, twisted etc. > > What would be the simplest [quickest to setup and fewest details of > > the server required - ideally with a simple example] and most reliable > > [this will eventually be 'in production' as part of a large scientific > > project] way to host this sort of WSGI with a process-per-request > > style? > > In this sort of situation one wouldn't normally do the work in the > main web server, but have a separarte long running daemon process > embedding mini web server that understands XML-RPC. The main web > server would then make XML-RPC requests against the backend daemon > process, which would use threading and or queueing to handle the > requests. > > If the work is indeed long running, the backend process would normally > just acknowledge the request and not wait. The web page would return > and it would be up to user to then somehow occassionally poll web > server, manually or by AJAX, to see how progres is going. That is, > further XML-RPC requests from main server to backend daemon process > asking about progress. > > I do't believe the suggestions about fastcgi/scgi/ajp/flup or mod_wsgi > are really appropriate as you don't want this done in web server > processes as then you are at mercy of web server processes being > killed or dying when part way through something. Some of these systems > will do this if requests take too long. Thus better to offload real > work to another process. Thanks - in this case I am contrained to use SOAP (I am providing SOAP services using soaplib so they run as a WSGI app). I choose soaplib becuase it seems the simplest way to get soap services running in Python (I was hoping to get this setup quickly). So I am not really able to get into anything more complex as you suggest... I have my nice easy WSGI app soap service, I would just like it to run in a process pool to avoid GIL. Turns out I can do that with apache+mod_wsgi and daemon mode, or flup forked server (I would probably use ajp - so flup is in a seperate process to apache and listens on some local port, and apache proxies to that using the ajp protocol). I'm not sure which one is best... for now I'm continuing to just develop on cherrypy on my own machine. I suspect I will use ajp forked flup, since that only requires mod_proxy and mod_proxy_ajp which I understand come with standard apache and the system administrators will probably be happier with. Cheers Robin From ntwrkd at gmail.com Wed Feb 11 17:20:36 2009 From: ntwrkd at gmail.com (Matthew Sacks) Date: Wed, 11 Feb 2009 14:20:36 -0800 Subject: getopt index out of range In-Reply-To: <3de24dce-1ee5-4f3f-9ef9-fcc2d28f372e@v5g2000pre.googlegroups.com> References: <3de24dce-1ee5-4f3f-9ef9-fcc2d28f372e@v5g2000pre.googlegroups.com> Message-ID: Perhaps you can give me a call privately and I will explain it to you. Regards, Matthew On Wed, Feb 11, 2009 at 1:48 PM, John Machin wrote: > On Feb 11, 6:16 am, Matthew Sacks wrote: >> Hi List, >> I am getting an index out of range error when trying to parse with getopt. >> Probably something simple. Any suggestions are appreciated >> >> optlist, args = getopt.getopt(sys.argv[1:], 'h', ['connectPassword=', >> 'adminServerURL=', 'action=', 'targets=', 'appDir=']) >> >> #Assign Opts >> connectPassword = optlist[0][1] >> adminServerURL = optlist[1][1] >> action = optlist[2][1] >> targets = optlist[3][1] >> appDir = optlist[4][1] > > As you have been told, it is blowing up on index 0. That is because > optlist is empty (in this case). optlist can contain anything from 0 > items to as many as your user cares to type in. It is NOT limited to > the number of different options specified in the getopt call; consider > the case where the arg string is "--action add --action del". Further, > the contents of optlist are presented in the order they are typed in > by the user. > > Consequently any attempt to give meaningful names to option values > using constant subscripting of optlist is prima facie an utter > nonsense. > > It is a mind-bogglingly astonishing utter nonsense given the lengthy > conversation about getopt that we had in another thread yesterday. > What on earth are you doing??? > > -- > http://mail.python.org/mailman/listinfo/python-list > From robince at gmail.com Wed Feb 11 17:22:17 2009 From: robince at gmail.com (Robin) Date: Wed, 11 Feb 2009 14:22:17 -0800 (PST) Subject: best way to serve wsgi with multiple processes References: <2d705579-6c7e-46b1-a9f7-4be4c3af487a@t13g2000yqc.googlegroups.com> <470f306f-a887-4ee5-952c-d01a66eec411@w39g2000prb.googlegroups.com> Message-ID: <5db4cb26-1558-44e7-ab34-72d78027740f@f3g2000yqf.googlegroups.com> On Feb 11, 9:32?pm, Graham Dumpleton wrote: > 2009/2/12 alex goretoy : > > > GAE (Google App Engine) uses WSGI for webapps. You don't have to overhead of > > managing a server and all it's services this way as well. Just manage dns > > entries. Although, there are limitations depending on your project needs of > > what libs you need to use. > > GAE is not suitable as they kill off any requests that take more than > a set time. That time isn't that long, so can't support long running > requests. GAE is definitely not suitable in this case... The servers are provided and maintained as part of a large scientific project for which I am providing just a few services... Other groups are running services in other platforms on tomcat through soaplab/instantsoap - but I was hoping to use native python services since I thought it would be easier. Cheers Robin From ntwrkd at gmail.com Wed Feb 11 17:27:13 2009 From: ntwrkd at gmail.com (Matthew Sacks) Date: Wed, 11 Feb 2009 14:27:13 -0800 Subject: getopt index out of range In-Reply-To: <3de24dce-1ee5-4f3f-9ef9-fcc2d28f372e@v5g2000pre.googlegroups.com> References: <3de24dce-1ee5-4f3f-9ef9-fcc2d28f372e@v5g2000pre.googlegroups.com> Message-ID: Keep your threadiquette to yourself. On Wed, Feb 11, 2009 at 1:48 PM, John Machin wrote: > On Feb 11, 6:16 am, Matthew Sacks wrote: >> Hi List, >> I am getting an index out of range error when trying to parse with getopt. >> Probably something simple. Any suggestions are appreciated >> >> optlist, args = getopt.getopt(sys.argv[1:], 'h', ['connectPassword=', >> 'adminServerURL=', 'action=', 'targets=', 'appDir=']) >> >> #Assign Opts >> connectPassword = optlist[0][1] >> adminServerURL = optlist[1][1] >> action = optlist[2][1] >> targets = optlist[3][1] >> appDir = optlist[4][1] > > As you have been told, it is blowing up on index 0. That is because > optlist is empty (in this case). optlist can contain anything from 0 > items to as many as your user cares to type in. It is NOT limited to > the number of different options specified in the getopt call; consider > the case where the arg string is "--action add --action del". Further, > the contents of optlist are presented in the order they are typed in > by the user. > > Consequently any attempt to give meaningful names to option values > using constant subscripting of optlist is prima facie an utter > nonsense. > > It is a mind-bogglingly astonishing utter nonsense given the lengthy > conversation about getopt that we had in another thread yesterday. > What on earth are you doing??? > > -- > http://mail.python.org/mailman/listinfo/python-list > From gnewsg at gmail.com Wed Feb 11 17:28:18 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Wed, 11 Feb 2009 14:28:18 -0800 (PST) Subject: ANN: Python 2.6 Quick Reference available References: <4991d7b0$0$4785$426a34cc@news.free.fr> Message-ID: On Feb 10, 8:38?pm, Richard Gruet <"rgruet at free dot fr"> wrote: > The Python 2.6 Quick Reference is available in HTML and PDF formats athttp://rgruet.free.fr/#QuickRef. > > This time I was helped by Josh Stone for the update. > > As usual, your feedback is welcome (pqr at rgruet.net). > > Cheers, > > Richard Gruet Thanks a lot. PQR is one of the most useful Python related document on Internet, IMHO. --- Giampaolo http://code.google.com/p/pyftpdlib From benjamin.kaplan at case.edu Wed Feb 11 17:35:57 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 11 Feb 2009 17:35:57 -0500 Subject: Unicode issue on Windows cmd line In-Reply-To: <173b3dc8-4c7d-4049-979f-492ac8d6fb17@i20g2000prf.googlegroups.com> References: <5827412b-5637-4005-9410-972b7f1f18ca@h20g2000yqn.googlegroups.com> <49933bb6$0$3304$9b622d9e@news.freenet.de> <173b3dc8-4c7d-4049-979f-492ac8d6fb17@i20g2000prf.googlegroups.com> Message-ID: On Wed, Feb 11, 2009 at 5:10 PM, jeffg wrote: > On Feb 11, 3:57 pm, "Martin v. L?wis" wrote: > > > Having issue on Windows cmd. > > >> Python.exe > > >>>> a = u'\xf0' > > >>>> print a > > > > > This gives a unicode error. > > > > > Works fine in IDLE, PythonWin, and my Macbook but I need to run this > > > from a windows batch. > > > > > Character should look like this "?". > > > > > Please help! > > > > Well, your terminal just cannot display this character by default; you > > need to use a different terminal program, or reconfigure your terminal. > > > > For example, do > > > > chcp 1252 > > > > and select Lucida Console as the terminal font, then try again. > > > > Of course, this will cause *different* characters to become > > non-displayable. > > > > Regards, > > Martin > > Thanks, I ended up using encode('iso-8859-15', "replace") > Perhaps more up to date than cp1252...?? > It still didn't print correctly, but it did write correctly, which was > my main problem. Let me guess, it showed up as *?**. *This is the cp437 symbol at 0xf0. When Python sends the string to stdout, it doesn't send characters, it sends a stream of bytes. It is up to the file or file-like object at the other end (in this case, cmd.exe) to interpret those bytes. Both cp1252 and ISO-8859-15 interpret the byte /xf0 as ?. When you opened the text file, it probbly opened as cp1252 because that's the Windows default. If you change the terminal encoding, it will display correctly for the same reason. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From aleksandr.goretoy at gmail.com Wed Feb 11 17:39:30 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Wed, 11 Feb 2009 16:39:30 -0600 Subject: best way to serve wsgi with multiple processes In-Reply-To: <5db4cb26-1558-44e7-ab34-72d78027740f@f3g2000yqf.googlegroups.com> References: <2d705579-6c7e-46b1-a9f7-4be4c3af487a@t13g2000yqc.googlegroups.com> <470f306f-a887-4ee5-952c-d01a66eec411@w39g2000prb.googlegroups.com> <5db4cb26-1558-44e7-ab34-72d78027740f@f3g2000yqf.googlegroups.com> Message-ID: > > > GAE is definitely not suitable in this case... The servers are >> provided and maintained as part of a large scientific project for >> which I am providing just a few services... Other groups are running >> services in other platforms on tomcat through soaplab/instantsoap - >> but I was hoping to use native python services since I thought it >> would be easier. >> > OK, that's cool. I understand about project requirements. It was just a suggestion. Nonetheless I'm still interested in what people have to say in this thread. -------------- next part -------------- An HTML attachment was scrubbed... URL: From Graham.Dumpleton at gmail.com Wed Feb 11 17:55:11 2009 From: Graham.Dumpleton at gmail.com (Graham Dumpleton) Date: Wed, 11 Feb 2009 14:55:11 -0800 (PST) Subject: best way to serve wsgi with multiple processes References: <2d705579-6c7e-46b1-a9f7-4be4c3af487a@t13g2000yqc.googlegroups.com> <470f306f-a887-4ee5-952c-d01a66eec411@w39g2000prb.googlegroups.com> <93a73522-66d6-4276-aa5c-4dc913de6adb@13g2000yql.googlegroups.com> Message-ID: On Feb 12, 9:19?am, Robin wrote: > On Feb 11, 7:59?pm, Graham Dumpleton > wrote: > > > > > On Feb 11, 8:50?pm, Robin wrote: > > > > Hi, > > > > I am building some computational web services using soaplib. This > > > creates a WSGI application. > > > > However, since some of these services are computationally intensive, > > > and may be long running, I was looking for a way to use multiple > > > processes. I thought about using multiprocessing.Process manually in > > > the service, but I was a bit worried about how that might interact > > > with a threaded server (I was hoping the thread serving that request > > > could just wait until the child is finished). Also it would be good to > > > keep the services as simple as possible so it's easier for people to > > > write them. > > > > I have at the moment the following WSGI structure: > > > TransLogger(URLMap(URLParser(soaplib objects))) > > > although presumably, due to the beauty of WSGI, this shouldn't matter. > > > > As I've found with all web-related Python stuff, I'm overwhelmed by > > > the choice and number of alternatives. I've so far been using cherrypy > > > and ajp-wsgi for my testing, but am aware of Spawning, twisted etc. > > > What would be the simplest [quickest to setup and fewest details of > > > the server required - ideally with a simple example] and most reliable > > > [this will eventually be 'in production' as part of a large scientific > > > project] way to host this sort of WSGI with a process-per-request > > > style? > > > In this sort of situation one wouldn't normally do the work in the > > main web server, but have a separarte long running daemon process > > embedding mini web server that understands XML-RPC. The main web > > server would then make XML-RPC requests against the backend daemon > > process, which would use threading and or queueing to handle the > > requests. > > > If the work is indeed long running, the backend process would normally > > just acknowledge the request and not wait. The web page would return > > and it would be up to user to then somehow occassionally poll web > > server, manually or by AJAX, to see how progres is going. That is, > > further XML-RPC requests from main server to backend daemon process > > asking about progress. > > > I do't believe the suggestions about fastcgi/scgi/ajp/flup or mod_wsgi > > are really appropriate as you don't want this done in web server > > processes as then you are at mercy of web server processes being > > killed or dying when part way through something. Some of these systems > > will do this if requests take too long. Thus better to offload real > > work to another process. > > Thanks - in this case I am contrained to use SOAP (I am providing SOAP > services using soaplib so they run as a WSGI app). I choose soaplib > becuase it seems the simplest way to get soap services running in > Python (I was hoping to get this setup quickly). > So I am not really able to get into anything more complex as you > suggest... I have my nice easy WSGI app soap service, I would just > like it to run in a process pool to avoid GIL. You can still use SOAP, you don't have to use XML-RPC, they are after all just an interprocess communications mechanism. > Turns out I can do that > with apache+mod_wsgi and daemon mode, or flup forked server (I would > probably use ajp - so flup is in a seperate process to apache and > listens on some local port, and apache proxies to that using the ajp > protocol). I'm not sure which one is best... for now I'm continuing to > just develop on cherrypy on my own machine. In mod_wsgi daemon mode the application is still in a distinct process. The only dfference is that Apache is acting as the process supervisor and you do not have to install a separate system such as supervisord or monit to start up the process and ensure it is restarted if it crashes, as Apache/mod_wsgi will do that for you. You also don't need flup when using mod_wsgi as it provides everything. > I suspect I will use ajp forked flup, since that only requires > mod_proxy and mod_proxy_ajp which I understand come with standard > apache and the system administrators will probably be happier with. The Apache/mod_wsgi approach actually has less dependencies. For it you only need Apache+mod_wsgi. For AJP you need Apache+flup+monit-or- supervisord. Just depends on which dependencies you think are easier to configure and manage. :-) Graham From antoinedg at gmail.com Wed Feb 11 18:00:22 2009 From: antoinedg at gmail.com (Antoine De Groote) Date: Thu, 12 Feb 2009 00:00:22 +0100 Subject: Clearing the keyboard buffer (wxPython) In-Reply-To: References: Message-ID: <26bd3$49935887$5449a757$28903@news.hispeed.ch> yes, the server seems to have been down :-( MarcusD wrote: > Whow. Thanks for the fast and comprehensive answer. To be honest I would > have posted to wxpython.org but the server seems to be down for the last > couple of days. > > I'll check this wx.Yield thing that I never heard of. And let's see what > else we get here. > Thanks again > marcus > > From daniel.watrous at gmail.com Wed Feb 11 18:01:01 2009 From: daniel.watrous at gmail.com (Daniel) Date: Wed, 11 Feb 2009 15:01:01 -0800 (PST) Subject: where is handle_timeout in SocketServer Message-ID: <4db93841-0fe9-4e3e-b90d-8e0f9cc986c4@m40g2000yqh.googlegroups.com> I've just been reading the docs to help me with a SocketServer issue. I found in the docs (http://docs.python.org/library/socketserver.html) a reference to a member attribute timeout and a member function handle_timeout() is made. I am using python 2.5 and there's no indication that these were added in 2.6 or later. I've also searched Google and found that it may have been committed as long ago as January of last year (http://mail.python.org/pipermail/python-checkins/ 2008-January/064877.html). Why isn't it available in my version of python? Is there another place to find it? Please help me figure out what I'm missing so that I can use the timeout functionality in my SocketServers. Thanks. From rpolanco at estudiantes.uci.cu Wed Feb 11 18:09:36 2009 From: rpolanco at estudiantes.uci.cu (Rosell Pupo Polanco) Date: Wed, 11 Feb 2009 15:09:36 -0800 Subject: how many databases exists? Message-ID: <4260DCD6-B6D4-4372-A658-C880DAACAF7E@mimectl> hello, i am working in pythoncard and i need to know how many databases exist in my server POstgresql, exists some funcion in python that can help me?? greettings..Rosell .::[ La vida es rica en saberes, pero la vida es breve y no se vive, si no se sabe. ]::. -------------- next part -------------- An HTML attachment was scrubbed... URL: From cosmo_general at yahoo.com Wed Feb 11 18:17:24 2009 From: cosmo_general at yahoo.com (Muddy Coder) Date: Wed, 11 Feb 2009 15:17:24 -0800 (PST) Subject: Can I 'LOOK' through urllib? Message-ID: <2c1dc513-977d-4796-8c5e-118619ef3ae2@v19g2000yqn.googlegroups.com> Hi Folks, I feel good after played urllib with fun! Now I want to LOOK to server through urllib. I read the urllib docs, but I did not find such a function. For example, if there are many files located in http://www.somedomain.com/data_folder, but I don't know what the filenames are residing in the data_folder. I wish urllib would have a function to let me do it, as well as I do 'dir' in DOS, 'ls' on unix/linux. Somebody write me a demo? Thanks! Muddy Coder From daniel.watrous at gmail.com Wed Feb 11 18:21:13 2009 From: daniel.watrous at gmail.com (Daniel) Date: Wed, 11 Feb 2009 15:21:13 -0800 (PST) Subject: where is handle_timeout in SocketServer References: <4db93841-0fe9-4e3e-b90d-8e0f9cc986c4@m40g2000yqh.googlegroups.com> Message-ID: <05d92dff-0eae-40e9-b456-53f4f73aa507@m42g2000yqb.googlegroups.com> On Feb 11, 4:01?pm, Daniel wrote: > I've just been reading the docs to help me with a SocketServer issue. > I found in the docs (http://docs.python.org/library/socketserver.html) > a reference to a member attribute timeout and a member function > handle_timeout() is made. ?I am using python 2.5 and there's no > indication that these were added in 2.6 or later. ?I've also searched > Google and found that it may have been committed as long ago as > January of last year (http://mail.python.org/pipermail/python-checkins/ > 2008-January/064877.html). > > Why isn't it available in my version of python? ?Is there another > place to find it? ?Please help me figure out what I'm missing so that > I can use the timeout functionality in my SocketServers. > > Thanks. I've just looked at the subversion repository and it does appear that the timeout functionality was introduced in python 2.6 (or after 2.5.2 anyway). http://svn.python.org/projects/python/trunk/Lib/SocketServer.py http://svn.python.org/projects/python/tags/r252/Lib/SocketServer.py I guess I'll see what I can do to adapt since porting my entire project isn't realistic at this point. From notvalid2 at sbcglobal.net Wed Feb 11 18:28:44 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Wed, 11 Feb 2009 15:28:44 -0800 Subject: Who's on First, IDLE or pythonWin? Dialog Problem? In-Reply-To: <5230d343-6a67-4bc9-af10-8d68ffdc8339@s20g2000yqh.googlegroups.com> References: <5230d343-6a67-4bc9-af10-8d68ffdc8339@s20g2000yqh.googlegroups.com> Message-ID: Mike Driscoll wrote: > On Feb 11, 3:27 pm, "W. eWatson" wrote: >> Steve Holden wrote: >>> W. eWatson wrote: >>>> Steve Holden wrote: >>>>> W. eWatson wrote: >>>>>> My program in IDLE bombed with: >>>>>> ============== >>>>>> Exception in Tkinter callback >>>>>> Traceback (most recent call last): >>>>>> File "C:\Python25\lib\lib-tk\Tkinter.py", line 1403, in __call__ >>>>>> return self.func(*args) >>>>>> File >>>>>> "C:\Sandia_Meteors\New_Sentinel_Development\Sentuser_Utilities_Related\sentuser\sentuserNC25-Dev4.py", >>>>>> line 552, in OperationalSettings >>>>>> dialog = OperationalSettingsDialog( self.master, set_loc_dict ) >>>>>> File >>>>>> "C:\Sandia_Meteors\New_Sentinel_Development\Sentuser_Utilities_Related\sentuser\sentuserNC25-Dev4.py", >>>>>> line 81, in __init__ >>>>>> tkSimpleDialog.Dialog.__init__(self, parent) >>>>>> File "C:\Python25\lib\lib-tk\tkSimpleDialog.py", line 69, in __init__ >>>>>> self.wait_visibility() # window needs to be visible for the grab >>>>>> File "C:\Python25\lib\lib-tk\Tkinter.py", line 415, in wait_visibility >>>>>> self.tk.call('tkwait', 'visibility', window._w) >>>>>> TclError: window ".34672232" was deleted before its visibility changed >>>>>> =============== >>>>>> It runs fine in pythonWin performing the same entry operation. Open a >>>>>> menu, select an item to open a dialog, select a select button in the >>>>>> dialog, press OK to leave the dialog. Boom, as above. >>>>>> (This does not mean pythonWin doesn't have problems of its own. ) If I >>>>>> just execute the code (double click on the py file, the console shows no >>>>>> problems. IDLE is unhappy. >>>>>> Another side to this is that I use WinMerge to find differences between >>>>>> my last saved copy and the current copy. I found the current copy had >>>>>> two lines where a abc.get() was changed to abc.get. This was undoubtedly >>>>>> from briefly using the pyWin editor, when I mis-hit some keys. Yet pyWin >>>>>> had no trouble executing the program. My guess is that while briefly >>>>>> editing there, I hit some odd combination of keys that produced, >>>>>> perhaps, an invisible character that pyWin ignores. >>>>>> Not the 34672232 window is a dialog that I closed by pressing OK. I >>>>>> would again guess, that, if there is a problem, it occurs in the code >>>>>> that destroys the dialog. >>>>> Well you have to remember that you are trying to run a windowed GUI >>>>> under the control of another windows GUI, so it isn't surprising that >>>>> you hit trouble. >>>>> With IDLE the issue will be that IDLE already created a main window >>>>> before your program started running. With PythonWin you are using two >>>>> different toolkits, so it isn't really surprising that breaks down - >>>>> there will be two entirely separate main loops competing with each other. >>>> Not quite. I take down IDLE when I run pyWin, and vice versa. >>> The two separate loops being PyWin (which uses MFC) and your program >>> (which uses Tkinter). You just can't mix GUIs in the same process like >>> that, sorry. >>> regards >>> Stedve >> I have no idea what MFC is or how it relates to Tkinter. Neither IDLE and >> pyWin are being run together. >> >> Assume neither is running. >> a. run IDLE, and execute program >> b. close IDLE script, and interactive window. Kill py program >> result: boom >> c. run pyWin and execute program >> d. do same as b for pyWin >> resulst: all OK >> e. repeat a and b. >> Result: boom >> >> Repeat the above and you get the same results. >> >> I had running IDLE successfully w/o using Pywin, and IDLE goofed, as above. >> I switched to it to see if it work there. It did. I double clicked on the py >> file, and it worked fine. Can you explain this? >> >> -- >> W. eWatson >> >> (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) >> Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet >> >> Web Page: > > What Steve (and I) are saying is that IDLE has it's own mainloop and > your program has a mainloop too as it sounds like it is running a > Tkinter app. Sometimes when you run a Tk app from another Tk app, the > two mainloops clash and have weird issue like this one. > > If you just double-click it or run it from the command line, you only > have one mainloop (i.e. the one that's part of your app). Thus, no > conflicts. > > Mike So, how do I get rid of it? reboot? -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From martin at v.loewis.de Wed Feb 11 18:30:07 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 12 Feb 2009 00:30:07 +0100 Subject: Unicode issue on Windows cmd line In-Reply-To: <173b3dc8-4c7d-4049-979f-492ac8d6fb17@i20g2000prf.googlegroups.com> References: <5827412b-5637-4005-9410-972b7f1f18ca@h20g2000yqn.googlegroups.com> <49933bb6$0$3304$9b622d9e@news.freenet.de> <173b3dc8-4c7d-4049-979f-492ac8d6fb17@i20g2000prf.googlegroups.com> Message-ID: <49935F7F.5070508@v.loewis.de> > Thanks, I ended up using encode('iso-8859-15', "replace") > Perhaps more up to date than cp1252...?? > > It still didn't print correctly, but it did write correctly, which was > my main problem. If you encode as iso-8859-15, but this is not what your terminal expects, it certainly won't print correctly. To get correct printing, the output encoding must be the same as the terminal encoding. If the terminal encoding is not up to date (as you consider cp1252), then the output encoding should not be up to date, either. If you want a modern encoding that supports all of Unicode, and you don't care whether the output is legible, use UTF-8. Regards, Martin From clp2 at rebertia.com Wed Feb 11 18:30:53 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 11 Feb 2009 15:30:53 -0800 Subject: Can I 'LOOK' through urllib? In-Reply-To: <2c1dc513-977d-4796-8c5e-118619ef3ae2@v19g2000yqn.googlegroups.com> References: <2c1dc513-977d-4796-8c5e-118619ef3ae2@v19g2000yqn.googlegroups.com> Message-ID: <50697b2c0902111530x5d3c827fy5731d6a100aa0529@mail.gmail.com> On Wed, Feb 11, 2009 at 3:17 PM, Muddy Coder wrote: > Hi Folks, > > I feel good after played urllib with fun! > > Now I want to LOOK to server through urllib. I read the urllib docs, > but I did not find such a function. For example, if there are many > files located in http://www.somedomain.com/data_folder, but I don't > know what the filenames are residing in the data_folder. I wish urllib > would have a function to let me do it, as well as I do 'dir' in DOS, > 'ls' on unix/linux. Somebody write me a demo? Thanks! No such functionality exists in raw HTTP (i.e. there's no LIST verb like there is a GET verb), so it's not like Python is erroneously leaving something out. You either need cooperation from the server (i.e. it exposes some URL that gives you `ls`-like output) or the filenames and/or directory structure need to have some guessable pattern to them so that you can just run thru the possibilities manually. So, what you're asking for is impossible in the general case. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From http Wed Feb 11 18:35:07 2009 From: http (Paul Rubin) Date: 11 Feb 2009 15:35:07 -0800 Subject: Can I 'LOOK' through urllib? References: <2c1dc513-977d-4796-8c5e-118619ef3ae2@v19g2000yqn.googlegroups.com> Message-ID: <7xy6wca6ok.fsf@ruckus.brouhaha.com> Muddy Coder writes: > Now I want to LOOK to server through urllib. I read the urllib docs, > but I did not find such a function. For example, if there are many > files located in http://www.somedomain.com/data_folder, but I don't > know what the filenames are residing in the data_folder. I wish urllib > would have a function to let me do it, as well as I do 'dir' in DOS, > 'ls' on unix/linux. Somebody write me a demo? Thanks! That is done on the server side, and only if the server operator wants to let you look at the filenames (which is not always). See for example: http://httpd.apache.org/docs/2.2/mod/mod_autoindex.html From rhodri at wildebst.demon.co.uk Wed Feb 11 18:53:33 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 11 Feb 2009 23:53:33 -0000 Subject: re.sub and named groups In-Reply-To: References: <4c7158d2-5663-46b9-b950-be81bd79964c@z6g2000pre.googlegroups.com> Message-ID: On Wed, 11 Feb 2009 21:05:53 -0000, Paul McGuire wrote: > On Feb 4, 10:51?am, "Emanuele D'Arrigo" wrote: >> Hi everybody, >> >> I'm having a ball with the power of regular expression > > Don't forget the ball you can have with the power of ordinary Python > strings, string methods, and string interpolation! So the moral of this story is take a ball of strings with you for when you get lost in regular expressions. -- Rhodri James *-* Wildebeeste Herder to the Masses From lists at cheimes.de Wed Feb 11 18:57:00 2009 From: lists at cheimes.de (Christian Heimes) Date: Thu, 12 Feb 2009 00:57:00 +0100 Subject: Can I 'LOOK' through urllib? In-Reply-To: <2c1dc513-977d-4796-8c5e-118619ef3ae2@v19g2000yqn.googlegroups.com> References: <2c1dc513-977d-4796-8c5e-118619ef3ae2@v19g2000yqn.googlegroups.com> Message-ID: Muddy Coder schrieb: > Hi Folks, > > I feel good after played urllib with fun! > > Now I want to LOOK to server through urllib. I read the urllib docs, > but I did not find such a function. For example, if there are many > files located in http://www.somedomain.com/data_folder, but I don't > know what the filenames are residing in the data_folder. I wish urllib > would have a function to let me do it, as well as I do 'dir' in DOS, > 'ls' on unix/linux. Somebody write me a demo? Thanks! The WebDAV [1] extension to the HTTP protocol supports the desired feature. Are you able to teach your webserver WebDAV by any chance? All major HTTP server have plugins for WebDAV. Christian [1] http://en.wikipedia.org/wiki/Webdav From grante at visi.com Wed Feb 11 19:28:56 2009 From: grante at visi.com (Grant Edwards) Date: Wed, 11 Feb 2009 18:28:56 -0600 Subject: Can I 'LOOK' through urllib? References: <2c1dc513-977d-4796-8c5e-118619ef3ae2@v19g2000yqn.googlegroups.com> Message-ID: On 2009-02-11, Muddy Coder wrote: > Hi Folks, > > I feel good after played urllib with fun! > > Now I want to LOOK to server through urllib. I read the urllib docs, > but I did not find such a function. For example, if there are many > files located in http://www.somedomain.com/data_folder, but I don't > know what the filenames are residing in the data_folder. Try a GET on http://www.somedomain.com/. If the admin has indexing enabled, you should get something like "ls" output. If not, you're out of luck. > I wish urllib would have a function to let me do it, as well > as I do 'dir' in DOS, 'ls' on unix/linux. I wish I was 20 years younger and ten times as rich as I am. > Somebody write me a demo? Somebody send me a time machine and a pile of cash? On second thought, don't bother with the cash -- with a time machine, I can generate my own pile of cash. -- Grant From grante at visi.com Wed Feb 11 19:34:03 2009 From: grante at visi.com (Grant Edwards) Date: Wed, 11 Feb 2009 18:34:03 -0600 Subject: Can I 'LOOK' through urllib? References: <2c1dc513-977d-4796-8c5e-118619ef3ae2@v19g2000yqn.googlegroups.com> Message-ID: On 2009-02-12, Grant Edwards wrote: > On 2009-02-11, Muddy Coder wrote: >> Hi Folks, >> >> I feel good after played urllib with fun! >> >> Now I want to LOOK to server through urllib. I read the urllib docs, >> but I did not find such a function. For example, if there are many >> files located in http://www.somedomain.com/data_folder, but I don't >> know what the filenames are residing in the data_folder. > > Try a GET on http://www.somedomain.com/. If the admin has Oops. Should have been GET on http://www.somedomain.com/data_folder/ -- Grant From darwin at nowhere.com Wed Feb 11 19:44:14 2009 From: darwin at nowhere.com (Carbon Man) Date: Thu, 12 Feb 2009 11:44:14 +1100 Subject: Embed a web browser into a page Message-ID: Hi, I need to embed a web browser into a python page. I am coming from the MS world where I created an app that all of it's interfaces were actually web pages rendered in an Internet Explorer activex control. There was a object hook that allowed you to call into the host environment from javascript. Basically the host environment would receive the documentComplete event and call a method in the document's Javascript passing in an object reference. That reference would then be available for calls to be made from Javascript back into the host environment. I am just starting to explore the Pythonic programming jungle and I was wondering if there is a way to do something similar that would work cross-platform? I guess there is much more complexity in it when you start to go across o/s platform boundaries. The common web interface would then be Gecko or WebKit? So can someone suggest what would be required to build a cross-platform Python app that was capable of browsing HTML files, receiving events from the browser, and that allows the embedded page to call host Python modules from Javascript via an object reference? Or I am asking too much :) From markus.schreyer at gmail.com Wed Feb 11 19:49:48 2009 From: markus.schreyer at gmail.com (Markus Schreyer) Date: Thu, 12 Feb 2009 01:49:48 +0100 Subject: ANN: Python 2.6 Quick Reference available In-Reply-To: References: <4991d7b0$0$4785$426a34cc@news.free.fr> Message-ID: Great stuff! Waiting for the 3.0 version.. :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From steven at REMOVE.THIS.cybersource.com.au Wed Feb 11 19:53:22 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 12 Feb 2009 00:53:22 GMT Subject: urllib2.Request:: http Request sending successfully, but Response contains in valid data. References: <6119b5e5-a500-48f4-9e9d-51a0974c2c66@n33g2000pri.googlegroups.com> Message-ID: On Wed, 11 Feb 2009 01:56:19 -0800, nRk wrote: > Hi > > I am trying to send Data to a website through "http" using > "urllib.request" library using the bellow code. Response status code > contains. 200 (OK) but Response contains nothing... No it doesn't, you say so later: it contains a set of bare tags. That's not the same as nothing. > > With same data When I test using C# it working fine.. Response having.. > some data in xml format. > But I am using below python code i am getting response only " HTML>". > > Is there any in my code.. > > req = urllib2.Request(url) // url is valid url This is not your real code. >>> import urllib2 >>> req = urllib2.Request(url) // url is valid url File "", line 1 req = urllib2.Request(url) // url is valid url ^ SyntaxError: invalid syntax How do you expect us to find bugs in your code when you don't show us your real code? Are we supposed to be mind-readers? Try using the same user-agent string as your C# code uses, and see if the server changes what it sends. -- Steven From python at bdurham.com Wed Feb 11 19:54:18 2009 From: python at bdurham.com (python at bdurham.com) Date: Wed, 11 Feb 2009 19:54:18 -0500 Subject: ANN: Python 2.6 Quick Reference available In-Reply-To: References: <4991d7b0$0$4785$426a34cc@news.free.fr> Message-ID: <1234400058.4012.1299898597@webmail.messagingengine.com> Richard, An excellent tool. Great job!!! Thank you for sharing this with the Python community. Regards, Malcolm From dan at puddle.net.au Wed Feb 11 19:57:20 2009 From: dan at puddle.net.au (Dan McKenzie) Date: Thu, 12 Feb 2009 10:57:20 +1000 Subject: SQL error Message-ID: <41D70633-6A08-41E2-B385-A1ED7B781B4F@puddle.net.au> Hi Guys, I am trying to move data from a file into our mysql database. The format of the text file is - ipaddress ipaddress bytes packets interface-in interface-out eg: 192.168.1.1 192.168.1.2 1522 12 * rob The sql table is 'ipflows' This is the code: ____________________________________________________________ #!/usr/bin/python host = 'localhost' user = 'username' passwd = 'password' dbname = 'databasename' import MySQLdb conn = MySQLdb.connect(host = host, user = user, passwd = passwd, db = dbname) cursor = conn.cursor() file = open ('ipflow.txt',"r") for line in file: data = line.split() if not line: break query = '''INSERT INTO ipflows (to,from,bytes,packets) VALUES ("%s","%s","%s","%s","%s","%s"))''' % (data[0],data[1],data[2],data[3],data[4],data[5]) cursor.execute(query) file.close() cursor.close() conn.commit() conn.close() __________________________________________________________ It is returning and error: Traceback (most recent call last): File "./process_ipflow.py", line 23, in cursor.execute(query) File "/var/lib/python-support/python2.5/MySQLdb/cursors.py", line 166, in execute self.errorhandler(self, exc, value) File "/var/lib/python-support/python2.5/MySQLdb/connections.py", line 35, in defaulterrorhandler raise errorclass, errorvalue _mysql_exceptions.ProgrammingError: (1064, 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'to,from,bytes,packets) VALUES ("192.168.1.1","192.168.1.2","1522","12","*","\' at line 1') Seems I have the sql syntax wrong but I can't seem to find the answer :( Any help would be appreciated. Regards, Dan Regards, Dan McKenzie Puddlenet Community Broadband Networks Brisbane, Australia Q4074 +61 (0) 407 622 557 +61 (0) 7 3376 8539 From steven at REMOVE.THIS.cybersource.com.au Wed Feb 11 19:57:34 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 12 Feb 2009 00:57:34 GMT Subject: Unexpected string behaviour: txt = 'this' ' works' References: <71e3e031-de35-4f7b-91e9-1c14436d36f1@j38g2000yqa.googlegroups.com> Message-ID: On Wed, 11 Feb 2009 12:57:31 -0800, bearophileHUGS wrote: > Jason: >> It's such a minor optimization, that you probably wouldn't see any >> effect on your program. > >>>> from dis import dis >>>> def f(): > ... return 'This is ' + 'an example.' ... >>>> dis(f) > 2 0 LOAD_CONST 3 ('This is an example.') > 3 RETURN_VALUE That's a feature of the CPython keyhole optimizer, not a language feature. I expect that if you try that same thing in various other Pythons (and earlier versions of CPython) you'll get a different result. And like all optimizations, it's not a language feature, it's subject to removal without notice if necessary. If you want guaranteed implicit concatenation, you need to leave out the plus operator. That is a language feature. And I do call it a feature. I find it useful, and I've never run into any bugs caused by it, and if I did, I expect they would show up quickly: x = "foo", "bar" y = "foo" "bar" x is a tuple of length 2, y is a string of length 6. You'll soon notice the difference. Since it only effects literals, it should be easy enough to find. -- Steven From jeffgemail at gmail.com Wed Feb 11 20:11:37 2009 From: jeffgemail at gmail.com (jeffg) Date: Wed, 11 Feb 2009 17:11:37 -0800 (PST) Subject: Unicode issue on Windows cmd line References: <5827412b-5637-4005-9410-972b7f1f18ca@h20g2000yqn.googlegroups.com> <49933bb6$0$3304$9b622d9e@news.freenet.de> <173b3dc8-4c7d-4049-979f-492ac8d6fb17@i20g2000prf.googlegroups.com> <49935F7F.5070508@v.loewis.de> Message-ID: <0203136e-4208-45a4-8071-e5249558943e@w35g2000yqm.googlegroups.com> On Feb 11, 6:30?pm, "Martin v. L?wis" wrote: > > Thanks, I ended up using encode('iso-8859-15', "replace") > > Perhaps more up to date than cp1252...?? > > > It still didn't print correctly, but it did write correctly, which was > > my main problem. > > If you encode as iso-8859-15, but this is not what your terminal > expects, it certainly won't print correctly. To get correct printing, > the output encoding must be the same as the terminal encoding. If the > terminal encoding is not up to date (as you consider cp1252), then > the output encoding should not be up to date, either. > > If you want a modern encoding that supports all of Unicode, and you > don't care whether the output is legible, use UTF-8. > > Regards, > Martin I did try UTF-8 but it produced the upper case character instead of the proper lower case, so the output was incorrect for the unicode supplied. I think both 8859-15 and cp1252 produced the correct output, but I figured 8859-15 would have additional character support (though not sure this is the case - if it is not, please let me know and I'll use 1252). I'm dealing with large data sets and this just happend to be one small example. I want to have the best ability to write future unicode characters properly based on running from the windows command line (unless there is a better way to do it on windows). From sjmachin at lexicon.net Wed Feb 11 20:16:33 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 11 Feb 2009 17:16:33 -0800 (PST) Subject: SQL error References: Message-ID: <4a601628-a598-4766-a3e2-68d7bb5a3003@a39g2000prl.googlegroups.com> On Feb 12, 11:57?am, Dan McKenzie wrote: > Hi Guys, > > I am trying to move data from a file into our mysql database. > > The format of the text file is - ipaddress ipaddress bytes packets ? > interface-in interface-out eg: 192.168.1.1 192.168.1.2 1522 12 * rob > > The sql table is 'ipflows' > > This is the code: > ____________________________________________________________ > > #!/usr/bin/python > > host ? ?= 'localhost' > user ? ?= 'username' > passwd ?= 'password' > dbname ?= 'databasename' > > import MySQLdb > > conn = MySQLdb.connect(host = ? host, > ? ? ? ? ? ? ? ? ? ? ? ?user = ? user, > ? ? ? ? ? ? ? ? ? ? ? ?passwd = passwd, > ? ? ? ? ? ? ? ? ? ? ? ?db = ? ? dbname) > > cursor = conn.cursor() > > file = open ('ipflow.txt',"r") > > for line in file: > ? data = line.split() > ? if not line: break The above line of code is redundant; it can't happen; "line" will never be "false". > ? query = '''INSERT INTO ipflows (to,from,bytes,packets) VALUES ? > ("%s","%s","%s","%s","%s","%s"))''' % ? You have 6 values but only 4 column names ... looks a bit suss to me. > (data[0],data[1],data[2],data[3],data[4],data[5]) Ummm .. why not just data instead of (data[0],data[1],data[2],data[3],data[4],data[5]) ? > ? cursor.execute(query) > file.close() > > cursor.close() > conn.commit() > conn.close() > __________________________________________________________ > > It is returning and error: > > Traceback (most recent call last): > ? File "./process_ipflow.py", line 23, in > ? ? cursor.execute(query) > ? File "/var/lib/python-support/python2.5/MySQLdb/cursors.py", line ? > 166, in execute > ? ? self.errorhandler(self, exc, value) > ? File "/var/lib/python-support/python2.5/MySQLdb/connections.py", ? > line 35, in defaulterrorhandler > ? ? raise errorclass, errorvalue > _mysql_exceptions.ProgrammingError: (1064, 'You have an error in your ? > SQL syntax; check the manual that corresponds to your MySQL server ? > version for the right syntax to use near \'to,from,bytes,packets) TO and FROM are reserved words in just about everybody's version of SQL. And they're not very meaningful either especially when compared with interface_in and interface_out. BUT I'm surprised [not being familiar with MySQL] that you were allowed to do a CREATE TABLE with those column names. ? > VALUES ("192.168.1.1","192.168.1.2","1522","12","*","\' at line 1') > > Dan McKenzie > Puddlenet whose mascot no doubt is a duck named Jemima :-) > Community Broadband Networks > Brisbane, Australia Q4074 Greetings from Melbourne. Cheers, John From basilisk96 at gmail.com Wed Feb 11 20:22:26 2009 From: basilisk96 at gmail.com (Basilisk96) Date: Wed, 11 Feb 2009 17:22:26 -0800 (PST) Subject: how can this iterator be optimized? Message-ID: <727aabd1-9682-47aa-88e2-5dde96e4c32e@j1g2000yqi.googlegroups.com> Hello all, I have the following function that uses an intermediate iterator "rawPairs": def MakePairs(path): import os import operator join = os.path.join rawPairs = ( (join(path, s), func(s)) for s in os.listdir(path) if func(s) is not None and func(s).endswith("some criterion") ) #Use the second item in the pair as the sort criterion result = sorted(rawPairs, key=operator.itemgetter(1)) return result where "func" is a single-argument function that returns either a string or None, but is an expensive call. I am pretty sure that the sorted() construct cannot be improved much further, but... ...does anyone have ideas on improving the "rawPairs" iterator so that it calls "func(s)" only once per iteration? Perhaps a lambda construct, but I am not sure how to go about it...? Cheers, Basilisk96 From mark.seagoe at gmail.com Wed Feb 11 20:33:23 2009 From: mark.seagoe at gmail.com (mark.seagoe at gmail.com) Date: Wed, 11 Feb 2009 17:33:23 -0800 (PST) Subject: Iterable Ctypes Struct References: <99d4c7ae-27ae-4f3a-8475-a58f1c4e6925@t26g2000prh.googlegroups.com> <002f91bd-a30a-4fbf-a757-d496cd381dbf@p23g2000prp.googlegroups.com> <9d48e184-5bae-4c3a-b500-d49c38913b39@r41g2000prr.googlegroups.com> Message-ID: <5928b28c-9ce5-4b28-a8dd-ddd749391726@y38g2000prg.googlegroups.com> Hi Gabriel; Not sure what generic attribute container is. I am reading in from xml file all reg names for a chip. So then I'd be able to use python scripts to access the regs. So eventually this class will get subclassed w/ hw access instead of just saving in int. So I want to call this module something like "CHIP" which contains a struct. I add the "REG" struct objects as I read them in from xml file. The "REG" struct would have info about address, # of bits, type (RO, RW, etc). Thx, Mark From gagsl-py2 at yahoo.com.ar Wed Feb 11 20:38:56 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 11 Feb 2009 23:38:56 -0200 Subject: how can this iterator be optimized? References: <727aabd1-9682-47aa-88e2-5dde96e4c32e@j1g2000yqi.googlegroups.com> Message-ID: En Wed, 11 Feb 2009 23:22:26 -0200, Basilisk96 escribi?: > def MakePairs(path): > import os > import operator > join = os.path.join > rawPairs = ( > (join(path, s), func(s)) > for s in os.listdir(path) > if func(s) is not None and func(s).endswith("some criterion") > ) > #Use the second item in the pair as the sort criterion > result = sorted(rawPairs, key=operator.itemgetter(1)) > return result > > where "func" is a single-argument function that returns either a > string or None, but is an expensive call. > I am pretty sure that the sorted() construct cannot be improved much > further, but... > ...does anyone have ideas on improving the "rawPairs" iterator so that > it calls "func(s)" only once per iteration? Perhaps a lambda > construct, but I am not sure how to go about it...? Don't use a generator then. If you're going to finally return a list (and sorted does exactly that), build a list right from the start: def MakePairs(path): join = os.path.join result = [] append = result.append for s in os.listdir(path): key = func(s) if key is not None and key.endswith("some criterion"): append((join(path, s), key)) #Use the second item in the pair as the sort criterion result.sort(key=operator.itemgetter(1)) return result -- Gabriel Genellina From shandy.b at gmail.com Wed Feb 11 20:47:00 2009 From: shandy.b at gmail.com (sjbrown) Date: Wed, 11 Feb 2009 17:47:00 -0800 (PST) Subject: CPython loading modules into memory References: <49934A78.10309@v.loewis.de> Message-ID: On Feb 11, 2:00?pm, "Martin v. L?wis" wrote: > > Can someone describe the details of how Python loads modules into > > memory? ?I assume once the .py file is compiled to .pyc that it is > > mmap'ed in. ?But that assumption is very naive. ?Maybe it uses an > > anonymous mapping? ?Maybe it does other special magic? ?This is all > > very alien to me, so if someone could explain it in terms that a > > person who never usually worries about memory could understand, that > > would be much appreciated. > > There is no magic whatsoever. Python opens a sequential file descriptor > for the .pyc file, and then reads it in small chunks, "unmarshalling" > it (indeed, the marshal module is used to restore Python objects). > > The marshal format is an object serialization in a type-value encoding > (sometimes type-length-value), with type codes for: > - None, True, False > - 32-bit ints, 64-bit ints (unmarshalled into int/long) > - floats, complex > - arbitrary-sized longs > - strings, unicode > - tuples (length + marshal data of values) > - lists > - dicts > - code objects > - a few others > > Result of unmarshalling is typically a code object. > > > Follow up: is this process different if the modules are loaded from a > > zipfile? > > No; it uncompresses into memory, and then unmarshals from there ( > compressed block for compressed block) > > > If there is a link that covers this info, that'd be great too. > > See the description of the marshal module. > > HTH, > Martin Thanks for the answers. For my own edification, and in case anyone is interested, I confirmed this by looking at import.c and marshal.c in the Python2.5.4 source. Looks like the actual reading of the file is done in the marshal.c function PyMarshal_ReadLastObjectFromFile. It is read sequentially using a small buffer on the heap. -sjbrown From jeffgemail at gmail.com Wed Feb 11 20:48:55 2009 From: jeffgemail at gmail.com (jeffg) Date: Wed, 11 Feb 2009 17:48:55 -0800 (PST) Subject: Another optimization request :-) Message-ID: If anyone wants to take this on... I would really really like to have the spring_layout modified to support multi-threading if at all possible. My test data is 20,000, which makes this process 20,000 x 20,000 or 400,000,000 (400 million) calculations. This is taking somewhere between 2-3 hours an iteration. I plan to plot out over 1,000,000 data points or more, which would put this at 1,000,000,000,000 (1 trillion) calculations. Any help in making this more efficient would be much appreciated. def spring_layout(G, iterations=50, dim=2, node_pos=None, verbose=False): """Spring force model layout""" if node_pos==None : # set the initial positions randomly in 1x1 box vpos=random_layout(G, dim=dim) else: vpos=node_pos if iterations==0: return vpos if G.order()==0: k=1.0 else: k=N.sqrt(1.0/G.order()) # optimal distance between nodes disp={} # displacements # initial "temperature" (about .1 of domain area) # this is the largest step allowed in the dynamics # linearly step down by dt on each iteration so # on last iteration it is size dt. t=0.1 dt=0.1/float(iterations+1) for i in range(0,iterations): for v in G: if verbose==True: print("Interation: " + str(i + 1) + ", Calculating: " + str(v.encode('iso-8859-15', "replace"))) disp[v]=N.zeros(dim) for u in G: delta=vpos[v]-vpos[u] dn=max(sqrt(N.dot(delta,delta)),0.01) # repulsive force between all deltaf=delta*k**2/dn**2 disp[v]=disp[v]+deltaf # attractive force between neighbors if G.has_edge(v,u): deltaf=-delta*dn**2/(k*dn) disp[v]=disp[v]+deltaf # update positions for v in G: l=max(sqrt(N.dot(disp[v],disp[v])),0.01) vpos[v]=vpos[v]+ disp[v]*t/l t-=dt return vpos From bj_666 at gmx.net Wed Feb 11 20:51:47 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 12 Feb 2009 01:51:47 GMT Subject: Iterable Ctypes Struct References: <99d4c7ae-27ae-4f3a-8475-a58f1c4e6925@t26g2000prh.googlegroups.com> <002f91bd-a30a-4fbf-a757-d496cd381dbf@p23g2000prp.googlegroups.com> <9d48e184-5bae-4c3a-b500-d49c38913b39@r41g2000prr.googlegroups.com> <5928b28c-9ce5-4b28-a8dd-ddd749391726@y38g2000prg.googlegroups.com> Message-ID: <6vhdljFju0haU1@mid.uni-berlin.de> On Wed, 11 Feb 2009 17:33:23 -0800, mark.seagoe wrote: > Not sure what generic attribute container is. I am reading in from xml > file all reg names for a chip. Are you using instances of that class to interface C code or to read/ write data intended to be read or written by a C program? If not then `ctypes` might be the wrong tool. Ciao, Marc 'BlackJack' Rintsch From drobinow at gmail.com Wed Feb 11 20:59:20 2009 From: drobinow at gmail.com (drobinow at gmail.com) Date: Wed, 11 Feb 2009 17:59:20 -0800 (PST) Subject: Who's on First, IDLE or pythonWin? Dialog Problem? References: Message-ID: <1a05ac6c-9c7e-4411-a702-99bae941f948@h20g2000yqn.googlegroups.com> On Feb 11, 2:51?pm, Steve Holden wrote: > W. eWatson wrote: > > Steve Holden wrote: > >> W. eWatson wrote: > >>> My program in IDLE bombed with: > >>> ============== > >>> Exception in Tkinter callback > >>> Traceback (most recent call last): > >>> ? File "C:\Python25\lib\lib-tk\Tkinter.py", line 1403, in __call__ > >>> ? ? return self.func(*args) > >>> ? File > >>> "C:\Sandia_Meteors\New_Sentinel_Development\Sentuser_Utilities_Related\sentuser\sentuserNC25-Dev4.py", > > >>> line 552, in OperationalSettings > >>> ? ? dialog = OperationalSettingsDialog( self.master, set_loc_dict ) > >>> ? File > >>> "C:\Sandia_Meteors\New_Sentinel_Development\Sentuser_Utilities_Related\sentuser\sentuserNC25-Dev4.py", > > >>> line 81, in __init__ > >>> ? ? tkSimpleDialog.Dialog.__init__(self, parent) > >>> ? File "C:\Python25\lib\lib-tk\tkSimpleDialog.py", line 69, in __init__ > >>> ? ? self.wait_visibility() # window needs to be visible for the grab > >>> ? File "C:\Python25\lib\lib-tk\Tkinter.py", line 415, in wait_visibility > >>> ? ? self.tk.call('tkwait', 'visibility', window._w) > >>> TclError: window ".34672232" was deleted before its visibility changed > >>> =============== > >>> It runs fine in pythonWin performing the same entry operation. Open a > >>> menu, ?select an item to open a dialog, select a select button in the > >>> dialog, press OK to leave the dialog. Boom, as above. > > >>> (This does not mean pythonWin doesn't have problems of its own. ) If I > >>> just execute the code (double click on the py file, the console shows no > >>> problems. IDLE is unhappy. > > >>> Another side to this is that I use WinMerge to find differences between > >>> my last saved copy and the current copy. I found the current copy had > >>> two lines where a abc.get() was changed to abc.get. This was undoubtedly > >>> from briefly using the pyWin editor, when I mis-hit some keys. Yet pyWin > >>> had no trouble executing the program. My guess is that while briefly > >>> editing there, I hit some odd combination of keys that produced, > >>> perhaps, an invisible character that pyWin ignores. > > >>> Not the 34672232 window is a dialog that I closed by pressing OK. I > >>> would again guess, that, if there is a problem, it occurs in the code > >>> that destroys the dialog. > > >> Well you have to remember that you are trying to run a windowed GUI > >> under the control of another windows GUI, so it isn't surprising that > >> you hit trouble. > > >> With IDLE the issue will be that IDLE already created a main window > >> before your program started running. With PythonWin you are using two > >> different toolkits, so it isn't really surprising that breaks down - > >> there will be two entirely separate main loops competing with each other. > > > Not quite. I take down IDLE when I run pyWin, and vice versa. > > The two separate loops being PyWin (which uses MFC) and your program > (which uses Tkinter). You just can't mix GUIs in the same process like > that, sorry. > > regards > ?Stedve > -- > Steve Holden ? ? ? ?+1 571 484 6266 ? +1 800 494 3119 > Holden Web LLC ? ? ? ? ? ? ?http://www.holdenweb.com/ Deja-vu! http://mail.python.org/pipermail/python-list/2001-March/076069.html From mark.seagoe at gmail.com Wed Feb 11 21:02:12 2009 From: mark.seagoe at gmail.com (mark.seagoe at gmail.com) Date: Wed, 11 Feb 2009 18:02:12 -0800 (PST) Subject: Iterable Ctypes Struct References: <99d4c7ae-27ae-4f3a-8475-a58f1c4e6925@t26g2000prh.googlegroups.com> <002f91bd-a30a-4fbf-a757-d496cd381dbf@p23g2000prp.googlegroups.com> <9d48e184-5bae-4c3a-b500-d49c38913b39@r41g2000prr.googlegroups.com> <5928b28c-9ce5-4b28-a8dd-ddd749391726@y38g2000prg.googlegroups.com> <6vhdljFju0haU1@mid.uni-berlin.de> Message-ID: On Feb 11, 5:51?pm, Marc 'BlackJack' Rintsch wrote: > On Wed, 11 Feb 2009 17:33:23 -0800, mark.seagoe wrote: > > Not sure what generic attribute container is. ?I am reading in from xml > > file all reg names for a chip. > > Are you using instances of that class to interface C code or to read/ > write data intended to be read or written by a C program? ?If not then > `ctypes` might be the wrong tool. > > Ciao, > ? ? ? ? Marc 'BlackJack' Rintsch It's accessing through USB so I'm also interfacing to Win32 drivers. But at this higher level, since I'm somewhat new to Python so I'm not aware of other classes which exist to allow accessing in the format desired (without quotes and using dot notation): classname.elementname1, instead of something like classname ["elementname1"]. It's just cosmetic, but I'd prefer the dot notation without quotes for the end user experience of script writing later. Is there something besides ctypes.Structure that would do that? Thx, Mark From andrew at acooke.org Wed Feb 11 21:44:10 2009 From: andrew at acooke.org (andrew cooke) Date: Wed, 11 Feb 2009 23:44:10 -0300 (CLST) Subject: Another optimization request :-) In-Reply-To: References: Message-ID: <3f05ec0f12c2042f52618fb0db5bbac4.squirrel@acooke.dyndns.org> why are you dong this point by point? surely you can express the physics as a set of equations and invert the matrix? wouldn't that be a lot faster? you'd replace the iteration over all combinations of points with a faster matrix inversion. see for example http://www.medwelljournals.com/fulltext/ajit/2006/324-338.pdf page 331 onwards. there's a very nice into to the verlet integration mentioned here - http://teknikus.dk/tj/gdc2001.htm andrew jeffg wrote: > If anyone wants to take this on... I would really really like to have > the spring_layout modified to support multi-threading if at all > possible. > My test data is 20,000, which makes this process 20,000 x 20,000 or > 400,000,000 (400 million) calculations. This is taking somewhere > between 2-3 hours an iteration. > I plan to plot out over 1,000,000 data points or more, which would put > this at 1,000,000,000,000 (1 trillion) calculations. Any help in > making this more efficient would be much appreciated. > > def spring_layout(G, iterations=50, dim=2, node_pos=None, > verbose=False): > """Spring force model layout""" > if node_pos==None : # set the initial positions randomly in 1x1 > box > vpos=random_layout(G, dim=dim) > else: > vpos=node_pos > if iterations==0: > return vpos > if G.order()==0: > k=1.0 > else: > k=N.sqrt(1.0/G.order()) # optimal distance between nodes > disp={} # displacements > > # initial "temperature" (about .1 of domain area) > # this is the largest step allowed in the dynamics > # linearly step down by dt on each iteration so > # on last iteration it is size dt. > t=0.1 > dt=0.1/float(iterations+1) > for i in range(0,iterations): > for v in G: > if verbose==True: > print("Interation: " + str(i + 1) + ", Calculating: " > + str(v.encode('iso-8859-15', "replace"))) > disp[v]=N.zeros(dim) > for u in G: > delta=vpos[v]-vpos[u] > dn=max(sqrt(N.dot(delta,delta)),0.01) > # repulsive force between all > deltaf=delta*k**2/dn**2 > disp[v]=disp[v]+deltaf > # attractive force between neighbors > if G.has_edge(v,u): > deltaf=-delta*dn**2/(k*dn) > disp[v]=disp[v]+deltaf > > # update positions > for v in G: > l=max(sqrt(N.dot(disp[v],disp[v])),0.01) > vpos[v]=vpos[v]+ disp[v]*t/l > t-=dt > return vpos > -- > http://mail.python.org/mailman/listinfo/python-list > > From david.birdsong at gmail.com Wed Feb 11 21:44:53 2009 From: david.birdsong at gmail.com (birdsong) Date: Wed, 11 Feb 2009 18:44:53 -0800 (PST) Subject: select.poll.poll() never blocks Message-ID: I'm pretty sure I've exhausted all searches and read all the forums Google will turn up related to this issue. I touch an empty file in a sh shell, fire up the python shell, open the file for reading(tried all buffering options), register it with a poll object for select.POLLIN and call poll(), but the poll never blocks and always returns for the FD, EVENT combination I ask for, but the file has not anything written to it. Here's an example snippet: >>> fd = os.open('/tmp/poll_test', os.O_RDONLY | os.O_SYNC) >>> p = select.poll() >>> p.register(fd, select.POLLIN) >>> s = p.poll() >>> os.read(fd, 10) '' >>> s [(3, 1)] >>> fd 3 I was using the open builtin originally, but a forum I read suggested that this created user level buffers that the system call wouldn't know about(which didn't completely jive with me), so I switched to the lower level os.open. Am I not getting the proper spirit of select.poll? I know that read() never blocks and I think I read somewhere that poll will return fd that will not block for the EVENT registered -so in that regard it's fitting. Any help on what I'm missing would be appreciated. From exarkun at divmod.com Wed Feb 11 21:49:09 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Wed, 11 Feb 2009 21:49:09 -0500 Subject: select.poll.poll() never blocks In-Reply-To: Message-ID: <20090212024909.12853.309763852.divmod.quotient.9093@henry.divmod.com> On Wed, 11 Feb 2009 18:44:53 -0800 (PST), birdsong wrote: >I'm pretty sure I've exhausted all searches and read all the forums >Google will turn up related to this issue. > >I touch an empty file in a sh shell, fire up the python shell, open >the file for reading(tried all buffering options), register it with a >poll object for select.POLLIN and call poll(), but the poll never >blocks and always returns for the FD, EVENT combination I ask for, but >the file has not anything written to it. Filesystem files are always reported as readable and writeable by select, poll, epoll, etc. If you want to do non-blocking filesystem I/O, your choices are to use a native thread (Python's threading module, or another third-party module which wraps the platform thread API) or to use POSIX AIO (or the mildly incompatible Linux variant. Of course, AIO has tons of caveats and is generally in a miserable state, so you probably shouldn't use it. That leaves you with threads. Jean-Paul From andrew at acooke.org Wed Feb 11 21:56:52 2009 From: andrew at acooke.org (andrew cooke) Date: Wed, 11 Feb 2009 23:56:52 -0300 (CLST) Subject: Another optimization request :-) In-Reply-To: <3f05ec0f12c2042f52618fb0db5bbac4.squirrel@acooke.dyndns.org> References: <3f05ec0f12c2042f52618fb0db5bbac4.squirrel@acooke.dyndns.org> Message-ID: <0fbde7b4d61078a9c7cda67e0b3bfbbb.squirrel@acooke.dyndns.org> sorry, that was stupid. there is no inversion (apart from 1/m), just the integration. still, improving the integration would allow larger steps. andrew andrew cooke wrote: > > why are you dong this point by point? surely you can express the physics > as a set of equations and invert the matrix? wouldn't that be a lot > faster? you'd replace the iteration over all combinations of points with > a faster matrix inversion. > > see for example > http://www.medwelljournals.com/fulltext/ajit/2006/324-338.pdf page 331 > onwards. > > there's a very nice into to the verlet integration mentioned here - > http://teknikus.dk/tj/gdc2001.htm > > andrew > > > jeffg wrote: >> If anyone wants to take this on... I would really really like to have >> the spring_layout modified to support multi-threading if at all >> possible. >> My test data is 20,000, which makes this process 20,000 x 20,000 or >> 400,000,000 (400 million) calculations. This is taking somewhere >> between 2-3 hours an iteration. >> I plan to plot out over 1,000,000 data points or more, which would put >> this at 1,000,000,000,000 (1 trillion) calculations. Any help in >> making this more efficient would be much appreciated. >> >> def spring_layout(G, iterations=50, dim=2, node_pos=None, >> verbose=False): >> """Spring force model layout""" >> if node_pos==None : # set the initial positions randomly in 1x1 >> box >> vpos=random_layout(G, dim=dim) >> else: >> vpos=node_pos >> if iterations==0: >> return vpos >> if G.order()==0: >> k=1.0 >> else: >> k=N.sqrt(1.0/G.order()) # optimal distance between nodes >> disp={} # displacements >> >> # initial "temperature" (about .1 of domain area) >> # this is the largest step allowed in the dynamics >> # linearly step down by dt on each iteration so >> # on last iteration it is size dt. >> t=0.1 >> dt=0.1/float(iterations+1) >> for i in range(0,iterations): >> for v in G: >> if verbose==True: >> print("Interation: " + str(i + 1) + ", Calculating: " >> + str(v.encode('iso-8859-15', "replace"))) >> disp[v]=N.zeros(dim) >> for u in G: >> delta=vpos[v]-vpos[u] >> dn=max(sqrt(N.dot(delta,delta)),0.01) >> # repulsive force between all >> deltaf=delta*k**2/dn**2 >> disp[v]=disp[v]+deltaf >> # attractive force between neighbors >> if G.has_edge(v,u): >> deltaf=-delta*dn**2/(k*dn) >> disp[v]=disp[v]+deltaf >> >> # update positions >> for v in G: >> l=max(sqrt(N.dot(disp[v],disp[v])),0.01) >> vpos[v]=vpos[v]+ disp[v]*t/l >> t-=dt >> return vpos >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > > > -- > http://mail.python.org/mailman/listinfo/python-list > > From gagsl-py2 at yahoo.com.ar Wed Feb 11 22:00:45 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 12 Feb 2009 01:00:45 -0200 Subject: Unicode issue on Windows cmd line References: <5827412b-5637-4005-9410-972b7f1f18ca@h20g2000yqn.googlegroups.com> <49933bb6$0$3304$9b622d9e@news.freenet.de> <173b3dc8-4c7d-4049-979f-492ac8d6fb17@i20g2000prf.googlegroups.com> <49935F7F.5070508@v.loewis.de> <0203136e-4208-45a4-8071-e5249558943e@w35g2000yqm.googlegroups.com> Message-ID: En Wed, 11 Feb 2009 23:11:37 -0200, jeffg escribi?: > On Feb 11, 6:30?pm, "Martin v. L?wis" wrote: >> > Thanks, I ended up using encode('iso-8859-15', "replace") >> > Perhaps more up to date than cp1252...?? >> If you encode as iso-8859-15, but this is not what your terminal >> expects, it certainly won't print correctly. To get correct printing, >> the output encoding must be the same as the terminal encoding. If the >> terminal encoding is not up to date (as you consider cp1252), then >> the output encoding should not be up to date, either. > I did try UTF-8 but it produced the upper case character instead of > the proper lower case, so the output was incorrect for the unicode > supplied. > I think both 8859-15 and cp1252 produced the correct output, but I > figured 8859-15 would have additional character support (though not > sure this is the case - if it is not, please let me know and I'll use > 1252). I'm dealing with large data sets and this just happend to be > one small example. I want to have the best ability to write future > unicode characters properly based on running from the windows command > line (unless there is a better way to do it on windows). As Martin v. L?wis already said, the encoding used by Python when writing to the console, must match the encoding the console expects. (And you also should use a font capable of displaying such characters). windows-1252 and iso-8859-15 are similar, but not identical. This table shows the differences (less than 30 printable characters): http://en.wikipedia.org/wiki/Western_Latin_character_sets_(computing) If your script encodes its output using iso-8859-15, the corresponding console code page should be 28605. "Western European" (whatever that means exactly) Windows versions use the windows-1252 encoding as the "Ansi code page" (GUI applications), and cp850 as the "OEM code page" (console applications) -- cp437 in the US only. C:\Documents and Settings\Gabriel>chcp 1252 Tabla de c?digos activa: 1252 C:\Documents and Settings\Gabriel>python Python 2.6 (r26:66721, Oct 2 2008, 11:35:03) [MSC v.1500 32 bit (Intel)] on win 32 Type "help", "copyright", "credits" or "license" for more information. py> unichr(0x0153).encode("windows-1252") '\x9c' py> print _ ? py> ^Z C:\Documents and Settings\Gabriel>chcp 28605 Tabla de c?digos activa: 28605 C:\Documents and Settings\Gabriel>python Python 2.6 (r26:66721, Oct 2 2008, 11:35:03) [MSC v.1500 32 bit (Intel)] on win 32 Type "help", "copyright", "credits" or "license" for more information. py> unichr(0x0153).encode("iso-8859-15") '\xbd' py> print _ ? py> unichr(0x0153).encode("latin9") '\xbd' -- Gabriel Genellina From david.birdsong at gmail.com Wed Feb 11 22:01:16 2009 From: david.birdsong at gmail.com (birdsong) Date: Wed, 11 Feb 2009 19:01:16 -0800 (PST) Subject: select.poll.poll() never blocks References: Message-ID: So I guess I didn't have a complete understanding of poll, I thought it returned file descriptors that had registered an event that the user asked to watch for. In my case, select.POLLIN Constant Meaning POLLIN There is data to read ...there ins't any data to be read. The file is readable, yes, but is that all that the syscall has to offer? On Feb 11, 6:49?pm, Jean-Paul Calderone wrote: > On Wed, 11 Feb 2009 18:44:53 -0800 (PST), birdsong wrote: > >I'm pretty sure I've exhausted all searches and read all the forums > >Google will turn up related to this issue. > > >I touch an empty file in a sh shell, fire up the python shell, open > >the file for reading(tried all buffering options), register it with a > >poll object for select.POLLIN and call poll(), but the poll never > >blocks and always returns for the FD, EVENT combination I ask for, but > >the file has not anything written to it. > > Filesystem files are always reported as readable and writeable by select, > poll, epoll, etc. > > If you want to do non-blocking filesystem I/O, your choices are to use a > native thread (Python's threading module, or another third-party module > which wraps the platform thread API) or to use POSIX AIO (or the mildly > incompatible Linux variant. ?Of course, AIO has tons of caveats and is > generally in a miserable state, so you probably shouldn't use it. ?That > leaves you with threads. > > Jean-Paul From scott.bronson.nelson at gmail.com Wed Feb 11 22:02:22 2009 From: scott.bronson.nelson at gmail.com (scott.bronson.nelson at gmail.com) Date: Wed, 11 Feb 2009 19:02:22 -0800 (PST) Subject: __import__ Confusion Message-ID: <5e61a9a8-7caa-4dfc-9454-aa8eddb8e593@z1g2000yqn.googlegroups.com> Can someone explain to me what's going on here? >>> __import__('some.package.module', {}, {}, []) >>> __import__('some.package.module', {}, {}, ['']) (Note that '' is two single quotes) Thanks, Scott From gagsl-py2 at yahoo.com.ar Wed Feb 11 22:17:37 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 12 Feb 2009 01:17:37 -0200 Subject: Iterable Ctypes Struct References: <99d4c7ae-27ae-4f3a-8475-a58f1c4e6925@t26g2000prh.googlegroups.com> <002f91bd-a30a-4fbf-a757-d496cd381dbf@p23g2000prp.googlegroups.com> <9d48e184-5bae-4c3a-b500-d49c38913b39@r41g2000prr.googlegroups.com> <5928b28c-9ce5-4b28-a8dd-ddd749391726@y38g2000prg.googlegroups.com> <6vhdljFju0haU1@mid.uni-berlin.de> Message-ID: En Thu, 12 Feb 2009 00:02:12 -0200, escribi?: > On Feb 11, 5:51?pm, Marc 'BlackJack' Rintsch wrote: >> On Wed, 11 Feb 2009 17:33:23 -0800, mark.seagoe wrote: >> > Not sure what generic attribute container is. ?I am reading in from > >> xml file all reg names for a chip. >> >> Are you using instances of that class to interface C code or to read/ >> write data intended to be read or written by a C program? ?If not then >> `ctypes` might be the wrong tool. > > It's accessing through USB so I'm also interfacing to Win32 drivers. > But at this higher level, since I'm somewhat new to Python so I'm not > aware of other classes which exist to allow accessing in the format > desired (without quotes and using dot notation): > classname.elementname1, instead of something like classname > ["elementname1"]. It's just cosmetic, but I'd prefer the dot notation > without quotes for the end user experience of script writing later. > Is there something besides ctypes.Structure that would do that? You don't need *anything* special to add attributes to an object in Python. Even an empty class is enough: py> class Struct(object): ... pass # an empty class ... py> s = Struct() py> s.x = 10 py> s.y = 20 py> print s.x, s.y 10 20 py> But since this thread started asking how to iterate over the attributes, let's use a named tuple: py> from collections import namedtuple py> StructWithNames = namedtuple("StructWithNames", "x,y,z") py> s = StructWithNames(10, 20, 30) py> s.z 30 py> s StructWithNames(x=10, y=20, z=30) py> list(s) [10, 20, 30] py> for item in s: print item ... 10 20 30 py> s._fields ('x', 'y', 'z') -- Gabriel Genellina From rhodri at wildebst.demon.co.uk Wed Feb 11 22:47:46 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 12 Feb 2009 03:47:46 -0000 Subject: select.poll.poll() never blocks In-Reply-To: References: Message-ID: On Thu, 12 Feb 2009 03:01:16 -0000, birdsong wrote: > So I guess I didn't have a complete understanding of poll, I thought > it returned file descriptors that had registered an event that the > user asked to watch for. In my case, select.POLLIN > Constant Meaning > POLLIN There is data to read > > ...there ins't any data to be read. The file is readable, yes, but is > that all that the syscall has to offer? To quote the web page referenced in help(select): "It cannot be used on regular files to determine whether a file has grown since it was last read." poll() and friends are wrappers over the socket library "poll" and "select" functions, which primarily exist to facilitate asynchronous socket communications. They can take ordinary file descriptors as well as sockets because there's no good reason not to, but a regular file will always be ready to read as long as you haven't read past the end of file. You're trying to use a regular file as if it was a pipe. My first obvious question is do you have to do it this way? Do you have any control over the program writing to file? Can you cause the output to go to stdout and pipe it into your script's stdin instead? That would make your life vastly easier. If you can't, I'm not sure what your best strategy is. I'd be tempted to use "tail -f filetocheck | yourscript.py" and palm the job off on an already-written tool. If you want to do it in Python, the only thing that springs to mind is periodically checking the size of the file and reading more when that changes. You'll need to be very careful to keep what size you think the file is in sync with how much you've read! -- Rhodri James *-* Wildebeeste Herder to the Masses From semanticist at gmail.com Wed Feb 11 22:51:33 2009 From: semanticist at gmail.com (Miles) Date: Wed, 11 Feb 2009 22:51:33 -0500 Subject: select.poll.poll() never blocks In-Reply-To: References: Message-ID: On Wed, Feb 11, 2009 at 10:47 PM, Rhodri James wrote: > If you want to > do it in Python, the only thing that springs to mind is > periodically checking the size of the file and reading more > when that changes. You'll need to be very careful to keep > what size you think the file is in sync with how much you've > read! See also this recipe: http://code.activestate.com/recipes/157035/ -Miles From notvalid2 at sbcglobal.net Wed Feb 11 22:57:55 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Wed, 11 Feb 2009 19:57:55 -0800 Subject: Who's on First, IDLE or pythonWin? Dialog Problem? In-Reply-To: <1a05ac6c-9c7e-4411-a702-99bae941f948@h20g2000yqn.googlegroups.com> References: <1a05ac6c-9c7e-4411-a702-99bae941f948@h20g2000yqn.googlegroups.com> Message-ID: <49939E43.6090205@sbcglobal.net> drobinow at gmail.com wrote: > On Feb 11, 2:51 pm, Steve Holden wrote: >> W. eWatson wrote: >>> Steve Holden wrote: >>>> W. eWatson wrote: >>>>> My program in IDLE bombed with: >>>>> ============== >>>>> Exception in Tkinter callback >>>>> Traceback (most recent call last): >>>>> File "C:\Python25\lib\lib-tk\Tkinter.py", line 1403, in __call__ >>>>> return self.func(*args) >>>>> File >>>>> "C:\Sandia_Meteors\New_Sentinel_Development\Sentuser_Utilities_Related\sentuser\sentuserNC25-Dev4.py", >>>>> line 552, in OperationalSettings >>>>> dialog = OperationalSettingsDialog( self.master, set_loc_dict ) >>>>> File >>>>> "C:\Sandia_Meteors\New_Sentinel_Development\Sentuser_Utilities_Related\sentuser\sentuserNC25-Dev4.py", >>>>> line 81, in __init__ >>>>> tkSimpleDialog.Dialog.__init__(self, parent) >>>>> File "C:\Python25\lib\lib-tk\tkSimpleDialog.py", line 69, in __init__ >>>>> self.wait_visibility() # window needs to be visible for the grab >>>>> File "C:\Python25\lib\lib-tk\Tkinter.py", line 415, in wait_visibility >>>>> self.tk.call('tkwait', 'visibility', window._w) >>>>> TclError: window ".34672232" was deleted before its visibility changed >>>>> =============== >>>>> It runs fine in pythonWin performing the same entry operation. Open a >>>>> menu, select an item to open a dialog, select a select button in the >>>>> dialog, press OK to leave the dialog. Boom, as above. >>>>> (This does not mean pythonWin doesn't have problems of its own. ) If I >>>>> just execute the code (double click on the py file, the console shows no >>>>> problems. IDLE is unhappy. >>>>> Another side to this is that I use WinMerge to find differences between >>>>> my last saved copy and the current copy. I found the current copy had >>>>> two lines where a abc.get() was changed to abc.get. This was undoubtedly >>>>> from briefly using the pyWin editor, when I mis-hit some keys. Yet pyWin >>>>> had no trouble executing the program. My guess is that while briefly >>>>> editing there, I hit some odd combination of keys that produced, >>>>> perhaps, an invisible character that pyWin ignores. >>>>> Not the 34672232 window is a dialog that I closed by pressing OK. I >>>>> would again guess, that, if there is a problem, it occurs in the code >>>>> that destroys the dialog. >>>> Well you have to remember that you are trying to run a windowed GUI >>>> under the control of another windows GUI, so it isn't surprising that >>>> you hit trouble. >>>> With IDLE the issue will be that IDLE already created a main window >>>> before your program started running. With PythonWin you are using two >>>> different toolkits, so it isn't really surprising that breaks down - >>>> there will be two entirely separate main loops competing with each other. >>> Not quite. I take down IDLE when I run pyWin, and vice versa. >> The two separate loops being PyWin (which uses MFC) and your program >> (which uses Tkinter). You just can't mix GUIs in the same process like >> that, sorry. >> >> regards >> Stedve >> -- >> Steve Holden +1 571 484 6266 +1 800 494 3119 >> Holden Web LLC http://www.holdenweb.com/ > > Deja-vu! > > http://mail.python.org/pipermail/python-list/2001-March/076069.html The question now is what can I do about it? reboot? Just to re-iterate the answer I provided the answer to above, I'm using Tkinter for the program's GUI. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From notvalid2 at sbcglobal.net Wed Feb 11 22:58:22 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Wed, 11 Feb 2009 19:58:22 -0800 Subject: Who's on First, IDLE or pythonWin? Dialog Problem? In-Reply-To: <1a05ac6c-9c7e-4411-a702-99bae941f948@h20g2000yqn.googlegroups.com> References: <1a05ac6c-9c7e-4411-a702-99bae941f948@h20g2000yqn.googlegroups.com> Message-ID: <49939E5E.2000309@sbcglobal.net> drobinow at gmail.com wrote: > On Feb 11, 2:51 pm, Steve Holden wrote: >> W. eWatson wrote: >>> Steve Holden wrote: >>>> W. eWatson wrote: >>>>> My program in IDLE bombed with: >>>>> ============== >>>>> Exception in Tkinter callback >>>>> Traceback (most recent call last): >>>>> File "C:\Python25\lib\lib-tk\Tkinter.py", line 1403, in __call__ >>>>> return self.func(*args) >>>>> File >>>>> "C:\Sandia_Meteors\New_Sentinel_Development\Sentuser_Utilities_Related\sentuser\sentuserNC25-Dev4.py", >>>>> line 552, in OperationalSettings >>>>> dialog = OperationalSettingsDialog( self.master, set_loc_dict ) >>>>> File >>>>> "C:\Sandia_Meteors\New_Sentinel_Development\Sentuser_Utilities_Related\sentuser\sentuserNC25-Dev4.py", >>>>> line 81, in __init__ >>>>> tkSimpleDialog.Dialog.__init__(self, parent) >>>>> File "C:\Python25\lib\lib-tk\tkSimpleDialog.py", line 69, in __init__ >>>>> self.wait_visibility() # window needs to be visible for the grab >>>>> File "C:\Python25\lib\lib-tk\Tkinter.py", line 415, in wait_visibility >>>>> self.tk.call('tkwait', 'visibility', window._w) >>>>> TclError: window ".34672232" was deleted before its visibility changed >>>>> =============== >>>>> It runs fine in pythonWin performing the same entry operation. Open a >>>>> menu, select an item to open a dialog, select a select button in the >>>>> dialog, press OK to leave the dialog. Boom, as above. >>>>> (This does not mean pythonWin doesn't have problems of its own. ) If I >>>>> just execute the code (double click on the py file, the console shows no >>>>> problems. IDLE is unhappy. >>>>> Another side to this is that I use WinMerge to find differences between >>>>> my last saved copy and the current copy. I found the current copy had >>>>> two lines where a abc.get() was changed to abc.get. This was undoubtedly >>>>> from briefly using the pyWin editor, when I mis-hit some keys. Yet pyWin >>>>> had no trouble executing the program. My guess is that while briefly >>>>> editing there, I hit some odd combination of keys that produced, >>>>> perhaps, an invisible character that pyWin ignores. >>>>> Not the 34672232 window is a dialog that I closed by pressing OK. I >>>>> would again guess, that, if there is a problem, it occurs in the code >>>>> that destroys the dialog. >>>> Well you have to remember that you are trying to run a windowed GUI >>>> under the control of another windows GUI, so it isn't surprising that >>>> you hit trouble. >>>> With IDLE the issue will be that IDLE already created a main window >>>> before your program started running. With PythonWin you are using two >>>> different toolkits, so it isn't really surprising that breaks down - >>>> there will be two entirely separate main loops competing with each other. >>> Not quite. I take down IDLE when I run pyWin, and vice versa. >> The two separate loops being PyWin (which uses MFC) and your program >> (which uses Tkinter). You just can't mix GUIs in the same process like >> that, sorry. >> >> regards >> Stedve >> -- >> Steve Holden +1 571 484 6266 +1 800 494 3119 >> Holden Web LLC http://www.holdenweb.com/ > > Deja-vu! > > http://mail.python.org/pipermail/python-list/2001-March/076069.html The question now is what can I do about it? reboot? Just to re-iterate the answer I provided the answer to above, I'm using Tkinter for the program's GUI. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From notvalid2 at sbcglobal.net Wed Feb 11 22:58:56 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Wed, 11 Feb 2009 19:58:56 -0800 Subject: Who's on First, IDLE or pythonWin? Dialog Problem? In-Reply-To: <1a05ac6c-9c7e-4411-a702-99bae941f948@h20g2000yqn.googlegroups.com> References: <1a05ac6c-9c7e-4411-a702-99bae941f948@h20g2000yqn.googlegroups.com> Message-ID: >> The two separate loops being PyWin (which uses MFC) and your program >> (which uses Tkinter). You just can't mix GUIs in the same process like >> that, sorry. >> >> regards >> Stedve >> -- >> Steve Holden +1 571 484 6266 +1 800 494 3119 >> Holden Web LLC http://www.holdenweb.com/ > > Deja-vu! > > http://mail.python.org/pipermail/python-list/2001-March/076069.html The question now is what can I do about it? reboot? Just to re-iterate the answer I provided the answer to above, I'm using Tkinter for the program's GUI. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From notvalid2 at sbcglobal.net Wed Feb 11 23:00:34 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Wed, 11 Feb 2009 20:00:34 -0800 Subject: Who's on First, IDLE or pythonWin? Dialog Problem? In-Reply-To: References: <5230d343-6a67-4bc9-af10-8d68ffdc8339@s20g2000yqh.googlegroups.com> Message-ID: <39Nkl.22667$ZP4.17550@nlpi067.nbdc.sbc.com> > So, how do I get rid of it? reboot? Just to re-iterate the I provided the question to above, I'm using Tkinter for the program's GUI. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From notvalid2 at sbcglobal.net Wed Feb 11 23:04:09 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Wed, 11 Feb 2009 20:04:09 -0800 Subject: Who's on First, IDLE or pythonWin? Dialog Problem? In-Reply-To: References: <1a05ac6c-9c7e-4411-a702-99bae941f948@h20g2000yqn.googlegroups.com> Message-ID: It looks like I got an accidentally case of send message 3 times. Well, here's a correct below. > The question now is what can I do about it? reboot? > > Just to re-iterate the answer I provided to *>the question to a post above<*, I'm using > Tkinter for the program's GUI. > -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From jeffgemail at gmail.com Wed Feb 11 23:16:09 2009 From: jeffgemail at gmail.com (jeffg) Date: Wed, 11 Feb 2009 20:16:09 -0800 (PST) Subject: Unicode issue on Windows cmd line References: <5827412b-5637-4005-9410-972b7f1f18ca@h20g2000yqn.googlegroups.com> <49933bb6$0$3304$9b622d9e@news.freenet.de> <173b3dc8-4c7d-4049-979f-492ac8d6fb17@i20g2000prf.googlegroups.com> <49935F7F.5070508@v.loewis.de> <0203136e-4208-45a4-8071-e5249558943e@w35g2000yqm.googlegroups.com> Message-ID: <56bb1488-91c7-434f-ab57-c9c52be80d5b@j35g2000yqh.googlegroups.com> On Feb 11, 10:00?pm, "Gabriel Genellina" wrote: > En Wed, 11 Feb 2009 23:11:37 -0200, jeffg escribi?: > > > > > On Feb 11, 6:30?pm, "Martin v. L?wis" wrote: > >> > Thanks, I ended up using encode('iso-8859-15', "replace") > >> > Perhaps more up to date than cp1252...?? > >> If you encode as iso-8859-15, but this is not what your terminal > >> expects, it certainly won't print correctly. To get correct printing, > >> the output encoding must be the same as the terminal encoding. If the > >> terminal encoding is not up to date (as you consider cp1252), then > >> the output encoding should not be up to date, either. > > I did try UTF-8 but it produced the upper case character instead of > > the proper lower case, so the output was incorrect for the unicode > > supplied. > > I think both 8859-15 and cp1252 produced the correct output, but I > > figured 8859-15 would have additional character support (though not > > sure this is the case - if it is not, please let me know and I'll use > > 1252). ?I'm dealing with large data sets and this just happend to be > > one small example. ?I want to have the best ability to write future > > unicode characters properly based on running from the windows command > > line (unless there is a better way to do it on windows). > > As Martin v. L?wis already said, the encoding used by Python when writing ? > to the console, must match the encoding the console expects. (And you also ? > should use a font capable of displaying such characters). > > windows-1252 and iso-8859-15 are similar, but not identical. This table ? > shows the differences (less than 30 printable characters): ?http://en.wikipedia.org/wiki/Western_Latin_character_sets_(computing) > If your script encodes its output using iso-8859-15, the corresponding ? > console code page should be 28605. > "Western European" (whatever that means exactly) Windows versions use the ? > windows-1252 encoding as the "Ansi code page" (GUI applications), and ? > cp850 as the "OEM code page" (console applications) -- cp437 in the US ? > only. > > C:\Documents and Settings\Gabriel>chcp 1252 > Tabla de c?digos activa: 1252 > > C:\Documents and Settings\Gabriel>python > Python 2.6 (r26:66721, Oct ?2 2008, 11:35:03) [MSC v.1500 32 bit (Intel)] ? > on win > 32 > Type "help", "copyright", "credits" or "license" for more information. > py> unichr(0x0153).encode("windows-1252") > '\x9c' > py> print _ > ? > py> ^Z > > C:\Documents and Settings\Gabriel>chcp 28605 > Tabla de c?digos activa: 28605 > > C:\Documents and Settings\Gabriel>python > Python 2.6 (r26:66721, Oct ?2 2008, 11:35:03) [MSC v.1500 32 bit (Intel)] ? > on win > 32 > Type "help", "copyright", "credits" or "license" for more information. > py> unichr(0x0153).encode("iso-8859-15") > '\xbd' > py> print _ > ? > py> unichr(0x0153).encode("latin9") > '\xbd' > > -- > Gabriel Genellina Thanks, switched it to windows-1252. From jeffgemail at gmail.com Wed Feb 11 23:19:53 2009 From: jeffgemail at gmail.com (jeffg) Date: Wed, 11 Feb 2009 20:19:53 -0800 (PST) Subject: Another optimization request :-) References: <3f05ec0f12c2042f52618fb0db5bbac4.squirrel@acooke.dyndns.org> Message-ID: On Feb 11, 9:56?pm, "andrew cooke" wrote: > sorry, that was stupid. ?there is no inversion (apart from 1/m), just the > integration. > > still, improving the integration would allow larger steps. > > andrew > > andrew cooke wrote: > > > why are you dong this point by point? ?surely you can express the physics > > as a set of equations and invert the matrix? ?wouldn't that be a lot > > faster? ?you'd replace the iteration over all combinations of points with > > a faster matrix inversion. > > > see for example > >http://www.medwelljournals.com/fulltext/ajit/2006/324-338.pdfpage 331 > > onwards. > > > there's a very nice into to the verlet integration mentioned here - > >http://teknikus.dk/tj/gdc2001.htm > > > andrew > > > jeffg wrote: > >> If anyone wants to take this on... I would really really like to have > >> the spring_layout modified to support multi-threading if at all > >> possible. > >> My test data is 20,000, which makes this process 20,000 x 20,000 or > >> 400,000,000 (400 million) calculations. ?This is taking somewhere > >> between 2-3 hours an iteration. > >> I plan to plot out over 1,000,000 data points or more, which would put > >> this at 1,000,000,000,000 (1 trillion) calculations. ?Any help in > >> making this more efficient would be much appreciated. > > >> def spring_layout(G, iterations=50, dim=2, node_pos=None, > >> verbose=False): > >> ? ? """Spring force model layout""" > >> ? ? if node_pos==None : ?# set the initial positions randomly in 1x1 > >> box > >> ? ? ? ? vpos=random_layout(G, dim=dim) > >> ? ? else: > >> ? ? ? ? vpos=node_pos > >> ? ? if iterations==0: > >> ? ? ? ? return vpos > >> ? ? if G.order()==0: > >> ? ? ? ? k=1.0 > >> ? ? else: > >> ? ? ? ? k=N.sqrt(1.0/G.order()) # optimal distance between nodes > >> ? ? disp={} ? ? ? ? # displacements > > >> ? ? # initial "temperature" (about .1 of domain area) > >> ? ? # this is the largest step allowed in the dynamics > >> ? ? # linearly step down by dt on each iteration so > >> ? ? # on last iteration it is size dt. > >> ? ? t=0.1 > >> ? ? dt=0.1/float(iterations+1) > >> ? ? for i in range(0,iterations): > >> ? ? ? ? for v in G: > >> ? ? ? ? ? ? if verbose==True: > >> ? ? ? ? ? ? ? ? print("Interation: " + str(i + 1) + ", Calculating: " > >> + str(v.encode('iso-8859-15', "replace"))) > >> ? ? ? ? ? ? disp[v]=N.zeros(dim) > >> ? ? ? ? ? ? for u in G: > >> ? ? ? ? ? ? ? ? delta=vpos[v]-vpos[u] > >> ? ? ? ? ? ? ? ? dn=max(sqrt(N.dot(delta,delta)),0.01) > >> ? ? ? ? ? ? ? ? # repulsive force between all > >> ? ? ? ? ? ? ? ? deltaf=delta*k**2/dn**2 > >> ? ? ? ? ? ? ? ? disp[v]=disp[v]+deltaf > >> ? ? ? ? ? ? ? ? # attractive force between neighbors > >> ? ? ? ? ? ? ? ? if G.has_edge(v,u): > >> ? ? ? ? ? ? ? ? ? ? deltaf=-delta*dn**2/(k*dn) > >> ? ? ? ? ? ? ? ? ? ? disp[v]=disp[v]+deltaf > > >> ? ? ? ? # update positions > >> ? ? ? ? for v in G: > >> ? ? ? ? ? ? l=max(sqrt(N.dot(disp[v],disp[v])),0.01) > >> ? ? ? ? ? ? vpos[v]=vpos[v]+ disp[v]*t/l > >> ? ? ? ? t-=dt > >> ? ? return vpos > >> -- > >>http://mail.python.org/mailman/listinfo/python-list > > > -- > >http://mail.python.org/mailman/listinfo/python-list > > To be honest, this is not my code and I'm new to python. It's part of the open source project NetworkX, but I'm using this one call extensively. I'm also not that familiar with the math behind the physics. I'll read the documents and see if I can figure it out. :-) Thank you for the links and suggestions. I really need to get this code performing at peak levels. From basilisk96 at gmail.com Wed Feb 11 23:26:12 2009 From: basilisk96 at gmail.com (Basilisk96) Date: Wed, 11 Feb 2009 20:26:12 -0800 (PST) Subject: how can this iterator be optimized? References: <727aabd1-9682-47aa-88e2-5dde96e4c32e@j1g2000yqi.googlegroups.com> Message-ID: > Don't use a generator then. If you're going to finally return a list (and ? > sorted does exactly that), build a list right from the start: Good point. However, for the sake of argument, what if I removed the sorting requirement and simply wanted the generator? I usually strive for comprehensions if a for loop can be reduced to such. Would there be any speed advantage in this case of a comprehension-style generator vs. a for-yield loop (assuming there is a way to call func(s) once per iteration in the comprehension)? In my example, func() operates on filename strings, so it's not too bad.. but it's possible for this pattern to apply to more substantial operations. My conjecture is that higher func() loads would favor more the use of a simple for- yield loop. Cheers, Basilisk96 From jonathan.chacon at telefonica.net Wed Feb 11 23:58:05 2009 From: jonathan.chacon at telefonica.net (=?iso-8859-1?Q?Jonathan_Chac=F3n?=) Date: Thu, 12 Feb 2009 05:58:05 +0100 Subject: TTS in windows Message-ID: <119422E84F8C43C8A5E693A09DAEC260@HPVista> Hello, I need to use SAPI5 text to speech with python but I don't find anything that lets me manage speech, tone, volume, etc Does anybody know anything to do this? Thanks and regards Jonathan Chac?n From elgrandchignon at gmail.com Wed Feb 11 23:58:28 2009 From: elgrandchignon at gmail.com (Jason) Date: Wed, 11 Feb 2009 20:58:28 -0800 (PST) Subject: Breaking Python list into set-length list of lists Message-ID: <8158439d-faae-4889-a1cf-8d9fee112e9b@v39g2000yqm.googlegroups.com> Hey everyone-- I'm pretty new to Python, & I need to do something that's incredibly simple, but combing my Python Cookbook & googling hasn't helped me out too much yet, and my brain is very, very tired & flaccid @ the moment.... I have a list of objects, simply called "list". I need to break it into an array (list of lists) wherein each sublist is the length of the variable "items_per_page". So array[0] would go from array[0][0] to array[0][items_per_page], then bump up to array[1][0] - array[1] [items_per_page], until all the items in the original list were accounted for. What would be the simplest way to do this in Python? And yes, I realize I should probably be taking Programming 101..... From jonathan.chacon at telefonica.net Thu Feb 12 00:00:36 2009 From: jonathan.chacon at telefonica.net (=?iso-8859-1?Q?Jonathan_Chac=F3n?=) Date: Thu, 12 Feb 2009 06:00:36 +0100 Subject: Capture images in macOS X Message-ID: <5732EB03A0054D80976798E0EE7FE3A4@HPVista> Hello, I need to capture images from the macbook webcam in leopard. Does anybody know how can I do this? Thanks and regards Jonathan Chac?n From argo785 at gmail.com Thu Feb 12 00:06:06 2009 From: argo785 at gmail.com (argo785 at gmail.com) Date: Wed, 11 Feb 2009 21:06:06 -0800 (PST) Subject: Thank you, Tkinter. (easy to use) Message-ID: Tonight I needed to draw a series of simple shapes in a window using a bit of math but didn't have much time to do it. I've got very little GUI toolkit experience. Briefly had a look at the usually-recommended heavyweight GUI toolkits, but I didn't want to inherit from widget classes or override paint methods (not that those things don't have their place). I just wanted to quickly draw some shapes. Within a few minutes I had what I needed, and it was by using Tkinter. The code looked something like this: ~~~~ #!/usr/bin/env python import Tkinter as tk root = tk.Tk() canv = tk.Canvas(root, width=647, height=400, background='white') canv.pack(side=tk.TOP, fill=tk.BOTH, expand=1) # drawing happens here ... canv.create_oval(50, 80, 150, 180) # ... root.mainloop() ~~~~ Wow that was *really* easy. After playing around just a bit more, regular GUI programs are pretty quick and simple to make as well. My only (minor) complaint is that Tk doesn't draw text antialiased in the various widgets (menus, labels, buttons, etc.). Anyway, thanks Tk and Tkinter! From mensanator at aol.com Thu Feb 12 00:41:30 2009 From: mensanator at aol.com (Mensanator) Date: Wed, 11 Feb 2009 21:41:30 -0800 (PST) Subject: Breaking Python list into set-length list of lists References: <8158439d-faae-4889-a1cf-8d9fee112e9b@v39g2000yqm.googlegroups.com> Message-ID: <4cf62c27-ce57-4101-83a8-34285db537ff@a12g2000yqm.googlegroups.com> On Feb 11, 10:58?pm, Jason wrote: > Hey everyone-- > > I'm pretty new to Python, & I need to do something that's incredibly > simple, but combing my Python Cookbook & googling hasn't helped me out > too much yet, and my brain is very, very tired & flaccid @ the > moment.... > > I have a list of objects, simply called "list". ?I need to break it > into an array (list of lists) wherein each sublist is the length of > the variable "items_per_page". ?So array[0] would go from array[0][0] > to array[0][items_per_page], then bump up to array[1][0] - array[1] > [items_per_page], until all the items in the original list were > accounted for. > > What would be the simplest way to do this in Python? ?And yes, I > realize I should probably be taking Programming 101..... >>> items_per_page = 20 >>> x = range(113) >>> layout = divmod(113,20) >>> if layout[1]>0: pages = layout[0]+1 else: pages = layout[0] >>> array = [ x[i*items_per_page:i*items_per_page+items_per_page] for i in xrange(pages)] >>> array [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39], [40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59], [60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79], [80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99], [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112]] From tjreedy at udel.edu Thu Feb 12 00:41:39 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 12 Feb 2009 00:41:39 -0500 Subject: how can this iterator be optimized? In-Reply-To: References: <727aabd1-9682-47aa-88e2-5dde96e4c32e@j1g2000yqi.googlegroups.com> Message-ID: Basilisk96 wrote: >> Don't use a generator then. If you're going to finally return a list (and >> sorted does exactly that), build a list right from the start: > > Good point. However, for the sake of argument, what if I removed the > sorting requirement and simply wanted the generator? Write a generator function with the same loop and a yield. ? I usually strive > for comprehensions if a for loop can be reduced to such. You are overdoing it, I think. Generator expressions are for saving programmer time, not machine time. From skippy.hammond at gmail.com Thu Feb 12 00:47:21 2009 From: skippy.hammond at gmail.com (Mark Hammond) Date: Thu, 12 Feb 2009 16:47:21 +1100 Subject: TTS in windows In-Reply-To: <119422E84F8C43C8A5E693A09DAEC260@HPVista> References: <119422E84F8C43C8A5E693A09DAEC260@HPVista> Message-ID: <4993B7E9.2030304@gmail.com> On 12/02/2009 3:58 PM, Jonathan Chac?n wrote: > Hello, > > I need to use SAPI5 text to speech with python but I don't find anything > that lets me manage speech, tone, volume, etc > > > Does anybody know anything to do this? It appears this is doable from COM. With the pywin32 package: >>> import win32com.client >>> o=win32com.client.Dispatch("{96749377-3391-11D2-9EE3-00C04F797396}") >>> o.Speak("Hello there") 1 >>> o.Volume 100 >>> o.Volume=50 >>> o.Speak("Hello there") 1 Works for me on Vista. The magic number is the value for CLSID_SpVoice, which I found by googling (for some reason, the actual definition of that CLSID doesn't appear in the SDK headers...) HTH, Mark From sambit2005 at gmail.com Thu Feb 12 00:48:26 2009 From: sambit2005 at gmail.com (Sambit Samal) Date: Thu, 12 Feb 2009 18:48:26 +1300 Subject: Need an application sends from paricular port Message-ID: <9e680b420902112148r75abe35emb629d2d9ddb33b9c@mail.gmail.com> Hi I am new to Python world I need a python script , which binds at a user defind port & sends to other enity , which waits at particular port. The other enity will respond & Python script should receive that at the defined port The communication will happen over UDP e.g *Python Appl* IP: 10.116.78.90 Port : 3000 *Other Enity* : IP: 10.116.98.87 Port : 3010 Pyhon Appl ------------>UDP ----> Other Enity <-------------------------- Please help -------------- next part -------------- An HTML attachment was scrubbed... URL: From si.422a at yahoo.com Thu Feb 12 00:52:49 2009 From: si.422a at yahoo.com (Saeed Iravani) Date: Wed, 11 Feb 2009 21:52:49 -0800 (PST) Subject: explain Message-ID: <25821.66604.qm@web111201.mail.gq1.yahoo.com> Hello, I want to use python but I do not know that I install Python or ActivePython or VPython or Jython? My operating system is Windows XP SP2. Please explain for me completely. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Thu Feb 12 00:53:25 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 12 Feb 2009 00:53:25 -0500 Subject: Another optimization request :-) In-Reply-To: References: Message-ID: jeffg wrote: > If anyone wants to take this on... I would really really like to have > the spring_layout modified to support multi-threading if at all > possible. > My test data is 20,000, which makes this process 20,000 x 20,000 or > 400,000,000 (400 million) calculations. This is taking somewhere > between 2-3 hours an iteration. > I plan to plot out over 1,000,000 data points or more, which would put > this at 1,000,000,000,000 (1 trillion) calculations. Any help in > making this more efficient would be much appreciated. > > def spring_layout(G, iterations=50, dim=2, node_pos=None, > verbose=False): > """Spring force model layout""" > if node_pos==None : # set the initial positions randomly in 1x1 > box > vpos=random_layout(G, dim=dim) > else: > vpos=node_pos > if iterations==0: > return vpos > if G.order()==0: > k=1.0 > else: > k=N.sqrt(1.0/G.order()) # optimal distance between nodes > disp={} # displacements > > # initial "temperature" (about .1 of domain area) > # this is the largest step allowed in the dynamics > # linearly step down by dt on each iteration so > # on last iteration it is size dt. > t=0.1 > dt=0.1/float(iterations+1) > for i in range(0,iterations): > for v in G: > if verbose==True: > print("Interation: " + str(i + 1) + ", Calculating: " > + str(v.encode('iso-8859-15', "replace"))) > disp[v]=N.zeros(dim) > for u in G: > delta=vpos[v]-vpos[u] Let n = len(vpos). I believe there are only n-1 different deltas, dns, and deltafs, where as n**2 calculations are made. > dn=max(sqrt(N.dot(delta,delta)),0.01) > # repulsive force between all > deltaf=delta*k**2/dn**2 > disp[v]=disp[v]+deltaf > # attractive force between neighbors > if G.has_edge(v,u): > deltaf=-delta*dn**2/(k*dn) > disp[v]=disp[v]+deltaf > > # update positions > for v in G: > l=max(sqrt(N.dot(disp[v],disp[v])),0.01) > vpos[v]=vpos[v]+ disp[v]*t/l > t-=dt > return vpos That aside, array calculations like this should be *much* faster with numpy. Or try compiling (with weave or Cython, for instance). From tjreedy at udel.edu Thu Feb 12 00:56:07 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 12 Feb 2009 00:56:07 -0500 Subject: Breaking Python list into set-length list of lists In-Reply-To: <8158439d-faae-4889-a1cf-8d9fee112e9b@v39g2000yqm.googlegroups.com> References: <8158439d-faae-4889-a1cf-8d9fee112e9b@v39g2000yqm.googlegroups.com> Message-ID: Jason wrote: > I have a list of objects, simply called "list". Bad idea. > I need to break it > into an array (list of lists) wherein each sublist is the length of > the variable "items_per_page". So array[0] would go from array[0][0] > to array[0][items_per_page], then bump up to array[1][0] - array[1] > [items_per_page], until all the items in the original list were > accounted for. Assuming this is not homework, look at itertools module. > What would be the simplest way to do this in Python? And yes, I > realize I should probably be taking Programming 101..... I guess it is not. From steven at REMOVE.THIS.cybersource.com.au Thu Feb 12 00:56:27 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 12 Feb 2009 05:56:27 GMT Subject: Breaking Python list into set-length list of lists References: <8158439d-faae-4889-a1cf-8d9fee112e9b@v39g2000yqm.googlegroups.com> Message-ID: On Wed, 11 Feb 2009 20:58:28 -0800, Jason wrote: > I have a list of objects, simply called "list". Generally speaking, that's not a good choice of names, because it over- writes ("shadows") the built-in function list(). > I need to break it into > an array (list of lists) wherein each sublist is the length of the > variable "items_per_page". So array[0] would go from array[0][0] to > array[0][items_per_page], then bump up to array[1][0] - array[1] > [items_per_page], until all the items in the original list were > accounted for. This may not be the simplest or most efficient way of doing it, but it doesn't involve any advanced techniques other than slicing (which is pretty fundamental to Python). >>> from string import lowercase # just some random data >>> list = list(lowercase) >>> items_per_page = 5 >>> array = [] >>> num_sublists = len(list)//items_per_page >>> if len(list) % items_per_page != 0: ... num_sublists += 1 ... >>> for i in range(num_sublists): ... array.append(list[i*items_per_page:(i+1)*items_per_page]) ... >>> >>> from pprint import pprint >>> pprint(array) [['a', 'b', 'c', 'd', 'e'], ['f', 'g', 'h', 'i', 'j'], ['k', 'l', 'm', 'n', 'o'], ['p', 'q', 'r', 's', 't'], ['u', 'v', 'w', 'x', 'y'], ['z']] >>> There are other alternatives. Here's a more advanced technique: >>> ipp = 7 # use a shorter name >>> m, n = divmod(len(list), ipp) >>> array = [list[i*ipp:(i+1)*ipp] for i in range(m+bool(n))] >>> pprint(array) [['a', 'b', 'c', 'd', 'e', 'f', 'g'], ['h', 'i', 'j', 'k', 'l', 'm', 'n'], ['o', 'p', 'q', 'r', 's', 't', 'u'], ['v', 'w', 'x', 'y', 'z']] -- Steven From pythonnutter at gmail.com Thu Feb 12 00:59:46 2009 From: pythonnutter at gmail.com (Python Nutter) Date: Thu, 12 Feb 2009 16:59:46 +1100 Subject: Programmatically changing network proxy settings on the Mac In-Reply-To: References: Message-ID: OS X is POSIX/UNIX system so your basic plan of going about things: 1. Learn what proxy/network subsystem Tiger uses 2. Learn what proxy/network subsystem Leopard uses (same as 1., or has it changed?) 3. Based on 1 and 2 learn the config file names and locations. 4. Based on 3 you will determine if the file is text or xml format so learn file processing for whichever one 5. Read the config file, Make some changes in OS X, read the config file and compare changes. 6. Programatically script changes to those config file(s). 7. Learn if any service/daemon needs to be restarted or if an interface needs to be brought down/up to bring in those changes to the config file. 8. Script in what you learned in 7. 9. Finished. 2009/2/11 : > Hi, > > Anybody have suggestions of how network proxy settings can be changed > programmatically on the Mac, Tiger and Leopard. Are there any helpful > python api's that can be used. > > Thanks > Sunil > -- > http://mail.python.org/mailman/listinfo/python-list > From david.birdsong at gmail.com Thu Feb 12 01:09:11 2009 From: david.birdsong at gmail.com (birdsong) Date: Wed, 11 Feb 2009 22:09:11 -0800 (PST) Subject: select.poll.poll() never blocks References: Message-ID: <3e3d6829-cda8-4e34-98ab-617b65caf436@l39g2000yqn.googlegroups.com> On Feb 11, 7:47?pm, "Rhodri James" wrote: > On Thu, 12 Feb 2009 03:01:16 -0000, birdsong ? > wrote: > > > So I guess I didn't have a complete understanding of poll, I thought > > it returned file descriptors that had registered an event that the > > user asked to watch for. ?In my case, select.POLLIN > > Constant ? Meaning > > POLLIN ? ? There is data to read > > > ...there ins't any data to be read. ?The file is readable, yes, but is > > that all that the syscall has to offer? > > To quote the web page referenced in help(select): > > "It cannot be used on regular files to determine whether a file has grown ? > since it was last read." > > poll() and friends are wrappers over the socket library "poll" and > "select" functions, which primarily exist to facilitate asynchronous > socket communications. ?They can take ordinary file descriptors as > well as sockets because there's no good reason not to, but a regular > file will always be ready to read as long as you haven't read past > the end of file. > > You're trying to use a regular file as if it was a pipe. ?My first > obvious question is do you have to do it this way? ?Do you have > any control over the program writing to file? ?Can you cause the > output to go to stdout and pipe it into your script's stdin > instead? ?That would make your life vastly easier. agreed, this was my original idea, but i figured implementing a tail - f via poll was alot faster to write and implement. i'm glad at least know why it wasn't working as expected. i've already written a tail -f similar to the one found in the link from a later poster, but i was hoping to use poll to cut down on unecessary seeks -i'm trying to avoid actions that would drive up iowait on the boxes this would run on. thanks for the clarification on the poll family of syscalls. > > If you can't, I'm not sure what your best strategy is. ?I'd > be tempted to use "tail -f filetocheck | yourscript.py" and > palm the job off on an already-written tool. ?If you want to > do it in Python, the only thing that springs to mind is > periodically checking the size of the file and reading more > when that changes. ?You'll need to be very careful to keep > what size you think the file is in sync with how much you've > read! > > -- > Rhodri James *-* Wildebeeste Herder to the Masses From ntwrkd at gmail.com Thu Feb 12 01:09:46 2009 From: ntwrkd at gmail.com (gofkuckyourself) Date: Wed, 11 Feb 2009 22:09:46 -0800 Subject: explain In-Reply-To: <25821.66604.qm@web111201.mail.gq1.yahoo.com> References: <25821.66604.qm@web111201.mail.gq1.yahoo.com> Message-ID: Saeed, The standard Python distribution is community supported and available on Windows http://www.python.org/download/windows/ ActivePython is ActiveState's version of Python with extra libraries and commercial support available VPython I am not familiar with, perhaps someone else can speak to this Jython is good if you are used to developing in Java and want to utlize / embed Python in Java code. It is also good for many other reasons, but for beginning purposes I would recommend the standard python distribution. To get started see http://www.python.org/about/gettingstarted/ Hope this helps. On Wed, Feb 11, 2009 at 9:52 PM, Saeed Iravani wrote: > Hello, I want to use python but I do not know that I install Python or > ActivePython or VPython or Jython? > My operating system is Windows XP SP2. > Please explain for me completely. > > > -- > http://mail.python.org/mailman/listinfo/python-list > > From pythonnutter at gmail.com Thu Feb 12 01:12:41 2009 From: pythonnutter at gmail.com (Python Nutter) Date: Thu, 12 Feb 2009 17:12:41 +1100 Subject: explain In-Reply-To: <25821.66604.qm@web111201.mail.gq1.yahoo.com> References: <25821.66604.qm@web111201.mail.gq1.yahoo.com> Message-ID: If your use is to Generically "want to use python on Windows XP" you install the standard/generic Python that you download from python.org Without any details to decide with, I would also say download version 2.5.4 of Python from python.org 2009/2/12 Saeed Iravani : > Hello, I want to use python but I do not know that I install Python or > ActivePython or VPython or Jython? > My operating system is Windows XP SP2. > Please explain for me completely. > > > -- > http://mail.python.org/mailman/listinfo/python-list > > From steven at REMOVE.THIS.cybersource.com.au Thu Feb 12 01:13:38 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 12 Feb 2009 06:13:38 GMT Subject: Avoiding argument checking in recursive calls References: <7xeiy52zfl.fsf@ruckus.brouhaha.com> Message-ID: On Wed, 11 Feb 2009 04:31:10 -0500, Terry Reedy wrote: >> Steven D'Aprano writes: >>> def fact(n): >>> if n < 0: raise ValueError >>> if n = 0: return 1 >>> return fact(n-1)*n >>> >>> At the risk of premature optimization, I wonder if there is an idiom >>> for avoiding the unnecessary test for n <= 0 in the subsequent >>> recursive calls? > > Reverse the test order > > def fact(n): > if n > 0: return fact(n-1)*n > if n == 0: return 1 > raise ValueError > > You must test recursive versus terminal case every call in any case. > Nearly always, the first test passes and second is not done. You only > test n==0 once, either to terminate or raise exception. This works for > any integral value and catches non-integral values. (There is some delay > for that, but only bad calls are penalized.) Nice try, but in fact no. >>> fact(None) # works okay Traceback (most recent call last): File "", line 1, in File "", line 4, in fact ValueError >>> >>> fact({}) Traceback (most recent call last): File "", line 1, in File "", line 2, in fact TypeError: unsupported operand type(s) for -: 'dict' and 'int' You're relying on arbitrary ordering of types in Python 2.x, and of course in Python 3 that fails altogether. Thanks for everyone who responded, I now have some food for thought. -- Steven From steven at REMOVE.THIS.cybersource.com.au Thu Feb 12 01:15:19 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 12 Feb 2009 06:15:19 GMT Subject: how can this iterator be optimized? References: <727aabd1-9682-47aa-88e2-5dde96e4c32e@j1g2000yqi.googlegroups.com> Message-ID: On Wed, 11 Feb 2009 20:26:12 -0800, Basilisk96 wrote: >> Don't use a generator then. If you're going to finally return a list >> (and sorted does exactly that), build a list right from the start: > > Good point. However, for the sake of argument, what if I removed the > sorting requirement and simply wanted the generator? The same applies. You're problem is that you call an expensive function three times instead of once. Some compilers can optimize that away, but not in Python, because there's no guarantee that the function will be the same function between calls. > I usually strive > for comprehensions if a for loop can be reduced to such. Any particular reason? > Would there be > any speed advantage in this case of a comprehension-style generator vs. > a for-yield loop (assuming there is a way to call func(s) once per > iteration in the comprehension)? I understand that comprehensions are slightly slower. I recently found a 40% speed up on a trivial generator expression when converted to a for loop. Admittedly the gen expr did very little, and I haven't tested list comprehensions. > In my example, func() operates on > filename strings, so it's not too bad.. but it's possible for this > pattern to apply to more substantial operations. My conjecture is that > higher func() loads would favor more the use of a simple for- yield > loop. If there's only one call to func(), and you ignore the (probably) fixed cost of jumping into a generator each time, then it shouldn't make any difference. If you are comparing one call to func() in a for loop versus three calls to func() in a list comp or generator expression, then of course the for loop will be more efficient. -- Steven From mail at microcorp.co.za Thu Feb 12 01:18:54 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Thu, 12 Feb 2009 08:18:54 +0200 Subject: Functional schmunctional... References: Message-ID: <00a501c98cd9$c8693620$0d00a8c0@hendrik> "Steve Holden" wrote: > Jeez, doesn't anyone read the fine manual any more? I hope this was just > an academic exercise. > > >>> socket.inet_ntoa(struct.pack("!l", 1000000000)) > '59.154.202.0' > >>> > > Holden's rule: when it looks simple enough to be worth including in the > standard library it may well already *be* in the standard library. Aaah! But how do you find it, if you don't already know where it lives and what it's called ? - Hendrik From mail at microcorp.co.za Thu Feb 12 01:36:03 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Thu, 12 Feb 2009 08:36:03 +0200 Subject: select.poll.poll() never blocks References: Message-ID: <018901c98cdc$2de44c40$0d00a8c0@hendrik> "birdsong" wrote: 8<----------- select not blocking on empty file stuff ----------------- > Any help on what I'm missing would be appreciated. Why do you expect it to block? It is ready to read, to return end of file. - Hendrik From rt8396 at gmail.com Thu Feb 12 01:39:24 2009 From: rt8396 at gmail.com (r) Date: Wed, 11 Feb 2009 22:39:24 -0800 (PST) Subject: Thank you, Tkinter. (easy to use) References: Message-ID: <766ffd59-b531-4268-88ae-357dc726c67f@33g2000yqm.googlegroups.com> Hello, Tkinter is a great GUI toolkit, for what it lacks in prettiness it more than makes up for in simple and quick GUI building. I think this is the main reason Tkinter continues to be Python's built-in GUI toolkit. It is a great place to start for those with no GUI experience. Sure it will never be as rich as wxPython or the like, but that is not what Tkinter is made for. I use Tkinter for all my tools that need a UI, and others as well. The only complaint i have is the poor support for image types i really wish there where at least support for one good image like jpg, png, and full color bitmaps.The canvas widget could also use a little more functionality, but hey maybe one day i will have time to polish it up a bit. From metolone+gmane at gmail.com Thu Feb 12 01:48:57 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Wed, 11 Feb 2009 22:48:57 -0800 Subject: Breaking Python list into set-length list of lists References: <8158439d-faae-4889-a1cf-8d9fee112e9b@v39g2000yqm.googlegroups.com> Message-ID: "Jason" wrote in message news:8158439d-faae-4889-a1cf-8d9fee112e9b at v39g2000yqm.googlegroups.com... > Hey everyone-- > > I'm pretty new to Python, & I need to do something that's incredibly > simple, but combing my Python Cookbook & googling hasn't helped me out > too much yet, and my brain is very, very tired & flaccid @ the > moment.... > > I have a list of objects, simply called "list". I need to break it > into an array (list of lists) wherein each sublist is the length of > the variable "items_per_page". So array[0] would go from array[0][0] > to array[0][items_per_page], then bump up to array[1][0] - array[1] > [items_per_page], until all the items in the original list were > accounted for. > > What would be the simplest way to do this in Python? And yes, I > realize I should probably be taking Programming 101..... >>> def splitlist(L,count): ... M=[] ... for i in xrange(0,len(L),count): ... M.append(L[i:i+count]) ... return M ... >>> L=range(18) >>> splitlist(L,3) [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11], [12, 13, 14], [15, 16, 17]] >>> splitlist(L,4) [[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15], [16, 17]] -Mark From timr at probo.com Thu Feb 12 01:58:32 2009 From: timr at probo.com (Tim Roberts) Date: Thu, 12 Feb 2009 06:58:32 GMT Subject: Python binaries with VC++ 8.0? References: <6va201FijdteU1@mid.individual.net> <17612b99-0756-47a1-ae4f-5e05e18813cd@r41g2000prr.googlegroups.com> <38b2p4d6g521bi0rtjiat686pamkvke3i3@4ax.com> <7xwsby7mw3.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: >In case anyone is interested: Gideon Smeding of the University of >Utrecht has written a masters' thesis titled "An executable >operational semantics for Python". That's an interesting grammatical construct. I would have said either "Executable operational semantics for Python," or "An executable operational semantic for Python." "A semantics" just doesn't flow. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From david.birdsong at gmail.com Thu Feb 12 02:14:25 2009 From: david.birdsong at gmail.com (birdsong) Date: Wed, 11 Feb 2009 23:14:25 -0800 (PST) Subject: select.poll.poll() never blocks References: Message-ID: <30014b58-d47a-4930-96a8-9fcd02764d7a@r41g2000yqm.googlegroups.com> On Feb 11, 10:36?pm, "Hendrik van Rooyen" wrote: > "birdsong" wrote: > > 8<----------- select not blocking on empty file stuff ----------------- > > > Any help on what I'm missing would be appreciated. > > Why do you expect it to block? > It is ready to read, to return end of file. > I expected it to block because of the name and meaning of the flag, POLLIN, which I thought meant new data has arrived to be read. Since I only registered a single file descriptor, I would have expected poll to not return until there was new data to be read. I understand now that it is not the case. From jonathan.chacon at telefonica.net Thu Feb 12 02:38:44 2009 From: jonathan.chacon at telefonica.net (=?iso-8859-1?Q?Jonathan_Chac=F3n?=) Date: Thu, 12 Feb 2009 08:38:44 +0100 Subject: TTS in windows In-Reply-To: <4993B7E9.2030304@gmail.com> References: <119422E84F8C43C8A5E693A09DAEC260@HPVista> <4993B7E9.2030304@gmail.com> Message-ID: -----Mensaje original----- De: Mark Hammond [mailto:skippy.hammond at gmail.com] Enviado el: jueves, 12 de febrero de 2009 6:47 >It appears this is doable from COM. With the pywin32 package: Well, I have problems to install pywin32 (pywin32-212.win32-py2.5.exe) I'll try to solve that problem later Thanks Jonathan Chac?n From xahlee at gmail.com Thu Feb 12 02:45:47 2009 From: xahlee at gmail.com (Xah Lee) Date: Wed, 11 Feb 2009 23:45:47 -0800 (PST) Subject: which language has syntax that visually represent a tree? [was X#] References: <6toeb5Fbjeu1U1@mid.individual.net> Message-ID: <258b8081-9265-4c47-b23a-132e0ff696c0@r37g2000prr.googlegroups.com> syntax that represent a tree purely [was X#] On Jan 21, 3:13 am, Pascal Costanza wrote: > LOL: http://www.xsharp.org/samples/ Today, i was nosing about some blogs, which made me come to: http://blog.fogus.me/2009/02/06/yegge-clojure-arc-and-lolita-or-days-of-future-past in which he wrote: ?Now I?m not a LISP expert, but it seems to me that the S-Expression is generally regarded as the canonical representation of the LISP AST (and many other languages for that matter). That is, the LISP syntax is as close to an AST as one can get. Perhaps the presence of macros, #, `, ?, and , muddy the waters a bit, but not much.? that is technically not true. Although you mentioned lisp syntax irregularities like ?# , ,@ '?, but in general this sentiment that lisp has regular syntax, or that its syntax is closest to abstract syntax tree, is perpetuating a myth. Mathematica language's syntax, XML, and XML derived general purpose languages (e.g. O:XML, X#), are in fact more regular and closest to a pure tree representation of the abstract syntax tree. For detail, see: ? Fundamental Problems of Lisp http://xahlee.org/UnixResource_dir/writ/lisp_problems.html (the first section; on syntax irregularity) ? The Concepts and Confusions of Prefix, Infix, Postfix and Fully Nested Notations http://xahlee.org/UnixResource_dir/writ/notations.html also note, nesting matching delimiters is not the only way to represent a tree. Indentation, such as used in Python or ascii-picture tree used to represent directories and sub dirs and files, is another form, arguably has more clarity than nesting with delimiters. As far as i known, there were a couple such proposal/spec/library with working implementation of this syntax that works for Scheme lisp. in general, the question is what are ways to represent a tree structure visually using text. The lisp, Mathematica approach is nesting matching pairs. Ascii-picture approch is using lines to represent a tree node and indentation to represent their level. (python's syntax borrows this idea, however not in a pure form, in the sense that the source code's visual representation does not correspond to python's AST, far from it) Note here, one of the important aspect here is VISUALLY. Because otherwise any syntax is abstract syntax tree by definition. This criterion can be formalized mathematically, by saying that the parser for such a syntax should be very simple as having just one heuristics that is based on recursion. (i dont have expertise in parsing, but in parser jargon, i think there are simple terms to describe this class of syntax, something like: its lexical grammar can be parsed by parsing expression grammar) Another important aspect here is that the source code of lang with such syntax also needs to remain human readable and practically usable for programers to type conveniently. This is the reason, lisp has few irregular syntax introduced. Mathematica, take the approach of a layer of syntax on top of the regular. This in my opinion has 2 major advantages: A: the regularity of the syntax is unadulterated. B: arbitrary shorter, traditional, or algebraic syntax can be introduced. This is also why, python's syntax isn't a pure representation of its abstract syntax tree, else, to code ?print 3+4*5? becomes: print + 3 * 4 5 As for XML derived languages, the problem of verbosity and nesting largely remains. The practiced solution seems to head towards a specialized editor so that programers work on the editor's simpler representation instead of the source code. (e.g. much of MathML, and conversely Microsoft Word with its XML file format) Xah ? http://xahlee.org/ ? From grflanagan at gmail.com Thu Feb 12 02:46:47 2009 From: grflanagan at gmail.com (Gerard Flanagan) Date: Thu, 12 Feb 2009 07:46:47 +0000 Subject: Breaking Python list into set-length list of lists In-Reply-To: <8158439d-faae-4889-a1cf-8d9fee112e9b@v39g2000yqm.googlegroups.com> References: <8158439d-faae-4889-a1cf-8d9fee112e9b@v39g2000yqm.googlegroups.com> Message-ID: Jason wrote: > Hey everyone-- > > I'm pretty new to Python, & I need to do something that's incredibly > simple, but combing my Python Cookbook & googling hasn't helped me out > too much yet, and my brain is very, very tired & flaccid @ the > moment.... > > I have a list of objects, simply called "list". I need to break it > into an array (list of lists) wherein each sublist is the length of > the variable "items_per_page". So array[0] would go from array[0][0] > to array[0][items_per_page], then bump up to array[1][0] - array[1] > [items_per_page], until all the items in the original list were > accounted for. > If you need to pad the last item: def chunk( seq, size, pad=None ): ''' Slice a list into consecutive disjoint 'chunks' of length equal to size. The last chunk is padded if necessary. >>> list(chunk(range(1,10),3)) [[1, 2, 3], [4, 5, 6], [7, 8, 9]] >>> list(chunk(range(1,9),3)) [[1, 2, 3], [4, 5, 6], [7, 8, None]] >>> list(chunk(range(1,8),3)) [[1, 2, 3], [4, 5, 6], [7, None, None]] >>> list(chunk(range(1,10),1)) [[1], [2], [3], [4], [5], [6], [7], [8], [9]] >>> list(chunk(range(1,10),9)) [[1, 2, 3, 4, 5, 6, 7, 8, 9]] >>> for X in chunk([],3): print X >>> ''' n = len(seq) mod = n % size for i in xrange(0, n-mod, size): yield seq[i:i+size] if mod: padding = [pad] * (size-mod) yield seq[-mod:] + padding If you search the list archive, there is surely an example which will do the same for an arbitrary iterable (in general, you can't assume that `len(seq)` will work for an iterable that is not a list, set or tuple). But if you are just starting with Python, don't worry about this. From greg at cosc.canterbury.ac.nz Thu Feb 12 03:30:49 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Thu, 12 Feb 2009 21:30:49 +1300 Subject: Python 3D CAD -- need collaborators, or just brave souls :) In-Reply-To: References: Message-ID: <4993DE39.8030200@cosc.canterbury.ac.nz> rantingrick wrote: > It has long been my dream to create an open source 3D CAD program and > > I have a real good idea of the UI design Have you seen Sketchup? http://sketchup.google.com/ It has an amazingly intuitive user interface, much better than any other 3D modeller I've seen. Anyone thinking of designing a 3D app would do well to study it closely, IMO. Something with a Sketchup-like UI but designed for serious CAD work would be an incredibly good thing to have. In any case, your project sounds interesting, and I'll be happy to discuss ideas if you want. -- Greg From sjmachin at lexicon.net Thu Feb 12 03:53:06 2009 From: sjmachin at lexicon.net (John Machin) Date: Thu, 12 Feb 2009 00:53:06 -0800 (PST) Subject: Breaking Python list into set-length list of lists References: <8158439d-faae-4889-a1cf-8d9fee112e9b@v39g2000yqm.googlegroups.com> Message-ID: On Feb 12, 6:46?pm, Gerard Flanagan wrote: > Jason wrote: > > Hey everyone-- > > > I'm pretty new to Python, & I need to do something that's incredibly > > simple, but combing my Python Cookbook & googling hasn't helped me out > > too much yet, and my brain is very, very tired & flaccid @ the > > moment.... > > > I have a list of objects, simply called "list". ?I need to break it > > into an array (list of lists) wherein each sublist is the length of > > the variable "items_per_page". ?So array[0] would go from array[0][0] > > to array[0][items_per_page], then bump up to array[1][0] - array[1] > > [items_per_page], until all the items in the original list were > > accounted for. > > If you need to pad the last item: > > def chunk( seq, size, pad=None ): > ? ? ?''' > ? ? ?Slice a list into consecutive disjoint 'chunks' of > ? ? ?length equal to size. The last chunk is padded if necessary. > > ? ? ?>>> list(chunk(range(1,10),3)) > ? ? ?[[1, 2, 3], [4, 5, 6], [7, 8, 9]] > ? ? ?>>> list(chunk(range(1,9),3)) > ? ? ?[[1, 2, 3], [4, 5, 6], [7, 8, None]] > ? ? ?>>> list(chunk(range(1,8),3)) > ? ? ?[[1, 2, 3], [4, 5, 6], [7, None, None]] > ? ? ?>>> list(chunk(range(1,10),1)) > ? ? ?[[1], [2], [3], [4], [5], [6], [7], [8], [9]] > ? ? ?>>> list(chunk(range(1,10),9)) > ? ? ?[[1, 2, 3, 4, 5, 6, 7, 8, 9]] > ? ? ?>>> for X in chunk([],3): print X > ? ? ?>>> > ? ? ?''' > ? ? ?n = len(seq) > ? ? ?mod = n % size > ? ? ?for i in xrange(0, n-mod, size): > ? ? ? ? ?yield seq[i:i+size] > ? ? ?if mod: > ? ? ? ? ?padding = [pad] * (size-mod) > ? ? ? ? ?yield seq[-mod:] + padding > > If you search the list archive, there is surely an example which will do > the same for an arbitrary iterable (in general, you can't assume that > `len(seq)` will work for an iterable that is not a list, set or tuple). > But if you are just starting with Python, don't worry about this. Aren't you making it out to be more mysterious than it needs to be? Let's show the guy just a teensy bit of Python 102: | >>> import string; data = string.ascii_lowercase | >>> page_size = 6 | >>> pages = [] | >>> index = 0 | >>> for item in data: | ... if not index: | ... pages.append([]) | ... shelve_it = pages[-1].append | ... index = (index + 1) % page_size | ... shelve_it(item) | ... | >>> pages | [['a', 'b', 'c', 'd', 'e', 'f'], ['g', 'h', 'i', 'j', 'k', 'l'], ['m', 'n', 'o', 'p', 'q', 'r'], ['s', 't', 'u', 'v', 'w', 'x'], ['y', 'z']] | >>> From no.i.dont at want.mail.from.spammers.com Thu Feb 12 04:07:53 2009 From: no.i.dont at want.mail.from.spammers.com (WP) Date: Thu, 12 Feb 2009 10:07:53 +0100 Subject: Why does way_1() obtain the correct list but way_2() gets an empty list? Message-ID: <6vi779Fk0ogtU1@mid.individual.net> Hello group! This is probably a silly newbie mistake but consider the following program: import libsbml def getSBMLModel(biomodel_path): reader = libsbml.SBMLReader() sbml_doc = reader.readSBML(biomodel_path) sbml_model = None if sbml_doc.getNumErrors() > 0: print 'I couldn\'t read the file %s!' % biomodel_path return None else: sbml_model = sbml_doc.getModel() return sbml_doc.getModel() # None if file couldn't be opened def way_1(biomodel_path): reader = libsbml.SBMLReader() sbml_doc = reader.readSBML(biomodel_path) sbml_model = sbml_doc.getModel() if sbml_model == None: return l = sbml_model.getListOfSpecies() print 'In way_1(): Got list %s with the length %i' % (l, len(l)) def way_2(biomodel_path): sbml_model = getSBMLModel(biomodel_path) if sbml_model == None: return l = sbml_model.getListOfSpecies() print 'In way_2(): Got list %s with the length %i' % (l, len(l)) file = '../BIOMD0000000003.xml' # Changing the order of these two calls doesn't help, only way_1() works. way_1(file) way_2(file) When run, the output is: In way_1(): Got list > with the length 3 In way_2(): Got list > with the length 0 I don't get it way the species list obtained in way_2() is empty? For the input file I'm using I should be getting 3 species for the test file I'm using. I'm sorry that this program uses a third-party library which is probably unknown to many, but since I make a lot of newbie mistakes I thought that it's very likely that this is a issue in how I use python, not a library issue. To compensate somewhat I tried to show my entire test program and its output and make that test program as clear as possible. So if anyone knows why I get this behavior I would like to hear it and I will have learned something today too! :) - WP From deets at nospam.web.de Thu Feb 12 04:22:33 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 12 Feb 2009 10:22:33 +0100 Subject: Embed a web browser into a page References: Message-ID: <6vi82pFjn2ocU1@mid.uni-berlin.de> Carbon Man wrote: > Hi, > I need to embed a web browser into a python page. I am coming from the MS > world where I created an app that all of it's interfaces were actually web > pages rendered in an Internet Explorer activex control. There was a object > hook that allowed you to call into the host environment from javascript. > Basically the host environment would receive the documentComplete event > and call a method in the document's Javascript passing in an object > reference. That reference would then be available for calls to be made > from Javascript back into the host environment. > I am just starting to explore the Pythonic programming jungle and I was > wondering if there is a way to do something similar that would work > cross-platform? > I guess there is much more complexity in it when you start to go across > o/s platform boundaries. The common web interface would then be Gecko or > WebKit? So can someone suggest what would be required to build a > cross-platform Python app that was capable of browsing HTML files, > receiving events from the browser, and that allows the embedded page to > call host Python modules from Javascript via an object reference? Or I am > asking too much :) The only thing that might work is Qt + webkit that is used as it's browser. Everything else is not cross platform. Diez From Krzysztof.Retel at googlemail.com Thu Feb 12 04:23:54 2009 From: Krzysztof.Retel at googlemail.com (Krzysztof Retel) Date: Thu, 12 Feb 2009 01:23:54 -0800 (PST) Subject: ANN: Python 2.6 Quick Reference available References: <4991d7b0$0$4785$426a34cc@news.free.fr> Message-ID: <8200f03c-886b-4520-87d4-6fc66515ad84@m40g2000yqh.googlegroups.com> On Feb 12, 12:54?am, pyt... at bdurham.com wrote: > Richard, > > An excellent tool. Great job!!! > > Thank you for sharing this with the Python community. > > Regards, > Malcolm Many thanks Richard and Josh. I've just started my adventure with Python, and this document will help me a lot. Cheers, K From see.signature at no.spam Thu Feb 12 04:29:44 2009 From: see.signature at no.spam (Eric Brunel) Date: Thu, 12 Feb 2009 10:29:44 +0100 Subject: Thank you, Tkinter. (easy to use) References: Message-ID: On Thu, 12 Feb 2009 06:06:06 +0100, wrote: [snip] > My only (minor) complaint is that Tk > doesn't draw text antialiased in the various widgets (menus, labels, > buttons, etc.). From version 8.5 of tcl/tk, it's supposed to do it. See this page: http://www.tcl.tk/software/tcltk/8.5.tml under 'Highlights of Tk 8.5', item 'Font rendering'. It seems to talk only about X11 and Mac OS X; don't know if it works on Windows... -- python -c "print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])" From robin at reportlab.com Thu Feb 12 05:08:11 2009 From: robin at reportlab.com (Robin Becker) Date: Thu, 12 Feb 2009 10:08:11 +0000 Subject: best way to serve wsgi with multiple processes In-Reply-To: <470f306f-a887-4ee5-952c-d01a66eec411@w39g2000prb.googlegroups.com> References: <2d705579-6c7e-46b1-a9f7-4be4c3af487a@t13g2000yqc.googlegroups.com> <470f306f-a887-4ee5-952c-d01a66eec411@w39g2000prb.googlegroups.com> Message-ID: <4993F50B.6060507@chamonix.reportlab.co.uk> Graham Dumpleton wrote: ......... > requests. > > If the work is indeed long running, the backend process would normally > just acknowledge the request and not wait. The web page would return > and it would be up to user to then somehow occassionally poll web > server, manually or by AJAX, to see how progres is going. That is, > further XML-RPC requests from main server to backend daemon process > asking about progress. ....... this is exactly what we do with the long runners. The wsgi (django in our case) process can work out how long the process is likely to take and either responds directly or offloads the job to an xmrpc server and responds with a page containing a token allowing access to the queue server which refreshes periodically to determine job status etc etc. When the job finishes the refresh request returns the job result and finishes looping. In our case we don't need to worry about people abandoning the job since the results are cached and may be of use to others (typical case produce brochure containing details of all resources in a country or large city). To avoid overload the xmlrpc server is only allowed to run 3 active threads from its queue. -- Robin Becker From anders.mackey at gmail.com Thu Feb 12 05:40:15 2009 From: anders.mackey at gmail.com (Fisherking) Date: Thu, 12 Feb 2009 02:40:15 -0800 (PST) Subject: Match items in large list Message-ID: <6c7720da-9e95-486c-9f28-c85ce3bc9a7e@q9g2000yqc.googlegroups.com> Hi, I hope you can help me with this optimizing problem! I have a large list of dictionaries (about 250 000 of them). Two or more of these dictionaries contains the same data (not more than five or six of them per item) e.g. [{'a':1,'b':'2','c':3} , {'d': 4,'e':'5','f':6},{'a':1,'b':'2','c':3} , {'d':4,'e':'5','f':6},...]. (the dictionaries are really containg phone numbers, duration time and call time.) Which are the best way of searching through the list and extract the items that are the same. In the first run I want to find every item that are the same as {'a':1,'b':'2','c':3}, the second {'d': 4,'e':'5','f':6} etc. The list are not read-only and I can pop them out of the list when I have found them! (How can I found items that are almost the same? e.g. {'a': 1,'b':'2','c':3.1} and {'a':1,'b':'2','c':3.2} ) In the second part of this program I need to take each of these items (similar items are treated as one) and find these in a database that contains 2.5M posts! The python version I am bound to is Python 2.3 thanks for your help! From andrew at acooke.org Thu Feb 12 05:53:47 2009 From: andrew at acooke.org (andrew cooke) Date: Thu, 12 Feb 2009 07:53:47 -0300 (CLST) Subject: Another optimization request :-) In-Reply-To: References: <3f05ec0f12c2042f52618fb0db5bbac4.squirrel@acooke.dyndns.org> Message-ID: <2a92b74f3f992874208a231626423169.squirrel@localhost> jeffg wrote: > To be honest, this is not my code and I'm new to python. It's part of > the open source project NetworkX, but I'm using this one call > extensively. I'm also not that familiar with the math behind the > physics. I'll read the documents and see if I can figure it > out. :-) Thank you for the links and suggestions. I really need to > get this code performing at peak levels. the maths is quite simple really, if you know any physics. it imagines that a spring connects each point, and then works out what the total effect of all the springs is. that gives the net "push" on each point. it then goes through and moves each point a small amount in the direction of the push (there's a "max" that makes no sense physically but probably gives better numeric stability). once they have moved, their positions have changed, so everything needs to be calculated again, hence the iteration. terry's suggestion was that, rather than working particle by particle, if you can generalise the code to use matrices then you can use numpy. that would mean more of the calculation is done using C rather than Python, and so would be a big speed-up. that means that you need to rewrite the program so that you don't have the for-loops in Python (for u.. and for v...). instead you need to call numpy to do array calculations. that is going to give you much more speedup than what i recommended (modifying the integration step at the end). to be honest, although this is not hard if you are used to this kind of thing, if the above isn't obvious it is quite a job. you would probably be better looking for a different library. unfortunately i don't know of one (i looked for exactly this a month or two ago and concluded i would have to write my own; i didn't have time so i used a simpler layout). i'm really busy, or i would do this for you, because it's interesting and useful. but the code you have looks "amateur" - it wasn't written by someone who does numerical work for a living. that doesn't mean it's not correct or that the original author was stupid, but it does mean that to make it efficient means looking at the problem in a different way. there are certainly (very good) java libraries that do this. could you use jpython and call out to one of those? if so, that's probably your best approach. andrew From http Thu Feb 12 06:06:48 2009 From: http (Paul Rubin) Date: 12 Feb 2009 03:06:48 -0800 Subject: Match items in large list References: <6c7720da-9e95-486c-9f28-c85ce3bc9a7e@q9g2000yqc.googlegroups.com> Message-ID: <7xy6wb3odz.fsf@ruckus.brouhaha.com> Fisherking writes: > Which are the best way of searching through the list and extract the > items that are the same. Sort the list, then scan through looking for duplicates, which will be adjacent to each other. From martin at marcher.name Thu Feb 12 06:32:33 2009 From: martin at marcher.name (Martin) Date: Thu, 12 Feb 2009 12:32:33 +0100 Subject: Match items in large list In-Reply-To: <7xy6wb3odz.fsf@ruckus.brouhaha.com> References: <6c7720da-9e95-486c-9f28-c85ce3bc9a7e@q9g2000yqc.googlegroups.com> <7xy6wb3odz.fsf@ruckus.brouhaha.com> Message-ID: <5fa6c12e0902120332h2381ff42t7585f8c3b83ad58e@mail.gmail.com> Hi, 2009/2/12 Paul Rubin : > Fisherking writes: >> Which are the best way of searching through the list and extract the >> items that are the same. hmmm how about using sqlites in memory database and let SQL take care of finding that for you? hth Martin -- http://soup.alt.delete.co.at http://www.xing.com/profile/Martin_Marcher http://www.linkedin.com/in/martinmarcher You are not free to read this message, by doing so, you have violated my licence and are required to urinate publicly. Thank you. Please avoid sending me Word or PowerPoint attachments. See http://www.gnu.org/philosophy/no-word-attachments.html From bruno.42.desthuilliers at websiteburo.invalid Thu Feb 12 06:54:55 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 12 Feb 2009 12:54:55 +0100 Subject: Why does way_1() obtain the correct list but way_2() gets an empty list? In-Reply-To: <6vi779Fk0ogtU1@mid.individual.net> References: <6vi779Fk0ogtU1@mid.individual.net> Message-ID: <49940e09$0$5147$426a34cc@news.free.fr> WP a ?crit : > Hello group! This is probably a silly newbie mistake but consider the > following program: > > import libsbml > > def getSBMLModel(biomodel_path): > reader = libsbml.SBMLReader() > > sbml_doc = reader.readSBML(biomodel_path) > sbml_model = None > > if sbml_doc.getNumErrors() > 0: > print 'I couldn\'t read the file %s!' % biomodel_path This should go to stderr. stdout is for normal program outputs. > return None Also, Python has exception handling, which is usually a better solution than returning None or whatever. > else: since you returned in the other branch, this else is useless > sbml_model = sbml_doc.getModel() > > return sbml_doc.getModel() # None if file couldn't be opened You're calling sbml_doc.getModel() a first time, binding the returned value to name sbml_model, then you're calling it a second time to return it. A first fix: import sys def getSBMLModel(biomodel_path): reader = libsbml.SBMLReader() sbml_doc = reader.readSBML(biomodel_path) if sbml_doc.getNumErrors() > 0: # XXX : there's perhaps a better error message # to get from sbml_doc ? print >> sys.stderr, "I couldn't read the file %s!"\ % biomodel_path return None return sbml_doc.getModel() > > def way_1(biomodel_path): > reader = libsbml.SBMLReader() > sbml_doc = reader.readSBML(biomodel_path) > sbml_model = sbml_doc.getModel() > > if sbml_model == None: Better to use the identity test here - None is garanteed to be a singleton: if sbml_model is None: > return > > l = sbml_model.getListOfSpecies() > print 'In way_1(): Got list %s with the length %i' % (l, len(l)) > > > def way_2(biomodel_path): > sbml_model = getSBMLModel(biomodel_path) > > if sbml_model == None: > return > > l = sbml_model.getListOfSpecies() > print 'In way_2(): Got list %s with the length %i' % (l, len(l)) > > > file = '../BIOMD0000000003.xml' This shadows the builtin 'file' symbol. Better to use another name. > # Changing the order of these two calls doesn't help, only way_1() works. > way_1(file) > way_2(file) > > When run, the output is: > In way_1(): Got list type 'ListOfSpecies *' at 0x291c8bc> > with the length 3 > In way_2(): Got list type 'ListOfSpecies *' at 0x27fb57c> > with the length 0 > > I don't get it way the species list obtained in way_2() is empty? The only explanation I can imagine here would be that a second call to sbml_doc.getModel() doesn't return the same thing as the first... (remember, there are two calls in your getSBMLModel() function). My 2 cents... From steve at holdenweb.com Thu Feb 12 06:56:38 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 12 Feb 2009 06:56:38 -0500 Subject: Functional schmunctional... In-Reply-To: <00a501c98cd9$c8693620$0d00a8c0@hendrik> References: <00a501c98cd9$c8693620$0d00a8c0@hendrik> Message-ID: <49940E76.4030007@holdenweb.com> Hendrik van Rooyen wrote: > "Steve Holden" wrote: > >> Jeez, doesn't anyone read the fine manual any more? I hope this was just >> an academic exercise. >> >>>>> socket.inet_ntoa(struct.pack("!l", 1000000000)) >> '59.154.202.0' >> Holden's rule: when it looks simple enough to be worth including in the >> standard library it may well already *be* in the standard library. > > Aaah! But how do you find it, if you don't already know > where it lives and what it's called ? > Well, my usual answer would be "Ask on c.l.py", but it appears that's no longer reliable. Jeez, doesn't anyone ... (rinse and repeat). regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From __peter__ at web.de Thu Feb 12 07:09:05 2009 From: __peter__ at web.de (Peter Otten) Date: Thu, 12 Feb 2009 13:09:05 +0100 Subject: Match items in large list References: <6c7720da-9e95-486c-9f28-c85ce3bc9a7e@q9g2000yqc.googlegroups.com> Message-ID: Fisherking wrote: > I hope you can help me with this optimizing problem! > I have a large list of dictionaries (about 250 000 of them). Two or > more of these dictionaries contains the same data (not more than five > or six of them per item) e.g. [{'a':1,'b':'2','c':3} , {'d': > 4,'e':'5','f':6},{'a':1,'b':'2','c':3} , {'d':4,'e':'5','f':6},...]. > (the dictionaries are really containg phone numbers, duration time and > call time.) I'd assume the dictionaries to look like {"phone": "0123...", "duration": 5.67, "calltime": "10:42"} What do the different keys ("a", "b", "c") versus ("d", "e", "f") mean? > Which are the best way of searching through the list and extract the > items that are the same. In the first run I want to find every item > that are the same as {'a':1,'b':'2','c':3}, the second {'d': > 4,'e':'5','f':6} etc. The list are not read-only and I can pop them > out of the list when I have found them! items = [dict(a=1, b=2), dict(a=1, b=2), dict(a=3, c=2), dict(a=3, c=2.2), dict(a=3, c=2.6)] # 2.5 seen = set() for row in items: rowkey = frozenset(row.iteritems()) if rowkey in seen: print "dupe", row else: seen.add(rowkey) # 2.3 (and older); not tested seen = {} for row in items: rowkey = row.items() rowkey.sort() rowkey = tuple(rowkey) if rowkey in seen: print "dupe", row else: seen[rowkey] = 1 > (How can I found items that are almost the same? e.g. {'a': > 1,'b':'2','c':3.1} and {'a':1,'b':'2','c':3.2} ) If you are content with detecting similarities on a single "axis": def window(items): items = iter(items) prev = items.next() for cur in items: yield cur, prev prev = cur def todict(k, v, rest): d = dict(rest) d[k] = v return d axis = "c" d = {} eps = 0.5 for row in items: row = dict(row) try: value = row.pop(axis) except KeyError: pass else: key = frozenset(row.iteritems()) d.setdefault(key, []).append(value) for key, values in d.iteritems(): if len(values) > 1: for cur, prev in window(sorted(values)): if abs(cur-prev) < eps: print "similar rows", todict(axis, cur, key), todict(axis, prev, key) Otherwise you have to define a distance function and use a clustering algorithm. Segaran's "Programming Collective Intelligence" has some examples in Python, though the code can hardly be called idiomatic. Peter From notvalid2 at sbcglobal.net Thu Feb 12 07:43:11 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Thu, 12 Feb 2009 04:43:11 -0800 Subject: Untangling pythonWin and IDLE Processes on XP Pro Message-ID: <%OUkl.6905$jZ1.2422@flpi144.ffdc.sbc.com> It appears if one moves between IDLE and pythonWin (pyWin) that two separate loops (threads?) can occur, and that IDLE can produce incorrect results. Since I have preferred IDLE over pyWin, that leaves me currently in a quandry. How do I renew these processes, so that I can proceed with IDLE? I noticed that I had about 10-15 copies of pythonw.exe as I tried to reach some understanding of what was going on. Killing these tasks didn't help restore order to IDLE. It seems my only choice now is to reboot? Comments? -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From deets at nospam.web.de Thu Feb 12 07:47:09 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 12 Feb 2009 13:47:09 +0100 Subject: Library similar to UserAgent (perl) References: <49933ca6$0$1125$4fafbaef@reader1.news.tin.it> Message-ID: <6vik2dFk1ph9U1@mid.uni-berlin.de> mattia wrote: > Hi everybody, I'm looking for an easy way to put data in a form, then > click the button and follow the redirect. Also I need to use cookies. I > read that using perl this can be done using the UserAgent lib, that also > provide th browser functionality to let the site believe that you are > getting the pages from a normali browser like ff. Any suggestion? I think > that the main concen is to easilly put the data in the numerous textlabel > provided and then magically simulate the 'click me' button. Python mechanize. Diez From comp.ogz at gmail.com Thu Feb 12 08:38:03 2009 From: comp.ogz at gmail.com (Oguz Yarimtepe) Date: Thu, 12 Feb 2009 15:38:03 +0200 Subject: xacml api info request Message-ID: <20831c740902120538y2f0896bcw3a73067a0223bd2e@mail.gmail.com> I am looking for how can i use XACML with Python. Anybody who had used xacml with python or and idea? Thanx. -- O?uz Yar?mtepe www.loopbacking.info -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.kaplan at case.edu Thu Feb 12 08:41:53 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 12 Feb 2009 08:41:53 -0500 Subject: cannot install In-Reply-To: <9CB4135F-EACF-4DE5-B2C9-F0C20A3E8D69@volny.cz> References: <46EB146D-6A7F-4457-A35D-CB0C388C19DB@volny.cz> <5929AA4E-C3C7-42FE-93B0-6D1F11932B73@volny.cz> <9B4AFD7B-F159-44C5-95D5-A6FCC04548C7@volny.cz> <9CB4135F-EACF-4DE5-B2C9-F0C20A3E8D69@volny.cz> Message-ID: On Thu, Feb 12, 2009 at 3:41 AM, Vladim?r ?upka wrote: > Here is config.log: > > This file contains any messages produced by compilers while > running configure, to aid debugging if configure makes a mistake. > > It was created by python configure 3.0, which was > generated by GNU Autoconf 2.61. Invocation command line was > > $ ./configure --enable-framework > > ## --------- ## > ## Platform. ## > ## --------- ## > > hostname = Macintosh.local > uname -m = i386 > uname -r = 9.6.0 > uname -s = Darwin > uname -v = Darwin Kernel Version 9.6.0: Mon Nov 24 17:37:00 PST 2008; > root:xnu-1228.9.59~1/RELEASE_I386 > > /usr/bin/uname -p = i386 > /bin/uname -X = unknown > > /bin/arch = unknown > /usr/bin/arch -k = unknown > /usr/convex/getsysinfo = unknown > /usr/bin/hostinfo = Mach kernel version: > Darwin Kernel Version 9.6.0: Mon Nov 24 17:37:00 PST 2008; > root:xnu-1228.9.59~1/RELEASE_I386 > Kernel configured for up to 2 processors. > 2 processors are physically available. > 2 processors are logically available. > Processor type: i486 (Intel 80486) > Processors active: 0 1 > Primary memory available: 4.00 gigabytes > Default processor set: 101 tasks, 414 threads, 2 processors > Load average: 1.02, Mach factor: 0.99 > /bin/machine = unknown > /usr/bin/oslevel = unknown > /bin/universe = unknown > > PATH: /opt/local/bin > PATH: /opt/local/sbin > PATH: /Developer/usr/bin > PATH: /usr/bin > PATH: /bin > PATH: /usr/sbin > PATH: /sbin > PATH: /Users/admin > PATH: /usr/local/bin > PATH: /usr/X11/bin > > > ## ----------- ## > ## Core tests. ## > ## ----------- ## > > configure:1900: checking for --with-universal-archs > configure:1912: result: 32-bit > configure:2033: checking MACHDEP > configure:2197: result: darwin > configure:2208: checking machine type as reported by uname -m > configure:2211: result: i386 > configure:2224: checking for --without-gcc > configure:2250: result: no > configure:2311: checking for gcc > configure:2327: found /Developer/usr/bin/gcc > configure:2338: result: gcc > configure:2576: checking for C compiler version > configure:2583: gcc --version >&5 > i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5490) > Copyright (C) 2005 Free Software Foundation, Inc. > This is free software; see the source for copying conditions. There is NO > warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. > > configure:2586: $? = 0 > configure:2593: gcc -v >&5 > Using built-in specs. > Target: i686-apple-darwin9 > Configured with: /var/tmp/gcc/gcc-5490~1/src/configure --disable-checking > -enable-werror --prefix=/usr --mandir=/share/man > --enable-languages=c,objc,c++,obj-c++ > --program-transform-name=/^[cg][^.-]*$/s/$/-4.0/ > --with-gxx-include-dir=/include/c++/4.0.0 --with-slibdir=/usr/lib > --build=i686-apple-darwin9 --with-arch=apple --with-tune=generic > --host=i686-apple-darwin9 --target=i686-apple-darwin9 > Thread model: posix > gcc version 4.0.1 (Apple Inc. build 5490) > configure:2596: $? = 0 > configure:2603: gcc -V >&5 > gcc-4.0: argument to `-V' is missing > configure:2606: $? = 1 > configure:2629: checking for C compiler default output file name > configure:2656: gcc conftest.c >&5 > ld: library not found for -lcrt1.10.5.o > collect2: ld returned 1 exit status > configure:2659: $? = 1 > configure:2697: result: > configure: failed program was: > | /* confdefs.h. */ > | #define _GNU_SOURCE 1 > | #define _NETBSD_SOURCE 1 > | #define __BSD_VISIBLE 1 > | #define _BSD_TYPES 1 > | #define _DARWIN_C_SOURCE 1 > | /* end confdefs.h. */ > | > | int > | main () > | { > | > | ; > | return 0; > | } > configure:2704: error: C compiler cannot create executables > See `config.log' for more details. > > ## ---------------- ## > ## Cache variables. ## > ## ---------------- ## > > ac_cv_env_CC_set= > ac_cv_env_CC_value= > ac_cv_env_CFLAGS_set= > ac_cv_env_CFLAGS_value= > ac_cv_env_CPPFLAGS_set= > ac_cv_env_CPPFLAGS_value= > ac_cv_env_CPP_set= > ac_cv_env_CPP_value= > ac_cv_env_LDFLAGS_set= > ac_cv_env_LDFLAGS_value= > ac_cv_env_LIBS_set= > ac_cv_env_LIBS_value= > ac_cv_env_build_alias_set= > ac_cv_env_build_alias_value= > ac_cv_env_host_alias_set= > ac_cv_env_host_alias_value= > ac_cv_env_target_alias_set= > ac_cv_env_target_alias_value= > ac_cv_prog_ac_ct_CC=gcc > > ## ----------------- ## > ## Output variables. ## > ## ----------------- ## > > AR='' > ARCH_RUN_32BIT='' > BASECFLAGS='' > BLDLIBRARY='' > BLDSHARED='' > BUILDEXEEXT='' > CC='gcc' > CCSHARED='' > CFLAGS='' > CFLAGSFORSHARED='' > CONFIGURE_MACOSX_DEPLOYMENT_TARGET='' > CONFIG_ARGS=' '\''--enable-framework'\''' > CPP='' > CPPFLAGS='' > CXX='' > DEFS='' > DLINCLDIR='' > DLLLIBRARY='' > DYNLOADFILE='' > ECHO_C='ECHO_N='' > ECHO_T='' > EGREP='' > EXEEXT='' > EXPORT_MACOSX_DEPLOYMENT_TARGET='#' > FRAMEWORKALTINSTALLFIRST='frameworkinstallstructure bininstall maninstall' > FRAMEWORKALTINSTALLLAST='frameworkinstallmaclib frameworkinstallapps > frameworkaltinstallunixtools' > FRAMEWORKINSTALLFIRST='frameworkinstallstructure' > FRAMEWORKINSTALLLAST='' > FRAMEWORKUNIXTOOLSPREFIX='/usr/local' > GREP='' > HAVE_GETHOSTBYNAME='' > HAVE_GETHOSTBYNAME_R='' > HAVE_GETHOSTBYNAME_R_3_ARG='' > HAVE_GETHOSTBYNAME_R_5_ARG='' > HAVE_GETHOSTBYNAME_R_6_ARG='' > INSTALL_DATA='' > INSTALL_PROGRAM='' > INSTALL_SCRIPT='' > INSTSONAME='' > LDFLAGS='' > LDLAST='' > LDLIBRARY='' > LDLIBRARYDIR='' > LDSHARED='' > LIBC='' > LIBM='' > LIBOBJS='' > LIBRARY='' > LIBS='' > LIBTOOL_CRUFT='' > LINKCC='' > LINKFORSHARED='' > LN='' > LTLIBOBJS='' > MACHDEP='darwin' > MACHDEP_OBJS='' > MAINCC='' > OBJEXT='' > OPT='' > OTHER_LIBTOOL_OPT='' > PACKAGE_BUGREPORT='http://www.python.org/python-bugs' > PACKAGE_NAME='python' > PACKAGE_STRING='python 3.0' > PACKAGE_TARNAME='python' > PACKAGE_VERSION='3.0' > PATH_SEPARATOR=':' > PYTHONFRAMEWORK='Python' > PYTHONFRAMEWORKDIR='Python.framework' > PYTHONFRAMEWORKIDENTIFIER='org.python.python' > PYTHONFRAMEWORKINSTALLDIR='/Library/Frameworks/Python.framework' > PYTHONFRAMEWORKPREFIX='/Library/Frameworks' > RANLIB='' > RUNSHARED='' > SGI_ABI='' > SHELL='/bin/sh' > SHLIBS='' > SIGNAL_OBJS='' > SO='' > SOVERSION='1.0' > SRCDIRS='' > SVNVERSION='' > THREADHEADERS='' > THREADOBJ='' > TRUE='' > UNIVERSALSDK='' > UNIVERSAL_ARCH_FLAGS='' > USE_SIGNAL_MODULE='' > USE_THREAD_MODULE='' > VERSION='3.0' > ac_ct_CC='gcc' > bindir='${exec_prefix}/bin' > build_alias='' > datadir='${datarootdir}' > datarootdir='${prefix}/share' > docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' > dvidir='${docdir}' > exec_prefix='NONE' > host_alias='' > htmldir='${docdir}' > includedir='${prefix}/include' > infodir='${datarootdir}/info' > libdir='${exec_prefix}/lib' > libexecdir='${exec_prefix}/libexec' > localedir='${datarootdir}/locale' > localstatedir='${prefix}/var' > mandir='${datarootdir}/man' > oldincludedir='/usr/include' > pdfdir='${docdir}' > prefix='/Library/Frameworks/Python.framework/Versions/3.0' > program_transform_name='s,x,x,' > psdir='${docdir}' > sbindir='${exec_prefix}/sbin' > sharedstatedir='${prefix}/com' > sysconfdir='${prefix}/etc' > target_alias='' > > ## ----------- ## > ## confdefs.h. ## > ## ----------- ## > > #define _GNU_SOURCE 1 > #define _NETBSD_SOURCE 1 > #define __BSD_VISIBLE 1 > #define _BSD_TYPES 1 > #define _DARWIN_C_SOURCE 1 > > configure: exit 77 > > On 11.2.2009, at 14:23, Benjamin Kaplan wrote: > > > > 2009/2/11 administrator > >> I tried as admin with Python-3.0 in my home directory but no success yet. >> Is there another help? >> >> Macintosh:~ admin$ export >> PATH=/opt/local/bin:/opt/local/sbin:/Developer/usr/bin:$PATH >> Macintosh:~ admin$ echo $PATH >> >> /opt/local/bin:/opt/local/sbin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/admin:/usr/local/bin:/usr/X11/bin >> Macintosh:~ admin$ cd ~/Python-3.0 >> Macintosh:Python-3.0 admin$ pwd >> /Users/admin/Python-3.0 >> Macintosh:Python-3.0 admin$ sudo ./configure --enable-framework >> checking for --with-universal-archs... 32-bit >> checking MACHDEP... darwin >> checking machine type as reported by uname -m... i386 >> checking for --without-gcc... no >> checking for gcc... gcc >> checking for C compiler default output file name... >> *configure: error: C compiler cannot create executables* >> See `config.log' for more details. >> Macintosh:Python-3.0 admin$ >> > > > > What does config.log say? > > >> >> Hmm. Not much useful there. Do you have XCode installed? Maybe someone else has seen this before and can help. -------------- next part -------------- An HTML attachment was scrubbed... URL: From james at agentultra.com Thu Feb 12 09:06:00 2009 From: james at agentultra.com (J Kenneth King) Date: Thu, 12 Feb 2009 09:06:00 -0500 Subject: [ANN] TracShell 0.1 released Message-ID: <85ab8rkawn.fsf@agentultra.com> I tend to work a lot with Trac for project management and have always found the browser interface to be a productivity killer. I always wanted a simple command-line interface to Trac, but having never found one I found a little free time and got off my laurels to make one. TracShell 0.1 is an early release, but it works. So far you can only query and view tickets, but planned updates include the obvious ability to create and edit tickets. Future plans will allow browsing of comments, change histories, attachments, and so forth. Please consider it really beta. The code needs a little tidying up around the edges. If you find any bugs, please report them and I'll fix them ASAP. Ideas, suggestions, and contributions are welcome. http://code.google.com/p/tracshell/ Cheers. From deets at nospam.web.de Thu Feb 12 09:07:43 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 12 Feb 2009 15:07:43 +0100 Subject: Untangling pythonWin and IDLE Processes on XP Pro References: <%OUkl.6905$jZ1.2422@flpi144.ffdc.sbc.com> Message-ID: <6viopfFkcasmU1@mid.uni-berlin.de> W. eWatson wrote: > It appears if one moves between IDLE and pythonWin (pyWin) that two > separate loops (threads?) can occur, and that IDLE can produce incorrect > results. Since I have preferred IDLE over pyWin, that leaves me currently > in a quandry. How do I renew these processes, so that I can proceed with > IDLE? > I noticed that I had about 10-15 copies of pythonw.exe as I tried to reach > some understanding of what was going on. Killing these tasks didn't help > restore order to IDLE. It seems my only choice now is to reboot? Comments? Gosh no, rebooting shouldn't be needed. Just quit all idle & pywin processes, including of course the main programs. Which *should* be anything that is needed anyway. And you still seem to not understand what is really happening. Working between pywin and idle is perfectly fine, they are separate programs. You can start as many instances of a program as you want and happily work with them. Even several instances of idle and pywin, unless these come with some logic to prevent multiple starts - some windows app do that. What does *NOT* work is writing a Tkinter-based app in idle, and to run it *FROM INSIDE* idle. Instead, open your explorer and double-click on the pyhton-file your app is in. That's all that there is to it. Diez From gideon.smeding at gmail.com Thu Feb 12 09:08:51 2009 From: gideon.smeding at gmail.com (gideon) Date: Thu, 12 Feb 2009 06:08:51 -0800 (PST) Subject: An executable operational semantics for Python Message-ID: <01cf8180-87e2-472a-9891-eb687fdd5e6c@j8g2000yql.googlegroups.com> Hi everybody, I've recently finished my Master's thesis on the semantics of Python. In my thesis I define the semantics of Python by rewriting an abstract machine. The sources that are used to produce my thesis can also be compiled into a working interpreter. Hence I call it an 'executable' semantics. Anyone interested should have a look at the short intro I put on my web page: http://gideon.smdng.nl/2009/01/an-executable-operational-semantics-for-python/ From Krzysztof.Retel at googlemail.com Thu Feb 12 09:53:49 2009 From: Krzysztof.Retel at googlemail.com (Krzysztof Retel) Date: Thu, 12 Feb 2009 06:53:49 -0800 (PST) Subject: TracShell 0.1 released References: <85ab8rkawn.fsf@agentultra.com> Message-ID: On 12 Feb, 14:06, J Kenneth King wrote: > I tend to work a lot with Trac for project management and have always > found the browser interface to be a productivity killer. I always > wanted a simple command-line interface to Trac, but having never found > one I found a little free time and got off my laurels to make one. > > TracShell 0.1 is an early release, but it works. So far you can only > query and view tickets, but planned updates include the obvious > ability to create and edit tickets. Future plans will allow browsing > of comments, change histories, attachments, and so forth. > > Please consider it really beta. The code needs a little tidying up > around the edges. If you find any bugs, please report them and I'll > fix them ASAP. Ideas, suggestions, and contributions are welcome. > > http://code.google.com/p/tracshell/ > > Cheers. Nice work. Maybe it would be worth building at some point vim or emacs interface. Krzysztof From notvalid2 at sbcglobal.net Thu Feb 12 09:57:38 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Thu, 12 Feb 2009 06:57:38 -0800 Subject: Untangling pythonWin and IDLE Processes on XP Pro In-Reply-To: <6viopfFkcasmU1@mid.uni-berlin.de> References: <%OUkl.6905$jZ1.2422@flpi144.ffdc.sbc.com> <6viopfFkcasmU1@mid.uni-berlin.de> Message-ID: <2NWkl.16040$YU2.9824@nlpi066.nbdc.sbc.com> Diez B. Roggisch wrote: > W. eWatson wrote: > >> It appears if one moves between IDLE and pythonWin (pyWin) that two >> separate loops (threads?) can occur, and that IDLE can produce incorrect >> results. Since I have preferred IDLE over pyWin, that leaves me currently >> in a quandry. How do I renew these processes, so that I can proceed with >> IDLE? > >> I noticed that I had about 10-15 copies of pythonw.exe as I tried to reach >> some understanding of what was going on. Killing these tasks didn't help >> restore order to IDLE. It seems my only choice now is to reboot? Comments? > > Gosh no, rebooting shouldn't be needed. Just quit all idle & pywin > processes, including of course the main programs. Which *should* be > anything that is needed anyway. Done that. Been there. It doesn't work. If I take another py tkinter program and run it in IDLE, it *will work*. The current program goes boom. > > And you still seem to not understand what is really happening. Whether I understand it exactly or not is not the issue. The issue is how do I execute IDLE *now* to get the correct results it once allowed? The fact of the matter is that I was happily working in IDLE for days and hours. I encountered a problem in IDLE that seemed suspicious, so I then fired up pyWin to see if it gave the same results. It worked fine. Then my problems with IDLE got worse. > > Working between pywin and idle is perfectly fine, they are separate > programs. You can start as many instances of a program as you want and > happily work with them. Even several instances of idle and pywin, unless > these come with some logic to prevent multiple starts - some windows app > do that. How could this be true; otherwise, I wouldn't be complaining? > > What does *NOT* work is writing a Tkinter-based app in idle, and to run it > *FROM INSIDE* idle. Instead, open your explorer and double-click on the > pyhton-file your app is in. That's all that there is to it. Personally, I like running entirely in IDLE. If there is no other way than you suggested in "NOT work", then I may just uninstall pyWin. > > Diez -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From btaylordesign at gmail.com Thu Feb 12 10:13:58 2009 From: btaylordesign at gmail.com (Brandon Taylor) Date: Thu, 12 Feb 2009 07:13:58 -0800 (PST) Subject: cx_Oracle-5.0 Problem Message-ID: <7fa4a7be-b4ca-4327-9c41-7e35ee2c41ae@x9g2000yqk.googlegroups.com> Hello everyone, I'm Brandon Taylor, senior web developer with the University of Texas at Austin. We're using Python 2.6.1 and having a lot of difficulty getting the cx_Oracle-5.0 library to install on one of our MacBooks running OS X 10.5.6. We can get cx_Oracle to compile, but after running setup.py install and trying to import the library, we are getting an error: Traceback (most recent call last): File "", line 1, in ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.6/ lib/python2.6/site-packages/cx_Oracle.so, 2): Symbol not found: ___divdi3 Referenced from: /Users/mas80/Library/Oracle/instantclient_10_2/ libclntsh.dylib.10.1 Expected in: flat namespace Can anyone shed some light on how we can solve this issue? It's a show stopper for us of we can not connect to Oracle from Python. Kind regards, Brandon Taylor From dear.jay.logan at gmail.com Thu Feb 12 10:15:29 2009 From: dear.jay.logan at gmail.com (josh logan) Date: Thu, 12 Feb 2009 07:15:29 -0800 (PST) Subject: how can this iterator be optimized? References: <727aabd1-9682-47aa-88e2-5dde96e4c32e@j1g2000yqi.googlegroups.com> Message-ID: On Feb 11, 8:22?pm, Basilisk96 wrote: > Hello all, > > I have the following function that uses an intermediate iterator > "rawPairs": > > def MakePairs(path): > ? ? import os > ? ? import operator > ? ? join = os.path.join > ? ? rawPairs = ( > ? ? ? ? (join(path, s), func(s)) > ? ? ? ? for s in os.listdir(path) > ? ? ? ? if func(s) is not None and func(s).endswith("some criterion") > ? ? ) > ? ? #Use the second item in the pair as the sort criterion > ? ? result = sorted(rawPairs, key=operator.itemgetter(1)) > ? ? return result > > where "func" is a single-argument function that returns either a > string or None, but is an expensive call. > I am pretty sure that the sorted() construct cannot be improved much > further, but... > ...does anyone have ideas on improving the "rawPairs" iterator so that > it calls "func(s)" only once per iteration? ?Perhaps a lambda > construct, but I am not sure how to go about it...? > > Cheers, > Basilisk96 Hi, Try something like this: import os from os.path import join from itertools import ifilter #assuming 2.5 and earlier, for 3.0 just use the filter builtin from operator import itemgetter def isvalid(pair): return (s[1] is not None) and s[1].endswith('some criteria') def makepairs(path): pair_iter = ((join(path,s), func(s)) for s in os.listdir(path)) pair_iter = ifilter(isvalid, pair_iter) result = sorted(pair_iter, key=itemgetter(1)) return result From james at agentultra.com Thu Feb 12 10:26:13 2009 From: james at agentultra.com (J Kenneth King) Date: Thu, 12 Feb 2009 10:26:13 -0500 Subject: TracShell 0.1 released References: <85ab8rkawn.fsf@agentultra.com> Message-ID: <8563jfk76y.fsf@agentultra.com> Krzysztof Retel writes: > On 12 Feb, 14:06, J Kenneth King wrote: >> I tend to work a lot with Trac for project management and have always >> found the browser interface to be a productivity killer. I always >> wanted a simple command-line interface to Trac, but having never found >> one I found a little free time and got off my laurels to make one. >> >> TracShell 0.1 is an early release, but it works. So far you can only >> query and view tickets, but planned updates include the obvious >> ability to create and edit tickets. Future plans will allow browsing >> of comments, change histories, attachments, and so forth. >> >> Please consider it really beta. The code needs a little tidying up >> around the edges. If you find any bugs, please report them and I'll >> fix them ASAP. Ideas, suggestions, and contributions are welcome. >> >> http://code.google.com/p/tracshell/ >> >> Cheers. > > Nice work. > > Maybe it would be worth building at some point vim or emacs interface. > > Krzysztof Thanks. :) I considered a native editor interface, but since both vi and emacs can run a shell within a buffer, I decided to go with a more flexible solution. However, if someone wanted to, the actual code fetching and displaying the data isn't tied directly to the shell interface. It could be possible to dispatch calls from a native editor front-end if it doesn't mind spawning a python interpreter (or keeping one running) for each request. Anyway, thanks for checking it out. Hope you find it useful. I do. :) From ivanov.maxim at gmail.com Thu Feb 12 10:27:44 2009 From: ivanov.maxim at gmail.com (redbaron) Date: Thu, 12 Feb 2009 07:27:44 -0800 (PST) Subject: Could you recommend job schedulling solution? References: Message-ID: <33403be1-8a8a-4e28-9d0e-12fbfd4b7510@j39g2000yqn.googlegroups.com> > > I think parallel python will take of that for you > (http://www.parallelpython.com/) I've found that RPyC (http://rpyc.wikidot.com/) is quite usefull for my task. It allows me to build RPC service which accepts ordinary python function from client and return result in synchronous or asynchronous way. Of course it is able to serve multiple clients and it's forking server help me to solve GIL problems on intense calculations inside Python code. Some limitations are present, like the fact that you couldn't send on execution any code which use C extensions which are not present on RPC server, but I didn't expect this could work at all, so in general RPyC makes me happy. From xahlee at gmail.com Thu Feb 12 10:30:26 2009 From: xahlee at gmail.com (Xah Lee) Date: Thu, 12 Feb 2009 07:30:26 -0800 (PST) Subject: some history of computing and celebrities [was lisp machine keyboards] References: <1935645c-5b26-4287-b492-cdb2834aa4c9@b38g2000prf.googlegroups.com> Message-ID: <70d7a15d-6c9d-4145-b718-1e83cbac510e@40g2000prx.googlegroups.com> On Feb 12, 7:28?am, Xah Lee wrote: > lisp machine keyboards. > > ? Knite keyboard. I think this is one of the earlist.http://world.std.com/~jdostale/kbd/Knight.html > > ? Symbolics earlier style keyboard (PN 364000), by Peter Painehttp://www.asl.dsl.pipex.com/symbolics/photos/IO/kbd-older.html > > Symbolics later model Symbolics keyboard PN 365407 Rev C > at Joey Devilla's blog, several hi quality photoshttp://www.globalnerdy.com/2009/02/05/hacklabtos-lisp-machine-keyboard/ > > also at Rainer site, with info on how to use it on mac os xhttp://lispm.dyndns.org/news?ID=NEWS-2008-07-27-1 > > one of the most funny comment from Joey's blog is: > ?Man, my pinkies are getting tired just looking at that thing.? > > of course, the most baroque, showy, with a fancy name is the > Space-cadet keyboard > ?http://xahlee.org/emacs/emacs_kb_shortcuts_pain.html > > Space-cadet! LOL. > > btw, how did that name came to be? > > ? Xah > ?http://xahlee.org/ > > ? while nosing about lisp machines, i checked out the Wikipedia article on Symbolics again: http://en.wikipedia.org/wiki/Symbolics it's content has improved significantly since last year or so i checked. My firts daily use of computer or owning one is ~1991, and didn't really become pro after 1995. So, lisp machines are before my time. Though, i have already had some interest in lisp history and have strong interest in the the history of how the motherfucking unix tookover its/lisp/vms/whatnot war. Reading such history is usually not easy, because you are bombarded with many OSes or technologies that you are not familiar and really difficult to understand its situation without having lived in the tech of that era... anyhow, check out some of the interesting tidbits in the article: ?Symbolics staffers Dan Weinreb, David Moon, Neal Feinberg, Kent Pitman, Scott McKay, Sonya Keene and others made significant contributions to the emerging Common Lisp language standard from the mid-1980s through the release of the ANSI Common Lisp standard in 1994? There, Dan Weinred, Kent Pitman, 2 guy who still write here sometimes, are mentioned. (Kent i knew as a online acquaintance since ~2000 here. Dan i knew only last year.) Also note how Richard Stallman, who the open sourcing or FSF fuckheads take to be a god unquestioned, who was at the time simply doing questionable deeds. (note that in general, history doesn't have a right and wrong. How came out as winner, is the hero.) Given the Symbolic vs MIT/RMS situation, one can question what is the interpersonal relation or formal relation between these people with RMS. (in general, often many historical issue or truth cannot be discussed when the persons are still alive, for many real life complexities.) Also of interest is tat Scott McKay, the Sun Micro guy, is there too... O, a wee bit of rambling. ?Advances in garbage collection techniques by Henry Baker, David Moon and others, particularly the first commercial use of generational scavenging, allowed Symbolics computers to run large Lisp programs for months at a time.? interesting to me is seeing the name Henry Baker. He has wrote a few articles i've came cross in the past and enjoyed. ? ?Buffer Overflow? Security Problems, (2001), by Henry G Baker http://catless.ncl.ac.uk/Risks/21.84.html#subj10.1 ? Communications of the ACM 34, 4 (April 1991), 18. Henry G Baker, 1990. (On the harm of speed) http://home.pipeline.com/~hbaker1/letters/CACM-DubiousAchievement.html ? ?Iterators: Signs of Weakness in Object-Oriented Languages? (1992) By Henry G Baker. http://home.pipeline.com/~hbaker1/Iterator.html I'm posting this to python group too, for the last article above about iterators. I whole heartedly agree to all Henry's opinions... often today's hotshot programing morons have no understanding fuck. Python 3 is going full with iterators and enumerators fuck. i'd link to few articles i wrote pertinent to some of the above issues... but think rather not, since i've already done that often. Xah ? http://xahlee.org/ ? From ivanov.maxim at gmail.com Thu Feb 12 10:31:57 2009 From: ivanov.maxim at gmail.com (redbaron) Date: Thu, 12 Feb 2009 07:31:57 -0800 (PST) Subject: cx_Oracle-5.0 Problem References: <7fa4a7be-b4ca-4327-9c41-7e35ee2c41ae@x9g2000yqk.googlegroups.com> Message-ID: <68b98811-6352-4b84-952a-c5e0209e8bd3@x9g2000yqk.googlegroups.com> > ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.6/ > lib/python2.6/site-packages/cx_Oracle.so, 2): Symbol not found: > ___divdi3 You didn't link cx_Oracle.so all libs which it use. run "ldd -r cx_Oracle.so" and you'll have an idea about all missing symbols. The names of missed symbols could give you an idea what else should cx_Oracle.so should be linked with From GDoermann at gmail.com Thu Feb 12 10:44:57 2009 From: GDoermann at gmail.com (TechieInsights) Date: Thu, 12 Feb 2009 07:44:57 -0800 (PST) Subject: Read Only attributes, auto properties and getters and setters Message-ID: <8090b400-dde2-4fc2-8d73-6d1bad3b5aeb@z6g2000pre.googlegroups.com> Ok, so I noticed some of the modules (such as many of the datetime attributes) are read-only, which means the __setattr__ and __set__ methods are intercepted... pretty easy. I am looking for a way to automate this. The real goal is not to have read only attributes, but to have getters and setters that are automatically called when a property is called. The getting is pretty easily achieved by setting the metaclass which also creates the properties. What I have so far will protect the get_ and set_ methods as well as the properties that call the get methods. The reasoning for this is that I don't want someone accidentally overwriting the property when the class uses a private class variable. What I have so far: class ReadOnlyMeta(type): def __new__(cls, name, bases, methoddict): pname = '_%s__protected_items' %(name) protected = [pname] methoddict[pname] = protected for key, value in methoddict.items(): if key.startswith("get_"): methoddict[key[4:]] = property(value) protected.append(key[4:]) protected.append(key) elif key.startswith("set_"): protected.append(key) return type.__new__(cls, name, bases, methoddict) class ReadOnly(object): __metaclass__ = ReadOnlyMeta def __check_private(self, name, msg = None): if name in self.__protected_items: if msg is None: msg = "'%s' of '%s' is Read only." %(name, self.__class__.__name__) raise AttributeError(msg) def __setattr__(self, name, value): self.__check_private(name, "attribute '%s' of '%s' objects is not writable" %(name, self.__class__.__name__)) self.__dict__[name] = value def __delattr__(self, name): self.__check_private(name, "attribute '%s' of '%s' objects cannot be removed" %(name, self.__class__.__name__)) self.__dict__.pop(name) def __set__(self, instance, value): self.__check_private(instance, "You cannot remap the method '%s'" % (instance)) self.__dict__[instance] = value I then implement this by creating a subclass of the read only class: class MyClass(ReadOnly): def __init__(self, x): self.set_x(x) def get_x(self): return self.__x def set_x(self, x): print 'Hello the setter was called!' self.__x = x What I want is to be able to auto-call the set_ methods whenever someone tries to call a method that has a setter. This could be done by each class... tedious! I want automation! To do this I have tried adding a list of setters to the metaclass and then in the __set__ and __setattr__ methods I check to see if 'set_%s' %(variable) exists in the list... if it does I call the method. This would work, however there are two lists of setters (in the example above), the ReadOnly list and a MyClass list. When you print out a dir(self) IN the ReadOnly class from an implementation (MyClass) it will show the MyClass attributes, however they cannot be called from the parent class... so my real question... how can you (or can you ever) call a child method from a parent class without explicitly passing the callable? I hope this hasn't been too confusing... or made your head hurt like mine does... If you want more code examples of what I have tried and the out put... I'd be happy to give them. Greg From deets at nospam.web.de Thu Feb 12 10:55:55 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 12 Feb 2009 16:55:55 +0100 Subject: Untangling pythonWin and IDLE Processes on XP Pro References: <%OUkl.6905$jZ1.2422@flpi144.ffdc.sbc.com> <6viopfFkcasmU1@mid.uni-berlin.de> <2NWkl.16040$YU2.9824@nlpi066.nbdc.sbc.com> Message-ID: <6viv4bFk8gonU1@mid.uni-berlin.de> > Done that. Been there. It doesn't work. If I take another py tkinter > program and run it in IDLE, it *will work*. The current program goes boom. That's pure luck then. IDLE is written in Tkinter, and *running* Tkinter apps inside of it is bound to fail sooner or later. Failure might be as drastic as termination of IDLE, or just some glitches. This has hit numerous people before, as you've been told several times now. What makes you think it doesn't affect you? >> >> And you still seem to not understand what is really happening. > Whether I understand it exactly or not is not the issue. The issue is how > do I execute IDLE *now* to get the correct results it once allowed? The > fact of the matter is that I was happily working in IDLE for days and > hours. I encountered a problem in IDLE that seemed suspicious, so I then > fired up pyWin to see if it gave the same results. It worked fine. Then my > problems with IDLE got worse. >> >> Working between pywin and idle is perfectly fine, they are separate >> programs. You can start as many instances of a program as you want and >> happily work with them. Even several instances of idle and pywin, unless >> these come with some logic to prevent multiple starts - some windows app >> do that. > How could this be true; otherwise, I wouldn't be complaining? Coincidence? When Mom tells me the car broke down after she passed by the bakery, I don't assume one has to do with the other either. >> What does *NOT* work is writing a Tkinter-based app in idle, and to run >> it *FROM INSIDE* idle. Instead, open your explorer and double-click on >> the pyhton-file your app is in. That's all that there is to it. > Personally, I like running entirely in IDLE. This is not a question of your liking, it's a question of technical feasibility. if you have been working happily for hours and days as you tell us, I can only hope & assume that you made actual progress. Which might have brought your own program to a point where it wasn't tolerable working from within idle anymore. That you in the meanttime chose to work with Pywin is irrelevant to that. > If there is no other way than you suggested in "NOT work", then I may just > uninstall pyWin. Do so if you like - cargo cult programming isn't uncommon these days. Diez From GDoermann at gmail.com Thu Feb 12 10:58:32 2009 From: GDoermann at gmail.com (TechieInsights) Date: Thu, 12 Feb 2009 07:58:32 -0800 (PST) Subject: Read Only attributes, auto properties and getters and setters References: <8090b400-dde2-4fc2-8d73-6d1bad3b5aeb@z6g2000pre.googlegroups.com> Message-ID: <61e02f4c-6006-4051-9ad4-9de11bceacea@o6g2000pre.googlegroups.com> Oh... one other thing that would be really cool is to do this with AOP/ descriptors! I just haven't been able to get that to work either. Basics... @readonly class MyClass(object): def __init__(self, x): self.set_x(x) def get_x(self): return self.__x def set_x(self, x): print 'Hello the setter was called!' self.__x = x and it's done! I don't think this will work because (maybe I'm wrong) but I don't think you can set the metaclass in the descriptor??? If this is the case, it is more work to do the AOP and set a metaclass... better to just inherit. If it can be done... that would be awesome! Greg From catherine.heathcote at gmail.com Thu Feb 12 11:03:05 2009 From: catherine.heathcote at gmail.com (Catherine Heathcote) Date: Thu, 12 Feb 2009 16:03:05 GMT Subject: Embarrasing questio Message-ID: But I just cant find it. How do I do an or, as in c/c++'s ||? Just trying to do something simple, the python equivilent of: if(i % 3 == 0 || i % 5 == 0) Thanks. From GDoermann at gmail.com Thu Feb 12 11:07:13 2009 From: GDoermann at gmail.com (TechieInsights) Date: Thu, 12 Feb 2009 08:07:13 -0800 (PST) Subject: Embarrasing questio References: Message-ID: <6296e1bc-d572-4cd9-bbe1-5784d01d0a73@f40g2000pri.googlegroups.com> On Feb 12, 9:03?am, Catherine Heathcote wrote: > But I just cant find it. How do I do an or, as in c/c++'s ||? Just > trying to do something simple, the python equivilent of: > > if(i % 3 == 0 || i % 5 == 0) > > Thanks. if i % 3 == 0 or i % 5 == 0 From GDoermann at gmail.com Thu Feb 12 11:07:48 2009 From: GDoermann at gmail.com (TechieInsights) Date: Thu, 12 Feb 2009 08:07:48 -0800 (PST) Subject: Embarrasing questio References: Message-ID: <2dd78188-434d-4c24-bd73-2047105c6a89@q30g2000prq.googlegroups.com> On Feb 12, 9:03?am, Catherine Heathcote wrote: > But I just cant find it. How do I do an or, as in c/c++'s ||? Just > trying to do something simple, the python equivilent of: > > if(i % 3 == 0 || i % 5 == 0) > > Thanks. in 2.5 and above you can do if any(i%3 == 0, i%5 == 0) From aahz at pythoncraft.com Thu Feb 12 11:11:51 2009 From: aahz at pythoncraft.com (Aahz) Date: 12 Feb 2009 08:11:51 -0800 Subject: Embarrasing questio References: Message-ID: In article , Catherine Heathcote wrote: > >But I just cant find it. How do I do an or, as in c/c++'s ||? Just >trying to do something simple, the python equivilent of: > >if(i % 3 == 0 || i % 5 == 0) if i % 3 == 0 or i % 5 == 0: You may find it worthwhile to quickly step through everything in the standard Python tutorial, it covers lots of stuff like this. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From catherine.heathcote at gmail.com Thu Feb 12 11:12:03 2009 From: catherine.heathcote at gmail.com (Catherine Heathcote) Date: Thu, 12 Feb 2009 16:12:03 GMT Subject: Embarrasing questio In-Reply-To: <6296e1bc-d572-4cd9-bbe1-5784d01d0a73@f40g2000pri.googlegroups.com> References: <6296e1bc-d572-4cd9-bbe1-5784d01d0a73@f40g2000pri.googlegroups.com> Message-ID: TechieInsights wrote: > On Feb 12, 9:03 am, Catherine Heathcote > wrote: >> But I just cant find it. How do I do an or, as in c/c++'s ||? Just >> trying to do something simple, the python equivilent of: >> >> if(i % 3 == 0 || i % 5 == 0) >> >> Thanks. > > if i % 3 == 0 or i % 5 == 0 > Yea, new it would be embarrasing, thanks! From google at mrabarnett.plus.com Thu Feb 12 11:12:11 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 12 Feb 2009 16:12:11 +0000 Subject: Breaking Python list into set-length list of lists In-Reply-To: <4cf62c27-ce57-4101-83a8-34285db537ff@a12g2000yqm.googlegroups.com> References: <8158439d-faae-4889-a1cf-8d9fee112e9b@v39g2000yqm.googlegroups.com> <4cf62c27-ce57-4101-83a8-34285db537ff@a12g2000yqm.googlegroups.com> Message-ID: <49944A5B.8070307@mrabarnett.plus.com> Mensanator wrote: > On Feb 11, 10:58?pm, Jason wrote: >> Hey everyone-- >> >> I'm pretty new to Python, & I need to do something that's incredibly >> simple, but combing my Python Cookbook & googling hasn't helped me out >> too much yet, and my brain is very, very tired & flaccid @ the >> moment.... >> >> I have a list of objects, simply called "list". ?I need to break it >> into an array (list of lists) wherein each sublist is the length of >> the variable "items_per_page". ?So array[0] would go from array[0][0] >> to array[0][items_per_page], then bump up to array[1][0] - array[1] >> [items_per_page], until all the items in the original list were >> accounted for. >> >> What would be the simplest way to do this in Python? ?And yes, I >> realize I should probably be taking Programming 101..... > >>>> items_per_page = 20 >>>> x = range(113) >>>> layout = divmod(113,20) >>>> if layout[1]>0: > pages = layout[0]+1 > else: > pages = layout[0] >>>> array = [ x[i*items_per_page:i*items_per_page+items_per_page] for i in xrange(pages)] >>>> array > [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, > 19], [20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, > 36, 37, 38, 39], [40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, > 53, 54, 55, 56, 57, 58, 59], [60, 61, 62, 63, 64, 65, 66, 67, 68, 69, > 70, 71, 72, 73, 74, 75, 76, 77, 78, 79], [80, 81, 82, 83, 84, 85, 86, > 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99], [100, 101, 102, > 103, 104, 105, 106, 107, 108, 109, 110, 111, 112]] > Using list comprehension: >>> my_list = range(113) >>> items_per_page = 20 >>> >>> array = [my_list[start : start + items_per_page] for start in range(0, len(my_list), items_per_page)] >>> >>> array [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39], [40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59], [60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79], [80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99], [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112]] >>> From bearophileHUGS at lycos.com Thu Feb 12 11:14:22 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Thu, 12 Feb 2009 08:14:22 -0800 (PST) Subject: An executable operational semantics for Python References: <01cf8180-87e2-472a-9891-eb687fdd5e6c@j8g2000yql.googlegroups.com> Message-ID: gideon: > I've recently finished my Master's thesis on the semantics of Python. > In my thesis I define the semantics of Python by rewriting an abstract > machine. The sources that are used to produce my thesis can also be > compiled into a working interpreter. Hence I call it an 'executable' > semantics. Can it be used for some useful purpose? Bye, bearophile From bearophileHUGS at lycos.com Thu Feb 12 11:16:42 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Thu, 12 Feb 2009 08:16:42 -0800 (PST) Subject: Another optimization request :-) References: Message-ID: <080baa3d-0bbf-4d46-8142-5401ec206395@l16g2000yqo.googlegroups.com> On Feb 12, 2:48?am, jeffg wrote: > If anyone wants to take this on... I would really really like to have > the spring_layout modified to support multi-threading if at all > possible. You can start creating a compiled Python extension using ShedSkin, it may be enough. Bye, bearophile From michele.simionato at gmail.com Thu Feb 12 11:19:39 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Thu, 12 Feb 2009 08:19:39 -0800 (PST) Subject: Embarrasing questio References: <2dd78188-434d-4c24-bd73-2047105c6a89@q30g2000prq.googlegroups.com> Message-ID: On Feb 12, 5:07?pm, TechieInsights wrote: > On Feb 12, 9:03?am, Catherine Heathcote > > wrote: > > But I just cant find it. How do I do an or, as in c/c++'s ||? Just > > trying to do something simple, the python equivilent of: > > > if(i % 3 == 0 || i % 5 == 0) > > > Thanks. > > in 2.5 and above you can do > if any(i%3 == 0, i%5 == 0) You are missing a few parenthesis: if any([i%3 == 0, i%5 == 0]) (but the idiomatic solution is to use or). From catherine.heathcote at gmail.com Thu Feb 12 11:20:03 2009 From: catherine.heathcote at gmail.com (Catherine Heathcote) Date: Thu, 12 Feb 2009 16:20:03 GMT Subject: Embarrasing questio In-Reply-To: References: Message-ID: Aahz wrote: > In article , > Catherine Heathcote wrote: >> But I just cant find it. How do I do an or, as in c/c++'s ||? Just >> trying to do something simple, the python equivilent of: >> >> if(i % 3 == 0 || i % 5 == 0) > > if i % 3 == 0 or i % 5 == 0: > > You may find it worthwhile to quickly step through everything in the > standard Python tutorial, it covers lots of stuff like this. I did, though perhapse a little to quickly! lol From srikrishnamohan at gmail.com Thu Feb 12 11:24:02 2009 From: srikrishnamohan at gmail.com (km) Date: Fri, 13 Feb 2009 01:24:02 +0900 Subject: Embarrasing questio In-Reply-To: References: <2dd78188-434d-4c24-bd73-2047105c6a89@q30g2000prq.googlegroups.com> Message-ID: Hi, you could do it this way also : if i in [3,5]: do something... KM ~~~~~~~~~~~~~~~~~~~~~ On Fri, Feb 13, 2009 at 1:19 AM, Michele Simionato < michele.simionato at gmail.com> wrote: > On Feb 12, 5:07 pm, TechieInsights wrote: > > On Feb 12, 9:03 am, Catherine Heathcote > > > > wrote: > > > But I just cant find it. How do I do an or, as in c/c++'s ||? Just > > > trying to do something simple, the python equivilent of: > > > > > if(i % 3 == 0 || i % 5 == 0) > > > > > Thanks. > > > > in 2.5 and above you can do > > if any(i%3 == 0, i%5 == 0) > > You are missing a few parenthesis: if any([i%3 == 0, i%5 == 0]) (but > the idiomatic solution is to use or). > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dear.jay.logan at gmail.com Thu Feb 12 11:27:09 2009 From: dear.jay.logan at gmail.com (josh logan) Date: Thu, 12 Feb 2009 08:27:09 -0800 (PST) Subject: Read Only attributes, auto properties and getters and setters References: <8090b400-dde2-4fc2-8d73-6d1bad3b5aeb@z6g2000pre.googlegroups.com> <61e02f4c-6006-4051-9ad4-9de11bceacea@o6g2000pre.googlegroups.com> Message-ID: On Feb 12, 10:58?am, TechieInsights wrote: > Oh... one other thing that would be really cool is to do this with AOP/ > descriptors! ?I just haven't been able to get that to work either. > Basics... > > @readonly > class MyClass(object): > ? ? ? ? def __init__(self, x): > ? ? ? ? ? ? ? ? self.set_x(x) > > ? ? ? ? def get_x(self): > ? ? ? ? ? ? ? ? return self.__x > > ? ? ? ? def set_x(self, x): > ? ? ? ? ? ? ? ? print 'Hello the setter was called!' > ? ? ? ? ? ? ? ? self.__x = x > > and it's done! ?I don't think this will work because (maybe I'm wrong) > but I don't think you can set the metaclass in the descriptor??? ?If > this is the case, it is more work to do the AOP and set a metaclass... > better to just inherit. ?If it can be done... that would be awesome! > > Greg Are your needs not already satisfied by the Python built-in property? http://docs.python.org/dev/3.0/library/functions.html#property From digitig at gmail.com Thu Feb 12 11:28:35 2009 From: digitig at gmail.com (Tim Rowe) Date: Thu, 12 Feb 2009 16:28:35 +0000 Subject: Embarrasing questio In-Reply-To: References: <2dd78188-434d-4c24-bd73-2047105c6a89@q30g2000prq.googlegroups.com> Message-ID: 2009/2/12 km : > Hi, > > you could do it this way also : > > if i in [3,5]: > do something... True, you could do it, but it would be wrong. The original is true for i = 6, 9, 10, 12 and so on, but yours doesn't seem to be... -- Tim Rowe From GDoermann at gmail.com Thu Feb 12 11:30:00 2009 From: GDoermann at gmail.com (TechieInsights) Date: Thu, 12 Feb 2009 08:30:00 -0800 (PST) Subject: Embarrasing questio References: <2dd78188-434d-4c24-bd73-2047105c6a89@q30g2000prq.googlegroups.com> Message-ID: <0c5dfe48-8625-4aca-b126-7c7b4f70f123@r41g2000prr.googlegroups.com> On Feb 12, 9:19?am, Michele Simionato wrote: > On Feb 12, 5:07?pm, TechieInsights wrote: > > > On Feb 12, 9:03?am, Catherine Heathcote > > > wrote: > > > But I just cant find it. How do I do an or, as in c/c++'s ||? Just > > > trying to do something simple, the python equivilent of: > > > > if(i % 3 == 0 || i % 5 == 0) > > > > Thanks. > > > in 2.5 and above you can do > > if any(i%3 == 0, i%5 == 0) > > You are missing a few parenthesis: if any([i%3 == 0, i%5 == 0]) (but > the idiomatic solution is to use or). Thanks... my mistake From GDoermann at gmail.com Thu Feb 12 11:32:37 2009 From: GDoermann at gmail.com (TechieInsights) Date: Thu, 12 Feb 2009 08:32:37 -0800 (PST) Subject: Read Only attributes, auto properties and getters and setters References: <8090b400-dde2-4fc2-8d73-6d1bad3b5aeb@z6g2000pre.googlegroups.com> <61e02f4c-6006-4051-9ad4-9de11bceacea@o6g2000pre.googlegroups.com> Message-ID: <7301e264-0364-4d93-afb3-522f013c1c2e@40g2000prx.googlegroups.com> On Feb 12, 9:27?am, josh logan wrote: > On Feb 12, 10:58?am, TechieInsights wrote: > > > > > Oh... one other thing that would be really cool is to do this with AOP/ > > descriptors! ?I just haven't been able to get that to work either. > > Basics... > > > @readonly > > class MyClass(object): > > ? ? ? ? def __init__(self, x): > > ? ? ? ? ? ? ? ? self.set_x(x) > > > ? ? ? ? def get_x(self): > > ? ? ? ? ? ? ? ? return self.__x > > > ? ? ? ? def set_x(self, x): > > ? ? ? ? ? ? ? ? print 'Hello the setter was called!' > > ? ? ? ? ? ? ? ? self.__x = x > > > and it's done! ?I don't think this will work because (maybe I'm wrong) > > but I don't think you can set the metaclass in the descriptor??? ?If > > this is the case, it is more work to do the AOP and set a metaclass... > > better to just inherit. ?If it can be done... that would be awesome! > > > Greg > > Are your needs not already satisfied by the Python built-in property? > > http://docs.python.org/dev/3.0/library/functions.html#property yea... just read the docs... I love reinventing the wheel (sarcasm)... Thanks for this... I just realized that you can set the fset and fdel to None... so everything can be done from the metaclass! From kyosohma at gmail.com Thu Feb 12 11:36:32 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Thu, 12 Feb 2009 08:36:32 -0800 (PST) Subject: Untangling pythonWin and IDLE Processes on XP Pro References: <%OUkl.6905$jZ1.2422@flpi144.ffdc.sbc.com> <6viopfFkcasmU1@mid.uni-berlin.de> <2NWkl.16040$YU2.9824@nlpi066.nbdc.sbc.com> Message-ID: <4ec6562a-08b2-4ec4-b9c0-e720e4ce7339@g38g2000yqd.googlegroups.com> On Feb 12, 8:57?am, "W. eWatson" wrote: > Diez B. Roggisch wrote: > > W. eWatson wrote: > > >> It appears if one moves between IDLE and pythonWin (pyWin) that two > >> separate loops (threads?) can occur, and that IDLE can produce incorrect > >> results. Since I have preferred IDLE over pyWin, that leaves me currently > >> in a quandry. How do I renew these processes, so that I can proceed with > >> IDLE? > > >> I noticed that I had about 10-15 copies of pythonw.exe as I tried to reach > >> some understanding of what was going on. Killing these tasks didn't help > >> restore order to IDLE. It seems my only choice now is to reboot? Comments? > > > Gosh no, rebooting shouldn't be needed. Just quit all idle & pywin > > processes, including of course the main programs. Which *should* be > > anything that is needed anyway. > > Done that. Been there. It doesn't work. If I take another py tkinter program > and run it in IDLE, it *will work*. The current program goes boom. > > > And you still seem to not understand what is really happening. > > Whether I understand it exactly or not is not the issue. The issue is how do > I execute IDLE *now* to get the correct results it once allowed? The fact of > the matter is that I was happily working in IDLE for days and hours. I > encountered a problem in IDLE that seemed suspicious, so I then fired up > pyWin to see if it gave the same results. It worked fine. Then my problems > with IDLE got worse. > > > Working between pywin and idle is perfectly fine, they are separate > > programs. You can start as many instances of a program as you want and > > happily work with them. Even several instances of idle and pywin, unless > > these come with some logic to prevent multiple starts ?- some windows app > > do that. > > How could this be true; otherwise, ?I wouldn't be complaining? > > > What does *NOT* work is writing a Tkinter-based app in idle, and to run it > > *FROM INSIDE* idle. Instead, open your explorer and double-click on the > > pyhton-file your app is in. That's all that there is to it. > > Personally, I like running entirely in IDLE. > > If there is no other way than you suggested in "NOT work", then I may just > uninstall pyWin. > > > > > Diez > > -- > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? W. eWatson > > ? ? ? ? ? ? ? (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) > ? ? ? ? ? ? ? ?Obz Site: ?39? 15' 7" N, 121? 2' 32" W, 2700 feet > > ? ? ? ? ? ? ? ? ? ? ?Web Page: I like IDLE too. However, I've experienced seemingly random crashes when programming wxPython programs in it. As already stated, the mainloops clash from time to time. So now I use Wingware or just edit the files in IDLE and run the program by double-click or via command line. Mike From google at mrabarnett.plus.com Thu Feb 12 11:37:10 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 12 Feb 2009 16:37:10 +0000 Subject: Match items in large list In-Reply-To: <6c7720da-9e95-486c-9f28-c85ce3bc9a7e@q9g2000yqc.googlegroups.com> References: <6c7720da-9e95-486c-9f28-c85ce3bc9a7e@q9g2000yqc.googlegroups.com> Message-ID: <49945036.70309@mrabarnett.plus.com> Fisherking wrote: > Hi, > > I hope you can help me with this optimizing problem! > I have a large list of dictionaries (about 250 000 of them). Two or > more of these dictionaries contains the same data (not more than five > or six of them per item) e.g. [{'a':1,'b':'2','c':3} , {'d': > 4,'e':'5','f':6},{'a':1,'b':'2','c':3} , {'d':4,'e':'5','f':6},...]. > (the dictionaries are really containg phone numbers, duration time and > call time.) > > Which are the best way of searching through the list and extract the > items that are the same. In the first run I want to find every item > that are the same as {'a':1,'b':'2','c':3}, the second {'d': > 4,'e':'5','f':6} etc. The list are not read-only and I can pop them > out of the list when I have found them! > > (How can I found items that are almost the same? e.g. {'a': > 1,'b':'2','c':3.1} and {'a':1,'b':'2','c':3.2} ) > > In the second part of this program I need to take each of these items > (similar items are treated as one) and find these in a database that > contains 2.5M posts! > > The python version I am bound to is Python 2.3 > The best way of looking for duplicates is to make a dict or set of the items. Unfortunately a dict isn't hashable, so it can't be a key. Therefore I suggest you convert the dicts into tuples, which are hashable: counts = {} for d in my_list: d_as_list = d.items() # Standardise the order so that identical dicts become identical tuples. d_as_list.sort() key = tuple(d_as_list) if key in counts: counts[key] += 1 else: counts[key] = 1 From notvalid2 at sbcglobal.net Thu Feb 12 11:44:56 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Thu, 12 Feb 2009 08:44:56 -0800 Subject: Untangling pythonWin and IDLE Processes on XP Pro In-Reply-To: <6viv4bFk8gonU1@mid.uni-berlin.de> References: <%OUkl.6905$jZ1.2422@flpi144.ffdc.sbc.com> <6viopfFkcasmU1@mid.uni-berlin.de> <2NWkl.16040$YU2.9824@nlpi066.nbdc.sbc.com> <6viv4bFk8gonU1@mid.uni-berlin.de> Message-ID: I simply ask, "How do I get around the problem?" -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From notvalid2 at sbcglobal.net Thu Feb 12 11:50:14 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Thu, 12 Feb 2009 08:50:14 -0800 Subject: Untangling pythonWin and IDLE Processes on XP Pro In-Reply-To: <4ec6562a-08b2-4ec4-b9c0-e720e4ce7339@g38g2000yqd.googlegroups.com> References: <%OUkl.6905$jZ1.2422@flpi144.ffdc.sbc.com> <6viopfFkcasmU1@mid.uni-berlin.de> <2NWkl.16040$YU2.9824@nlpi066.nbdc.sbc.com> <4ec6562a-08b2-4ec4-b9c0-e720e4ce7339@g38g2000yqd.googlegroups.com> Message-ID: As with Diez, I simply ask, "How do I get around the problem?" Are you two telling me that it is impossible? OK, here's my offer to both of you. Do you have IDLE for Python 2.5 and have good familiarity with Tkinter? If so, I'll send you the code and you can try it yourself. My guess is that it will work, and if not, and you are sufficiently skilled with Tkinter and debugging, you may find the problem in the code. The steps to create the problem are very easy. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From jfabiani at yolo.com Thu Feb 12 11:55:28 2009 From: jfabiani at yolo.com (John Fabiani) Date: Thu, 12 Feb 2009 08:55:28 -0800 Subject: openOffic, windows, and Python 2.5 References: Message-ID: Terry Reedy wrote: > John Fabiani wrote: >> Hi, >> OpenOffice 3 on windows uses python 2.3.x (I have no idea why). > > I presume because no one has volunteered to do the update for the Py-UNO > bridge. In any case, why do you consider that to be a problem. It is > common for apps to include the Python they are known to work with. > > tjr Thanks for the response. The reason is the others apps are written in python 2.5.x. All the testing was done on Linux using 2.5 and now we need it to work on the windows side too. From n.kottiyath at gmail.com Thu Feb 12 11:55:58 2009 From: n.kottiyath at gmail.com (Kottiyath) Date: Thu, 12 Feb 2009 08:55:58 -0800 (PST) Subject: Spam Message-ID: <467e1f02-47ba-4bd2-ad40-853e3886ff60@40g2000prx.googlegroups.com> Hi, There seems to be lot of spam coming in this newsgroup. Is it possible to have some mechanism similar to say - slashdot - wherein mails can be moderated by any of the usual users? This is required only for people who is posting for the first time (or people who has been rated spam before). Second post onwards, no moderation required. Just wondering. From notvalid2 at sbcglobal.net Thu Feb 12 12:01:19 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Thu, 12 Feb 2009 09:01:19 -0800 Subject: Untangling pythonWin and IDLE Processes on XP Pro In-Reply-To: References: <%OUkl.6905$jZ1.2422@flpi144.ffdc.sbc.com> <6viopfFkcasmU1@mid.uni-berlin.de> <2NWkl.16040$YU2.9824@nlpi066.nbdc.sbc.com> <4ec6562a-08b2-4ec4-b9c0-e720e4ce7339@g38g2000yqd.googlegroups.com> Message-ID: <%AYkl.16675$yr3.11280@nlpi068.nbdc.sbc.com> W. eWatson wrote: > As with Diez, I simply ask, "How do I get around the problem?" Are you > two telling me that it is impossible? > > OK, here's my offer to both of you. Do you have IDLE for Python 2.5 and > have good familiarity with Tkinter? If so, I'll send you the code and > you can try it yourself. My guess is that it will work, and if not, and > you are sufficiently skilled with Tkinter and debugging, you may find > the problem in the code. The steps to create the problem are very easy. > Well, this may be a bit trickier than I thought. I'd have to give you the same PIL, tkinter, numpy libraries the program users. However, I"m willing to send the files for them to you. Here's the start of the code ===================== from Tkinter import * from numpy import * import Image import ImageChops import ImageTk import ImageDraw # wtw import time import binascii import tkMessageBox import tkSimpleDialog from pylab import plot, xlabel, ylabel, title, show, xticks, bar from tkFileDialog import asksaveasfilename, asksaveasfile from tkFileDialog import askopenfilename import MakeQTE ======================= You'd also need clut.txt, wagon.gif, and MakQTE. All small files. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From apt.shansen at gmail.com Thu Feb 12 12:09:22 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Thu, 12 Feb 2009 09:09:22 -0800 Subject: Spam In-Reply-To: <467e1f02-47ba-4bd2-ad40-853e3886ff60@40g2000prx.googlegroups.com> References: <467e1f02-47ba-4bd2-ad40-853e3886ff60@40g2000prx.googlegroups.com> Message-ID: <7a9c25c20902120909r3ae5e67cx682603e33c9b3863@mail.gmail.com> > There seems to be lot of spam coming in this newsgroup. > Is it possible to have some mechanism similar to say - slashdot - > wherein mails can be moderated by any of the usual users? > This is required only for people who is posting for the first time > (or people who has been rated spam before). Second post onwards, no > moderation required. > Just wondering. C.P.L is an unmoderated newsgroup: so there's no content controls on posts. I don't think that's possible to change. But I haven't gotten directly near a newsgroup-as-a-newsgroup in eons, so I may be wrong. If you subscribe to C.P.L as a mailing list instead of a newsgroup, I believe most of the spam gets filtered out at the mailing list<->news group gateway by the Python.org spam filters... At least no spam in my Gmail spam folder appears to be flagged from this group(at a very brief glance) so they appear to be doing quite well. http://mail.python.org/mailman/listinfo/python-list is the list subscription page. (C.P.L and python-list are essentially the same thing: things posted to the list get forwarded to the newsgroup, and vice-versa) --S From apt.shansen at gmail.com Thu Feb 12 12:10:02 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Thu, 12 Feb 2009 09:10:02 -0800 Subject: Spam In-Reply-To: <7a9c25c20902120909r3ae5e67cx682603e33c9b3863@mail.gmail.com> References: <467e1f02-47ba-4bd2-ad40-853e3886ff60@40g2000prx.googlegroups.com> <7a9c25c20902120909r3ae5e67cx682603e33c9b3863@mail.gmail.com> Message-ID: <7a9c25c20902120910h560a6bc7qfae73d456a9634e2@mail.gmail.com> > C.P.L C.L.P even. Ahem. --S From google at mrabarnett.plus.com Thu Feb 12 12:22:30 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 12 Feb 2009 17:22:30 +0000 Subject: Embarrasing questio In-Reply-To: References: <2dd78188-434d-4c24-bd73-2047105c6a89@q30g2000prq.googlegroups.com> Message-ID: <49945AD6.5060400@mrabarnett.plus.com> Michele Simionato wrote: > On Feb 12, 5:07 pm, TechieInsights wrote: >> On Feb 12, 9:03 am, Catherine Heathcote >> >> wrote: >>> But I just cant find it. How do I do an or, as in c/c++'s ||? Just >>> trying to do something simple, the python equivilent of: >>> if(i % 3 == 0 || i % 5 == 0) >>> Thanks. >> in 2.5 and above you can do >> if any(i%3 == 0, i%5 == 0) > > You are missing a few parenthesis: if any([i%3 == 0, i%5 == 0]) (but > the idiomatic solution is to use or). > any() is really only useful with a generator, otherwise you're always evaluating both conditions, unlike the solution with 'or'. From python.list at tim.thechases.com Thu Feb 12 12:23:29 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 12 Feb 2009 11:23:29 -0600 Subject: Spam In-Reply-To: <7a9c25c20902120909r3ae5e67cx682603e33c9b3863@mail.gmail.com> References: <467e1f02-47ba-4bd2-ad40-853e3886ff60@40g2000prx.googlegroups.com> <7a9c25c20902120909r3ae5e67cx682603e33c9b3863@mail.gmail.com> Message-ID: <49945B11.9030007@tim.thechases.com> > If you subscribe to C.P.L as a mailing list instead of a > newsgroup, I believe most of the spam gets filtered out at the > mailing list<->news group gateway by the Python.org spam > filters... At least no spam in my Gmail spam folder appears to > be flagged from this group(at a very brief glance) so they > appear to be doing quite well. Allow me to take this opportunity to thank the folks that *are* doing/managing this spam-filtering of the mailing list side of things -- the drastic drop in spam (from 6+ months back) is much appreciated! Though I guess this thread does beg the question: is there a way to read the filtered mailing list with a newsreader (via NNTP) instead of getting it delivered via email or subjecting oneself to the spamminess of c.l.p? I like some of the "kill-thread" types of options I've got on the NNTP side of readers that aren't as readily available to me on the email side of things (Thunderbird allows for thread-kills in News, but not in email). -tkc From tjreedy at udel.edu Thu Feb 12 12:24:43 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 12 Feb 2009 12:24:43 -0500 Subject: Avoiding argument checking in recursive calls In-Reply-To: References: <7xeiy52zfl.fsf@ruckus.brouhaha.com> Message-ID: Steven D'Aprano wrote: > On Wed, 11 Feb 2009 04:31:10 -0500, Terry Reedy wrote: > >>> Steven D'Aprano writes: >>>> def fact(n): >>>> if n < 0: raise ValueError >>>> if n = 0: return 1 >>>> return fact(n-1)*n >>>> >>>> At the risk of premature optimization, I wonder if there is an idiom >>>> for avoiding the unnecessary test for n <= 0 in the subsequent >>>> recursive calls? >> Reverse the test order >> >> def fact(n): >> if n > 0: return fact(n-1)*n >> if n == 0: return 1 >> raise ValueError >> >> You must test recursive versus terminal case every call in any case. >> Nearly always, the first test passes and second is not done. You only >> test n==0 once, either to terminate or raise exception. This works for >> any integral value and catches non-integral values. (There is some delay >> for that, but only bad calls are penalized.) > > Nice try, but in fact no. I meant non-integral numbers. Others inputs are outside the usual spec for fact(). You asked about "an idiom for avoiding the unnecessary test for n <= 0 in the subsequent recursive calls?" and I gave you that. You should have thanked me. >>>> fact(None) # works okay > Traceback (most recent call last): > File "", line 1, in > File "", line 4, in fact > ValueError >>>> fact({}) > Traceback (most recent call last): > File "", line 1, in > File "", line 2, in fact > TypeError: unsupported operand type(s) for -: 'dict' and 'int' > > You're relying on arbitrary ordering of types in Python 2.x, No I'm not. I don't even know what you mean by that claim. > and of course in Python 3 that fails altogether. In 3.0, which is what I use, the comparison 'n>0' raises an exception for non-numbers, as it should. To me, that is success. What else would you want? Terry Jan Reedy From travis+ml-python at subspacefield.org Thu Feb 12 12:26:19 2009 From: travis+ml-python at subspacefield.org (Travis) Date: Thu, 12 Feb 2009 11:26:19 -0600 Subject: zlib interface semi-broken In-Reply-To: <20090210205739.GT6522@subspacefield.org> References: <20090210205739.GT6522@subspacefield.org> Message-ID: <20090212172619.GG6522@subspacefield.org> So I've submitted a patch to bugs.python.org to add a new member called is_finished to the zlib decompression object. Issue 5210, file 13056, msg 81780 -- Crypto ergo sum. http://www.subspacefield.org/~travis/ Do unto other faiths as you would have them do unto yours. If you are a spammer, please email john at subspacefield.org to get blacklisted. From GDoermann at gmail.com Thu Feb 12 12:27:07 2009 From: GDoermann at gmail.com (TechieInsights) Date: Thu, 12 Feb 2009 09:27:07 -0800 (PST) Subject: Read Only attributes, auto properties and getters and setters References: <8090b400-dde2-4fc2-8d73-6d1bad3b5aeb@z6g2000pre.googlegroups.com> <61e02f4c-6006-4051-9ad4-9de11bceacea@o6g2000pre.googlegroups.com> <7301e264-0364-4d93-afb3-522f013c1c2e@40g2000prx.googlegroups.com> Message-ID: <6531a55c-194d-432c-acc4-612700abf935@w24g2000prd.googlegroups.com> Ok... for some closure I have written a class to automate the process. It takes getters and setters and deleters and then sets the property automatically. Sweet! class AutoProperty(type): def __new__(cls, name, bases, methoddict): processed = [] getter = 'get_' setter = 'set_' deleter = 'del_' starters = {getter:PropertyAttr(getter, PropertyAttr.FGET), setter:PropertyAttr(setter, PropertyAttr.FSET), deleter:PropertyAttr(deleter, PropertyAttr.FDEL) } for key, value in methoddict.items(): var = None for start in starters.keys(): if key.startswith(start): var = key[len(start):] break if var is None or var in processed: continue property_values = [] for start in starters.keys(): if '%s%s' %(start, var) in methoddict.keys(): property_values.append(starters[start].tostring(var)) else: property_values.append(starters[start].tostring(None)) property_map = 'methoddict["%s"] = property(%s)' %(var, ','.join (property_values)) exec(property_map) return type.__new__(cls, name, bases, methoddict) class PropertyAttr(object): FGET = 'fget' FSET = 'fset' FDEL = 'fdel' def __init__(self, start, type = FGET): self.start = start self.type = type def tostring(self, var): if self.type == self.FSET: vars = ['v'] else: vars = [] fullvar = ['self'] + vars if var is None: return '%s=None' %(self.type) return '%s=lambda %s: self.%s%s(%s)' %(self.type, ','.join(fullvar), self.start, var, ','.join(vars)) class ReadOnly(object): __metaclass__ = AutoProperty class MyClass(ReadOnly): def __init__(self, x, y): self.__x = x self.__y = y def get_x(self): return self.__x def set_x(self, x): self.__x = x def get_y(self): return self.__y mc = MyClass(10, 100) print mc.x, mc.y mc.x = 10 print mc.x try: mc.y = 100 except AttributeError: print 'Yea it worked!' try: del mc.y except AttributeError: print "It's read only!" And the output: 10 100 10 Yea it worked! It's read only! Now to work on descriptors doing it for you. From GDoermann at gmail.com Thu Feb 12 12:30:30 2009 From: GDoermann at gmail.com (TechieInsights) Date: Thu, 12 Feb 2009 09:30:30 -0800 (PST) Subject: Spam References: <467e1f02-47ba-4bd2-ad40-853e3886ff60@40g2000prx.googlegroups.com> <7a9c25c20902120909r3ae5e67cx682603e33c9b3863@mail.gmail.com> Message-ID: On Feb 12, 10:23?am, Tim Chase wrote: > > If you subscribe to C.P.L as a mailing list instead of a > > newsgroup, I believe most of the spam gets filtered out at the > > mailing list<->news group gateway by the Python.org spam > > filters... At least no spam in my Gmail spam folder appears to > > be flagged from this group(at a very brief glance) so they > > appear to be doing quite well. > > Allow ?me to take this opportunity to thank the folks that *are* > doing/managing this spam-filtering of the mailing list side of > things -- the drastic drop in spam (from 6+ months back) is much > appreciated! > > Though I guess this thread does beg the question: ?is there a way > to read the filtered mailing list with a newsreader (via NNTP) > instead of getting it delivered via email or subjecting oneself > to the spamminess of c.l.p? ?I like some of the "kill-thread" > types of options I've got on the NNTP side of readers that aren't > as readily available to me on the email side of things > (Thunderbird allows for thread-kills in News, but not in email). > > -tkc Enhancement request for google: hide messages by a certain author it would be individually set, but can get rid of a lot of junk at once. From tjreedy at udel.edu Thu Feb 12 12:36:20 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 12 Feb 2009 12:36:20 -0500 Subject: Match items in large list In-Reply-To: <6c7720da-9e95-486c-9f28-c85ce3bc9a7e@q9g2000yqc.googlegroups.com> References: <6c7720da-9e95-486c-9f28-c85ce3bc9a7e@q9g2000yqc.googlegroups.com> Message-ID: Fisherking wrote: > Hi, > > I hope you can help me with this optimizing problem! > I have a large list of dictionaries (about 250 000 of them). Two or > more of these dictionaries contains the same data (not more than five > or six of them per item) e.g. [{'a':1,'b':'2','c':3} , {'d': > 4,'e':'5','f':6},{'a':1,'b':'2','c':3} , {'d':4,'e':'5','f':6},...]. > (the dictionaries are really containg phone numbers, duration time and > call time.) > > Which are the best way of searching through the list and extract the > items that are the same. In the first run I want to find every item > that are the same as {'a':1,'b':'2','c':3}, the second {'d': > 4,'e':'5','f':6} etc. The list are not read-only and I can pop them > out of the list when I have found them! Popping items out of the middle of a list is a slow O(n) operation. MRAB's set of tuples is what I would have suggested. > > (How can I found items that are almost the same? e.g. {'a': > 1,'b':'2','c':3.1} and {'a':1,'b':'2','c':3.2} ) > > In the second part of this program I need to take each of these items > (similar items are treated as one) and find these in a database that > contains 2.5M posts! > > The python version I am bound to is Python 2.3 For that, dict of tuples (with fake value == None) might be faster than the add-on set module. From travis+ml-python at subspacefield.org Thu Feb 12 12:38:12 2009 From: travis+ml-python at subspacefield.org (Travis) Date: Thu, 12 Feb 2009 11:38:12 -0600 Subject: how to distribute python extensions independently of python Message-ID: <20090212173812.GH6522@subspacefield.org> So, Recently I made a fix to the zlib module that I need for use at work. I would like other employees to be able to use it without recompiling python. I assume I can just rename it and distribute it as a python extension. I was wondering how I can provide a way for other employees to build it. I saw a "Universal Unix Makefile for Python extensions" that looks promising. Is this the accepted way to compile python extensions still? -- Crypto ergo sum. http://www.subspacefield.org/~travis/ Do unto other faiths as you would have them do unto yours. If you are a spammer, please email john at subspacefield.org to get blacklisted. From deets at nospam.web.de Thu Feb 12 12:38:19 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 12 Feb 2009 18:38:19 +0100 Subject: Untangling pythonWin and IDLE Processes on XP Pro References: <%OUkl.6905$jZ1.2422@flpi144.ffdc.sbc.com> <6viopfFkcasmU1@mid.uni-berlin.de> <4ec6562a-08b2-4ec4-b9c0-e720e4ce7339@g38g2000yqd.googlegroups.com> Message-ID: <6vj54bFjd14jU1@mid.uni-berlin.de> W. eWatson wrote: > As with Diez, I simply ask, "How do I get around the problem?" Are you two > telling me that it is impossible? YES. That's what we and all the others who answered to you in the other thread are telling you, repeatedly. It is impossible. Really. No kidding. For sure. Jawoll, ganz sicher sogar. Diez From andrew at acooke.org Thu Feb 12 12:42:15 2009 From: andrew at acooke.org (andrew cooke) Date: Thu, 12 Feb 2009 14:42:15 -0300 (CLST) Subject: Spam In-Reply-To: <49945B11.9030007@tim.thechases.com> References: <467e1f02-47ba-4bd2-ad40-853e3886ff60@40g2000prx.googlegroups.com> <7a9c25c20902120909r3ae5e67cx682603e33c9b3863@mail.gmail.com> <49945B11.9030007@tim.thechases.com> Message-ID: <15b8ac796d4482926d373b153409383c.squirrel@localhost> A quick search on "imap nntp" turned up this list that might be useful - http://deflexion.com/messaging/ although I wonder when it was written because I remember using Aaron's RSS to email aggregator when RSS was new(!). It mentions gmane, though, which certainly still exists (I assume it carries this list too). And this page suggests you can read gmane via nntp - http://reticule.gmane.org/ Aha! yes! It;s in the FAQ :o) Can I read news via secure NNTP (nntps)? Yes. Point your news reader towards nntps://snews.gmane.org/. http://www.gmane.org/faq.php I should be working; I will try that this evening. What was the name of the client that threaded messages with a cute ascii tree?! Cheers, Andrew Tim Chase wrote: > Though I guess this thread does beg the question: is there a way > to read the filtered mailing list with a newsreader (via NNTP) From michele.simionato at gmail.com Thu Feb 12 12:44:26 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Thu, 12 Feb 2009 09:44:26 -0800 (PST) Subject: Embarrasing questio References: <2dd78188-434d-4c24-bd73-2047105c6a89@q30g2000prq.googlegroups.com> Message-ID: <589cecad-6edd-4a9f-ae84-0791b37d292a@m42g2000yqb.googlegroups.com> On Feb 12, 6:22?pm, MRAB wrote: > Michele Simionato wrote: > > On Feb 12, 5:07 pm, TechieInsights wrote: > >> On Feb 12, 9:03 am, Catherine Heathcote > > >> wrote: > >>> But I just cant find it. How do I do an or, as in c/c++'s ||? Just > >>> trying to do something simple, the python equivilent of: > >>> if(i % 3 == 0 || i % 5 == 0) > >>> Thanks. > >> in 2.5 and above you can do > >> if any(i%3 == 0, i%5 == 0) > > > You are missing a few parenthesis: if any([i%3 == 0, i%5 == 0]) (but > > the idiomatic solution is to use or). > > any() is really only useful with a generator, otherwise you're always > evaluating both conditions, unlike the solution with 'or'. Indeed. From andrew at acooke.org Thu Feb 12 12:45:33 2009 From: andrew at acooke.org (andrew cooke) Date: Thu, 12 Feb 2009 14:45:33 -0300 (CLST) Subject: how to distribute python extensions independently of python In-Reply-To: <20090212173812.GH6522@subspacefield.org> References: <20090212173812.GH6522@subspacefield.org> Message-ID: You might want to read https://www.dfwpython.org/repo/Presentations/2008-10-04-PyArkansas-PythonEggsIntro/eggs-introduction.pdf It covers a lot of ground; I used it to work out how to distribute a pure Python package, but I am sure it mentions compiled packages too. In my case I ended up using setuptools (easy_install) and distutils. (Not sure if you asking just about compiling, or more general packaging, but IIRC it covers both). Andrew Travis wrote: > So, > > Recently I made a fix to the zlib module that I need for use at work. > > I would like other employees to be able to use it without recompiling > python. > > I assume I can just rename it and distribute it as a python extension. > > I was wondering how I can provide a way for other employees to build it. > > I saw a "Universal Unix Makefile for Python extensions" that looks > promising. > > Is this the accepted way to compile python extensions still? > -- > Crypto ergo sum. http://www.subspacefield.org/~travis/ > Do unto other faiths as you would have them do unto yours. > If you are a spammer, please email john at subspacefield.org to get > blacklisted. > -- > http://mail.python.org/mailman/listinfo/python-list > > From Scott.Daniels at Acm.Org Thu Feb 12 12:51:16 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 12 Feb 2009 09:51:16 -0800 Subject: Untangling pythonWin and IDLE Processes on XP Pro In-Reply-To: References: <%OUkl.6905$jZ1.2422@flpi144.ffdc.sbc.com> <6viopfFkcasmU1@mid.uni-berlin.de> <2NWkl.16040$YU2.9824@nlpi066.nbdc.sbc.com> <4ec6562a-08b2-4ec4-b9c0-e720e4ce7339@g38g2000yqd.googlegroups.com> Message-ID: W. eWatson wrote: > As with Diez, I simply ask, "How do I get around the problem?" Are you > two telling me that it is impossible? > > OK, here's my offer to both of you. Do you have IDLE for Python 2.5 and > have good familiarity with Tkinter? If so, I'll send you the code and > you can try it yourself. My guess is that it will work, and if not, and > you are sufficiently skilled with Tkinter and debugging, you may find > the problem in the code. The steps to create the problem are very easy. They are telling you the truth, and you are replying, "I don't want to understand, I just want it to work." They have shown great forbearance. The only time I have debugged any Tkinter code in IDLE, I have start with "python -m idlelib.idle -n" and accepted the fact that I will see crashes. The one advantage of my technique is that I can hand-execute single Tkinter operations and see the results immediately since I am running piggyback on IDLE's main loop. Once more, though I'm sure you don't want to hear it: Normally IDLE starts as a program running that talks to the user (idle.py). It starts a separate process that talks to the user interface over a TCP/IP port and does the things inside the shell (for example the expression evaluation). When you use the command "Shell / Restart Shell," the process that interacts with your program is wiped out and new process is started (I think, perhaps they simply flush almost everything and restart). The reason only one IDLE session can live at a time is that a TCP/IP communication port has only two ends. If you don't kill _all_ of the pythonw processes, something will go wrong in the initial setting up the parent/child processes. Similarly, a GUI is not a library, but a framework. The GUI itself is the main program (run after you do some setup) that calls parts of your program as subroutines. You have a problem when you use a GUI to debug another GUI (there can be only _one_ main program). It does no good to stomp your foot and proclaim that you want it to work. Sometimes your code doesn't interfere too badly with IDLE's GUI, so it looks as if you have gotten away with it. For example, in-process IDLE (the "-n" flag) fiddles with the Tkinter environment in an attempt to reduce the conflict between IDLE's and your program's use of the GUI. The only solutions I've seen for debugging GUIs involve separated processes (even more so than IDLE), running on separate machines. With those, you don't share a keyboard, mouse, or display between the debugger and the program under test. Such solutions are available for a price. ActiveState, for example, sells one. The issue in each case is sharing things that the programs have every right to expect that they "own." To wit, Display refresh points, the main program, the keyboard, tcp/ip ports, the mouse. --Scott David Daniels Scott.Daniels at Acm.Org From maksym.kaban at gmail.com Thu Feb 12 12:53:04 2009 From: maksym.kaban at gmail.com (maksym.kaban at gmail.com) Date: Thu, 12 Feb 2009 09:53:04 -0800 (PST) Subject: something wrong with isinstance Message-ID: <2a84f320-8be2-4482-9513-4d7edf3295ac@j8g2000yql.googlegroups.com> Hi there. now i'm a complete newbie for python, and maybe my problem is stupid but i cannot solve it myself i have an object of class GeoMap which contains lists with objects of GeoMapCell (i will not explain what they should do, hope its not important). Then i want to serialize these objects to json notation. So i imported json module and as shown in docs for it extended JSONEncoder class. Look at the code below ##main module from worldmap import GeoMap, GeoMapCell import testdata import json class GeoMapEncoder(json.JSONEncoder): def default(self, obj): if isinstance(obj, GeoMap): return None return json.JSONEncoder.default(self, obj) def main(): print(json.dumps(2 + 5j, cls=ComplexEncoder)) geomap = testdata.createTestMap() print(json.dumps(geomap, cls=GeoMapEncoder)) pass if __name__ == '__main__': main() =========== ##worldmap module class GeoMap: cells = [] activerow = 0 activecol = 0 def addCell(self, acell): if len(self.cells) == 0: self.cells.append([]) self.activerow = 0 acell.col = self.activerow acell.row = self.activecol self.cells[self.activerow].append(acell) self.activecol += 1 def addRow(self): self.cells.append([]) self.activerow += 1; self.activecol = 0; class GeoMapCell: neighbours = (None, None, None, None, None, None, ) col = 0 row = 0 The problem is in here. class GeoMapEncoder(json.JSONEncoder): def default(self, obj): if isinstance(obj, GeoMap): ## <======= isinstance doesnot work as i expected return None return json.JSONEncoder.default(self, obj) Though obj is object of GeoMap class, isinstance returns False. Where was i mistaken. If i shouldn't use isinstance, then what function would check class of object? Oh, maybe its important. I'm working on WinXP SP3, Python 3.0, IDE - PyScript From tjreedy at udel.edu Thu Feb 12 13:00:54 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 12 Feb 2009 13:00:54 -0500 Subject: Untangling pythonWin and IDLE Processes on XP Pro In-Reply-To: References: <%OUkl.6905$jZ1.2422@flpi144.ffdc.sbc.com> <6viopfFkcasmU1@mid.uni-berlin.de> <2NWkl.16040$YU2.9824@nlpi066.nbdc.sbc.com> <4ec6562a-08b2-4ec4-b9c0-e720e4ce7339@g38g2000yqd.googlegroups.com> Message-ID: W. eWatson wrote: > As with Diez, I simply ask, "How do I get around the problem?" Are you > two telling me that it is impossible? Try this analogy. One television, two stubborn kids that want to watch different programs. One has the remote, the other the buttons on the TV. What happens? How do you make both happy. Solve that and get rich ;-). Even better analogy. One inbox. Two people on opposite sides each want 'first dibs' on each item that drops. How do you make them both happy, especially if they are equally stubborn clones? > OK, here's my offer to both of you. Do you have IDLE for Python 2.5 and > have good familiarity with Tkinter? If so, I'll send you the code and > you can try it yourself. My guess is that it will work, and if not, and > you are sufficiently skilled with Tkinter and debugging, you may find > the problem in the code. The steps to create the problem are very easy. That is a request, not an offer. From hniksic at xemacs.org Thu Feb 12 13:02:28 2009 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Thu, 12 Feb 2009 19:02:28 +0100 Subject: Embarrasing questio References: <2dd78188-434d-4c24-bd73-2047105c6a89@q30g2000prq.googlegroups.com> <589cecad-6edd-4a9f-ae84-0791b37d292a@m42g2000yqb.googlegroups.com> Message-ID: <874oyzjzyj.fsf@mulj.homelinux.net> Michele Simionato writes: > On Feb 12, 6:22?pm, MRAB wrote: >> Michele Simionato wrote: >> > On Feb 12, 5:07 pm, TechieInsights wrote: >> >> On Feb 12, 9:03 am, Catherine Heathcote >> >> >> wrote: >> >>> But I just cant find it. How do I do an or, as in c/c++'s ||? Just >> >>> trying to do something simple, the python equivilent of: >> >>> if(i % 3 == 0 || i % 5 == 0) >> >>> Thanks. >> >> in 2.5 and above you can do >> >> if any(i%3 == 0, i%5 == 0) >> >> > You are missing a few parenthesis: if any([i%3 == 0, i%5 == 0]) (but >> > the idiomatic solution is to use or). >> >> any() is really only useful with a generator, otherwise you're always >> evaluating both conditions, unlike the solution with 'or'. > > Indeed. any(f() for f in (lambda: i % 3 == 0, lambda: i % 5 == 0)) :-) From invalid at invalid Thu Feb 12 13:06:09 2009 From: invalid at invalid (Grant Edwards) Date: Thu, 12 Feb 2009 12:06:09 -0600 Subject: Spam References: <467e1f02-47ba-4bd2-ad40-853e3886ff60@40g2000prx.googlegroups.com> <7a9c25c20902120909r3ae5e67cx682603e33c9b3863@mail.gmail.com> <49945B11.9030007@tim.thechases.com> Message-ID: On 2009-02-12, andrew cooke wrote: > Can I read news via secure NNTP (nntps)? > Yes. Point your news reader towards nntps://snews.gmane.org/. > > http://www.gmane.org/faq.php > > I should be working; I will try that this evening. What was the name of > the client that threaded messages with a cute ascii tree?! slrn? -- Grant Edwards grante Yow! How's the wife? at Is she at home enjoying visi.com capitalism? From cosmo_general at yahoo.com Thu Feb 12 13:11:44 2009 From: cosmo_general at yahoo.com (Muddy Coder) Date: Thu, 12 Feb 2009 10:11:44 -0800 (PST) Subject: Help: makefile in Windows Message-ID: <14f4ef16-0af6-4bdd-b195-a768e63aaf7a@j35g2000yqh.googlegroups.com> Hi Folks, I am learning Extending Python, by testing the demo script of Programming Python. In the book, a makefile for Linux is there, but I am using Windows currently. I wish somebody would help me to get a makefile for Windows, my makefile.linux is as below: PYDIR= c:\Python25 PY = $(PYDIR) hello.so: hello.c gcc hello.c -g -I$(PY)/include -I$(PY) -fpic -share -o hello.so clean: rm hello.so core Thanks a lot! Muddy Colder From dear.jay.logan at gmail.com Thu Feb 12 13:11:50 2009 From: dear.jay.logan at gmail.com (josh logan) Date: Thu, 12 Feb 2009 10:11:50 -0800 (PST) Subject: Read Only attributes, auto properties and getters and setters References: <8090b400-dde2-4fc2-8d73-6d1bad3b5aeb@z6g2000pre.googlegroups.com> <61e02f4c-6006-4051-9ad4-9de11bceacea@o6g2000pre.googlegroups.com> <7301e264-0364-4d93-afb3-522f013c1c2e@40g2000prx.googlegroups.com> <6531a55c-194d-432c-acc4-612700abf935@w24g2000prd.googlegroups.com> Message-ID: On Feb 12, 12:27?pm, TechieInsights wrote: > Ok... for some closure I have written a class to automate the > process. ?It takes getters and setters and deleters and then sets the > property automatically. ?Sweet! > > class AutoProperty(type): > ? ? ? ? def __new__(cls, name, bases, methoddict): > ? ? ? ? ? ? ? ? processed = [] > ? ? ? ? ? ? ? ? getter = 'get_' > ? ? ? ? ? ? ? ? setter = 'set_' > ? ? ? ? ? ? ? ? deleter = 'del_' > > ? ? ? ? ? ? ? ? starters = {getter:PropertyAttr(getter, PropertyAttr.FGET), > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? setter:PropertyAttr(setter, PropertyAttr.FSET), > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? deleter:PropertyAttr(deleter, PropertyAttr.FDEL) > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? } > ? ? ? ? ? ? ? ? for key, value in methoddict.items(): > ? ? ? ? ? ? ? ? ? ? ? ? var = None > ? ? ? ? ? ? ? ? ? ? ? ? for start in starters.keys(): > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if key.startswith(start): > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? var = key[len(start):] > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break > ? ? ? ? ? ? ? ? ? ? ? ? if var is None or var in processed: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? continue > ? ? ? ? ? ? ? ? ? ? ? ? property_values = [] > > ? ? ? ? ? ? ? ? ? ? ? ? for start in starters.keys(): > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if '%s%s' %(start, var) in methoddict.keys(): > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? property_values.append(starters[start].tostring(var)) > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? else: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? property_values.append(starters[start].tostring(None)) > ? ? ? ? ? ? ? ? ? ? ? ? property_map = 'methoddict["%s"] = property(%s)' %(var, ','.join > (property_values)) > ? ? ? ? ? ? ? ? ? ? ? ? exec(property_map) > ? ? ? ? ? ? ? ? return type.__new__(cls, name, bases, methoddict) > > class PropertyAttr(object): > ? ? ? ? FGET = 'fget' > ? ? ? ? FSET = 'fset' > ? ? ? ? FDEL = 'fdel' > ? ? ? ? def __init__(self, start, type = FGET): > ? ? ? ? ? ? ? ? self.start = start > ? ? ? ? ? ? ? ? self.type = type > > ? ? ? ? def tostring(self, var): > ? ? ? ? ? ? ? ? if self.type == self.FSET: > ? ? ? ? ? ? ? ? ? ? ? ? vars = ['v'] > ? ? ? ? ? ? ? ? else: > ? ? ? ? ? ? ? ? ? ? ? ? vars = [] > ? ? ? ? ? ? ? ? fullvar = ['self'] + vars > ? ? ? ? ? ? ? ? if var is None: > ? ? ? ? ? ? ? ? ? ? ? ? return '%s=None' %(self.type) > ? ? ? ? ? ? ? ? return '%s=lambda %s: self.%s%s(%s)' %(self.type, ','.join(fullvar), > self.start, var, ','.join(vars)) > > class ReadOnly(object): > ? ? ? ? __metaclass__ = AutoProperty > > class MyClass(ReadOnly): > ? ? ? ? def __init__(self, x, y): > ? ? ? ? ? ? ? ? self.__x = x > ? ? ? ? ? ? ? ? self.__y = y > > ? ? ? ? def get_x(self): > ? ? ? ? ? ? ? ? return self.__x > > ? ? ? ? def set_x(self, x): > ? ? ? ? ? ? ? ? self.__x = x > > ? ? ? ? def get_y(self): > ? ? ? ? ? ? ? ? return self.__y > > mc = MyClass(10, 100) > print mc.x, mc.y > mc.x = 10 > print mc.x > try: > ? ? ? ? mc.y = 100 > except AttributeError: > ? ? ? ? print 'Yea it worked!' > > try: > ? ? ? ? del mc.y > except AttributeError: > ? ? ? ? print "It's read only!" > > And the output: > 10 100 > 10 > Yea it worked! > It's read only! > > Now to work on descriptors doing it for you. I think I'll stick with the built-in, Thanks :) From andrew at acooke.org Thu Feb 12 13:14:33 2009 From: andrew at acooke.org (andrew cooke) Date: Thu, 12 Feb 2009 15:14:33 -0300 (CLST) Subject: Spam In-Reply-To: References: <467e1f02-47ba-4bd2-ad40-853e3886ff60@40g2000prx.googlegroups.com> <7a9c25c20902120909r3ae5e67cx682603e33c9b3863@mail.gmail.com> <49945B11.9030007@tim.thechases.com> Message-ID: <032621e9f3f550d0b980acb9d9cfa40e.squirrel@localhost> Grant Edwards wrote: >> I should be working; I will try that this evening. What was the name of >> the client that threaded messages with a cute ascii tree?! > > slrn? i think i was remembering trn, which is now apparently dead. will try slrn... thanks, andrew From ptmcg at austin.rr.com Thu Feb 12 13:14:36 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Thu, 12 Feb 2009 10:14:36 -0800 (PST) Subject: something wrong with isinstance References: <2a84f320-8be2-4482-9513-4d7edf3295ac@j8g2000yql.googlegroups.com> Message-ID: <153b1a1e-e9eb-4e94-85bf-db019d0d1e55@x10g2000yqk.googlegroups.com> On Feb 12, 11:53?am, maksym.ka... at gmail.com wrote: > Hi there. > now i'm a complete newbie for python, and maybe my problem is stupid > but i cannot solve it myself > > i have an object of class GeoMap which contains lists with objects of > GeoMapCell (i will not explain what they should do, hope its not > important). Then i want to serialize these objects to json notation. > So i imported json module and as shown in docs for it extended > JSONEncoder class. ?Look at the code below > > ##main module > from worldmap import GeoMap, GeoMapCell > > import testdata > import json > > class GeoMapEncoder(json.JSONEncoder): > ? ? def default(self, obj): > ? ? ? ? if isinstance(obj, GeoMap): > ? ? ? ? ? ? return None > ? ? ? ? return json.JSONEncoder.default(self, obj) > > def main(): > ? ? print(json.dumps(2 + 5j, cls=ComplexEncoder)) > > ? ? geomap = testdata.createTestMap() > ? ? print(json.dumps(geomap, cls=GeoMapEncoder)) > ? ? pass > > if __name__ == '__main__': > ? ? main() > > =========== > > ##worldmap module > class GeoMap: > ? ? cells = [] > ? ? activerow = 0 > ? ? activecol = 0 > > ? ? def addCell(self, acell): > ? ? ? ? if len(self.cells) == 0: > ? ? ? ? ? self.cells.append([]) > ? ? ? ? ? self.activerow = 0 > ? ? ? ? acell.col = self.activerow > ? ? ? ? acell.row = self.activecol > ? ? ? ? self.cells[self.activerow].append(acell) > ? ? ? ? self.activecol += 1 > > ? ? def addRow(self): > ? ? ? ? self.cells.append([]) > ? ? ? ? self.activerow += 1; > ? ? ? ? self.activecol = 0; > > class GeoMapCell: > ? ? neighbours = (None, None, None, None, None, None, ) > ? ? col = 0 > ? ? row = 0 > > The problem is in here. > > class GeoMapEncoder(json.JSONEncoder): > ? ? def default(self, obj): > ? ? ? ? if isinstance(obj, GeoMap): ?## <======= ? isinstance doesnot > work as i expected > ? ? ? ? ? ? return None > ? ? ? ? return json.JSONEncoder.default(self, obj) > > ?Though obj is object of GeoMap class, isinstance returns False. Where > was i mistaken. If i shouldn't use isinstance, then what function > would check class of object? > > Oh, maybe its important. I'm working on WinXP SP3, Python 3.0, IDE - > PyScript Here's a crazy idea out of left field. Just before calling isinstance, why not try: print(type(obj)) print(str(obj)) This may illuminate the unexpected behavior, you'll find out just what obj has in it. -- Paul From aahz at pythoncraft.com Thu Feb 12 13:25:38 2009 From: aahz at pythoncraft.com (Aahz) Date: 12 Feb 2009 10:25:38 -0800 Subject: Spam References: <467e1f02-47ba-4bd2-ad40-853e3886ff60@40g2000prx.googlegroups.com> Message-ID: In article , andrew cooke wrote: >Grant Edwards wrote: >>> I should be working; I will try that this evening. What was the name of >>> the client that threaded messages with a cute ascii tree?! >> >> slrn? > >i think i was remembering trn, which is now apparently dead. will try >slrn... thanks, andrew trn 3.6 works fine for me ... just as it has for almost twenty years. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From maksym.kaban at gmail.com Thu Feb 12 13:26:14 2009 From: maksym.kaban at gmail.com (maksym.kaban at gmail.com) Date: Thu, 12 Feb 2009 10:26:14 -0800 (PST) Subject: something wrong with isinstance References: <2a84f320-8be2-4482-9513-4d7edf3295ac@j8g2000yql.googlegroups.com> <153b1a1e-e9eb-4e94-85bf-db019d0d1e55@x10g2000yqk.googlegroups.com> Message-ID: <2d88e036-a529-4364-9fcb-e8fe7446827e@g38g2000yqd.googlegroups.com> > Here's a crazy idea out of left field. ?Just before calling > isinstance, why not try: > > print(type(obj)) > print(str(obj)) > > This may illuminate the unexpected behavior, you'll find out just what > obj has in it. > > -- Paul Well the output of > print(type(obj)) > print(str(obj)) was Just looks well, isn't it? i have no idea what's wrong From tjreedy at udel.edu Thu Feb 12 13:48:45 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 12 Feb 2009 13:48:45 -0500 Subject: openOffic, windows, and Python 2.5 In-Reply-To: References: Message-ID: John Fabiani wrote: > Terry Reedy wrote: > >> John Fabiani wrote: >>> Hi, >>> OpenOffice 3 on windows uses python 2.3.x (I have no idea why). >> I presume because no one has volunteered to do the update for the Py-UNO >> bridge. In any case, why do you consider that to be a problem. It is >> common for apps to include the Python they are known to work with. >> >> tjr > > Thanks for the response. The reason is the others apps are written in > python 2.5.x. All the testing was done on Linux using 2.5 and now we need > it to work on the windows side too. Have you tried it? What breaks? Win OOo's use of 2.3 should only affect Python code that you run within the OO process itself, with its copy of Python. Avoiding things introduced in 2.4/2.5 is probably easier than recompiling OOo on Windows. From ivanov.maxim at gmail.com Thu Feb 12 13:49:52 2009 From: ivanov.maxim at gmail.com (redbaron) Date: Thu, 12 Feb 2009 10:49:52 -0800 (PST) Subject: something wrong with isinstance References: <2a84f320-8be2-4482-9513-4d7edf3295ac@j8g2000yql.googlegroups.com> Message-ID: <8677703b-4284-4283-83a7-ac095eb5af4f@33g2000yqm.googlegroups.com> Don't really sure, but try to define your class as new-style one. Like class GeoMap(object): ... From maksym.kaban at gmail.com Thu Feb 12 13:59:03 2009 From: maksym.kaban at gmail.com (maksym.kaban at gmail.com) Date: Thu, 12 Feb 2009 10:59:03 -0800 (PST) Subject: something wrong with isinstance References: <2a84f320-8be2-4482-9513-4d7edf3295ac@j8g2000yql.googlegroups.com> <8677703b-4284-4283-83a7-ac095eb5af4f@33g2000yqm.googlegroups.com> Message-ID: On 12 ???, 21:49, redbaron wrote: > Don't really sure, but try to define your class as new-style one. > Like > class GeoMap(object): > ? ?... Sorry, it didn't work From jura.grozni at gmail.com Thu Feb 12 14:15:36 2009 From: jura.grozni at gmail.com (azrael) Date: Thu, 12 Feb 2009 11:15:36 -0800 (PST) Subject: is there a project running (GUI Builder for Python ) ? Message-ID: To be honest, in compare to Visual Studio, Gui Builders for wx widgets are really bad. Also completly for python there is not one good GuiBuilder. The only one I have seen that would come near VS was BoaConstructor, But the number of Bugs is just horrific. Too bad that no one is developing it further. Do you know if there is any project curently running for GUI builders, maybe for WX, That I could maybe join. From benjamin at python.org Thu Feb 12 14:22:32 2009 From: benjamin at python.org (Benjamin Peterson) Date: Thu, 12 Feb 2009 19:22:32 +0000 (UTC) Subject: =?utf-8?b?X19pbXBvcnRfXw==?= Confusion References: <5e61a9a8-7caa-4dfc-9454-aa8eddb8e593@z1g2000yqn.googlegroups.com> Message-ID: gmail.com> writes: > > Can someone explain to me what's going on here? > > >>> __import__('some.package.module', {}, {}, []) > > >>> __import__('some.package.module', {}, {}, ['']) > As documented [1], unless fromlist is not empty, the first module is returned. Use the solution at the end of the docs to get around this. [1] http://docs.python.org/library/functions.html#__import__ From btaylordesign at gmail.com Thu Feb 12 14:24:05 2009 From: btaylordesign at gmail.com (Brandon Taylor) Date: Thu, 12 Feb 2009 11:24:05 -0800 (PST) Subject: cx_Oracle-5.0 Problem References: <7fa4a7be-b4ca-4327-9c41-7e35ee2c41ae@x9g2000yqk.googlegroups.com> <68b98811-6352-4b84-952a-c5e0209e8bd3@x9g2000yqk.googlegroups.com> Message-ID: <3e91a7f3-53b3-4454-91b6-d1bd00892010@s20g2000yqh.googlegroups.com> On Feb 12, 9:31?am, redbaron wrote: > > ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.6/ > > lib/python2.6/site-packages/cx_Oracle.so, 2): Symbol not found: > > ___divdi3 > > You didn't link cx_Oracle.so all libs which it use. run "ldd -r > cx_Oracle.so" and you'll have an idea about all missing symbols. The > names of missed symbols could give you an idea what else should > cx_Oracle.so should be linked with We are getting a "command not found" error for the ldd command in OS X 10.5.6 Please advise. From james at agentultra.com Thu Feb 12 14:25:46 2009 From: james at agentultra.com (J Kenneth King) Date: Thu, 12 Feb 2009 14:25:46 -0500 Subject: is there a project running (GUI Builder for Python ) ? References: Message-ID: <85fxijh2yt.fsf@agentultra.com> azrael writes: > To be honest, in compare to Visual Studio, Gui Builders for wx > widgets are really bad. That's because Visual Studio is a Microsoft product to build interfaces for Microsoft products. wx on the other hand is cross platform and ergo, much more complicated. > Do you know if there is any project curently running for GUI > builders, maybe for WX, That I could maybe join. You could help wx. Make your own gui builder if you think you could do better. There's also GTK and Qt... and probably many others. From krmane at gmail.com Thu Feb 12 14:34:10 2009 From: krmane at gmail.com (Krishnakant) Date: Fri, 13 Feb 2009 01:04:10 +0530 Subject: need help from some one who uses python-ooolib Message-ID: <1234467250.10414.155.camel@kk-laptop> hello all, Has any one used python-ooolib to create open office spreadsheets? I want to know the method of merging cells using the library's calc class. happy hacking. Krishnakant. From tjreedy at udel.edu Thu Feb 12 14:34:21 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 12 Feb 2009 14:34:21 -0500 Subject: Spam In-Reply-To: <15b8ac796d4482926d373b153409383c.squirrel@localhost> References: <467e1f02-47ba-4bd2-ad40-853e3886ff60@40g2000prx.googlegroups.com> <7a9c25c20902120909r3ae5e67cx682603e33c9b3863@mail.gmail.com> <49945B11.9030007@tim.thechases.com> <15b8ac796d4482926d373b153409383c.squirrel@localhost> Message-ID: andrew cooke wrote: > A quick search on "imap nntp" turned up this list that might be useful - > http://deflexion.com/messaging/ although I wonder when it was written > because I remember using Aaron's RSS to email aggregator when RSS was > new(!). > > It mentions gmane, though, which certainly still exists (I assume it > carries this list too). Yes. For everything possible, I read and post via gmane. Gmane mirrors technical mailing lists. As near as I can tell, posts via gmane go to the mailing list first, for whatever filtering the list does. Conversely then, gmane only posts the filtered output from the mailing list. > And this page suggests you can read gmane via > nntp - http://reticule.gmane.org/ news.gmane.org works fine. > Aha! yes! It;s in the FAQ :o) > > Can I read news via secure NNTP (nntps)? > Yes. Point your news reader towards nntps://snews.gmane.org/. > > http://www.gmane.org/faq.php From sushiboy21 at gmail.com Thu Feb 12 14:40:57 2009 From: sushiboy21 at gmail.com (S-boy) Date: Thu, 12 Feb 2009 11:40:57 -0800 (PST) Subject: Can't load smtplib Message-ID: <027b7c9e-3e63-4246-99a4-212fe297a260@l1g2000yqj.googlegroups.com> I can't seem to import smtplib in either a script or the command line interpreter. When I try to import smtp, there seems to be some kind of collision with urllib2. I get a weird error about Web server authorization, even though I'm not calling urllib2. Any ideas on what might be causing this? Here's the mess.... Python 2.5.4 (r254:67917, Dec 23 2008, 14:57:27) [GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin >>> import smtplib Traceback (most recent call last): File "", line 1, in File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/smtplib.py", line 46, in import email.Utils File "email.py", line 4, in response = urlopen("https://webmail.canwest.com") File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/urllib2.py", line 124, in urlopen return _opener.open(url, data) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/urllib2.py", line 387, in open response = meth(req, response) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/urllib2.py", line 498, in http_response 'http', request, response, code, msg, hdrs) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/urllib2.py", line 425, in error return self._call_chain(*args) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/urllib2.py", line 360, in _call_chain result = func(*args) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/urllib2.py", line 506, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 401: Unauthorized ( The server requires authorization to fulfill the request. Access to the Web server is denied. Contact the server administrator. ) From stef.mientki at gmail.com Thu Feb 12 14:41:17 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Thu, 12 Feb 2009 20:41:17 +0100 Subject: is there a project running (GUI Builder for Python ) ? In-Reply-To: References: Message-ID: <49947B5D.4000202@gmail.com> azrael wrote: > To be honest, in compare to Visual Studio, Gui Builders for wx widgets > are really bad. Also completly for python there is not one good > GuiBuilder. The only one I have seen that would come near VS was > BoaConstructor, But the number of Bugs is just horrific. Too bad that > no one is developing it further. > > Do you know if there is any project curently running for GUI builders, > maybe for WX, That I could maybe join. > -- > http://mail.python.org/mailman/listinfo/python-list > Well I come from Delphi, and compared to Delphi, even Visual Studio vanishes ;-) I also tried to start with wxGlad, Boa, XRC .... ... but they were full of bugs, or even couldn't be started. The best seems to be PyQt, but the license is (still) terrible (and maybe only their stories are much better than the real result ;-). I didn't try XRC, because I found it much too difficult, but instead I wrote a small program, making a much easier version of the XRC-idea. And after a few months, I don't even notice the difference between Delphi (which I'm still using) and wxPython. I think this story happened to other people to, so instead of putting a lot of effort in designing and maintaining a GUI builders, it might be better to choose another solution. btw, the idea I used, can be seen here] http://mientki.ruhosting.nl/data_www/pylab_works/pw_gui_support.html and the code can be found here http://code.google.com/p/pylab-works/downloads/list cheers, Stef From tjreedy at udel.edu Thu Feb 12 14:42:46 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 12 Feb 2009 14:42:46 -0500 Subject: Spam In-Reply-To: References: <467e1f02-47ba-4bd2-ad40-853e3886ff60@40g2000prx.googlegroups.com> <7a9c25c20902120909r3ae5e67cx682603e33c9b3863@mail.gmail.com> <49945B11.9030007@tim.thechases.com> <15b8ac796d4482926d373b153409383c.squirrel@localhost> Message-ID: Terry Reedy wrote: > andrew cooke wrote: >> A quick search on "imap nntp" turned up this list that might be useful - >> http://deflexion.com/messaging/ although I wonder when it was written >> because I remember using Aaron's RSS to email aggregator when RSS was >> new(!). >> >> It mentions gmane, though, which certainly still exists (I assume it >> carries this list too). > > Yes. For everything possible, I read and post via gmane. Gmane mirrors > technical mailing lists. As near as I can tell, posts via gmane go to > the mailing list first, for whatever filtering the list does. Conversely > then, gmane only posts the filtered output from the mailing list. > > > And this page suggests you can read gmane via >> nntp - http://reticule.gmane.org/ > > news.gmane.org works fine. > >> Aha! yes! It;s in the FAQ :o) >> >> Can I read news via secure NNTP (nntps)? >> Yes. Point your news reader towards nntps://snews.gmane.org/. >> >> http://www.gmane.org/faq.php I just switched my Thunderbird gmane account to snews... and [x] use ssl and it seems to work ok. It did, however, reset everything to unread. From exarkun at divmod.com Thu Feb 12 14:50:42 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Thu, 12 Feb 2009 14:50:42 -0500 Subject: Can't load smtplib In-Reply-To: <027b7c9e-3e63-4246-99a4-212fe297a260@l1g2000yqj.googlegroups.com> Message-ID: <20090212195042.12853.200194161.divmod.quotient.9312@henry.divmod.com> On Thu, 12 Feb 2009 11:40:57 -0800 (PST), S-boy wrote: >I can't seem to import smtplib in either a script or the command line >interpreter. > >When I try to import smtp, there seems to be some kind of collision >with urllib2. I get a weird error about Web server authorization, even >though I'm not calling urllib2. > >Any ideas on what might be causing this? > >Here's the mess.... > >Python 2.5.4 (r254:67917, Dec 23 2008, 14:57:27) >[GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin > >>>> import smtplib > >Traceback (most recent call last): > File "", line 1, in > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ >python2.5/smtplib.py", line 46, in > import email.Utils > File "email.py", line 4, in Ooops. Here's your problem. Notice how that's not /Library/Frameworks/Python.framework/Versions/2.5/lib/ >python2.5/email/? You have an "email" module that's obscuring the stdlib email package. > response = urlopen("https://webmail.canwest.com") > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ >python2.5/urllib2.py", line 124, in urlopen > return _opener.open(url, data) > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ >python2.5/urllib2.py", line 387, in open > response = meth(req, response) > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ >python2.5/urllib2.py", line 498, in http_response > 'http', request, response, code, msg, hdrs) > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ >python2.5/urllib2.py", line 425, in error > return self._call_chain(*args) > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ >python2.5/urllib2.py", line 360, in _call_chain > result = func(*args) > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ >python2.5/urllib2.py", line 506, in http_error_default > raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) >urllib2.HTTPError: HTTP Error 401: Unauthorized ( The server requires >authorization to fulfill the request. Access to the Web server is >denied. Contact the server administrator. ) Jean-Paul From ptmcg at austin.rr.com Thu Feb 12 14:56:40 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Thu, 12 Feb 2009 11:56:40 -0800 (PST) Subject: something wrong with isinstance References: <2a84f320-8be2-4482-9513-4d7edf3295ac@j8g2000yql.googlegroups.com> <153b1a1e-e9eb-4e94-85bf-db019d0d1e55@x10g2000yqk.googlegroups.com> <2d88e036-a529-4364-9fcb-e8fe7446827e@g38g2000yqd.googlegroups.com> Message-ID: <1e02747f-3058-4e9b-b971-e2500da500d2@z1g2000yqn.googlegroups.com> On Feb 12, 12:26?pm, maksym.ka... at gmail.com wrote: > > Well the output of > > > print(type(obj)) > > print(str(obj)) > > was > > > > > Just looks well, isn't it? i have no idea what's wrong So then how do you know isinstance is evaluating to False? And why do you return None if it evals to True? Can you drop a print command inside the if block just before returning None, and another print just before returning the default default? I also would recommend using a debugger like winpdb when in a spot like this - despite the name, it is not Windows-only, and you can step through this code and evaluate variables and expressions inline. -- Paul From deets at nospam.web.de Thu Feb 12 14:56:43 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 12 Feb 2009 20:56:43 +0100 Subject: something wrong with isinstance In-Reply-To: <2a84f320-8be2-4482-9513-4d7edf3295ac@j8g2000yql.googlegroups.com> References: <2a84f320-8be2-4482-9513-4d7edf3295ac@j8g2000yql.googlegroups.com> Message-ID: <6vjd7rFjdhqrU1@mid.uni-berlin.de> maksym.kaban at gmail.com schrieb: > Hi there. > now i'm a complete newbie for python, and maybe my problem is stupid > but i cannot solve it myself > > i have an object of class GeoMap which contains lists with objects of > GeoMapCell (i will not explain what they should do, hope its not > important). Then i want to serialize these objects to json notation. > So i imported json module and as shown in docs for it extended > JSONEncoder class. Look at the code below > > ##main module > from worldmap import GeoMap, GeoMapCell > > import testdata > import json > > class GeoMapEncoder(json.JSONEncoder): > def default(self, obj): > if isinstance(obj, GeoMap): > return None > return json.JSONEncoder.default(self, obj) > > def main(): > print(json.dumps(2 + 5j, cls=ComplexEncoder)) > > geomap = testdata.createTestMap() > print(json.dumps(geomap, cls=GeoMapEncoder)) > pass > > if __name__ == '__main__': > main() > > =========== > > ##worldmap module > class GeoMap: > cells = [] > activerow = 0 > activecol = 0 > > def addCell(self, acell): > if len(self.cells) == 0: > self.cells.append([]) > self.activerow = 0 > acell.col = self.activerow > acell.row = self.activecol > self.cells[self.activerow].append(acell) > self.activecol += 1 > > def addRow(self): > self.cells.append([]) > self.activerow += 1; > self.activecol = 0; > > class GeoMapCell: > neighbours = (None, None, None, None, None, None, ) > col = 0 > row = 0 > > The problem is in here. > > class GeoMapEncoder(json.JSONEncoder): > def default(self, obj): > if isinstance(obj, GeoMap): ## <======= isinstance doesnot > work as i expected > return None > return json.JSONEncoder.default(self, obj) > > Though obj is object of GeoMap class, isinstance returns False. Where > was i mistaken. If i shouldn't use isinstance, then what function > would check class of object? > > Oh, maybe its important. I'm working on WinXP SP3, Python 3.0, IDE - > PyScript I think you have a common problem here that occurs when using a script with more that non-trivial contents as main-script. What happens is this: you have a __main__.GeoMap, which is the one tested against in isinstance. *And* you have a .GeoMap (replace with the actual name) that is imported & used from the other module. A simple testscript illustrates the issue: ### test.py #### class Foo(object): pass if __name__ == "__main__": import test print Foo == test.Foo Run it from inside the directory you saved it in. To work around this issue, simply create a bootstrap-main-module that has not much in it. Diez From deets at nospam.web.de Thu Feb 12 14:58:28 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 12 Feb 2009 20:58:28 +0100 Subject: Capture images in macOS X In-Reply-To: References: Message-ID: <6vjdb4FjdhqrU2@mid.uni-berlin.de> Jonathan Chac?n schrieb: > Hello, > > I need to capture images from the macbook webcam in leopard. > Does anybody know how can I do this? Use the pyobjc bridge & some ObjectiveC-framework such as CocoaSequenceGrabber. http://www.skyfell.org/cocoasequencegrabber.html There are similar ones out there. Diez From vincent at vincentdavis.net Thu Feb 12 15:01:32 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Thu, 12 Feb 2009 13:01:32 -0700 Subject: Spam In-Reply-To: References: <467e1f02-47ba-4bd2-ad40-853e3886ff60@40g2000prx.googlegroups.com> <7a9c25c20902120909r3ae5e67cx682603e33c9b3863@mail.gmail.com> <49945B11.9030007@tim.thechases.com> <15b8ac796d4482926d373b153409383c.squirrel@localhost> Message-ID: <77e831100902121201v5820dac8p4f9399fa68a0d332@mail.gmail.com> I am a little disturbed that there are no moderators, mostly because I received an email back from the list"Your mail to 'Python-list' with the subject. Above and beyond, critique request. Is being held until the list moderator can review it for approval. The reason it is being held: Message body is too big: 41670 bytes with a limit of 40 KB. Either the message will get posted to the list, or you will receive notification of the moderator's decision. If you would like to cancel this posting, please visit the following URL:" So does this mean it will never actually be reviewed? Thanks Vincent Davis On Thu, Feb 12, 2009 at 12:42 PM, Terry Reedy wrote: > Terry Reedy wrote: > >> andrew cooke wrote: >> >>> A quick search on "imap nntp" turned up this list that might be useful - >>> http://deflexion.com/messaging/ although I wonder when it was written >>> because I remember using Aaron's RSS to email aggregator when RSS was >>> new(!). >>> >>> It mentions gmane, though, which certainly still exists (I assume it >>> carries this list too). >>> >> >> Yes. For everything possible, I read and post via gmane. Gmane mirrors >> technical mailing lists. As near as I can tell, posts via gmane go to the >> mailing list first, for whatever filtering the list does. Conversely then, >> gmane only posts the filtered output from the mailing list. >> >> > And this page suggests you can read gmane via >> >>> nntp - http://reticule.gmane.org/ >>> >> >> news.gmane.org works fine. >> >> Aha! yes! It;s in the FAQ :o) >>> >>> Can I read news via secure NNTP (nntps)? >>> Yes. Point your news reader towards nntps://snews.gmane.org/. >>> >>> http://www.gmane.org/faq.php >>> >> > I just switched my Thunderbird gmane account to snews... and [x] use ssl > and it seems to work ok. It did, however, reset everything to unread. > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jura.grozni at gmail.com Thu Feb 12 15:04:55 2009 From: jura.grozni at gmail.com (azrael) Date: Thu, 12 Feb 2009 12:04:55 -0800 (PST) Subject: A little bit else I would like to discuss Message-ID: <7f4cd287-dad4-4605-8b96-5edfdacc3da2@a12g2000yqm.googlegroups.com> Sometimes I really get confused when looking out for a modul for some kind of need. Sometimes I get frightened when I get the resaults. 8 wraper for this, 7 wrapers for that, 10 modules for anything. Between them are maybe some kind of small differences, but to work with any of the modules, I have to spend 10 hours of reading the help, If there is any at all. I think that there should be a list on python.org of supported or sugested modules for some need. For example Database access. Or GUI Building. It is a complete pain in the ass. Let's face the true, TK is out of date. There should be another one used and appended to the standard Python Library. One that plays well with other platforms. And if it does't, let's make it play better. Why will Microsoft's products kick the ass of open source. Because anyone does what he wants. Let's say There are 5 GUI libraries competing against each other. Think about it what could these 5 teams acomplish if they would work together. Or maybe a framework for RAD GUI devbelopment. after 10 years of python, there is still not one application for GUI Building that can beat Visual Studio. Anyone I talk to says: "Oh my god, Python and GUI" There are a dozen of modules that should be, if you ask me, be implemented into Python. Like NumPy, SciPY, PIL. A lot of people I talk to, are using them. But everyone has to download them manually and hope that if someone is using their code, has also installed the needed modules. My solution would be: Let's make an announcement on Python.org. something like this. We need Ideas for creating the a standard library in Python for Image processing. Tell us your problem. What do you think which feature should be implemented. Which transformation, which algorithm. Make a vote. This should be that not. But how to start something like that. Anyone that sees a problem that should be solved, becomes the project leader. Find the best Ideas and make a good library. It's is very good that people have a choice. But why not make some standards. I know that there is already a standard python library, But why not extending it. classify the standard library into subcategories like Networking, DataBase, Computation, ...... One other thing. I am not looking for war on groups. I just would like to discuss some things that drive me crazy while using Python. This group has a lot of members. not to mention every Python Forum. Why not using this number of people and accomplish something great. If anyone of us would write 10 line of good code, it would result a very great and powerfull environment. From jura.grozni at gmail.com Thu Feb 12 15:11:41 2009 From: jura.grozni at gmail.com (azrael) Date: Thu, 12 Feb 2009 12:11:41 -0800 (PST) Subject: is there a project running (GUI Builder for Python ) ? References: <85fxijh2yt.fsf@agentultra.com> Message-ID: <4f44bff6-d0fc-496c-9055-a50fdd06f339@c12g2000yqj.googlegroups.com> On Feb 12, 8:25?pm, J Kenneth King wrote: > azrael writes: > > To be honest, in compare to Visual Studio, Gui Builders for wx > > widgets are really bad. > > That's because Visual Studio is a Microsoft product to build > interfaces for Microsoft products. > > wx on the other hand is cross platform and ergo, much more > complicated. > I think that WX is really great but there is really a great lack of a builder. > > Do you know if there is any project curently running for GUI > > builders, maybe for WX, That I could maybe join. > > You could help wx. Make your own gui builder if you think you could do > better. There's also GTK and Qt... and probably many others. I think that this would be a great mistake. Let's sit down and make my own gui builder. I think That some people should sit together and discuss what we need to make a good GUI builder. I am in. Who would like to join me. From philip at semanchuk.com Thu Feb 12 15:15:12 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Thu, 12 Feb 2009 15:15:12 -0500 Subject: A little bit else I would like to discuss In-Reply-To: <7f4cd287-dad4-4605-8b96-5edfdacc3da2@a12g2000yqm.googlegroups.com> References: <7f4cd287-dad4-4605-8b96-5edfdacc3da2@a12g2000yqm.googlegroups.com> Message-ID: On Feb 12, 2009, at 3:04 PM, azrael wrote: > Why will Microsoft's products kick the ass of open source. Because > anyone does what he wants. Let's say There are 5 GUI libraries > competing against each other. Think about it what could these 5 teams > acomplish if they would work together. Or maybe a framework for RAD > GUI devbelopment. after 10 years of python, there is still not one > application for GUI Building that can beat Visual Studio. Let me know when Visual Studio tries to address building GUIs for Windows, OS X, Gnome, and KDE. Until then, you're comparing apples to oranges, or chalk and cheese if you're from that part of the world. From jura.grozni at gmail.com Thu Feb 12 15:18:38 2009 From: jura.grozni at gmail.com (azrael) Date: Thu, 12 Feb 2009 12:18:38 -0800 (PST) Subject: A little bit else I would like to discuss Message-ID: <98e33cd6-aa9d-4626-9f07-20fe5984bfbb@j38g2000yqa.googlegroups.com> Sometimes I really get confused when looking out for a modul for some kind of need. Sometimes I get frightened when I get the resaults. 8 wraper for this, 7 wrapers for that, 10 modules for anything. Between them are maybe some kind of small differences, but to work with any of the modules, I have to spend 10 hours of reading the help, If there is any at all. I think that there should be a list on python.org of supported or sugested modules for some need. For example Database access. Or GUI Building. It is a complete pain in the ass. Let's face the true, TK is out of date. There should be another one used and appended to the standard Python Library. One that plays well with other platforms. And if it does't, let's make it play better. Why will Microsoft's products kick the ass of open source. Because anyone does what he wants. Let's say There are 5 GUI libraries competing against each other. Think about it what could these 5 teams acomplish if they would work together. Or maybe a framework for RAD GUI devbelopment. after 10 years of python, there is still not one application for GUI Building that can beat Visual Studio. Anyone I talk to says: "Oh my god, Python and GUI" There are a dozen of modules that should be, if you ask me, be implemented into Python. Like NumPy, SciPY, PIL. A lot of people I talk to, are using them. But everyone has to download them manually and hope that if someone is using their code, has also installed the needed modules. My solution would be: Let's make an announcement on Python.org. something like this. We need Ideas for creating the a standard library in Python for Image processing. Tell us your problem. What do you think which feature should be implemented. Which transformation, which algorithm. Make a vote. This should be that not. But how to start something like that. Anyone that sees a problem that should be solved, becomes the project leader. Find the best Ideas and make a good library. It's is very good that people have a choice. But why not make some standards. I know that there is already a standard python library, But why not extending it. classify the standard library into subcategories like Networking, DataBase, Computation, ...... One other thing. I am not looking for war on groups. I just would like to discuss some things that drive me crazy while using Python. This group has a lot of members. not to mention every Python Forum. Why not using this number of people and accomplish something great. If anyone of us would write 10 line of good code, it would result a very great and powerfull environment. From gervaz at gmail.com Thu Feb 12 15:20:39 2009 From: gervaz at gmail.com (mattia) Date: 12 Feb 2009 20:20:39 GMT Subject: Library similar to UserAgent (perl) References: <49933ca6$0$1125$4fafbaef@reader1.news.tin.it> <6vik2dFk1ph9U1@mid.uni-berlin.de> Message-ID: <49948497$0$1123$4fafbaef@reader2.news.tin.it> Il Thu, 12 Feb 2009 13:47:09 +0100, Diez B. Roggisch ha scritto: > mattia wrote: > >> Hi everybody, I'm looking for an easy way to put data in a form, then >> click the button and follow the redirect. Also I need to use cookies. I >> read that using perl this can be done using the UserAgent lib, that >> also provide th browser functionality to let the site believe that you >> are getting the pages from a normali browser like ff. Any suggestion? I >> think that the main concen is to easilly put the data in the numerous >> textlabel provided and then magically simulate the 'click me' button. > > Python mechanize. > > Diez Thanks a lot. Mattia From steve at holdenweb.com Thu Feb 12 15:22:28 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 12 Feb 2009 15:22:28 -0500 Subject: hpw to convert a linux python script ? In-Reply-To: <1ac73184-be09-4b56-8ad1-7cd4896e0f7c@z6g2000pre.googlegroups.com> References: <8848a16f-83db-4acf-a1cc-46653869f27c@z1g2000yqn.googlegroups.com> <1ac73184-be09-4b56-8ad1-7cd4896e0f7c@z6g2000pre.googlegroups.com> Message-ID: John Machin wrote: > On Feb 12, 7:48 am, Stef Mientki wrote: >> Alec Schueler wrote: >>> On Feb 11, 7:58 pm, Stef Mientki wrote: >>>> As there are a whole lot of these lines, in a whole lot of files, >>>> I wonder if there's a simple trick to point >>>> /usr/share/tinybldLin/ >>>> to my directory ? >>>> thanks, >>>> Stef >>> Find and replace? >> well I was thinking of a more elegant way, >> so the scripts remains, or better become multi-platform. > > Your current setup is not even single-platform portable ... consider > the scenario where some Linux admin wants your gear to live in some > directory other than /usr/share/tinybldLin/ > > The standard technique for ensuring that kind of portability involves: > 1. Find the directory in which your script lives. Inspect sys.argv[0], > use some os.path.some_functionality() to extract the directory, name > it (say) home_base. > 2. When you want to open a data file in the script's directory, do > this: > the_path = os.path.join(home_base, 'stef1.dat') > f = open(the_path, .....) > > NOTE: Use os.path.join() instead of some DIY technique; it knows > better than you what the path separator is on the OS it's being run > on. In fact, read the whole of the os.path manual carefully before you > jump in to changing your code. > > If you prefer to have the data files in (say) .../script_locn/data > instead of .../script_locn, the adjustment should be obvious. > > Unfortunately, you are still going to need use find and replace to fix > your script. Code in haste, repent at leisure :-) > Of course the real issue here is that the same hard-coded directory name (or possibly multiple directory names all rooted in the same directory) are scattered throughout the program. Your (the OP's) first task should be to store that "root" directory in a variable and then use the variable in place of all current uses of the root directory. For example, I have a Django project that I like to run under both Windows and Cygwin. So in my settings.py file I have: # Django settings for PyTeach project. import sys if sys.platform == 'cygwin': fsroot = "/home/sholden" elif sys.platform == 'win32': fsroot = "C:/Users/sholden/Documents" else: sys.exit("Only configured for Windows and Cygwin") Than further down I have # Absolute path to the directory that holds media. # Example: "/home/media/media.lawrence.com/" MEDIA_ROOT = fsroot+'/Projects/PytDj/images/' Note that most Windows APIs allow you to use the forward slash as a delimiter. It's mostly the command line and Windows Explorer that are snotty about insisting on the backslash. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From mail at timgolden.me.uk Thu Feb 12 15:24:33 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 12 Feb 2009 20:24:33 +0000 Subject: A little bit else I would like to discuss In-Reply-To: References: <7f4cd287-dad4-4605-8b96-5edfdacc3da2@a12g2000yqm.googlegroups.com> Message-ID: <49948581.6070001@timgolden.me.uk> Philip Semanchuk wrote: > > On Feb 12, 2009, at 3:04 PM, azrael wrote: > >> Why will Microsoft's products kick the ass of open source. Because >> anyone does what he wants. Let's say There are 5 GUI libraries >> competing against each other. Think about it what could these 5 teams >> acomplish if they would work together. Or maybe a framework for RAD >> GUI devbelopment. after 10 years of python, there is still not one >> application for GUI Building that can beat Visual Studio. > > Let me know when Visual Studio tries to address building GUIs for > Windows, OS X, Gnome, and KDE. Until then, you're comparing apples to > oranges, or chalk and cheese if you're from that part of the world. While your point is obviously good, it only applies if you even care about building for OS X, Gnome etc. If all you want is build on Windows (or Gnome or KDE or whatever) then the cross-platformness of any proposed toolkit is worthless and may even be a drawback if it reduces its functionality to a lowest common denominator. I have nothing really to say about GUI-building whatsits in general; I don't have cause to use them myself so I simply stand back and let their proponents fight it out. I just wanted to point out that playing the cross-platform card does not mean the game is over. TJG From lists at cheimes.de Thu Feb 12 15:40:24 2009 From: lists at cheimes.de (Christian Heimes) Date: Thu, 12 Feb 2009 21:40:24 +0100 Subject: A little bit else I would like to discuss In-Reply-To: <7f4cd287-dad4-4605-8b96-5edfdacc3da2@a12g2000yqm.googlegroups.com> References: <7f4cd287-dad4-4605-8b96-5edfdacc3da2@a12g2000yqm.googlegroups.com> Message-ID: azrael wrote: > I think that there should be a list on python.org of supported or > sugested modules for some need. For example Database access. Or GUI > Building. It is a complete pain in the ass. Let's face the true, TK is > out of date. There should be another one used and appended to the > standard Python Library. One that plays well with other platforms. And > if it does't, let's make it play better. The Python core will not ship with another GUI toolkit. TK may be removed from the core in some distant future but we - the Python core development team - will *not* make a choice between GTK, WX and Qt. > One other thing. I am not looking for war on groups. I just would like > to discuss some things that drive me crazy while using Python. In your opinion all third party are bad. You like to have one monolithic block of software. That's a typical Microsoft approach. Lot's of people from the open source community prefer small and loosely coupled pieces of software. One of the greatest ruler of all time once said "divide et impera" -- divide it in small pieces to make it much easier to conquer every piece by its own. We are following the same path here. Nobody is going to stop you from creating a large bundle of useful extensions as long as you follow the licenses. In fact lots of people may appreciate a bundle. But the Python core package will always stay small and agile. Christian From lists at cheimes.de Thu Feb 12 15:42:14 2009 From: lists at cheimes.de (Christian Heimes) Date: Thu, 12 Feb 2009 21:42:14 +0100 Subject: is there a project running (GUI Builder for Python ) ? In-Reply-To: <4f44bff6-d0fc-496c-9055-a50fdd06f339@c12g2000yqj.googlegroups.com> References: <85fxijh2yt.fsf@agentultra.com> <4f44bff6-d0fc-496c-9055-a50fdd06f339@c12g2000yqj.googlegroups.com> Message-ID: azrael wrote: > On Feb 12, 8:25 pm, J Kenneth King wrote: >> azrael writes: >>> To be honest, in compare to Visual Studio, Gui Builders for wx >>> widgets are really bad. >> That's because Visual Studio is a Microsoft product to build >> interfaces for Microsoft products. >> >> wx on the other hand is cross platform and ergo, much more >> complicated. >> > > I think that WX is really great but there is really a great lack of a > builder. This isn't a Python problem - really. Please discuss your issues with the WX Gui builder on a WX list. We can't do anything about it. Christian From gc_ottawa at yahoo.ca Thu Feb 12 15:53:13 2009 From: gc_ottawa at yahoo.ca (gc_ottawa at yahoo.ca) Date: Thu, 12 Feb 2009 12:53:13 -0800 (PST) Subject: is there a project running (GUI Builder for Python ) ? References: Message-ID: ......I come from Delphi, and compared to Delphi, even Visual Studio > vanishes ;-) ...........I don't even notice the difference between Delphi (which I'm still using) > and wxPython. > > I think this story happened to other people to, > so instead of putting a lot of effort in designing and maintaining a GUI > builders, > it might be better to choose another solution. > > btw, the idea I used, can be seen here]http://mientki.ruhosting.nl/data_www/pylab_works/pw_gui_support.html > and the code can be found herehttp://code.google.com/p/pylab-works/downloads/list > > cheers, > Stef You know, 10 or more years ago both Borland and Microsoft got it right when they incorporated a GUI with an IDE in their Delphi and Visual Basic products. As wonderful as the Python language is, it is very much a work in progress when compared to the ease of use of the aforementioned products. These products revolutionized the industry with their "Rapid Applications Development" (RAD). Python reminds me of a toolbox filled with a multitude of single use tools when all you need is a Skilsaw and a combination screwdriver. Gord From joshua at joshuakugler.com Thu Feb 12 16:22:15 2009 From: joshua at joshuakugler.com (Joshua Kugler) Date: Thu, 12 Feb 2009 12:22:15 -0900 Subject: Change in cgi module's handling of POST requests References: <4991E16F.3010407@rksystems.com> Message-ID: Bob Kline wrote: > [Didn't realize the mirror didn't work both ways] > > We just upgraded Python to 2.6 on some of our servers and a number of our > CGI scripts broke because the cgi module has changed the way it handles > POST requests. > When the 'action' attribute was not present in the form > element on an HTML page the module behaved as if the value of the > attribute was the URL which brought the user to the page with the form, > but without the query (?x=y...) part. This does not make sense. Can you give an example? When you POST, the attributes are not appended to the URL, but form encoded. > Now FieldStorage.getvalue () is > giving the script a list of two copies of the value for some of the > parameters (folding in the parameters from the previous request) instead > of the single string it used to return for each. There is a function call to get only one value. I think it's get_first() or some such. Well, the CGI module hasn't had many changes. There was this bug fix a few months back: http://svn.python.org/view?rev=64447&view=rev Diff to previous: http://svn.python.org/view/python/trunk/Lib/cgi.py?rev=64447&r1=58218&r2=64447 For all revisions: http://svn.python.org/view/python/trunk/Lib/cgi.py?rev=67528&view=log It is possible that by fixing a bug, they brought the behavior in line with what it *should* be. Or maybe the browser behavior changed? The server does not care about an "action" attribute. That only tells the browser where to send the data. It is possible the browser did not properly format a request when there was no "action" attribute. Can you provide more details? j From argo785 at gmail.com Thu Feb 12 16:23:54 2009 From: argo785 at gmail.com (argo785 at gmail.com) Date: Thu, 12 Feb 2009 13:23:54 -0800 (PST) Subject: Thank you, Tkinter. (easy to use) References: Message-ID: <65f014fd-2013-48ec-9f2e-ae0527714e24@p13g2000yqc.googlegroups.com> On Feb 12, 4:29?am, "Eric Brunel" wrote: > On Thu, 12 Feb 2009 06:06:06 +0100, wrote: > > [snip] > > > My only (minor) complaint is that Tk > > doesn't draw text antialiased in the various widgets (menus, labels, > > buttons, etc.). > > ?From version 8.5 of tcl/tk, it's supposed to do it. See this page:http://www.tcl.tk/software/tcltk/8.5.tml > under 'Highlights of Tk 8.5', item 'Font rendering'. It seems to talk only ? > about X11 and Mac OS X; don't know if it works on Windows... Looking forward to it. Searching around some more, also found this: http://tkinter.unpythonic.net/wiki/Tk85AndPython which sheds a little light. And following a link therein, it would seem that we'll have it by default with Python 2.7/3.1 -- [this bug](http://bugs.python.org/ issue2983) was closed about 2 weeks ago. From hamish at valvesoftware.com Thu Feb 12 16:26:26 2009 From: hamish at valvesoftware.com (Hamish McKenzie) Date: Thu, 12 Feb 2009 13:26:26 -0800 Subject: getting caller Message-ID: so I'm trying to wrap some functionality around execfile but don't want to modify the way it works. specifically when you call execfile, it automatically grabs globals and locals from the frame the execfile exists in. so if I wrap execfile in a function, I need a way to reliably get at the calling frame. what I want to know is - is it *ALWAYS* true that: inspect.getouterframes( inspect.currentframe() )[ 1 ][ 0 ] will return me the frame that called execfile in the first place? I can't think of a way that this wouldn't be the case, but I'm not 100% sure that assertion is valid. -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin at marcher.name Thu Feb 12 16:36:20 2009 From: martin at marcher.name (Martin) Date: Thu, 12 Feb 2009 22:36:20 +0100 Subject: A little bit else I would like to discuss In-Reply-To: References: <7f4cd287-dad4-4605-8b96-5edfdacc3da2@a12g2000yqm.googlegroups.com> Message-ID: <5fa6c12e0902121336w6716187awc9495f852791988d@mail.gmail.com> Hi, at first I wanted to file this under meta-discussions, but your lost paragraph got me thinking... 2009/2/12 Christian Heimes : > Nobody is going to stop you from creating a large bundle of useful > extensions as long as you follow the licenses. In fact lots of people > may appreciate a bundle. But the Python core package will always stay > small and agile. How does "small and agile" work with "batteries included"? >From my point of view: agile:: Would describe faster extension of the standard lib (rrd, yaml should IMHO already be in the standard lib). I'm pretty sure other people want to see other modules, but that's what agile + standard lib would mean for me. (Also I'm sometimes confused by the naming of modules but that's a different story) small:: just the opposite of "batteries included" My absolute favorite would be * python as just python (no standard lib) * a (rather) fast moving standard lib available as an addon download * possibly for each version I guess that would mean *a lot* maintenance overhead so that will probably never. Finally: Ignore me, Python is still the language that let's me get stuff done in the fastest and most enjoyable way. Thanks to GvR for the initial idea and all the volounteers for making it even better :) -- http://soup.alt.delete.co.at http://www.xing.com/profile/Martin_Marcher http://www.linkedin.com/in/martinmarcher You are not free to read this message, by doing so, you have violated my licence and are required to urinate publicly. Thank you. Please avoid sending me Word or PowerPoint attachments. See http://www.gnu.org/philosophy/no-word-attachments.html From martin at marcher.name Thu Feb 12 16:36:51 2009 From: martin at marcher.name (Martin) Date: Thu, 12 Feb 2009 22:36:51 +0100 Subject: A little bit else I would like to discuss In-Reply-To: <5fa6c12e0902121336w6716187awc9495f852791988d@mail.gmail.com> References: <7f4cd287-dad4-4605-8b96-5edfdacc3da2@a12g2000yqm.googlegroups.com> <5fa6c12e0902121336w6716187awc9495f852791988d@mail.gmail.com> Message-ID: <5fa6c12e0902121336j7168bfe6ofeeb194f5851e17b@mail.gmail.com> Oh yeah and ignore my typos also :) 2009/2/12 Martin : > Hi, > > at first I wanted to file this under meta-discussions, but your lost > paragraph got me thinking... > > 2009/2/12 Christian Heimes : >> Nobody is going to stop you from creating a large bundle of useful >> extensions as long as you follow the licenses. In fact lots of people >> may appreciate a bundle. But the Python core package will always stay >> small and agile. > > How does "small and agile" work with "batteries included"? > > From my point of view: > > agile:: > Would describe faster extension of the standard lib (rrd, yaml should > IMHO already be in the standard lib). I'm pretty sure other people > want to see other modules, but that's what agile + standard lib would > mean for me. (Also I'm sometimes confused by the naming of modules but > that's a different story) > > small:: > just the opposite of "batteries included" > > My absolute favorite would be > > * python as just python (no standard lib) > * a (rather) fast moving standard lib available as an addon download > * possibly for each version > > I guess that would mean *a lot* maintenance overhead so that will > probably never. > > Finally: Ignore me, Python is still the language that let's me get > stuff done in the fastest and most enjoyable way. Thanks to GvR for > the initial idea and all the volounteers for making it even better :) > > > -- > http://soup.alt.delete.co.at > http://www.xing.com/profile/Martin_Marcher > http://www.linkedin.com/in/martinmarcher > > You are not free to read this message, > by doing so, you have violated my licence > and are required to urinate publicly. Thank you. > > Please avoid sending me Word or PowerPoint attachments. > See http://www.gnu.org/philosophy/no-word-attachments.html > -- http://soup.alt.delete.co.at http://www.xing.com/profile/Martin_Marcher http://www.linkedin.com/in/martinmarcher You are not free to read this message, by doing so, you have violated my licence and are required to urinate publicly. Thank you. Please avoid sending me Word or PowerPoint attachments. See http://www.gnu.org/philosophy/no-word-attachments.html From Scott.Daniels at Acm.Org Thu Feb 12 16:40:33 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 12 Feb 2009 13:40:33 -0800 Subject: Help: makefile in Windows In-Reply-To: <14f4ef16-0af6-4bdd-b195-a768e63aaf7a@j35g2000yqh.googlegroups.com> References: <14f4ef16-0af6-4bdd-b195-a768e63aaf7a@j35g2000yqh.googlegroups.com> Message-ID: <1LydnXXXgdpNCwnUnZ2dnUVZ_sjinZ2d@pdx.net> Muddy Coder wrote: > Hi Folks, > > I am learning Extending Python, by testing the demo script of > Programming Python. In the book, a makefile for Linux is there, but I > am using Windows currently. I wish somebody would help me to get a > makefile for Windows, my makefile.linux is as below: Use distutils, and write a setup.py. You will want to use mingw32. Searching for "building python25 C extensions mingw32" should point you right. --Scott David Daniels Scott.Daniels at Acm.Org From martin at marcher.name Thu Feb 12 16:42:30 2009 From: martin at marcher.name (Martin) Date: Thu, 12 Feb 2009 22:42:30 +0100 Subject: how many databases exists? In-Reply-To: <4260DCD6-B6D4-4372-A658-C880DAACAF7E@mimectl> References: <4260DCD6-B6D4-4372-A658-C880DAACAF7E@mimectl> Message-ID: <5fa6c12e0902121342h1667f3d2p59603c86b3fcd2cc@mail.gmail.com> Hi, you want to check the postgres documentation for that :) 2009/2/12 Rosell Pupo Polanco : > hello, i am working in pythoncard and i need to know how many databases > exist in my server POstgresql, exists some funcion in python that can help > me?? http://www.postgresql.org/docs/current/static/catalog-pg-database.html hth Martin -- http://soup.alt.delete.co.at http://www.xing.com/profile/Martin_Marcher http://www.linkedin.com/in/martinmarcher You are not free to read this message, by doing so, you have violated my licence and are required to urinate publicly. Thank you. Please avoid sending me Word or PowerPoint attachments. See http://www.gnu.org/philosophy/no-word-attachments.html From cameron.pulsford at gmail.com Thu Feb 12 16:57:19 2009 From: cameron.pulsford at gmail.com (dlocpuwons) Date: Thu, 12 Feb 2009 13:57:19 -0800 (PST) Subject: Problem with objects copying each other in memory Message-ID: <8f4a72d2-6fb1-484a-99ef-81b4a5918997@f20g2000yqg.googlegroups.com> Using Python 2.6.1... I am (attempting) to make an A* search for a chess problem, but I am running into a really annoying shared memory issue in my successor function. Here it is stripped down to the important parts that relate to my problem. def successors(self): result = [] moves = [[2, 1], [2, -1], [-2, 1], [-2, -1], [1, 2], [1, -2], [-1, 2], [-1, -2]] #possible moves for a knight for i in moves: temp = Knight(self.x, self.y, self.g, self.h, self.gp, self.sl) temp.x += i[0] temp.y += i[1] temp.sl.append([temp.x, temp.y]) #Adds the new current state to the visited states list result.append(temp) return result The method creates a temporary Knight object, increments it to the new position and then adds this new position to its list of visited states. Then it returns a list of these 8 new objects. The problem seems to be with the "result.sl.append()" line. As the method chugs along and creates the new objects the "temp.sl" lines seems to stay in memory, so when the method is done all the new objects have all the new states that were made over the course of the method instead of just their own created in the loop. For example when I try to get successors for a piece that is initially at (2,2) with no previously visited states, the method prints this out for the sl (state list) value [[2, 2], [4, 3], [4, 1], [0, 3], [0, 1], [3, 4], [3, 0], [1, 4], [1, 0]] [[2, 2], [4, 3], [4, 1], [0, 3], [0, 1], [3, 4], [3, 0], [1, 4], [1, 0]] [[2, 2], [4, 3], [4, 1], [0, 3], [0, 1], [3, 4], [3, 0], [1, 4], [1, 0]] [[2, 2], [4, 3], [4, 1], [0, 3], [0, 1], [3, 4], [3, 0], [1, 4], [1, 0]] [[2, 2], [4, 3], [4, 1], [0, 3], [0, 1], [3, 4], [3, 0], [1, 4], [1, 0]] [[2, 2], [4, 3], [4, 1], [0, 3], [0, 1], [3, 4], [3, 0], [1, 4], [1, 0]] [[2, 2], [4, 3], [4, 1], [0, 3], [0, 1], [3, 4], [3, 0], [1, 4], [1, 0]] [[2, 2], [4, 3], [4, 1], [0, 3], [0, 1], [3, 4], [3, 0], [1, 4], [1, 0]] but what it should print out is [[2, 2], [4, 3]] [[2, 2], [4, 1]] [[2, 2], [0, 3]] [[2, 2], [0, 1]] [[2, 2], [3, 4]] [[2, 2], [3, 0]] [[2, 2], [1, 4]] [[2, 2], [1, 0]] It sort of seems like python is trying to be too smart and is trying to keep things in memory. Is there anyway to work around this? From meshko at gmail.com Thu Feb 12 17:02:29 2009 From: meshko at gmail.com (mk) Date: Thu, 12 Feb 2009 14:02:29 -0800 (PST) Subject: SOAP client References: <9670bb81-a879-43cc-8abf-040e7b18c59d@q9g2000yqc.googlegroups.com> Message-ID: On Feb 11, 11:20?am, Robin wrote: > On Feb 11, 3:33?pm, mk wrote: > > > Hi, > > > I'm trying to consume aSOAPweb service using Python. ?So far I have > > found two libraries: SOAPpy and ZSI. ?Both of them rely on PyXML which > > is no longer maintained (and there is no build for 64bit Windows and > > the setup.py doesn't seem to know how to build it on Windows). ?Is > > there a liveSOAPlibrary for Python? ?I'm sort of surprised that a > > common standard likeSOAPis not more actively supported in Python. > > I'm probably missing something? > > > Thanks, > > m > > For consuming services, I've found suds to be the best client:https://fedorahosted.org/suds/ > > For creating them, I've been using soaplib:http://trac.optio.webfactional.com/ > > HTH, > > Robin Yes, thank you, Suds worked for me. Kind of weird how it is not in the google results for obvious searches. From shreyas22 at gmail.com Thu Feb 12 17:03:53 2009 From: shreyas22 at gmail.com (shreyas shah) Date: Thu, 12 Feb 2009 17:03:53 -0500 Subject: Regarding Joystick In-Reply-To: References: Message-ID: Hi , I am trying to control the motion of the camera with help of joystick , i need some basic functionality where if i move a joystick to left the camera moves to the left . Can anyone help me with that ? Thanks Shreyas -------------- next part -------------- An HTML attachment was scrubbed... URL: From sushiboy21 at gmail.com Thu Feb 12 17:04:14 2009 From: sushiboy21 at gmail.com (S-boy) Date: Thu, 12 Feb 2009 14:04:14 -0800 (PST) Subject: Can't load smtplib References: Message-ID: <6f04dfdc-929f-4584-8319-9ad696901863@b16g2000yqb.googlegroups.com> Thanks. Turns out I had a script I wrote called email.py in my Python path that was screwing things up. On Feb 12, 2:50 pm, Jean-Paul Calderone wrote: > On Thu, 12 Feb 2009 11:40:57 -0800 (PST), S-boy wrote: > >I can't seem to import smtplib in either a script or the command line > >interpreter. > > >When I try to import smtp, there seems to be some kind of collision > >with urllib2. I get a weird error about Web server authorization, even > >though I'm not calling urllib2. > > >Any ideas on what might be causing this? > > >Here's the mess.... > > >Python 2.5.4 (r254:67917, Dec 23 2008, 14:57:27) > >[GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin > > >>>> import smtplib > > >Traceback (most recent call last): > > File "", line 1, in > > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ > >python2.5/smtplib.py", line 46, in > > import email.Utils > > File "email.py", line 4, in > > Ooops. Here's your problem. Notice how that's not /Library/Frameworks/Python.framework/Versions/2.5/lib/>python2.5/email/? You have an "email" module that's obscuring the stdlib > > email package. > > > > > response = urlopen("https://webmail.canwest.com") > > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ > >python2.5/urllib2.py", line 124, in urlopen > > return _opener.open(url, data) > > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ > >python2.5/urllib2.py", line 387, in open > > response = meth(req, response) > > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ > >python2.5/urllib2.py", line 498, in http_response > > 'http', request, response, code, msg, hdrs) > > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ > >python2.5/urllib2.py", line 425, in error > > return self._call_chain(*args) > > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ > >python2.5/urllib2.py", line 360, in _call_chain > > result = func(*args) > > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ > >python2.5/urllib2.py", line 506, in http_error_default > > raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) > >urllib2.HTTPError: HTTP Error 401: Unauthorized ( The server requires > >authorization to fulfill the request. Access to the Web server is > >denied. Contact the server administrator. ) > > Jean-Paul From lists at cheimes.de Thu Feb 12 17:08:05 2009 From: lists at cheimes.de (Christian Heimes) Date: Thu, 12 Feb 2009 23:08:05 +0100 Subject: A little bit else I would like to discuss In-Reply-To: <5fa6c12e0902121336w6716187awc9495f852791988d@mail.gmail.com> References: <7f4cd287-dad4-4605-8b96-5edfdacc3da2@a12g2000yqm.googlegroups.com> <5fa6c12e0902121336w6716187awc9495f852791988d@mail.gmail.com> Message-ID: Martin wrote: [typos igored as requested ;)] > How does "small and agile" work with "batteries included"? The Python slogan says "batteries included", not "fusion reactor included". > agile:: > Would describe faster extension of the standard lib (rrd, yaml should > IMHO already be in the standard lib). I'm pretty sure other people > want to see other modules, but that's what agile + standard lib would > mean for me. (Also I'm sometimes confused by the naming of modules but > that's a different story) > > small:: > just the opposite of "batteries included" We have very high standard for the inclusion of new packages to the stdlib. For lot's of packages it makes no sense to add them to the stdlib for one or more reason. The rules are: * only mature, well tested, widely used software which is useful for a broad audience. * PSF License 2.0 * follows rules for Python and C code * The extension must work cross platform as far as all platforms support it. Only Python and C89 compatible code, no C++ * software must be supported for a long time, about 5 to 10 years is a minimum. * no new features during a release cycle of a minor version (about 2 to years) * incompatible changes and API changes need at least one minor release of deprecation warnings. It takes at least 1.5 years to get a new feature into an extension and at least 3 years to remove or change a feature. That's a major shop stopper for every fast moving piece of Python software. > My absolute favorite would be > > * python as just python (no standard lib) > * a (rather) fast moving standard lib available as an addon download > * possibly for each version > > I guess that would mean *a lot* maintenance overhead so that will > probably never. We considered to remove optional software from the core like the email package, TCL/TK and more. Eventually we decided against it for various reasons. For one we don't have the resources to maintain additional packages. Christian From clp2 at rebertia.com Thu Feb 12 17:10:29 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 12 Feb 2009 14:10:29 -0800 Subject: Problem with objects copying each other in memory In-Reply-To: <8f4a72d2-6fb1-484a-99ef-81b4a5918997@f20g2000yqg.googlegroups.com> References: <8f4a72d2-6fb1-484a-99ef-81b4a5918997@f20g2000yqg.googlegroups.com> Message-ID: <50697b2c0902121410u50df6c7cy342ec1f6a00cd545@mail.gmail.com> On Thu, Feb 12, 2009 at 1:57 PM, dlocpuwons wrote: > Using Python 2.6.1... > > I am (attempting) to make an A* search for a chess problem, but I am > running into a really annoying shared memory issue in my successor > function. Here it is stripped down to the important parts that relate > to my problem. > > def successors(self): > result = [] > moves = [[2, 1], [2, -1], [-2, 1], [-2, -1], [1, 2], [1, -2], [-1, > 2], [-1, -2]] #possible moves for a knight > > for i in moves: > temp = Knight(self.x, self.y, self.g, self.h, self.gp, self.sl) > temp.x += i[0] > temp.y += i[1] > temp.sl.append([temp.x, temp.y]) #Adds the new current state to the > visited states list > result.append(temp) > return result > > The method creates a temporary Knight object, increments it to the new > position and then adds this new position to its list of visited > states. Then it returns a list of these 8 new objects. The problem > seems to be with the "result.sl.append()" line. As the method chugs > along and creates the new objects the "temp.sl" lines seems to stay in > memory, so when the method is done all the new objects have all the > new states that were made over the course of the method instead of > just their own created in the loop. For example when I try to get > successors for a piece that is initially at (2,2) with no previously > visited states, the method prints this out for the sl (state list) > value Just a guess based on the behavior you described, but do you by chance have the Knight class defined as something like this?: class Knight(whatever): sl = [] If so, that is not the proper way to create an instance variable in Python. You've instead created a class variable, which is shared by all instances of the class. class Knight(whatever): def __init__(self, some, args, here): self.sl = [] If not, do you by chance define Knight as: class Knight(whatever): def __init__(self, some, args, here, sl=[]): self.sl = sl If so, you've fallen victim to the Important Warning on http://docs.python.org/tutorial/controlflow.html#default-argument-values under "Default Argument Values". The correct way to code it is: class Knight(whatever): def __init__(self, some, args, here, sl=None): if sl is None: sl = [] self.sl = sl Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From andrew at acooke.org Thu Feb 12 17:15:08 2009 From: andrew at acooke.org (andrew cooke) Date: Thu, 12 Feb 2009 19:15:08 -0300 (CLST) Subject: Problem with objects copying each other in memory In-Reply-To: <8f4a72d2-6fb1-484a-99ef-81b4a5918997@f20g2000yqg.googlegroups.com> References: <8f4a72d2-6fb1-484a-99ef-81b4a5918997@f20g2000yqg.googlegroups.com> Message-ID: <6033c55d3f76cd47dbe4cbb627d016c3.squirrel@acooke.dyndns.org> you're setting the new knight's "sl" to the value self.sl and then adding values to it. that's the same list - so you are adding values to the self.sl list when you add them to the knight's sl. this is easier to understand just by seeing the fix, which is to use: temp = Knight(self.x, self.y, self.g, self.h, self.gp, list(self.sl)) which will make a new copy of the list, so you are only adding to the sl in the (new) knight. andrew dlocpuwons wrote: > Using Python 2.6.1... > > I am (attempting) to make an A* search for a chess problem, but I am > running into a really annoying shared memory issue in my successor > function. Here it is stripped down to the important parts that relate > to my problem. > > def successors(self): > result = [] > moves = [[2, 1], [2, -1], [-2, 1], [-2, -1], [1, 2], [1, -2], [-1, > 2], [-1, -2]] #possible moves for a knight > > for i in moves: > temp = Knight(self.x, self.y, self.g, self.h, self.gp, self.sl) > temp.x += i[0] > temp.y += i[1] > temp.sl.append([temp.x, temp.y]) #Adds the new current state to the > visited states list > result.append(temp) > return result > > The method creates a temporary Knight object, increments it to the new > position and then adds this new position to its list of visited > states. Then it returns a list of these 8 new objects. The problem > seems to be with the "result.sl.append()" line. As the method chugs > along and creates the new objects the "temp.sl" lines seems to stay in > memory, so when the method is done all the new objects have all the > new states that were made over the course of the method instead of > just their own created in the loop. For example when I try to get > successors for a piece that is initially at (2,2) with no previously > visited states, the method prints this out for the sl (state list) > value > > [[2, 2], [4, 3], [4, 1], [0, 3], [0, 1], [3, 4], [3, 0], [1, 4], [1, > 0]] > [[2, 2], [4, 3], [4, 1], [0, 3], [0, 1], [3, 4], [3, 0], [1, 4], [1, > 0]] > [[2, 2], [4, 3], [4, 1], [0, 3], [0, 1], [3, 4], [3, 0], [1, 4], [1, > 0]] > [[2, 2], [4, 3], [4, 1], [0, 3], [0, 1], [3, 4], [3, 0], [1, 4], [1, > 0]] > [[2, 2], [4, 3], [4, 1], [0, 3], [0, 1], [3, 4], [3, 0], [1, 4], [1, > 0]] > [[2, 2], [4, 3], [4, 1], [0, 3], [0, 1], [3, 4], [3, 0], [1, 4], [1, > 0]] > [[2, 2], [4, 3], [4, 1], [0, 3], [0, 1], [3, 4], [3, 0], [1, 4], [1, > 0]] > [[2, 2], [4, 3], [4, 1], [0, 3], [0, 1], [3, 4], [3, 0], [1, 4], [1, > 0]] > > but what it should print out is > > [[2, 2], [4, 3]] > [[2, 2], [4, 1]] > [[2, 2], [0, 3]] > [[2, 2], [0, 1]] > [[2, 2], [3, 4]] > [[2, 2], [3, 0]] > [[2, 2], [1, 4]] > [[2, 2], [1, 0]] > > It sort of seems like python is trying to be too smart and is trying > to keep things in memory. Is there anyway to work around this? > -- > http://mail.python.org/mailman/listinfo/python-list > > From rt8396 at gmail.com Thu Feb 12 17:22:05 2009 From: rt8396 at gmail.com (r) Date: Thu, 12 Feb 2009 14:22:05 -0800 (PST) Subject: A little bit else I would like to discuss References: <7f4cd287-dad4-4605-8b96-5edfdacc3da2@a12g2000yqm.googlegroups.com> Message-ID: <7a52418e-82b7-4901-8c82-d90ce70160b7@v39g2000yqm.googlegroups.com> On Feb 12, 2:04?pm, azrael wrote: > Sometimes I really get confused when looking out for a modul for some > kind of need. Sometimes I get frightened when I get the resaults. 8 > wraper for this, 7 wrapers for that, 10 modules for anything. Between > them are maybe some kind of small differences, but to work with any of > the modules, I have to spend 10 hours of reading the help, If there is > any at all. I don't follow you here?? > I think that there should be a list on python.org of supported or > sugested modules for some need. For example Database access. Or GUI > Building. It is a complete pain in the ass. Let's face the true, TK is > out of date. There should be another one used and appended to the > standard Python Library. One that plays well with other platforms. And > if it does't, let's make it play better. There is a list of third party modules on the Python.org site and it is huge! Tk is very simple i agree, but i would hate to double the size of my python installer download just to have this or that module built-in. Trust me you really don't want that. But i will agree a better classification of modules would be nice > Why will Microsoft's products kick the ass of open source. Because > anyone does what he wants. Let's say There are 5 GUI libraries > competing against each other. Think about it what could these 5 teams > acomplish if they would work together. Or maybe a framework for RAD > GUI devbelopment. after 10 years of python, there is still not one > application for GUI Building that can beat Visual Studio. > > Anyone I talk to says: "Oh my god, Python and GUI" I will agree with you here. Just think what could be accomplished if all the linux distro developers could band together to create one golden linux distro. This level of collaboration would create a distro so powerful the vibrations of it will cause Bill Gates house to slide into lake Washington :). Tk could use a polishing i much agree and so could IDLE. Maybe we should start a revolution here? i am game! > There are a dozen of modules that should be, if you ask me, be > implemented into Python. Like NumPy, SciPY, PIL. A lot of people I > talk to, are using them. But everyone has to download them manually > and hope that if someone is using their code, has also installed the > needed modules. Again i very much disagree here. We don't want to make Python a piece of elephant-size MS bloatware. Not everybody needs or wants all these libraries and maintaining this extra code-base puts exrta strain on the Python dev team. We need them to concentrate on other more important issues. > My solution would be: > Let's make an announcement on Python.org. something like this. > > We need Ideas for creating the a standard library in Python for Image > processing. Tell ?us your problem. What do you think which feature > should be implemented. Which transformation, which algorithm. > Make a vote. This should be that not. There is a library PIL but it could use some updating too. > But how to start something like that. Anyone that sees a problem that > should be solved, becomes the project leader. Find the best Ideas and > make a good library. Motivation is hard to find, and it's more than that. People have to make a living, but we never know until we try. I am with you! Lest revolutionize Python! > It's is very good that people have a choice. But why not make some > standards. I know that there is already a standard python library, But > why not extending it. classify the standard library into subcategories > like Networking, DataBase, Computation, ...... Bloated_python == dead_Python > One other thing. I am not looking for war on groups. I just would like > to discuss some things that drive me crazy while using Python. > > This group has a lot of members. not to mention every Python Forum. > Why not using this number of people and accomplish something great. If > anyone of us would write 10 line of good code, it would result a very > great and powerfull environment. I agree, anybody else out there want to add to this converstation? From tjreedy at udel.edu Thu Feb 12 17:24:05 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 12 Feb 2009 17:24:05 -0500 Subject: A little bit else I would like to discuss In-Reply-To: <7f4cd287-dad4-4605-8b96-5edfdacc3da2@a12g2000yqm.googlegroups.com> References: <7f4cd287-dad4-4605-8b96-5edfdacc3da2@a12g2000yqm.googlegroups.com> Message-ID: azrael wrote: > Sometimes I really get confused when looking out for a modul for some > kind of need. Sometimes I get frightened when I get the resaults. 8 > wraper for this, 7 wrapers for that, 10 modules for anything. Between > them are maybe some kind of small differences, but to work with any of > the modules, I have to spend 10 hours of reading the help, If there is > any at all. > > I think that there should be a list on python.org of supported or > sugested modules for some need. For example Database access. Or GUI > Building. It is a complete pain in the ass. Let's face the true, TK is > out of date. There should be another one used and appended to the > standard Python Library. One that plays well with other platforms. And > if it does't, let's make it play better. You are welcome to volunteer to write entries for the Python wiki. From sambit2005 at gmail.com Thu Feb 12 17:25:57 2009 From: sambit2005 at gmail.com (Sambit Samal) Date: Fri, 13 Feb 2009 11:25:57 +1300 Subject: getting caller In-Reply-To: References: Message-ID: <9e680b420902121425y6c20f6abnee3afa4059e772d1@mail.gmail.com> Hi I am new to Python world I need a python script , which binds at a user defind port & sends to other enity , which waits at particular port. The other enity will respond & Python script should receive that at the defined port The communication will happen over UDP e.g Python Appl IP: 10.116.78.90 Port : 3000 Other Enity : IP: 10.116.98.87 Port : 3010 Pyhon Appl ------------>UDP ----> Other Enity <-------------------------- Please help -------------- next part -------------- An HTML attachment was scrubbed... URL: From cameron.pulsford at gmail.com Thu Feb 12 17:29:29 2009 From: cameron.pulsford at gmail.com (Cameron Pulsford) Date: Thu, 12 Feb 2009 17:29:29 -0500 Subject: Problem with objects copying each other in memory In-Reply-To: <6033c55d3f76cd47dbe4cbb627d016c3.squirrel@acooke.dyndns.org> References: <8f4a72d2-6fb1-484a-99ef-81b4a5918997@f20g2000yqg.googlegroups.com> <6033c55d3f76cd47dbe4cbb627d016c3.squirrel@acooke.dyndns.org> Message-ID: Thanks, that did it! Why is that the case though? Or rather, why do the assignments to temp.x and temp.y not effect the self.x and self.y? How come I only run into the problem with the list? On Feb 12, 2009, at 5:15 PM, andrew cooke wrote: > > you're setting the new knight's "sl" to the value self.sl and then > adding > values to it. that's the same list - so you are adding values to the > self.sl list when you add them to the knight's sl. > > this is easier to understand just by seeing the fix, which is to use: > > temp = Knight(self.x, self.y, self.g, self.h, self.gp, list(self.sl)) > > which will make a new copy of the list, so you are only adding to > the sl > in the (new) knight. > > andrew > > > > dlocpuwons wrote: >> Using Python 2.6.1... >> >> I am (attempting) to make an A* search for a chess problem, but I am >> running into a really annoying shared memory issue in my successor >> function. Here it is stripped down to the important parts that relate >> to my problem. >> >> def successors(self): >> result = [] >> moves = [[2, 1], [2, -1], [-2, 1], [-2, -1], [1, 2], [1, -2], [-1, >> 2], [-1, -2]] #possible moves for a knight >> >> for i in moves: >> temp = Knight(self.x, self.y, self.g, self.h, self.gp, self.sl) >> temp.x += i[0] >> temp.y += i[1] >> temp.sl.append([temp.x, temp.y]) #Adds the new current state to >> the >> visited states list >> result.append(temp) >> return result >> >> The method creates a temporary Knight object, increments it to the >> new >> position and then adds this new position to its list of visited >> states. Then it returns a list of these 8 new objects. The problem >> seems to be with the "result.sl.append()" line. As the method chugs >> along and creates the new objects the "temp.sl" lines seems to stay >> in >> memory, so when the method is done all the new objects have all the >> new states that were made over the course of the method instead of >> just their own created in the loop. For example when I try to get >> successors for a piece that is initially at (2,2) with no previously >> visited states, the method prints this out for the sl (state list) >> value >> >> [[2, 2], [4, 3], [4, 1], [0, 3], [0, 1], [3, 4], [3, 0], [1, 4], [1, >> 0]] >> [[2, 2], [4, 3], [4, 1], [0, 3], [0, 1], [3, 4], [3, 0], [1, 4], [1, >> 0]] >> [[2, 2], [4, 3], [4, 1], [0, 3], [0, 1], [3, 4], [3, 0], [1, 4], [1, >> 0]] >> [[2, 2], [4, 3], [4, 1], [0, 3], [0, 1], [3, 4], [3, 0], [1, 4], [1, >> 0]] >> [[2, 2], [4, 3], [4, 1], [0, 3], [0, 1], [3, 4], [3, 0], [1, 4], [1, >> 0]] >> [[2, 2], [4, 3], [4, 1], [0, 3], [0, 1], [3, 4], [3, 0], [1, 4], [1, >> 0]] >> [[2, 2], [4, 3], [4, 1], [0, 3], [0, 1], [3, 4], [3, 0], [1, 4], [1, >> 0]] >> [[2, 2], [4, 3], [4, 1], [0, 3], [0, 1], [3, 4], [3, 0], [1, 4], [1, >> 0]] >> >> but what it should print out is >> >> [[2, 2], [4, 3]] >> [[2, 2], [4, 1]] >> [[2, 2], [0, 3]] >> [[2, 2], [0, 1]] >> [[2, 2], [3, 4]] >> [[2, 2], [3, 0]] >> [[2, 2], [1, 4]] >> [[2, 2], [1, 0]] >> >> It sort of seems like python is trying to be too smart and is trying >> to keep things in memory. Is there anyway to work around this? >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > > From andrew at acooke.org Thu Feb 12 18:04:23 2009 From: andrew at acooke.org (andrew cooke) Date: Thu, 12 Feb 2009 20:04:23 -0300 (CLST) Subject: Problem with objects copying each other in memory In-Reply-To: References: <8f4a72d2-6fb1-484a-99ef-81b4a5918997@f20g2000yqg.googlegroups.com> <6033c55d3f76cd47dbe4cbb627d016c3.squirrel@acooke.dyndns.org> Message-ID: <54753ad5197ca440238714f7e1c8ffae.squirrel@acooke.dyndns.org> the official answer to that question is here - http://docs.python.org/reference/datamodel.html?highlight=containers - at about the 6th paragraph where it talks about "containers". i think it's a hard question and really in a sense (imho) the real reason is just that this tends to be the best compromise for the kind of language that python is. andrew Cameron Pulsford wrote: > Thanks, that did it! Why is that the case though? Or rather, why do > the assignments to temp.x and temp.y not effect the self.x and self.y? > How come I only run into the problem with the list? > > > On Feb 12, 2009, at 5:15 PM, andrew cooke wrote: > >> >> you're setting the new knight's "sl" to the value self.sl and then >> adding >> values to it. that's the same list - so you are adding values to the >> self.sl list when you add them to the knight's sl. >> >> this is easier to understand just by seeing the fix, which is to use: >> >> temp = Knight(self.x, self.y, self.g, self.h, self.gp, list(self.sl)) >> >> which will make a new copy of the list, so you are only adding to >> the sl >> in the (new) knight. >> >> andrew >> >> >> >> dlocpuwons wrote: >>> Using Python 2.6.1... >>> >>> I am (attempting) to make an A* search for a chess problem, but I am >>> running into a really annoying shared memory issue in my successor >>> function. Here it is stripped down to the important parts that relate >>> to my problem. >>> >>> def successors(self): >>> result = [] >>> moves = [[2, 1], [2, -1], [-2, 1], [-2, -1], [1, 2], [1, -2], [-1, >>> 2], [-1, -2]] #possible moves for a knight >>> >>> for i in moves: >>> temp = Knight(self.x, self.y, self.g, self.h, self.gp, self.sl) >>> temp.x += i[0] >>> temp.y += i[1] >>> temp.sl.append([temp.x, temp.y]) #Adds the new current state to >>> the >>> visited states list >>> result.append(temp) >>> return result >>> >>> The method creates a temporary Knight object, increments it to the >>> new >>> position and then adds this new position to its list of visited >>> states. Then it returns a list of these 8 new objects. The problem >>> seems to be with the "result.sl.append()" line. As the method chugs >>> along and creates the new objects the "temp.sl" lines seems to stay >>> in >>> memory, so when the method is done all the new objects have all the >>> new states that were made over the course of the method instead of >>> just their own created in the loop. For example when I try to get >>> successors for a piece that is initially at (2,2) with no previously >>> visited states, the method prints this out for the sl (state list) >>> value >>> >>> [[2, 2], [4, 3], [4, 1], [0, 3], [0, 1], [3, 4], [3, 0], [1, 4], [1, >>> 0]] >>> [[2, 2], [4, 3], [4, 1], [0, 3], [0, 1], [3, 4], [3, 0], [1, 4], [1, >>> 0]] >>> [[2, 2], [4, 3], [4, 1], [0, 3], [0, 1], [3, 4], [3, 0], [1, 4], [1, >>> 0]] >>> [[2, 2], [4, 3], [4, 1], [0, 3], [0, 1], [3, 4], [3, 0], [1, 4], [1, >>> 0]] >>> [[2, 2], [4, 3], [4, 1], [0, 3], [0, 1], [3, 4], [3, 0], [1, 4], [1, >>> 0]] >>> [[2, 2], [4, 3], [4, 1], [0, 3], [0, 1], [3, 4], [3, 0], [1, 4], [1, >>> 0]] >>> [[2, 2], [4, 3], [4, 1], [0, 3], [0, 1], [3, 4], [3, 0], [1, 4], [1, >>> 0]] >>> [[2, 2], [4, 3], [4, 1], [0, 3], [0, 1], [3, 4], [3, 0], [1, 4], [1, >>> 0]] >>> >>> but what it should print out is >>> >>> [[2, 2], [4, 3]] >>> [[2, 2], [4, 1]] >>> [[2, 2], [0, 3]] >>> [[2, 2], [0, 1]] >>> [[2, 2], [3, 4]] >>> [[2, 2], [3, 0]] >>> [[2, 2], [1, 4]] >>> [[2, 2], [1, 0]] >>> >>> It sort of seems like python is trying to be too smart and is trying >>> to keep things in memory. Is there anyway to work around this? >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >>> >>> >> >> > > From python.dev.9 at gmail.com Thu Feb 12 18:44:45 2009 From: python.dev.9 at gmail.com (mercado) Date: Thu, 12 Feb 2009 18:44:45 -0500 Subject: Passing a variable number of arguments to a function Message-ID: <2678157f0902121544n5b5a49fer85e1054ece8f8076@mail.gmail.com> I have the following piece of code that is bugging me: #------------------------------------------------------------------------------- def someFunc(arg1, arg2=True, arg3=0): print arg1, arg2, arg3 someTuple = ( ("this is a string",), ("this is another string", False), ("this is another string", False, 100) ) for argList in someTuple: if len(argList) == 1: someFunc(argList[0]) elif len(argList) == 2: someFunc(argList[0], argList[1]) elif len(argList) == 3: someFunc(argList[0], argList[1], argList[2]) #------------------------------------------------------------------------------- Is it possible to rewrite this code so I don't have that awkward if statement at the bottom that passes every variation in the number of arguments to the function? I know that it's possible to define a function to accept a variable number of parameters using *args or **kwargs, but it's not possible for me to redefine this function in the particular project I'm working on. What I would really like to do is something like this (pseudocode) and do away with the if statement completely: #------------------------------------------------------------------------------- def someFunc(arg1, arg2=True, arg3=0): print arg1, arg2, arg3 someTuple = ( ("this is a string",), ("this is another string", False), ("this is another string", False, 100) ) for argList in someTuple: someFunc(expandArgList(argList)) #------------------------------------------------------------------------------- Is this possible? Thanks in advance. -------------- next part -------------- An HTML attachment was scrubbed... URL: From akitada at gmail.com Thu Feb 12 18:45:32 2009 From: akitada at gmail.com (Akira Kitada) Date: Fri, 13 Feb 2009 08:45:32 +0900 Subject: New book "The Python Programming Language" by Guido van Rossum Message-ID: <90bb445a0902121545s77378e59y74d63cee8d9ba02e@mail.gmail.com> The Python Programming Language by Guido van Rossum, Raymond Hettinger, Jack Diedrich, David Beazley, David Mertz, Nicholas Coghlan to be published. http://www.amazon.co.uk/Python-Programming-Language-Guido-Rossum/dp/0132299690 Anyone found the TOC of this? Thanks, From clp2 at rebertia.com Thu Feb 12 18:51:25 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 12 Feb 2009 15:51:25 -0800 Subject: Passing a variable number of arguments to a function In-Reply-To: <2678157f0902121544n5b5a49fer85e1054ece8f8076@mail.gmail.com> References: <2678157f0902121544n5b5a49fer85e1054ece8f8076@mail.gmail.com> Message-ID: <50697b2c0902121551s8bbf434hd6be17e7cee1f333@mail.gmail.com> On Thu, Feb 12, 2009 at 3:44 PM, mercado wrote: > I have the following piece of code that is bugging me: > > #------------------------------------------------------------------------------- > def someFunc(arg1, arg2=True, arg3=0): > print arg1, arg2, arg3 > > someTuple = ( > ("this is a string",), > ("this is another string", False), > ("this is another string", False, 100) > ) > > for argList in someTuple: > if len(argList) == 1: > someFunc(argList[0]) > elif len(argList) == 2: > someFunc(argList[0], argList[1]) > elif len(argList) == 3: > someFunc(argList[0], argList[1], argList[2]) > #------------------------------------------------------------------------------- > > Is it possible to rewrite this code so I don't have that awkward if > statement at the bottom that passes every variation in the number of > arguments to the function? I know that it's possible to define a function > to accept a variable number of parameters using *args or **kwargs, but it's > not possible for me to redefine this function in the particular project I'm > working on. There is a nicely symmetrical calling syntax that does the inverse of * in a function declaration: for argList in someTuple: someFunc(*argList) There's also an analogous func(**dictOfKwdArgs) call syntax. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From john106henry at hotmail.com Thu Feb 12 18:55:37 2009 From: john106henry at hotmail.com (John Henry) Date: Thu, 12 Feb 2009 15:55:37 -0800 (PST) Subject: Invoking CutePDF from within Python Message-ID: <590ed3f4-089a-41d7-aaa2-6d96f5ea1fa9@j39g2000yqn.googlegroups.com> Hi all, I have a need to invoke CutePDF from within a Python program. The program creates an EXCEL spreadsheet and set the print area and properties. Then I wish to store the spreadsheet in a PDF file. xtopdf does not work well (text only). ReportLab is an overkill. PyPDF can only shuffle PDF pages. All I need is to say "Print this to CUTEPDF and store as xyz.pdf". I found that this can be done in VB but I do not know VB, unfortunately. Private Sub Print_PDF() Dim lRetVal As Long Dim hKey As Long Dim sValue As String lRetVal = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\Custom PDF Printer", _ 0&, vbNullString, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, _ 0&, hKey, lRetVal) sValue = "C:\Sample.pdf" RegSetValueExString hKey, "OutputFile", 0&, REG_SZ, sValue, Len (sValue) sValue = "1" RegSetValueExString hKey, "BypassSaveAs", 0&, REG_SZ, sValue, Len (sValue) Dim worddoc As Word.Document Set worddoc = wordapp.Documents.Open("C:\Sample.doc") wordapp.ActivePrinter = "Custom PDF Printer" wordapp.PrintOut worddoc.Close sValue = "0" RegSetValueExString hKey, "BypassSaveAs", 0&, REG_SZ, sValue, Len (sValue) RegCloseKey (hKey) End Sub From http Thu Feb 12 18:59:08 2009 From: http (Paul Rubin) Date: 12 Feb 2009 15:59:08 -0800 Subject: New book "The Python Programming Language" by Guido van Rossum References: Message-ID: <7x3aejgqb7.fsf@ruckus.brouhaha.com> Akira Kitada writes: > The Python Programming Language by Guido van Rossum, Raymond Hettinger, > Jack Diedrich, David Beazley, David Mertz, Nicholas Coghlan to be published. > http://www.amazon.co.uk/Python-Programming-Language-Guido-Rossum/dp/0132299690 Wow! But it says the pub date is 28 Aug 2009. > Anyone found the TOC of this? Chances are, it's still being written and the final TOC is not yet known. From jason.scheirer at gmail.com Thu Feb 12 19:13:11 2009 From: jason.scheirer at gmail.com (Jason Scheirer) Date: Thu, 12 Feb 2009 16:13:11 -0800 (PST) Subject: A little bit else I would like to discuss References: <7f4cd287-dad4-4605-8b96-5edfdacc3da2@a12g2000yqm.googlegroups.com> Message-ID: <47c331cb-5adb-42ef-9741-8537f91b82e8@p13g2000yqc.googlegroups.com> On Feb 12, 12:04?pm, azrael wrote: > Sometimes I really get confused when looking out for a modul for some > kind of need. Sometimes I get frightened when I get the resaults. 8 > wraper for this, 7 wrapers for that, 10 modules for anything. Between > them are maybe some kind of small differences, but to work with any of > the modules, I have to spend 10 hours of reading the help, If there is > any at all. > > I think that there should be a list on python.org of supported or > sugested modules for some need. For example Database access. Or GUI > Building. It is a complete pain in the ass. Let's face the true, TK is > out of date. There should be another one used and appended to the > standard Python Library. One that plays well with other platforms. And > if it does't, let's make it play better. > > Why will Microsoft's products kick the ass of open source. Because > anyone does what he wants. Let's say There are 5 GUI libraries > competing against each other. Think about it what could these 5 teams > acomplish if they would work together. Or maybe a framework for RAD > GUI devbelopment. after 10 years of python, there is still not one > application for GUI Building that can beat Visual Studio. > > Anyone I talk to says: "Oh my god, Python and GUI" > > There are a dozen of modules that should be, if you ask me, be > implemented into Python. Like NumPy, SciPY, PIL. A lot of people I > talk to, are using them. But everyone has to download them manually > and hope that if someone is using their code, has also installed the > needed modules. > > My solution would be: > Let's make an announcement on Python.org. something like this. > > We need Ideas for creating the a standard library in Python for Image > processing. Tell ?us your problem. What do you think which feature > should be implemented. Which transformation, which algorithm. > Make a vote. This should be that not. > > But how to start something like that. Anyone that sees a problem that > should be solved, becomes the project leader. Find the best Ideas and > make a good library. > > It's is very good that people have a choice. But why not make some > standards. I know that there is already a standard python library, But > why not extending it. classify the standard library into subcategories > like Networking, DataBase, Computation, ...... > > One other thing. I am not looking for war on groups. I just would like > to discuss some things that drive me crazy while using Python. > > This group has a lot of members. not to mention every Python Forum. > Why not using this number of people and accomplish something great. If > anyone of us would write 10 line of good code, it would result a very > great and powerfull environment. Now hold on here, Microsoft has a pretty schizophrenic opinion on GUIs itself. Over the years you've had direct Win32 calls, the MFC libraries, then WinForms and later WPF on .NET. If I were a C++/C# developer new to Windows, which one should I go with? Or how about I want to be cross-platform and start looking into Fox or QT or even GTK? The only difference between this and the number of Python GUIs is that your version of Visual Studio sticks around for a few years. You could standardize on a single version of the GUI you're using (say, WX) and declare it to have a 5 year lifespan in your organization, install QT builder and use that, or any of a large number of options. Don't expect other people to make the decision for you, though, as an open source environment brings about a plurality of options. Python has a far broader scope as a tool for all kinds of tasks than a GUI-Centric Microsoft development environment, and assuming every Python developer wants to focus on making Python a vehicle of platform-specific GUIs for producing shrink-wrapped software is a little off base. > Anyone I talk to says: "Oh my god, Python and GUI" Have these people needed to spend much time getting to know any one GUI environment? They all suck in every language at first, then the Stockholm syndrome sets in and it's not so bad. The problem here also is that there have been attempts to get something going that sputtered and failed (a sort of anygui module). It's relatively easy to standardize on how to talk to a relational database (that PEP is nice and solid), but looking at a grand unified way of talking to so many different paradigms of GUI library, writing bindings, testing, etc. is a much larger, less sensical beast. The cross-platform UIs like Swing or QT all feel slightly out-of-place on many systems because the interface elements and design decisions are different from platform to platform. If you want a platform-integrated GUI, use Glade/GTK/Python or QT Designer/Python in Linux, XCode/Interface Builder/PyObjC in OSX, and even consider IronPython and the .Net GUI stuff on Windows. Heck, I've done some Swing and Jython and it was not as bad as writing Swing in Java. Might I also suggest that if you are struggling to make a proper GUI in Python, and a GUI is what you need, that Python is probably not the right tool for you to be using to get the job done. From jura.grozni at gmail.com Thu Feb 12 19:22:32 2009 From: jura.grozni at gmail.com (azrael) Date: Thu, 12 Feb 2009 16:22:32 -0800 (PST) Subject: A little bit else I would like to discuss References: <7f4cd287-dad4-4605-8b96-5edfdacc3da2@a12g2000yqm.googlegroups.com> Message-ID: <678601bf-65ef-4afa-afc5-2d4cef4d457f@v42g2000yqj.googlegroups.com> On Feb 12, 9:24?pm, Tim Golden wrote: > Philip Semanchuk wrote: > > > On Feb 12, 2009, at 3:04 PM, azrael wrote: > > >> Why will Microsoft's products kick the ass of open source. Because > >> anyone does what he wants. Let's say There are 5 GUI libraries > >> competing against each other. Think about it what could these 5 teams > >> acomplish if they would work together. Or maybe a framework for RAD > >> GUI devbelopment. after 10 years of python, there is still not one > >> application for GUI Building that can beat Visual Studio. > > > Let me know when Visual Studio tries to address building GUIs for > > Windows, OS X, Gnome, and KDE. Until then, you're comparing apples to > > oranges, or chalk and cheese if you're from that part of the world. > > While your point is obviously good, it only applies if you > even care about building for OS X, Gnome etc. If all you > want is build on Windows (or Gnome or KDE or whatever) then > the cross-platformness of any proposed toolkit is worthless > and may even be a drawback if it reduces its functionality > to a lowest common denominator. > > I have nothing really to say about GUI-building whatsits in > general; I don't have cause to use them myself so I simply > stand back and let their proponents fight it out. I just > wanted to point out that playing the cross-platform card > does not mean the game is over. > > TJG OK. If I don't use GUIs, is there anything other that I do. Is there anything else where I can contribute. Maybe there should be a better networking, crypto, database connection library. Or whatever. Forget about Crossplatform Gui Building. That is something that the developers from wxWidgets think about. Where is the point of python in crossplatform compability if I download on windows machine a piece of code writen for GTK and I don't have anything installed to support it. Again I am going to make some downloads. Python is bundled with TK, which is out of date. From jura.grozni at gmail.com Thu Feb 12 19:39:06 2009 From: jura.grozni at gmail.com (azrael) Date: Thu, 12 Feb 2009 16:39:06 -0800 (PST) Subject: A little bit else I would like to discuss References: <7f4cd287-dad4-4605-8b96-5edfdacc3da2@a12g2000yqm.googlegroups.com> Message-ID: <7160ddaf-b202-4e41-a8a5-b12a280ca04e@v13g2000yqm.googlegroups.com> On Feb 12, 9:40?pm, Christian Heimes wrote: > azrael wrote: > > I think that there should be a list on python.org of supported or > > sugested modules for some need. For example Database access. Or GUI > > Building. It is a complete pain in the ass. Let's face the true, TK is > > out of date. There should be another one used and appended to the > > standard Python Library. One that plays well with other platforms. And > > if it does't, let's make it play better. > > The Python core will not ship with another GUI toolkit. TK may be > removed from the core in some distant future but we - the Python core > development team - will *not* make a choice between GTK, WX and Qt. > > > One other thing. I am not looking for war on groups. I just would like > > to discuss some things that drive me crazy while using Python. > > In your opinion all third party are bad. You like to have one monolithic > block of software. That's a typical Microsoft approach. Lot's of people > from the open source community prefer small and loosely coupled pieces > of software. One of the greatest ruler of all time once said "divide et > impera" -- divide it in small pieces to make it much easier to conquer > every piece by its own. We are following the same path here. > > Nobody is going to stop you from creating a large bundle of useful > extensions as long as you follow the licenses. In fact lots of people > may appreciate a bundle. But the Python core package will always stay > small and agile. > > Christian I understand that. completely. I don't think that third party is bad. It is great that someone has an Idea and decides to make a new project. But why not adopting best practices or maybe even make a small effort to construct better support for some popular and commonly used modules. If these modules always stay third party, there will come a day when they stop being developed. At this point , Python looses a good module from beeing developed any further. And some time later, someone else starts again from scratch and make something new. I came to Python because it has some features that always annoyed me in C++ or Java. The diference between Java and Python that Java is today way much often used thaen python, has a much larger Library collection. I am mainly afraid that Python will become just a small Scripting languages. There are a lot of people that say that they would start Python, but they dont't want to because they don't want to get their results in Comand line. I don't say that Comandline is bad, but I think about the common user. From rhodri at wildebst.demon.co.uk Thu Feb 12 19:51:10 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 13 Feb 2009 00:51:10 -0000 Subject: Problem with objects copying each other in memory In-Reply-To: References: <8f4a72d2-6fb1-484a-99ef-81b4a5918997@f20g2000yqg.googlegroups.com> <6033c55d3f76cd47dbe4cbb627d016c3.squirrel@acooke.dyndns.org> Message-ID: On Thu, 12 Feb 2009 22:29:29 -0000, Cameron Pulsford wrote: > Thanks, that did it! Why is that the case though? Or rather, why do the > assignments to temp.x and temp.y not effect the self.x and self.y? How > come I only run into the problem with the list? Variable names and assignment don't work the same way in Python as they do in C (say). What assignment does is to attach the name on the left to the object on the right. Obviously this is oversimplifying, since "the name on the left" could be a list or dictionary element or the like, but the principle holds: variables aren't objects themselves, they're just references to objects. For your ordinary everyday integers, this is arranged to be no different from normal. Suppose we have x = 5 y = x x = x + 1 print y Then we start by creating an integer object with the value 5 and labelling it "x". Then we pick up that object and label it 'y' as well. The next line causes us to create an integer object with the value 1, pick up the object we called 'x', and tell that object to add the '1' object to itself. That results in creating a brand new object (with the value 6), which we then label 'x'. The original '5' object (still labelled 'y') hasn't been changed by this, because Python does arithmetic by creating new integer objects. Lists operate the same way for concatenation and repetition. a = [1, 2, 3] b = [4, 5, 6] c = a a = a + b print c The "a = a + b" line creates a new list consisting of the elements of the old list 'a' followed by the elements of the old list 'b', without changing either of those lists in the slightest, and then calls this new list 'a'. The old list is still hanging around, and still has the label 'c' attached to it. The differences from your expectations arise because lists are mutable, and integers aren't. In other words we can change the contents of a list "in place" without creating a new list. a = [1, 2, 3] b = a a.append(4) print b Here, the list has both labels 'a' and 'b' attached to it. When we call a.append, it doesn't create a new list or anything like that, it just makes the existing list larger and tacks the new value on the end. Because it's still the same list as before, it's still got both names attached to it, so when you print 'b' out you see the changed list [1, 2, 3, 4]. -- Rhodri James *-* Wildebeeste Herder to the Masses From argo785 at gmail.com Thu Feb 12 20:09:26 2009 From: argo785 at gmail.com (argo785 at gmail.com) Date: Thu, 12 Feb 2009 17:09:26 -0800 (PST) Subject: Thank you, Tkinter. (easy to use) References: Message-ID: <279ea3e5-edcb-42a6-a7b8-016d55cd7453@f3g2000yqf.googlegroups.com> On Feb 12, 4:29?am, "Eric Brunel" wrote: > On Thu, 12 Feb 2009 06:06:06 +0100, wrote: > > [snip] > > > My only (minor) complaint is that Tk > > doesn't draw text antialiased in the various widgets (menus, labels, > > buttons, etc.). > > ?From version 8.5 of tcl/tk, it's supposed to do it. See this page:http://www.tcl.tk/software/tcltk/8.5.tml > under 'Highlights of Tk 8.5', item 'Font rendering'. It seems to talk only ? > about X11 and Mac OS X; don't know if it works on Windows... I also don't know about MS Windows. I've been fortunate enough to not have to use that OS for *years*. Also, after some more searching, found this: http://tkinter.unpythonic.net/wiki/Tk85AndPython And according to [this](http://bugs.python.org/issue2983), the ttk support has been merged into Python 2.7/3.1 as of about 2 weeks ago. From rhodri at wildebst.demon.co.uk Thu Feb 12 20:10:59 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 13 Feb 2009 01:10:59 -0000 Subject: Untangling pythonWin and IDLE Processes on XP Pro In-Reply-To: References: <%OUkl.6905$jZ1.2422@flpi144.ffdc.sbc.com> <6viopfFkcasmU1@mid.uni-berlin.de> <2NWkl.16040$YU2.9824@nlpi066.nbdc.sbc.com> <6viv4bFk8gonU1@mid.uni-berlin.de> Message-ID: On Thu, 12 Feb 2009 16:44:56 -0000, W. eWatson wrote: > I simply ask, "How do I get around the problem?" Run your program from the command line, or by double-clicking. You've been told this several times now. -- Rhodri James *-* Wildebeeste Herder to the Masses From notvalid2 at sbcglobal.net Thu Feb 12 20:16:38 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Thu, 12 Feb 2009 17:16:38 -0800 Subject: Untangling pythonWin and IDLE Processes on XP Pro In-Reply-To: References: <%OUkl.6905$jZ1.2422@flpi144.ffdc.sbc.com> <6viopfFkcasmU1@mid.uni-berlin.de> <2NWkl.16040$YU2.9824@nlpi066.nbdc.sbc.com> <4ec6562a-08b2-4ec4-b9c0-e720e4ce7339@g38g2000yqd.googlegroups.com> Message-ID: Greetings and salutations. I just uninstalled all traces of (Active) pythonWin 2.5.2 from this machine, In fact, I uninstalled python 2.5.2 with IDLE from this machine. I then reinstalled the latter. Then I ran the program. XP Pro. I then went to another machine that has never had pythonWin on it all, but does have python 2.5.2 with IDLE. I ran the same program there. W2K. In both cases, I got the output below. Your conclusions? ===========================Output on Interactive Shell Screen=========== GUI self----------->>>>: <__main__.Sentuser_GUI instance at 0x02154058> counter: 3 OSett self = <__main__.Sentuser_GUI instance at 0x02154058> type = gray scale now--wtw: True Set OSDiag sdict body from OSDialog, self = .35167928 type = apply OSD ok Exception in Tkinter callback Traceback (most recent call last): File "C:\Python25\Lib\lib-tk\Tkinter.py", line 1403, in __call__ return self.func(*args) File "C:\Sandia_Meteors\New_Sentinel_Development\Sentuser_Utilities_Related\sentuser\sentuserNC25-Dev4.py", line 553, in OperationalSettings dialog = OperationalSettingsDialog( self.master, set_loc_dict ) File "C:\Sandia_Meteors\New_Sentinel_Development\Sentuser_Utilities_Related\sentuser\sentuserNC25-Dev4.py", line 81, in __init__ tkSimpleDialog.Dialog.__init__(self, parent) File "C:\Python25\lib\lib-tk\tkSimpleDialog.py", line 69, in __init__ self.wait_visibility() # window needs to be visible for the grab File "C:\Python25\Lib\lib-tk\Tkinter.py", line 415, in wait_visibility self.tk.call('tkwait', 'visibility', window._w) TclError: window ".35167928" was deleted before its visibility changed -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From rhodri at wildebst.demon.co.uk Thu Feb 12 20:27:54 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 13 Feb 2009 01:27:54 -0000 Subject: Untangling pythonWin and IDLE Processes on XP Pro In-Reply-To: References: <%OUkl.6905$jZ1.2422@flpi144.ffdc.sbc.com> <6viopfFkcasmU1@mid.uni-berlin.de> <2NWkl.16040$YU2.9824@nlpi066.nbdc.sbc.com> <4ec6562a-08b2-4ec4-b9c0-e720e4ce7339@g38g2000yqd.googlegroups.com> Message-ID: On Fri, 13 Feb 2009 01:16:38 -0000, W. eWatson wrote: > Greetings and salutations. > > I just uninstalled all traces of (Active) pythonWin 2.5.2 from this > machine, In fact, I uninstalled python 2.5.2 with IDLE from this > machine. I then reinstalled the latter. Then I ran the program. XP Pro. > > I then went to another machine that has never had pythonWin on it all, > but does have python 2.5.2 with IDLE. I ran the same program there. W2K. > > In both cases, I got the output below. Your conclusions? That you haven't listened to a word anyone has said. -- Rhodri James *-* Wildebeeste Herder to the Masses From jura.grozni at gmail.com Thu Feb 12 20:48:33 2009 From: jura.grozni at gmail.com (azrael) Date: Thu, 12 Feb 2009 17:48:33 -0800 (PST) Subject: is there a project running (GUI Builder for Python ) ? References: <85fxijh2yt.fsf@agentultra.com> <4f44bff6-d0fc-496c-9055-a50fdd06f339@c12g2000yqj.googlegroups.com> Message-ID: On Feb 12, 9:42?pm, Christian Heimes wrote: > azrael wrote: > > On Feb 12, 8:25 pm, J Kenneth King wrote: > >> azrael writes: > >>> To be honest, in compare to Visual Studio, Gui Builders for wx > >>> widgets are really bad. > >> That's because Visual Studio is a Microsoft product to build > >> interfaces for Microsoft products. > > >> wx on the other hand is cross platform and ergo, much more > >> complicated. > > > I think that WX is really great but there is really a great lack of a > > builder. > > This isn't a Python problem - really. Please discuss your issues with > the WX Gui builder on a WX list. We can't do anything about it. > > Christian How come that it is a problem for the people from WX. It is also a problem of Python. Python people say that that is not their problem. Let wX team make the work. But we, who program in python use also wX. The development of such a tool would make us all a big favour. Well if 99 percent of computer users use GUIs an prefer it in comparison with comand line, Why should it be a pain in the ass to make a application that we could offer to normal common users. From cjns1989 at gmail.com Thu Feb 12 20:48:35 2009 From: cjns1989 at gmail.com (Chris Jones) Date: Thu, 12 Feb 2009 20:48:35 -0500 Subject: Ipython - Do they have a separate mailing list or newsgroup? Message-ID: <20090213014835.GC2889@turki.gavron.org> Just wondering if ipython is supported elsewhere. Thanks, CJ From cournape at gmail.com Thu Feb 12 21:19:12 2009 From: cournape at gmail.com (David Cournapeau) Date: Fri, 13 Feb 2009 11:19:12 +0900 Subject: Ipython - Do they have a separate mailing list or newsgroup? In-Reply-To: <20090213014835.GC2889@turki.gavron.org> References: <20090213014835.GC2889@turki.gavron.org> Message-ID: <5b8d13220902121819w4ed2ac87gad056fccb0f18534@mail.gmail.com> On Fri, Feb 13, 2009 at 10:48 AM, Chris Jones wrote: > Just wondering if ipython is supported elsewhere. > The ipython mailing list is there: http://projects.scipy.org/mailman/listinfo/ipython-user David From ldl08 at gmx.net Thu Feb 12 21:20:54 2009 From: ldl08 at gmx.net (David) Date: Fri, 13 Feb 2009 10:20:54 +0800 Subject: Ipython - Do they have a separate mailing list or newsgroup? In-Reply-To: <20090213014835.GC2889@turki.gavron.org> References: <20090213014835.GC2889@turki.gavron.org> Message-ID: <4994D906.9020006@gmx.net> Chris Jones wrote: > Just wondering if ipython is supported elsewhere. Indeed, indeed: IPython-user mailing list IPython-user at scipy.org http://lists.ipython.scipy.org/mailman/listinfo/ipython-user David From cournape at gmail.com Thu Feb 12 21:25:26 2009 From: cournape at gmail.com (David Cournapeau) Date: Fri, 13 Feb 2009 11:25:26 +0900 Subject: is there a project running (GUI Builder for Python ) ? In-Reply-To: References: <85fxijh2yt.fsf@agentultra.com> <4f44bff6-d0fc-496c-9055-a50fdd06f339@c12g2000yqj.googlegroups.com> Message-ID: <5b8d13220902121825k2ce7b07aw6c5713e525d4f490@mail.gmail.com> On Fri, Feb 13, 2009 at 10:48 AM, azrael wrote: > On Feb 12, 9:42 pm, Christian Heimes wrote: >> azrael wrote: >> > On Feb 12, 8:25 pm, J Kenneth King wrote: >> >> azrael writes: >> >>> To be honest, in compare to Visual Studio, Gui Builders for wx >> >>> widgets are really bad. >> >> That's because Visual Studio is a Microsoft product to build >> >> interfaces for Microsoft products. >> >> >> wx on the other hand is cross platform and ergo, much more >> >> complicated. >> >> > I think that WX is really great but there is really a great lack of a >> > builder. >> >> This isn't a Python problem - really. Please discuss your issues with >> the WX Gui builder on a WX list. We can't do anything about it. >> >> Christian > > How come that it is a problem for the people from WX. It is also a > problem of Python. Python people say that that is not their problem. > Let wX team make the work. But we, who program in python use also wX. > The development of such a tool would make us all a big favour. Well if > 99 percent of computer users use GUIs an prefer it in comparison with > comand line, Why should it be a pain in the ass to make a application > that we could offer to normal common users. Because not all discussion related to python happens on this ML- this has nothing to do with the usefulness of GUI per-se. This is about general questions about python. David From notvalid2 at sbcglobal.net Thu Feb 12 21:40:12 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Thu, 12 Feb 2009 18:40:12 -0800 Subject: Untangling pythonWin and IDLE Processes on XP Pro In-Reply-To: <5-KdnfUPXNqQSgnUnZ2dnUVZ_sudnZ2d@earthlink.com> References: <%OUkl.6905$jZ1.2422@flpi144.ffdc.sbc.com> <6viopfFkcasmU1@mid.uni-berlin.de> <2NWkl.16040$YU2.9824@nlpi066.nbdc.sbc.com> <4ec6562a-08b2-4ec4-b9c0-e720e4ce7339@g38g2000yqd.googlegroups.com> <5-KdnfUPXNqQSgnUnZ2dnUVZ_sudnZ2d@earthlink.com> Message-ID: From Diez above. What does *NOT* work is writing a Tkinter-based app in idle, and to run it *FROM INSIDE* idle. Instead, open your explorer and double-click on the pyhton-file your app is in. That's all that there is to it. So this is the absolute truth? No wiggle room? One can never use a Tkinter program with IDLE, and execute it successfully. So IDLE doesn't issue a standard warning that says, "Get out of here with your Tkinter program, it will fail when you try to run it here. You have entered Tkinter hell. Good-bye." -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From jura.grozni at gmail.com Thu Feb 12 21:53:18 2009 From: jura.grozni at gmail.com (azrael) Date: Thu, 12 Feb 2009 18:53:18 -0800 (PST) Subject: A little bit else I would like to discuss References: <7f4cd287-dad4-4605-8b96-5edfdacc3da2@a12g2000yqm.googlegroups.com> Message-ID: <24ea9c29-6a0a-43cb-98c6-b6e486f017b9@j38g2000yqa.googlegroups.com> There is no need to make it elephant size. Python takes only 14 MB if I am not wrong. Compare 10 GB of VS package in compare with that. nothing. Python enthought edition is something really sweet. For starters, Why does Python not have a build in library to handle images. I don't get this. Why? PIL is great, but it could really need some polish. I think that the last programming language I can remind of that could not handle images, If I am not wrong was QBASIC. All I hear when I talk to people who own or eork in SW companies is "Python? Isn't that that small scripting language. This will never bring a real application." I am tired of hearing this. Even Microsoft implemented Python. Only because the GUI building I am thinking about of moving to IronPython. But this great comunity holds me bac on CPython. We need better and not out of date libraries and modules. Python was build because of bad experiences of bad programing languages. I sak The Python Development team to listen to us users an developers. listen to our problems. From gagsl-py2 at yahoo.com.ar Thu Feb 12 22:05:32 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 13 Feb 2009 01:05:32 -0200 Subject: getting caller References: Message-ID: En Thu, 12 Feb 2009 19:26:26 -0200, Hamish McKenzie escribi?: > so I'm trying to wrap some functionality around execfile but don't want > to modify the way it works. specifically when you call execfile, it > automatically grabs globals and locals from the frame the execfile > exists in. > > so if I wrap execfile in a function, I need a way to reliably get at the > calling frame. Instead of doing that, just pass the desired namespaces to be used; you'll want to use locals() and globals() for that. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Thu Feb 12 22:12:58 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 13 Feb 2009 01:12:58 -0200 Subject: getting caller References: <9e680b420902121425y6c20f6abnee3afa4059e772d1@mail.gmail.com> Message-ID: (If you aren't replying to the original message, please post an entirely *new* one to create a new thread). En Thu, 12 Feb 2009 20:25:57 -0200, Sambit Samal escribi?: > I need a python script , which binds at a user defind port & sends to > other > enity , which waits at particular port. > The other enity will respond & Python script should receive that at the > defined port > The communication will happen over UDP See the SocketServer module: http://docs.python.org/library/socketserver.html There is a simple UDP server example at the end. -- Gabriel Genellina From damonwischik at gmail.com Thu Feb 12 22:16:11 2009 From: damonwischik at gmail.com (Damon) Date: Thu, 12 Feb 2009 19:16:11 -0800 (PST) Subject: A little bit else I would like to discuss References: <7f4cd287-dad4-4605-8b96-5edfdacc3da2@a12g2000yqm.googlegroups.com> Message-ID: <3ee5cf15-27de-4ed2-ace3-9f08ab5a793d@t11g2000yqg.googlegroups.com> On Feb 12, 8:15?pm, Philip Semanchuk wrote: > Let me know when Visual Studio tries to address building GUIs for ? > Windows, OS X, Gnome, and KDE. Until then, you're comparing apples to ? > oranges, or chalk and cheese if you're from that part of the world. Right now. Use Visual Studio to program a .net application using Windows Forms. Run it in Mono on Windows, or OS X, or Linux. You can even do it with IronPython. Or, if you prefer a native look on each application, do it with wx.net. The great thing about IronPython in .net is that you can just link in any other .net library in whatever language it's written in, without needing any sort of wrapper. Admittedly, I haven't tried this, I'm just going by the hype I read on the Mono and wx.net pages. Also, you can quibble whether it's Visual Studio that tries to address this, or the Mono effort. Damon. From spacebar265 at gmail.com Thu Feb 12 22:24:21 2009 From: spacebar265 at gmail.com (Spacebar265) Date: Thu, 12 Feb 2009 19:24:21 -0800 (PST) Subject: Scanning a file character by character References: <557daab0-504f-47f4-84a7-e98000e7c3b1@y1g2000pra.googlegroups.com> <203f699b-de30-422a-aa7d-97eb62d6ebba@a12g2000pro.googlegroups.com> Message-ID: On Feb 11, 1:06?am, Duncan Booth wrote: > Steven D'Aprano wrote: > > On Mon, 09 Feb 2009 19:10:28 -0800, Spacebar265 wrote: > > >> How would I do separate lines into words without scanning one character > >> at a time? > > > Scan a line at a time, then split each line into words. > > > for line in open('myfile.txt'): > > ? ? words = line.split() > > > should work for a particularly simple-minded idea of words. > > Or for a slightly less simple minded splitting you could try re.split: > > >>> re.split("(\w+)", "The quick brown fox jumps, and falls over.")[1::2] > > ['The', 'quick', 'brown', 'fox', 'jumps', 'and', 'falls', 'over'] > > -- > Duncan Boothhttp://kupuguy.blogspot.com Using this code how would it load each word into a temporary variable. From damonwischik at gmail.com Thu Feb 12 22:39:07 2009 From: damonwischik at gmail.com (Damon) Date: Thu, 12 Feb 2009 19:39:07 -0800 (PST) Subject: A little bit else I would like to discuss References: <7f4cd287-dad4-4605-8b96-5edfdacc3da2@a12g2000yqm.googlegroups.com> Message-ID: <8655e896-8276-4c53-ac6b-557e85f96992@r41g2000yqm.googlegroups.com> On Feb 12, 8:40?pm, Christian Heimes wrote: > In your opinion all third party are bad. You like to have one monolithic > block of software. That's a typical Microsoft approach. Lot's of people > from the open source community prefer small and loosely coupled pieces > of software. One of the greatest ruler of all time once said "divide et > impera" -- divide it in small pieces to make it much easier to conquer > every piece by its own. "Divide et impera" was a strategy used by the monolithic Roman empire to divide and subjugate others. I hope that's not what happens to Python! The original poster complained about needing to go off to third-party sites to hunt for software. I wonder if the Python team has ever considered following the lead of miktex or R, and setting up a centralized (mirrored) repository of packages? Let anyone who wants, submit packages. * Like R, every time there is a new version of Python, the repository should rebuild the packages, for all supported platforms, and make available all those that compile cleanly. R also forces you to write properly structured documentation for every exposed function, before the repository will accept it. * Like miktex, when the user does "import foo", the Python interpreter should (optionally) look for foo in its cached list of packages, and download the latest version if necessary. This works fine for R and miktex, and it has made my life very easy. Damon. From gagsl-py2 at yahoo.com.ar Thu Feb 12 22:47:03 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 13 Feb 2009 01:47:03 -0200 Subject: Why does way_1() obtain the correct list but way_2() gets an empty list? References: <6vi779Fk0ogtU1@mid.individual.net> Message-ID: En Thu, 12 Feb 2009 07:07:53 -0200, WP escribi?: > Hello group! This is probably a silly newbie mistake but consider the > following program: > > import libsbml > > def getSBMLModel(biomodel_path): > reader = libsbml.SBMLReader() > > sbml_doc = reader.readSBML(biomodel_path) > sbml_model = None > > if sbml_doc.getNumErrors() > 0: > print 'I couldn\'t read the file %s!' % biomodel_path > return None > else: > sbml_model = sbml_doc.getModel() > > return sbml_doc.getModel() # None if file couldn't be opened Note that sbml_doc.getModel() is called *twice*, the first one is discarded. Probably you want to replace the last line with: return sbml_model -- Gabriel Genellina From rhodri at wildebst.demon.co.uk Thu Feb 12 22:56:20 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 13 Feb 2009 03:56:20 -0000 Subject: Scanning a file character by character In-Reply-To: References: <557daab0-504f-47f4-84a7-e98000e7c3b1@y1g2000pra.googlegroups.com> <203f699b-de30-422a-aa7d-97eb62d6ebba@a12g2000pro.googlegroups.com> Message-ID: On Fri, 13 Feb 2009 03:24:21 -0000, Spacebar265 wrote: > On Feb 11, 1:06?am, Duncan Booth wrote: >> Steven D'Aprano wrote: >> > On Mon, 09 Feb 2009 19:10:28 -0800, Spacebar265 wrote: >> >> >> How would I do separate lines into words without scanning one >> character >> >> at a time? >> >> > Scan a line at a time, then split each line into words. >> >> > for line in open('myfile.txt'): >> > ? ? words = line.split() >> >> > should work for a particularly simple-minded idea of words. >> >> Or for a slightly less simple minded splitting you could try re.split: >> >> >>> re.split("(\w+)", "The quick brown fox jumps, and falls >> over.")[1::2] >> >> ['The', 'quick', 'brown', 'fox', 'jumps', 'and', 'falls', 'over'] > Using this code how would it load each word into a temporary variable. Why on earth would you want to? Just index through the list. -- Rhodri James *-* Wildebeeste Herder to the Masses From cournape at gmail.com Thu Feb 12 23:15:33 2009 From: cournape at gmail.com (David Cournapeau) Date: Fri, 13 Feb 2009 13:15:33 +0900 Subject: A little bit else I would like to discuss In-Reply-To: <8655e896-8276-4c53-ac6b-557e85f96992@r41g2000yqm.googlegroups.com> References: <7f4cd287-dad4-4605-8b96-5edfdacc3da2@a12g2000yqm.googlegroups.com> <8655e896-8276-4c53-ac6b-557e85f96992@r41g2000yqm.googlegroups.com> Message-ID: <5b8d13220902122015g431353bci7e473abb6390ac9a@mail.gmail.com> On Fri, Feb 13, 2009 at 12:39 PM, Damon wrote: > The original poster complained about needing to go off to third-party > sites to hunt for software. I wonder if the Python team has ever > considered following the lead of miktex or R, and setting up a > centralized (mirrored) repository of packages? Let anyone who wants, > submit packages. Of course they have, that's what pypi is for. Pypi does not solve all the problems, though. > > * Like R, every time there is a new version of Python, the repository > should rebuild the packages, for all supported platforms, and make > available all those that compile cleanly. R also forces you to write > properly structured documentation for every exposed function, before > the repository will accept it. > > * Like miktex, when the user does "import foo", the Python interpreter > should (optionally) look for foo in its cached list of packages, and > download the latest version if necessary. > > This works fine for R and miktex, and it has made my life very easy. Yes, R in particular is very nice for this. But it is a complex problem - and it is even more complex for python compared to R and miktex, because python is more general. In particular, in R (and miktex I guess ?), you rarely care about having several versions installed at the same time (interpreter and/or packages), but in python, this is often useful. This complicates matter quite a bit. Having automatic download at import who annoy many users, me included. For the time being, my opinion is that the only solution for deployment on desktop apps on windows/mac os X is something like Enthought distribution, which is self contained. But when you start installing something outside Enthought, it can become tricky for "average users" (the one who don't care about the technicalities). cheers, David From pavlovevidence at gmail.com Thu Feb 12 23:17:50 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 12 Feb 2009 20:17:50 -0800 (PST) Subject: Python binaries with VC++ 8.0? References: <6va201FijdteU1@mid.individual.net> <17612b99-0756-47a1-ae4f-5e05e18813cd@r41g2000prr.googlegroups.com> <38b2p4d6g521bi0rtjiat686pamkvke3i3@4ax.com> Message-ID: <1df828ff-2bd4-4bcb-8c8d-9655dc44fae3@m42g2000yqb.googlegroups.com> On Feb 9, 11:34?pm, Tim Roberts wrote: > Carl Banks wrote: > > >I'm pretty sure 2.6.1 is compiled with 8.0. ?However, I think the > >Visual C++ 8.0 uses msvcrt90.dll. > > No, the two digits of the DLL match the version number of C++. ?The > confusion arises because the product is called "Visual Studio 2008", but it > includes Visual C++ 9.0, and hence msvcrt90.dll. ?People say "VC8" when > they really mean Visual Studio 2008. > > ? Visual Studio 98 ? ?- ?VC++ 6.0 > ? Visual Studio 2002 ?- ?VC++ 7.0 > ? Visual Studio 2003 ?- ?VC++ 7.1 > ? Visual Studio 2005 ?- ?VC++ 8.0 > ? Visual Studio 2008 ?- ?VC++ 9.0 Ah, that explains a lot. Carl Banks From banibrata.dutta at gmail.com Thu Feb 12 23:36:59 2009 From: banibrata.dutta at gmail.com (Banibrata Dutta) Date: Fri, 13 Feb 2009 10:06:59 +0530 Subject: Regarding Joystick In-Reply-To: References: Message-ID: <3de8e1f70902122036i2fc88f85h351370a9ddaababb@mail.gmail.com> AFAIK, the mechanism / API / protocol to actuate the Camera's tilt, pan, zoom functions are not standardized (happy to be corrected there!), so even if you find something, it'd most likely be something very specific to a particular device. As for Joystick usage, I remember seeing one thread on that couple of months back, so searching thru the archive should give you leads. On Fri, Feb 13, 2009 at 3:33 AM, shreyas shah wrote: > Hi , > > I am trying to control the motion of the camera with help of joystick , i > need some basic functionality where if i move a joystick to left the camera > moves to the left . Can anyone help me with that ? > > Thanks > Shreyas > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- regards, Banibrata http://www.linkedin.com/in/bdutta -------------- next part -------------- An HTML attachment was scrubbed... URL: From bkline at rksystems.com Thu Feb 12 23:43:48 2009 From: bkline at rksystems.com (Bob Kline) Date: Thu, 12 Feb 2009 23:43:48 -0500 Subject: Change in cgi module's handling of POST requests In-Reply-To: References: <4991E16F.3010407@rksystems.com> Message-ID: <4994FA84.5070806@rksystems.com> Joshua Kugler wrote: >> We just upgraded Python to 2.6 on some of our servers and a number of our >> CGI scripts broke because the cgi module has changed the way it handles >> POST requests. When the 'action' attribute was not present in the form >> element on an HTML page the module behaved as if the value of the >> attribute was the URL which brought the user to the page with the form, >> but without the query (?x=y...) part. > > This does not make sense. Can you give an example? Sure. Here's a tiny repro script: #!/usr/bin/python import cgi, xml.sax.saxutils def quote(me): return me and xml.sax.saxutils.quoteattr(str(me)) or '' print """\ Content-type: text/html
""" % quote(cgi.FieldStorage().getvalue('x')) #################### end of repro script ######################## Try it out on this pre-2.6 Python page: http://www.rksystems.com/cgi-bin/cgi-repro.py?x=y When the page comes up, click Submit. Click it several times. No change in the content of the text field, which is populated when the page first comes up from the GET request's URL, and then subsequently from the POST request's parameters. For comparison, here's the equivalent Perl page, which behaves the same way: http://www.rksystems.com/cgi-bin/cgi-repro.pl?x=y Or PHP; again, same behavior, no matter how many times you click the Submit button: http://www.rksystems.com/cgi-repro.php?x=y Now try the Python script above from a server where Python has been upgraded to version 2.6: http://mahler.nci.nih.gov/cgi-bin/cgi-repro.py?x=y Notice that when you click on the Submit button, the field is populated with the string representation of the list which FieldStorage.getvalue() returns. Each time you click the submit button you'll see the effect recursively snowballing. This is exactly the same script as the one behind the first URL above, byte for byte. >> Now FieldStorage.getvalue () is >> giving the script a list of two copies of the value for some of the >> parameters (folding in the parameters from the previous request) instead >> of the single string it used to return for each. > > There is a function call to get only one value. I think it's get_first() or > some such. That's true, but risky. I have no guarantee that the value entered by the user on the form will be first on the list. I might instead get the initial value carried over from the URL which brought up the form to begin with. We're working around the problem by modifying the broken scripts to explicitly set the action attributes. > > Well, the CGI module hasn't had many changes. There was this bug fix a few > months back: > > http://svn.python.org/view?rev=64447&view=rev Looks like that was where it happened. > It is possible that by fixing a bug, they brought the behavior in line with > what it *should* be. That's certainly possible. I'm not contending that Perl and PHP and the previous versions of Python all got it right and the new Python is wrong. It could very well be the other way around.[1] But my expectation, based on what I've seen happen over the years with other proposed changes to the language and the libraries, was that there would have been some (possibly extended) discussion of the risks of breaking existing code, and the best way to phase in the change with as little sudden breakage as possible. I haven't been able to find that discussion, and I was hoping some kind soul would point me in the right direction. > Or maybe the browser behavior changed? Clearly not, as you will see by using the same browser to try out the URLs above. If you look at the HTML source when the page first comes up for each of the scripts, you'll see it's the same. It's the behavior on the server (that is, in the Python library module) which changes. > The server > does not care about an "action" attribute. That only tells the browser > where to send the data. Well that's a pretty good formulation of the conclusion you would come to based on the behavior of all of Perl, PHP, and (pre-2.6) Python. And intuitively, that's how one (or at least I) would expect things to work. The parameters in the original URL are appropriately used to seed initial values in the form when the form is invoked with a GET request, but after that point it's hard to see them as anything but history. But that's not how the new version of the cgi module is behaving. It's folding in the parameters it finds in the original URL, which it gets from the environment's QUERY_STRING variable, in with the fields it parses from the POST request's body. > It is possible the browser did not properly format > a request when there was no "action" attribute. When the 'action' attribute is not present in the form element, the browser implicitly assigns it the value of the original URL which first brought up the page with the form. This browser behavior has not changed. It's doing the same thing no matter which version of which language and libraries are used to implement the CGI script (it has no idea what those are). Nor, as far as I have been able to determine, is this behavior dependent on which (version of which) browser you're using. > Can you provide more details? I think we should have enough specifics with what I've provided above to make it clear what's happening, but if you can think of anything I've left out which you think would be useful, let me know and I'll try to supply it. Cheers, Bob [1] I haven't yet finished my attempts to parse the relevant RFCs; I assumed that the original authors and maintainers of this module (which includes the BDFL himself), would have been more adept at that than I am, which is one of the reasons I was hoping to find some discussion in the mailing list archives of the discussion of the proposed change in the module's behavior. From mohitranka at gmail.com Thu Feb 12 23:54:47 2009 From: mohitranka at gmail.com (mohit_ranka) Date: Thu, 12 Feb 2009 20:54:47 -0800 (PST) Subject: NNTPlib encoding issue Message-ID: <6f905a64-abeb-4dba-992c-8dc6aad7326c@33g2000yqm.googlegroups.com> I am getting unknown encoding like, "=?Utf-8?B?QWRyaWFu?= " (quotes for clarity) for name of the author from nntplib module. which seems like an encoding issue with NNTPLib module. What should i do to get author name information in human readable format. Thanks and regards, Mohit Ranka From benjamin.kaplan at case.edu Fri Feb 13 00:04:04 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 13 Feb 2009 00:04:04 -0500 Subject: A little bit else I would like to discuss In-Reply-To: <3ee5cf15-27de-4ed2-ace3-9f08ab5a793d@t11g2000yqg.googlegroups.com> References: <7f4cd287-dad4-4605-8b96-5edfdacc3da2@a12g2000yqm.googlegroups.com> <3ee5cf15-27de-4ed2-ace3-9f08ab5a793d@t11g2000yqg.googlegroups.com> Message-ID: On Thu, Feb 12, 2009 at 10:16 PM, Damon wrote: > On Feb 12, 8:15 pm, Philip Semanchuk wrote: > > Let me know when Visual Studio tries to address building GUIs for > > Windows, OS X, Gnome, and KDE. Until then, you're comparing apples to > > oranges, or chalk and cheese if you're from that part of the world. > > Right now. > > Use Visual Studio to program a .net application using Windows Forms. > Run it in Mono on Windows, or OS X, or Linux. You can even do it with > IronPython. Or, if you prefer a native look on each application, do it > with wx.net. The great thing about IronPython in .net is that you can > just link in any other .net library in whatever language it's written > in, without needing any sort of wrapper. > Windows.Forms isn't native in OS X or Linux though. To get a native look, you need to use the Cocoa and GTK C-sharp bindings, which means you're not using Visual Studio. wx is actually a wrapper around the native components, so it will look nice on every platform that supports it (well, except KDE because of the Qt license issue). > > Admittedly, I haven't tried this, I'm just going by the hype I read on > the Mono and wx.net pages. Also, you can quibble whether it's Visual > Studio that tries to address this, or the Mono effort. > > Damon. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Fri Feb 13 00:09:42 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 13 Feb 2009 00:09:42 -0500 Subject: A little bit else I would like to discuss In-Reply-To: <8655e896-8276-4c53-ac6b-557e85f96992@r41g2000yqm.googlegroups.com> References: <7f4cd287-dad4-4605-8b96-5edfdacc3da2@a12g2000yqm.googlegroups.com> <8655e896-8276-4c53-ac6b-557e85f96992@r41g2000yqm.googlegroups.com> Message-ID: Damon wrote: > The original poster complained about needing to go off to third-party > sites to hunt for software. I wonder if the Python team has ever The 'Python team' is everyone who volunteers to help. How about you? > considered following the lead of miktex or R, and setting up a > centralized (mirrored) repository of packages? Let anyone who wants, > submit packages. > * Like R, every time there is a new version of Python, the repository > should rebuild the packages, for all supported platforms, and make > available all those that compile cleanly. R also forces you to write > properly structured documentation for every exposed function, before > the repository will accept it. > > * Like miktex, when the user does "import foo", the Python interpreter > should (optionally) look for foo in its cached list of packages, and > download the latest version if necessary. > > This works fine for R and miktex, and it has made my life very easy. If you have an idea on how to improve the current package index, help improve it. Appoint yourself the 'test with new release' manager. tjr From tjreedy at udel.edu Fri Feb 13 00:12:56 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 13 Feb 2009 00:12:56 -0500 Subject: A little bit else I would like to discuss In-Reply-To: <24ea9c29-6a0a-43cb-98c6-b6e486f017b9@j38g2000yqa.googlegroups.com> References: <7f4cd287-dad4-4605-8b96-5edfdacc3da2@a12g2000yqm.googlegroups.com> <24ea9c29-6a0a-43cb-98c6-b6e486f017b9@j38g2000yqa.googlegroups.com> Message-ID: azrael wrote: > We need better and not out of date libraries and modules. Python was > build because of bad experiences of bad programing languages. I sak > The Python Development team to listen to us users an developers. > listen to our problems. I ask you to help update a module or package that you care about. Join the team and contribute. tjr From tjreedy at udel.edu Fri Feb 13 00:23:34 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 13 Feb 2009 00:23:34 -0500 Subject: Untangling pythonWin and IDLE Processes on XP Pro In-Reply-To: References: <%OUkl.6905$jZ1.2422@flpi144.ffdc.sbc.com> <6viopfFkcasmU1@mid.uni-berlin.de> <2NWkl.16040$YU2.9824@nlpi066.nbdc.sbc.com> <4ec6562a-08b2-4ec4-b9c0-e720e4ce7339@g38g2000yqd.googlegroups.com> <5-KdnfUPXNqQSgnUnZ2dnUVZ_sudnZ2d@earthlink.com> Message-ID: W. eWatson wrote: > From Diez above. > What does *NOT* work is writing a Tkinter-based app in idle, and to run it > *FROM INSIDE* idle. Instead, open your explorer and double-click on the > pyhton-file your app is in. That's all that there is to it. > > So this is the absolute truth? No wiggle room? One can never use a > Tkinter program with IDLE, and execute it successfully. So IDLE doesn't > issue a standard warning that says, "Get out of here with your Tkinter > program, it will fail when you try to run it here. You have entered > Tkinter hell. Good-bye." Re-read my post about kids fighting to control a television. Maybe they work together, maybe they crash the TV. Hard to predict. ***ANY*** Python program that tries to grab and control the same resources that TK does may conflict with it. There is no way that IDLE can have a list of, for instance, all event-grabbing mainloop programs. From sudhandra_selvi at yahoo.co.in Fri Feb 13 01:18:05 2009 From: sudhandra_selvi at yahoo.co.in (sudhandra selvi) Date: Fri, 13 Feb 2009 11:48:05 +0530 (IST) Subject: similar_text in python Message-ID: <647605.23303.qm@web8905.mail.in.yahoo.com> Hi Does anyone know if Python has a function like similar_text in PHP. It compares two strings and returns a percentage for the match. Anyone know of anything like this in Python and would be willing to send along an example? thanks selvi Add more friends to your messenger and enjoy! Go to http://messenger.yahoo.com/invite/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From apt.shansen at gmail.com Fri Feb 13 01:37:47 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Thu, 12 Feb 2009 22:37:47 -0800 Subject: hpw to convert a linux python script ? In-Reply-To: References: <8848a16f-83db-4acf-a1cc-46653869f27c@z1g2000yqn.googlegroups.com> <1ac73184-be09-4b56-8ad1-7cd4896e0f7c@z6g2000pre.googlegroups.com> Message-ID: <7a9c25c20902122237i125b8610v1d553979c98a95c9@mail.gmail.com> > # Absolute path to the directory that holds media. > # Example: "/home/media/media.lawrence.com/" > MEDIA_ROOT = fsroot+'/Projects/PytDj/images/' > > Note that most Windows APIs allow you to use the forward slash as a > delimiter. It's mostly the command line and Windows Explorer that are > snotty about insisting on the backslash. Idle curiosity, why do you prefer that to: MEDIA_ROOT = os.path.join(fsroot, 'Projects', 'PytDj', 'images') Not arguing that one is actually better then the other, just curious. In my own environment we have grown a whole big filesystem abstraction layer because we have to be able to address the same resources on network volumes in the same client on multiple OS's (mainly windows and mac presently, but a linux client has long been a consideration),... and on the mac having to sometimes use mac paths (":this:that:other") and sometimes posix paths ("/this/that/other") depending on what API layer I'm poking at in a given point of view... so personally I just end up being mildly curious how everyone else handles paths and such. Cuz it was quite a bit of a pain early on. --S From brianlong at cox.net Fri Feb 13 01:44:54 2009 From: brianlong at cox.net (brianrpsgt1) Date: Thu, 12 Feb 2009 22:44:54 -0800 (PST) Subject: Break large file down into multiple files Message-ID: New to python.... I have a large file that I need to break up into multiple smaller files. I need to break the large file into sections where there are 65535 lines and then write those sections to seperate files. I am familiar with opening and writing files, however, I am struggling with creating the sections and writing the different sections to their own files. Thanks B From gagsl-py2 at yahoo.com.ar Fri Feb 13 01:52:32 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 13 Feb 2009 04:52:32 -0200 Subject: similar_text in python References: <647605.23303.qm@web8905.mail.in.yahoo.com> Message-ID: En Fri, 13 Feb 2009 04:18:05 -0200, sudhandra selvi escribi?: > Does anyone know if Python has a function like similar_text in PHP. It > compares two strings and returns a percentage for the match. Anyone > know of anything like this in Python and would be willing to send > along an example? See the difflib module. http://docs.python.org/library/difflib.html -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Fri Feb 13 02:02:52 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 13 Feb 2009 05:02:52 -0200 Subject: Break large file down into multiple files References: Message-ID: En Fri, 13 Feb 2009 04:44:54 -0200, brianrpsgt1 escribi?: > New to python.... I have a large file that I need to break up into > multiple smaller files. I need to break the large file into sections > where there are 65535 lines and then write those sections to seperate > files. I am familiar with opening and writing files, however, I am > struggling with creating the sections and writing the different > sections to their own files. This function copies at most n lines from fin to fout: def copylines(fin, fout, n): for i, line in enumerate(fin): fout.write(line) if i+1>=n: break Now you have to open the source file, create new files as needed and repeatedly call the above function until the end of source file. You'll have to enhace it bit, to know whether there are remaining lines or not. -- Gabriel Genellina From brianlong at cox.net Fri Feb 13 02:43:02 2009 From: brianlong at cox.net (brianrpsgt1) Date: Thu, 12 Feb 2009 23:43:02 -0800 (PST) Subject: Break large file down into multiple files References: Message-ID: On Feb 12, 11:02?pm, "Gabriel Genellina" wrote: > En Fri, 13 Feb 2009 04:44:54 -0200, brianrpsgt1 ? > escribi?: > > > New to python.... I have a large file that I need to break upinto > > multiple smallerfiles. I need to break the large fileintosections > > where there are 65535 lines and then write thosesectionsto seperate > >files. ?I am familiar with opening and writingfiles, however, I am > > struggling with creating thesectionsand writing the different > >sectionsto their ownfiles. > > This function copies at most n lines from fin to fout: > > def copylines(fin, fout, n): > ? ?for i, line in enumerate(fin): > ? ? ?fout.write(line) > ? ? ?if i+1>=n: break > > Now you have to open the source file, create newfilesas needed and ? > repeatedly call the above function until the end of source file. You'll ? > have to enhace it bit, to know whether there are remaining lines or not. > > -- > Gabriel Genellina Gabriel :: Thanks for the direction. Do I simply define fin, fout and n as variables above the def copylines(fin, fout, n): line? Would it look like this? fin = open('C:\Path\file') fout = 'C:\newfile.csv') n = 65535 def copylines(fin, fout, n): for i, line in enumerate(fin): ? ? ?fout.write(line) ? ? ?if i+1>=n: break Thanks B From ivanov.maxim at gmail.com Fri Feb 13 03:02:56 2009 From: ivanov.maxim at gmail.com (redbaron) Date: Fri, 13 Feb 2009 00:02:56 -0800 (PST) Subject: Break large file down into multiple files References: Message-ID: <3ee93344-685b-42e6-9fd8-f07843a0b667@k19g2000yqg.googlegroups.com> > New to python.... I have a large file that I need to break up into > multiple smaller files. I need to break the large file into sections > where there are 65535 lines and then write those sections to seperate > files. If your lines are variable-length, then look at itertools recipes. from itertools import izip_longest def grouper(n, iterable, fillvalue=None): "grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx" args = [iter(iterable)] * n return izip_longest(fillvalue=fillvalue, *args) with open("/file","r") as f: for lines in grouper(65535,f,""): data_to_write = '\n'.join(lines).rstrip("\n") ... ... From mail at microcorp.co.za Fri Feb 13 03:27:11 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Fri, 13 Feb 2009 10:27:11 +0200 Subject: is there a project running (GUI Builder for Python ) ? References: Message-ID: <01e001c98dba$310340a0$0d00a8c0@hendrik> "azrael" wrote: > To be honest, in compare to Visual Studio, Gui Builders for wx widgets > are really bad. Also completly for python there is not one good > GuiBuilder. The only one I have seen that would come near VS was > BoaConstructor, But the number of Bugs is just horrific. Too bad that > no one is developing it further. What are these horrific bugs - I was forced to use Boa on a project recently, and I did not notice any - In fact, I was impressed because everything that was there, seemed to be working properly. - Hendrik From anders.mackey at gmail.com Fri Feb 13 03:28:09 2009 From: anders.mackey at gmail.com (Fisherking) Date: Fri, 13 Feb 2009 00:28:09 -0800 (PST) Subject: Match items in large list References: <6c7720da-9e95-486c-9f28-c85ce3bc9a7e@q9g2000yqc.googlegroups.com> Message-ID: <00402c5a-725f-4941-b335-f80fc63a781c@u13g2000yqg.googlegroups.com> Thank you all for your answers! I must say I'm really impressed by the willing to help and the quick responses in this group (since it is my first post)! I solved the problem using SQL-queries. I added a id, the same for each item in a chain (two or more similar posts) and just updated the database for each unique post. I had to do this anyway and I think it is the simplest and quickest way! thanks again! From tim.wintle at teamrubber.com Fri Feb 13 03:33:49 2009 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Fri, 13 Feb 2009 08:33:49 +0000 Subject: thread. question In-Reply-To: References: <1234187238.7630.34.camel@tim-laptop> <1234193642.7630.63.camel@tim-laptop> Message-ID: <1234514029.16298.5.camel@tim-laptop> On Mon, 2009-02-09 at 21:02 +0100, Christian Heimes wrote: > The module was renamed to _thread to stop people from using it directly. > The extension module is the interface to some low level types and > functions. Especially the usage of thread.start_new_thread is > problematic, since it bypasses Python's high level threading API. Ok, I'll take that in - I'll have a look around the threading module to see what it is that it bypasses so I can persuade myself that _thread is bad ... > For the rest I have to agree with Jean-Paul. If you need performance > don't use threads! Threads and performance are orthogonal -- sometimes > they are even contradictorily. I've taken that in too - "performance" here is over a non-uniform workload (essentially a web server), but I'm probably best offloading just about all the work to a secondary process (already passed most of it) and dealing with requests in a completely synchronous process. Tim From bruno.42.desthuilliers at websiteburo.invalid Fri Feb 13 03:34:42 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 13 Feb 2009 09:34:42 +0100 Subject: something wrong with isinstance In-Reply-To: <8677703b-4284-4283-83a7-ac095eb5af4f@33g2000yqm.googlegroups.com> References: <2a84f320-8be2-4482-9513-4d7edf3295ac@j8g2000yql.googlegroups.com> <8677703b-4284-4283-83a7-ac095eb5af4f@33g2000yqm.googlegroups.com> Message-ID: <49953096$0$15292$426a74cc@news.free.fr> redbaron a ?crit : > Don't really sure, but try to define your class as new-style one. isinstance() works as well with classic classes. From mail at timgolden.me.uk Fri Feb 13 03:39:01 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 13 Feb 2009 08:39:01 +0000 Subject: Invoking CutePDF from within Python In-Reply-To: <590ed3f4-089a-41d7-aaa2-6d96f5ea1fa9@j39g2000yqn.googlegroups.com> References: <590ed3f4-089a-41d7-aaa2-6d96f5ea1fa9@j39g2000yqn.googlegroups.com> Message-ID: <499531A5.5010805@timgolden.me.uk> John Henry wrote: > I have a need to invoke CutePDF from within a Python program. > > All I need is to say "Print this to CUTEPDF and store as xyz.pdf". > Private Sub Print_PDF() > > lRetVal = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\Custom PDF > Printer", _ > 0&, vbNullString, REG_OPTION_NON_VOLATILE, > KEY_ALL_ACCESS, _ > 0&, hKey, lRetVal) > sValue = "C:\Sample.pdf" > RegSetValueExString hKey, "OutputFile", 0&, REG_SZ, sValue, Len > (sValue) > sValue = "1" > RegSetValueExString hKey, "BypassSaveAs", 0&, REG_SZ, sValue, Len > (sValue) > > Dim worddoc As Word.Document > Set worddoc = wordapp.Documents.Open("C:\Sample.doc") > wordapp.ActivePrinter = "Custom PDF Printer" > wordapp.PrintOut > worddoc.Close > > sValue = "0" > RegSetValueExString hKey, "BypassSaveAs", 0&, REG_SZ, sValue, Len > (sValue) > RegCloseKey (hKey) Direct translation (untested since I don't have CutePDF installed) import win32api import win32con import win32com hKey, ret = win32api.RegCreateKeyEx ( win32con.HKEY_CURRENT_USER, "Software\Custom PDF Printer", win32con.KEY_ALL_ACCESS ) win32api.RegSetValueEx (hKey, "OutputFile", None, win32con.REG_SZ, r"c:\sample.pdf") win32api.RegSetValueEx (hKey, "BypassSaveAs", None, win32con.REG_SZ, r"1") word = win32com.client.gencache.EnsureDispatch ("Word.Application") doc = word.Documents.Open (r"c:\sample.doc") doc.ActivePrinter = "Custom PDF Printer" word.Printout () doc.Close () win32api.RegSetValueEx (hKey, "BypassSaveAs", None, win32con.REG_SZ, r"0") FWIW, I usually generate PDFs by printing to a Postscript printer (some random Apple Laserthingy) and then using Ghostscript to do the conversion. I'm happy to post if you're interested. TJG From bruno.42.desthuilliers at websiteburo.invalid Fri Feb 13 03:50:15 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 13 Feb 2009 09:50:15 +0100 Subject: something wrong with isinstance In-Reply-To: <2a84f320-8be2-4482-9513-4d7edf3295ac@j8g2000yql.googlegroups.com> References: <2a84f320-8be2-4482-9513-4d7edf3295ac@j8g2000yql.googlegroups.com> Message-ID: <4995343c$0$4817$426a74cc@news.free.fr> maksym.kaban at gmail.com a ?crit : > Hi there. > now i'm a complete newbie for python, and maybe my problem is stupid > but i cannot solve it myself > Others already addressed your problem (cf Paul and Diez answers). I'll just allow myself to point a couple other potential problems with your code: > ##worldmap module > class GeoMap: > cells = [] > activerow = 0 > activecol = 0 Attributes defined at the class level are *class* attributes, shared by all instances of the class - that is, all instances will access the one same 'cells' list. Instance attributes are canonically created in the initialize method (__init__) that is automagically called on instanciation. IOW, you want to replace the above lines with: def __init__(self): self.cells = [] self.activerow = 0 self.activecol = 0 > def addCell(self, acell): > if len(self.cells) == 0: An empty list evals to False in a boolean context, so the above can be simply expressed as: if not self.cells: > self.cells.append([]) > self.activerow = 0 > acell.col = self.activerow > acell.row = self.activecol > self.cells[self.activerow].append(acell) > self.activecol += 1 > > def addRow(self): > self.cells.append([]) > self.activerow += 1; > self.activecol = 0; > > class GeoMapCell: > neighbours = (None, None, None, None, None, None, ) > col = 0 > row = 0 Same remark as above. You want to move all this code to the __init__ method. From bruno.42.desthuilliers at websiteburo.invalid Fri Feb 13 04:10:34 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 13 Feb 2009 10:10:34 +0100 Subject: Problem with objects copying each other in memory In-Reply-To: References: <8f4a72d2-6fb1-484a-99ef-81b4a5918997@f20g2000yqg.googlegroups.com> <6033c55d3f76cd47dbe4cbb627d016c3.squirrel@acooke.dyndns.org> Message-ID: <499538ff$0$4837$426a34cc@news.free.fr> Cameron Pulsford a ?crit : > Thanks, that did it! Why is that the case though? Or rather, why do the > assignments to temp.x and temp.y not effect the self.x and self.y? How > come I only run into the problem with the list? Because there's a huge difference between binding an object to a name and mutating an object ? First point: Python's "assignment" is really a binding of a name and an object _reference_ in a given namespace. Think of namespaces as name=>object_ref dictionnaries. This implies that "assignement" never copies anything. So when you do: >>> list1 = [] >>> list2 = list1 the second line actually creates *another* name=>object pair referencing the *same* list object. IOW, list1 and list2 are two named references to a single object: >>> list1 is list2 True >>> id(list1) == id(list2) True So whether you access it thru name 'list1' or 'list2', if you mutate the object (like append/remove/replace an element of the list), you'll see the result thru the other name as well: >>> list1.append('foo') >>> list2.append('bar') >>> list1 ['foo', 'bar'] >>> list2 ['foo', 'bar'] >>> Note FWIW that list subscripting (somelist[x] = y) is really a method call (somelist.__setitem__(x, y)) in disguise, so the same reasonning applies. Now *rebinding* a name is a different thing. It makes the name refer to another object, but has no impact on other name=>object bindings refering to the previously bound object, ie: >>> list2 = ['hou', 'lala'] Now list2 points to a newly created list object. This doesn't impact list1 of course: >>> list1 ['foo', 'bar'] >>> list1 is list2 False >>> id(list1) == id(list2) False >>> (snip) From martijnsteenwijk at gmail.com Fri Feb 13 04:30:48 2009 From: martijnsteenwijk at gmail.com (martijnsteenwijk at gmail.com) Date: Fri, 13 Feb 2009 01:30:48 -0800 (PST) Subject: Problem building Python extension Message-ID: <728a0c1c-2808-493c-a2db-c583442d2303@d32g2000yqe.googlegroups.com> Hi all, I'm trying to build my first python extensionon a win32 system. I followed the description in http://starship.python.net/crew/mwh/toext/your-first-extension.html, but after running C:\Python26\python first-setup.py build_ext -i nothing seems to happen and no file first.pyd is produced. The result from the cmd is the following: running build_ext building `first` extension error: None Does anyone have an idea what's going wrong? Thanks for replies in advance, Martijn From marco at sferacarta.com Fri Feb 13 04:49:53 2009 From: marco at sferacarta.com (Marco Mariani) Date: Fri, 13 Feb 2009 10:49:53 +0100 Subject: A little bit else I would like to discuss In-Reply-To: <7f4cd287-dad4-4605-8b96-5edfdacc3da2@a12g2000yqm.googlegroups.com> References: <7f4cd287-dad4-4605-8b96-5edfdacc3da2@a12g2000yqm.googlegroups.com> Message-ID: <5nbll.29481$8Z.20616@tornado.fastwebnet.it> azrael wrote: > I know that there is already a standard python library, But > why not extending it. classify the standard library into subcategories > like Networking, DataBase, Computation, ...... If the standard library where that huge, python 3.0 would have been late by a couple of years. > Why not using this number of people and accomplish something great. If > anyone of us would write 10 line of good code, it would result a very > great and powerfull environment. I totally want to write my 10 lines of great image processing or speech recognition software, but it's not how development works. From cournape at gmail.com Fri Feb 13 04:53:30 2009 From: cournape at gmail.com (David Cournapeau) Date: Fri, 13 Feb 2009 18:53:30 +0900 Subject: Problem building Python extension In-Reply-To: <728a0c1c-2808-493c-a2db-c583442d2303@d32g2000yqe.googlegroups.com> References: <728a0c1c-2808-493c-a2db-c583442d2303@d32g2000yqe.googlegroups.com> Message-ID: <5b8d13220902130153k9b119m5b58088350b87dba@mail.gmail.com> On Fri, Feb 13, 2009 at 6:30 PM, wrote: > Hi all, > > I'm trying to build my first python extensionon a win32 system. I > followed the description in http://starship.python.net/crew/mwh/toext/your-first-extension.html, > but after running > > C:\Python26\python first-setup.py build_ext -i > > nothing seems to happen and no file first.pyd is produced. > > The result from the cmd is the following: > running build_ext > building `first` extension > error: None It is a bug in distutils - you reminded me that I did not report it :) . IIRC, it is caused by the lack of a recognized installation VS 2008. You should either install VS 2008 (the express vesion is free) or make sure your VS 2008 is correctly installed. Building python 2.6 extensions with mingw is possible as well, but I think you need to build your own mingw (because python 2.6 requires msvcr90.dll) - maybe recent mingw have msvcrt90.dll included. cheers, David From pavlovevidence at gmail.com Fri Feb 13 05:07:58 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 13 Feb 2009 02:07:58 -0800 (PST) Subject: something wrong with isinstance References: <2a84f320-8be2-4482-9513-4d7edf3295ac@j8g2000yql.googlegroups.com> <8677703b-4284-4283-83a7-ac095eb5af4f@33g2000yqm.googlegroups.com> Message-ID: On Feb 12, 10:49?am, redbaron wrote: > Don't really sure, but try to define your class as new-style one. > Like > class GeoMap(object): > ? ?... Well, the OP said he was using Python 3.0, where all classes are new- style classes. But that brings up another very slight possibility, though not a very likely one in this case: the behavior of isinstance can be customized. It can happen unbeknownst to a user who subclasses a class that does that. Carl Banks From s.selvamsiva at gmail.com Fri Feb 13 05:16:00 2009 From: s.selvamsiva at gmail.com (S.Selvam Siva) Date: Fri, 13 Feb 2009 15:46:00 +0530 Subject: Levenshtein word comparison -performance issue Message-ID: Hi all, I need some help. I tried to find top n(eg. 5) similar words for a given word, from a dictionary of 50,000 words. I used python-levenshtein module,and sample code is as follow. def foo(searchword): disdict={} for word in self.dictionary-words: distance=Levenshtein.ratio(searchword,word) disdict[word]=distance """ sort the disdict dictionary by values in descending order """ similarwords=sorted(disdict, key=disdict.__getitem__, reverse=True) return similarwords[:5] foo() takes a search word and compares it with dictionary of 50,000 and assigns each word a value(lies between 0 to 1). Then after sorting in descending order it returns top 5 similar words. The problem is, it* takes long time* for processing(as i need to pass more search words within a loop),i guess the code could be improved to work efficiently.Your suggestions are welcome... -- Yours, S.Selvam -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Fri Feb 13 05:16:47 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 13 Feb 2009 08:16:47 -0200 Subject: Break large file down into multiple files References: Message-ID: En Fri, 13 Feb 2009 05:43:02 -0200, brianrpsgt1 escribi?: > On Feb 12, 11:02?pm, "Gabriel Genellina" > wrote: >> En Fri, 13 Feb 2009 04:44:54 -0200, brianrpsgt1 ? >> escribi?: >> >> > New to python.... I have a large file that I need to break upinto >> > multiple smallerfiles. I need to break the large fileintosections >> > where there are 65535 lines and then write thosesectionsto seperate >> >files. ?I am familiar with opening and writingfiles, however, I am >> > struggling with creating thesectionsand writing the different >> >sectionsto their ownfiles. >> >> This function copies at most n lines from fin to fout: >> >> def copylines(fin, fout, n): >> ? ?for i, line in enumerate(fin): >> ? ? ?fout.write(line) >> ? ? ?if i+1>=n: break >> >> Now you have to open the source file, create newfilesas needed and ? >> repeatedly call the above function until the end of source file. You'll >> ? >> have to enhace it bit, to know whether there are remaining lines or not. >> >> -- >> Gabriel Genellina > > Gabriel :: > > Thanks for the direction. Do I simply define fin, fout and n as > variables above the def copylines(fin, fout, n): line? > > Would it look like this? > > fin = open('C:\Path\file') > fout = 'C:\newfile.csv') > n = 65535 Warning: see this FAQ entry http://www.python.org/doc/faq/general/#why-can-t-raw-strings-r-strings-end-with-a-backslash > > def copylines(fin, fout, n): > for i, line in enumerate(fin): > ? ? ?fout.write(line) > ? ? ?if i+1>=n: break Almost. You have to *call* the copylines function, not just define it. After calling it with: copylines(fin, fout, 65535), you'll have the *first* chunk of lines copied. So you'll need to create a second file, call the copylines function again, create a third file, call... You'll need some kind of loop, and a way to detect when to stop and break out of it. The copylines function already knows what happened (whether there are more lines to copy or not) so you should enhace it and return such information to the caller. It isn't so hard, after working out the tutorial (linked from http://wiki.python.org/moin/BeginnersGuide ) you'll know enough Python to finish this program. If you have some previous programming experience, Dive into Python (linked from the Beginners Guide above) is a good online book. Feel free to come back when you're stuck with something. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Fri Feb 13 05:27:35 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 13 Feb 2009 08:27:35 -0200 Subject: something wrong with isinstance References: <2a84f320-8be2-4482-9513-4d7edf3295ac@j8g2000yql.googlegroups.com> <8677703b-4284-4283-83a7-ac095eb5af4f@33g2000yqm.googlegroups.com> Message-ID: En Fri, 13 Feb 2009 08:07:58 -0200, Carl Banks escribi?: > Well, the OP said he was using Python 3.0, where all classes are new- > style classes. > > But that brings up another very slight possibility, though not a very > likely one in this case: the behavior of isinstance can be > customized. It can happen unbeknownst to a user who subclasses a > class that does that. Really? I didn't know that -- how do you do that? -- Gabriel Genellina From pavlovevidence at gmail.com Fri Feb 13 05:36:05 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 13 Feb 2009 02:36:05 -0800 (PST) Subject: thread. question References: <1234187238.7630.34.camel@tim-laptop> Message-ID: On Feb 9, 7:34?am, Tim Wintle wrote: > Thanks for both replies, > > On Mon, 2009-02-09 at 15:59 +0100, Christian Heimes wrote: > > You shouldn't use the thread module directly. It's not meant to be used > > by a user. Please stick to the threading module. You won't notice a > > slowdown, trust me :) > > I'm aware that thread is being renamed to _thread in python 3.0, but is > it being depricated or anything like that? > > This is for an app that has been running for quite a long time and it's > now time for fairly heavy optimisations as load is increasing (Believe > me, I wouldn't have been looking at the C otherwise) - so I'll see if I > do notice any effect with threading. The threading module is likely to be slightly slower when spawning new threads, because the Thread class has a bit of overhead that allows you to do things like thread.join(). Simple locking will be same speed whether you use the threading or thread module, because threading.Lock and thread.acquire return the same type of object. This is an implementation detail, though. Carl Banks From gagsl-py2 at yahoo.com.ar Fri Feb 13 05:42:19 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 13 Feb 2009 08:42:19 -0200 Subject: Levenshtein word comparison -performance issue References: Message-ID: En Fri, 13 Feb 2009 08:16:00 -0200, S.Selvam Siva escribi?: > I need some help. > I tried to find top n(eg. 5) similar words for a given word, from a > dictionary of 50,000 words. > I used python-levenshtein module,and sample code is as follow. > > def foo(searchword): > disdict={} > for word in self.dictionary-words: > distance=Levenshtein.ratio(searchword,word) > disdict[word]=distance > """ > sort the disdict dictionary by values in descending order > """ > similarwords=sorted(disdict, key=disdict.__getitem__, reverse=True) > > return similarwords[:5] You may replace the last steps (sort + slice top 5) by heapq.nlargest - at least you won't waste time sorting 49995 irrelevant words... Anyway you should measure the time taken by the first part (Levenshtein), it may be the most demanding. I think there is a C extension for this, should be much faster than pure Python calculations. -- Gabriel Genellina From __peter__ at web.de Fri Feb 13 05:43:03 2009 From: __peter__ at web.de (Peter Otten) Date: Fri, 13 Feb 2009 11:43:03 +0100 Subject: something wrong with isinstance References: <2a84f320-8be2-4482-9513-4d7edf3295ac@j8g2000yql.googlegroups.com> <8677703b-4284-4283-83a7-ac095eb5af4f@33g2000yqm.googlegroups.com> Message-ID: Gabriel Genellina wrote: > En Fri, 13 Feb 2009 08:07:58 -0200, Carl Banks > escribi?: > >> Well, the OP said he was using Python 3.0, where all classes are new- >> style classes. >> >> But that brings up another very slight possibility, though not a very >> likely one in this case: the behavior of isinstance can be >> customized. It can happen unbeknownst to a user who subclasses a >> class that does that. > > Really? I didn't know that -- how do you do that? >>> class Type(type): ... def __instancecheck__(self, other): return True ... >>> class A(metaclass=Type): pass ... >>> class B: pass ... >>> isinstance(B(), A) True See also http://www.python.org/dev/peps/pep-3119/#overloading-isinstance-and-issubclass I doubt that this is the source of the OP's troubles, though. Peter From martijnsteenwijk at gmail.com Fri Feb 13 05:58:29 2009 From: martijnsteenwijk at gmail.com (martijnsteenwijk at gmail.com) Date: Fri, 13 Feb 2009 02:58:29 -0800 (PST) Subject: Problem building Python extension References: <728a0c1c-2808-493c-a2db-c583442d2303@d32g2000yqe.googlegroups.com> Message-ID: On 13 feb, 10:53, David Cournapeau wrote: > On Fri, Feb 13, 2009 at 6:30 PM, ? wrote: > > Hi all, > > > I'm trying to build my first python extensionon a win32 system. I > > followed the description inhttp://starship.python.net/crew/mwh/toext/your-first-extension.html, > > but after running > > > C:\Python26\python first-setup.py build_ext -i > > > nothing seems to happen and no file first.pyd is produced. > > > The result from the cmd is the following: > > running build_ext > > building `first` extension > > error: None > > It is a bug in distutils - you reminded me that I did not report it :) > . IIRC, it is caused by the lack of a recognized installation VS 2008. > You should either install VS 2008 (the express vesion is free) or make > sure your VS 2008 is correctly installed. > > Building python 2.6 extensions with mingw is possible as well, but I > think you need to build your own mingw (because python 2.6 requires > msvcr90.dll) - maybe recent mingw have msvcrt90.dll included. > > cheers, > > David Thanks a lot for your reply. I downloaded & installed Visual C# 2008 express, but unfortunately this doesn't change anything in running the setup file. Unfortunately, still no pyd file is produced... Did I something wrong? From gagsl-py2 at yahoo.com.ar Fri Feb 13 05:58:41 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 13 Feb 2009 08:58:41 -0200 Subject: Change in cgi module's handling of POST requests References: <4991E16F.3010407@rksystems.com> <4994FA84.5070806@rksystems.com> Message-ID: En Fri, 13 Feb 2009 02:43:48 -0200, Bob Kline escribi?: > Joshua Kugler wrote: >>> We just upgraded Python to 2.6 on some of our servers and a number of >>> our >>> CGI scripts broke because the cgi module has changed the way it handles >>> POST requests. When the 'action' attribute was not present in the >>> form element on an HTML page the module behaved as if the value of the >>> attribute was the URL which brought the user to the page with the form, >>> but without the query (?x=y...) part. > [1] I haven't yet finished my attempts to parse the relevant RFCs; I > assumed that the original authors and maintainers of this module (which > includes the BDFL himself), would have been more adept at that than I > am, which is one of the reasons I was hoping to find some discussion in > the mailing list archives of the discussion of the proposed change in > the module's behavior. I noticed this change in behaviour too, and indeed, it is due to http://bugs.python.org/issue1817 But I could not find any RFC/standard/reccomendation/whatever that clearly states *what* should happen with a POST request directed to an URI having a query string itself. So I could not say "it's a bug" -- it's just... annoying in these cases (although it might be useful in some other cases, I think) A posible workaround is to ensure all forms have an action attribute, and that it doesn't contain any query string. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Fri Feb 13 05:59:01 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 13 Feb 2009 08:59:01 -0200 Subject: something wrong with isinstance References: <2a84f320-8be2-4482-9513-4d7edf3295ac@j8g2000yql.googlegroups.com> <8677703b-4284-4283-83a7-ac095eb5af4f@33g2000yqm.googlegroups.com> Message-ID: En Fri, 13 Feb 2009 08:43:03 -0200, Peter Otten <__peter__ at web.de> escribi?: > Gabriel Genellina wrote: >> En Fri, 13 Feb 2009 08:07:58 -0200, Carl Banks >> >> escribi?: >>> But that brings up another very slight possibility, though not a very >>> likely one in this case: the behavior of isinstance can be >>> customized. It can happen unbeknownst to a user who subclasses a >>> class that does that. >> >> Really? I didn't know that -- how do you do that? > >>>> class Type(type): > ... def __instancecheck__(self, other): return True > ... >>>> class A(metaclass=Type): pass > ... >>>> class B: pass > ... >>>> isinstance(B(), A) > True > > See also > > http://www.python.org/dev/peps/pep-3119/#overloading-isinstance-and-issubclass Ah, ok. Isn't menctioned in the main documentation though. -- Gabriel Genellina From greg.ewing at canterbury.ac.nz Fri Feb 13 06:11:02 2009 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sat, 14 Feb 2009 00:11:02 +1300 Subject: ANN: Supy 1.1 Message-ID: SuPy 1.1 Available ------------------ http://www.cosc.canterbury.ac.nz/greg.ewing/SuPy/ Changes in this version: - Added explicit ways of calling method names ending in '?' or '!'. Python method names 'is_xxx' and 'xxx_ip' map to Ruby 'xxx?' and 'xxx!' respectively. The plain name 'xxx' can still be used where there is no ambiguity. - Ruby true and false are now converted to Python True and False. - Ruby methods expecting a block can be called from Python by passing a callable Python object with the keyword 'body'. What is SuPy? ------------- SuPy is a plugin for the Sketchup 3D modelling application that lets you script it in Python. -- Greg Ewing greg.ewing at canterbury.ac.nz From notvalid2 at sbcglobal.net Fri Feb 13 06:13:38 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Fri, 13 Feb 2009 03:13:38 -0800 Subject: Untangling pythonWin and IDLE Processes on XP Pro In-Reply-To: References: <%OUkl.6905$jZ1.2422@flpi144.ffdc.sbc.com> <6viopfFkcasmU1@mid.uni-berlin.de> <2NWkl.16040$YU2.9824@nlpi066.nbdc.sbc.com> <4ec6562a-08b2-4ec4-b9c0-e720e4ce7339@g38g2000yqd.googlegroups.com> <5-KdnfUPXNqQSgnUnZ2dnUVZ_sudnZ2d@earthlink.com> Message-ID: <1Bcll.10420$hc1.4903@flpi150.ffdc.sbc.com> Terry Reedy wrote: > W. eWatson wrote: >> From Diez above. >> What does *NOT* work is writing a Tkinter-based app in idle, and to >> run it >> *FROM INSIDE* idle. Instead, open your explorer and double-click on the >> pyhton-file your app is in. That's all that there is to it. >> >> So this is the absolute truth? No wiggle room? One can never use a >> Tkinter program with IDLE, and execute it successfully. So IDLE >> doesn't issue a standard warning that says, "Get out of here with your >> Tkinter program, it will fail when you try to run it here. You have >> entered Tkinter hell. Good-bye." > > Re-read my post about kids fighting to control a television. Maybe they > work together, maybe they crash the TV. Hard to predict. > > ***ANY*** Python program that tries to grab and control the same > resources that TK does may conflict with it. There is no way that IDLE > can have a list of, for instance, all event-grabbing mainloop programs. > OK, enough tinkering with the code and others matters on my end trying to find a work around. Somehow after much successful use of IDLE's execution facility, I've stepped on an invisible banana peel. I think it's evident that I'm not going around this problem easily with the IDLE execution attempts, and that another solution is required. First, I think somewhere up the thread someone suggested that Active pythonWin is not dependent upon Tk, correct? Therefore, it is immune from such problems, correct? Second, maybe I missed it above, but when I posted the output from the program that showed the failure, was there anything that said, "IDLE problem" or would even give a clue that's the culprit? Finally, we can probably agree that I can continue to use IDLE for editing and syntax checking, but to "guarantee" successful execution of the program, I can just double-click on the py file in my folder. Perhaps there is a better way than clicking on it in the folder. For example, putting it on the desktop. As I look at the folder, previous copies only differ by a digit, I can easily find myself executing an earlier version, differing as Dev4, to Dev5 at the end of each name. Let me ask this. When I install Active Python, am I getting something beyond their interface? That is, does executing the code there result in using the same python interpreter that is used by IDLE? My use of their editor has been somewhat exasperating. It does not seem as friendly as the IDLE editor. I still find it bizarre that the original creator of this program can spend months using IDLE to develop this program, and that I've spent maybe 10 days recently now adding to it without having much, if any, problem with IDLE and the programs execution within IDLE. I asked him almost a year ago what tool he used. IDLE, was the reply. Maybe it was really IDLE with no execution from inside IDLE. I'll ask him. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From cournape at gmail.com Fri Feb 13 06:15:03 2009 From: cournape at gmail.com (David Cournapeau) Date: Fri, 13 Feb 2009 20:15:03 +0900 Subject: Problem building Python extension In-Reply-To: References: <728a0c1c-2808-493c-a2db-c583442d2303@d32g2000yqe.googlegroups.com> Message-ID: <5b8d13220902130315m433f25day88e9df65c24d9f66@mail.gmail.com> On Fri, Feb 13, 2009 at 7:58 PM, wrote: > On 13 feb, 10:53, David Cournapeau wrote: >> On Fri, Feb 13, 2009 at 6:30 PM, wrote: >> > Hi all, >> >> > I'm trying to build my first python extensionon a win32 system. I >> > followed the description inhttp://starship.python.net/crew/mwh/toext/your-first-extension.html, >> > but after running >> >> > C:\Python26\python first-setup.py build_ext -i >> >> > nothing seems to happen and no file first.pyd is produced. >> >> > The result from the cmd is the following: >> > running build_ext >> > building `first` extension >> > error: None >> >> It is a bug in distutils - you reminded me that I did not report it :) >> . IIRC, it is caused by the lack of a recognized installation VS 2008. >> You should either install VS 2008 (the express vesion is free) or make >> sure your VS 2008 is correctly installed. >> >> Building python 2.6 extensions with mingw is possible as well, but I >> think you need to build your own mingw (because python 2.6 requires >> msvcr90.dll) - maybe recent mingw have msvcrt90.dll included. >> >> cheers, >> >> David > > Thanks a lot for your reply. I downloaded & installed Visual C# 2008 > express, but unfortunately this doesn't change anything in running the > setup file. Unfortunately, still no pyd file is produced... I am not 100 % confident, but I think the problem is that for Visual Studio express, you need to build the extension in a Visual Studio shell (in the VS 2008 express menu). If that still does not work, I will check on a windows VM (I need to do the bug report anyway). cheers, David From carlos.mora at atisa.es Fri Feb 13 06:15:13 2009 From: carlos.mora at atisa.es (cm) Date: Fri, 13 Feb 2009 12:15:13 +0100 Subject: Invoking CutePDF from within Python References: <590ed3f4-089a-41d7-aaa2-6d96f5ea1fa9@j39g2000yqn.googlegroups.com> Message-ID: Hi John, > All I need is to say "Print this to CUTEPDF and store as xyz.pdf". I can't answer you question but let me make a suggestion: Try PdfCreator. It lets you control all the process using an activex control. It has events to tell you when the jobs has finish, or report you of eventual errors. Download it from sf.net, and look into the samples. Best regards, Carlos. From cwitts at gmail.com Fri Feb 13 06:19:52 2009 From: cwitts at gmail.com (Chris) Date: Fri, 13 Feb 2009 03:19:52 -0800 (PST) Subject: Break large file down into multiple files References: <3ee93344-685b-42e6-9fd8-f07843a0b667@k19g2000yqg.googlegroups.com> Message-ID: <61a8c5b2-9b81-4b51-a2c3-f9e43b01586f@m42g2000yqb.googlegroups.com> On Feb 13, 10:02?am, redbaron wrote: > > New to python.... I have a large file that I need to break up into > > multiple smaller files. I need to break the large file into sections > > where there are 65535 lines and then write those sections to seperate > > files. > > If your lines are variable-length, then look at itertools recipes. > > from itertools import izip_longest > > def grouper(n, iterable, fillvalue=None): > ? ? "grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx" > ? ? args = [iter(iterable)] * n > ? ? return izip_longest(fillvalue=fillvalue, *args) > > with open("/file","r") as f: > ? ? for lines in grouper(65535,f,""): > ? ? ? ? data_to_write = '\n'.join(lines).rstrip("\n") > ? ? ? ? ... > ? ? ? ? > ? ? ? ? ... I really would not recommend joining a large about of lines, that will take some times. fIn = open(input_filename, 'rb') chunk_size = 65535 for i,line in enumerate(fIn): if not i: # First Line in the File, create a file to start writing to filenum = '%04d'%(i%chunk_size)+1 fOut = open('%s.txt'%filenum, 'wb') if i and not i % chunk_size: # Once at the chunk_size close the old file object and create a new one fOut.close() filenum = '%04d'%(i%chunk_size)+1 fOut = open('%s.txt'%filenum, 'wb') if not i % 1000: fOut.flush() fOut.write(line) fOut.close() fIn.close() From cwitts at gmail.com Fri Feb 13 06:36:11 2009 From: cwitts at gmail.com (Chris) Date: Fri, 13 Feb 2009 03:36:11 -0800 (PST) Subject: Break large file down into multiple files References: <3ee93344-685b-42e6-9fd8-f07843a0b667@k19g2000yqg.googlegroups.com> <61a8c5b2-9b81-4b51-a2c3-f9e43b01586f@m42g2000yqb.googlegroups.com> Message-ID: On Feb 13, 1:19?pm, Chris wrote: > On Feb 13, 10:02?am, redbaron wrote: > > > > > > New to python.... I have a large file that I need to break up into > > > multiple smaller files. I need to break the large file into sections > > > where there are 65535 lines and then write those sections to seperate > > > files. > > > If your lines are variable-length, then look at itertools recipes. > > > from itertools import izip_longest > > > def grouper(n, iterable, fillvalue=None): > > ? ? "grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx" > > ? ? args = [iter(iterable)] * n > > ? ? return izip_longest(fillvalue=fillvalue, *args) > > > with open("/file","r") as f: > > ? ? for lines in grouper(65535,f,""): > > ? ? ? ? data_to_write = '\n'.join(lines).rstrip("\n") > > ? ? ? ? ... > > ? ? ? ? > > ? ? ? ? ... > > I really would not recommend joining a large about of lines, that will > take some times. > > fIn = open(input_filename, 'rb') > chunk_size = 65535 > > for i,line in enumerate(fIn): > ? ? if not i: ? # First Line in the File, create a file to start > writing to > ? ? ? ? filenum = '%04d'%(i%chunk_size)+1 > ? ? ? ? fOut = open('%s.txt'%filenum, 'wb') > ? ? if i and not i % chunk_size: ? # Once at the chunk_size close the > old file object and create a new one > ? ? ? ? fOut.close() > ? ? ? ? filenum = '%04d'%(i%chunk_size)+1 > ? ? ? ? fOut = open('%s.txt'%filenum, 'wb') > ? ? if not i % 1000: > ? ? ? ? fOut.flush() > ? ? fOut.write(line) > > fOut.close() > fIn.close() Whoops, day-dreaming mistake. Use "filenum = '%04d'%(i/chunk_size)+1" and not i%chunk_size. From python.list at tim.thechases.com Fri Feb 13 06:38:06 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 13 Feb 2009 05:38:06 -0600 Subject: Break large file down into multiple files In-Reply-To: References: Message-ID: <49955B9E.2070209@tim.thechases.com> > New to python.... I have a large file that I need to break up > into multiple smaller files. I need to break the large file > into sections where there are 65535 lines and then write those > sections to seperate files. I am familiar with opening and > writing files, however, I am struggling with creating the > sections and writing the different sections to their own > files. While this thread has offered many nice Python solutions, the "split" command is pretty standard on most Linux boxes: bash$ split -l 65535 infile.txt which will do what you describe. You can read the man page for more details. So if you just want a fast route to a goal rather than going through the learning process (I'm all for learning how to do it too), this may be a quick answer. -tkc From lists at cheimes.de Fri Feb 13 06:45:30 2009 From: lists at cheimes.de (Christian Heimes) Date: Fri, 13 Feb 2009 12:45:30 +0100 Subject: Problem building Python extension In-Reply-To: References: <728a0c1c-2808-493c-a2db-c583442d2303@d32g2000yqe.googlegroups.com> Message-ID: martijnsteenwijk at gmail.com wrote: > Thanks a lot for your reply. I downloaded & installed Visual C# 2008 > express, but unfortunately this doesn't change anything in running the > setup file. Unfortunately, still no pyd file is produced... > > Did I something wrong? Yeah, you installed the C# environment. Python is written in C, so you have to get Visual Studio C++ 2008. However a recent version of MinGW32 is sufficient to build most extensions. Christian From juergen.riemer at gmail.com Fri Feb 13 06:49:05 2009 From: juergen.riemer at gmail.com (JuergenRiemer) Date: Fri, 13 Feb 2009 03:49:05 -0800 (PST) Subject: get wget log message Message-ID: <6eb958bd-3d9b-4388-99c0-944268914be1@x10g2000yqk.googlegroups.com> Hi, I didn't succeed to do the following: I download a PDF file via wget yet I am not interested in the file itself but the wget verbose output (log message) e.g. download speed, total size, etc. I know I could use < -o log.txt > and then read from that file yet this seems not very elegant. I am new to both wget/linux and python and am struggling for quite some time now, could anyone help me here? thx a lot Juergen From gnewsg at gmail.com Fri Feb 13 07:00:17 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Fri, 13 Feb 2009 04:00:17 -0800 (PST) Subject: Problem building Python extension References: <728a0c1c-2808-493c-a2db-c583442d2303@d32g2000yqe.googlegroups.com> Message-ID: On Feb 13, 10:53?am, David Cournapeau wrote: > On Fri, Feb 13, 2009 at 6:30 PM, ? wrote: > > Hi all, > > > I'm trying to build my first python extensionon a win32 system. I > > followed the description inhttp://starship.python.net/crew/mwh/toext/your-first-extension.html, > > but after running > > > C:\Python26\python first-setup.py build_ext -i > > > nothing seems to happen and no file first.pyd is produced. > > > The result from the cmd is the following: > > running build_ext > > building `first` extension > > error: None > > It is a bug in distutils - you reminded me that I did not report it :) > . IIRC, it is caused by the lack of a recognized installation VS 2008. > You should either install VS 2008 (the express vesion is free) or make > sure your VS 2008 is correctly installed. > > Building python 2.6 extensions with mingw is possible as well, but I > think you need to build your own mingw (because python 2.6 requires > msvcr90.dll) - maybe recent mingw have msvcrt90.dll included. > > cheers, > > David I already reported that: http://bugs.python.org/issue4931 --- Giampaolo http://code.google.com/p/pyftpdlib From juergen.riemer at gmail.com Fri Feb 13 07:02:37 2009 From: juergen.riemer at gmail.com (JuergenRiemer) Date: Fri, 13 Feb 2009 04:02:37 -0800 (PST) Subject: get wget log message References: <6eb958bd-3d9b-4388-99c0-944268914be1@x10g2000yqk.googlegroups.com> Message-ID: > itself but the wget verbose output (log message) e.g. download speed, > total size, etc. ahh I got it 1 minute after sending this post grrrr commands.getstatusoutput(cmd) Juergen From paul at boddie.org.uk Fri Feb 13 07:03:44 2009 From: paul at boddie.org.uk (Paul Boddie) Date: Fri, 13 Feb 2009 04:03:44 -0800 (PST) Subject: Change in cgi module's handling of POST requests References: <4991E16F.3010407@rksystems.com> <4994FA84.5070806@rksystems.com> Message-ID: <9436b83e-5283-466a-a1d9-0822bcca37e7@h20g2000yqn.googlegroups.com> On 13 Feb, 11:58, "Gabriel Genellina" wrote: > > I noticed this change in behaviour too, and indeed, it is due to ?http://bugs.python.org/issue1817 > But I could not find any RFC/standard/reccomendation/whatever that clearly ? > states *what* should happen with a POST request directed to an URI having ? > a query string itself. So I could not say "it's a bug" -- it's just... ? > annoying in these cases (although it might be useful in some other cases, ? > I think) The issue of distinguishing between query-originating parameters and form-originating parameters has been around for a very long time, and in my own work, especially where the cgi module has been used, I've been careful to distinguish between the two types and to merge them only if this is desired (get_fields vs. get_fields_from_path and get_fields_from_body in WebStack). If the cgi module has now changed its behaviour to just merge the two data sources, I can imagine that a few applications aren't going to be happy any more, and since I doubt that I'm the only one to take the approach I've just described, I can imagine that I'm not alone in regarding this "bug fix" as more of a regression if it has been done in a way which does not preserve the behaviour of unmodified existing code. Paul From martin at marcher.name Fri Feb 13 07:08:02 2009 From: martin at marcher.name (Martin) Date: Fri, 13 Feb 2009 13:08:02 +0100 Subject: A little bit else I would like to discuss In-Reply-To: References: <7f4cd287-dad4-4605-8b96-5edfdacc3da2@a12g2000yqm.googlegroups.com> <5fa6c12e0902121336w6716187awc9495f852791988d@mail.gmail.com> Message-ID: <5fa6c12e0902130408k2bf075f0x138ffcd93b1df92b@mail.gmail.com> 2009/2/12 Christian Heimes : > Martin wrote: > [typos igored as requested ;)] > >> How does "small and agile" work with "batteries included"? > > The Python slogan says "batteries included", not "fusion reactor included". I'd be fine with a fusion reactor, my objections would be if skynet was included :) > The rules are: > > ... > > It takes at least 1.5 years to get a new feature into an extension and > at least 3 years to remove or change a feature. That's a major shop > stopper for every fast moving piece of Python software. True, I thought a bit more about it and decided for myself to be happy with the way it is since I prefer quality to features :) /Martin -- http://soup.alt.delete.co.at http://www.xing.com/profile/Martin_Marcher http://www.linkedin.com/in/martinmarcher You are not free to read this message, by doing so, you have violated my licence and are required to urinate publicly. Thank you. Please avoid sending me Word or PowerPoint attachments. See http://www.gnu.org/philosophy/no-word-attachments.html From google at mrabarnett.plus.com Fri Feb 13 07:25:24 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 13 Feb 2009 12:25:24 +0000 Subject: NNTPlib encoding issue In-Reply-To: <6f905a64-abeb-4dba-992c-8dc6aad7326c@33g2000yqm.googlegroups.com> References: <6f905a64-abeb-4dba-992c-8dc6aad7326c@33g2000yqm.googlegroups.com> Message-ID: <499566B4.8080608@mrabarnett.plus.com> mohit_ranka wrote: > I am getting unknown encoding like, "=?Utf-8?B?QWRyaWFu?= > " (quotes for clarity) for name of > the author from nntplib module. which seems like an encoding issue > with NNTPLib module. > > What should i do to get author name information in human readable > format. > The original text was encoded in UTF-8 and then into base-64: =?Utf-8?B?QWRyaWFu?= ^^^^^ UTF-8 =?Utf-8?B?QWRyaWFu?= ^ Base-64 So that's: >>> "QWRyaWFu".decode("base-64").decode("Utf-8") u'Adrian' From gideon.smeding at gmail.com Fri Feb 13 08:13:09 2009 From: gideon.smeding at gmail.com (gideon) Date: Fri, 13 Feb 2009 05:13:09 -0800 (PST) Subject: An executable operational semantics for Python References: <01cf8180-87e2-472a-9891-eb687fdd5e6c@j8g2000yql.googlegroups.com> Message-ID: On Feb 12, 5:14?pm, bearophileH... at lycos.com wrote: > gideon: > > > I've recently finished my Master's thesis on the semantics of Python. > > In my thesis I define the semantics of Python by rewriting an abstract > > machine. The sources that are used to produce my thesis can also be > > compiled into a working interpreter. Hence I call it an 'executable' > >semantics. > > Can it be used for some useful purpose? The interpreter? Probably not. The semantics. Yes. From berend at dotmpe.com Fri Feb 13 08:58:03 2009 From: berend at dotmpe.com (Berend van Berkum) Date: Fri, 13 Feb 2009 14:58:03 +0100 Subject: sgmllib parser keeps old tag data? Message-ID: <20090213135803.GB2168@iris.furrow.ath.cx> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi everyone, I read the source, made numerous tests, but SGMLParser's keeps returning *tag* data from previous parser instances. I'm totally confused why.. The content data it returns is ok. E.g.:: sp = MyParser() sp.feed('Test') print sp.content, sp.markup sp.close() sp = MyParser() sp.feed('\n\r\n') print sp.content, sp.markup sp.close() gives:: ('Test', [{'t': ({}, (0, 0))}, {'test': ({}, (0, 4))}]) ('\n\r\n', [{'t': ({}, (0, 0))}, {'test': ({}, (0, 4))}, {'xml': ({}, (0, 1))}]) It keeps the tags from the previous session, while i'm sure the stack etc. should be clean.. Any ideas? regards, Berend - ---- import sgmllib class MyParser(sgmllib.SGMLParser): content = '' markup = [] span_stack = [] def handle_data(self, data): self.content += data def unknown_starttag(self, tag, attr): stack = { tag: ( dict(attr), ( len(self.content), ) ) } self.span_stack.append(stack) def unknown_endtag(self, tag): prev_tag, ( attr, ( offset, ) ) = self.span_stack.pop().items()[0] if tag: # close all tags on stack until it finds a matching end tag # XXX: need to return to LEVEL, not same tag name while tag != prev_tag: span = { prev_tag: ( attr, ( offset, 0 ) ) } self.markup.append( span ) prev_tag, ( attr, ( offset, ) ) = self.span_stack.pop().items()[0] length = len( self.content ) - offset span = { tag: ( attr, ( offset, length ) ) } self.markup.append( span ) def do_unknown_tag(self, tag, attr): assert not tag and not attr, "do_unknown_tag %s, %s" % (tag, attr) def close(self): sgmllib.SGMLParser.close(self) self.content = '' self.markup = [] self.span_stack = [] def parse_data(data): sp = MyParser() sp.feed(data) r = sp.content, sp.markup sp.close() return r print parse_data('Test') print parse_data('\n\r\n') print parse_data('Test 3') - -- web, http://dotmpe.com () ASCII Ribbon email, berend.van.berkum at gmail.com /\ icq, 26727647; irc, berend/mpe at irc.oftc.net -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFJlXxrn70fkTNDJRgRArWwAKCbhe/FwOu3/XtAja7+rbvIv29HEQCgwtf3 k3eiwfD0yw6t+giXJy1nako= =afE6 -----END PGP SIGNATURE----- From news123 at free.fr Fri Feb 13 09:04:33 2009 From: news123 at free.fr (News123) Date: Fri, 13 Feb 2009 15:04:33 +0100 Subject: best set of modules for web automation without javascript Message-ID: <49957df1$0$15145$426a74cc@news.free.fr> Hi, I'd like to do some web automation with python 2.5 - https: - a cookiejar - some forms to be filled in what is the best set of modules. As far as I understood, there is httplib, but it seems (if I understood well) to be incoompatible with cookielib I'm a newcomer to webautomation with python and would be thankful for good suggestions. I used so far perl with LWP::UserAgent HTTP::Cookies and some module (I forgot the name) to handle parsing and filling in Forms. thanks in advance for any pointers opinions N From goon12 at gmail.com Fri Feb 13 09:23:21 2009 From: goon12 at gmail.com (Joe Riopel) Date: Fri, 13 Feb 2009 09:23:21 -0500 Subject: best set of modules for web automation without javascript In-Reply-To: <49957df1$0$15145$426a74cc@news.free.fr> References: <49957df1$0$15145$426a74cc@news.free.fr> Message-ID: <6a2ccd190902130623ra571796o62d0143a1ddca6bb@mail.gmail.com> On Fri, Feb 13, 2009 at 9:04 AM, News123 wrote: > Hi, > I'd like to do some web automation with python 2.5 > - https: > - a cookiejar > - some forms to be filled in > what is the best set of modules. I have automated some testing of our product, using it's web UI with Python with urllib2 and urrlib. I don't actually fill in the forms, I just recreate the post and set the values of the post variables (so I don't get any form validation). Check out: urllib2.build_opener urllib2.HTTPCookieProcessor urllib2.Request From andrew at acooke.org Fri Feb 13 09:27:51 2009 From: andrew at acooke.org (andrew cooke) Date: Fri, 13 Feb 2009 11:27:51 -0300 Subject: sgmllib parser keeps old tag data? References: <20090213135803.GB2168@iris.furrow.ath.cx> Message-ID: you are declaring class variables, not instance variables. you need to declare these in an __init__ method. RTFM. http://docs.python.org/tutorial/classes.html#a-first-look-at-classes Berend van Berkum wrote: > class MyParser(sgmllib.SGMLParser): > > content = '' > markup = [] > span_stack = [] From google at mrabarnett.plus.com Fri Feb 13 09:31:40 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 13 Feb 2009 14:31:40 +0000 Subject: sgmllib parser keeps old tag data? In-Reply-To: <20090213135803.GB2168@iris.furrow.ath.cx> References: <20090213135803.GB2168@iris.furrow.ath.cx> Message-ID: <4995844C.7080104@mrabarnett.plus.com> Berend van Berkum wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > > Hi everyone, > > I read the source, made numerous tests, but SGMLParser's keeps returning *tag* data > from previous parser instances. I'm totally confused why.. The content data it > returns is ok. > > E.g.:: > > sp = MyParser() > sp.feed('Test') > print sp.content, sp.markup > sp.close() > > sp = MyParser() > sp.feed('\n\r\n') > print sp.content, sp.markup > sp.close() > > gives:: > > ('Test', [{'t': ({}, (0, 0))}, {'test': ({}, (0, 4))}]) > ('\n\r\n', [{'t': ({}, (0, 0))}, {'test': ({}, (0, 4))}, {'xml': ({}, (0, 1))}]) > > It keeps the tags from the previous session, while i'm sure the stack etc. > should be clean.. > > Any ideas? > > > regards, Berend > > - ---- > > import sgmllib > > > class MyParser(sgmllib.SGMLParser): > > content = '' > markup = [] > span_stack = [] > These are in the _class_ itself, so they will be shared by all its instances. You should so something like this instead: def __init__(self): self.content = '' self.markup = [] self.span_stack = [] > def handle_data(self, data): > self.content += data > > def unknown_starttag(self, tag, attr): > stack = { tag: ( dict(attr), ( len(self.content), ) ) } > self.span_stack.append(stack) > > def unknown_endtag(self, tag): > prev_tag, ( attr, ( offset, ) ) = self.span_stack.pop().items()[0] > > if tag: > # close all tags on stack until it finds a matching end tag > # XXX: need to return to LEVEL, not same tag name > while tag != prev_tag: > span = { prev_tag: ( attr, ( offset, 0 ) ) } > self.markup.append( span ) > > prev_tag, ( attr, ( offset, ) ) = self.span_stack.pop().items()[0] > > length = len( self.content ) - offset > span = { tag: ( attr, ( offset, length ) ) } > self.markup.append( span ) > > def do_unknown_tag(self, tag, attr): > assert not tag and not attr, "do_unknown_tag %s, %s" % (tag, attr) > > def close(self): > sgmllib.SGMLParser.close(self) > self.content = '' > self.markup = [] > self.span_stack = [] > > > def parse_data(data): > sp = MyParser() > sp.feed(data) > r = sp.content, sp.markup > sp.close() > return r > > print parse_data('Test') > print parse_data('\n\r\n') > print parse_data('Test 3') > From python at bdurham.com Fri Feb 13 09:45:08 2009 From: python at bdurham.com (python at bdurham.com) Date: Fri, 13 Feb 2009 09:45:08 -0500 Subject: Invoking CutePDF from within Python In-Reply-To: <499531A5.5010805@timgolden.me.uk> References: <590ed3f4-089a-41d7-aaa2-6d96f5ea1fa9@j39g2000yqn.googlegroups.com> <499531A5.5010805@timgolden.me.uk> Message-ID: <1234536308.14311.1300203191@webmail.messagingengine.com> Tim, > FWIW, I usually generate PDFs by printing to a Postscript printer (some random Apple Laserthingy) and then using Ghostscript to do the conversion. I'm happy to post if you're interested. If its not too much bother, I would be interested in learning how you're interfacing to Python to Ghostscript. Regards, Malcolm From berend at dotmpe.com Fri Feb 13 09:51:01 2009 From: berend at dotmpe.com (Berend van Berkum) Date: Fri, 13 Feb 2009 15:51:01 +0100 Subject: sgmllib parser keeps old tag data? In-Reply-To: <4995844C.7080104@mrabarnett.plus.com> References: <20090213135803.GB2168@iris.furrow.ath.cx> <4995844C.7080104@mrabarnett.plus.com> Message-ID: <20090213145101.GC2168@iris.furrow.ath.cx> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Fri, Feb 13, 2009 at 02:31:40PM +0000, MRAB wrote: > Berend van Berkum wrote: > > > >import sgmllib > > > > > >class MyParser(sgmllib.SGMLParser): > > > > content = '' > > markup = [] > > span_stack = [] > > > These are in the _class_ itself, so they will be shared by all its > instances. You should so something like this instead: > > def __init__(self): > self.content = '' > self.markup = [] > self.span_stack = [] > Yes.. tested that and SGMLParser won't let me override __init__, (SGMLParser vars are uninitialized even with sgmllib.SGMLParser(self) call). Tried some but not the following: with a differently named init function and one boolean class var 'initialized' it can check 'if self.initialized' in front of each handler. Does the trick. Confusion dissolved :) thanks. - -- web, http://dotmpe.com () ASCII Ribbon email, berend.van.berkum at gmail.com /\ icq, 26727647; irc, berend/mpe at irc.oftc.net -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFJlYjVn70fkTNDJRgRAhFRAJ9XDPaR2zb8EjKfTACDjtzwI7z/9ACgzcmB Ms1QZ9IoB2s6RJ+tdXJtzfs= =itBb -----END PGP SIGNATURE----- From mail at timgolden.me.uk Fri Feb 13 09:54:33 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 13 Feb 2009 14:54:33 +0000 Subject: Invoking CutePDF from within Python In-Reply-To: <1234536308.14311.1300203191@webmail.messagingengine.com> References: <590ed3f4-089a-41d7-aaa2-6d96f5ea1fa9@j39g2000yqn.googlegroups.com> <499531A5.5010805@timgolden.me.uk> <1234536308.14311.1300203191@webmail.messagingengine.com> Message-ID: <499589A9.3060404@timgolden.me.uk> python at bdurham.com wrote: > Tim, > >> FWIW, I usually generate PDFs by printing to a Postscript printer (some random Apple Laserthingy) and then using Ghostscript to do the conversion. I'm happy to post if you're interested. > > If its not too much bother, I would be interested in learning how you're > interfacing to Python to Ghostscript. Really boring, I'm afraid. Just popen and an .exe: http://pastebin.com/m461bf8f2 (There are a few dependencies I haven't shown but I hope the approach is obvious; happy to explain / supply details) TJG From python at bdurham.com Fri Feb 13 10:07:51 2009 From: python at bdurham.com (python at bdurham.com) Date: Fri, 13 Feb 2009 10:07:51 -0500 Subject: Invoking CutePDF from within Python In-Reply-To: <499589A9.3060404@timgolden.me.uk> References: <590ed3f4-089a-41d7-aaa2-6d96f5ea1fa9@j39g2000yqn.googlegroups.com> <499531A5.5010805@timgolden.me.uk> <1234536308.14311.1300203191@webmail.messagingengine.com> <499589A9.3060404@timgolden.me.uk> Message-ID: <1234537671.19677.1300207371@webmail.messagingengine.com> Tim, > http://pastebin.com/m461bf8f2 Wonderful! That's enough to get me started. Thank you very much. Cheers, Malcolm From news123 at free.fr Fri Feb 13 10:09:05 2009 From: news123 at free.fr (News123) Date: Fri, 13 Feb 2009 16:09:05 +0100 Subject: best set of modules for web automation without javascript In-Reply-To: References: <49957df1$0$15145$426a74cc@news.free.fr> Message-ID: <49958d11$0$12422$426a74cc@news.free.fr> Hi Joel, Thanks, This (the urllib2 methods you combined with cookielib) is what I am currently trying to do. I would just like to retrieve all the field names and default values of a form. (Some forms are huge) and wondered thus whether there's already a python module parsing a html documents for forms , form fields and field vaules, returning an objcet. that could be modified and posted. bye N Joe Riopel wrote: > On Fri, Feb 13, 2009 at 9:04 AM, News123 wrote: >> Hi, >> I'd like to do some web automation with python 2.5 >> - https: >> - a cookiejar >> - some forms to be filled in >> what is the best set of modules. > > I have automated some testing of our product, using it's web UI with > Python with urllib2 and urrlib. I don't actually fill in the forms, I > just recreate the post and set the values of the post variables (so I > don't get any form validation). > > Check out: > urllib2.build_opener > urllib2.HTTPCookieProcessor > urllib2.Request From marco at sferacarta.com Fri Feb 13 10:12:24 2009 From: marco at sferacarta.com (Marco Mariani) Date: Fri, 13 Feb 2009 16:12:24 +0100 Subject: best set of modules for web automation without javascript In-Reply-To: <49958d11$0$12422$426a74cc@news.free.fr> References: <49957df1$0$15145$426a74cc@news.free.fr> <49958d11$0$12422$426a74cc@news.free.fr> Message-ID: News123 wrote: > I would just like to retrieve all the field names and default values of > a form. (Some forms are huge) and wondered thus whether there's already > a python module parsing a html documents for forms , form fields and > field vaules, returning an objcet. that could be modified and posted. http://wwwsearch.sourceforge.net/ClientForm/ http://wwwsearch.sourceforge.net/mechanize/ From james at agentultra.com Fri Feb 13 10:17:48 2009 From: james at agentultra.com (J Kenneth King) Date: Fri, 13 Feb 2009 07:17:48 -0800 Subject: [ANN] TracShell 0.1 released References: <85ab8rkawn.fsf@agentultra.com> Message-ID: <87k57uv00z.fsf@agentultra.com> J Kenneth King writes: > I tend to work a lot with Trac for project management and have always > found the browser interface to be a productivity killer. I always > wanted a simple command-line interface to Trac, but having never found > one I found a little free time and got off my laurels to make one. > > TracShell 0.1 is an early release, but it works. So far you can only > query and view tickets, but planned updates include the obvious > ability to create and edit tickets. Future plans will allow browsing > of comments, change histories, attachments, and so forth. > > Please consider it really beta. The code needs a little tidying up > around the edges. If you find any bugs, please report them and I'll > fix them ASAP. Ideas, suggestions, and contributions are welcome. > > http://code.google.com/p/tracshell/ > > Cheers. Just added the ability to create tickets, more features forthcoming. I highly recommend anyone using this tool to stick to the latest svn versions. I'll package the feature-complete stables going forward. Cheers. From james at agentultra.com Fri Feb 13 10:21:04 2009 From: james at agentultra.com (J Kenneth King) Date: Fri, 13 Feb 2009 07:21:04 -0800 Subject: is there a project running (GUI Builder for Python ) ? References: Message-ID: <87fxiiuzvj.fsf@agentultra.com> gc_ottawa at yahoo.ca writes: > ......I come from Delphi, and compared to Delphi, even Visual Studio >> vanishes ;-) > ...........I don't even notice the difference between Delphi (which > I'm still using) >> and wxPython. >> >> I think this story happened to other people to, >> so instead of putting a lot of effort in designing and maintaining a GUI >> builders, >> it might be better to choose another solution. >> >> btw, the idea I used, can be seen here]http://mientki.ruhosting.nl/data_www/pylab_works/pw_gui_support.html >> and the code can be found herehttp://code.google.com/p/pylab-works/downloads/list >> >> cheers, >> Stef > > You know, 10 or more years ago both Borland and Microsoft got it right > when they incorporated a GUI with an IDE in their Delphi and Visual > Basic products. As wonderful as the Python language is, it is very > much a work in progress when compared to the ease of use of the > aforementioned products. These products revolutionized the industry > with their "Rapid Applications Development" (RAD). > > Python reminds me of a toolbox filled with a multitude of single use > tools when all you need is a Skilsaw and a combination screwdriver. > Gord ... So use the combination screwdriver. Python isn't all things to all people. It is what it is. From google at mrabarnett.plus.com Fri Feb 13 10:41:52 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 13 Feb 2009 15:41:52 +0000 Subject: sgmllib parser keeps old tag data? In-Reply-To: <20090213145101.GC2168@iris.furrow.ath.cx> References: <20090213135803.GB2168@iris.furrow.ath.cx> <4995844C.7080104@mrabarnett.plus.com> <20090213145101.GC2168@iris.furrow.ath.cx> Message-ID: <499594C0.9020509@mrabarnett.plus.com> Berend van Berkum wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On Fri, Feb 13, 2009 at 02:31:40PM +0000, MRAB wrote: >> Berend van Berkum wrote: >>> import sgmllib >>> >>> >>> class MyParser(sgmllib.SGMLParser): >>> >>> content = '' >>> markup = [] >>> span_stack = [] >>> >> These are in the _class_ itself, so they will be shared by all its >> instances. You should so something like this instead: >> >> def __init__(self): >> self.content = '' >> self.markup = [] >> self.span_stack = [] >> > > Yes.. tested that and SGMLParser won't let me override __init__, > (SGMLParser vars are uninitialized even with sgmllib.SGMLParser(self) call). OK, so SGMLParser needs to be initialised: def __init__(self): sgmllib.SGMLParser.__init__(self) self.content = '' self.markup = [] self.span_stack = [] > Tried some but not the following: > with a differently named init function and one boolean class var 'initialized' > it can check 'if self.initialized' in front of each handler. Does the trick. > > Confusion dissolved :) > thanks. > From synnovefredericks at gmail.com Fri Feb 13 10:52:57 2009 From: synnovefredericks at gmail.com (synarcane) Date: Fri, 13 Feb 2009 07:52:57 -0800 (PST) Subject: Developer needed for Open Source Django/Pinax on-line community Message-ID: The Hub is a global community of innovators from every profession, background and culture working at 'new frontiers' to tackle the world's most pressing social, cultural and environmental challenges. The Hub has over 1000 members hotdesking in stunning spaces around the world. The Hub aims to give its members the tools and resources they need to take their ideas from inception to scale. To this end we are building an Open Source online platform to enable Hub members to collaborate virtually. We have identified Pinax as the platform for building this over the next few months. The Hub+ team is the team which provides technology to Hubs globally. We are looking for an experienced and enthusiastic Python programmer to work on a Django/Pinax project in a team committed to Open Source software and open innovation. If you are interested in inspiring initiatives and enjoy working in an innovative environment we'd like you to join our small team to help build the Hub's ambitious technical infrastructure. There will be plenty of opportunities to get involved in other cutting edge technical projects with The Hub including real-time comet based services, network visualisation, collaborative real-time mind- mapping, guided navigation, VOIP triggering, and video messaging. Required - Experienced Python developer - Knowledge of Django development - Javascript - Basic HTML/CSS - Based in London (or willing to move) Preferred* - Experience in Pinax - JQuery / YUI - Active in Open Source communities - Interest in open innovation - Twisted - Comet / Orbited Please send an e-mail by 23rd February 2009, to synnove.fredericks at the- hub.net, with some samples of your work, your CV and tell us why you are interested in joining us. From andrew at acooke.org Fri Feb 13 10:54:45 2009 From: andrew at acooke.org (andrew cooke) Date: Fri, 13 Feb 2009 12:54:45 -0300 Subject: sgmllib parser keeps old tag data? References: <20090213135803.GB2168@iris.furrow.ath.cx> Message-ID: Sorry, this reply was delayed (trying to use usenet...) and so now seems (even more) bad tempered than needed. Andrew andrew cooke wrote: > you are declaring class variables, not instance variables. you need to > declare these in an __init__ method. RTFM. > http://docs.python.org/tutorial/classes.html#a-first-look-at-classes > > Berend van Berkum wrote: >> class MyParser(sgmllib.SGMLParser): >> >> content = '' >> markup = [] >> span_stack = [] > > > -- > http://mail.python.org/mailman/listinfo/python-list From zpeteljac at gmaljo.com Fri Feb 13 11:06:55 2009 From: zpeteljac at gmaljo.com (Kurioz) Date: Fri, 13 Feb 2009 17:06:55 +0100 Subject: Python knapsack problem Message-ID: Hi, I got the assignment to solve the knapsack problem in Python. I have to find the solution to put items in a sack (I have only one item A, B and C) which maxWeight can't be larger than 6 kilograms. Solution of this problem should be A and C but the only solution I'm getting is B and C which aren't true because weight of the B and C is 7 kilograms which is heavier than the maxWeight. If anyone could point me what am I doing wrong I'd be very grateful! Thanks in advance! Code: #1st array element is weight of an item, and 2nd array element is value A=[2.0,1.0] B=[3.0,7.0] C=[4.0,8.0] #Checking the values per one kilo vA=A[1]/A[0] vB=B[1]/B[0] vC=C[1]/C[0] maxWeight=0 print vA,vB,vC #Checking the values while maxWeight<6: if int(vA)>int(vB) and int(vA)>int(vC): maxWeight=maxWeight+A[0] vA=0 print maxWeight elif int(vB)>int(vA) and int(vB)>int(vC): maxWeight=maxWeight+B[0] print maxWeight else: vC=0 maxWeight=maxWeight+C[0] print maxWeight From nick at craig-wood.com Fri Feb 13 11:31:56 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Fri, 13 Feb 2009 10:31:56 -0600 Subject: Escaping my own chroot... References: Message-ID: Jean-Paul Calderone wrote: > On Wed, 11 Feb 2009 09:31:56 -0600, Nick Craig-Wood wrote: > >r0g wrote: > >> I'm writing a linux remastering script in python where I need to chroot > >> into a folder, run some system commands and then come out and do some > >> tidying up, un-mounting proc & sys etc. > >> > >> I got in there with os.chroot() and I tried using that to get back out > >> but that didn't work so... is my script trapped in there forever now or > >> is there an un-hacky way to escape? > > > >No! > > If you still have root in the chroot (and you need root to get in there, so > it's not implausible that you will), then you can get out. Googling for > "escape chroot" turns up lots of hits. This page contains a fairly simple, > explicit description of how to get out of a chroot: > > http://www.bpfh.net/simes/computing/chroot-break.html > > See the bulleted list in the "Breaking chroot()" section. Since you also > control the process before the chroot happens, breaking out is even simpler > in your case (just open / before you chroot in the first place). forking > before doing the chroot may still be a good idea, but it's not the only > solution. I admit it can be done, but I'm not sure it isn't hacky! #!/usr/bin/python """ Enter a chroot and escape again Run as root """ import os import sys def ls(path): """List the path""" print "Directory listing of %r" % path for f in os.listdir(path): print ">>", f def main(): if len(sys.argv) < 2: print >>sys.stderr, "Need directory to chroot to as an argument" raise SystemExit(1) chroot_dir = sys.argv[1] print "Opening root" root = os.open("/", os.O_RDONLY) print "Before chroot" ls("/") print "Chrooting to %r" % chroot_dir os.chroot(chroot_dir) ls("/") print "Breaking the chroot" os.fchdir(root) for i in range(100): os.chdir("..") os.chroot(".") ls("/") os.close(root) if __name__ == "__main__": main() I ran this $ mkdir chroot_test $ touch chroot_test/in_the_chroot $ sudo ./chroot_test.py chroot_test And it produced this Opening root Before chroot Directory listing of '/' >> lost+found >> home >> bin >> boot >> proc >> dev >> etc [snip] Chrooting to 'chroot_test' Directory listing of '/' >> in_the_chroot Breaking the chroot Directory listing of '/' >> lost+found >> home >> bin >> boot >> proc >> dev >> etc [snip] -- Nick Craig-Wood -- http://www.craig-wood.com/nick From david at abbottdavid.com Fri Feb 13 12:03:42 2009 From: david at abbottdavid.com (David) Date: Fri, 13 Feb 2009 12:03:42 -0500 Subject: *nix tail -f multiple log files with Thread Message-ID: <4995A7EE.2000302@abbottdavid.com> Hi everyone, I copied a program from C to track multiple log files. I would like to be able to print a label when a log file is updated. Here is the program; #!/usr/bin/python from threading import Thread import subprocess from Queue import Queue num_threads = 3 queue = Queue() logfiles = ["/var/log/messages", "/var/log/apache2/access_log", "/var/log/apache2/error_log"] def logtailer(i, q,): while True: lfile = q.get() sudo = "sudo" tail = "tail" arg = "-f" ret = subprocess.call([sudo, tail, arg, lfile]) q.task_done() for i in range(num_threads): worker = Thread(target=logtailer, args=(i, queue)) worker.setDaemon(True) worker.start() for lfile in logfiles: queue.put(lfile) queue.join() And here is a sample of the output; [Fri Feb 13 08:58:48 2009] [error] [client 127.0.0.1] File does not exist: /var/www/localhost/htdocs/moodle/favicon.ico [Fri Feb 13 08:58:51 2009] [error] [client 127.0.0.1] File does not exist: /var/www/localhost/htdocs/moodle/favicon.ico Feb 13 09:02:26 opteron sudo: david : TTY=pts/4 ; PWD=/home/david ; USER=root ; COMMAND=/bin/tail -f /var/log/apache2/error_log Feb 13 09:02:26 opteron sudo: pam_unix(sudo:session): session opened for user root by david(uid=0) Feb 13 09:02:26 opteron sudo: pam_unix(sudo:session): session closed for user root Feb 13 09:10:01 opteron cron[10633]: (root) CMD (test -x /usr/sbin/run-crons && /usr/sbin/run-crons ) Feb 13 09:18:33 opteron su[10678]: Successful su for root by david Feb 13 09:18:33 opteron su[10678]: + pts/6 david:root Feb 13 09:18:33 opteron su[10678]: pam_unix(su:session): session opened for user root by david(uid=1000) 127.0.0.1 - - [13/Feb/2009:09:18:47 -0500] "GET /theme/custom_corners/favicon.ico HTTP/1.1" 200 894 127.0.0.1 - - [13/Feb/2009:09:18:47 -0500] "GET /lib/speller/spellChecker.js HTTP/1.1" 200 15980 127.0.0.1 - - [13/Feb/2009:09:18:47 -0500] "GET / HTTP/1.1" 200 13718 127.0.0.1 - - [13/Feb/2009:09:18:47 -0500] "GET /theme/custom_corners/styles.php HTTP/1.1" 200 30709 I would like to be able to add a label like; [Fri Feb 13 08:58:48 2009] [error] [client 127.0.0.1] File does not exist: /var/www/localhost/htdocs/moodle/favicon.ico [Fri Feb 13 08:58:51 2009] [error] [client 127.0.0.1] File does not exist: /var/www/localhost/htdocs/moodle/favicon.ico Feb 13 09:02:26 opteron sudo: david : TTY=pts/4 ; PWD=/home/david ; USER=root ; COMMAND=/bin/tail -f /var/log/apache2/error_log Feb 13 09:02:26 opteron sudo: pam_unix(sudo:session): session opened for user root by david(uid=0) Feb 13 09:02:26 opteron sudo: pam_unix(sudo:session): session closed for user root Feb 13 09:10:01 opteron cron[10633]: (root) CMD (test -x /usr/sbin/run-crons && /usr/sbin/run-crons ) Feb 13 09:18:33 opteron su[10678]: Successful su for root by david Feb 13 09:18:33 opteron su[10678]: + pts/6 david:root Feb 13 09:18:33 opteron su[10678]: pam_unix(su:session): session opened for user root by david(uid=1000) 127.0.0.1 - - [13/Feb/2009:09:18:47 -0500] "GET /theme/custom_corners/favicon.ico HTTP/1.1" 200 894 127.0.0.1 - - [13/Feb/2009:09:18:47 -0500] "GET /lib/speller/spellChecker.js HTTP/1.1" 200 15980 127.0.0.1 - - [13/Feb/2009:09:18:47 -0500] "GET / HTTP/1.1" 200 13718 127.0.0.1 - - [13/Feb/2009:09:18:47 -0500] "GET /theme/custom_corners/styles.php HTTP/1.1" 200 30709 I can create the label like this; def label() print "<%s\n>" % lfile But I have no idea how to get it to work when a thread is updated. thanks -david -- Powered by Gentoo GNU/LINUX http://www.linuxcrazy.com pgp.mit.edu From http Fri Feb 13 12:25:10 2009 From: http (Paul Rubin) Date: 13 Feb 2009 09:25:10 -0800 Subject: best set of modules for web automation without javascript References: <49957df1$0$15145$426a74cc@news.free.fr> <49958d11$0$12422$426a74cc@news.free.fr> Message-ID: <7xr622z1u1.fsf@ruckus.brouhaha.com> News123 writes: > I would just like to retrieve all the field names and default values of > a form. (Some forms are huge) and wondered thus whether there's already > a python module parsing a html documents for forms , form fields and > field vaules, returning an objcet. that could be modified and posted. BeautifulSoup may be of some help. From news123 at free.fr Fri Feb 13 12:41:00 2009 From: news123 at free.fr (News123) Date: Fri, 13 Feb 2009 18:41:00 +0100 Subject: best set of modules for web automation without javascript In-Reply-To: <49958d11$0$12422$426a74cc@news.free.fr> References: <49957df1$0$15145$426a74cc@news.free.fr> <49958d11$0$12422$426a74cc@news.free.fr> Message-ID: <4995b0ad$0$2695$426a74cc@news.free.fr> Hi Marco / Paul, Thanks I'll look into mechanize,ClientForm and BeautifulSoup. All three are now installed. I'll just have to play with them. bye N News123 wrote: > Hi Joel, > > Thanks, > This (the urllib2 methods you combined with cookielib) is what I am > currently trying to do. > > I would just like to retrieve all the field names and default values of > a form. (Some forms are huge) and wondered thus whether there's already > a python module parsing a html documents for forms , form fields and > field vaules, returning an objcet. that could be modified and posted. > > > bye > > N > > > > Joe Riopel wrote: >> On Fri, Feb 13, 2009 at 9:04 AM, News123 wrote: >>> Hi, >>> I'd like to do some web automation with python 2.5 >>> - https: >>> - a cookiejar >>> - some forms to be filled in >>> what is the best set of modules. >> I have automated some testing of our product, using it's web UI with >> Python with urllib2 and urrlib. I don't actually fill in the forms, I >> just recreate the post and set the values of the post variables (so I >> don't get any form validation). >> >> Check out: >> urllib2.build_opener >> urllib2.HTTPCookieProcessor >> urllib2.Request From tripplowe at gmail.com Fri Feb 13 12:59:22 2009 From: tripplowe at gmail.com (tripp) Date: Fri, 13 Feb 2009 09:59:22 -0800 (PST) Subject: Fortran array in python (f2py?)... Message-ID: <42cda6f6-eaa2-44d9-be39-443fcc460806@o36g2000yqh.googlegroups.com> Hello Folks, I have a fortran program I use to process several satellite images. I currently output the results to a text file (~750 mb) which is then read by a perl program that outputs a GIS-ready image using GDAL (www.gdal.org). There are python libraries for GDAL too. I'd like to pipe the array directly to python from fortran (instead of writing it out to a text file). Is it possible to access an in-memory fortran array with python? I've looked at f2py, but I could not tell if this was possible. Thanks. -TLowe From matiassurdi at gmail.com Fri Feb 13 13:01:04 2009 From: matiassurdi at gmail.com (Matias Surdi) Date: Fri, 13 Feb 2009 19:01:04 +0100 Subject: best set of modules for web automation without javascript In-Reply-To: <49957df1$0$15145$426a74cc@news.free.fr> References: <49957df1$0$15145$426a74cc@news.free.fr> Message-ID: You should give a look to Selenium. It's great. http://www.openqa.org News123 wrote: > Hi, > > > I'd like to do some web automation with python 2.5 > - https: > - a cookiejar > - some forms to be filled in > > > what is the best set of modules. > > As far as I understood, there is httplib, but it seems (if I understood > well) to be incoompatible with cookielib > > I'm a newcomer to webautomation with python and would be thankful for > good suggestions. > > > I used so far perl with LWP::UserAgent HTTP::Cookies and some module (I > forgot the name) to handle parsing and filling in Forms. > > thanks in advance for any pointers opinions > > > N > -- > http://mail.python.org/mailman/listinfo/python-list > From tjreedy at udel.edu Fri Feb 13 13:05:10 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 13 Feb 2009 13:05:10 -0500 Subject: something wrong with isinstance In-Reply-To: References: <2a84f320-8be2-4482-9513-4d7edf3295ac@j8g2000yql.googlegroups.com> <8677703b-4284-4283-83a7-ac095eb5af4f@33g2000yqm.googlegroups.com> Message-ID: Gabriel Genellina wrote: > En Fri, 13 Feb 2009 08:43:03 -0200, Peter Otten <__peter__ at web.de> > escribi?: >>>>> class Type(type): >> ... def __instancecheck__(self, other): return True >> ... >>>>> class A(metaclass=Type): pass >> ... >>>>> class B: pass >> ... >>>>> isinstance(B(), A) >> True >> >> See also >> >> http://www.python.org/dev/peps/pep-3119/#overloading-isinstance-and-issubclass >> > > Ah, ok. Isn't menctioned in the main documentation though. Lack reported in http://bugs.python.org/issue5250 From mccredie at gmail.com Fri Feb 13 13:16:40 2009 From: mccredie at gmail.com (Matimus) Date: Fri, 13 Feb 2009 10:16:40 -0800 (PST) Subject: Python knapsack problem References: Message-ID: <1d7e1bcd-58f6-4788-9e42-9f6ed04369c1@b38g2000prf.googlegroups.com> On Feb 13, 8:06?am, "Kurioz" wrote: > Hi, > > I got the assignment to solve the knapsack problem in Python. I have to find > the solution to put items in a sack (I have only one item A, B and C) which > maxWeight can't be larger than 6 kilograms. ?Solution of this problem should > be A and C but the only solution I'm getting is B and C which aren't true > because weight of the B and C is 7 kilograms which is heavier than the > maxWeight. > > If anyone could point me what am I doing wrong I'd be very grateful! Thanks > in advance! > > Code: > > #1st array element is weight of an item, and 2nd array element is value > A=[2.0,1.0] > B=[3.0,7.0] > C=[4.0,8.0] > #Checking the values per one kilo > vA=A[1]/A[0] > vB=B[1]/B[0] > vC=C[1]/C[0] > maxWeight=0 > print vA,vB,vC > #Checking the values > while maxWeight<6: > ? ? if int(vA)>int(vB) and int(vA)>int(vC): > ? ? ? ? maxWeight=maxWeight+A[0] > ? ? ? ? vA=0 > ? ? ? ? print maxWeight > > ? ? elif int(vB)>int(vA) and int(vB)>int(vC): > ? ? ? ? maxWeight=maxWeight+B[0] > ? ? ? ? print maxWeight > > ? ? else: > ? ? ? ? vC=0 > ? ? ? ? maxWeight=maxWeight+C[0] > ? ? ? ? print maxWeight You will need to check whether each item can fit before adding it. Currently you are doing: while there is room in the sac: add the next most valuable item You should be doing: while there is room in the sac: if the next most valuable item fits add it But... once you fix that you will run into another issue. You are using ints to compare. Casting floating point values to ints will always round down. vA = 0.5 vB = 2.3333... vC = 2.0 But.. >>> int(vA) 0 >>> int(vB) 2 >>> int(vC) 2 Matt From tjreedy at udel.edu Fri Feb 13 13:22:45 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 13 Feb 2009 13:22:45 -0500 Subject: Levenshtein word comparison -performance issue In-Reply-To: References: Message-ID: Gabriel Genellina wrote: > En Fri, 13 Feb 2009 08:16:00 -0200, S.Selvam Siva > escribi?: > >> I need some help. >> I tried to find top n(eg. 5) similar words for a given word, from a >> dictionary of 50,000 words. >> I used python-levenshtein module,and sample code is as follow. >> >> def foo(searchword): >> disdict={} >> for word in self.dictionary-words: >> distance=Levenshtein.ratio(searchword,word) >> disdict[word]=distance >> """ >> sort the disdict dictionary by values in descending order >> """ >> similarwords=sorted(disdict, key=disdict.__getitem__, reverse=True) >> >> return similarwords[:5] > > You may replace the last steps (sort + slice top 5) by heapq.nlargest - > at least you won't waste time sorting 49995 irrelevant words... There is also no need to build the 50000 entry word-distance dictionary. import heapq, functools def foo(searchword, n): distance = functools.partial(Levenshtein.ratio, searchword) return heapq.nlargest(n, words, distance) If the distances are wanted along with the similar words, I strongly suspect that it would be faster to recalculate a small number than to generate the dict of 50000 pairs. > Anyway you should measure the time taken by the first part > (Levenshtein), it may be the most demanding. I think there is a C > extension for this, should be much faster than pure Python calculations. And such could be dropped into the code above. Terry Jan Reedy From google at mrabarnett.plus.com Fri Feb 13 13:27:00 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 13 Feb 2009 18:27:00 +0000 Subject: Fortran array in python (f2py?)... In-Reply-To: <42cda6f6-eaa2-44d9-be39-443fcc460806@o36g2000yqh.googlegroups.com> References: <42cda6f6-eaa2-44d9-be39-443fcc460806@o36g2000yqh.googlegroups.com> Message-ID: <4995BB74.7000200@mrabarnett.plus.com> tripp wrote: > Hello Folks, > > I have a fortran program I use to process several satellite images. I > currently output the results to a text file (~750 mb) which is then > read by a perl program that outputs a GIS-ready image using GDAL > (www.gdal.org). There are python libraries for GDAL too. > > I'd like to pipe the array directly to python from fortran (instead of > writing it out to a text file). Is it possible to access an in-memory > fortran array with python? > > I've looked at f2py, but I could not tell if this was possible. > How about outputting the results to the Python program via a pipe? From tjreedy at udel.edu Fri Feb 13 13:34:03 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 13 Feb 2009 13:34:03 -0500 Subject: Python knapsack problem In-Reply-To: References: Message-ID: Kurioz wrote: > I got the assignment to solve the knapsack problem in Python. I have to > find the solution to put items in a sack (I have only one item A, B and > C) which maxWeight can't be larger than 6 kilograms. Solution of this > problem should be A and C but the only solution I'm getting is B and C > which aren't true because weight of the B and C is 7 kilograms which is > heavier than the maxWeight. > > If anyone could point me what am I doing wrong I'd be very grateful! > Thanks in advance! There are several comments I could make, but your immediate problem is this: before putting something in the knapsack, you must check whether it will exceed the limit. Since this is a class assignment, I will stop there. > > Code: > > #1st array element is weight of an item, and 2nd array element is value > A=[2.0,1.0] > B=[3.0,7.0] > C=[4.0,8.0] > #Checking the values per one kilo > vA=A[1]/A[0] > vB=B[1]/B[0] > vC=C[1]/C[0] > maxWeight=0 > print vA,vB,vC > #Checking the values > while maxWeight<6: > if int(vA)>int(vB) and int(vA)>int(vC): > maxWeight=maxWeight+A[0] > vA=0 > print maxWeight > > elif int(vB)>int(vA) and int(vB)>int(vC): > maxWeight=maxWeight+B[0] > print maxWeight > > else: > vC=0 > maxWeight=maxWeight+C[0] > print maxWeight > -- > http://mail.python.org/mailman/listinfo/python-list > From lists at cheimes.de Fri Feb 13 13:50:06 2009 From: lists at cheimes.de (Christian Heimes) Date: Fri, 13 Feb 2009 19:50:06 +0100 Subject: *nix tail -f multiple log files with Thread In-Reply-To: <4995A7EE.2000302@abbottdavid.com> References: <4995A7EE.2000302@abbottdavid.com> Message-ID: David schrieb: > Hi everyone, > > I copied a program from C to track multiple log files. I would like to > be able to print a label when a log file is updated. Here is the program; Don't use threads for the job. On Unix the preferred way is select()'ing or poll()'ing multiple file descriptors. Christian From goon12 at gmail.com Fri Feb 13 13:59:58 2009 From: goon12 at gmail.com (Joe Riopel) Date: Fri, 13 Feb 2009 13:59:58 -0500 Subject: *nix tail -f multiple log files with Thread In-Reply-To: <4995A7EE.2000302@abbottdavid.com> References: <4995A7EE.2000302@abbottdavid.com> Message-ID: <6a2ccd190902131059t3502fdfep90a796c65546b302@mail.gmail.com> On Fri, Feb 13, 2009 at 12:03 PM, David wrote: > Hi everyone, > > I copied a program from C to track multiple log files. I would like to be > able to print a label when a log file is updated. Here is the program; Since you're calling tail itself, why not just use tail's ability to tail multiple files? It too will output the label. I am using tail from the GNU coreutils, version 5.97. I did the following, using two xterms: First, in one xterm window: $ touch foo bar $ tail -f foo bar Then in another xterm: $ echo "Hi foo" > foo $ echo "Hi bar" > bar Back in the first xterm window I see this: $ tail -f foo bar ==> foo <== ==> bar <== ==> foo <== Hi foo ==> bar <== Hi bar From david at abbottdavid.com Fri Feb 13 14:18:11 2009 From: david at abbottdavid.com (David) Date: Fri, 13 Feb 2009 14:18:11 -0500 Subject: *nix tail -f multiple log files with Thread In-Reply-To: <6a2ccd190902131059t3502fdfep90a796c65546b302@mail.gmail.com> References: <4995A7EE.2000302@abbottdavid.com> <6a2ccd190902131059t3502fdfep90a796c65546b302@mail.gmail.com> Message-ID: <4995C773.9000000@abbottdavid.com> Joe Riopel wrote: > On Fri, Feb 13, 2009 at 12:03 PM, David wrote: >> Hi everyone, >> >> I copied a program from C to track multiple log files. I would like to be >> able to print a label when a log file is updated. Here is the program; > > Since you're calling tail itself, why not just use tail's ability to > tail multiple files? It too will output the label. > > I am using tail from the GNU coreutils, version 5.97. > > I did the following, using two xterms: > > First, in one xterm window: > $ touch foo bar > $ tail -f foo bar > > Then in another xterm: > $ echo "Hi foo" > foo > $ echo "Hi bar" > bar > > Back in the first xterm window I see this: > $ tail -f foo bar > ==> foo <== > > ==> bar <== > > ==> foo <== > Hi foo > > ==> bar <== > Hi bar > > Thanks Joe, sure am glad I asked. Oh well it was good practice as I am just learning python, I don't know how I missed that I could tail more than one file. -- Powered by Gentoo GNU/LINUX http://www.linuxcrazy.com pgp.mit.edu From mmaddox at umd.edu Fri Feb 13 14:28:09 2009 From: mmaddox at umd.edu (mike) Date: Fri, 13 Feb 2009 11:28:09 -0800 (PST) Subject: problems opening files Message-ID: <016a4163-1aaf-493d-9145-c1a1f5cb5cf3@g38g2000yqd.googlegroups.com> I have aprogram that manipulates several text files, does some math and saves new files then exits. The program worked fine on the original set of data, but with new data does not open the files as needed. When I copy and paste the 'open line' from the module to IDLE the file opens. section of code that is not working and import statements below: import statements------------ # combine point source data from numpy import * from string import * import point_input section of code----------------- pathincbp=path+'/sub'+sub+'/cbp_'+npdes+'.txt' flag='false' while flag=='false': try: cbpin=open(pathincbp,'r') flag='true' stopping the module manually------------------------------ Traceback (most recent call last): File "C:\Python25\point_sources\combine_point_sources_swat.py", line 155, in print pathincbp+' not found' KeyboardInterrupt IDLE commands--------------------------- >>> cbpin=open(pathincbp,'r') >>> cbpin I am running in windows xp professional 2002 service pack 3 on a Xeon dell Thanks, Mike From tripplowe at gmail.com Fri Feb 13 14:35:07 2009 From: tripplowe at gmail.com (tripp) Date: Fri, 13 Feb 2009 11:35:07 -0800 (PST) Subject: Fortran array in python (f2py?)... References: <42cda6f6-eaa2-44d9-be39-443fcc460806@o36g2000yqh.googlegroups.com> Message-ID: On Feb 13, 1:27?pm, MRAB wrote: > tripp wrote: > > Hello Folks, > > > I have a fortran program I use to process several satellite images. ?I > > currently output the results to a text file (~750 mb) which is then > > read by a perl program that outputs a GIS-ready image using GDAL > > (www.gdal.org). ? There are python libraries for GDAL too. > > > I'd like to pipe the array directly to python from fortran (instead of > > writing it out to a text file). ?Is it possible to access an in-memory > > fortran array with python? > > > I've looked at f2py, but I could not tell if this was possible. > > How about outputting the results to the Python program via a pipe? The array I'd like to output is 8500 x 7500. Would that be possible? I'm NOT RAM limited. From google at mrabarnett.plus.com Fri Feb 13 14:40:51 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 13 Feb 2009 19:40:51 +0000 Subject: problems opening files In-Reply-To: <016a4163-1aaf-493d-9145-c1a1f5cb5cf3@g38g2000yqd.googlegroups.com> References: <016a4163-1aaf-493d-9145-c1a1f5cb5cf3@g38g2000yqd.googlegroups.com> Message-ID: <4995CCC3.7020403@mrabarnett.plus.com> mike wrote: > I have aprogram that manipulates several text files, does some math > and saves new files then exits. > > The program worked fine on the original set of data, but with new data > does not open the files as needed. When I copy and paste the 'open > line' from the module to IDLE the file opens. > > section of code that is not working and import statements below: > > import statements------------ > > # combine point source data > > from numpy import * > from string import * > import point_input > > section of code----------------- > > pathincbp=path+'/sub'+sub+'/cbp_'+npdes+'.txt' > flag='false' > while flag=='false': > try: > cbpin=open(pathincbp,'r') > flag='true' > > stopping the module manually------------------------------ > > Traceback (most recent call last): > File "C:\Python25\point_sources\combine_point_sources_swat.py", line > 155, in > print pathincbp+' not found' > KeyboardInterrupt > > IDLE commands--------------------------- > >>>> cbpin=open(pathincbp,'r') >>>> cbpin > at 0x01450380> > > I am running in windows xp professional 2002 service pack 3 on a Xeon > dell > What exception is the open() raising? From the partial code you've provided I can't tell whether the 'try' is catching any exception. The traceback just tells me that you interrupted the script, not what "is not working" actually means. From Scott.Daniels at Acm.Org Fri Feb 13 15:09:41 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 13 Feb 2009 12:09:41 -0800 Subject: Untangling pythonWin and IDLE Processes on XP Pro In-Reply-To: <1Bcll.10420$hc1.4903@flpi150.ffdc.sbc.com> References: <%OUkl.6905$jZ1.2422@flpi144.ffdc.sbc.com> <6viopfFkcasmU1@mid.uni-berlin.de> <2NWkl.16040$YU2.9824@nlpi066.nbdc.sbc.com> <4ec6562a-08b2-4ec4-b9c0-e720e4ce7339@g38g2000yqd.googlegroups.com> <5-KdnfUPXNqQSgnUnZ2dnUVZ_sudnZ2d@earthlink.com> <1Bcll.10420$hc1.4903@flpi150.ffdc.sbc.com> Message-ID: <-5OdnU6H_-GbTgjUnZ2dnUVZ_h6dnZ2d@pdx.net> W. eWatson wrote: > Terry Reedy wrote: >> W. eWatson wrote: >>> From Diez above. >>> What does *NOT* work is writing a Tkinter-based app in idle, and to >>> run it >>> *FROM INSIDE* idle. Instead, open your explorer and double-click on the >>> pyhton-file your app is in. That's all that there is to it. >>> >>> So this is the absolute truth? No wiggle room? One can never use a >>> Tkinter program with IDLE, and execute it successfully. So IDLE >>> doesn't issue a standard warning that says, "Get out of here with >>> your Tkinter program, it will fail when you try to run it here. You >>> have entered Tkinter hell. Good-bye." >> >> Re-read my post about kids fighting to control a television. Maybe >> they work together, maybe they crash the TV. Hard to predict. >> >> ***ANY*** Python program that tries to grab and control the same >> resources that TK does may conflict with it. There is no way that >> IDLE can have a list of, for instance, all event-grabbing mainloop >> programs. >> > OK, enough tinkering with the code and others matters on my end trying > to find a work around. Somehow after much successful use of IDLE's > execution facility, I've stepped on an invisible banana peel. I think > it's evident that I'm not going around this problem easily with the IDLE > execution attempts, and that another solution is required. That's correct, but you still don't understand _why_ it is correct. I suggest you re-read the thread and try to understand everything you are being told. > First, I think somewhere up the thread someone suggested that Active > pythonWin is not dependent upon Tk, correct? Therefore, it is immune > from such problems, correct? Wrong. I was the one who said that ActiveState had a product to debug Python programs across a nertwork connection. The product is _not_ ActivePython (the freely distributed system), but rather the Komodo IDE, which does cost money. > Finally, we can probably agree that I can continue to use IDLE for > editing and syntax checking, but to "guarantee" successful execution of > the program, I can just double-click on the py file in my folder. > Perhaps there is a better way than clicking on it in the folder. For > example, putting it on the desktop. As I look at the folder, previous > copies only differ by a digit, I can easily find myself executing an > earlier version, differing as Dev4, to Dev5 at the end of each name. OK, you are using the oldest and least useful revision control system, "rename and remember." I'd suggest you get and use bazaar, but you'll just ask for shortcuts on how to use it without understanding what it does. --Scott David Daniels Scott.Daniels at Acm.Org From bryanvick at gmail.com Fri Feb 13 15:42:41 2009 From: bryanvick at gmail.com (Bryan) Date: Fri, 13 Feb 2009 12:42:41 -0800 (PST) Subject: Upgrading standard library module Message-ID: I have a Python v2.5.2 server running and I found some undesirable behavior in the xmlrpclib module that is included with that version of Python. The xmlrpclib version that is included with Python 2.6 changes the behavior for the better. I nervous about upgrading my Python install to 2.6 on this server because I remember reading in the docs of a library I use that it targets the 2.5 branch. What is the best way to only upgrade the xmlrpclib in my 2.5 install? Also, have you all had problems with libraries not specifying which Python version they target? I can't find a requirements for the formencode library. It is kind of scary upgrading my Python server install without being sure all my libraries will work. Experiences?? Bryan From castironpi at gmail.com Fri Feb 13 15:45:49 2009 From: castironpi at gmail.com (Aaron Brady) Date: Fri, 13 Feb 2009 12:45:49 -0800 (PST) Subject: pdb in 3.0 very buggy (Win XP Home) Message-ID: <8a640af7-41e9-4de6-8b18-fa18c3448b64@v5g2000pre.googlegroups.com> Hi, got a freeze when running 'pdb' in 3.0. The program executes correctly with the command 'c', but freezes part way through when running successive 'n' commands. Platform Windows XP Home. Python 3.0 (r30:67507, Dec 3 2008, 20:14:27) [MSC v.1500 32 bit (Intel)] on win32. The 'list' command was also not working properly, printing '[EOF]' many places, even when prompted with arguments for 'first' and 'last'. /Screen dump: C:\Documents and Settings\usr\Desktop\working>\programs \python30\python -m pdb picktest.py --Return-- > (5)A()->None (Pdb) c 0 1 2 The program finished and will be restarted --Return-- > (5)A()->None (Pdb) n --Return-- > c:\programs\python30\lib\io.py(757)closed()->False -> return self.raw.closed (Pdb) n --Return-- > c:\programs\python30\lib\io.py(1467)closed()->False -> return self.buffer.closed (Pdb) n --Return-- > c:\programs\python30\lib\encodings\cp437.py(19)encode()->b'0' -> return codecs.charmap_encode(input,self.errors,encoding_map)[0] (Pdb) n --Return-- > c:\programs\python30\lib\io.py(757)closed()->False -> return self.raw.closed (Pdb) n 0--Return-- > c:\programs\python30\lib\io.py(1060)write()->1 -> return written (Pdb) n --Return-- > c:\programs\python30\lib\io.py(1498)write()->1 -> return length (Pdb) n --Return-- > c:\programs\python30\lib\io.py(757)closed()->False -> return self.raw.closed (Pdb) n --Return-- > c:\programs\python30\lib\io.py(1467)closed()->False -> return self.buffer.closed (Pdb) n --Return-- > c:\programs\python30\lib\encodings\cp437.py(19)encode()->b'\n' -> return codecs.charmap_encode(input,self.errors,encoding_map)[0] (Pdb) n --Return-- > c:\programs\python30\lib\io.py(757)closed()->False -> return self.raw.closed (Pdb) n --Return-- > c:\programs\python30\lib\io.py(1060)write()->1 -> return written (Pdb) n /Program: class A: def f( self ): self.x= 0 print( self.x ) def g( self ): self.x+= 1 print( self.x ) a= A() a.f() a.g() a.g() From kyosohma at gmail.com Fri Feb 13 15:46:37 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Fri, 13 Feb 2009 12:46:37 -0800 (PST) Subject: Upgrading standard library module References: Message-ID: <9943880a-2d4f-4532-96f5-83ebe4b32e6b@c12g2000yqj.googlegroups.com> On Feb 13, 2:42?pm, Bryan wrote: > I have a Python v2.5.2 server running and I found some undesirable > behavior in the xmlrpclib module that is included with that version of > Python. ?The xmlrpclib version that is included with Python 2.6 > changes the behavior for the better. ?I nervous about upgrading my > Python install to 2.6 on this server because I remember reading in the > docs of a library I use that it targets the 2.5 branch. ?What is the > best way to only upgrade the xmlrpclib in my 2.5 install? > > Also, have you all had problems with libraries not specifying which > Python version they target? ?I can't find a requirements for the > formencode library. ?It is kind of scary upgrading my Python server > install without being sure all my libraries will work. ?Experiences?? > > Bryan Well, you could put your current install in a virtualenv and then try the new version of Python 2.6 in another virtualenv. See http://pypi.python.org/pypi/virtualenv for more info. As long as your 3rd party packages are pure python, you should be ok. If they depend on c/c++ headers, then you may have issues. Mike From robert.kern at gmail.com Fri Feb 13 16:41:04 2009 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 13 Feb 2009 15:41:04 -0600 Subject: Fortran array in python (f2py?)... In-Reply-To: <42cda6f6-eaa2-44d9-be39-443fcc460806@o36g2000yqh.googlegroups.com> References: <42cda6f6-eaa2-44d9-be39-443fcc460806@o36g2000yqh.googlegroups.com> Message-ID: On 2009-02-13 11:59, tripp wrote: > Hello Folks, > > I have a fortran program I use to process several satellite images. I > currently output the results to a text file (~750 mb) which is then > read by a perl program that outputs a GIS-ready image using GDAL > (www.gdal.org). There are python libraries for GDAL too. > > I'd like to pipe the array directly to python from fortran (instead of > writing it out to a text file). Is it possible to access an in-memory > fortran array with python? > > I've looked at f2py, but I could not tell if this was possible. f2py makes Python extension modules that wrap FORTRAN code. Basically, what you would have to do is use f2py to wrap the subroutines of your FORTRAN program; your Python program will be the main driver. It is usually recommended that your Python program allocate the memory in the form of a numpy array, and pass it into your FORTRAN subroutines to be filled. F77 fixed arrays are well-supported; F90 allocatable arrays and pointers are not. You may need a fixed array shim layer around your Fortran 90 code if it uses these features. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From jason.scheirer at gmail.com Fri Feb 13 16:52:07 2009 From: jason.scheirer at gmail.com (Jason Scheirer) Date: Fri, 13 Feb 2009 13:52:07 -0800 (PST) Subject: Upgrading standard library module References: Message-ID: On Feb 13, 12:42?pm, Bryan wrote: > I have a Python v2.5.2 server running and I found some undesirable > behavior in the xmlrpclib module that is included with that version of > Python. ?The xmlrpclib version that is included with Python 2.6 > changes the behavior for the better. ?I nervous about upgrading my > Python install to 2.6 on this server because I remember reading in the > docs of a library I use that it targets the 2.5 branch. ?What is the > best way to only upgrade the xmlrpclib in my 2.5 install? > > Also, have you all had problems with libraries not specifying which > Python version they target? ?I can't find a requirements for the > formencode library. ?It is kind of scary upgrading my Python server > install without being sure all my libraries will work. ?Experiences?? > > Bryan Python has always been pretty backwards-compatible and has a nice roadmap for upgrades (with new languages features living in __future__ for a version or so before they're in the main version). With the exception of 2.X->3, you can usually assume that any pure-Python modules written for 2.x will work in 2.(x+1), and assuming they don't issue any warnings, also in 2.(x+2). What behavior, exactly, do you not like in xmlrpclib? Diffing the 2.5 and 2.6, only significant differences I see are checks for True/False as builtins left over from pre-2.4 and some datetime handling. From bryanvick at gmail.com Fri Feb 13 17:17:35 2009 From: bryanvick at gmail.com (Bryan) Date: Fri, 13 Feb 2009 14:17:35 -0800 (PST) Subject: Upgrading standard library module References: Message-ID: On Feb 13, 1:52?pm, Jason Scheirer wrote: > On Feb 13, 12:42?pm, Bryan wrote: > > > I have a Python v2.5.2 server running and I found some undesirable > > behavior in the xmlrpclib module that is included with that version of > > Python. ?The xmlrpclib version that is included with Python 2.6 > > changes the behavior for the better. ?I nervous about upgrading my > > Python install to 2.6 on this server because I remember reading in the > > docs of a library I use that it targets the 2.5 branch. ?What is the > > best way to only upgrade the xmlrpclib in my 2.5 install? > > > Also, have you all had problems with libraries not specifying which > > Python version they target? ?I can't find a requirements for the > > formencode library. ?It is kind of scary upgrading my Python server > > install without being sure all my libraries will work. ?Experiences?? > > > Bryan > > Python has always been pretty backwards-compatible and has a nice > roadmap for upgrades (with new languages features living in __future__ > for a version or so before they're in the main version). With the > exception of 2.X->3, you can usually assume that any pure-Python > modules written for 2.x will work in 2.(x+1), and assuming they don't > issue any warnings, also in 2.(x+2). > > What behavior, exactly, do you not like in xmlrpclib? Diffing the 2.5 > and 2.6, only significant differences I see are checks for True/False > as builtins left over from pre-2.4 and some datetime handling. The xmlrpclib in my 2.5.2 install does not allow the marshaling of my custom objects. It checks the type of my object, and if it isn't in a hard-coded list of types, then a "Cannot marshal object of type" exception message shows up. The version in my Windows 2.6 install has a fall back case where if the type is not in the hard- coded list, it simply calls Object.__dict__ to get a graph of the object's values that can be marshaled into xmlrpc. I am using xmlrpc through Pylons. As a workaround, instead of returning my custom objects in my xmlrpc server functions, I return MyObject.__dict__ I also did not see anything in the revision log in the source file about this change. From torppa at staff.megabaud.fi Fri Feb 13 17:50:57 2009 From: torppa at staff.megabaud.fi (Jarkko Torppa) Date: Fri, 13 Feb 2009 22:50:57 GMT Subject: *nix tail -f multiple log files with Thread References: <4995A7EE.2000302@abbottdavid.com> Message-ID: On 2009-02-13, Christian Heimes wrote: > David schrieb: >> Hi everyone, >> >> I copied a program from C to track multiple log files. I would like to >> be able to print a label when a log file is updated. Here is the program; > > Don't use threads for the job. On Unix the preferred way is select()'ing > or poll()'ing multiple file descriptors. File descriptors associated with regular files always select true for ready to read, ready to write, and error condi- tions. Regular files always poll TRUE for reading and writing. You have to either sleep or use kevent/completion/... -- Jarkko Torppa, Elisa From rhodri at wildebst.demon.co.uk Fri Feb 13 17:57:42 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 13 Feb 2009 22:57:42 -0000 Subject: Untangling pythonWin and IDLE Processes on XP Pro In-Reply-To: <1Bcll.10420$hc1.4903@flpi150.ffdc.sbc.com> References: <%OUkl.6905$jZ1.2422@flpi144.ffdc.sbc.com> <6viopfFkcasmU1@mid.uni-berlin.de> <2NWkl.16040$YU2.9824@nlpi066.nbdc.sbc.com> <4ec6562a-08b2-4ec4-b9c0-e720e4ce7339@g38g2000yqd.googlegroups.com> <5-KdnfUPXNqQSgnUnZ2dnUVZ_sudnZ2d@earthlink.com> <1Bcll.10420$hc1.4903@flpi150.ffdc.sbc.com> Message-ID: On Fri, 13 Feb 2009 11:13:38 -0000, W. eWatson wrote: > OK, enough tinkering with the code and others matters on my end trying > to find a work around. Somehow after much successful use of IDLE's > execution facility, I've stepped on an invisible banana peel. I think > it's evident that I'm not going around this problem easily with the IDLE > execution attempts, and that another solution is required. Congratulations, we've only been telling you this for the last few days. I wonder, is there any chance that you've noticed the solution given? > First, I think somewhere up the thread someone suggested that Active > pythonWin is not dependent upon Tk, correct? Someone certainly suggested that something is based on Microsoft Foundation Classes, which isn't very likely to be Tk-based :-) Whatever that something is, I'm pretty sure it isn't called "Active pythonWin". > Therefore, it is immune from such problems, correct? No. Let me put it like this. Your Tkinter program is listening out for events like windows being moved, the mouse being clicked, keys being pressed and so on. IDLE also listens out for a selection of events of the same sort. A different graphical IDE will do the same, but will trap and interpret the events in an entirely different manner that is probably not even a little bit compatible with your program. When you run your program from inside *any* IDE, not just IDLE, it's a bit of a lottery as to whether your program gets an event, or the IDE does. Chances are, *both* need to see it, at which point you're stuck. It is possible to do this successfully, but only in a very limited way and only if you're very careful. If you think either of those conditions hold, you are wrong. > Second, maybe I missed it above, but when I posted the output from the > program that showed the failure, was there anything that said, "IDLE > problem" or would even give a clue that's the culprit? How can it? It's not IDLE's problem, it's yours. > Finally, we can probably agree that I can continue to use IDLE for > editing and syntax checking, but to "guarantee" successful execution of > the program, I can just double-click on the py file in my folder. > Perhaps there is a better way than clicking on it in the folder. Typing at a command prompt. > For example, putting it on the desktop. This causes an extra file read as Windows indirects through the desktop link. It's unlikely to be a noticeable delay at startup, but I'd hesitate to call it "better". > As I look at the folder, previous copies only differ by a digit, I can > easily find myself executing an earlier version, differing as Dev4, to > Dev5 at the end of each name. I'd suggest spending a while reading up on version control systems. -- Rhodri James *-* Wildebeeste Herder to the Masses From simon.hibbs at gmail.com Fri Feb 13 18:16:56 2009 From: simon.hibbs at gmail.com (Simon Hibbs) Date: Fri, 13 Feb 2009 15:16:56 -0800 (PST) Subject: A little bit else I would like to discuss References: <7f4cd287-dad4-4605-8b96-5edfdacc3da2@a12g2000yqm.googlegroups.com> <24ea9c29-6a0a-43cb-98c6-b6e486f017b9@j38g2000yqa.googlegroups.com> Message-ID: <165a0269-e7bb-49f0-a1cb-5507901604d7@h5g2000yqh.googlegroups.com> On 13 Feb, 02:53, azrael wrote: > All I hear when I talk to people who own or eork in SW companies is > "Python? Isn't that that small scripting language. This will never > bring a real application." I am tired of hearing this. Even Microsoft > implemented Python. Only because the GUI building I am thinking about > of moving to IronPython. But this great comunity holds me bac on > CPython. I don't agree at all that Python can't compete with Visual Studio for GUI development. There are Python modules for Eclipse if you need an enterprise class IDE. For GUI design the PyQT GUI toolkit includes QT Designer - a fully featured graphical GUI builder every bit as capable as the one in Visual Studio. In fact I much prefer working in QT Designer for GUI layout, the Signals/Slots model for hooking up to the application logic is just so much more elegant and robust. If Eclipse is a bit heavyweight for you, and you're after a Pyhton equivalent to VB, I can't recommend Eric enough. It's a Python IDE written in Python using the PyQT toolkit, and integrates directly with QTDesigner. IMHO it's far superior to anything Microsoft has to offer, with full native support for MacOS X, Linux and Windows. The only fly in the ointment in licensing. The QT toolkit will be fully GPL and LGPL from version 4.4, but PyQT itself has a dual GPL/ commercial licensing structure. Still, it's relatively cheap and well worth it if you're goingt to do commercial development. Simon Hibbs From me at gustavonarea.net Fri Feb 13 18:56:34 2009 From: me at gustavonarea.net (Gustavo Narea) Date: Fri, 13 Feb 2009 15:56:34 -0800 (PST) Subject: Turning a signature-changing decorator into a signature-preserving one Message-ID: <6b0518e3-142c-4555-8ad0-02c559f6b224@u13g2000yqg.googlegroups.com> Hello, everybody. I have this signature-changing decorator which I want to turn into a signature-preserving one. Here's my try , but I get this error: http://paste.chrisarndt.de/paste/33e06be6e6d74e49b05c45534dfcc9fe?wrap=no What am I doing wrong? I think it looks like this example: http://pypi.python.org/pypi/decorator#async Thanks in advance. - Gustavo. PS: functols.wrap is not an option because my code has to work with Python 2.4+. From basilisk96 at gmail.com Fri Feb 13 19:22:41 2009 From: basilisk96 at gmail.com (Basilisk96) Date: Fri, 13 Feb 2009 16:22:41 -0800 (PST) Subject: A little bit else I would like to discuss References: <7f4cd287-dad4-4605-8b96-5edfdacc3da2@a12g2000yqm.googlegroups.com> <8655e896-8276-4c53-ac6b-557e85f96992@r41g2000yqm.googlegroups.com> Message-ID: <69a1b6a7-94f3-448f-aebc-cbb628a72693@j38g2000yqa.googlegroups.com> On Feb 12, 10:39?pm, Damon wrote: > * Like R, every time there is a new version of Python, the repository > should rebuild the packages, for all supported platforms, and make > available all those that compile cleanly. R also forces you to write > properly structured documentation for every exposed function, before > the repository will accept it. A very good idea indeed. I would love to start using Py3k today, but I am still on 2.5 because I depend on win32 binaries for the majority of my library packages. I can build some myself, but not all. A repository of prebuilt binaries that stay in step with currently available language releases would be most welcome. Just my $0.02, -Basilisk96 From gloxy at yahoo.com Fri Feb 13 19:35:28 2009 From: gloxy at yahoo.com (Sue) Date: Sat, 14 Feb 2009 00:35:28 -0000 Subject: Which to install on my windows vista laptop? Message-ID: Hi, Which python 2.6.1 file should I download for my windows vista home premium laptop? (32bit, AMD turion 64 x2) the windows x86 MSI installer or the windows AMD64 MSI installer? Thank you! Sue From basilisk96 at gmail.com Fri Feb 13 19:44:38 2009 From: basilisk96 at gmail.com (Basilisk96) Date: Fri, 13 Feb 2009 16:44:38 -0800 (PST) Subject: how can this iterator be optimized? References: <727aabd1-9682-47aa-88e2-5dde96e4c32e@j1g2000yqi.googlegroups.com> Message-ID: <48b49eef-b3c1-4a9d-bf38-ad24c2b89622@t11g2000yqg.googlegroups.com> On Feb 12, 1:15?am, Steven D'Aprano wrote: > > I usually strive > > for comprehensions if a for loop can be reduced to such. > > Any particular reason? Only two. 1.) I was impressed by their clarity and conciseness when I first discovered them. 2.) I also read now and then that simple list comprehensions are faster when compared with their for-loop equivalents because of the way comprehensions are implemented under the hood. My example is a far cry from a "simple" comprehension, however. :) > If there's only one call to func(), and you ignore the (probably) fixed > cost of jumping into a generator each time, then it shouldn't make any > difference. > > If you are comparing one call to func() in a for loop versus three calls > to func() in a list comp or generator expression, then of course the for > loop will be more efficient. I agree. I would rather call func() only once per iteration in any case. I will revise it to a plain for loop with a single call. Thanks, -Basilisk96 From zpeteljac at gmaljo.com Fri Feb 13 19:45:53 2009 From: zpeteljac at gmaljo.com (Kurioz) Date: Sat, 14 Feb 2009 01:45:53 +0100 Subject: Which to install on my windows vista laptop? In-Reply-To: References: Message-ID: If you are using 32bit OS(which you are) then use the x86 MSI installer. AMD64 MSI installer is used only when you are using 64bit OS. "Sue" wrote in message news:mailman.9515.1234572128.3487.python-list at python.org... Hi, Which python 2.6.1 file should I download for my windows vista home premium laptop? (32bit, AMD turion 64 x2) the windows x86 MSI installer or the windows AMD64 MSI installer? Thank you! Sue From basilisk96 at gmail.com Fri Feb 13 19:54:32 2009 From: basilisk96 at gmail.com (Basilisk96) Date: Fri, 13 Feb 2009 16:54:32 -0800 (PST) Subject: Levenshtein word comparison -performance issue References: Message-ID: <78b2288c-6a67-4bc0-bd75-aebd85cc2a1a@i38g2000yqd.googlegroups.com> On Feb 13, 5:42?am, "Gabriel Genellina" wrote: > You may replace the last steps (sort + slice top 5) by heapq.nlargest - at ? > least you won't waste time sorting 49995 irrelevant words... > Anyway you should measure the time taken by the first part (Levenshtein), ? > it may be the most demanding. I think there is a C extension for this, ? > should be much faster than pure Python calculations. subdist: http://pypi.python.org/pypi/subdist/0.2.1 It uses a modified "fuzzy" version of the Levenshtein algorithm, which I found more useful than the strict version. The only quirk to it is that it accepts nothing but unicode. Other than that, it's a keeper. It is extremely fast. Cheers, -Basilisk96 From benjamin.kaplan at case.edu Fri Feb 13 20:01:32 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 13 Feb 2009 20:01:32 -0500 Subject: A little bit else I would like to discuss In-Reply-To: <69a1b6a7-94f3-448f-aebc-cbb628a72693@j38g2000yqa.googlegroups.com> References: <7f4cd287-dad4-4605-8b96-5edfdacc3da2@a12g2000yqm.googlegroups.com> <8655e896-8276-4c53-ac6b-557e85f96992@r41g2000yqm.googlegroups.com> <69a1b6a7-94f3-448f-aebc-cbb628a72693@j38g2000yqa.googlegroups.com> Message-ID: On Fri, Feb 13, 2009 at 7:22 PM, Basilisk96 wrote: > On Feb 12, 10:39 pm, Damon wrote: > > * Like R, every time there is a new version of Python, the repository > > should rebuild the packages, for all supported platforms, and make > > available all those that compile cleanly. R also forces you to write > > properly structured documentation for every exposed function, before > > the repository will accept it. > > A very good idea indeed. I would love to start using Py3k today, but I > am still on 2.5 because I depend on win32 binaries for the majority of > my library packages. I can build some myself, but not all. A > repository of prebuilt binaries that stay in step with currently > available language releases would be most welcome. > > Just my $0.02, > -Basilisk96 With Py3K, it's a little bit more complicated than rebuilding all the packages. Because it broke compatibility, all of the C extensions have to be rewritten before they'll work. That's why it's taking longer to create Python 3 packages than to create 2.6 versions. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From argo785 at gmail.com Fri Feb 13 20:35:04 2009 From: argo785 at gmail.com (argo785 at gmail.com) Date: Fri, 13 Feb 2009 17:35:04 -0800 (PST) Subject: Easier to wrap C or C++ libraries? Message-ID: <7baacd31-58c8-4e11-b25a-f827cc63d6ac@e18g2000yqo.googlegroups.com> When creating a Python binding to a C or C++ library, which is easier to wrap, the C lib or the C++ one? Given a choice, if you had to choose between using one of two libs, one written in C, the other in C+ + -- both having approximately the same functionality -- which would you rather deal with from your Python code? It would seem to me that there's fewer design considerations when wrapping a library written in C; you just wrap the functions. However, since Python supports OOP nicely, it might also be that wrapping C++ code *could* also be staightforward... Are there many pitfalls when having to map C++'s notion of OO to Python? From zooko at zooko.com Fri Feb 13 20:55:55 2009 From: zooko at zooko.com (zooko) Date: Fri, 13 Feb 2009 18:55:55 -0700 Subject: ANNOUNCING allmydata.org "Tahoe", the Least-Authority Filesystem, v1.3 Message-ID: <4DEC20D9-6E49-451C-9F32-50A377F5FAA4@zooko.com> Folks: This "Cloud Storage" system is written entirely in Python except for the CPU-intensive parts (cryptography and erasure coding), which are provided as Python extension modules. Thanks for making Python such a high-quality and effective tool! Regards, Zooko ANNOUNCING allmydata.org "Tahoe", the Least-Authority Filesystem, v1.3 We are pleased to announce the release of version 1.3.0 of "Tahoe", the Least Authority Filesystem. Tahoe-LAFS is a secure, decentralized, fault-tolerant filesystem. All of the source code is available under a choice of two Free Software, Open Source licences. This filesystem is encrypted and distributed over multiple peers in such a way it continues to function even when some of the peers are unavailable, malfunctioning, or malicious. Here is the one-page explanation of the security and fault-tolerance properties that it offers: http://allmydata.org/source/tahoe/trunk/docs/about.html This is the successor to v1.2, which was released July 21, 2008 [1]. This is a major new release, adding a repairer, an efficient backup command, support for large files, an (S)FTP server, and much more. See the NEWS file [2] and the known_issues.txt file [3] for more information. In addition to the many new features of Tahoe itself, a crop of related projects have sprung up, including Tahoe frontends for Windows and Macintosh, two front-ends written in JavaScript, a Tahoe plugin for duplicity, a Tahoe plugin for TiddlyWiki, a project to create a new backup tool, CIFS/SMB integration, an iPhone app, and three incomplete Tahoe frontends for FUSE. See Related Projects on the wiki: [4]. COMPATIBILITY The version 1 branch of Tahoe is the basis of the consumer backup product from Allmydata, Inc. -- http://allmydata.com . Tahoe v1.3 is fully compatible with the version 1 branch of Tahoe. Files written by v1.3 clients can be read by clients of all versions back to v1.0 unless the file is too large -- files greater than about 12 GiB (depending on the configuration) can't be read by older clients. v1.3 clients can read files produced by clients of all versions since v1.0. v1.3 servers can serve clients of all versions back to v1.0 and v1.3 clients can use servers of all versions back to v1.0 (but can't upload large files to them). This is the fourth release in the version 1 series. We believe that this version of Tahoe is stable enough to rely on as a permanent store of valuable data. The version 1 branch of Tahoe will be actively supported and maintained for the forseeable future, and future versions of Tahoe will retain the ability to read files and directories produced by Tahoe v1 for the forseeable future. WHAT IS IT GOOD FOR? With Tahoe, you can distribute your filesystem across a set of computers, such that if some of the computers fail or turn out to be malicious, the entire filesystem continues to be available, thanks to the remaining computers. You can also share your files with other users, using a simple and flexible access control scheme. Because this software is new, we do not categorically recommend it as the sole repository of data which is extremely confidential or precious. However, we believe that erasure coding, strong encryption, Free/Open Source Software and careful engineering make Tahoe safer than common alternatives, such as RAID, removable drive, tape, or "on-line storage" or "Cloud storage" systems. This software comes with extensive unit tests [5], and there are no known security flaws which would compromise confidentiality or data integrity. (For all currently known issues please see the known_issues.txt file [2].) This release of Tahoe is suitable for the "friendnet" use case [6] -- it is easy to create a filesystem spread over the computers of you and your friends so that you can share disk space and files. LICENCE You may use this package under the GNU General Public License, version 2 or, at your option, any later version. See the file "COPYING.GPL" [7] for the terms of the GNU General Public License, version 2. You may use this package under the Transitive Grace Period Public Licence, version 1.0. The Transitive Grace Period Public Licence has requirements similar to the GPL except that it allows you to wait for up to twelve months after you redistribute a derived work before releasing the source code of your derived work. See the file "COPYING.TGPPL.html" [8] for the terms of the Transitive Grace Period Public Licence, version 1.0. (You may choose to use this package under the terms of either licence, at your option.) INSTALLATION Tahoe works on Linux, Mac OS X, Windows, Cygwin, and Solaris, and probably most other systems. Start with "docs/install.html" [9]. HACKING AND COMMUNITY Please join us on the mailing list [10]. Patches that extend and improve Tahoe are gratefully accepted -- the RoadMap page [11] shows the next improvements that we plan to make and CREDITS [12] lists the names of people who've contributed to the project. The wiki Dev page [13] contains resources for hackers. SPONSORSHIP Tahoe is sponsored by Allmydata, Inc. [14], a provider of commercial backup services. Allmydata, Inc. created the Tahoe project, and contributes hardware, software, ideas, bug reports, suggestions, demands, and money (employing several Tahoe hackers and instructing them to spend part of their work time on this Free Software project). Also they award customized t-shirts to hackers who find security flaws in Tahoe (see http://hacktahoe.org ). Thank you to Allmydata, Inc. for their generous and public-spirited support. Zooko Wilcox-O'Hearn on behalf of the allmydata.org team Special acknowledgment goes to Brian Warner, whose superb engineering skills and dedication are primarily responsible for the Tahoe implementation, and largely responsible for the Tahoe design as well, not to mention most of the docs and many other things besides. February 13, 2009 Boulder, Colorado, USA [1] http://allmydata.org/trac/tahoe/browser/relnotes.txt?rev=2789 [2] http://allmydata.org/trac/tahoe/browser/NEWS [3] http://allmydata.org/trac/tahoe/browser/docs/known_issues.txt [4] http://allmydata.org/trac/tahoe/wiki/RelatedProjects [5] http://allmydata.org/trac/tahoe/wiki/Dev [6] http://allmydata.org/trac/tahoe/wiki/UseCases [7] http://allmydata.org/trac/tahoe/browser/COPYING.GPL [8] http://allmydata.org/source/tahoe/trunk/COPYING.TGPPL.html [9] http://allmydata.org/source/tahoe/trunk/docs/install.html [10] http://allmydata.org/cgi-bin/mailman/listinfo/tahoe-dev [11] http://allmydata.org/trac/tahoe/roadmap [12] http://allmydata.org/trac/tahoe/browser/CREDITS?rev=2677 [13] http://allmydata.org/trac/tahoe/wiki/Dev [14] http://allmydata.com From barry at python.org Fri Feb 13 21:15:38 2009 From: barry at python.org (Barry Warsaw) Date: Fri, 13 Feb 2009 21:15:38 -0500 Subject: RELEASED Python 3.0.1 Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On behalf of the Python development team, I'm happy to announce the availability of Python 3.0.1, the first bug fix release of Python 3.0. Version 3.0.1 fixes dozens of bugs reported since the release of Python 3.0 on December 3rd, 2008. Python 3.0 represents a major milestone in Python's history. This new version of the language is incompatible with the 2.x line of releases, while remaining true to BDFL Guido van Rossum's vision. For more information, links to documentation, and downloadable distributions, see the Python 3.0.1 release page: http://www.python.org/download/releases/3.0.1/ To report bugs in Python 3.0.1, please submit them to the issue tracker at: http://bugs.python.org/ Enjoy! Barry -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (Darwin) iQCVAwUBSZYpSnEjvBPtnXfVAQLQwgP/WSHp12dJVpEYtEOL/X8ynCQACriij9AM PgT6SacbMJLbsy84CTGA1lxF4NdEUQMY1IYz0do/aZ0+nBkSoy7SlkOVcncysLSC hVyTVlWQBdh63yA8QUk1I5dMbKeNpbCqRRgvSHaBrVdVz9mDM/r/L+j9lhBW4Cam 2lHLjRdQaG0= =vy0O -----END PGP SIGNATURE----- From fetchinson at googlemail.com Fri Feb 13 21:28:22 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Fri, 13 Feb 2009 18:28:22 -0800 Subject: Easier to wrap C or C++ libraries? In-Reply-To: <7baacd31-58c8-4e11-b25a-f827cc63d6ac@e18g2000yqo.googlegroups.com> References: <7baacd31-58c8-4e11-b25a-f827cc63d6ac@e18g2000yqo.googlegroups.com> Message-ID: > When creating a Python binding to a C or C++ library, which is easier > to wrap, the C lib or the C++ one? Given a choice, if you had to > choose between using one of two libs, one written in C, the other in C+ > + -- both having approximately the same functionality -- which would > you rather deal with from your Python code? > > It would seem to me that there's fewer design considerations when > wrapping a library written in C; you just wrap the functions. However, > since Python supports OOP nicely, it might also be that wrapping C++ > code *could* also be staightforward... Are there many pitfalls when > having to map C++'s notion of OO to Python? There is no question about it in my mind that wrapping C is easier. Reason being that python is written in C and not C++. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From benjamin at python.org Fri Feb 13 21:40:32 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 14 Feb 2009 02:40:32 +0000 (UTC) Subject: pdb in 3.0 very buggy (Win XP Home) References: <8a640af7-41e9-4de6-8b18-fa18c3448b64@v5g2000pre.googlegroups.com> Message-ID: Aaron Brady gmail.com> writes: > > Hi, got a freeze when running 'pdb' in 3.0. This is a known issue because of the rewrite of the IO library in 3.0. It will hopefully be fixed in 3.1. See http://bugs.python.org/issue3618 for more information. From clp2 at rebertia.com Fri Feb 13 21:40:56 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 13 Feb 2009 18:40:56 -0800 Subject: Easier to wrap C or C++ libraries? In-Reply-To: <7baacd31-58c8-4e11-b25a-f827cc63d6ac@e18g2000yqo.googlegroups.com> References: <7baacd31-58c8-4e11-b25a-f827cc63d6ac@e18g2000yqo.googlegroups.com> Message-ID: <50697b2c0902131840h6000f2adkb1c1011a33d8189b@mail.gmail.com> On Fri, Feb 13, 2009 at 5:35 PM, wrote: > When creating a Python binding to a C or C++ library, which is easier > to wrap, the C lib or the C++ one? Given a choice, if you had to > choose between using one of two libs, one written in C, the other in C+ > + -- both having approximately the same functionality -- which would > you rather deal with from your Python code? > > It would seem to me that there's fewer design considerations when > wrapping a library written in C; you just wrap the functions. However, > since Python supports OOP nicely, it might also be that wrapping C++ > code *could* also be staightforward... Are there many pitfalls when > having to map C++'s notion of OO to Python? You're asking two separate questions here. (1) For Python bindings, is it easier to wrap C, or C++ libraries? As Daniel points out, C is easier to wrap because CPython itself is written in C, and C++ cannot be linked directly to C. (2) Is it easier to use C or C++ bindings from Python code? Interface-wise, the C++ bindings would be easier to work with at the Python level as they are object-oriented. In practice, C libraries are usually wrapped because that's easier to do. However, to compensate for their procedural interface, people often write another module on top of the raw Python bindings to expose a public interface that appears more object-oriented, and make the lower-level module internal/private. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From sammo2828 at gmail.com Fri Feb 13 23:01:22 2009 From: sammo2828 at gmail.com (Sammo) Date: Fri, 13 Feb 2009 20:01:22 -0800 (PST) Subject: String concatenation performance with += Message-ID: <2b2d6d33-f43d-4dd0-b881-1f4edb24ad2e@o2g2000prl.googlegroups.com> String concatenation has been optimized since 2.3, so using += should be fairly fast. In my first test, I tried concatentating a 4096 byte string 1000 times in the following code, and the result was indeed very fast (12.352 ms on my machine). import time t = time.time() mydata = "" moredata = "A"*4096 for i in range(1000): mydata += moredata # 12.352 ms print "%0.3f ms"%(1000*(time.time() - t)) However, I got a different result in my second test, which is implemented in a class with a feed() method. This test took 4653.522 ms on my machine, which is 350x slower than the previous test! class StringConcatTest: def __init__(self): self.mydata = "" def feed(self, moredata): self.mydata += moredata # 4653.522 ms test = StringConcatTest() t = time.time() for i in range(1000): test.feed(moredata) print "%0.3f ms"%(1000*(time.time() - t)) Note that I need to do something to mydata INSIDE the loop, so please don't tell me to append moredata to a list and then use "".join after the loop. Why is the second test so much slower? From benjamin at python.org Fri Feb 13 23:12:29 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 14 Feb 2009 04:12:29 +0000 (UTC) Subject: String concatenation performance with += References: <2b2d6d33-f43d-4dd0-b881-1f4edb24ad2e@o2g2000prl.googlegroups.com> Message-ID: Sammo gmail.com> writes: > > String concatenation has been optimized since 2.3, so using += should > be fairly fast. This is implementation dependent and shouldn't be relied upon. > > Note that I need to do something to mydata INSIDE the loop, so please > don't tell me to append moredata to a list and then use "".join after > the loop. Then why not just mutate the list and then call "".join? > > Why is the second test so much slower? Probably several reasons: 1. Function call overhead is quite large compared to these simple operations. 2. You are resolving attribute names. From benjamin.kaplan at case.edu Fri Feb 13 23:46:12 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 13 Feb 2009 23:46:12 -0500 Subject: RELEASED Python 3.0.1 In-Reply-To: References: Message-ID: On Fri, Feb 13, 2009 at 9:15 PM, Barry Warsaw wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On behalf of the Python development team, I'm happy to announce the > availability of Python 3.0.1, the first bug fix release of Python 3.0. > Version 3.0.1 fixes dozens of bugs reported since the release of Python 3.0 > on December 3rd, 2008. > > Python 3.0 represents a major milestone in Python's history. This new > version of the language is incompatible with the 2.x line of releases, while > remaining true to BDFL Guido van Rossum's vision. > > For more information, links to documentation, and downloadable > distributions, see the Python 3.0.1 release page: > > http://www.python.org/download/releases/3.0.1/ > > To report bugs in Python 3.0.1, please submit them to the issue tracker at: > > http://bugs.python.org/ > > Enjoy! > Barry Any chance of getting a Mac installer for this one? -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at pearwood.info Fri Feb 13 23:47:19 2009 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 14 Feb 2009 15:47:19 +1100 Subject: A little bit else I would like to discuss References: <7f4cd287-dad4-4605-8b96-5edfdacc3da2@a12g2000yqm.googlegroups.com> Message-ID: <01a64287$0$16735$c3e8da3@news.astraweb.com> Martin wrote: > Hi, > > at first I wanted to file this under meta-discussions, but your lost > paragraph got me thinking... > > 2009/2/12 Christian Heimes : >> Nobody is going to stop you from creating a large bundle of useful >> extensions as long as you follow the licenses. In fact lots of people >> may appreciate a bundle. But the Python core package will always stay >> small and agile. > > How does "small and agile" work with "batteries included"? Well, it certainly isn't agile without batteries. >>From my point of view: > > agile:: > Would describe faster extension of the standard lib (rrd, yaml should > IMHO already be in the standard lib). No, agile describes the language. It's easy to get things done *with* Python. You're asking whether the Python-dev development process of getting packages added to the standard library is agile. It absolutely is not, and that is by design: python-dev doesn't want to fill the std lib up with unnecessary, unused and buggy batteries just because one or two people request them. > I'm pretty sure other people > want to see other modules, but that's what agile + standard lib would > mean for me. (Also I'm sometimes confused by the naming of modules but > that's a different story) The process for getting modules added to the std lib is on the Python website. http://www.python.org/dev/peps/pep-0002/ If you have a library you want added, go right ahead and make a PEP. > small:: > just the opposite of "batteries included" Says who? Batteries can be small, and adding a few new batteries to the pile doesn't necessarily make the pile significantly bigger. Small means it doesn't have unnecessary batteries. > My absolute favorite would be > > * python as just python (no standard lib) Would be a toy. > * a (rather) fast moving standard lib available as an addon download No no no, the std lib needs to be conservative, so that if you write code that relies on the std lib, you can be confident that it will work anywhere. The core language and std library are conservative, slowly changing, so that developers have stability. You don't have to write code like this: if version == 2.5: code block elif version == 2.5.1b: different code block elif version == 2.5.1: still different code block elif version == 2.5.2: if exists(module): code block else: something different again elif version == 2.5.3: ... If you want to live on the bleeding edge, with rapidly changing APIs and libraries, they have a repository for that. It's called "the Internet". -- Steven From notvalid2 at sbcglobal.net Fri Feb 13 23:58:33 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Fri, 13 Feb 2009 20:58:33 -0800 Subject: Untangling pythonWin and IDLE Processes on XP Pro In-Reply-To: <-5OdnU6H_-GbTgjUnZ2dnUVZ_h6dnZ2d@pdx.net> References: <%OUkl.6905$jZ1.2422@flpi144.ffdc.sbc.com> <6viopfFkcasmU1@mid.uni-berlin.de> <2NWkl.16040$YU2.9824@nlpi066.nbdc.sbc.com> <4ec6562a-08b2-4ec4-b9c0-e720e4ce7339@g38g2000yqd.googlegroups.com> <5-KdnfUPXNqQSgnUnZ2dnUVZ_sudnZ2d@earthlink.com> <1Bcll.10420$hc1.4903@flpi150.ffdc.sbc.com> <-5OdnU6H_-GbTgjUnZ2dnUVZ_h6dnZ2d@pdx.net> Message-ID: Scott David Daniels wrote: > W. eWatson wrote: >> Terry Reedy wrote: >>> W. eWatson wrote: >>>> From Diez above. >>>> What does *NOT* work is writing a Tkinter-based app in idle, and to >>>> run it >>>> *FROM INSIDE* idle. Instead, open your explorer and double-click on the >>>> pyhton-file your app is in. That's all that there is to it. >>>> >>>> So this is the absolute truth? No wiggle room? One can never use a >>>> Tkinter program with IDLE, and execute it successfully. So IDLE >>>> doesn't issue a standard warning that says, "Get out of here with >>>> your Tkinter program, it will fail when you try to run it here. You >>>> have entered Tkinter hell. Good-bye." >>> >>> Re-read my post about kids fighting to control a television. Maybe >>> they work together, maybe they crash the TV. Hard to predict. >>> >>> ***ANY*** Python program that tries to grab and control the same >>> resources that TK does may conflict with it. There is no way that >>> IDLE can have a list of, for instance, all event-grabbing mainloop >>> programs. >>> >> OK, enough tinkering with the code and others matters on my end trying >> to find a work around. Somehow after much successful use of IDLE's >> execution facility, I've stepped on an invisible banana peel. I think >> it's evident that I'm not going around this problem easily with the >> IDLE execution attempts, and that another solution is required. > That's correct, but you still don't understand _why_ it is correct. > I suggest you re-read the thread and try to understand everything you > are being told. > >> First, I think somewhere up the thread someone suggested that Active >> pythonWin is not dependent upon Tk, correct? Therefore, it is immune >> from such problems, correct? > > Wrong. I was the one who said that ActiveState had a product to debug > Python programs across a nertwork connection. The product is _not_ > ActivePython (the freely distributed system), but rather the Komodo IDE, > which does cost money. I'm pretty sure it wasn't you, and had no relationship to what you brought up earlier several messages up the thread. There are other forums. > >> Finally, we can probably agree that I can continue to use IDLE for >> editing and syntax checking, but to "guarantee" successful execution >> of the program, I can just double-click on the py file in my folder. >> Perhaps there is a better way than clicking on it in the folder. For >> example, putting it on the desktop. As I look at the folder, previous >> copies only differ by a digit, I can easily find myself executing an >> earlier version, differing as Dev4, to Dev5 at the end of each name. > > OK, you are using the oldest and least useful revision control system, > "rename and remember." I'd suggest you get and use bazaar, but you'll > just ask for shortcuts on how to use it without understanding what it does. It works for me, and, frankly, I'm not interested in going to Linux, SunOS or other "revision systmes". These are way in my distant past, and the only reason I'm currently, and begrudgingly, once again writing programs is that the Python software program I am using is limited in its ability. I've finally, after 2-3 years of hoping someone else would do it, taken up the torch to add new features. Frankly, I'd rather be doing something else with my time. And, yes, you are somewhat correct in your earlier assessment of my goals, the sooner this is over the better. You may not like my philosophy, but it serves me well at the moment, and I'm moving ahead nicely now. As I recall from the old movie Desk Set, a conversation between their two characters regarding a puzzle he was about to give her as a test of her office abilities: Tracy cautions Hepburn, "Never assume!" before relating the famous "detective" problem. Never assume. Nevertheless, thank you for your responses. Be kind to your keyboard. Cheers. > > --Scott David Daniels > Scott.Daniels at Acm.Org -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From notvalid2 at sbcglobal.net Sat Feb 14 00:03:13 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Fri, 13 Feb 2009 21:03:13 -0800 Subject: Untangling pythonWin and IDLE Processes on XP Pro In-Reply-To: References: <%OUkl.6905$jZ1.2422@flpi144.ffdc.sbc.com> <6viopfFkcasmU1@mid.uni-berlin.de> <2NWkl.16040$YU2.9824@nlpi066.nbdc.sbc.com> <4ec6562a-08b2-4ec4-b9c0-e720e4ce7339@g38g2000yqd.googlegroups.com> <5-KdnfUPXNqQSgnUnZ2dnUVZ_sudnZ2d@earthlink.com> <1Bcll.10420$hc1.4903@flpi150.ffdc.sbc.com> Message-ID: ... > How can it? It's not IDLE's problem, it's yours. > >> Finally, we can probably agree that I can continue to use IDLE for >> editing and syntax checking, but to "guarantee" successful execution >> of the program, I can just double-click on the py file in my folder. >> Perhaps there is a better way than clicking on it in the folder. > > Typing at a command prompt. > >> For example, putting it on the desktop. > > This causes an extra file read as Windows indirects through the desktop > link. It's unlikely to be a noticeable delay at startup, but I'd > hesitate to call it "better". > >> As I look at the folder, previous copies only differ by a digit, I can >> easily find myself executing an earlier version, differing as Dev4, to >> Dev5 at the end of each name. > > I'd suggest spending a while reading up on version control systems. > See my response to Scott. Thanks for your reply. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From steve at pearwood.info Sat Feb 14 00:37:01 2009 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 14 Feb 2009 16:37:01 +1100 Subject: Embarrasing questio References: <2dd78188-434d-4c24-bd73-2047105c6a89@q30g2000prq.googlegroups.com> Message-ID: <01a64e2d$0$20655$c3e8da3@news.astraweb.com> TechieInsights wrote: > On Feb 12, 9:03?am, Catherine Heathcote > wrote: >> But I just cant find it. How do I do an or, as in c/c++'s ||? Just >> trying to do something simple, the python equivilent of: >> >> if(i % 3 == 0 || i % 5 == 0) >> >> Thanks. > > in 2.5 and above you can do > if any(i%3 == 0, i%5 == 0) [nitpick: you need an additional set of brackets inside the call to any] I love it! A totally unnecessary creation of a tuple and a function call instead of a straight-forward 'or' expression. Can we make this simple task even more obfuscated? not all( (i%3 != 0, i%5 !=0) ) Still not convoluted enough. all( (sum(int(c) for c in str(i))%3 in (1, 2), str(i).endswith(chr(53)) - 1, str(i).endswith(chr(48)) - 1) ) - 1 Hmmm... how can I get rid of that pesky %3? all( (divmod( sum(int(c) for c in str(i)), 41^42)[1] in (1, 2), str(i).endswith(chr(53)) - 1, str(i).endswith(chr(48)) - 1) ) - 1 Okay, that makes my brain hurt. I think it will do. :-) -- Steven From michele.simionato at gmail.com Sat Feb 14 00:38:15 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 13 Feb 2009 21:38:15 -0800 (PST) Subject: Turning a signature-changing decorator into a signature-preserving one References: <6b0518e3-142c-4555-8ad0-02c559f6b224@u13g2000yqg.googlegroups.com> Message-ID: <6b0874ad-4c30-4b3f-a559-f83465d332da@z1g2000yqn.googlegroups.com> On Feb 14, 12:56?am, Gustavo Narea wrote: > Hello, everybody. > > I have this signature-changing decorator > > which I > want to turn into a signature-preserving one. Here's my try > , > but I get > this error:http://paste.chrisarndt.de/paste/33e06be6e6d74e49b05c45534dfcc9fe?wra... > > What am I doing wrong? I think it looks like this example:http://pypi.python.org/pypi/decorator#async > > Thanks in advance. > > ? - Gustavo. > > PS: functols.wrap is not an option because my code has to work with > Python 2.4+. Difficult to see what is happening, since you have so many dependencies. However, from the traceback I would say that you are passing to the decorator a function with a __name__ attribute which is None. I would insert a call to pdb here def __call__(self, func): import pdb; pdb.set_trace() return decorator(self.call, func) and I would inspect func.__name__. HTH, M.Simionato From steve at pearwood.info Sat Feb 14 00:41:09 2009 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 14 Feb 2009 16:41:09 +1100 Subject: A little bit else I would like to discuss References: <7f4cd287-dad4-4605-8b96-5edfdacc3da2@a12g2000yqm.googlegroups.com> <3ee5cf15-27de-4ed2-ace3-9f08ab5a793d@t11g2000yqg.googlegroups.com> Message-ID: <01a64f24$0$20669$c3e8da3@news.astraweb.com> Damon wrote: > Use Visual Studio to program a .net application using Windows Forms. > Run it in Mono on Windows, or OS X, or Linux. ... > Also, you can quibble whether it's Visual > Studio that tries to address this, or the Mono effort. There's no quibble. It's obviously Mono. How can you possible justify the suggestion that it could be Visual Studio? That's rather like saying that American electrical plugs fit perfectly into Australian power sockets because there are adaptors. -- Steven From sammo2828 at gmail.com Sat Feb 14 00:44:12 2009 From: sammo2828 at gmail.com (Sammo) Date: Fri, 13 Feb 2009 21:44:12 -0800 (PST) Subject: String concatenation performance with += References: <2b2d6d33-f43d-4dd0-b881-1f4edb24ad2e@o2g2000prl.googlegroups.com> Message-ID: <748284e0-7e93-4a7a-9511-b6a5e5aaa5ab@w1g2000prk.googlegroups.com> Okay, this is what I have tried for string concatenation: 1. Using += implemented using simple operations (12 ms) 2. Using += implemented inside a class (4000+ ms) 3. Using "".join implemented using simple operations (4000+ ms) 4. Using "".join implemented inside a class (4000+ ms) On Feb 14, 3:12?pm, Benjamin Peterson wrote: > Sammo gmail.com> writes: > > > String concatenation has been optimized since 2.3, so using += should > > be fairly fast. > > This is implementation dependent and shouldn't be relied upon. > > > Note that I need to do something to mydata INSIDE the loop, so please > > don't tell me to append moredata to a list and then use "".join after > > the loop. > > Then why not just mutate the list and then call "".join? AFAIK, using list mutation and "".join only improves performance if the "".join is executed outside of the loop. In fact, in Python 2.5.2, using "".join inside the loop is actually much slower compared to my original test, which concatenates using +=. My original test with simple operations took 12 ms to run: import time t = time.time() mydata = "" moredata = "A"*4096 for i in range(1000): mydata += moredata # 12.352 ms # do some stuff to mydata # ... print "%0.3f ms"%(1000*(time.time() - t)) New code modified to mutate the list, then call "".join now takes 4417 ms to run. This is much slower! import time t = time.time() mydata = [] moredata = "A"*4096 for i in range(1000): mydata.append(moredata) mydata = ["".join(mydata)] # do some stuff to mydata # ... Using list mutation and "".join, implemented in a class. This took 4434 ms to run, which is again much slower than the original test. Note that it is about the same speed as using += implemented in a class. import time moredata = "A"*4096 class StringConcatTest: def __init__(self): self.mydata = [] def feed(self, moredata): self.mydata.append(moredata) self.mydata = ["".join(self.mydata)] # do some stuff to self.mydata # ... test = StringConcatTest() t = time.time() for i in range(1000): test.feed(moredata) print "%0.3f ms"%(1000*(time.time() - t)) > > Why is the second test so much slower? > > Probably several reasons: > > 1. Function call overhead is quite large compared to these simple operations. > 2. You are resolving attribute names. The main problem I need help with is how to improve the performance of the code implemented in a class. It is currently 350x slower than the first test using simple operations, so surely there's got to be a way. From steve at pearwood.info Sat Feb 14 00:47:57 2009 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 14 Feb 2009 16:47:57 +1100 Subject: String concatenation performance with += References: <2b2d6d33-f43d-4dd0-b881-1f4edb24ad2e@o2g2000prl.googlegroups.com> Message-ID: <01a650bd$0$31512$c3e8da3@news.astraweb.com> Benjamin Peterson wrote: > Sammo gmail.com> writes: > >> String concatenation has been optimized since 2.3, so using += should >> be fairly fast. > > This is implementation dependent and shouldn't be relied upon. It's also a fairly simple optimization and really only applies to direct object access, not items or attributes. >>> Timer('s += "x"', 's = ""').repeat(number=100000) [0.067316055297851562, 0.063985109329223633, 0.066659212112426758] >>> Timer('s[0] += "x"', 's = [""]').repeat(number=100000) [3.0495560169219971, 2.2938292026519775, 2.2914319038391113] >>> Timer('s.s += "x"', ... 'class K(object): pass \ns=K();s.s = ""').repeat(number=100000) [3.3624241352081299, 2.3346412181854248, 2.9846079349517822] >> Note that I need to do something to mydata INSIDE the loop, so please >> don't tell me to append moredata to a list and then use "".join after >> the loop. > > Then why not just mutate the list and then call "".join? Yes, there almost certainly is a way to avoid the repeated concatenation. >> Why is the second test so much slower? > > Probably several reasons: > > 1. Function call overhead is quite large compared to these simple > operations. 2. You are resolving attribute names. 3. Because the optimization isn't applied in this case. -- Steven From steve at pearwood.info Sat Feb 14 01:06:02 2009 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 14 Feb 2009 17:06:02 +1100 Subject: Avoiding argument checking in recursive calls References: <7xeiy52zfl.fsf@ruckus.brouhaha.com> Message-ID: <01a654fa$0$20662$c3e8da3@news.astraweb.com> Terry Reedy wrote: > Steven D'Aprano wrote: >> On Wed, 11 Feb 2009 04:31:10 -0500, Terry Reedy wrote: >> >>>> Steven D'Aprano writes: >>>>> def fact(n): >>>>> if n < 0: raise ValueError >>>>> if n = 0: return 1 >>>>> return fact(n-1)*n >>>>> >>>>> At the risk of premature optimization, I wonder if there is an idiom >>>>> for avoiding the unnecessary test for n <= 0 in the subsequent >>>>> recursive calls? >>> Reverse the test order >>> >>> def fact(n): >>> if n > 0: return fact(n-1)*n >>> if n == 0: return 1 >>> raise ValueError >>> >>> You must test recursive versus terminal case every call in any case. >>> Nearly always, the first test passes and second is not done. You only >>> test n==0 once, either to terminate or raise exception. This works for >>> any integral value and catches non-integral values. (There is some delay >>> for that, but only bad calls are penalized.) >> >> Nice try, but in fact no. > > I meant non-integral numbers. Others inputs are outside the usual spec > for fact(). I thought I had made it clear that fact() was just an illustration of a recursive function, and the test n < 0 was just a stand-in for a more expensive test. It was toy example to illustrate a general question. Perhaps I could have made it more obvious with a less concrete example. Sorry for the confusion. > You asked about "an idiom for avoiding the unnecessary test > for n <= 0 in the subsequent recursive calls?" and I gave you that. You > should have thanked me. I did thank everybody who responded. That included you. I do appreciate your suggestions, even if I ultimately choose to do something else. [...] >> You're relying on arbitrary ordering of types in Python 2.x, > > No I'm not. I don't even know what you mean by that claim. What I understood was that you expected fact(some_arbitrary_object) to raise a ValueError. This works if some_arbitrary_object happens to be ordered less than 0, which only works at all because of the specific arbitrary ordering of types in Python 2.x. In Python 3 it won't work at all. >> and of course in Python 3 that fails altogether. > > In 3.0, which is what I use, the comparison 'n>0' raises an exception > for non-numbers, as it should. To me, that is success. What else would > you want? I might want not to expose exceptions from the implementation, and instead raise my own exception. For fact(), I might choose to do what you did, but for a more complex test, arbitrary objects might fail anywhere with potentially misleading error messages. It's a perfectly legitimate approach to let unexpected objects fail in unexpected ways. The advantage is that it's nice and lightweight. But it's also a legitimate approach to have a little more control over what exceptions are raised. -- Steven From steve at pearwood.info Sat Feb 14 01:08:58 2009 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 14 Feb 2009 17:08:58 +1100 Subject: String concatenation performance with += References: <2b2d6d33-f43d-4dd0-b881-1f4edb24ad2e@o2g2000prl.googlegroups.com> <01a650bd$0$31512$c3e8da3@news.astraweb.com> Message-ID: <01a655a9$0$20662$c3e8da3@news.astraweb.com> Steven D'Aprano wrote: > Benjamin Peterson wrote: > >> Sammo gmail.com> writes: >> >>> String concatenation has been optimized since 2.3, so using += should >>> be fairly fast. >> >> This is implementation dependent and shouldn't be relied upon. > > It's also a fairly simple optimization and really only applies to direct > object access, not items or attributes. > >>>> Timer('s += "x"', 's = ""').repeat(number=100000) > [0.067316055297851562, 0.063985109329223633, 0.066659212112426758] Oops, sorry, I should have said... Timer is timeit.Timer. -- Steven From steve at pearwood.info Sat Feb 14 01:33:21 2009 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 14 Feb 2009 17:33:21 +1100 Subject: String concatenation performance with += References: <2b2d6d33-f43d-4dd0-b881-1f4edb24ad2e@o2g2000prl.googlegroups.com> <748284e0-7e93-4a7a-9511-b6a5e5aaa5ab@w1g2000prk.googlegroups.com> Message-ID: <01a65b61$0$30497$c3e8da3@news.astraweb.com> Sammo wrote: > Okay, this is what I have tried for string concatenation: > > 1. Using += implemented using simple operations (12 ms) > 2. Using += implemented inside a class (4000+ ms) > 3. Using "".join implemented using simple operations (4000+ ms) > 4. Using "".join implemented inside a class (4000+ ms) I think you're doing more work than you need to. Here are my results: >>> def join_test(): ... L = [] ... block = "abcdefghijklmnopqrstuvwxyz"*1000 ... for i in xrange(1000): ... L.append(block) ... return ''.join(L) ... >>> def concat_test(): ... s = "" ... block = "abcdefghijklmnopqrstuvwxyz"*1000 ... for i in xrange(1000): ... s += block ... return s ... >>> assert join_test() == concat_test() >>> >>> from timeit import Timer >>> Timer('concat_test()', ... 'from __main__ import concat_test').repeat(number=100) [5.397799015045166, 4.3106229305267334, 4.3492171764373779] >>> Timer('join_test()', ... 'from __main__ import join_test').repeat(number=100) [4.5378072261810303, 3.9887290000915527, 3.919511079788208] The join() idiom is slightly faster than repeated concatenation, even with the optimization. If you're not seeing that result, you need to consider what extra work you're doing that you don't need to. >> Then why not just mutate the list and then call "".join? > > AFAIK, using list mutation and "".join only improves performance if > the "".join is executed outside of the loop. Naturally. If you needlessly join over and over again, instead of delaying until the end, then you might as well do string concatenation without the optimization. join() isn't some magical function that makes your bugs go away. You have to use it sensibly. What you've done is a variant of Shlemiel the road-painter's algorithm: http://www.joelonsoftware.com/articles/fog0000000319.html Perhaps you have to repeatedly do work on the *temporary* results in between loops? Something like this toy example? s = "" block = "abcdefghijklmnopqrstuvwxyz"*1000 for i in xrange(1000): s += block # do something with the partially concatenated string print "partial length is", len(s) # all finished do_something(s) You've written that using join: L = [] block = "abcdefghijklmnopqrstuvwxyz"*1000 for i in xrange(1000): L.append(block) # do something with the partially concatenated string L = [ ''.join(L) ] print "partial length is", len(L[0]) # all finished s = ''.join(L) do_something(s) Okay, but we can re-write that more sensibly: L = [] block = "abcdefghijklmnopqrstuvwxyz"*1000 for i in xrange(1000): L.append(block) # do something with the partially concatenated string print "partial length is", sum(len(item) for item in L) # all finished s = ''.join(L) do_something(s) There's still a Shlemiel algorithm in there, but it's executed in fast C instead of slow Python and it doesn't involve copying large blocks of memory, only walking them, so you won't notice as much. Can we be smarter? L = [] block = "abcdefghijklmnopqrstuvwxyz"*1000 partial_length = 0 for i in xrange(1000): L.append(block) partial_length += len(block) # do something with the partially concatenated string print "partial length is", partial_length # all finished s = ''.join(L) do_something(s) Naturally this is a toy example, but I think it illustrates one technique for avoiding turning an O(N) algorithm into an O(N**2) algorithm. Good luck! -- Steven From bj_666 at gmx.net Sat Feb 14 01:39:02 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 14 Feb 2009 06:39:02 GMT Subject: Untangling pythonWin and IDLE Processes on XP Pro References: <%OUkl.6905$jZ1.2422@flpi144.ffdc.sbc.com> <6viopfFkcasmU1@mid.uni-berlin.de> <2NWkl.16040$YU2.9824@nlpi066.nbdc.sbc.com> <4ec6562a-08b2-4ec4-b9c0-e720e4ce7339@g38g2000yqd.googlegroups.com> <5-KdnfUPXNqQSgnUnZ2dnUVZ_sudnZ2d@earthlink.com> <1Bcll.10420$hc1.4903@flpi150.ffdc.sbc.com> <-5OdnU6H_-GbTgjUnZ2dnUVZ_h6dnZ2d@pdx.net> Message-ID: <6vn786Fl3f4sU1@mid.uni-berlin.de> On Fri, 13 Feb 2009 20:58:33 -0800, W. eWatson wrote: > Scott David Daniels wrote: >> OK, you are using the oldest and least useful revision control system, >> "rename and remember." I'd suggest you get and use bazaar, but you'll >> just ask for shortcuts on how to use it without understanding what it >> does. > It works for me, and, frankly, I'm not interested in going to Linux, > SunOS or other "revision systmes". Linux and SunOS are *operating systems*, something completely different from *revision control systems*. A revision or version control system (VCS) lets you record the evolution of your software. You can tag versions with symbolic names like "Dev4" or "Release-1.0" and can ask the VCS for a copy of the sources with a given tag or even date. Ciao, Marc 'BlackJack' Rintsch From eliben at gmail.com Sat Feb 14 01:47:37 2009 From: eliben at gmail.com (eliben) Date: Fri, 13 Feb 2009 22:47:37 -0800 (PST) Subject: data structure for ASTs in Python-written parsers Message-ID: Hello, The Python interpreter uses ASDL (http://www.cs.princeton.edu/~danwang/ Papers/dsl97/dsl97.html) to describe the AST resulting from parsing. In previous versions, there was another AST being used by the compiler module - ast.txt and astgen.py in tools/compiler in the Python 2.5 source. However, as far as I understand this has been discontinued in later Pythons. I'm writing parsers in pure Python (with PLY), and wonder about the best representation to use for the AST. So far I've been using a self- cooked solution similar to ast.txt/astgen.py, but I was wondering about ASDL. Looking at it closely, it seems to me that ASDL is much more suitable for statically-typed languages like C and Java than the duck-typed Python. The assignment of types of nodes seems superfluous when "real" Node classes can be used. Wherever dispatching is needed on the type enum, in Python we can dispatch on isinstance(), and traversal using reflection (automatic AST walkers) is possible in Python on the simple representation, while ASDL just adds another complexity level. Does this make sense? I realize Python itself uses ASDL because its parser is coded in C. But what would you prefer as a representation for parsers written *in* Python? Thanks in advance From steve at pearwood.info Sat Feb 14 02:19:17 2009 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 14 Feb 2009 18:19:17 +1100 Subject: doctest fails to see tests in decorated functions Message-ID: <01a66625$0$21875$c3e8da3@news.astraweb.com> I've just spotted a bug in doctest that it fails to see tests inside decorated functions. It's been reported before: http://bugs.python.org/issue1108 but the patch submitted doesn't work for me. I have a test script on the page demonstrating the problem. Can anyone give me some clues as to a work-around? I tried adding objects to __test__ but testmod() still failed to pick up their tests. if __name__ == '__main__': import doctest import types __test__ = {} allowed = [str, types.FunctionType, types.ClassType, types.GeneratorType, types.MethodType, types.UnboundMethodType] for name in dir(): obj = vars()[name] if type(obj) in allowed: __test__[name] = obj doctest.testmod() -- Steven From martijnsteenwijk at gmail.com Sat Feb 14 03:04:46 2009 From: martijnsteenwijk at gmail.com (martijnsteenwijk at gmail.com) Date: Sat, 14 Feb 2009 00:04:46 -0800 (PST) Subject: Problem building Python extension References: <728a0c1c-2808-493c-a2db-c583442d2303@d32g2000yqe.googlegroups.com> Message-ID: On 13 feb, 12:45, Christian Heimes wrote: > martijnsteenw... at gmail.com wrote: > > Thanks a lot for your reply. I downloaded & installed Visual C# 2008 > > express, but unfortunately this doesn't change anything in running the > > setup file. Unfortunately, still no pyd file is produced... > > > Did I something wrong? > > Yeah, you installed the C# environment. Python is written in C, so you > have to get Visual Studio C++ 2008. However a recent version of MinGW32 > is sufficient to build most extensions. > > Christian Hi Christian, Thanks for your reply. In mean time, I discovered the C++ thing already ;-). Now I installed MinGW, but still the same happens. If I run the setup file, the same output comes on the command line and no pyd file is created... GRRR Any suggestions? Martijn From Nicolas.Thiery at u-psud.fr Sat Feb 14 03:19:53 2009 From: Nicolas.Thiery at u-psud.fr (=?ISO-8859-1?Q?Nicolas_M=2E_Thi=E9ry?=) Date: Sat, 14 Feb 2009 00:19:53 -0800 (PST) Subject: Pickling classes (not class instances) References: <582b45b4-ed93-4a05-9c7b-7f72da34861d@r36g2000prf.googlegroups.com> Message-ID: Dear python developers, I got no answer to my previous post on this thread "Pickling classes (not class instances)". This issue is a show stopper for our project. Any suggestion for where to ask? Thanks in advance! Best regards, Nicolas > Purpose of this e-mail: > ----------------------- > > How to customize how a class (not an instance of a class!!!) is > pickled? > > Example: > ============================================================================== > class metaclass(type): > def __new__(mcs, name, bases, dict): > print " running metaclass.__new__" > return type.__new__(mcs, name, bases, dict) > # > def __reduce_class__(self): > print "reducing a class" > # do the real work > > c = metaclass("foo", (object,), dict()) > > import copy_reg > copy_reg.pickle(metaclass, metaclass.__reduce_class__) > > pickle.dumps(c) > --------------------------------------------------------------------------- > PicklingError Traceback (most recent call > last) > ... > PicklingError: Can't pickle : it's not found as > __main__.foo > ============================================================================== > > Context: > -------- > > I am working on the Sage project (www.sagemath.org), and more > precisely on the category infrastructure. The code is building lots of > classes on the fly by composing preexisting classes by inheritance > (for the curious, see the doc of the class Category inhttp://sage.math.washington.edu:2144/file/1567cea09170/categories-nt....). > > Since those classes are built on the fly, they cannot be pickled with > the default mechanism of name lookup. A proper pickling would be to > rebuild the class anew. Nothing problematic, except for the question > above. > > Discussion: > ----------- > > It sounds like copy_reg would be the natural way to go (as in the > example above). However, its documentation suggests that it explicitly > is not intended for pickling classes, e.g. first paragraph of: > > http://docs.python.org/library/copy_reg.html#module-copy_reg > > is: > > The copy_reg module provides support for the pickle and cPickle > modules. The copy module is likely to use this in the future as > well. It provides configuration information about object > constructors which are not classes. Such constructors may be factory > functions or class instances. > > And indeed, looking up at the code of pickle (l. 289-299 of pickle.py) > (and similarly in cpickle), the copy-reg dispatch is explicit bypassed > for metaclasses: > > # Check for a class with a custom metaclass; treat as regular > class > try: > issc = issubclass(t, TypeType) > except TypeError: # t is not a class (old Boost; see SF > #502085) > issc = 0 > if issc: > self.save_global(obj) > return > > # Check copy_reg.dispatch_table > reduce = dispatch_table.get(t) > > Which causes the failure above. > > Is there a specific reason for this restriction? > > Would it be thinkable to move up the copy reg dispatch before the > metaclass treatment in pickle and cPickle? I did it locally, and it > fixed my problem. > > If not, what would be the right way to achieve this? > > Many thanks in advance! > > Best regards, > Nicolas > -- > Nicolas M. Thi?ry "Isil" http://Nicolas.Thiery.name/ From martijnsteenwijk at gmail.com Sat Feb 14 03:31:59 2009 From: martijnsteenwijk at gmail.com (martijnsteenwijk at gmail.com) Date: Sat, 14 Feb 2009 00:31:59 -0800 (PST) Subject: Problem building Python extension References: <728a0c1c-2808-493c-a2db-c583442d2303@d32g2000yqe.googlegroups.com> Message-ID: <3d42c023-07b5-4216-a217-d67cff580422@h20g2000yqn.googlegroups.com> On 14 feb, 09:04, martijnsteenw... at gmail.com wrote: > On 13 feb, 12:45, Christian Heimes wrote: > > > martijnsteenw... at gmail.com wrote: > > > Thanks a lot for your reply. I downloaded & installed Visual C# 2008 > > > express, but unfortunately this doesn't change anything in running the > > > setup file. Unfortunately, still no pyd file is produced... > > > > Did I something wrong? > > > Yeah, you installed the C# environment. Python is written in C, so you > > have to get Visual Studio C++ 2008. However a recent version of MinGW32 > > is sufficient to build most extensions. > > > Christian > > Hi Christian, > > Thanks for your reply. In mean time, I discovered the C++ thing > already ;-). > Now I installed MinGW, but still the same happens. If I run the setup > file, the same output comes on the command line and no pyd file is > created... GRRR > > Any suggestions? > > Martijn Hmmm, problem fixed :-) Downloaded the C++ compiler, runned the Visual Studio 2008 command prompt and it works! From martin at v.loewis.de Sat Feb 14 03:55:47 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 14 Feb 2009 09:55:47 +0100 Subject: [Python-Dev] RELEASED Python 3.0.1 In-Reply-To: References: Message-ID: <49968713.4080705@v.loewis.de> > Any chance of getting a Mac installer for this one? Chances are non-zero, yes. Martin From castironpi at gmail.com Sat Feb 14 04:26:20 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sat, 14 Feb 2009 01:26:20 -0800 (PST) Subject: Pickling classes (not class instances) References: <582b45b4-ed93-4a05-9c7b-7f72da34861d@r36g2000prf.googlegroups.com> Message-ID: On Feb 14, 2:19?am, Nicolas M. Thi?ry wrote: > ? ? ? ? ?Dear python developers, > > I got no answer to my previous post on this thread "Pickling classes > (not class instances)". > This issue is a show stopper for our project. Any suggestion for where > to ask? snip to http://groups.google.com/group/comp.lang.python/browse_thread/thread/66c282afc04aa39c/4d9304aa0cc791c2#4d9304aa0cc791c2 > > How to customize how a class (not an instance of a class!!!) is > > pickled? snip > > Is there a specific reason for this restriction? > > > Would it be thinkable to move up the copy reg dispatch before the > > metaclass treatment in pickle and cPickle? I did it locally, and it > > fixed my problem. > > > If not, what would be the right way to achieve this? Hi Nicolas, I couldn't get yours to work. I also tried defining '__reduce__' and '__getstate__' in the metaclass; they didn't work either. Can you just subclass Pickler, and override the 'save' method? > > Is there a specific reason for this restriction? It sounds very odd. I'm not a core dev, so I can't say. I also tried defining '__subclasshook__' to convince 'metaclass' it is not a subclass of 'type'. It didn't work, but 'register' was not working the way I wanted. Perhaps you could define your own 'custom_type' type, which looks and acts just like type, but just doesn't pass the 'subclass' test. It may be as simple as just cutting-and-pasting the TypeObject definition from the core. From __peter__ at web.de Sat Feb 14 04:31:38 2009 From: __peter__ at web.de (Peter Otten) Date: Sat, 14 Feb 2009 10:31:38 +0100 Subject: Levenshtein word comparison -performance issue References: Message-ID: Gabriel Genellina wrote: > En Fri, 13 Feb 2009 08:16:00 -0200, S.Selvam Siva > escribi?: > >> I need some help. >> I tried to find top n(eg. 5) similar words for a given word, from a >> dictionary of 50,000 words. >> I used python-levenshtein module,and sample code is as follow. >> >> def foo(searchword): >> disdict={} >> for word in self.dictionary-words: >> distance=Levenshtein.ratio(searchword,word) >> disdict[word]=distance >> """ >> sort the disdict dictionary by values in descending order >> """ >> similarwords=sorted(disdict, key=disdict.__getitem__, reverse=True) >> >> return similarwords[:5] > > You may replace the last steps (sort + slice top 5) by heapq.nlargest - at > least you won't waste time sorting 49995 irrelevant words... > Anyway you should measure the time taken by the first part (Levenshtein), > it may be the most demanding. I think there is a C extension for this, > should be much faster than pure Python calculations. > [I didn't see the original post] You can use the distance instead of the ratio and put the words into bins of the same length. Then if you find enough words with a distance <= 1 in the bin with the same length as the search word you can stop looking. You might be able to generalize this approach to other properties that are fast to calculate and guarantee a minimum distance, e. g. set(word). Peter From samslists at gmail.com Sat Feb 14 04:51:40 2009 From: samslists at gmail.com (Sam) Date: Sat, 14 Feb 2009 01:51:40 -0800 (PST) Subject: codecs.open and buffering modes... References: <56a55b5c-ca64-4c84-a8a8-3912af384e4c@f40g2000pri.googlegroups.com> Message-ID: Hmmm...no one knows the reason for the discrepancy? Should I post on the developers' list to see if anyone knows? Thanks On Feb 9, 6:19?pm, Sam wrote: > codecs.open defaults to line buffering. ?But open defaults to using > the system buffer size. ?Why the discrepancy? ?Is it different for a > reason? > > How do these choices affect performance? ?(Particularly under Linux). > > Thanks From vriolk at gmail.com Sat Feb 14 05:08:38 2009 From: vriolk at gmail.com (coldpizza) Date: Sat, 14 Feb 2009 02:08:38 -0800 (PST) Subject: best set of modules for web automation without javascript References: <49957df1$0$15145$426a74cc@news.free.fr> Message-ID: <70d53ba1-7451-413a-807f-3e1021cdf8bb@d32g2000yqe.googlegroups.com> You should have a look at twill: http://twill.idyll.org It seems to be no longer maintained, but will probably do most of what you expect. And it is built on top of mechanize. On Feb 13, 4:04?pm, News123 wrote: > Hi, > > I'd like to do some web automation with python 2.5 > - https: > - a cookiejar > - some forms to be filled in > > what is the best set of modules. > > As far as I understood, there is httplib, but it seems (if I understood > well) to be incoompatible with cookielib > > I'm a newcomer to webautomation with python and would be thankful for > good suggestions. > > I used so far perl with LWP::UserAgent HTTP::Cookies and some module (I > forgot the name) to handle parsing and filling in Forms. > > thanks in advance for any pointers opinions > > N From vriolk at gmail.com Sat Feb 14 05:16:41 2009 From: vriolk at gmail.com (coldpizza) Date: Sat, 14 Feb 2009 02:16:41 -0800 (PST) Subject: best set of modules for web automation without javascript References: <49957df1$0$15145$426a74cc@news.free.fr> Message-ID: <425241d1-6e51-4638-af07-9360cc5d1b24@s20g2000yqh.googlegroups.com> And btw, Selenium scripts can be exported to Python and run under Selenium Remote Control server. I'd say this is the most flexible and advanced way to do webtesting, since you can have a single script that runs with many browsers (opera, firefox, ie, etc), and on many platforms. And combined with HTMLTestRunner you can get beautiful test reports. On Feb 13, 8:01?pm, Matias Surdi wrote: > You should give a look to Selenium. It's great. > > http://www.openqa.org > > > > News123 wrote: > > Hi, > > > I'd like to do some web automation with python 2.5 > > - https: > > - a cookiejar > > - some forms to be filled in > > > what is the best set of modules. > > > As far as I understood, there is httplib, but it seems (if I understood > > well) to be incoompatible with cookielib > > > I'm a newcomer to webautomation with python and would be thankful for > > good suggestions. > > > I used so far perl with LWP::UserAgent HTTP::Cookies and some module (I > > forgot the name) to handle parsing and filling in Forms. > > > thanks in advance for any pointers opinions > > > N > > -- > >http://mail.python.org/mailman/listinfo/python-list From ssj4_dave at hotmail.com Sat Feb 14 06:35:56 2009 From: ssj4_dave at hotmail.com (DLitgo) Date: Sat, 14 Feb 2009 03:35:56 -0800 (PST) Subject: Thank you, Tkinter. (easy to use) References: <766ffd59-b531-4268-88ae-357dc726c67f@33g2000yqm.googlegroups.com> Message-ID: On Feb 12, 12:39?am, r wrote: > Hello, > > Tkinter is a great GUI toolkit, for what it lacks in prettiness it > more than makes up for in simple and quick GUI building. I think this > is the main reason Tkinter continues to be Python's built-in GUI > toolkit. It is a great place to start for those with no GUI > experience. Sure it will never be as rich as wxPython or the like, but > that is not what Tkinter is made for. > > I use Tkinter for all my tools that need a UI, and others as well. The > only complaint i have is the poor support for image types i really > wish there where at least support for one good image like jpg, png, > and full color bitmaps.The canvas widget could also use a little more > functionality, but hey maybe one day i will have time to polish it up > a bit. There is the Python Image Library (PIL), but when I tried to install it I of course had to install the JPEG package as well which didn't install correctly. After trying several times to install it (the JPEG package that is, PIL installed fine, but I only wanted it for the extra image support) I just gave up. Does anyone know of a quick and easy install for PIL + JPEG for Mac OS X (10.5)? From greg.ewing at canterbury.ac.nz Sat Feb 14 06:50:04 2009 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sun, 15 Feb 2009 00:50:04 +1300 Subject: ANN: SuPy 1.2 Message-ID: SuPy 1.2 Available ------------------ http://www.cosc.canterbury.ac.nz/greg.ewing/SuPy/ Changes in this version: - Ruby object and class wrappers now have __class__ and __bases__ attributes that return the right things. As a consequence, isinstance() and issubclass() also work properly on Ruby objects. - UI module made available to Python. - Data in a module can be preserved across a Py.refresh() by giving the module a __keep__ attribute holding a sequence of names to preserve. - Added a utility module to assist with managing menu items. - Fixed some bugs in the block-passing mechanism. What is SuPy? ------------- SuPy is a plugin for the Sketchup 3D modelling application that lets you script it in Python. -- Greg Ewing greg.ewing at canterbury.ac.nz From sammo2828 at gmail.com Sat Feb 14 07:00:39 2009 From: sammo2828 at gmail.com (Sammo) Date: Sat, 14 Feb 2009 04:00:39 -0800 (PST) Subject: String concatenation performance with += References: <2b2d6d33-f43d-4dd0-b881-1f4edb24ad2e@o2g2000prl.googlegroups.com> <01a650bd$0$31512$c3e8da3@news.astraweb.com> Message-ID: <56a6c7a9-fae7-4368-8f59-2aa7b5c8df8c@z6g2000pre.googlegroups.com> On Feb 14, 4:47?pm, Steven D'Aprano wrote: > > Sammo gmail.com> writes: > >> String concatenation has been optimized since 2.3, so using += should > >> be fairly fast. > > > This is implementation dependent and shouldn't be relied upon. > > It's also a fairly simple optimization and really only applies to direct > object access, not items or attributes. > > >> Why is the second test so much slower? > > > Probably several reasons: > > > 1. Function call overhead is quite large compared to these simple > > operations. 2. You are resolving attribute names. > > 3. Because the optimization isn't applied in this case. Thanks Steven -- that's the answer I was looking for. The += string concatenation optimization only applies to local variables. In my case, I incorrectly assumed it applied to attributes. Can you point me to any references regarding the limitations of the optimization? I guess it's another Python idiom that's documented somewhere ... From sammo2828 at gmail.com Sat Feb 14 07:15:19 2009 From: sammo2828 at gmail.com (Sammo) Date: Sat, 14 Feb 2009 04:15:19 -0800 (PST) Subject: String concatenation performance with += References: <2b2d6d33-f43d-4dd0-b881-1f4edb24ad2e@o2g2000prl.googlegroups.com> <748284e0-7e93-4a7a-9511-b6a5e5aaa5ab@w1g2000prk.googlegroups.com> <01a65b61$0$30497$c3e8da3@news.astraweb.com> Message-ID: <69fe8286-a6f9-4cc5-976e-405280e4edb0@z6g2000pre.googlegroups.com> On Feb 14, 5:33?pm, Steven D'Aprano wrote: > > AFAIK, using list mutation and "".join only improves performance if > > the "".join is executed outside of the loop. > > Naturally. If you needlessly join over and over again, instead of delaying > until the end, then you might as well do string concatenation without the > optimization. > > join() isn't some magical function that makes your bugs go away. You have to > use it sensibly. What you've done is a variant of Shlemiel the > road-painter's algorithm: > > http://www.joelonsoftware.com/articles/fog0000000319.html > > Perhaps you have to repeatedly do work on the *temporary* results in between > loops? Something like this toy example? > > s = "" > block = "abcdefghijklmnopqrstuvwxyz"*1000 > for i in xrange(1000): > ? ? s += block > ? ? # do something with the partially concatenated string > ? ? print "partial length is", len(s) > # all finished > do_something(s) > > You've written that using join: > > L = [] > block = "abcdefghijklmnopqrstuvwxyz"*1000 > for i in xrange(1000): > ? ? L.append(block) > ? ? # do something with the partially concatenated string > ? ? L = [ ''.join(L) ] > ? ? print "partial length is", len(L[0]) > # all finished > s = ''.join(L) > do_something(s) > > Okay, but we can re-write that more sensibly: > > L = [] > block = "abcdefghijklmnopqrstuvwxyz"*1000 > for i in xrange(1000): > ? ? L.append(block) > ? ? # do something with the partially concatenated string > ? ? print "partial length is", sum(len(item) for item in L) > # all finished > s = ''.join(L) > do_something(s) > > There's still a Shlemiel algorithm in there, but it's executed in fast C > instead of slow Python and it doesn't involve copying large blocks of > memory, only walking them, so you won't notice as much. Can we be smarter? > > L = [] > block = "abcdefghijklmnopqrstuvwxyz"*1000 > partial_length = 0 > for i in xrange(1000): > ? ? L.append(block) > ? ? partial_length += len(block) > ? ? # do something with the partially concatenated string > ? ? print "partial length is", partial_length > # all finished > s = ''.join(L) > do_something(s) > > Naturally this is a toy example, but I think it illustrates one technique > for avoiding turning an O(N) algorithm into an O(N**2) algorithm. So even though I can't delay the "".join operation until after the loop, I can still improve performance by reducing the length of "".join operations inside the loop. In my case, I need to temporarily work on the latest two blocks only. L = [] block = "abcdefghijklmnopqrstuvwxyz"*1000 for i in xrange(1000): L.append(block) # do something with the latest two blocks tmp = "".join(L[-2:]) # all finished s = ''.join(L) do_something(s) Unfortunately, the downside is that the code becomes more difficult to read compared to using the obvious +=. If only the optimization worked for attributes ... From me at gustavonarea.net Sat Feb 14 07:30:08 2009 From: me at gustavonarea.net (Gustavo Narea) Date: Sat, 14 Feb 2009 04:30:08 -0800 (PST) Subject: Turning a signature-changing decorator into a signature-preserving one References: <6b0518e3-142c-4555-8ad0-02c559f6b224@u13g2000yqg.googlegroups.com> <6b0874ad-4c30-4b3f-a559-f83465d332da@z1g2000yqn.googlegroups.com> Message-ID: <2610ff6e-d487-42e8-a619-aa4db6f9556f@h5g2000yqh.googlegroups.com> On Feb 14, 6:38 am, Michele Simionato wrote: > On Feb 14, 12:56 am, Gustavo Narea wrote: > > > > > Hello, everybody. > > > I have this signature-changing decorator > > > > which I > > want to turn into a signature-preserving one. Here's my try > > , > > but I get > > this error:http://paste.chrisarndt.de/paste/33e06be6e6d74e49b05c45534dfcc9fe?wra... > > > What am I doing wrong? I think it looks like this example:http://pypi.python.org/pypi/decorator#async > > > Thanks in advance. > > > - Gustavo. > > > PS: functols.wrap is not an option because my code has to work with > > Python 2.4+. > > Difficult to see what is happening, since you have so many > dependencies. However, from the traceback I would say that > you are passing to the decorator a function with a __name__ > attribute which is None. I would insert a call to pdb here > > def __call__(self, func): > import pdb; pdb.set_trace() > return decorator(self.call, func) > > and I would inspect func.__name__. > > HTH, > > M.Simionato Thanks for your response, Michele. This is what I get: """ (Pdb) func.__name__ 'greetings' (Pdb) func.__dict__ {} (Pdb) func.__module__ 'pylonsproject.controllers.root' """ Which seems correct to me. By the way, I forgot to mention that what is decorated is an instance method. I don't know if that would change something. Thanks in advance. - Gustavo. From user at domain.invalid Sat Feb 14 07:33:46 2009 From: user at domain.invalid (Canned) Date: Sat, 14 Feb 2009 13:33:46 +0100 Subject: encrypting lines from file with md5 module doesn't work? Message-ID: <4996ba26$0$7834$9a622dc7@news.kpnplanet.nl> Hi, I need some help with my script. I hope someone can show me the right direction or at least explain to me what did I wrong? I write a small script that read lines from plain text file and encrypt each lines using md5 module. I have a small word list that contain 2000+ words, 1 word/line. Using the code below, I can save the output to another file to use it with john the ripper (http://www.openwall.com). Here is the part that annoys me, john recognize the output as des and not as md5. Using the original wordlist, I tried to crack the list but nothing has come up after waiting for almost 9 hours. Can someone please tell me what did I wrong? Why john don't recognize the output as md5? I'm using python 2.5.1 and I'm python noob and also don't have any knowledge about encryption. ----------------code------------------------ import sys, md5 f = open(sys.argv[1]) obj = md5.new() for line in f: if line[-1:] == '\n': text = line[:-1] obj.update(text), print text + ':' + obj.hexdigest() f.close() ---------------result----------------------- 000000:670b14728ad9902aecba32e22fa4f6bd 00000000:c47532bbb1e2883c902071591ae1ec9b 111111:bf874003f752e86e6d6ba6d6df1f24a2 11111111:65a89de3000110bf37bcafdbd33df55a 121212:38a8eeb4dfb0f86aefea908365817c15 123123:f226a65a908909b83aed92661897d0c9 Thanks in advance From zaheer.agadi at gmail.com Sat Feb 14 07:37:57 2009 From: zaheer.agadi at gmail.com (zaheer.agadi at gmail.com) Date: Sat, 14 Feb 2009 04:37:57 -0800 (PST) Subject: Reading a file Message-ID: Hi How do i read a file in Python and search a particular pattern like I have a file char.txt which has Mango=sweet Sky=blue I want to get the strings sweet and blue,How to do this..? Thanks From berend at dotmpe.com Sat Feb 14 08:18:37 2009 From: berend at dotmpe.com (Berend van Berkum) Date: Sat, 14 Feb 2009 14:18:37 +0100 Subject: sgmllib parser keeps old tag data? In-Reply-To: <499594C0.9020509@mrabarnett.plus.com> References: <20090213135803.GB2168@iris.furrow.ath.cx> <4995844C.7080104@mrabarnett.plus.com> <20090213145101.GC2168@iris.furrow.ath.cx> <499594C0.9020509@mrabarnett.plus.com> Message-ID: <20090214131837.GB3799@iris.furrow.ath.cx> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Fri, Feb 13, 2009 at 03:41:52PM +0000, MRAB wrote: > Berend van Berkum wrote: > >Yes.. tested that and SGMLParser won't let me override __init__, > >(SGMLParser vars are uninitialized even with sgmllib.SGMLParser(self) > >call). > > OK, so SGMLParser needs to be initialised: > > def __init__(self): > sgmllib.SGMLParser.__init__(self) > self.content = '' > self.markup = [] > self.span_stack = [] argh.. forgot about old-style supercall syntax used sgmllib.SGMLParser(self), did not investigate the error gonna be ashamed for a while now.. - -- web, http://dotmpe.com () ASCII Ribbon email, berend.van.berkum at gmail.com /\ icq, 26727647; irc, berend/mpe at irc.oftc.net -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFJlsStn70fkTNDJRgRArzdAJ9QhTaIcx0Kgps8rHe0oGnf6qQm+QCeJSh/ +pMOged64wmns1HvoV+u4fA= =O4QU -----END PGP SIGNATURE----- From google at mrabarnett.plus.com Sat Feb 14 09:14:59 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 14 Feb 2009 14:14:59 +0000 Subject: encrypting lines from file with md5 module doesn't work? In-Reply-To: <4996ba26$0$7834$9a622dc7@news.kpnplanet.nl> References: <4996ba26$0$7834$9a622dc7@news.kpnplanet.nl> Message-ID: <4996D1E3.9040304@mrabarnett.plus.com> Canned wrote: > Hi, > I need some help with my script. I hope someone can show me the right > direction or at least explain to me what did I wrong? > > I write a small script that read lines from plain text file and encrypt > each lines using md5 module. I have a small word list that contain 2000+ > words, 1 word/line. Using the code below, I can save the output to > another file to use it with john the ripper (http://www.openwall.com). > [snip] MD5 is a type of checksum, not a method of encryption. From michele.simionato at gmail.com Sat Feb 14 09:27:10 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Sat, 14 Feb 2009 06:27:10 -0800 (PST) Subject: Turning a signature-changing decorator into a signature-preserving one References: <6b0518e3-142c-4555-8ad0-02c559f6b224@u13g2000yqg.googlegroups.com> <6b0874ad-4c30-4b3f-a559-f83465d332da@z1g2000yqn.googlegroups.com> <2610ff6e-d487-42e8-a619-aa4db6f9556f@h5g2000yqh.googlegroups.com> Message-ID: On Feb 14, 1:30?pm, Gustavo Narea wrote: > This is what I get: > """ > (Pdb) func.__name__ > 'greetings' > (Pdb) func.__dict__ > {} > (Pdb) func.__module__ > 'pylonsproject.controllers.root' > """ > > Which seems correct to me. > > By the way, I forgot to mention that what is decorated is an instance > method. I don't know if that would change something. This is bad, func should be a function and not an instance method (see line 49 of decorator.py). If the .signature attribute of the FunctionMaker is missing, than that's the reason for the AssertionError you see. I should probably raise a clearer error message. I lack the context to see how this could be fixed in your case, but this a not a show stopper, you can just keep the original decorator and forget about making it signature preserving. From barry at python.org Sat Feb 14 09:32:43 2009 From: barry at python.org (Barry Warsaw) Date: Sat, 14 Feb 2009 09:32:43 -0500 Subject: [Python-Dev] RELEASED Python 3.0.1 In-Reply-To: References: Message-ID: <30B69D1B-E36B-4FAA-A584-0B892E50A11C@python.org> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Feb 13, 2009, at 11:46 PM, Benjamin Kaplan wrote: > Any chance of getting a Mac installer for this one? I believe Ronald is planning to upload it soon. Barry -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (Darwin) iQCVAwUBSZbWDHEjvBPtnXfVAQJNOQQAl89fJc7ezmpaDlClehtFJTwX5xE7JAtD yZ47O9yUOQfdIem2l1VVApHnsnUmLKILYG3v4MHiWJBjOT10Oxjc4JKlV3nmREda aUYOHCk1aHrPgdLHS4Cb/NBA6uYoG/+fHBcEMujClxv30lUTj76kDcjIMlflcpu6 r9I/jJdYywg= =nyT7 -----END PGP SIGNATURE----- From linuxguy123 at gmail.com Sat Feb 14 09:45:08 2009 From: linuxguy123 at gmail.com (Linuxguy123) Date: Sat, 14 Feb 2009 07:45:08 -0700 Subject: Function name limit in Python ? Message-ID: <1234622708.3786.17.camel@localhost.localdomain> Excuse my ignorance, but is there a limit to the size of function names in Python ? I named a function getSynclientVersion() and I got an error when I called it. I renamed the same function to getSCVersion() and it called fine. Why ? Thanks From sjmachin at lexicon.net Sat Feb 14 09:51:56 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 14 Feb 2009 06:51:56 -0800 (PST) Subject: Problem building Python extension References: <728a0c1c-2808-493c-a2db-c583442d2303@d32g2000yqe.googlegroups.com> Message-ID: <8c2d80db-f948-4221-97a1-9eb0650a8403@r15g2000prh.googlegroups.com> On Feb 14, 7:04?pm, martijnsteenw... at gmail.com wrote: > On 13 feb, 12:45, Christian Heimes wrote: > > > martijnsteenw... at gmail.com wrote: > > > Thanks a lot for your reply. I downloaded & installed Visual C# 2008 > > > express, but unfortunately this doesn't change anything in running the > > > setup file. Unfortunately, still no pyd file is produced... > > > > Did I something wrong? > > > Yeah, you installed the C# environment. Python is written in C, so you > > have to get Visual Studio C++ 2008. However a recent version of MinGW32 > > is sufficient to build most extensions. > > > Christian > > Hi Christian, > > Thanks for your reply. In mean time, I discovered the C++ thing > already ;-). > Now I installed MinGW, but still the same happens. If I run the setup > file, the same output comes on the command line and no pyd file is > created... GRRR > > Any suggestions? AFAIK it will attempt to use a compiler other than the one that Python was compiled with only if specifically directed to e.g. with -- compiler=mingw32 in the command line when running setup.py. From dear.jay.logan at gmail.com Sat Feb 14 10:03:54 2009 From: dear.jay.logan at gmail.com (josh logan) Date: Sat, 14 Feb 2009 07:03:54 -0800 (PST) Subject: how can this iterator be optimized? References: <727aabd1-9682-47aa-88e2-5dde96e4c32e@j1g2000yqi.googlegroups.com> <48b49eef-b3c1-4a9d-bf38-ad24c2b89622@t11g2000yqg.googlegroups.com> Message-ID: On Feb 13, 7:44?pm, Basilisk96 wrote: > On Feb 12, 1:15?am, Steven D'Aprano > > wrote: > > > I usually strive > > > for comprehensions if a for loop can be reduced to such. > > > Any particular reason? > > Only two. > 1.) I was impressed by their clarity and conciseness when I first > discovered them. > 2.) I also read now and then that simple list comprehensions are > faster when compared with their for-loop equivalents because of the > way comprehensions are implemented under the hood. My example is a far > cry from a "simple" comprehension, however. :) > > > If there's only one call to func(), and you ignore the (probably) fixed > > cost of jumping into a generator each time, then it shouldn't make any > > difference. > > > If you are comparing one call to func() in a for loop versus three calls > > to func() in a list comp or generator expression, then of course the for > > loop will be more efficient. > > I agree. I would rather call func() only once per iteration in any > case. I will revise it to a plain for loop with a single call. > > Thanks, > -Basilisk96 Just as long as you do realize that it is possible to do what you were looking with one call to func() using chained generators, as demonstrated in my post above. Whichever way is clearest for you would be the way I'd go. From google at mrabarnett.plus.com Sat Feb 14 10:08:00 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 14 Feb 2009 15:08:00 +0000 Subject: Function name limit in Python ? In-Reply-To: <1234622708.3786.17.camel@localhost.localdomain> References: <1234622708.3786.17.camel@localhost.localdomain> Message-ID: <4996DE50.807@mrabarnett.plus.com> Linuxguy123 wrote: > Excuse my ignorance, but is there a limit to the size of function names > in Python ? > > I named a function getSynclientVersion() and I got an error when I > called it. I renamed the same function to getSCVersion() and it called > fine. > > Why ? > Probably a just spelling mistake. Double-check that the two names are identical. From ptmcg at austin.rr.com Sat Feb 14 10:13:42 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Sat, 14 Feb 2009 07:13:42 -0800 (PST) Subject: Function name limit in Python ? References: Message-ID: On Feb 14, 8:45?am, Linuxguy123 wrote: > Excuse my ignorance, but is there a limit to the size of function names > in Python ? > > I named a function getSynclientVersion() and I got an error when I > called it. ?I renamed the same function to getSCVersion() and it called > fine. > > Why ? > Hello again, Linuxguy123! I see you are forging ahead in your quest for Python knowledge. Here is a small snippet that refutes your assertion that function name length is a problem (but surely, you could have written this small a test and answered your own question...): def getSynclientVersion(): return "1.2.3.4" print getSynclientVersion() prints: 1.2.3.4 Let's try something a bit longer: def abcdefghijklmnopqrstuvwxyz_1234567890_abcdefghijklmnopqrstuvwxyz_1234567890 (): return "Howdy!" print abcdefghijklmnopqrstuvwxyz_1234567890_abcdefghijklmnopqrstuvwxyz_1234567890 () prints: Howdy! So I don't think the problem you are having is the length of your method name. Your quest will be much more productive if, in the future, you post a little more information with these questions: - Post the code that you wrote - this is trickier than it sounds. The best post is the smallest possible extract of your code that reproduces the error in question. But please, DONT try to send in fresh code that you feel represents your problem without first verifying that it does. Many people post a summary of their code because they don't want to post their secret source code, or their 3000 lines of code - and then in their summary, they fix the problem they were having. Then c.l.py readers spend a lot of time going "wha...?" because the posted code has no error. - Post the exception that was returned Probably even more helpful than posting code. What exactly was the problem? Python is not really that bad at giving some informative messages. Perhaps you misspelled your method name: print getSynClientVersion() gives this error: NameError: name 'getSynClientVersion' is not defined It's not defined because I named it "getSynclientVersion" - with a little 'c', not a big 'C'. Or maybe you misused the value returned from the method: print getSynclientVersion().length gives: AttributeError: 'str' object has no attribute 'length' An error, surely, but it has nothing to do with the length of the method name I called. Help us help you, Linuxguy123! -- Paul From ptmcg at austin.rr.com Sat Feb 14 10:19:45 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Sat, 14 Feb 2009 07:19:45 -0800 (PST) Subject: how can this iterator be optimized? References: <727aabd1-9682-47aa-88e2-5dde96e4c32e@j1g2000yqi.googlegroups.com> Message-ID: <2b4e62a9-efa8-4656-98e4-4755a10e7cac@v5g2000pre.googlegroups.com> On Feb 11, 7:22?pm, Basilisk96 wrote: >... > where "func" is a single-argument function that returns either a > string or None, but is an expensive call. > I am pretty sure that the sorted() construct cannot be improved much > further, but... > ...does anyone have ideas on improving the "rawPairs" iterator so that > it calls "func(s)" only once per iteration? ?Perhaps a lambda > construct, but I am not sure how to go about it...? > > Cheers, > Basilisk96 If func is expensive, you could try memoizing it. Then subsequent "calls" just do arg lookups. Michele Simianato has posted a good memoizing decorator on the Python wiki. -- Paul From gyromagnetic at gmail.com Sat Feb 14 10:53:46 2009 From: gyromagnetic at gmail.com (gyro) Date: Sat, 14 Feb 2009 08:53:46 -0700 Subject: confusion about variable scope in a class Message-ID: Hi, I was writing a Python script to perform some data analyses and was surprised by some behavior I noted. A simple test program illustrating the behavior is below. I do not understand why the value of 'data' is being modified. I am obviously missing something obvious, and would certainly appreciate an explanation of why this is happening. Thank you. -gf ---------- #!/bin/env python class TestPop(object): def round1(self,data1): t = data1.pop(-1) def round2(self,data2): t = data2.pop(-1) def tester(self): data = range(10) self.round1(data) print data self.round2(data) print data if __name__ == '__main__': tp = TestPop() tp.tester() From andrew at acooke.org Sat Feb 14 11:22:19 2009 From: andrew at acooke.org (andrew cooke) Date: Sat, 14 Feb 2009 13:22:19 -0300 (CLST) Subject: confusion about variable scope in a class In-Reply-To: References: Message-ID: <524bdbf505d1e37ad0807c8e97087edb.squirrel@acooke.dyndns.org> it's not a scope issue. you are confusing variables and objects. a variable is a box that can hold an object so x = 2 puts the object '2' in the box 'x'. following that with x = '3' changes the box 'x' to hold the object '3'. but lists are also boxes, different from variables. so x = [1,2,3] puts the a list object, that is a box that contains 1, 2 and 3, in 'x' then y = x puts THE SAME list object in box 'y'. then y[1] = 4 changes the second item in the list's box to 4 the print x gives "[1,4,3]" because you have changed contents of the list. in contrast x = 3 then y = x then y = 4 does not change x because you care changing variables, not list contents. to fix your code, you need to copy the list x = [1,2,3] y = list(x) # copy y[1] = 4 print x [1,2,3] surely this is ina faq? it comes up once a day... andrew gyro wrote: > Hi, > I was writing a Python script to perform some data analyses and was > surprised by some behavior I noted. A simple test program illustrating > the behavior is below. > I do not understand why the value of 'data' is being modified. I am > obviously missing something obvious, and would certainly appreciate an > explanation of why this is happening. > > Thank you. > > -gf > > ---------- > > #!/bin/env python > > class TestPop(object): > def round1(self,data1): > t = data1.pop(-1) > > def round2(self,data2): > t = data2.pop(-1) > > def tester(self): > data = range(10) > self.round1(data) > print data > self.round2(data) > print data > > if __name__ == '__main__': > tp = TestPop() > tp.tester() > -- > http://mail.python.org/mailman/listinfo/python-list > > From nagle at animats.com Sat Feb 14 11:27:29 2009 From: nagle at animats.com (John Nagle) Date: Sat, 14 Feb 2009 08:27:29 -0800 Subject: Can Python serial support run at 45.45 baud? Message-ID: <4996e984$0$1657$742ec2ed@news.sonic.net> Can Python's serial port support be made to run at 45.45 baud, the old "60 speed" Teletype machine speed? I've restored a Model 15 teletype from WWII. Works great after cleaning, oiling, and adjustment. There's Perl support for this, and a Perl program ("http://www.buzbee.net/heavymetal") that runs the things. I'd like to do something similar in Python, both on Windows and Linux. I'm proposing to use Python 2.6, PyWin32-212, and PySerial 2.4. The PySerial interface allows requesting a specific baud rate, but does that propagate properly all the way down into Windows? And what about Linux, where the "stty" interface is quite different? John Nagle From nick at craig-wood.com Sat Feb 14 11:32:00 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Sat, 14 Feb 2009 10:32:00 -0600 Subject: String concatenation performance with += References: <2b2d6d33-f43d-4dd0-b881-1f4edb24ad2e@o2g2000prl.googlegroups.com> Message-ID: Sammo wrote: > String concatenation has been optimized since 2.3, so using += should > be fairly fast. > > In my first test, I tried concatentating a 4096 byte string 1000 times > in the following code, and the result was indeed very fast (12.352 ms > on my machine). > > import time > t = time.time() > mydata = "" > moredata = "A"*4096 > for i in range(1000): > mydata += moredata # 12.352 ms > print "%0.3f ms"%(1000*(time.time() - t)) > > However, I got a different result in my second test, which is > implemented in a class with a feed() method. This test took 4653.522 > ms on my machine, which is 350x slower than the previous test! > > class StringConcatTest: > def __init__(self): > self.mydata = "" > > def feed(self, moredata): > self.mydata += moredata # 4653.522 ms > > test = StringConcatTest() > t = time.time() > for i in range(1000): > test.feed(moredata) > print "%0.3f ms"%(1000*(time.time() - t)) > > Note that I need to do something to mydata INSIDE the loop, so please > don't tell me to append moredata to a list and then use "".join after > the loop. > > Why is the second test so much slower? The optimized += depends on their being no other references to the string. Strings are immutable in python. So append must return a new string. However the += operation was optimised to do an in-place append if and only if there are no other references to the string. You can see this demonstrated here $ python -m timeit -s 'a="x"' 'a+="x"' 1000000 loops, best of 3: 0.231 usec per loop $ python -m timeit -s 'a="x"; b=a' 's = a; a+="x"' 100000 loops, best of 3: 30.1 usec per loop You are keeping the extra reference in a class instance like this $ python -m timeit -s 'class A(object): pass' -s 'a=A(); a.a="x"' 'a.a+="x"' 100000 loops, best of 3: 30.7 usec per loop Knowing that, this optimization suggests itself $ python -m timeit -s 'class A(object): pass' -s 'a=A(); a.a="x"' 's = a.a; a.a = None; s += "x"; a.a = s' 1000000 loops, best of 3: 0.954 usec per loop Or in your example class StringConcatTest: def __init__(self): self.mydata = "" def feed(self, moredata): #self.mydata += moredata s = self.mydata del self.mydata s += moredata self.mydata = s moredata = "A"*4096 test = StringConcatTest() t = time.time() for i in range(1000): test.feed(moredata) print "%0.3f ms"%(1000*(time.time() - t)) Before it was 3748.012 ms on my PC, afterwards it was 52.737 ms However that isn't a perfect solution - what if something had another reference on self.mydata? You really want a non-immutable string for this use. array.array is a possibility $ python -m timeit -s 'import array' -s 'a = array.array("c")' 'a.extend("x")' 100000 loops, best of 3: 2.01 usec per loop There are many other possibilities though like the mmap module. -- Nick Craig-Wood -- http://www.craig-wood.com/nick From nick at craig-wood.com Sat Feb 14 11:32:00 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Sat, 14 Feb 2009 10:32:00 -0600 Subject: encrypting lines from file with md5 module doesn't work? References: <4996ba26$0$7834$9a622dc7@news.kpnplanet.nl> Message-ID: Canned wrote: > I write a small script that read lines from plain text file and encrypt > each lines using md5 module. I have a small word list that contain 2000+ > words, 1 word/line. Using the code below, I can save the output to > another file to use it with john the ripper (http://www.openwall.com). > > Here is the part that annoys me, john recognize the output as des and > not as md5. Using the original wordlist, I tried to crack the list but > nothing has come up after waiting for almost 9 hours. Can someone please > tell me what did I wrong? Why john don't recognize the output as md5? > I'm using python 2.5.1 and I'm python noob and also don't have any > knowledge about encryption. > > import sys, md5 > > f = open(sys.argv[1]) > obj = md5.new() > > for line in f: > if line[-1:] == '\n': > text = line[:-1] > obj.update(text), > print text + ':' + obj.hexdigest() > > f.close() > > > 000000:670b14728ad9902aecba32e22fa4f6bd > 00000000:c47532bbb1e2883c902071591ae1ec9b > 111111:bf874003f752e86e6d6ba6d6df1f24a2 > 11111111:65a89de3000110bf37bcafdbd33df55a > 121212:38a8eeb4dfb0f86aefea908365817c15 > 123123:f226a65a908909b83aed92661897d0c9 john cracks password files if I remember rightly. md5 encoded password files don't look like that, they look like this guest:$1$3nvOlOaw$vRWaitT8Ne4sMjf9NOrVZ.:13071:0:99999:7::: (not a real password line!) You need to work out how to write that format. >From memory: the "$1" bit means it is an md5 hash, the next "$3nvOlOaw$" is the salt and the final "$vRWaitT8Ne4sMjf9NOrVZ." is the md5 hash in some encoded format or other! Some googling should reveal the correct algorithm! -- Nick Craig-Wood -- http://www.craig-wood.com/nick From user at domain.invalid Sat Feb 14 11:32:03 2009 From: user at domain.invalid (Canned) Date: Sat, 14 Feb 2009 17:32:03 +0100 Subject: encrypting lines from file with md5 module doesn't work? In-Reply-To: References: <4996ba26$0$7834$9a622dc7@news.kpnplanet.nl> Message-ID: <4996f1ff$0$7833$9a622dc7@news.kpnplanet.nl> MRAB schreef: > Canned wrote: >> Hi, >> I need some help with my script. I hope someone can show me the right >> direction or at least explain to me what did I wrong? >> >> I write a small script that read lines from plain text file and encrypt >> each lines using md5 module. I have a small word list that contain 2000+ >> words, 1 word/line. Using the code below, I can save the output to >> another file to use it with john the ripper (http://www.openwall.com). >> > [snip] > MD5 is a type of checksum, not a method of encryption. I found this from google: http://tinyurl.com/4ow2q4 Using that, I changed my script and it seems that it works well. John recognize it as md5. It also raise another question. John can crack my password from /etc/shadow in less than a second, but if I write it down in a file and using the code below to encrypt the password, john would took really long time to crack the password. I've tried several different password using passwd command and my code to generate md5 hash, but it seems that john really having trouble with hashes generated with my code as the hashes generated with passwd being cracked in a matter of second. Is there something wrong with the code? Am I missing something? -----------------code------------------------- #!/usr/bin/env python import sys import md5encrypt # from http://tinyurl.com/4ow2q4 f = open(sys.argv[1]) for line in f: if line[-1:] == '\n': text = line[:-1] print text + ':' + md5encrypt.md5crypt(text, md5encrypt.generate_salt(5)) f.close() ---------------password.txt-------------------- 000000 00000000 111111 11111111 121212 123123 -------------result.txt----------------- 000000:$1$ Message-ID: <-rednU9RmNnrbwvUnZ2dnUVZ_sHinZ2d@posted.usinternet> On 2009-02-14, John Nagle wrote: > Can Python's serial port support be made to run at 45.45 baud, > the old "60 speed" Teletype machine speed? If your hardware and OS supports it, Python can be made to support it. > I've restored a Model 15 teletype from WWII. Fun. I worked with one of those in school back in the day. > Works great after cleaning, oiling, and adjustment. There's > Perl support for this, and a Perl program > ("http://www.buzbee.net/heavymetal") that runs the things. I'd > like to do something similar in Python, both on Windows and > Linux. OK, go ahead. > I'm proposing to use Python 2.6, PyWin32-212, and PySerial > 2.4. The PySerial interface allows requesting a specific baud > rate, but does that propagate properly all the way down into > Windows? Good question. Since you're the one with the hardware, you'll have to tell us. If it doesn't work, it should be trivial to fix. Just tell us what mechanism is used by Perl, and we'll either fix pyserial or tell you how to do so. > And what about Linux, where the "stty" interface is quite > different? Same answer. -- Grant From deets at nospam.web.de Sat Feb 14 11:37:07 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 14 Feb 2009 17:37:07 +0100 Subject: confusion about variable scope in a class In-Reply-To: References: Message-ID: <6voa9mFku543U1@mid.uni-berlin.de> gyro schrieb: > Hi, > I was writing a Python script to perform some data analyses and was > surprised by some behavior I noted. A simple test program illustrating > the behavior is below. > I do not understand why the value of 'data' is being modified. I am > obviously missing something obvious, and would certainly appreciate an > explanation of why this is happening. Lists are mutables, and python passes around references to objects, not copies. So if you want a copy, you need to create one explicit, either by using e.g. new_list = list(old_list) which will create a shollow copy of the list, or by using the library-module "copy" that also offers a "deepcopy" function. Diez From google at mrabarnett.plus.com Sat Feb 14 11:56:00 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 14 Feb 2009 16:56:00 +0000 Subject: Can Python serial support run at 45.45 baud? In-Reply-To: <-rednU9RmNnrbwvUnZ2dnUVZ_sHinZ2d@posted.usinternet> References: <4996e984$0$1657$742ec2ed@news.sonic.net> <-rednU9RmNnrbwvUnZ2dnUVZ_sHinZ2d@posted.usinternet> Message-ID: <4996F7A0.4060008@mrabarnett.plus.com> Grant Edwards wrote: > On 2009-02-14, John Nagle wrote: > >> Can Python's serial port support be made to run at 45.45 baud, >> the old "60 speed" Teletype machine speed? > > If your hardware and OS supports it, Python can be made to > support it. > [snip] I had a quick look at the Windows API. The struct member for the baud rate is of type DWORD, ie an integer. From marduk at letterboxes.org Sat Feb 14 11:57:17 2009 From: marduk at letterboxes.org (Albert Hopkins) Date: Sat, 14 Feb 2009 11:57:17 -0500 Subject: Function name limit in Python ? In-Reply-To: <1234622708.3786.17.camel@localhost.localdomain> References: <1234622708.3786.17.camel@localhost.localdomain> Message-ID: <1234630637.7402.0.camel@centar.nbk> On Sat, 2009-02-14 at 07:45 -0700, Linuxguy123 wrote: > Excuse my ignorance, but is there a limit to the size of function names > in Python ? > > I named a function getSynclientVersion() and I got an error when I > called it. You forgot to paste the error. From user at domain.invalid Sat Feb 14 11:57:30 2009 From: user at domain.invalid (Canned) Date: Sat, 14 Feb 2009 17:57:30 +0100 Subject: encrypting lines from file with md5 module doesn't work? In-Reply-To: References: <4996ba26$0$7834$9a622dc7@news.kpnplanet.nl> Message-ID: <4996f7f6$0$7827$9a622dc7@news.kpnplanet.nl> Nick Craig-Wood schreef: > Canned wrote: >> I write a small script that read lines from plain text file and encrypt >> each lines using md5 module. I have a small word list that contain 2000+ >> words, 1 word/line. Using the code below, I can save the output to >> another file to use it with john the ripper (http://www.openwall.com). >> >> Here is the part that annoys me, john recognize the output as des and >> not as md5. Using the original wordlist, I tried to crack the list but >> nothing has come up after waiting for almost 9 hours. Can someone please >> tell me what did I wrong? Why john don't recognize the output as md5? >> I'm using python 2.5.1 and I'm python noob and also don't have any >> knowledge about encryption. >> >> import sys, md5 >> >> f = open(sys.argv[1]) >> obj = md5.new() >> >> for line in f: >> if line[-1:] == '\n': >> text = line[:-1] >> obj.update(text), >> print text + ':' + obj.hexdigest() >> >> f.close() >> >> >> 000000:670b14728ad9902aecba32e22fa4f6bd >> 00000000:c47532bbb1e2883c902071591ae1ec9b >> 111111:bf874003f752e86e6d6ba6d6df1f24a2 >> 11111111:65a89de3000110bf37bcafdbd33df55a >> 121212:38a8eeb4dfb0f86aefea908365817c15 >> 123123:f226a65a908909b83aed92661897d0c9 > > john cracks password files if I remember rightly. > > md5 encoded password files don't look like that, they look like this > > guest:$1$3nvOlOaw$vRWaitT8Ne4sMjf9NOrVZ.:13071:0:99999:7::: > > (not a real password line!) > > You need to work out how to write that format. > Yes, I'm aware of that format and john only need the first 2 fields to work with, and the rest, AFAIK is ignored. So the format from my example should be: 000000:$1$670b14728ad9902aecba32e22fa4f6bd > From memory: the "$1" bit means it is an md5 hash, the next > "$3nvOlOaw$" is the salt and the final "$vRWaitT8Ne4sMjf9NOrVZ." is > the md5 hash in some encoded format or other! Some googling should > reveal the correct algorithm! > Googling around, I found a piece of code that could do that. http://tinyurl.com/4ow2q4. Please read my another post about that. I'm not python expert and I have a little knowledge about encryption. From Bryan.Fodness at gmail.com Sat Feb 14 11:57:46 2009 From: Bryan.Fodness at gmail.com (Bryan.Fodness at gmail.com) Date: Sat, 14 Feb 2009 08:57:46 -0800 (PST) Subject: Extract an image from a RTF file Message-ID: I have a large amount of RTF files where the only thing in them is an image. I would like to extract them an save them as a png. Eventually, I would like to also grab some text that is on the image. I think PIL has something for this. Does anyone have any suggestion on how to start this? From deets at nospam.web.de Sat Feb 14 12:14:11 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 14 Feb 2009 18:14:11 +0100 Subject: Easier to wrap C or C++ libraries? In-Reply-To: <7baacd31-58c8-4e11-b25a-f827cc63d6ac@e18g2000yqo.googlegroups.com> References: <7baacd31-58c8-4e11-b25a-f827cc63d6ac@e18g2000yqo.googlegroups.com> Message-ID: <6vocf5Fkv5a9U1@mid.uni-berlin.de> argo785 at gmail.com schrieb: > When creating a Python binding to a C or C++ library, which is easier > to wrap, the C lib or the C++ one? Given a choice, if you had to > choose between using one of two libs, one written in C, the other in C+ > + -- both having approximately the same functionality -- which would > you rather deal with from your Python code? > > It would seem to me that there's fewer design considerations when > wrapping a library written in C; you just wrap the functions. However, > since Python supports OOP nicely, it might also be that wrapping C++ > code *could* also be staightforward... Are there many pitfalls when > having to map C++'s notion of OO to Python? The answer is easy: if you use C, you can use ctypes to create a wrapper - with pure python, no compilation, no platform issues. Which IMHO makes a strong point for C - if you need OO, it's bolted on easily using Python itself, by creating some nice wrapper classes. Diez From ronaldoussoren at mac.com Sat Feb 14 12:16:58 2009 From: ronaldoussoren at mac.com (Ronald Oussoren) Date: Sat, 14 Feb 2009 18:16:58 +0100 Subject: [Python-Dev] RELEASED Python 3.0.1 In-Reply-To: <49968713.4080705@v.loewis.de> References: <49968713.4080705@v.loewis.de> Message-ID: <7B96CE20-80E9-47DF-9C14-A542E47F0017@mac.com> On 14 Feb, 2009, at 9:55, Martin v. L?wis wrote: >> Any chance of getting a Mac installer for this one? > > Chances are non-zero, yes. I had hoped to build one last night, but got home way later than I had planned. The installer is building as I type this. Ronald -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2224 bytes Desc: not available URL: From orpap at nus.edu.sg Sat Feb 14 12:31:10 2009 From: orpap at nus.edu.sg (Ajith Prasad) Date: Sat, 14 Feb 2009 09:31:10 -0800 (PST) Subject: Financial Modeling in Python Message-ID: http://as.wiley.com/WileyCDA/WileyTitle/productCd-0470987847.html now lists the contents of a new book: Financial Modeling in Python Shayne Fletcher, Christopher Gardner ISBN: 978-0-470-98784-1 Hardcover 280 pages August 2009 Wiley List Price: US $130.00 From tjreedy at udel.edu Sat Feb 14 12:33:53 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 Feb 2009 12:33:53 -0500 Subject: Thank you, Tkinter. (easy to use) In-Reply-To: References: <766ffd59-b531-4268-88ae-357dc726c67f@33g2000yqm.googlegroups.com> Message-ID: DLitgo wrote: > Does anyone know of a quick and easy install for > PIL + JPEG for Mac OS X (10.5)? If you don't get an answer, try a thread with the above as the title. There may be a python-mac list somewhere too. From tjreedy at udel.edu Sat Feb 14 12:45:44 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 Feb 2009 12:45:44 -0500 Subject: Reading a file In-Reply-To: References: Message-ID: zaheer.agadi at gmail.com wrote: > Hi > > How do i read a file in Python and search a particular pattern > like I have a file char.txt which has > > Mango=sweet > Sky=blue > > I want to get the strings sweet and blue,How to do this..? for line in open('char.txt'): if line.find('sweet') != -1 or line.find('blue') != -1: print(line) Read the section of the Lib Manual on string methods. From tjreedy at udel.edu Sat Feb 14 13:01:57 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 Feb 2009 13:01:57 -0500 Subject: Extract an image from a RTF file In-Reply-To: References: Message-ID: Bryan.Fodness at gmail.com wrote: > I have a large amount of RTF files where the only thing in them is an > image. I would like to extract them an save them as a png. > Eventually, I would like to also grab some text that is on the image. > I think PIL has something for this. > > Does anyone have any suggestion on how to start this? Wikepedia Rich Text Format has several links, which lead to http://pyrtf.sourceforge.net/ http://code.google.com/p/pyrtf-ng/ The former says rtf generation, including images. The latter says rtf generation and parsing, but only claims to be a rewrite of the former. From aahz at pythoncraft.com Sat Feb 14 13:05:01 2009 From: aahz at pythoncraft.com (Aahz) Date: 14 Feb 2009 10:05:01 -0800 Subject: How to debug deadlock? References: Message-ID: In article , Victor Lin wrote: > >I am developing a multi-threading application, I encounter a deadlock. >I use Visual C++ Express 2008 to trace the program. Once the deadlock >occurs, I just pause the program and trace. I found that when deadlock >occurs, there will be two threads called python from my C++ extension. >All of them use Queue in python code, so I guess the deadlock might >caused by Queue. But however, once the extension goes into python >code, I can't see nothing but asm code and binary from the VC++ >debugger. I would like to know are there any way to dump the call >stack of python code after I paused the program? And how can I know >what lock are there in threads caused the deadlock? You are already hosed if you have two threads calling into Python, because you didn't properly acquire the GIL. I can't help beyond that; try using the mailing list http://mail.python.org/mailman/listinfo/capi-sig -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From google at mrabarnett.plus.com Sat Feb 14 13:07:20 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 14 Feb 2009 18:07:20 +0000 Subject: Can Python serial support run at 45.45 baud? In-Reply-To: <49970561$0$1642$742ec2ed@news.sonic.net> References: <4996e984$0$1657$742ec2ed@news.sonic.net> <-rednU9RmNnrbwvUnZ2dnUVZ_sHinZ2d@posted.usinternet> <49970561$0$1642$742ec2ed@news.sonic.net> Message-ID: <49970858.3070005@mrabarnett.plus.com> John Nagle wrote: > Grant Edwards wrote: >> On 2009-02-14, John Nagle wrote: >> >>> Can Python's serial port support be made to run at 45.45 baud, >>> the old "60 speed" Teletype machine speed? >> >> If your hardware and OS supports it, Python can be made to >> support it. > > OK, tried to open the port, using Python 2.6, latest PySerial > and PyWin32: > > ser = serial.Serial(port, baudrate=baud, > bytesize=serial.FIVEBITS, > parity=serial.PARITY_NONE, > stopbits=serial.STOPBITS_TWO) > > Traceback (most recent call last): > File "serialtest.py", line 27, in > main() > File "serialtest.py", line 24, in main > ser = openportbaudot(0,45.45) > File "serialtest.py", line 17, in openportbaudot > stopbits=serial.STOPBITS_TWO) > File "D:\python26\lib\site-packages\serial\serialutil.py", line 171, > in __init__ > self.open() > File "D:\python26\lib\site-packages\serial\serialwin32.py", line 63, > in open > self._reconfigurePort() > File "D:\python26\lib\site-packages\serial\serialwin32.py", line 171, > in _reconfigurePort > raise ValueError("Cannot configure port, some setting was wrong. > Original message: %s" % e) > ValueError: Cannot configure port, some setting was wrong. Original > message: (87, 'SetCommState', 'The parameter is incorrect.') > > Something doesn't like "serial.FIVEBITS". That's a valid value, > according > to "http://pyserial.wiki.sourceforge.net/pySerial". If changed to > "serial.EIGHTBITS", the code will execute, but of course does the wrong > thing. That looks like a bug. > > I tried various values for "baud". PySerial will accept "45", and > even "45.45", although I doubt that it's really calculating the serial > port divisor > values from a floating point value. (Standard serial port hardware can do > 45.45 baud, and most PCs with non-USB serial ports will do it quite well.) > For my application, 45 baud should work, with two stop bits; the > tolerances aren't that tight. > I don't think it's a Python bug. The MSDN website says this: (http://msdn.microsoft.com/en-us/library/aa363214(VS.85).aspx.) When a DCB structure is used to configure the 8250, the following restrictions apply to the values specified for the ByteSize and StopBits members: * The number of data bits must be 5 to 8 bits. * The use of 5 data bits with 2 stop bits is an invalid combination, as is 6, 7, or 8 data bits with 1.5 stop bits. From nagle at animats.com Sat Feb 14 13:26:22 2009 From: nagle at animats.com (John Nagle) Date: Sat, 14 Feb 2009 10:26:22 -0800 Subject: Can Python serial support run at 45.45 baud? In-Reply-To: <-rednU9RmNnrbwvUnZ2dnUVZ_sHinZ2d@posted.usinternet> References: <4996e984$0$1657$742ec2ed@news.sonic.net> <-rednU9RmNnrbwvUnZ2dnUVZ_sHinZ2d@posted.usinternet> Message-ID: <49970561$0$1642$742ec2ed@news.sonic.net> Grant Edwards wrote: > On 2009-02-14, John Nagle wrote: > >> Can Python's serial port support be made to run at 45.45 baud, >> the old "60 speed" Teletype machine speed? > > If your hardware and OS supports it, Python can be made to > support it. OK, tried to open the port, using Python 2.6, latest PySerial and PyWin32: ser = serial.Serial(port, baudrate=baud, bytesize=serial.FIVEBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_TWO) Traceback (most recent call last): File "serialtest.py", line 27, in main() File "serialtest.py", line 24, in main ser = openportbaudot(0,45.45) File "serialtest.py", line 17, in openportbaudot stopbits=serial.STOPBITS_TWO) File "D:\python26\lib\site-packages\serial\serialutil.py", line 171, in __init__ self.open() File "D:\python26\lib\site-packages\serial\serialwin32.py", line 63, in open self._reconfigurePort() File "D:\python26\lib\site-packages\serial\serialwin32.py", line 171, in _reconfigurePort raise ValueError("Cannot configure port, some setting was wrong. Original message: %s" % e) ValueError: Cannot configure port, some setting was wrong. Original message: (87, 'SetCommState', 'The parameter is incorrect.') Something doesn't like "serial.FIVEBITS". That's a valid value, according to "http://pyserial.wiki.sourceforge.net/pySerial". If changed to "serial.EIGHTBITS", the code will execute, but of course does the wrong thing. That looks like a bug. I tried various values for "baud". PySerial will accept "45", and even "45.45", although I doubt that it's really calculating the serial port divisor values from a floating point value. (Standard serial port hardware can do 45.45 baud, and most PCs with non-USB serial ports will do it quite well.) For my application, 45 baud should work, with two stop bits; the tolerances aren't that tight. John Nagle From google at mrabarnett.plus.com Sat Feb 14 13:48:56 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 14 Feb 2009 18:48:56 +0000 Subject: Can Python serial support run at 45.45 baud? In-Reply-To: <49970ce7$0$1665$742ec2ed@news.sonic.net> References: <4996e984$0$1657$742ec2ed@news.sonic.net> <-rednU9RmNnrbwvUnZ2dnUVZ_sHinZ2d@posted.usinternet> <49970561$0$1642$742ec2ed@news.sonic.net> <49970ce7$0$1665$742ec2ed@news.sonic.net> Message-ID: <49971218.2000403@mrabarnett.plus.com> John Nagle wrote: > John Nagle wrote: > >> OK, tried to open the port, using Python 2.6, latest PySerial >> and PyWin32: >> >> ser = serial.Serial(port, baudrate=baud, >> bytesize=serial.FIVEBITS, >> parity=serial.PARITY_NONE, >> stopbits=serial.STOPBITS_TWO) >> >> ValueError: Cannot configure port, some setting was wrong. Original >> message: (87, 'SetCommState', 'The parameter is incorrect.') >> >> Something doesn't like "serial.FIVEBITS". That's a valid value, >> according >> to "http://pyserial.wiki.sourceforge.net/pySerial". If changed to >> "serial.EIGHTBITS", the code will execute, but of course does the wrong >> thing. That looks like a bug. > > OK, here's what's wrong. The allowed numbers for stop bits in > Windows are > > ONESTOPBIT 0 1 stop bit. > ONE5STOPBITS 1 1.5 stop bits. > TWOSTOPBITS 2 2 stop bits. > > The Python interface, however, only exports STOPBITS_ONE and STOPBITS_TWO. > See "serialutil.py", at line 9, and "serialwin32.py" at lines 141-146. > > Microsoft documentation > ("http://msdn.microsoft.com/en-us/library/aa363214(VS.85).aspx") says: > > * The use of 5 data bits with 2 stop bits is an invalid combination, > as is 6, 7, or 8 data bits with 1.5 stop bits. > > So the correct combination, 5 bits with 1.5 stop bits, isn't supported in > Python. 1 stop bit will not physically work on Baudot teletypes; the > main camshaft doesn't come around fast enough. (Yes, there's an actual > mechanical reason for 1.5 stop bits.) Requesting 2 stop bits at the > Python level gets a reject at the Win32 level. (Not sure why Win32 > doesn't allow that; extra stop bits just add delay, but don't hurt > anything. But it's not supported.) > > Linux has a different set of restrictions; Linux offers only 1 or 2 stop > bits, and won't do arbitrary baud rates via the "termios" data structure, > although there are other ways to request that. At the hardware level, > there's a clock rate, a counter, and a divisor, so arbitrary baud > rates can be set. > If 5+2 is invalid, could you work around it with 6+1 instead (one of the data bits masquerading as a stop bit)? Presumably the device on the other end won't care as long as it gets the bits it expects... From google at mrabarnett.plus.com Sat Feb 14 13:53:12 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 14 Feb 2009 18:53:12 +0000 Subject: Can Python serial support run at 45.45 baud? In-Reply-To: <49970ce7$0$1665$742ec2ed@news.sonic.net> References: <4996e984$0$1657$742ec2ed@news.sonic.net> <-rednU9RmNnrbwvUnZ2dnUVZ_sHinZ2d@posted.usinternet> <49970561$0$1642$742ec2ed@news.sonic.net> <49970ce7$0$1665$742ec2ed@news.sonic.net> Message-ID: <49971318.4090208@mrabarnett.plus.com> John Nagle wrote: [snip] > So the correct combination, 5 bits with 1.5 stop bits, isn't supported in > Python. 1 stop bit will not physically work on Baudot teletypes; the > main camshaft doesn't come around fast enough. (Yes, there's an actual > mechanical reason for 1.5 stop bits.) Requesting 2 stop bits at the > Python level gets a reject at the Win32 level. (Not sure why Win32 > doesn't allow that; extra stop bits just add delay, but don't hurt > anything. But it's not supported.) > I forgot to add that what Windows allows depends on what the hardware (the serial chip) allows: the MSDN webpage mentions that the DCB struct configures the 8250. From nagle at animats.com Sat Feb 14 13:59:28 2009 From: nagle at animats.com (John Nagle) Date: Sat, 14 Feb 2009 10:59:28 -0800 Subject: Can Python serial support run at 45.45 baud? In-Reply-To: <49970561$0$1642$742ec2ed@news.sonic.net> References: <4996e984$0$1657$742ec2ed@news.sonic.net> <-rednU9RmNnrbwvUnZ2dnUVZ_sHinZ2d@posted.usinternet> <49970561$0$1642$742ec2ed@news.sonic.net> Message-ID: <49970ce7$0$1665$742ec2ed@news.sonic.net> John Nagle wrote: > OK, tried to open the port, using Python 2.6, latest PySerial > and PyWin32: > > ser = serial.Serial(port, baudrate=baud, > bytesize=serial.FIVEBITS, > parity=serial.PARITY_NONE, > stopbits=serial.STOPBITS_TWO) > > ValueError: Cannot configure port, some setting was wrong. Original > message: (87, 'SetCommState', 'The parameter is incorrect.') > > Something doesn't like "serial.FIVEBITS". That's a valid value, > according > to "http://pyserial.wiki.sourceforge.net/pySerial". If changed to > "serial.EIGHTBITS", the code will execute, but of course does the wrong > thing. That looks like a bug. OK, here's what's wrong. The allowed numbers for stop bits in Windows are ONESTOPBIT 0 1 stop bit. ONE5STOPBITS 1 1.5 stop bits. TWOSTOPBITS 2 2 stop bits. The Python interface, however, only exports STOPBITS_ONE and STOPBITS_TWO. See "serialutil.py", at line 9, and "serialwin32.py" at lines 141-146. Microsoft documentation ("http://msdn.microsoft.com/en-us/library/aa363214(VS.85).aspx") says: * The use of 5 data bits with 2 stop bits is an invalid combination, as is 6, 7, or 8 data bits with 1.5 stop bits. So the correct combination, 5 bits with 1.5 stop bits, isn't supported in Python. 1 stop bit will not physically work on Baudot teletypes; the main camshaft doesn't come around fast enough. (Yes, there's an actual mechanical reason for 1.5 stop bits.) Requesting 2 stop bits at the Python level gets a reject at the Win32 level. (Not sure why Win32 doesn't allow that; extra stop bits just add delay, but don't hurt anything. But it's not supported.) Linux has a different set of restrictions; Linux offers only 1 or 2 stop bits, and won't do arbitrary baud rates via the "termios" data structure, although there are other ways to request that. At the hardware level, there's a clock rate, a counter, and a divisor, so arbitrary baud rates can be set. John Nagle From roy at panix.com Sat Feb 14 14:10:39 2009 From: roy at panix.com (Roy Smith) Date: Sat, 14 Feb 2009 14:10:39 -0500 Subject: Can Python serial support run at 45.45 baud? References: <4996e984$0$1657$742ec2ed@news.sonic.net> <-rednU9RmNnrbwvUnZ2dnUVZ_sHinZ2d@posted.usinternet> <49970561$0$1642$742ec2ed@news.sonic.net> <49970ce7$0$1665$742ec2ed@news.sonic.net> Message-ID: In article <49970ce7$0$1665$742ec2ed at news.sonic.net>, John Nagle wrote: > At the hardware level, there's a clock rate, a counter, and a divisor, > so arbitrary baud rates can be set. Is that really true of modern hardware? The last time I looked at serial port hardware, UARTs took a base clock rate and divided it sequentially with flip-flops to get all the possible rates (they usually had some ugly logic to generate 110). You were limited to the specific rates the hardware gave you. Is that no longer the case? From curt.hash at gmail.com Sat Feb 14 14:15:49 2009 From: curt.hash at gmail.com (Curt Hash) Date: Sat, 14 Feb 2009 12:15:49 -0700 Subject: Extract an image from a RTF file In-Reply-To: References: Message-ID: <736698790902141115i5c109300xc9193ed33e973c8b@mail.gmail.com> On Sat, Feb 14, 2009 at 11:01 AM, Terry Reedy wrote: > > Bryan.Fodness at gmail.com wrote: >> >> I have a large amount of RTF files where the only thing in them is an >> image. I would like to extract them an save them as a png. >> Eventually, I would like to also grab some text that is on the image. >> I think PIL has something for this. >> >> Does anyone have any suggestion on how to start this? > > Wikepedia Rich Text Format has several links, which lead to > http://pyrtf.sourceforge.net/ > http://code.google.com/p/pyrtf-ng/ > The former says rtf generation, including images. > The latter says rtf generation and parsing, but only claims to be a rewrite of the former. > > -- > http://mail.python.org/mailman/listinfo/python-list I've written an RTF parser in Python before, but for the purpose of filtering and discarding content rather than extracting it. Take a look at the specification here: http://www.microsoft.com/downloads/details.aspx?familyid=dd422b8d-ff06-4207-b476-6b5396a18a2b&displaylang=en You will find that images are specified by one or more RTF control words followed by a long string of hex data. For this special purpose, you will not need to write a parser for the entire specification. Just search the file for the correct sequence of control words, extract the hex data that follows, and save it to a file. It helps if you open the RTF document in a text editor and locate the specific control group that contains the image, as the format and order of control words varies depending on the application that created it. If all of your documents are created with the same application, it will be much easier. From argo785 at gmail.com Sat Feb 14 14:37:01 2009 From: argo785 at gmail.com (argo785 at gmail.com) Date: Sat, 14 Feb 2009 11:37:01 -0800 (PST) Subject: Easier to wrap C or C++ libraries? References: <7baacd31-58c8-4e11-b25a-f827cc63d6ac@e18g2000yqo.googlegroups.com> <6vocf5Fkv5a9U1@mid.uni-berlin.de> Message-ID: <5079b2c4-2dae-484b-96b3-78dedd9b071d@z6g2000pre.googlegroups.com> On Feb 14, 12:14?pm, "Diez B. Roggisch" wrote: > > The answer is easy: if you use C, you can use ctypes to create a wrapper > - with pure python, no compilation, no platform issues. > > Which IMHO makes a strong point for C - if you need OO, it's bolted on > easily using Python itself, by creating some nice wrapper classes. > Thanks for the replies, everyone. After posting I went back and reviewed some of my old C books as well as the C++ ones. It's interesting and instructive to look back at C++ after you've used languages like Python for a while. I'd forgotten how complicated C++ code can get. From hniksic at xemacs.org Sat Feb 14 14:49:45 2009 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Sat, 14 Feb 2009 20:49:45 +0100 Subject: Easier to wrap C or C++ libraries? References: <7baacd31-58c8-4e11-b25a-f827cc63d6ac@e18g2000yqo.googlegroups.com> <6vocf5Fkv5a9U1@mid.uni-berlin.de> Message-ID: <87vdrciysm.fsf@mulj.homelinux.net> "Diez B. Roggisch" writes: > The answer is easy: if you use C, you can use ctypes to create a > wrapper - with pure python, no compilation, no platform issues. The last part is not true. ctypes doesn't work on 64-bit architectures, nor does it work when Python is built with non-gcc Unix compilers. From tripplowe at gmail.com Sat Feb 14 15:06:14 2009 From: tripplowe at gmail.com (tripp) Date: Sat, 14 Feb 2009 12:06:14 -0800 (PST) Subject: Fortran array in python (f2py?)... References: <42cda6f6-eaa2-44d9-be39-443fcc460806@o36g2000yqh.googlegroups.com> Message-ID: OK. It sounds like it would be easiest for me, then, to dump the arrays to a binary file (much faster than dumping it to a text) from the fortran program. Then use f2py to load a fortran module to read it.?. How well does python handle binary files? Maybe I could skit the f2py all together if I can get python to read the fortran binary file... -TLowe From lists at cheimes.de Sat Feb 14 15:08:45 2009 From: lists at cheimes.de (Christian Heimes) Date: Sat, 14 Feb 2009 21:08:45 +0100 Subject: Easier to wrap C or C++ libraries? In-Reply-To: <87vdrciysm.fsf@mulj.homelinux.net> References: <7baacd31-58c8-4e11-b25a-f827cc63d6ac@e18g2000yqo.googlegroups.com> <6vocf5Fkv5a9U1@mid.uni-berlin.de> <87vdrciysm.fsf@mulj.homelinux.net> Message-ID: Hrvoje Niksic schrieb: > "Diez B. Roggisch" writes: > >> The answer is easy: if you use C, you can use ctypes to create a >> wrapper - with pure python, no compilation, no platform issues. > > The last part is not true. ctypes doesn't work on 64-bit > architectures, nor does it work when Python is built with non-gcc Unix > compilers ctypes works on 64bit systems, too. However it's a pain in the ... back to write code with ctypes that works across all platforms. I used to use ctypes for wrapper but eventually I switched to Cython. Christian From kwmsmith at gmail.com Sat Feb 14 15:34:18 2009 From: kwmsmith at gmail.com (Kurt Smith) Date: Sat, 14 Feb 2009 14:34:18 -0600 Subject: Fortran array in python (f2py?)... In-Reply-To: References: <42cda6f6-eaa2-44d9-be39-443fcc460806@o36g2000yqh.googlegroups.com> Message-ID: On Sat, Feb 14, 2009 at 2:06 PM, tripp wrote: > OK. It sounds like it would be easiest for me, then, to dump the > arrays to a binary file (much faster than dumping it to a text) from > the fortran program. Then use f2py to load a fortran module to read > it.?. I've done something similar and have written some wrapper functions (in pure python) that read in fortran binary arrays and puts them into a numpy array. You have to deal with fortran records, which (for the fortran compiler I'm using) puts a 4-byte record length indicator at the beginning and end of each record, with the raw binary data between. The issue is mildly complicated if you have to deal with endianness incompatibilites between computers. IIRC, the format of the records is compiler dependent, although I've found that gfortran, g77 and xlfortran are consistent with each other. If you like I'd be happy to send you the code. Kurt -------------- next part -------------- An HTML attachment was scrubbed... URL: From Scott.Daniels at Acm.Org Sat Feb 14 15:39:33 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 14 Feb 2009 12:39:33 -0800 Subject: Fortran array in python (f2py?)... In-Reply-To: References: <42cda6f6-eaa2-44d9-be39-443fcc460806@o36g2000yqh.googlegroups.com> Message-ID: tripp wrote: > ... dump the arrays to a binary file (much faster than dumping it to a text) > from the fortran program.... > > How well does python handle binary files? Maybe I could skit the f2py > all together if I can get python to read the fortran binary file... Likely your best plan. Look into the numpy external package, because those arrays are _far_ superior for actual calculation. With numpy you can do array_1 + array_2 without requiring a Python loop. I'm sure it has a way to read in binary arrays of the various data types. --Scott David Daniels Scott.Daniels at Acm.Org From zubeido at yahoo.com.br Sat Feb 14 15:46:25 2009 From: zubeido at yahoo.com.br (aiwarrior) Date: Sat, 14 Feb 2009 12:46:25 -0800 (PST) Subject: Rapidshare to Megaupload script Message-ID: I've made this script and would like to have some input and share it with the community. I also have a page with some code i produce on my spare time. http://pneves.net Thanks # -*- coding: utf-8 -*- ## I Paulo Neves am the owner of this script and i do not allow the copy or distribution ## of this script without my permission to commercial purposes ## If you have any suggestions please mail me and i will reply and post the on the site from __future__ import with_statement from urlparse import urljoin import urllib2, urllib import os, sys import re import ConfigParser urls = [] acc_details = 0 firs_run = 0 def from_rapidshare(url): '''Check if this is a rapidshare link''' return (url.startswith("rapidshare.com") or url.startswith("www.rapidshare.com") or url.startswith("http://rapidshare.com") or url.startswith("http://www.rapidshare.com")) def account_details(): if os.environ.has_key("APPDATA") and os.path.exists(os.environ ["APPDATA"]): path = os.environ["APPDATA"] + "\\murs.cfg" else: path = os.path.expanduser("~") + "\.murs.cfg" if not os.path.exists(path): print path m_user = raw_input("Enter your user name for megaupload: ") m_password = raw_input("Enter your password for megaupload: ") r_user = raw_input("Enter your user name for rapidshare: ") r_password = raw_input("Enter your password for rapidshare: ") cfg = ConfigParser.SafeConfigParser() cfg.add_section('Acc_Details') cfg.set('Acc_Details', 'm_user ', m_user) cfg.set('Acc_Details', 'm_password', m_password) cfg.set('Acc_Details', 'r_user', r_user) cfg.set('Acc_Details', 'r_password', r_password) with open(path, 'wb') as configfile: cfg.write(configfile) cfg = ConfigParser.SafeConfigParser() cfg.read(path) try: m_user = cfg.get("Acc_Details", "m_user") m_password = cfg.get("Acc_Details", "m_password") r_user = cfg.get("Acc_Details", "r_user") r_password = cfg.get("Acc_Details", "r_password") except ConfigParser.NoSectionError or ConfigParser.NoOptionError: print "no section or No Option" print os.remove(path) return (m_user, m_password, r_user, r_password) def cookie_processor(cookie): cookie = cookie.split("; ") ## cookie = dict( [cookie[x].split("=") for x in xrange ( len (cookie) ) ] ) ## if cookie['user'] != None: return cookie ## else: ## print "Scheme has changed or authentication failes. Last option most likely" ## sys.exit() ## def rs_auth(login): r_user = login[0] r_password = login[1] opener = urllib2.build_opener(urllib2.HTTPSHandler()) urllib2.install_opener( opener ) cred = urllib.urlencode({"login": r_user, "password": r_password}) try: req = urllib2.urlopen("https://ssl.rapidshare.com/cgi-bin/ premiumzone.cgi", cred) cookie_rs = cookie_processor( req.headers.get("set-cookie", "") ) except urllib2.URLError: print"Some error with the connection ocurred. Try again now or later" sys.exit() #Returns the page if flag is set return req.read(), cookie_rs def mu_auth(login): r_user = login[0] r_password = login[1] cred = urllib.urlencode({"login": r_user, "password": r_password}) try: req = urllib2.urlopen("http://www.megaupload.com", cred) cookie_mu = cookie_processor( req.headers.get("set-cookie", "") ) except: print "Connection failed" sys.exit() #returns the authenticated header, in case future changes specificaly ask the cookie it would be easy #to change code or even extract it from the header itself as a dictionary key return cookie_mu def set_rscookie_in_musite(cookie_mu, cookie_rs) : #it doesnt need to check for the cookie because it automaticaly resets for the new value cookie_rs = cookie_rs.split("=",1) header = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain", "cookie":cookie_mu} params = urllib.urlencode({'domain': "http://rapidshare.com", 'cookiename1': cookie_rs[0], 'cookievalue1': cookie[1] }) req = urllib2.Request("http://www.megaupload.com/multifetch/? c=cookies", params, header ) print header print params #r = urllib2.urlopen(req) return True acc_details = account_details() if len(sys.argv)==1: print "Try -help for more information" sys.exit("No arguments") if sys.argv[1] == "-h" or sys.argv[1] == "?help": print " > murs http://megaupload.com/?d=FILE1 ? http://megaupload.com/?d=FILEN" print " Download one or several rapidshare links passed as argument separated by whitespace\n" print " >murs links.txt" print " Download a list of links from a file\n" print " >murs account" print " Automaticaly downloads the entire contents of your account" sys.exit() ## Process the arguments ## AFTER THIS ITS ALL ROLLING if sys.argv[1] == "account" or sys.argv[1] == "-a": #Getting the rapidshare user and password respectivelyfrom the account details already called print acc_details[2:] page = rs_auth( acc_details[2:] ) rex = re.findall('''Adliste\["(........|.)"\]\["filename"\] = "(.*)"''', page[0]) for retrieved_data in rex: #as there are two matches the retrieved_data is still a list urls.append("http://rapidshare.com/files/" + retrieved_data [0] + "/" + retrieved_data[1]) elif os.path.exists(sys.argv[1]): # If this is a file from_file = True l_file = sys.argv[1] print "Reading list of links from the file " , l_file print "\n" list_f = file(l_file, "r") urls = list_f.readlines() list_f.close() if not from_rapidshare(urls): sys.exit("Urls in text file were not valid") elif from_rapidshare(sys.argv[1]): #if argument is one or more urls for i in range(1, len(sys.argv)): if from_rapidshare(sys.argv[i]): urls.append(sys.argv[i]) else: print "This is not valid argument" , sys.argv[1] sys.exit() urls = [] cookie_mu = mu_auth(acc_details[:2]) print cookie_mu headers = {"User Agent": "Mozilla/5.0", "Accept": "text/plain", "cookie":cookie_mu[0]} for url in urls: try: params = urllib.urlencode({'srcurl': url, 'description': "something"}) req = urllib2.Request("http://megaupload.com/multifetch/", params, headers ) r = urllib2.urlopen(req) except: print "An error ocurred while trying to talk to megaupload. Make sure you enter the correct password" From tino at wildenhain.de Sat Feb 14 15:54:25 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Sat, 14 Feb 2009 21:54:25 +0100 Subject: PySerial "write" should accept "bytearray" In-Reply-To: <49972dbc$0$1648$742ec2ed@news.sonic.net> References: <49972dbc$0$1648$742ec2ed@news.sonic.net> Message-ID: <49972F81.8020000@wildenhain.de> John Nagle wrote: > PySerial, which is basically a binary input/output system, is > still requiring "str" instead of "bytearray", even under Python 2.6. > For "file-like objects", "write" functions are supposed to accept > "bytearray" now, and "read" functions should return a "bytearray". > I'm sure patches are welcome. And did you copy the pyserial author? Regards Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From rt8396 at gmail.com Sat Feb 14 16:10:31 2009 From: rt8396 at gmail.com (r) Date: Sat, 14 Feb 2009 13:10:31 -0800 (PST) Subject: ANN: SuPy - Script Sketchup with Python References: <6v1u4pFho98dU1@mid.individual.net> <498C64E2.1050204@islandtraining.com> Message-ID: Great work Greg, you are a Python zen master! From nagle at animats.com Sat Feb 14 16:16:14 2009 From: nagle at animats.com (John Nagle) Date: Sat, 14 Feb 2009 13:16:14 -0800 Subject: Can Python serial support run at 45.45 baud? In-Reply-To: References: <4996e984$0$1657$742ec2ed@news.sonic.net> <-rednU9RmNnrbwvUnZ2dnUVZ_sHinZ2d@posted.usinternet> <49970561$0$1642$742ec2ed@news.sonic.net> <49970ce7$0$1665$742ec2ed@news.sonic.net> Message-ID: <49972cf5$0$1612$742ec2ed@news.sonic.net> MRAB wrote: > John Nagle wrote: > [snip] >> So the correct combination, 5 bits with 1.5 stop bits, isn't supported in >> Python. 1 stop bit will not physically work on Baudot teletypes; the >> main camshaft doesn't come around fast enough. (Yes, there's an actual >> mechanical reason for 1.5 stop bits.) Requesting 2 stop bits at the >> Python level gets a reject at the Win32 level. (Not sure why Win32 >> doesn't allow that; extra stop bits just add delay, but don't hurt >> anything. But it's not supported.) I patched PySerial to support "STOPBITS_ONE5", for 1.5 stop bits, and the big Teletype Model 15 is now banging out text from Python. I actually put in "45.45" as the baud rate; it gets rounded down to 45 for Windows, which works. That won't work on Linux, though; there's a canned list of speeds for POSIX serial ports. (It's the same list PDP-11 serial ports had in the 1970s, plus some later extensions at the high end.) 1.5 or 2 stop bits is acceptable for the old heavy iron, but 1.5 is preferred, because there's less vibration and wear. With 2 stop bits, the Teletype Model 15 clutch drops out on every character and the drive train momentarily comes to a halt. With 1.5, everything rotates steadily. John Nagle From nagle at animats.com Sat Feb 14 16:19:34 2009 From: nagle at animats.com (John Nagle) Date: Sat, 14 Feb 2009 13:19:34 -0800 Subject: PySerial "write" should accept "bytearray" Message-ID: <49972dbc$0$1648$742ec2ed@news.sonic.net> PySerial, which is basically a binary input/output system, is still requiring "str" instead of "bytearray", even under Python 2.6. For "file-like objects", "write" functions are supposed to accept "bytearray" now, and "read" functions should return a "bytearray". John Nagle From nagle at animats.com Sat Feb 14 16:25:37 2009 From: nagle at animats.com (John Nagle) Date: Sat, 14 Feb 2009 13:25:37 -0800 Subject: Can Python serial support run at 45.45 baud? In-Reply-To: References: <4996e984$0$1657$742ec2ed@news.sonic.net> <-rednU9RmNnrbwvUnZ2dnUVZ_sHinZ2d@posted.usinternet> <49970561$0$1642$742ec2ed@news.sonic.net> <49970ce7$0$1665$742ec2ed@news.sonic.net> Message-ID: <49972f28$0$1622$742ec2ed@news.sonic.net> Roy Smith wrote: > In article <49970ce7$0$1665$742ec2ed at news.sonic.net>, > John Nagle wrote: > >> At the hardware level, there's a clock rate, a counter, and a divisor, >> so arbitrary baud rates can be set. > > Is that really true of modern hardware? The last time I looked at serial > port hardware, UARTs took a base clock rate and divided it sequentially > with flip-flops to get all the possible rates (they usually had some ugly > logic to generate 110). You were limited to the specific rates the > hardware gave you. Is that no longer the case? It is, but the traditional serial clock rate is 115200 Hz, so you can use any subdivision of that as a baud rate. The divisor for 45.45 baud is something like 2535. Some exotic serial port devices use a 16MHz clock; I've used those for supporting SICK LMS laser rangerfinders at 500,000 baud. John Nagle From thorsten at thorstenkampe.de Sat Feb 14 16:35:12 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Sat, 14 Feb 2009 22:35:12 +0100 Subject: Untangling pythonWin and IDLE Processes on XP Pro References: <%OUkl.6905$jZ1.2422@flpi144.ffdc.sbc.com> <6viopfFkcasmU1@mid.uni-berlin.de> <2NWkl.16040$YU2.9824@nlpi066.nbdc.sbc.com> <4ec6562a-08b2-4ec4-b9c0-e720e4ce7339@g38g2000yqd.googlegroups.com> <5-KdnfUPXNqQSgnUnZ2dnUVZ_sudnZ2d@earthlink.com> <1Bcll.10420$hc1.4903@flpi150.ffdc.sbc.com> Message-ID: * Rhodri James (Fri, 13 Feb 2009 22:57:42 -0000) > > On Fri, 13 Feb 2009 11:13:38 -0000, W. eWatson > wrote: > > > OK, enough tinkering with the code and others matters on my end trying > > to find a work around. Somehow after much successful use of IDLE's > > execution facility, I've stepped on an invisible banana peel. I think > > it's evident that I'm not going around this problem easily with the IDLE > > execution attempts, and that another solution is required. > > Congratulations, we've only been telling you this for the last few days. > I wonder, is there any chance that you've noticed the solution given? The Lord gives and the Lord takes. Sometimes it just takes a bit longer... Thorsten From thorsten at thorstenkampe.de Sat Feb 14 16:37:52 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Sat, 14 Feb 2009 22:37:52 +0100 Subject: Untangling pythonWin and IDLE Processes on XP Pro References: <%OUkl.6905$jZ1.2422@flpi144.ffdc.sbc.com> <6viopfFkcasmU1@mid.uni-berlin.de> <2NWkl.16040$YU2.9824@nlpi066.nbdc.sbc.com> <4ec6562a-08b2-4ec4-b9c0-e720e4ce7339@g38g2000yqd.googlegroups.com> <5-KdnfUPXNqQSgnUnZ2dnUVZ_sudnZ2d@earthlink.com> <1Bcll.10420$hc1.4903@flpi150.ffdc.sbc.com> <-5OdnU6H_-GbTgjUnZ2dnUVZ_h6dnZ2d@pdx.net> Message-ID: * W. eWatson (Fri, 13 Feb 2009 20:58:33 -0800) > Scott David Daniels wrote: > > OK, you are using the oldest and least useful revision control > > system, "rename and remember." I'd suggest you get and use bazaar, > > but you'll just ask for shortcuts on how to use it without > > understanding what it does. > It works for me, and, frankly, I'm not interested in going to Linux, > SunOS or other "revision systmes". These are way in my distant past, > and the only reason I'm currently, and begrudgingly, once again > writing programs is that the Python software program I am using is > limited in its ability. You, sir, certainly made my day. Thank you! Thorsten From google at mrabarnett.plus.com Sat Feb 14 17:17:09 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 14 Feb 2009 22:17:09 +0000 Subject: Rapidshare to Megaupload script In-Reply-To: References: Message-ID: <499742E5.9040000@mrabarnett.plus.com> aiwarrior wrote: > I've made this script and would like to have some input and share it > with the community. > I also have a page with some code i produce on my spare time. http://pneves.net > Thanks > [snip] > > def from_rapidshare(url): > '''Check if this is a rapidshare link''' > return (url.startswith("rapidshare.com") or > url.startswith("www.rapidshare.com") or > url.startswith("http://rapidshare.com") or > url.startswith("http://www.rapidshare.com")) > You can shorten: s.startswith(x) or s.startswith(y) or ... to: s.startswith((x, y, ...)) [snip] > cfg = ConfigParser.SafeConfigParser() > cfg.read(path) > try: > m_user = cfg.get("Acc_Details", "m_user") > m_password = cfg.get("Acc_Details", "m_password") > r_user = cfg.get("Acc_Details", "r_user") > r_password = cfg.get("Acc_Details", "r_password") > except ConfigParser.NoSectionError or ConfigParser.NoOptionError: In order to catch multiple exceptions it should be: except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): > print "no section or No Option" > print > os.remove(path) > return (m_user, m_password, r_user, r_password) > > def cookie_processor(cookie): > cookie = cookie.split("; ") > ## cookie = dict( [cookie[x].split("=") for x in xrange ( len > (cookie) ) ] ) Or: ## cookie = dict(x.split("=") for x in cookie) > ## if cookie['user'] != None: When checking for None use "is" and "is not": ## if cookie['user'] is not None: > return cookie > ## else: > ## print "Scheme has changed or authentication failes. Last > option most likely" > ## sys.exit() Raising an exception is better than exiting. > ## > [snip] > def mu_auth(login): > r_user = login[0] > r_password = login[1] > cred = urllib.urlencode({"login": r_user, "password": r_password}) > try: > req = urllib2.urlopen("http://www.megaupload.com", cred) > cookie_mu = cookie_processor( req.headers.get("set-cookie", > "") ) > > except: Don't use an empty "except"; be explicit in which exception you want to catch . [snip] > > if sys.argv[1] == "-h" or sys.argv[1] == "?help": Or: if sys.argv[1] in ("-h", "?help"): [snip] > elif from_rapidshare(sys.argv[1]): #if argument is one or more urls > for i in range(1, len(sys.argv)): Or: for arg in sys.argv[1 : ]: and so on. > if from_rapidshare(sys.argv[i]): > urls.append(sys.argv[i]) > else: > print "This is not valid argument" , sys.argv[1] > sys.exit() > urls = [] > [snip] HTH From nytrokiss at gmail.com Sat Feb 14 17:27:47 2009 From: nytrokiss at gmail.com (James Matthews) Date: Sun, 15 Feb 2009 00:27:47 +0200 Subject: Rapidshare to Megaupload script In-Reply-To: <499742E5.9040000@mrabarnett.plus.com> References: <499742E5.9040000@mrabarnett.plus.com> Message-ID: <8a6b8e350902141427y630b8daet537009181516e7f2@mail.gmail.com> This can be used as a great guide on writing pythonic code. Don't look at the specific code that is being corrected but look at how the improvements are being presented. I would recommend someone who is learning python read this guide. On Sun, Feb 15, 2009 at 12:17 AM, MRAB wrote: > aiwarrior wrote: > >> I've made this script and would like to have some input and share it >> with the community. >> I also have a page with some code i produce on my spare time. >> http://pneves.net >> Thanks >> >> [snip] > >> >> def from_rapidshare(url): >> '''Check if this is a rapidshare link''' >> return (url.startswith("rapidshare.com") or >> url.startswith("www.rapidshare.com") or >> url.startswith("http://rapidshare.com") or >> url.startswith("http://www.rapidshare.com")) >> >> You can shorten: > > s.startswith(x) or s.startswith(y) or ... > > to: > > s.startswith((x, y, ...)) > > [snip] > >> cfg = ConfigParser.SafeConfigParser() >> cfg.read(path) >> try: >> m_user = cfg.get("Acc_Details", "m_user") >> m_password = cfg.get("Acc_Details", "m_password") >> r_user = cfg.get("Acc_Details", "r_user") >> r_password = cfg.get("Acc_Details", "r_password") >> except ConfigParser.NoSectionError or ConfigParser.NoOptionError: >> > > In order to catch multiple exceptions it should be: > > except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): > > print "no section or No Option" >> print >> os.remove(path) >> return (m_user, m_password, r_user, r_password) >> >> def cookie_processor(cookie): >> cookie = cookie.split("; ") >> ## cookie = dict( [cookie[x].split("=") for x in xrange ( len >> (cookie) ) ] ) >> > Or: > ## cookie = dict(x.split("=") for x in cookie) > > ## if cookie['user'] != None: >> > When checking for None use "is" and "is not": > ## if cookie['user'] is not None: > > return cookie >> ## else: >> ## print "Scheme has changed or authentication failes. Last >> option most likely" >> ## sys.exit() >> > Raising an exception is better than exiting. > > ## >> >> [snip] > >> def mu_auth(login): >> r_user = login[0] >> r_password = login[1] >> cred = urllib.urlencode({"login": r_user, "password": r_password}) >> try: >> req = urllib2.urlopen("http://www.megaupload.com", cred) >> cookie_mu = cookie_processor( req.headers.get("set-cookie", >> "") ) >> >> except: >> > Don't use an empty "except"; be explicit in which exception you want to > catch . > > [snip] > >> >> if sys.argv[1] == "-h" or sys.argv[1] == "?help": >> > Or: > > if sys.argv[1] in ("-h", "?help"): > > [snip] > > elif from_rapidshare(sys.argv[1]): #if argument is one or more urls >> for i in range(1, len(sys.argv)): >> > Or: > > for arg in sys.argv[1 : ]: > > and so on. > > if from_rapidshare(sys.argv[i]): >> urls.append(sys.argv[i]) >> else: >> print "This is not valid argument" , sys.argv[1] >> sys.exit() >> urls = [] >> >> [snip] > HTH > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://www.goldwatches.com/ http://www.jewelerslounge.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From pDOTpagel at wzw.tum.de Sat Feb 14 17:31:29 2009 From: pDOTpagel at wzw.tum.de (Philipp Pagel) Date: Sat, 14 Feb 2009 22:31:29 +0000 (UTC) Subject: Reading a file References: Message-ID: zaheer.agadi at gmail.com wrote: > Hi > How do i read a file in Python and search a particular pattern > like I have a file char.txt which has > Mango=sweet > Sky=blue > I want to get the strings sweet and blue,How to do this..? If your entire file consists of such key=value pairs you may want to properly parse them: for lne in infile: line = line.rstrip() key, value = line.split('=') if key in ('Mango', 'Sky'): print value Or something like that - details depend on what exactly your criteria for picking the values are, of course. cu Philipp -- Dr. Philipp Pagel Lehrstuhl f. Genomorientierte Bioinformatik Technische Universit?t M?nchen http://mips.gsf.de/staff/pagel From greg.ewing at canterbury.ac.nz Sat Feb 14 18:29:40 2009 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sun, 15 Feb 2009 12:29:40 +1300 Subject: ANN: SuPy 1.3 Message-ID: SuPy 1.3 Available ------------------ http://www.cosc.canterbury.ac.nz/greg.ewing/SuPy/ Changes in this version: - Added the rest of the promised functionality to the menus module (submenus and separators) and provided an example of its usage in examples.py. - The scheme for preserving variables using a __keep__ attribute turned out to be fatally flawed. It has been replaced by a new mechanism using a keep() function instead. See the section on "Preserving Data" for details. What is SuPy? ------------- SuPy is a plugin for the Sketchup 3D modelling application that lets you script it in Python. -- Greg Ewing greg.ewing at canterbury.ac.nz From rhodri at wildebst.demon.co.uk Sat Feb 14 19:09:42 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sun, 15 Feb 2009 00:09:42 -0000 Subject: Untangling pythonWin and IDLE Processes on XP Pro In-Reply-To: References: <%OUkl.6905$jZ1.2422@flpi144.ffdc.sbc.com> <6viopfFkcasmU1@mid.uni-berlin.de> <2NWkl.16040$YU2.9824@nlpi066.nbdc.sbc.com> <4ec6562a-08b2-4ec4-b9c0-e720e4ce7339@g38g2000yqd.googlegroups.com> <5-KdnfUPXNqQSgnUnZ2dnUVZ_sudnZ2d@earthlink.com> <1Bcll.10420$hc1.4903@flpi150.ffdc.sbc.com> Message-ID: On Sat, 14 Feb 2009 05:03:13 -0000, W. eWatson wrote: > See my response to Scott. Thanks for your reply. I did. It was fundamentally mistaken in so many respects that I formally give up on you. -- Rhodri James *-* Wildebeeste Herder to the Masses From sou1980 at tellas.gr Sat Feb 14 19:42:52 2009 From: sou1980 at tellas.gr (Tsolakos Stavros) Date: Sun, 15 Feb 2009 02:42:52 +0200 Subject: GetKeyboardLayoutName Win32API Message-ID: Hi all. I was trying to find a way to read the currently selected input layout from an app written in python. I am aware that if the app were written in C, I would have to call the GetKeyboardLayoutName() function. How can this be done in Python? I want to avoid writing an extension just for this. The function is not available through pywin32. Thank you, Stavros From konteyaj at gmail.com Sat Feb 14 22:30:40 2009 From: konteyaj at gmail.com (konteya joshi) Date: Sat, 14 Feb 2009 19:30:40 -0800 Subject: ImportError: dynamic module does not define init function (inittypes) Message-ID: Hi, Iam trying to run a programs which resides insides ..\pythonroot. I see the following error on running the program: 'import site' failed; use -v for traceback Traceback (most recent call last): File "skyline\alpine_kickoff.py", line 6, in ? import re File "C:\Perforce\qa\testware\build\vmqa\python\python-2.4.1-as\lib\re.py", line 5, in ? from sre import * File "C:\Per\qa\test\build\vmqa\python\python-2.4.1-as\lib\sre.py", line 265, in ? import copy_reg File "C:\Per\qa\test\build\vmqa\python\python-2.4.1-as\lib\copy_reg.py", line 7, in ? from types import ClassType as _ClassType ImportError: dynamic module does not define init function (inittypes) Any body who would have an idea on what might be going wrong? I have python-2.4.1-as directory in my PYTHONPATH which contains the Lib,libs...etc in the directory. The Lib contains the re,sre,copy_reg inside the directory. Thanks. From steve at pearwood.info Sat Feb 14 22:34:04 2009 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 15 Feb 2009 14:34:04 +1100 Subject: Function name limit in Python ? References: Message-ID: <01a782d5$0$14422$c3e8da3@news.astraweb.com> Linuxguy123 wrote: > Excuse my ignorance, but is there a limit to the size of function names > in Python ? > > I named a function getSynclientVersion() and I got an error when I > called it. No no, don't tell us what error you got! I love guessing games. I'm guessing you got either a SyntaxError or a NameError. > I renamed the same function to getSCVersion() and it called > fine. >>> def python_allows_really_long_function_names_with_no_problem(): ... print "hello world" ... >>> python_allows_really_long_function_names_with_no_problem() hello world >>> >>> ptyhon_allows_really_long_function_names_with_no_problem() Traceback (most recent call last): File "", line 1, in ? NameError: name 'ptyhon_allows_really_long_function_names_with_no_problem' is not defined Can you spot the difference? More importantly, can you see how the error message actually tells you what the error is? -- Steven From steve at pearwood.info Sat Feb 14 22:44:45 2009 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 15 Feb 2009 14:44:45 +1100 Subject: String concatenation performance with += References: <2b2d6d33-f43d-4dd0-b881-1f4edb24ad2e@o2g2000prl.googlegroups.com> Message-ID: <01a78556$0$20669$c3e8da3@news.astraweb.com> Nick Craig-Wood wrote: > The optimized += depends on their being no other references to the > string. ?Strings are immutable in python. ?So append must return a new > string. ?However the += operation was optimised to do an in-place > append if and only if there are no other references to the string. > > You can see this demonstrated here > > $ python -m timeit -s 'a="x"' 'a+="x"' > 1000000 loops, best of 3: 0.231 usec per loop > > $ python -m timeit -s 'a="x"; b=a' 's = a; a+="x"' > 100000 loops, best of 3: 30.1 usec per loop That is a fantastic explanation of why you shouldn't rely on the concat optimization, although the assignment b=a in the setup isn't necessary and is a little misleading. Thank you. -- Steven From grante at visi.com Sun Feb 15 00:03:03 2009 From: grante at visi.com (Grant Edwards) Date: Sat, 14 Feb 2009 23:03:03 -0600 Subject: Can Python serial support run at 45.45 baud? References: <4996e984$0$1657$742ec2ed@news.sonic.net> <-rednU9RmNnrbwvUnZ2dnUVZ_sHinZ2d@posted.usinternet> <49970561$0$1642$742ec2ed@news.sonic.net> <49970ce7$0$1665$742ec2ed@news.sonic.net> Message-ID: On 2009-02-14, John Nagle wrote: > John Nagle wrote: > >> OK, tried to open the port, using Python 2.6, latest PySerial >> and PyWin32: >> >> ser = serial.Serial(port, baudrate=baud, >> bytesize=serial.FIVEBITS, >> parity=serial.PARITY_NONE, >> stopbits=serial.STOPBITS_TWO) >> >> ValueError: Cannot configure port, some setting was wrong. Original >> message: (87, 'SetCommState', 'The parameter is incorrect.') >> >> Something doesn't like "serial.FIVEBITS". That's a valid value, >> according >> to "http://pyserial.wiki.sourceforge.net/pySerial". If changed to >> "serial.EIGHTBITS", the code will execute, but of course does the wrong >> thing. That looks like a bug. > > OK, here's what's wrong. The allowed numbers for stop bits in Windows are > > ONESTOPBIT 0 1 stop bit. > ONE5STOPBITS 1 1.5 stop bits. > TWOSTOPBITS 2 2 stop bits. > > The Python interface, however, only exports STOPBITS_ONE and STOPBITS_TWO. > See "serialutil.py", at line 9, and "serialwin32.py" at lines 141-146. That should be simple enough to fix. > Linux has a different set of restrictions; Linux offers only 1 or 2 stop > bits, and won't do arbitrary baud rates via the "termios" data structure, > although there are other ways to request that. It can be done via the ioctl that setserial uses, but that's specific to a very few low-level drivers like the 16x50 one -- which is probably the one that matters to the OP, though he hasn't said so. -- Grant From grante at visi.com Sun Feb 15 00:23:16 2009 From: grante at visi.com (Grant Edwards) Date: Sat, 14 Feb 2009 23:23:16 -0600 Subject: Can Python serial support run at 45.45 baud? References: <4996e984$0$1657$742ec2ed@news.sonic.net> <-rednU9RmNnrbwvUnZ2dnUVZ_sHinZ2d@posted.usinternet> <49970561$0$1642$742ec2ed@news.sonic.net> <49970ce7$0$1665$742ec2ed@news.sonic.net> <49972f28$0$1622$742ec2ed@news.sonic.net> Message-ID: On 2009-02-14, John Nagle wrote: > Roy Smith wrote: >> In article <49970ce7$0$1665$742ec2ed at news.sonic.net>, >> John Nagle wrote: >> >>> At the hardware level, there's a clock rate, a counter, and a >>> divisor, so arbitrary baud rates can be set. >> >> Is that really true of modern hardware? The last time I >> looked at serial port hardware, UARTs took a base clock rate >> and divided it sequentially with flip-flops to get all the >> possible rates (they usually had some ugly logic to generate >> 110). You were limited to the specific rates the hardware >> gave you. Is that no longer the case? > > It is, but the traditional serial clock rate is 115200 Hz, so > you can use any subdivision of that as a baud rate. The > divisor for 45.45 baud is something like 2535. On Linux IFF you're using a 16x50 UART, you can set arbitrary divisors using the setserial utility. From Python, you can just invoke setserial (via os.system() or subprocess). It should be pretty trivial: execute setserial with the parameters "/dev/whatever spd_cust divisor 2535". Then use the normal calls to set the baud rate to 38400, and you should get 45.444 baud. [Disclaimer: I haven't tested the above, and I may be remembering it incorrectly.] If that's too easy and you want to get your hands dirty, you can look up the ioctl and parameter structure used by setserial and invoke the ioctl directly from Python. Neither method is portable to any other OS (or any other serial driver, AFAIK). > Some exotic serial port devices use a 16MHz clock; I've used > those for supporting SICK LMS laser rangerfinders at 500,000 > baud. :) Been there, done that -- along with that goofy checksum they call a CRC. They actually only do the CRC on one bit out of every byte, and then they just xor in the rest of the byte. It's very strange, rather slow, and not very good at detecting errors. A real, table-driven CRC would be both a lot faster and a lot more robust. My guess is that it was _supposed_ to be a CRC routine, but somebody botched it. They used the same botched routine on the host end when they did testing, so nobody noticed it was broken. By the time anybody realized that the CRC routine was broken, masked ROMs were in the field and it was too late to fix it -- so they just documented the "custom" algorithm in the manual and called it good. -- Grant From grante at visi.com Sun Feb 15 00:25:12 2009 From: grante at visi.com (Grant Edwards) Date: Sat, 14 Feb 2009 23:25:12 -0600 Subject: PySerial "write" should accept "bytearray" References: <49972dbc$0$1648$742ec2ed@news.sonic.net> Message-ID: On 2009-02-14, John Nagle wrote: > PySerial, which is basically a binary input/output system, is > still requiring "str" instead of "bytearray", even under Python 2.6. > For "file-like objects", "write" functions are supposed to accept > "bytearray" now, and "read" functions should return a "bytearray". I'm sure a patch would be happily accepted. I don't use 2.6 yet, and I don't know if the other people who've worked on pyserial do either. -- Grant From steve at pearwood.info Sun Feb 15 00:27:53 2009 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 15 Feb 2009 16:27:53 +1100 Subject: Reading a file References: Message-ID: <01a79d80$0$20652$c3e8da3@news.astraweb.com> Philipp Pagel wrote: > zaheer.agadi at gmail.com wrote: >> Hi > >> How do i read a file in Python and search a particular pattern >> like I have a file char.txt which has > >> Mango=sweet >> Sky=blue > >> I want to get the strings sweet and blue,How to do this..? > > If your entire file consists of such key=value pairs you may want to > properly parse them: The proper way to parse them would be with the ConfigParser module. The only negative with ConfigParser is that it requires a section label. In my experience it is quite common for INI files with only a single section to leave out the label. -- Steven From steve at pearwood.info Sun Feb 15 00:31:37 2009 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 15 Feb 2009 16:31:37 +1100 Subject: doctest fails to see tests in decorated functions References: <01a66625$0$21875$c3e8da3@news.astraweb.com> Message-ID: <01a79e61$0$20647$c3e8da3@news.astraweb.com> Steven D'Aprano wrote: > I've just spotted a bug in doctest that it fails to see tests inside > decorated functions. It's been reported before: > > http://bugs.python.org/issue1108 > > but the patch submitted doesn't work for me. Never mind, it was a PEBCAK error. I failed to notice that applying a decorator to a function shadows the functions docstring. Normally I would use functools.wraps, but I am currently limping along on a Python 2.4 installation here, which doesn't have it. -- Steven From michele.simionato at gmail.com Sun Feb 15 00:35:49 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Sat, 14 Feb 2009 21:35:49 -0800 (PST) Subject: doctest fails to see tests in decorated functions References: <01a66625$0$21875$c3e8da3@news.astraweb.com> <01a79e61$0$20647$c3e8da3@news.astraweb.com> Message-ID: <503ff63e-527a-4bed-a931-722b73d63989@i38g2000yqd.googlegroups.com> On Feb 15, 6:31?am, Steven D'Aprano wrote: > Never mind, it was a PEBCAK error. I failed to notice that applying a > decorator to a function shadows the functions docstring. > > Normally I would use functools.wraps, but I am currently limping along on a > Python 2.4 installation here, which doesn't have it. You may consider this: http://pypi.python.org/pypi/decorator M.S. From lie.1296 at gmail.com Sun Feb 15 00:56:17 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 15 Feb 2009 05:56:17 +0000 (UTC) Subject: "Byte" type? References: <4997aa38$0$1678$742ec2ed@news.sonic.net> Message-ID: On Sat, 14 Feb 2009 22:10:41 -0800, John Nagle wrote: > >>> xx = b'x' Isn't this creating a regular byte? Shouldn't creation of bytearray be: >>> xx = bytearray(b'x') From max at alcyone.com Sun Feb 15 00:58:54 2009 From: max at alcyone.com (Erik Max Francis) Date: Sat, 14 Feb 2009 21:58:54 -0800 Subject: "Byte" type? In-Reply-To: <4997aa38$0$1678$742ec2ed@news.sonic.net> References: <4997aa38$0$1678$742ec2ed@news.sonic.net> Message-ID: John Nagle wrote: > With "bytearray", the element type is considered to be "unsigned byte", > or so says PEP 3137: "The element data type is always 'B' (i.e. unsigned > byte)." > > Let's try: > > Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit > (Intel)] on > win32 > >>> xx = b'x' > >>> repr(xx) > "'x'" > >>> repr(xx[0]) > "'x'" > >>> repr(xx[0][0]) > "'x'" > >>> > > But that's not what "repr" indicates. The bytearray element is apparently > being promoted to "bytes" as soon as it comes out of the array. There's no distinction byte type. A single character of a bytes type is also a bytes. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis Did you ever love somebody / Did you ever really care -- Cassandra Wilson From clp2 at rebertia.com Sun Feb 15 01:06:42 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 14 Feb 2009 22:06:42 -0800 Subject: "Byte" type? In-Reply-To: References: <4997aa38$0$1678$742ec2ed@news.sonic.net> Message-ID: <50697b2c0902142206o6878b65ek7887eb4ce271b490@mail.gmail.com> On Sat, Feb 14, 2009 at 9:56 PM, Lie Ryan wrote: > On Sat, 14 Feb 2009 22:10:41 -0800, John Nagle wrote: > >> >>> xx = b'x' > > Isn't this creating a regular byte? > > Shouldn't creation of bytearray be: > >>>> xx = bytearray(b'x') Indeed, and slicing that does give back a single byte (which Python represents as an integer): >>> b = bytearray(b'abc') >>> b[0] 97 Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From nagle at animats.com Sun Feb 15 01:10:41 2009 From: nagle at animats.com (John Nagle) Date: Sat, 14 Feb 2009 22:10:41 -0800 Subject: "Byte" type? Message-ID: <4997aa38$0$1678$742ec2ed@news.sonic.net> With "bytearray", the element type is considered to be "unsigned byte", or so says PEP 3137: "The element data type is always 'B' (i.e. unsigned byte)." Let's try: Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on win32 >>> xx = b'x' >>> repr(xx) "'x'" >>> repr(xx[0]) "'x'" >>> repr(xx[0][0]) "'x'" >>> But that's not what "repr" indicates. The bytearray element is apparently being promoted to "bytes" as soon as it comes out of the array. John Nagle From nihil.is at free.fr Sun Feb 15 01:17:08 2009 From: nihil.is at free.fr (Sylvain Rabot) Date: Sat, 14 Feb 2009 22:17:08 -0800 Subject: Setuptools & Python 3.0 Message-ID: <4997b3ae$0$20705$426a74cc@news.free.fr> Hi, I would like to know if the official maintainers of setuptools are working on a release for Python 3.0. Regards. From steve at pearwood.info Sun Feb 15 01:29:42 2009 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 15 Feb 2009 17:29:42 +1100 Subject: How to peek inside a decorated function Message-ID: <01a7abfe$0$20629$c3e8da3@news.astraweb.com> Suppose I have a function f() which I know has been decorated, but I don't have access to the original undecorated function any longer: def reverse(func): def f(*args): args = list(args) args.reverse() return func(*args) return f def say(*args): print args rsay = reverse(say) del say Is there any way to peek inside the decorated function rsay() to get access to the undecorated function say()? If I look at the code object I can see a reference to the original: >>> rsay.func_code.co_names ('list', 'args', 'reverse', 'func') and if I disassemble the code object I can see it being dereferenced: >>> dis.dis(rsay.func_code) [snip for brevity] 5 22 LOAD_DEREF 0 (func) 25 LOAD_FAST 0 (args) 28 CALL_FUNCTION_VAR 0 31 RETURN_VALUE but if I look at the closure object, nothing seems useful: >>> dir(rsay.func_closure[0]) ['__class__', '__cmp__', '__delattr__', '__doc__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__'] and I can't find any other attributes which refers back to the undecorated original function. -- Steven From kentandkat at sbcglobal.net Sun Feb 15 02:14:13 2009 From: kentandkat at sbcglobal.net (kentandkat at sbcglobal.net) Date: Sun, 15 Feb 2009 01:14:13 -0600 Subject: python in emacs Message-ID: When I visit a file with extension .py, emacs says "loading python...done", and gives me a "python" menu with options like "start interpreter" and "eval buffer". When I try to use one of these options emacs says "loading compile...done", then hangs and has to be shut down from the task manager. The Python folder is in my PATH variable and works fine from the command line (or with IDLE). I'm using emacs-22.3 on windows xp, and have the same problem with both python-2.2 and python-3.0. Anybody got any tips, or should I just give up and use some other editor? Thanks, Kent. From srikrishnamohan at gmail.com Sun Feb 15 02:38:31 2009 From: srikrishnamohan at gmail.com (km) Date: Sun, 15 Feb 2009 16:38:31 +0900 Subject: multiprocessing python2.6.1 Message-ID: Dear all, I have a problem with multiprocessing module usage with python2.6.1 Here Pool object is to be instantiated with 50 processes and the method 'run' has to be called with pool object. My actual requirement is to reuse the 50 processes for further processing until 100 items. ######################### import multiprocessing as mp def add(a,b): return a+b if __name__ == '__main__': p = mp.Pool(processes=50) y = 40 for x in range(100): p.apply_async(run, (x, y) ) ########################## The problem now is that it creates only 32 processes (and not more) and exits with processing first 32 numbers from range(100) . Is there a cap on the number of subprocesses one can fork ? Even then, once these 32 processes r free, I would like to reuse them with next 32 inputs (x) from range(100 ) in that order. how could i accomplish this ? thanks in advance. KM -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Sun Feb 15 03:43:57 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 15 Feb 2009 03:43:57 -0500 Subject: How to peek inside a decorated function In-Reply-To: <01a7abfe$0$20629$c3e8da3@news.astraweb.com> References: <01a7abfe$0$20629$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Suppose I have a function f() which I know has been decorated, but I don't > have access to the original undecorated function any longer: > > def reverse(func): > def f(*args): > args = list(args) > args.reverse() > return func(*args) > return f > > def say(*args): > print args > > rsay = reverse(say) > del say > > > Is there any way to peek inside the decorated function rsay() to get access > to the undecorated function say()? > > If I look at the code object I can see a reference to the original: > >>>> rsay.func_code.co_names > ('list', 'args', 'reverse', 'func') > > and if I disassemble the code object I can see it being dereferenced: > >>>> dis.dis(rsay.func_code) > [snip for brevity] > 5 22 LOAD_DEREF 0 (func) > 25 LOAD_FAST 0 (args) > 28 CALL_FUNCTION_VAR 0 > 31 RETURN_VALUE > > but if I look at the closure object, nothing seems useful: > >>>> dir(rsay.func_closure[0]) > ['__class__', '__cmp__', '__delattr__', '__doc__', > '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', > '__reduce_ex__', '__repr__', '__setattr__', '__str__'] > > > and I can't find any other attributes which refers back to the undecorated > original function. In 3.0, rsay.__closure__[0].cell_contents would be the original function object. From zaheer.agadi at gmail.com Sun Feb 15 03:55:52 2009 From: zaheer.agadi at gmail.com (zaheer.agadi at gmail.com) Date: Sun, 15 Feb 2009 00:55:52 -0800 (PST) Subject: Reading a file References: <01a79d80$0$20652$c3e8da3@news.astraweb.com> Message-ID: <093cb726-76e5-421d-8ed3-9547bcd0f3e6@a39g2000prl.googlegroups.com> On Feb 15, 10:27?am, Steven D'Aprano wrote: > Philipp Pagel wrote: > > zaheer.ag... at gmail.com wrote: > >> Hi > > >> How do i read ?a file in Python and search a particular pattern > >> like I have a file char.txt ?which has > > >> Mango=sweet > >> Sky=blue > > >> I want to get the strings sweet and blue,How to do this..? > > > If your entire file consists of such key=value pairs you may want to > > properly parse them: > > The proper way to parse them would be with the ConfigParser module. > > The only negative with ConfigParser is that it requires a section label. In > my experience it is quite common for INI files with only a single section > to leave out the label. > > -- > Steven Thanks to all of you,I used to ConfigParser worked fine. -Zaheer From __peter__ at web.de Sun Feb 15 04:05:32 2009 From: __peter__ at web.de (Peter Otten) Date: Sun, 15 Feb 2009 10:05:32 +0100 Subject: How to peek inside a decorated function References: <01a7abfe$0$20629$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Suppose I have a function f() which I know has been decorated, but I don't > have access to the original undecorated function any longer: > > def reverse(func): > def f(*args): > args = list(args) > args.reverse() > return func(*args) > return f > > def say(*args): > print args > > rsay = reverse(say) > del say > > > Is there any way to peek inside the decorated function rsay() to get > access to the undecorated function say()? > > If I look at the code object I can see a reference to the original: > >>>> rsay.func_code.co_names > ('list', 'args', 'reverse', 'func') > > and if I disassemble the code object I can see it being dereferenced: > >>>> dis.dis(rsay.func_code) > [snip for brevity] > 5 22 LOAD_DEREF 0 (func) > 25 LOAD_FAST 0 (args) > 28 CALL_FUNCTION_VAR 0 > 31 RETURN_VALUE > > but if I look at the closure object, nothing seems useful: > >>>> dir(rsay.func_closure[0]) > ['__class__', '__cmp__', '__delattr__', '__doc__', > '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', > '__reduce_ex__', '__repr__', '__setattr__', '__str__'] > > > and I can't find any other attributes which refers back to the undecorated > original function. > > Following Terry's lead it turns out that cell contents become easily accessible in python 2.5: $ cat cellcontents.py """ >>> def reverse(func): ... def f(*args): ... args = list(args) ... args.reverse() ... return func(*args) ... return f ... >>> def say(*args): ... print args ... >>> rsay = reverse(say) >>> del say >>> c = rsay.func_closure[0] >>> "cell_contents" in dir(c) True >>> c.cell_contents(1,2,3) (1, 2, 3) >>> """ import doctest doctest.testmod() $ python2.6 cellcontents.py $ python2.5 cellcontents.py $ python2.4 cellcontents.py ********************************************************************** File "cellcontents.py", line 15, in __main__ Failed example: "cell_contents" in dir(c) Expected: True Got: False ********************************************************************** File "cellcontents.py", line 17, in __main__ Failed example: c.cell_contents(1,2,3) Exception raised: Traceback (most recent call last): File "doctest.py", line 1248, in __run compileflags, 1) in test.globs File "", line 1, in ? c.cell_contents(1,2,3) AttributeError: 'cell' object has no attribute 'cell_contents' ********************************************************************** 1 items had failures: 2 of 7 in __main__ ***Test Failed*** 2 failures. Peter From mail at timgolden.me.uk Sun Feb 15 04:53:24 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Sun, 15 Feb 2009 09:53:24 +0000 Subject: GetKeyboardLayoutName Win32API In-Reply-To: References: Message-ID: <4997E614.2080209@timgolden.me.uk> Tsolakos Stavros wrote: > Hi all. > > I was trying to find a way to read the currently selected input layout > from an app written in python. I am aware that if the app were written > in C, I would have to call the GetKeyboardLayoutName() function. How can > this be done in Python? I want to avoid writing an extension just for > this. The function is not available through pywin32. import ctypes s = ctypes.create_unicode_buffer (1024) ctypes.windll.user32.GetKeyboardLayoutNameW (s) print s.value TJG From mail at microcorp.co.za Sun Feb 15 05:04:37 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sun, 15 Feb 2009 12:04:37 +0200 Subject: Can Python serial support run at 45.45 baud? References: <4996e984$0$1657$742ec2ed@news.sonic.net><-rednU9RmNnrbwvUnZ2dnUVZ_sHinZ2d@posted.usinternet> <4996F7A0.4060008@mrabarnett.plus.com> Message-ID: <000201c98f58$2f7ec160$0d00a8c0@hendrik> "MRAB" wrote: > Grant Edwards wrote: > > On 2009-02-14, John Nagle wrote: > > > >> Can Python's serial port support be made to run at 45.45 baud, > >> the old "60 speed" Teletype machine speed? > > > > If your hardware and OS supports it, Python can be made to > > support it. > > > [snip] > I had a quick look at the Windows API. The struct member for the baud > rate is of type DWORD, ie an integer. I think there could be other hassles - the baud rate is basically derived by setting a divisor that divides a high frequency clock that is fed to the UART chip. Now this means that the frequency, and the maximum value of the divisor, defines the lowest rate that can be attained. The chips are standard, so the maximum divisor is fixed, but the frequency fed the chip is a design parameter of the motherboard. So you could be lucky, or you might have to change the hardware... - Hendrik From stefan_ml at behnel.de Sun Feb 15 05:05:34 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 15 Feb 2009 11:05:34 +0100 Subject: ImportError: dynamic module does not define init function (inittypes) In-Reply-To: References: Message-ID: <4997e8ee$0$31879$9b4e6d93@newsspool3.arcor-online.net> konteya joshi wrote: > I see the following error on running the program: > > 'import site' failed; use -v for traceback > Traceback (most recent call last): > File "skyline\alpine_kickoff.py", line 6, in ? > import re > File "C:\Perforce\qa\testware\build\vmqa\python\python-2.4.1-as\lib\re.py", > line 5, in ? > from sre import * > File "C:\Per\qa\test\build\vmqa\python\python-2.4.1-as\lib\sre.py", > line 265, in ? > import copy_reg > File "C:\Per\qa\test\build\vmqa\python\python-2.4.1-as\lib\copy_reg.py", > line 7, in ? > from types import ClassType as _ClassType > ImportError: dynamic module does not define init function (inittypes) > > Any body who would have an idea on what might be going wrong? > > I have python-2.4.1-as directory in my PYTHONPATH which contains the > Lib,libs...etc in the directory. The Lib contains the re,sre,copy_reg > inside the directory. Check if you have a file "types.dll" somewhere in your PYTHONPATH. If Python finds such a file when resolving the "import types" statement, it will try to import the DLL instead of the correct module. Stefan From mail at microcorp.co.za Sun Feb 15 05:18:37 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sun, 15 Feb 2009 12:18:37 +0200 Subject: Can Python serial support run at 45.45 baud? References: <4996e984$0$1657$742ec2ed@news.sonic.net><-rednU9RmNnrbwvUnZ2dnUVZ_sHinZ2d@posted.usinternet><49970561$0$1642$742ec2ed@news.sonic.net> <49970ce7$0$1665$742ec2ed@news.sonic.net> Message-ID: <000301c98f58$30144aa0$0d00a8c0@hendrik> "John Nagle" wrote: > So the correct combination, 5 bits with 1.5 stop bits, isn't supported in > Python. 1 stop bit will not physically work on Baudot teletypes; the > main camshaft doesn't come around fast enough. (Yes, there's an actual > mechanical reason for 1.5 stop bits.) Requesting 2 stop bits at the > Python level gets a reject at the Win32 level. (Not sure why Win32 > doesn't allow that; extra stop bits just add delay, but don't hurt > anything. But it's not supported.) If you can get down so low in baud rate, then you can fudge it in software. Set the port to the single stop bit, and make a transmit character function that outputs a single character and a flush(), and then waits for a bit time or so - time.sleep(0.022) will do the trick - means you have to make a string transmitter that calls your character transmitter - you cannot just write a string to the port - but that is no great hardship. The receive side will not be a problem, as the syncing is done every char. - Hendrik From hniksic at xemacs.org Sun Feb 15 05:27:36 2009 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Sun, 15 Feb 2009 11:27:36 +0100 Subject: How to peek inside a decorated function References: <01a7abfe$0$20629$c3e8da3@news.astraweb.com> Message-ID: <87ocx4hu5j.fsf@mulj.homelinux.net> Steven D'Aprano writes: > Suppose I have a function f() which I know has been decorated, but I don't > have access to the original undecorated function any longer: > > def reverse(func): > def f(*args): > args = list(args) > args.reverse() > return func(*args) > return f > > def say(*args): > print args > > rsay = reverse(say) > del say > > Is there any way to peek inside the decorated function rsay() to get access > to the undecorated function say()? This works in Python 2.5.2: >>> rsay.func_closure[0].cell_contents Of course, this applies only if you know there's only one free variable, and you know that the decorator is in fact implemented with a closure, and so on. >>>> dir(rsay.func_closure[0]) > ['__class__', '__cmp__', '__delattr__', '__doc__', > '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', > '__reduce_ex__', '__repr__', '__setattr__', '__str__'] I got 'cell_contents' as well when I did the 'dir', at least under Python 2.5.2. From mail at microcorp.co.za Sun Feb 15 05:40:34 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sun, 15 Feb 2009 12:40:34 +0200 Subject: Fw: Can Python serial support run at 45.45 baud? Message-ID: <001201c98f59$d53a5140$0d00a8c0@hendrik> "Hendrik van Rooyen" wrote: > If you can get down so low in baud rate, then you can fudge it in software. > Set the port to the single stop bit, and make a transmit character function > that outputs a single character and a flush(), and then waits for a bit time > or so - time.sleep(0.022) will do the trick - means you have to make > a string transmitter that calls your character transmitter - you cannot > just write a string to the port - but that is no great hardship. Talking nonsense again - the sleep time must not be just the bit you want to add to the character, but the full character time, start bit, five data, stop + 1/2 bit time. - 7.5 * 22 = 165 milliseconds. - Hendrik From castironpi at gmail.com Sun Feb 15 05:48:08 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 15 Feb 2009 02:48:08 -0800 (PST) Subject: How to peek inside a decorated function References: <01a7abfe$0$20629$c3e8da3@news.astraweb.com> <87ocx4hu5j.fsf@mulj.homelinux.net> Message-ID: <4af8fc75-c2ef-4c9c-8829-560a9ae4df6c@r34g2000vbp.googlegroups.com> On Feb 15, 4:27?am, Hrvoje Niksic wrote: > Steven D'Aprano writes: > > Suppose I have a function f() which I know has been decorated, but I don't > > have access to the original undecorated function any longer: > > > def reverse(func): > > ? ? def f(*args): > > ? ? ? ? args = list(args) > > ? ? ? ? args.reverse() > > ? ? ? ? return func(*args) > > ? ? return f > > > def say(*args): > > ? ? print args > > > rsay = reverse(say) > > del say > > > Is there any way to peek inside the decorated function rsay() to get access > > to the undecorated function say()? > > This works in Python 2.5.2: > > >>> rsay.func_closure[0].cell_contents > > > > Of course, this applies only if you know there's only one free > variable, and you know that the decorator is in fact implemented with > a closure, and so on. > > >>>> dir(rsay.func_closure[0]) > > ['__class__', '__cmp__', '__delattr__', '__doc__', > > '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', > > '__reduce_ex__', '__repr__', '__setattr__', '__str__'] > > I got 'cell_contents' as well when I did the 'dir', at least under > Python 2.5.2. Assume the decorator preserves the function at all; that is, it doesn't discard it. Then you can scan func_closure. In poor cases, you might have to search through a nested decoration as well. In others, such as when the decorator is an object, not a function, you might have to search an instance dictionary, also possibly nested. The leading assumption also requires that the function is stored in a Python object; that is, not in a C structure. In Python 3.0.1: >>> def f( fun ): ... def g( *ar, **kw ): ... return fun( *ar, **kw ) ... return g ... >>> def h( x ): ... print( x ) ... >>> i= f( h ) >>> i.__closure__[0].cell_contents From zaheer.agadi at gmail.com Sun Feb 15 05:55:41 2009 From: zaheer.agadi at gmail.com (zaheer.agadi at gmail.com) Date: Sun, 15 Feb 2009 02:55:41 -0800 (PST) Subject: Python WebDAV library Message-ID: <75f5d38b-bb93-4d9d-bc64-d073ee0c1992@w1g2000prm.googlegroups.com> Hi I am looking for WebDAV library in Python I found one in http://users.sfo.com/~jdavis/Software/PyDAV/readme.html and one here http://pypi.python.org/packages/any/P/Python_WebDAV_Library/ I basically have to upload and download files/folders to/from a server should be able to copy them move them and delete. Any body know if these serve the purpose or there are libraries more promising than listed above Thanks From steve at pearwood.info Sun Feb 15 06:39:32 2009 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 15 Feb 2009 22:39:32 +1100 Subject: How to peek inside a decorated function References: <01a7abfe$0$20629$c3e8da3@news.astraweb.com> <87ocx4hu5j.fsf@mulj.homelinux.net> Message-ID: <01a7f49a$0$11497$c3e8da3@news.astraweb.com> Hrvoje Niksic wrote: >> Is there any way to peek inside the decorated function rsay() to get >> access to the undecorated function say()? > > This works in Python 2.5.2: > >>>> rsay.func_closure[0].cell_contents > Thanks to everyone who responded. The reason I ask is because I've just spent the weekend battling with doctests of decorated functions, and discovering that without functools.wraps() all my doctests weren't being called. I'm wondering whether it would be a good idea for doctest to auto-detect tests in closures. This is not needed if you call wraps() appropriately, but you might not always do that. -- Steven From __peter__ at web.de Sun Feb 15 07:23:33 2009 From: __peter__ at web.de (Peter Otten) Date: Sun, 15 Feb 2009 13:23:33 +0100 Subject: How to peek inside a decorated function References: <01a7abfe$0$20629$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Suppose I have a function f() which I know has been decorated, but I don't > have access to the original undecorated function any longer: > > def reverse(func): > def f(*args): > args = list(args) > args.reverse() > return func(*args) > return f > > def say(*args): > print args > > rsay = reverse(say) > del say > > > Is there any way to peek inside the decorated function rsay() to get > access to the undecorated function say()? Here's a hack for Python 2.4: def make_extractor(x=None): def extractor(): return x return extractor extractor = make_extractor() function = type(extractor) def get_cell_contents(cell): return function(extractor.func_code, {}, "yadda", None, (cell,))() get_cell_contents(rsay.func_closure[0])(1,2,3) Peter From duncan.booth at invalid.invalid Sun Feb 15 07:52:12 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 15 Feb 2009 12:52:12 GMT Subject: How to peek inside a decorated function References: <01a7abfe$0$20629$c3e8da3@news.astraweb.com> <87ocx4hu5j.fsf@mulj.homelinux.net> <01a7f49a$0$11497$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > > The reason I ask is because I've just spent the weekend battling with > doctests of decorated functions, and discovering that without > functools.wraps() all my doctests weren't being called. I'm wondering > whether it would be a good idea for doctest to auto-detect tests in > closures. > > This is not needed if you call wraps() appropriately, but you might not > always do that. > I don't think it is a good idea to call the wrapped doctests automatically, but I do think it might be a good idea to detect and warn about anything which looks like it is a wrapper where the wrapped function includes a doctest and the wrapper doesn't. -- Duncan Booth http://kupuguy.blogspot.com From steve at holdenweb.com Sun Feb 15 07:53:44 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 15 Feb 2009 07:53:44 -0500 Subject: Who's on First, IDLE or pythonWin? Dialog Problem? In-Reply-To: References: <1a05ac6c-9c7e-4411-a702-99bae941f948@h20g2000yqn.googlegroups.com> Message-ID: W. eWatson wrote: > It looks like I got an accidentally case of send message 3 times. Well, > here's a correct below. >> The question now is what can I do about it? reboot? >> >> Just to re-iterate the answer I provided to *>the question to a post >> above<*, I'm using Tkinter for the program's GUI. >> > > Just stop running the damned thing under IDLE. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sun Feb 15 08:03:42 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 15 Feb 2009 08:03:42 -0500 Subject: hpw to convert a linux python script ? In-Reply-To: <7a9c25c20902122237i125b8610v1d553979c98a95c9@mail.gmail.com> References: <8848a16f-83db-4acf-a1cc-46653869f27c@z1g2000yqn.googlegroups.com> <1ac73184-be09-4b56-8ad1-7cd4896e0f7c@z6g2000pre.googlegroups.com> <7a9c25c20902122237i125b8610v1d553979c98a95c9@mail.gmail.com> Message-ID: Stephen Hansen wrote: >> # Absolute path to the directory that holds media. >> # Example: "/home/media/media.lawrence.com/" >> MEDIA_ROOT = fsroot+'/Projects/PytDj/images/' >> >> Note that most Windows APIs allow you to use the forward slash as a >> delimiter. It's mostly the command line and Windows Explorer that are >> snotty about insisting on the backslash. > > Idle curiosity, why do you prefer that to: > > MEDIA_ROOT = os.path.join(fsroot, 'Projects', 'PytDj', 'images') > > Not arguing that one is actually better then the other, just curious. > Going for "good enough", I suppose. It's more readable, at least, not that that makes a *huge* difference. > In my own environment we have grown a whole big filesystem abstraction > layer because we have to be able to address the same resources on > network volumes in the same client on multiple OS's (mainly windows > and mac presently, but a linux client has long been a > consideration),... and on the mac having to sometimes use mac paths > (":this:that:other") and sometimes posix paths ("/this/that/other") > depending on what API layer I'm poking at in a given point of view... > so personally I just end up being mildly curious how everyone else > handles paths and such. > > Cuz it was quite a bit of a pain early on. The old Mac paths would indeed require your solution, which is strictly speaking the best. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From deets at nospam.web.de Sun Feb 15 08:05:04 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 15 Feb 2009 14:05:04 +0100 Subject: Easier to wrap C or C++ libraries? In-Reply-To: <87vdrciysm.fsf@mulj.homelinux.net> References: <7baacd31-58c8-4e11-b25a-f827cc63d6ac@e18g2000yqo.googlegroups.com> <6vocf5Fkv5a9U1@mid.uni-berlin.de> <87vdrciysm.fsf@mulj.homelinux.net> Message-ID: <6vqi81FliulnU1@mid.uni-berlin.de> Hrvoje Niksic schrieb: > "Diez B. Roggisch" writes: > >> The answer is easy: if you use C, you can use ctypes to create a >> wrapper - with pure python, no compilation, no platform issues. > > The last part is not true. ctypes doesn't work on 64-bit > architectures, nor does it work when Python is built with non-gcc Unix > compilers. It's not working on Windows with the standard distribution? I'm sorry for spreading FUD about being no issues at all, that apparently wasn't right - however, so far I didn't encounter them. Diez From steve at holdenweb.com Sun Feb 15 08:41:17 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 15 Feb 2009 08:41:17 -0500 Subject: "Byte" type? In-Reply-To: References: <4997aa38$0$1678$742ec2ed@news.sonic.net> Message-ID: Erik Max Francis wrote: > John Nagle wrote: >> With "bytearray", the element type is considered to be "unsigned >> byte", >> or so says PEP 3137: "The element data type is always 'B' (i.e. >> unsigned byte)." >> >> Let's try: >> >> Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit >> (Intel)] on >> win32 >> >>> xx = b'x' >> >>> repr(xx) >> "'x'" >> >>> repr(xx[0]) >> "'x'" >> >>> repr(xx[0][0]) >> "'x'" >> >>> >> >> But that's not what "repr" indicates. The bytearray element is >> apparently >> being promoted to "bytes" as soon as it comes out of the array. > > There's no distinction byte type. A single character of a bytes type is > also a bytes. > Beware, also, that in 2.6 the "bytes" type is essentially an ugly hack to enable easier forward compatibility with the 3.X series ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From roy at panix.com Sun Feb 15 08:51:29 2009 From: roy at panix.com (Roy Smith) Date: Sun, 15 Feb 2009 08:51:29 -0500 Subject: Can Python serial support run at 45.45 baud? References: <4996e984$0$1657$742ec2ed@news.sonic.net> <-rednU9RmNnrbwvUnZ2dnUVZ_sHinZ2d@posted.usinternet> <49970561$0$1642$742ec2ed@news.sonic.net> <49970ce7$0$1665$742ec2ed@news.sonic.net> <49972f28$0$1622$742ec2ed@news.sonic.net> Message-ID: In article , Grant Edwards wrote: > My guess is that it was _supposed_ to > be a CRC routine, but somebody botched it. They used the same > botched routine on the host end when they did testing, so > nobody noticed it was broken. Stuff like this happens all the time. That's why RFC 2026 requires, "a specification from which at least two independent and interoperable implementations from different code bases have been developed". To drag this back on topic, however, it's interesting to note that Python itself has been successful, while still being essentially a single implementation. From benjamin at python.org Sun Feb 15 09:32:15 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sun, 15 Feb 2009 14:32:15 +0000 (UTC) Subject: "Byte" type? References: <4997aa38$0$1678$742ec2ed@news.sonic.net> Message-ID: Steve Holden holdenweb.com> writes: > Beware, also, that in 2.6 the "bytes" type is essentially an ugly hack > to enable easier forward compatibility with the 3.X series ... It's not an ugly hack. It just isn't all that you might hope it'd live up to be. From theller at python.net Sun Feb 15 09:45:10 2009 From: theller at python.net (Thomas Heller) Date: Sun, 15 Feb 2009 15:45:10 +0100 Subject: Easier to wrap C or C++ libraries? In-Reply-To: References: <7baacd31-58c8-4e11-b25a-f827cc63d6ac@e18g2000yqo.googlegroups.com> <6vocf5Fkv5a9U1@mid.uni-berlin.de> <87vdrciysm.fsf@mulj.homelinux.net> Message-ID: <6vqo3kFlerq0U1@mid.individual.net> Christian Heimes schrieb: > Hrvoje Niksic schrieb: >> "Diez B. Roggisch" writes: >> >>> The answer is easy: if you use C, you can use ctypes to create a >>> wrapper - with pure python, no compilation, no platform issues. >> >> The last part is not true. ctypes doesn't work on 64-bit >> architectures, nor does it work when Python is built with non-gcc Unix >> compilers > > ctypes works on 64bit systems, too. However it's a pain in the ... back > to write code with ctypes that works across all platforms. I used to use > ctypes for wrapper but eventually I switched to Cython. > I have plans to add the types from the ansi-c standard to ctypes, like these: stddef.h: ptrdiff_t, size_t, wchar_t signal.h: sig_atomic_t stdio.h: FILE, fpos_t, stderr, stdout, stdin stdlib.h: div_t, ldiv_t time.h: clock_t, time_t, struct tm Do you think that would have helped for writing cross-platform wrappers? Thomas From google at mrabarnett.plus.com Sun Feb 15 09:56:12 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sun, 15 Feb 2009 14:56:12 +0000 Subject: Can Python serial support run at 45.45 baud? In-Reply-To: References: <4996e984$0$1657$742ec2ed@news.sonic.net> <-rednU9RmNnrbwvUnZ2dnUVZ_sHinZ2d@posted.usinternet> <49970561$0$1642$742ec2ed@news.sonic.net> <49970ce7$0$1665$742ec2ed@news.sonic.net> <49972f28$0$1622$742ec2ed@news.sonic.net> Message-ID: <49982D0C.8020604@mrabarnett.plus.com> Roy Smith wrote: > In article , > Grant Edwards wrote: > >> My guess is that it was _supposed_ to be a CRC routine, but >> somebody botched it. They used the same botched routine on the >> host end when they did testing, so nobody noticed it was broken. > > Stuff like this happens all the time. That's why RFC 2026 requires, > "a specification from which at least two independent and > interoperable implementations from different code bases have been > developed". > > To drag this back on topic, however, it's interesting to note that > Python itself has been successful, while still being essentially a > single implementation. > That's because it's open source, so many people can test and debug it. From deets at nospam.web.de Sun Feb 15 10:23:00 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 15 Feb 2009 16:23:00 +0100 Subject: python in emacs In-Reply-To: References: Message-ID: <6vqqakFlct0rU1@mid.uni-berlin.de> kentandkat at sbcglobal.net schrieb: > When I visit a file with extension .py, emacs says "loading > python...done", and gives me a "python" menu with options like "start > interpreter" and "eval buffer". When I try to use one of these options > emacs says "loading compile...done", then hangs and has to be shut down > from the task manager. The Python folder is in my PATH variable and > works fine from the command line (or with IDLE). I'm using emacs-22.3 on > windows xp, and have the same problem with both python-2.2 and > python-3.0. Anybody got any tips, or should I just give up and use some > other editor? Did you try setting the python interpreter with the full path? Diez From steve at holdenweb.com Sun Feb 15 10:32:33 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 15 Feb 2009 10:32:33 -0500 Subject: "Byte" type? In-Reply-To: References: <4997aa38$0$1678$742ec2ed@news.sonic.net> Message-ID: Benjamin Peterson wrote: > Steve Holden holdenweb.com> writes: >> Beware, also, that in 2.6 the "bytes" type is essentially an ugly hack >> to enable easier forward compatibility with the 3.X series ... > > It's not an ugly hack. It just isn't all that you might hope it'd live up to be. > I take it back It's not an ugly hack It's just an aliased type regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sun Feb 15 10:33:57 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 15 Feb 2009 10:33:57 -0500 Subject: Can Python serial support run at 45.45 baud? In-Reply-To: <49982D0C.8020604@mrabarnett.plus.com> References: <4996e984$0$1657$742ec2ed@news.sonic.net> <-rednU9RmNnrbwvUnZ2dnUVZ_sHinZ2d@posted.usinternet> <49970561$0$1642$742ec2ed@news.sonic.net> <49970ce7$0$1665$742ec2ed@news.sonic.net> <49972f28$0$1622$742ec2ed@news.sonic.net> <49982D0C.8020604@mrabarnett.plus.com> Message-ID: MRAB wrote: > Roy Smith wrote: >> In article , Grant >> Edwards wrote: >> >>> My guess is that it was _supposed_ to be a CRC routine, but >>> somebody botched it. They used the same botched routine on the >>> host end when they did testing, so nobody noticed it was broken. >> >> Stuff like this happens all the time. That's why RFC 2026 requires, >> "a specification from which at least two independent and >> interoperable implementations from different code bases have been >> developed". >> >> To drag this back on topic, however, it's interesting to note that >> Python itself has been successful, while still being essentially a >> single implementation. >> > That's because it's open source, so many people can test and debug it. IronPython, J(P)ython and PyPy? TinyPython? Jython must be over ten years old now. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From kentandkat at sbcglobal.net Sun Feb 15 10:40:55 2009 From: kentandkat at sbcglobal.net (kentandkat at sbcglobal.net) Date: Sun, 15 Feb 2009 09:40:55 -0600 Subject: python in emacs Message-ID: When I visit a file with extension .py, emacs says "loading Python...done" and gives me a "Python" menu with options like "start interpreter" and "eval buffer". When I try to use these options, or others on the "Python" menu, emacs says "loading compile...done", then hangs and has to be shut down from the task bar. The folder containing python is in my PATH and python works from the command line (and IDLE). Neither the emacs nor the python directory tree has any spaces in it. I'm using emacs-22.3 on windows xp and have tried using both python-2.2 and python-3.0 in emacs with the same problem. Can anyone give me a tip? Thanks, Kent. From nick at craig-wood.com Sun Feb 15 11:31:55 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Sun, 15 Feb 2009 10:31:55 -0600 Subject: Easier to wrap C or C++ libraries? References: <7baacd31-58c8-4e11-b25a-f827cc63d6ac@e18g2000yqo.googlegroups.com> <6vocf5Fkv5a9U1@mid.uni-berlin.de> <87vdrciysm.fsf@mulj.homelinux.net> Message-ID: Christian Heimes wrote: > Hrvoje Niksic schrieb: > > "Diez B. Roggisch" writes: > > > >> The answer is easy: if you use C, you can use ctypes to create a > >> wrapper - with pure python, no compilation, no platform issues. > > > > The last part is not true. ctypes doesn't work on 64-bit > > architectures, nor does it work when Python is built with non-gcc Unix > > compilers > > ctypes works on 64bit systems, too. However it's a pain in the ... back > to write code with ctypes that works across all platforms. I used to use > ctypes for wrapper but eventually I switched to Cython. What sort of problems have you had? I find as long as I use the same types as the C code actually uses it all works fine. If on a 64 bit platform long is 64 bits then it will be under ctypes too. -- Nick Craig-Wood -- http://www.craig-wood.com/nick From nagle at animats.com Sun Feb 15 11:57:12 2009 From: nagle at animats.com (John Nagle) Date: Sun, 15 Feb 2009 08:57:12 -0800 Subject: "Byte" type? In-Reply-To: References: <4997aa38$0$1678$742ec2ed@news.sonic.net> Message-ID: <499841bf$0$1624$742ec2ed@news.sonic.net> Benjamin Peterson wrote: > Steve Holden holdenweb.com> writes: >> Beware, also, that in 2.6 the "bytes" type is essentially an ugly hack >> to enable easier forward compatibility with the 3.X series ... > > It's not an ugly hack. It just isn't all that you might hope it'd live up to be. The semantics aren't what the naive user would expect. One would expect an element of a bytearray to be a small integer. But instead, it has string-like behavior. "+" means concatenate, not add. The bit operators don't work at all. Python 2.6.1 ... >>> a = b'A' >>> b = b'B' >>> a+b 'AB' >>> a[0]+b[0] 'AB' >>>>>> a = b'A' >>> b = b'B' >>> a+b 'AB' >>> a[0]+b[0] 'AB' >>> >>> a & b Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for &: 'str' and 'str' Given that the intent of bytearray is that it's a data type for handling raw binary data of unknown format, one might expect it to behave like "array.array('B')", which is an array of unsigned bytes that are treated as integers. But that's not how "bytearray" works. "bytearray" is more like the old meaning of "str", before Unicode support, circa Python 2.1. I sort of understand the mindset, but the documentation needs to be improved. Right now, we have a few PEPs and the 2.6 "New features" article, but no comprehensive documentation. The relationship between "str", "unicode", "bytearray", "array.array('B')", and integers, and how this changes from version to version of Python, needs to be made clearer, or conversion to 2.6/3.0 will not happen rapidly. John Nagle From benjamin.kaplan at case.edu Sun Feb 15 12:16:10 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 15 Feb 2009 12:16:10 -0500 Subject: "Byte" type? In-Reply-To: <499841bf$0$1624$742ec2ed@news.sonic.net> References: <4997aa38$0$1678$742ec2ed@news.sonic.net> <499841bf$0$1624$742ec2ed@news.sonic.net> Message-ID: On Sun, Feb 15, 2009 at 11:57 AM, John Nagle wrote: > Benjamin Peterson wrote: > >> Steve Holden holdenweb.com> writes: >> >>> Beware, also, that in 2.6 the "bytes" type is essentially an ugly hack >>> to enable easier forward compatibility with the 3.X series ... >>> >> >> It's not an ugly hack. It just isn't all that you might hope it'd live up >> to be. >> > > The semantics aren't what the naive user would expect. One would > expect an element of a bytearray to be a small integer. But instead, > it has string-like behavior. "+" means concatenate, not add. > The bit operators don't work at all. > Because b'x' is NOT a bytearray. It is a bytes object. When you actually use a bytearray, it behaves like you expect. >>> type(b'x') >>> type(bytearray(b'x')) >>> ba = bytearray(b'abc') >>> ba[0] + ba[1] 195 > > Python 2.6.1 ... > >>> a = b'A' > >>> b = b'B' > >>> a+b > 'AB' > >>> a[0]+b[0] > 'AB' > >>>>>> a = b'A' > >>> b = b'B' > >>> a+b > 'AB' > >>> a[0]+b[0] > 'AB' > >>> > >>> a & b > Traceback (most recent call last): > File "", line 1, in > TypeError: unsupported operand type(s) for &: 'str' and 'str' > > Given that the intent of bytearray is that it's a data type for > handling raw binary data of unknown format, one might expect it to behave > like > "array.array('B')", which is an array of unsigned bytes that are > treated as integers. But that's not how "bytearray" works. "bytearray" > is more like the old meaning of "str", before Unicode support, circa Python > 2.1. > > I sort of understand the mindset, but the documentation needs to be > improved. > Right now, we have a few PEPs and the 2.6 "New features" article, but > no comprehensive documentation. The relationship between "str", "unicode", > "bytearray", "array.array('B')", and integers, and how this changes from > version to version of Python, needs to be made clearer, or conversion > to 2.6/3.0 will not happen rapidly. > > John Nagle > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From pauljefferson at gmail.com Sun Feb 15 12:31:23 2009 From: pauljefferson at gmail.com (Paul) Date: Sun, 15 Feb 2009 09:31:23 -0800 (PST) Subject: BaseHttpServer Message-ID: <718d890c-dfce-416d-934b-db0a47fc4678@b16g2000yqb.googlegroups.com> Hi, I currently have a webserver using BaseHttpServe that serves images like this: if self.path.endswith(".jpg"): print(curdir + sep + self.path) f = open(curdir + sep + self.path,"b") self.send_response(200) self.send_header('Content-type', 'image/jpg') self.end_headers() self.wfile.write(f.read()) f.close() return Whilst it works, it does take quite a while to load (approx 10secs for a 4mb file even though its over the local connection) - does anyone have any hints/tips for speeding it up? Thanks, Paul From fasteliteprogrammer at yahoo.com Sun Feb 15 12:41:46 2009 From: fasteliteprogrammer at yahoo.com (Craig) Date: Sun, 15 Feb 2009 09:41:46 -0800 (PST) Subject: python in emacs Message-ID: <107637.91428.qm@web36506.mail.mud.yahoo.com> I would go to ubuntu linux if you can. --- On Sun, 2/15/09, Diez B. Roggisch wrote: From: Diez B. Roggisch Subject: Re: python in emacs To: python-list at python.org Date: Sunday, February 15, 2009, 9:23 AM kentandkat at sbcglobal.net schrieb: > When I visit a file with extension .py, emacs says "loading > python...done", and gives me a "python" menu with options like "start > interpreter" and "eval buffer". When I try to use one of these options > emacs says "loading compile...done", then hangs and has to be shut down > from the task manager. The Python folder is in my PATH variable and > works fine from the command line (or with IDLE). I'm using emacs-22.3 on > windows xp, and have the same problem with both python-2.2 and > python-3.0. Anybody got any tips, or should I just give up and use some > other editor? Did you try setting the python interpreter with the full path? Diez -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Sun Feb 15 12:46:56 2009 From: python at bdurham.com (python at bdurham.com) Date: Sun, 15 Feb 2009 12:46:56 -0500 Subject: Pythonic way to determine if a string is a number Message-ID: <1234720016.23422.1300488109@webmail.messagingengine.com> What's the Pythonic way to determine if a string is a number? By number I mean a valid integer or float. I searched the string and cMath libraries for a similar function without success. I can think of at least 3 or 4 ways to build my own function. Here's what I came up with as a proof-of-concept. Are there 'better' ways to perform this type of test? Thanks, Malcolm def isnumber( input ): try: if '.' in input: num = float( input ) else: num = int( input ) return True except ValueError: return False if __name__ == '__main__': tests = """ 12 -12 -12.34 .0 . 1 2 3 1 . 2 just text """ for test in tests.split( '\n' ): print 'test (%0s), isnumber: %1s' % \ ( test.strip(), isnumber( test ) ) From lists at cheimes.de Sun Feb 15 12:51:57 2009 From: lists at cheimes.de (Christian Heimes) Date: Sun, 15 Feb 2009 18:51:57 +0100 Subject: Pythonic way to determine if a string is a number In-Reply-To: <1234720016.23422.1300488109@webmail.messagingengine.com> References: <1234720016.23422.1300488109@webmail.messagingengine.com> Message-ID: python at bdurham.com schrieb: > What's the Pythonic way to determine if a string is a number? By > number I mean a valid integer or float. > > I searched the string and cMath libraries for a similar function > without success. I can think of at least 3 or 4 ways to build my > own function. > > Here's what I came up with as a proof-of-concept. Are there > 'better' ways to perform this type of test? > > Thanks, > Malcolm > > > def isnumber( input ): > try: > if '.' in input: > num = float( input ) > else: > num = int( input ) > return True > > except ValueError: > return False You code doesn't check for several float representations like "1e10", "1E10", "inf" and "nan". Christian From pavanmishra at gmail.com Sun Feb 15 12:54:31 2009 From: pavanmishra at gmail.com (Pavan Mishra) Date: Sun, 15 Feb 2009 09:54:31 -0800 (PST) Subject: PHP like documentation? Message-ID: <0b0364a9-85a9-4fe1-822b-07c1d7eeacd1@p23g2000prp.googlegroups.com> I was wondering if I can use python documentation source (reStructuredText) and restructure it along the lines of PHP documentation. Allowing users to add comments, improving search etc. I was thinking if it would be useful. From metolone+gmane at gmail.com Sun Feb 15 12:58:33 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Sun, 15 Feb 2009 09:58:33 -0800 Subject: "Byte" type? References: <4997aa38$0$1678$742ec2ed@news.sonic.net> <499841bf$0$1624$742ec2ed@news.sonic.net> Message-ID: "John Nagle" wrote in message news:499841bf$0$1624$742ec2ed at news.sonic.net... > Benjamin Peterson wrote: >> Steve Holden holdenweb.com> writes: >>> Beware, also, that in 2.6 the "bytes" type is essentially an ugly hack >>> to enable easier forward compatibility with the 3.X series ... >> >> It's not an ugly hack. It just isn't all that you might hope it'd live up >> to be. > > The semantics aren't what the naive user would expect. One would > expect an element of a bytearray to be a small integer. But instead, > it has string-like behavior. "+" means concatenate, not add. > The bit operators don't work at all. > > Python 2.6.1 ... > >>> a = b'A' > >>> b = b'B' > >>> a+b > 'AB' > >>> a[0]+b[0] > 'AB' > >>>>>> a = b'A' > >>> b = b'B' > >>> a+b > 'AB' > >>> a[0]+b[0] > 'AB' > >>> > >>> a & b > Traceback (most recent call last): > File "", line 1, in > TypeError: unsupported operand type(s) for &: 'str' and 'str' > > Given that the intent of bytearray is that it's a data type for > handling raw binary data of unknown format, one might expect it to behave > like > "array.array('B')", which is an array of unsigned bytes that are > treated as integers. But that's not how "bytearray" works. "bytearray" > is more like the old meaning of "str", before Unicode support, circa > Python 2.1. It *is* the old meaning of str. It isn't a bytearray object in 2.6.X (and it isn't a bytearray object in 3.X either, but a bytes object): Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> type(b'x') >>> b'x'[0] 'x' As Steve said, it is just an aliased type. In 3.X it is really a bytes object: Python 3.0.1 (r301:69561, Feb 13 2009, 20:04:18) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> type(b'x') >>> b'x'[0] 120 -Mark From philip at semanchuk.com Sun Feb 15 13:03:36 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Sun, 15 Feb 2009 13:03:36 -0500 Subject: Pythonic way to determine if a string is a number In-Reply-To: <1234720016.23422.1300488109@webmail.messagingengine.com> References: <1234720016.23422.1300488109@webmail.messagingengine.com> Message-ID: <2B9BDEC0-5D49-4760-86D7-C36A5FC849C6@semanchuk.com> On Feb 15, 2009, at 12:46 PM, python at bdurham.com wrote: > What's the Pythonic way to determine if a string is a number? By > number I mean a valid integer or float. try: int(number) is_an_int = True except: is_an_int = False try: float(number) is_a_float = True except: is_a_float = False is_a_number = (is_an_int or is_a_float) From nagle at animats.com Sun Feb 15 13:09:09 2009 From: nagle at animats.com (John Nagle) Date: Sun, 15 Feb 2009 10:09:09 -0800 Subject: "Byte" type? In-Reply-To: References: <4997aa38$0$1678$742ec2ed@news.sonic.net> <499841bf$0$1624$742ec2ed@news.sonic.net> Message-ID: <49985A45.7030507@animats.com> Benjamin Kaplan wrote: > On Sun, Feb 15, 2009 at 11:57 AM, John Nagle wrote: > >> Benjamin Peterson wrote: > Because b'x' is NOT a bytearray. It is a bytes object. When you actually use > a bytearray, it behaves like you expect. >>>> type(b'x') > >>>> type(bytearray(b'x')) > >>>> ba = bytearray(b'abc') >>>> ba[0] + ba[1] > 195 That's indeed how Python 2.6 works. But that's not how PEP 3137 says it's supposed to work. Guido: "I propose the following type names at the Python level: * bytes is an immutable array of bytes (PyString) * bytearray is a mutable array of bytes (PyBytes)" ... "Indexing bytes and bytearray returns small ints (like the bytes type in 3.0a1, and like lists or array.array('B'))." (Not true in Python 2.6 - indexing a "bytes" object returns a "bytes" object with length 1.) "b1 + b2: concatenation. With mixed bytes/bytearray operands, the return type is that of the first argument (this seems arbitrary until you consider how += works)." (Not true in Python 2.6 - concatenation returns a bytearray in both cases.) Is this a bug, a feature, a documentation error, or bad design? John Nagle From roy at panix.com Sun Feb 15 13:15:38 2009 From: roy at panix.com (Roy Smith) Date: Sun, 15 Feb 2009 13:15:38 -0500 Subject: Pythonic way to determine if a string is a number References: Message-ID: In article , python at bdurham.com wrote: > What's the Pythonic way to determine if a string is a number? By > number I mean a valid integer or float. try: int(myString) except ValueError: print "That's bogus, man" From lists at cheimes.de Sun Feb 15 13:27:03 2009 From: lists at cheimes.de (Christian Heimes) Date: Sun, 15 Feb 2009 19:27:03 +0100 Subject: relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC In-Reply-To: <74d2b9c1-be68-4585-bb92-36815ca2b759@w35g2000yqm.googlegroups.com> References: <74d2b9c1-be68-4585-bb92-36815ca2b759@w35g2000yqm.googlegroups.com> Message-ID: tkevans schrieb: > Found a couple of references to this in the newsgroup, but no > solutions. > > I'm trying to build libsbml-3.3.0 with python 2.5.4 support on RHEL > 5.3. This RedHat distro has python 2.4.5, and libsbml builds ok with > that release. > > After building 2.5.4 (./configure CFLAGS=-fPIC , as the error message > suggests), ld still croaks here: How about compiling Python as a shared library? ./configure --enable-shared does the trick. Christian From lists at cheimes.de Sun Feb 15 13:27:47 2009 From: lists at cheimes.de (Christian Heimes) Date: Sun, 15 Feb 2009 19:27:47 +0100 Subject: Pythonic way to determine if a string is a number In-Reply-To: <2B9BDEC0-5D49-4760-86D7-C36A5FC849C6@semanchuk.com> References: <1234720016.23422.1300488109@webmail.messagingengine.com> <2B9BDEC0-5D49-4760-86D7-C36A5FC849C6@semanchuk.com> Message-ID: Philip Semanchuk schrieb: > > On Feb 15, 2009, at 12:46 PM, python at bdurham.com wrote: > >> What's the Pythonic way to determine if a string is a number? By >> number I mean a valid integer or float. > > > try: > int(number) > is_an_int = True > except: > is_an_int = False Please don't teach new Python developers to use bare excepts. In fact never use bare excepts at all! Christian From zubeido at yahoo.com.br Sun Feb 15 13:33:15 2009 From: zubeido at yahoo.com.br (aiwarrior) Date: Sun, 15 Feb 2009 10:33:15 -0800 (PST) Subject: Rapidshare to Megaupload script References: Message-ID: Thanks a lot for your input i really needed because i realized these are minor flaws but even so define whether its good or bad code and i really need to improve that. I already implemented the changes you suggested and this one, > cookie = dict(x.split("=") for x in cookie) for me is just very good and really is elegant. An aspect you didn't mention was the > urls.append("http://rapidshare.com/files/" + retrieved_data[0] + "/" + retrieved_data[1]) I think its very hackish and crude but urlparser doesnt seem to accept more than one argument at a time and doing it in a loop seem worse than the current solution. What would you do? Thanks a lot again From zubeido at yahoo.com.br Sun Feb 15 13:33:25 2009 From: zubeido at yahoo.com.br (aiwarrior) Date: Sun, 15 Feb 2009 10:33:25 -0800 (PST) Subject: Rapidshare to Megaupload script References: Message-ID: <896e9948-6dbc-4fb2-9ec2-74bb914166ab@33g2000yqm.googlegroups.com> Thanks a lot for your input i really needed because i realized these are minor flaws but even so define whether its good or bad code and i really need to improve that. I already implemented the changes you suggested and this one, > cookie = dict(x.split("=") for x in cookie) for me is just very good and really is elegant. An aspect you didn't mention was the > urls.append("http://rapidshare.com/files/" + retrieved_data[0] + "/" + retrieved_data[1]) I think its very hackish and crude but urlparser doesnt seem to accept more than one argument at a time and doing it in a loop seem worse than the current solution. What would you do? Thanks a lot again From nagle at animats.com Sun Feb 15 13:35:26 2009 From: nagle at animats.com (John Nagle) Date: Sun, 15 Feb 2009 10:35:26 -0800 Subject: Can Python serial support run at 45.45 baud? In-Reply-To: <49972cf5$0$1612$742ec2ed@news.sonic.net> References: <4996e984$0$1657$742ec2ed@news.sonic.net> <-rednU9RmNnrbwvUnZ2dnUVZ_sHinZ2d@posted.usinternet> <49970561$0$1642$742ec2ed@news.sonic.net> <49970ce7$0$1665$742ec2ed@news.sonic.net> <49972cf5$0$1612$742ec2ed@news.sonic.net> Message-ID: <499858c5$0$1618$742ec2ed@news.sonic.net> John Nagle wrote: > MRAB wrote: >> John Nagle wrote: >> [snip] >>> So the correct combination, 5 bits with 1.5 stop bits, isn't >>> supported in >>> Python. 1 stop bit will not physically work on Baudot teletypes; the >>> main camshaft doesn't come around fast enough. (Yes, there's an actual >>> mechanical reason for 1.5 stop bits.) Requesting 2 stop bits at the >>> Python level gets a reject at the Win32 level. (Not sure why Win32 >>> doesn't allow that; extra stop bits just add delay, but don't hurt >>> anything. But it's not supported.) > > I patched PySerial to support "STOPBITS_ONE5", for 1.5 stop bits, > and the big Teletype Model 15 is now banging out text from Python. Logged in as a PySerial bug, with discussion of fix: [ 2603052 ] 5-bit mode not properly supported on Windows Linux support for nonstandard baud rates is possible, but needs a call to "setserial", which is not standard POSIX. John Nagle From nagle at animats.com Sun Feb 15 13:40:11 2009 From: nagle at animats.com (John Nagle) Date: Sun, 15 Feb 2009 10:40:11 -0800 Subject: "Byte" type? In-Reply-To: References: <4997aa38$0$1678$742ec2ed@news.sonic.net> <499841bf$0$1624$742ec2ed@news.sonic.net> Message-ID: <499859e2$0$1618$742ec2ed@news.sonic.net> Benjamin Kaplan wrote: > On Sun, Feb 15, 2009 at 11:57 AM, John Nagle wrote: > >> Benjamin Peterson wrote: > Because b'x' is NOT a bytearray. It is a bytes object. When you actually use > a bytearray, it behaves like you expect. >>>> type(b'x') > >>>> type(bytearray(b'x')) > >>>> ba = bytearray(b'abc') >>>> ba[0] + ba[1] > 195 That's indeed how Python 2.6 works. But that's not how PEP 3137 says it's supposed to work. Guido: "I propose the following type names at the Python level: * bytes is an immutable array of bytes (PyString) * bytearray is a mutable array of bytes (PyBytes)" ... "Indexing bytes and bytearray returns small ints (like the bytes type in 3.0a1, and like lists or array.array('B'))." (Not true in Python 2.6 - indexing a "bytes" object returns a "bytes" object with length 1.) "b1 + b2: concatenation. With mixed bytes/bytearray operands, the return type is that of the first argument (this seems arbitrary until you consider how += works)." (Not true in Python 2.6 - concatenation returns a bytearray in both cases.) Is this a bug, a feature, a documentation error, or bad design? John Nagle From google at mrabarnett.plus.com Sun Feb 15 13:56:53 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sun, 15 Feb 2009 18:56:53 +0000 Subject: Pythonic way to determine if a string is a number In-Reply-To: References: Message-ID: <49986575.1040902@mrabarnett.plus.com> Roy Smith wrote: > In article , > python at bdurham.com wrote: > >> What's the Pythonic way to determine if a string is a number? By >> number I mean a valid integer or float. > > try: > int(myString) It could be a float, so: float(myString) This will work even if it's an int. > except ValueError: > print "That's bogus, man" > From roy at panix.com Sun Feb 15 14:01:12 2009 From: roy at panix.com (Roy Smith) Date: Sun, 15 Feb 2009 14:01:12 -0500 Subject: Pythonic way to determine if a string is a number References: <1234720016.23422.1300488109@webmail.messagingengine.com> <2B9BDEC0-5D49-4760-86D7-C36A5FC849C6@semanchuk.com> Message-ID: In article , Christian Heimes wrote: > Philip Semanchuk schrieb: > > > > On Feb 15, 2009, at 12:46 PM, python at bdurham.com wrote: > > > >> What's the Pythonic way to determine if a string is a number? By > >> number I mean a valid integer or float. > > > > > > try: > > int(number) > > is_an_int = True > > except: > > is_an_int = False > > Please don't teach new Python developers to use bare excepts. In fact > never use bare excepts at all! I agree that the bare except is incorrect in this situation, but I don't agree that you should *never* use them. They make sense when you need to recover from any error that may occur, possibly as the last resort after catching and dealing with more specific exceptions. In an unattended embedded system (think Mars Rover), the top-level code might well be: while 1: try: main() except: reset() or perhaps even (Range Safety Controller): try: main() except: self_destruct() From google at mrabarnett.plus.com Sun Feb 15 14:10:42 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sun, 15 Feb 2009 19:10:42 +0000 Subject: Rapidshare to Megaupload script In-Reply-To: References: Message-ID: <499868B2.2040705@mrabarnett.plus.com> aiwarrior wrote: > Thanks a lot for your input i really needed because i realized these > are minor flaws but even so define whether its good or bad code and i > really need to improve that. I already implemented the changes you > suggested and this one, > >> cookie = dict(x.split("=") for x in cookie) > > for me is just very good and really is elegant. An aspect you didn't > mention was the >> urls.append("http://rapidshare.com/files/" + retrieved_data[0] + >> "/" + retrieved_data[1]) > I think its very hackish and crude but urlparser doesnt seem to > accept more than one argument at a time and doing it in a loop seem > worse than the current solution. What would you do? > re.findall() returns a list of tuples, so retrieved_data is a tuple and the following will work: urls.append("http://rapidshare.com/files/%s/%s" % retrieved_data) From rushik.upadhyay at gmail.com Sun Feb 15 14:56:55 2009 From: rushik.upadhyay at gmail.com (rushik) Date: Sun, 15 Feb 2009 11:56:55 -0800 (PST) Subject: Cannot able to retreive compressed html URL Message-ID: Hi, I am trying to build python script which retreives and analyze the various URLs and generate reports. Some of the urls are like "http://xyz.com/test.html.gz", I am trying to retreive it using urllib2 library and then using gzip library trying to decompress it. ex - server_url is say - http://xyz.com/test.html.gz logpage = urllib2.urlopen(server_url) html_content = cal_logpage.read() logpage.close() gz_tmp = open("gzip.txt.gz", "w") gz_tmp.write(html_content) gz_tmp.close() f = gzip.open("gzip.txt.gz", "rb") file_content = f.read() f.close() #return the resulting html content. return html_content on executing the code, its giving zlib.error - Error -3 while decompressing: invalid distance too far back the same URL I am able to retreive in proper html page format from browser please let me know if I am doing something wrong here, or is there any other better way to do so. Thanks, R From dotancohen at gmail.com Sun Feb 15 15:03:25 2009 From: dotancohen at gmail.com (Dotan Cohen) Date: Sun, 15 Feb 2009 22:03:25 +0200 Subject: Python interface to ODF documents? Message-ID: <880dece00902151203v2ba64befjb2d4b29a688143a5@mail.gmail.com> Is there a Python interface to ODF documents? I'm thinking of something that will import, for example, an ADS spreadsheet into a multidimensional array (including formulas and formatting) and let me manipulate it, then save it back. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-??-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-? From lists at cheimes.de Sun Feb 15 15:04:49 2009 From: lists at cheimes.de (Christian Heimes) Date: Sun, 15 Feb 2009 21:04:49 +0100 Subject: Pythonic way to determine if a string is a number In-Reply-To: References: <1234720016.23422.1300488109@webmail.messagingengine.com> <2B9BDEC0-5D49-4760-86D7-C36A5FC849C6@semanchuk.com> Message-ID: Roy Smith wrote: > I agree that the bare except is incorrect in this situation, but I don't > agree that you should *never* use them. A bare except should be used when followed by a raise try: func() except: log_error() raise > They make sense when you need to recover from any error that may occur, > possibly as the last resort after catching and dealing with more specific > exceptions. In an unattended embedded system (think Mars Rover), the > top-level code might well be: > > while 1: > try: > main() > except: > reset() Do you really want to except SystemExit, KeyboardInterrupt, MemoryError and SyntaxError? Christian From python at bdurham.com Sun Feb 15 15:05:01 2009 From: python at bdurham.com (python at bdurham.com) Date: Sun, 15 Feb 2009 15:05:01 -0500 Subject: Pythonic way to determine if a string is a number In-Reply-To: References: <1234720016.23422.1300488109@webmail.messagingengine.com> <2B9BDEC0-5D49-4760-86D7-C36A5FC849C6@semanchuk.com> Message-ID: <1234728301.16829.1300503743@webmail.messagingengine.com> Thanks for everyone's feedback. I believe my original post's code (updated following my signature) was in line with this list's feedback. Christian: Thanks for reminding me about exponential formats. My updated code accounts for these type of numbers. I don't need to handle inf or nan values. My original code's except catches an explicit ValueError exception per your concern about bare excepts. Malcolm # str_to_num.py def isnumber( input ): try: num = float( input ) return True except ValueError: return False if __name__ == '__main__': tests = """ 12 -12 -12.34 .0 . 1 2 3 1 . 2 1e10 1E10 inf nan 12 and text just text """ for test in tests.split( '\n' ): print 'test (%0s), isnumber: %1s' % ( test.strip(), isnumber( test ) ) From mail at timgolden.me.uk Sun Feb 15 15:08:53 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Sun, 15 Feb 2009 20:08:53 +0000 Subject: Pythonic way to determine if a string is a number In-Reply-To: <1234728301.16829.1300503743@webmail.messagingengine.com> References: <1234720016.23422.1300488109@webmail.messagingengine.com> <2B9BDEC0-5D49-4760-86D7-C36A5FC849C6@semanchuk.com> <1234728301.16829.1300503743@webmail.messagingengine.com> Message-ID: <49987655.7020605@timgolden.me.uk> python at bdurham.com wrote: > > # str_to_num.py > > def isnumber( input ): > try: > num = float( input ) > return True > > except ValueError: > return False Just for the info, Malcolm, you don't actually need to assign the result of float (input) to anything if you don't need to use it. All you're looking for is the exception. Let the intepreter convert it and then throw it away. Also, as an alternative style which can be more appropriate depending on the structure and intention of what you're doing, you can use the else: clause of the try-except block. try: float (input) except ValueError: return False else: return True TJG From tino at wildenhain.de Sun Feb 15 15:10:30 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Sun, 15 Feb 2009 21:10:30 +0100 Subject: Python interface to ODF documents? In-Reply-To: <880dece00902151203v2ba64befjb2d4b29a688143a5@mail.gmail.com> References: <880dece00902151203v2ba64befjb2d4b29a688143a5@mail.gmail.com> Message-ID: <499876B6.2070304@wildenhain.de> Hi, Dotan Cohen wrote: > Is there a Python interface to ODF documents? I'm thinking of > something that will import, for example, an ADS spreadsheet into a > multidimensional array (including formulas and formatting) and let me > manipulate it, then save it back. Yes, you have zipfile and a host of xml parsers included in the standard lib. This works very well to my experience. Not sure if an abstraction layer on top of that exists. Regards Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From mailinglists at vanwingerde.net Sun Feb 15 15:24:22 2009 From: mailinglists at vanwingerde.net (Jaap van Wingerde) Date: Sun, 15 Feb 2009 21:24:22 +0100 Subject: PHP like documentation? In-Reply-To: <0b0364a9-85a9-4fe1-822b-07c1d7eeacd1@p23g2000prp.googlegroups.com> References: <0b0364a9-85a9-4fe1-822b-07c1d7eeacd1@p23g2000prp.googlegroups.com> Message-ID: <499879F6.8060505@vanwingerde.net> Pavan Mishra wrote: > I was wondering if I can use python documentation source > (reStructuredText) and restructure it along the lines of PHP > documentation. Allowing users to add comments, improving search etc. > I was thinking if it would be useful. Very good idea! -- Jaap van Wingerde e-mail: 1234567890 at vanwingerde.net web: http://jaap.vanwingerde.net/ From quentel.pierre at wanadoo.fr Sun Feb 15 15:31:50 2009 From: quentel.pierre at wanadoo.fr (Pierre Quentel) Date: Sun, 15 Feb 2009 12:31:50 -0800 (PST) Subject: BaseHttpServer References: <718d890c-dfce-416d-934b-db0a47fc4678@b16g2000yqb.googlegroups.com> Message-ID: <67131875-26c6-48b2-b337-104ed4fa633c@v38g2000yqb.googlegroups.com> On 15 f?v, 18:31, Paul wrote: > Hi, > I currently have a webserver using BaseHttpServe that serves images > like this: > if self.path.endswith(".jpg"): > ? ? ? ? ? ? ? ? print(curdir + sep + self.path) > ? ? ? ? ? ? ? ? f = open(curdir + sep + self.path,"b") > ? ? ? ? ? ? ? ? self.send_response(200) > ? ? ? ? ? ? ? ? self.send_header('Content-type', ? ? ? ?'image/jpg') > ? ? ? ? ? ? ? ? self.end_headers() > ? ? ? ? ? ? ? ? self.wfile.write(f.read()) > ? ? ? ? ? ? ? ? f.close() > ? ? ? ? ? ? ? ? return > Whilst it works, it does take quite a while to load (approx 10secs for > a 4mb file even though its over the local connection) - does anyone > have any hints/tips for speeding it up? > Thanks, > Paul Hi, This is probably because you first load the file content in memory by f.read() before sending it. In this case it's better to send the content by chunk, using shutil : replace self.wfile.write(f.read()) by : shutil.copyfileobj(f,self.wfile) - Pierre From hackingkk at gmail.com Sun Feb 15 15:32:15 2009 From: hackingkk at gmail.com (Krishnakant) Date: Mon, 16 Feb 2009 02:02:15 +0530 Subject: Python interface to ODF documents? In-Reply-To: <499876B6.2070304@wildenhain.de> References: <880dece00902151203v2ba64befjb2d4b29a688143a5@mail.gmail.com> <499876B6.2070304@wildenhain.de> Message-ID: <1234729935.21750.0.camel@kk-laptop> hello look at python-ooolib it can do what ever is needed and more. happy hacking. Krishnakant. On Sun, 2009-02-15 at 21:10 +0100, Tino Wildenhain wrote: > Hi, > > Dotan Cohen wrote: > > Is there a Python interface to ODF documents? I'm thinking of > > something that will import, for example, an ADS spreadsheet into a > > multidimensional array (including formulas and formatting) and let me > > manipulate it, then save it back. > > Yes, you have zipfile and a host of xml parsers included in the > standard lib. This works very well to my experience. > > Not sure if an abstraction layer on top of that exists. > > Regards > Tino > > > -- > http://mail.python.org/mailman/listinfo/python-list From steve at holdenweb.com Sun Feb 15 15:36:15 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 15 Feb 2009 15:36:15 -0500 Subject: "Byte" type? In-Reply-To: <499859e2$0$1618$742ec2ed@news.sonic.net> References: <4997aa38$0$1678$742ec2ed@news.sonic.net> <499841bf$0$1624$742ec2ed@news.sonic.net> <499859e2$0$1618$742ec2ed@news.sonic.net> Message-ID: John Nagle wrote: > Benjamin Kaplan wrote: >> On Sun, Feb 15, 2009 at 11:57 AM, John Nagle wrote: >> >>> Benjamin Peterson wrote: > >> Because b'x' is NOT a bytearray. It is a bytes object. When you >> actually use >> a bytearray, it behaves like you expect. >>>>> type(b'x') >> >>>>> type(bytearray(b'x')) >> >>>>> ba = bytearray(b'abc') >>>>> ba[0] + ba[1] >> 195 > > That's indeed how Python 2.6 works. But that's not how > PEP 3137 says it's supposed to work. > > Guido: > > "I propose the following type names at the Python level: > > * bytes is an immutable array of bytes (PyString) > * bytearray is a mutable array of bytes (PyBytes)" > > ... > > "Indexing bytes and bytearray returns small ints (like the bytes type in > 3.0a1, and like lists or array.array('B'))." > (Not true in Python 2.6 - indexing a "bytes" object returns a "bytes" > object with length 1.) > > "b1 + b2: concatenation. With mixed bytes/bytearray operands, the return > type is > that of the first argument (this seems arbitrary until you consider how > += works)." > (Not true in Python 2.6 - concatenation returns a bytearray in both cases.) > > Is this a bug, a feature, a documentation error, or bad design? > It's a feature. In fact all that was done to accommodate easier migration to 3.x is easily shown in one statement: >>> str is bytes True >>> So that's why bytes works the way it does in 2.6 ... hence my contested description of it as an "ugly hack". I am happy to withdraw "ugly", but I think "hack" could still be held to apply. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From konteyaj at gmail.com Sun Feb 15 15:38:17 2009 From: konteyaj at gmail.com (karan) Date: Sun, 15 Feb 2009 12:38:17 -0800 (PST) Subject: error while importing os Message-ID: Hi, Iam new to python i see the following when iam in the python shell and i try to import os,though i can import the sys and sys.path does contain the path to the python binary or the folder where the python binaries reside: Traceback (most recent call last): File "", line 1, in ? File "C:\Perf\qa\test\build\vmqa\python\python-2.4.1-as\lib\os.py", line 683, in ? import copy_reg as _copy_reg File "C:\Perf\qa\test\build\vmqa\python\python-2.4.1-as\lib \copy_reg.py", line 7, in ? from types import ClassType as _ClassType ImportError: dynamic module does not define init function (inittypes) I have the added the path to the Python which contain the python binaries,DLLs to the PYTHONPATH. Let me know what might be the reason for getting this error. Thanks. From python at bdurham.com Sun Feb 15 15:40:47 2009 From: python at bdurham.com (python at bdurham.com) Date: Sun, 15 Feb 2009 15:40:47 -0500 Subject: Pythonic way to determine if a string is a number In-Reply-To: <49987655.7020605@timgolden.me.uk> References: <1234720016.23422.1300488109@webmail.messagingengine.com> <2B9BDEC0-5D49-4760-86D7-C36A5FC849C6@semanchuk.com> <1234728301.16829.1300503743@webmail.messagingengine.com> <49987655.7020605@timgolden.me.uk> Message-ID: <1234730447.23415.1300508497@webmail.messagingengine.com> Tim, > Just for the info, Malcolm, you don't actually need to assign the result of float (input) to anything if you don't need to use it. All you're looking for is the exception. Let the intepreter convert it and then throw it away. Yes! > Also, as an alternative style which can be more appropriate depending on the structure and intention of what you're doing, you can use the else: clause of the try-except block. > > try: > float (input) > except ValueError: > return False > else: > return True I follow the semantics, but I don't know why I would prefer the try/else technique over the simpler: try: float( input ) return True except ValueError: return False Thank you for your feedback, Malcolm From steve at holdenweb.com Sun Feb 15 15:46:01 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 15 Feb 2009 15:46:01 -0500 Subject: BaseHttpServer In-Reply-To: <718d890c-dfce-416d-934b-db0a47fc4678@b16g2000yqb.googlegroups.com> References: <718d890c-dfce-416d-934b-db0a47fc4678@b16g2000yqb.googlegroups.com> Message-ID: Paul wrote: > Hi, > I currently have a webserver using BaseHttpServe that serves images > like this: > if self.path.endswith(".jpg"): > print(curdir + sep + self.path) > f = open(curdir + sep + self.path,"b") > self.send_response(200) > self.send_header('Content-type', 'image/jpg') > self.end_headers() > self.wfile.write(f.read()) > f.close() > return > Whilst it works, it does take quite a while to load (approx 10secs for > a 4mb file even though its over the local connection) - does anyone > have any hints/tips for speeding it up? You could consider reading the file in smaller blocks and writing the output in a loop. That way the next block of the file can be read in while the network buffers are emptying. Just keep reading data and writing it until the number of data bytes you wrote is fewer than the number you tried to read. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From rushik.upadhyay at gmail.com Sun Feb 15 16:17:53 2009 From: rushik.upadhyay at gmail.com (rushik) Date: Sun, 15 Feb 2009 13:17:53 -0800 (PST) Subject: Cannot able to retreive compressed html URL References: Message-ID: <322a11e8-47b8-4b8a-b9d8-5fbb61627538@q30g2000vbn.googlegroups.com> On Feb 15, 11:56?am, rushik wrote: > Hi, > I am trying to build python script which retreives and analyze the > various URLs and generate reports. > > Some of the urls are like "http://xyz.com/test.html.gz", I am trying > to retreive it using urllib2 library and then using gzip library > trying to decompress it. > > ex - server_url is say -http://xyz.com/test.html.gz > > ? ? ? ? ? ? ? ? logpage = urllib2.urlopen(server_url) > ? ? ? ? ? ? ? ? html_content = cal_logpage.read() > ? ? ? ? ? ? ? ? logpage.close() > > ? ? ? ? ? ? ? ? gz_tmp = open("gzip.txt.gz", "w") > ? ? ? ? ? ? ? ? gz_tmp.write(html_content) > ? ? ? ? ? ? ? ? gz_tmp.close() > ? ? ? ? ? ? ? ? f = gzip.open("gzip.txt.gz", "rb") > ? ? ? ? ? ? ? ? file_content = f.read() > ? ? ? ? ? ? ? ? f.close() > > ? ? ? ? ? ? ? ? #return the resulting html content. > ? ? ? ? ? ? ? ? return html_content > > on executing the code, its giving > > zlib.error - Error -3 while decompressing: invalid distance too far > back > > the same URL I am able to retreive in proper html page format from > browser > > please let me know if I am doing something wrong here, or is there any > other better way to do so. > > Thanks, > R I got the solution !! using now urllib.retrieve thx, R From jason.scheirer at gmail.com Sun Feb 15 17:04:57 2009 From: jason.scheirer at gmail.com (Jason Scheirer) Date: Sun, 15 Feb 2009 14:04:57 -0800 (PST) Subject: error while importing os References: Message-ID: On Feb 15, 12:38?pm, karan wrote: > Hi, > > Iam new to python i see the following when iam in the python shell and > i try to import os,though i can import the sys and sys.path does > contain the path to the python binary or the folder where the python > binaries reside: > > Traceback (most recent call last): > ? File "", line 1, in ? > ? File "C:\Perf\qa\test\build\vmqa\python\python-2.4.1-as\lib\os.py", > line 683, in ? > ? ? import copy_reg as _copy_reg > ? File "C:\Perf\qa\test\build\vmqa\python\python-2.4.1-as\lib > \copy_reg.py", line 7, in ? > ? ? from types import ClassType as _ClassType > ImportError: dynamic module does not define init function (inittypes) > > I have the added the path to the Python which contain the python > binaries,DLLs to the PYTHONPATH. > > Let me know what might be the reason for getting this error. > > Thanks. Looks like you have an errant dynamic library -- look for types.pyd on your pythonpath and make sure the right one is getting imported. From peter at www.pjb.com.au Sun Feb 15 17:21:22 2009 From: peter at www.pjb.com.au (Peter Billam) Date: 15 Feb 2009 22:21:22 GMT Subject: Module to read/write MIDI ? Message-ID: Greetings, I speak as a newbie, in the sense that I've been programming Perl4&5 for fifteen years, but am checking out Python3 as an alternative to Perl6. So far I've translated one of my cpan modules into Python3 http://www.pjb.com.au/comp/free/TermClui.py http://www.pjb.com.au/comp/free/test_script and it basically works (the termios ioctls aren't quite what I want yet). Another thing I'd need to proceed with Python3 is some equivalent of Sean Burke's MIDI-Perl module: http://search.cpan.org/search?query=MIDI-Perl I had my first look around pypi.python.org/pypi yesterday and didn't see anything. Is there a MIDI-module for Python ? If not, I'll email Sean to ask if he'd mind me translating his module into Python3... Regards, Peter -- Peter Billam www.pjb.com.au www.pjb.com.au/comp/contact.html From jcd at sdf.lonestar.org Sun Feb 15 18:02:03 2009 From: jcd at sdf.lonestar.org (J. Clifford Dyer) Date: Sun, 15 Feb 2009 18:02:03 -0500 Subject: PHP like documentation? In-Reply-To: <0b0364a9-85a9-4fe1-822b-07c1d7eeacd1@p23g2000prp.googlegroups.com> References: <0b0364a9-85a9-4fe1-822b-07c1d7eeacd1@p23g2000prp.googlegroups.com> Message-ID: <1234738923.721.4.camel@mctell> On Sun, 2009-02-15 at 09:54 -0800, Pavan Mishra wrote: > I was wondering if I can use python documentation source > (reStructuredText) and restructure it along the lines of PHP > documentation. Allowing users to add comments, improving search etc. > > I was thinking if it would be useful. > -- > http://mail.python.org/mailman/listinfo/python-list > I think it would be useful to have somewhere, but I'm -1 on replacing the official documentation with it. I like having the official documentation more... official. I like that what you see there has been fully vetted, edited, and tested. If there's something wrong with it, fix it. If you've got a helpful tip, add it, but it shouldn't be as easy as commenting to add to the official documentation. You could argue that the documentation itself is official, and the comments are not, but I like not having to worry about what part of the page I'm looking at. I also like that google only indexes the official documentation, and not the comments. As I said, it could be very helpful, and I'm not against people having a place to share their advice, but I'd rather see it happen somewhere besides python.org. Just my thought. From catphive at catphive.net Sun Feb 15 18:07:06 2009 From: catphive at catphive.net (Brendan Miller) Date: Sun, 15 Feb 2009 15:07:06 -0800 Subject: documentation link for python 3.0.1 on python.org is broken Message-ID: Like the title says. From pauljefferson at gmail.com Sun Feb 15 18:24:01 2009 From: pauljefferson at gmail.com (Paul) Date: Sun, 15 Feb 2009 15:24:01 -0800 (PST) Subject: BaseHttpServer References: <718d890c-dfce-416d-934b-db0a47fc4678@b16g2000yqb.googlegroups.com> Message-ID: On Feb 15, 8:46?pm, Steve Holden wrote: > Paul wrote: > > Hi, > > I currently have a webserver using BaseHttpServe that serves images > > like this: > > if self.path.endswith(".jpg"): > > ? ? ? ? ? ? ? ? print(curdir + sep + self.path) > > ? ? ? ? ? ? ? ? f = open(curdir + sep + self.path,"b") > > ? ? ? ? ? ? ? ? self.send_response(200) > > ? ? ? ? ? ? ? ? self.send_header('Content-type', ? 'image/jpg') > > ? ? ? ? ? ? ? ? self.end_headers() > > ? ? ? ? ? ? ? ? self.wfile.write(f.read()) > > ? ? ? ? ? ? ? ? f.close() > > ? ? ? ? ? ? ? ? return > > Whilst it works, it does take quite a while to load (approx 10secs for > > a 4mb file even though its over the local connection) - does anyone > > have any hints/tips for speeding it up? > > You could consider reading the file in smaller blocks and writing the > output in a loop. That way the next block of the file can be read in > while the network buffers are emptying. > > Just keep reading data and writing it until the number of data bytes you > wrote is fewer than the number you tried to read. > > regards > ?Steve > -- > Steve Holden ? ? ? ?+1 571 484 6266 ? +1 800 494 3119 > Holden Web LLC ? ? ? ? ? ? ?http://www.holdenweb.com/ Thanks for these but they seem to have made no difference - it still loads (visually) in chunks on the screen taking quite a while. Intrestingly, with the looping idea I got it to print out on each loop and some took a substantial amount of time to load compared to others (I tried using 1500 and then 10,000 size chunks,with the code being: if self.path.endswith(".jpg"): print(curdir + sep + self.path) f = open(curdir + sep + self.path,"rb") self.send_response(200) self.send_header('Content-type', 'image/jpg') self.end_headers() h = 10000 while h==10000: g = f.read(10000) h = len(g) print h self.wfile.write(g) #self.wfile.write(f.read()) #shutil.copyfileobj(f,self.wfile) f.close() return I also tried loading it to memory before it was requested but that also made no difference. If anyone's got any suggestions, I would be very greatful, Paul From greg.ewing at canterbury.ac.nz Sun Feb 15 18:33:42 2009 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Mon, 16 Feb 2009 12:33:42 +1300 Subject: ANN: SuPy 1.4 Message-ID: SuPy 1.4 Available ------------------ http://www.cosc.canterbury.ac.nz/greg.ewing/SuPy/ Changes in this version: - Python tuples are converted to Ruby arrays, so you can pass them directly to Sketchup methods that require an array. - 'Array' function for converting other Python sequences to arrays. - X_AXIS, Y_AXIS, Z_AXIS constants. - Unit conversion constants (feet, yard, etc.) e.g. 5 * feet What is SuPy? ------------- SuPy is a plugin for the Sketchup 3D modelling application that lets you script it in Python. -- Greg Ewing greg.ewing at canterbury.ac.nz From jaomatos at gmail.com Sun Feb 15 18:36:21 2009 From: jaomatos at gmail.com (=?utf-8?q?Jos=C3=A9_Matos?=) Date: Sun, 15 Feb 2009 23:36:21 +0000 Subject: Python is slow? In-Reply-To: References: Message-ID: <200902152336.22016.jaomatos@gmail.com> On Monday 06 October 2008 00:01:50 Lawrence D'Oliveiro wrote: > Not listed as one > . Look further http://directory.fsf.org/project/gnuplot/ -- Jos? Ab?lio From tjreedy at udel.edu Sun Feb 15 18:39:38 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 15 Feb 2009 18:39:38 -0500 Subject: PHP like documentation? In-Reply-To: <0b0364a9-85a9-4fe1-822b-07c1d7eeacd1@p23g2000prp.googlegroups.com> References: <0b0364a9-85a9-4fe1-822b-07c1d7eeacd1@p23g2000prp.googlegroups.com> Message-ID: Pavan Mishra wrote: > I was wondering if I can use python documentation source > (reStructuredText) and restructure it along the lines of PHP > documentation. Allowing users to add comments, improving search etc. I presume the docs that are part of the distribution are covered by the rather liberal Python license, which is included with the doc set. From tjreedy at udel.edu Sun Feb 15 18:41:14 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 15 Feb 2009 18:41:14 -0500 Subject: Python interface to ODF documents? In-Reply-To: <880dece00902151203v2ba64befjb2d4b29a688143a5@mail.gmail.com> References: <880dece00902151203v2ba64befjb2d4b29a688143a5@mail.gmail.com> Message-ID: Dotan Cohen wrote: > Is there a Python interface to ODF documents? I'm thinking of > something that will import, for example, an ADS spreadsheet into a > multidimensional array (including formulas and formatting) and let me > manipulate it, then save it back. odf2py, probably among others. From tjreedy at udel.edu Sun Feb 15 18:43:36 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 15 Feb 2009 18:43:36 -0500 Subject: documentation link for python 3.0.1 on python.org is broken In-Reply-To: References: Message-ID: Brendan Miller wrote: > Like the title says. but on which page? in any case, inform webmaster at python.org of specific site problems From mwilson at the-wire.com Sun Feb 15 19:05:36 2009 From: mwilson at the-wire.com (Mel) Date: Sun, 15 Feb 2009 19:05:36 -0500 Subject: Pythonic way to determine if a string is a number References: <1234720016.23422.1300488109@webmail.messagingengine.com> <2B9BDEC0-5D49-4760-86D7-C36A5FC849C6@semanchuk.com> Message-ID: Christian Heimes wrote: > Roy Smith wrote: >> They make sense when you need to recover from any error that may occur, >> possibly as the last resort after catching and dealing with more specific >> exceptions. In an unattended embedded system (think Mars Rover), the >> top-level code might well be: >> >> while 1: >> try: >> main() >> except: >> reset() > > Do you really want to except SystemExit, KeyboardInterrupt, MemoryError > and SyntaxError? Exactly. A normal program should never do anything more comprehensive than try: some_function () except StandardError: some_handling () IMHO Mel. From Scott.Daniels at Acm.Org Sun Feb 15 19:13:41 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sun, 15 Feb 2009 16:13:41 -0800 Subject: Pythonic way to determine if a string is a number In-Reply-To: References: <1234720016.23422.1300488109@webmail.messagingengine.com> <2B9BDEC0-5D49-4760-86D7-C36A5FC849C6@semanchuk.com> Message-ID: <5--dnbQlAdqsMgXUnZ2dnUVZ_tmWnZ2d@pdx.net> python at bdurham.com wrote: > Thanks for everyone's feedback.... > def isnumber( input ): > try: > num = float( input ) > return True > > except ValueError: > return False Pretty good, but what about 0x23? def isnumber( input ): try: num = float(input) return True except ValueError: try: num = int(input, 0) # Convert to int, base spec in arg return True except ValueError: return False --Scott David Daniels Scott.Daniels at Acm.Org From sandraqu at silverica.com Sun Feb 15 19:24:29 2009 From: sandraqu at silverica.com (Sandra Quiles) Date: Sun, 15 Feb 2009 19:24:29 -0500 Subject: illegal list name Message-ID: <23C4EB98-C660-4C24-8C98-05BE7E7BDE41@silverica.com> Hello. I have followed the instructions of a post on Installing mailman on OS X 10.4, and got to step 7 and hit this error. The hard- and software involved is: OS X 10.4.x, Python 2.3.5, Mailman 2.1.5 (using this outdated version because I don't know how to upgrade Python despite going to the Python site. It wasn't obvious to me which Linux package was an upgrade, and the installation of MacPython 2.6.1 was not recognized by Terminal). So. illegal name error. it list listname as 'mailman@' that's in response to the 'bin/newlist mailman' command also, I purchased the Postfix Enabler, but have no clue what to do with the software. Tips, advise, hand-holding welcomed. -- sandra From vincent at vincentdavis.net Sun Feb 15 19:29:09 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Sun, 15 Feb 2009 17:29:09 -0700 Subject: Above and beyond, A critique request Message-ID: <77e831100902151629y286badf1t5af11adac45e5940@mail.gmail.com> So I am new to python and not much of a programmer. Mostly program using statistical packages. I been working on a project to simulate the medical residency match for about 2 weeks. I don't know any python programmers so I would greatly appreciate any comment or suggestions you may have to improve my programing skills. My program does work but I have no comparison or experience to know if I have used "best practices". Suggestion may be broad or specific all input is appreciated. I have already benefited from the group and am appreciative of it. Due to python-list at python.org limited post size I have only included the final step. If someone is willing to review my complete program ~250 lines it can be downloaded at http://vincentdavis.org/match In word this is what it does. - Creates a population of institutions and applicants, quality and score are generated for each by drawing from a random dist. - The is an observation error, that is the institutions do not see the true applicant score and the applicant do not see the true institution quality. - applicants apply to institution that are near there ability - institutions reject if applicant is not qualified - applicant rank the institutions 0 best large values worse - institutions rank applicants - The Match is best described here http://www.nrmp.org/res_match/about_res/algorithms.html I have a lot of print functions mostly to track what was going on during development. Thanks Vincent Davis 720-301-3003 # NumApp is the number of applicants # NumInst is the number of institutions # ari is a list of institutions rank by each applicant, [[5, 6, 2], [8, 3, 6, 2], [......... So applicant 1 ranked institution 2 first and institution 6 second, applicant 2 ranked institution 6 third # ira institutions ranking of applicants same format as ari but from the institutions perspective # iram is a "matrix" version of ira, rows are applicants, colums are institutions values represent the rank, that is the rank the institution gave the applicant # I think that is all that is used in this part that is not defined below. #### Starts here #### app_match = [None]*NumApp # the list of institution each applicant is matched to try_list = [] # makes a copy of ari try_list.extend(ari) # makes a copy of ari inst_match=[[] for x in range(NumInst)] # this is a list of applicants each Institution accepted #get list of applicants not matched notmatched = [x for x in range(NumApp) if (app_match[x] == None and len(try_list[x]) > 0)] print 'notmatched', notmatched print 'len(notmatched)', len(notmatched) while len(notmatched) > 0: for x in notmatched: try_inst = try_list[x][0] # try this institution try_rank = ari[x].index(try_inst) # try_inst is ranked -- app_ranked = iram[x][try_inst] # this is what try_inst ranked the applicant print 'Try to match Applicant', x, ' to rank', try_rank, 'at inst', try_inst print 'Who is in inst', try_inst, inst_match[try_inst] print 'Institution', try_inst, 'ranked applicant', x, app_ranked ranklist = [iram[i][try_inst] for i in inst_match[try_inst]] # this is the rank of each applicant matched to try_inst if len(ranklist) > 0: max_rank = max(ranklist) # the max rank value "lowest rank" max_app = inst_match[try_inst][ranklist.index(max_rank)] # the applicant corresponding to max_rank if len(inst_match[try_inst]) < NumAccept : #Does the institution have an empty spot. print 'Institution', try_inst, 'has an empty spot for', x inst_match[try_inst].append(x) # Add to institutions list print x, 'in now in', try_inst, 'with', inst_match[try_inst] app_match[x] = try_inst # assign inst to app try_list[x].remove(try_inst) # remove the institution so it is not tried later elif (len(inst_match[try_inst]) == NumAccept and app_ranked < max_rank) : print 'Applicant',x , 'is ranked', app_ranked, 'which is higher than', max_app, 'who was ranked', max_rank print 'so applicant', x, 'bumps', max_app app_match[max_app] = None inst_match[try_inst].remove(max_app) app_match[x] = try_inst inst_match[try_inst].append(x) try_list[x].remove(try_inst) # remove the institution so it is not tried later elif (len(inst_match[try_inst]) == NumAccept and iram[x][try_inst] > max_rank) : print 'Applicant',x , 'is ranked', app_ranked, 'which is Lower than', max_app, 'who was ranked', max_rank print 'therefor', x, 'does not match at', try_inst try_list[x].remove(try_inst) # remove the institution so it is not tried later elif (len(inst_match[try_inst]) > NumAccept) : print '#################### to many matched to institution, fix this, some thing is broke ###################' else: print '#################### fix this, some thing is broke ###################' print 'finished with applicant', x notmatched = [x for x in range(NumApp) if (app_match[x] == None and len(try_list[x]) > 0)] -------------- next part -------------- An HTML attachment was scrubbed... URL: From vincent at vincentdavis.net Sun Feb 15 19:39:06 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Sun, 15 Feb 2009 17:39:06 -0700 Subject: illegal list name In-Reply-To: <23C4EB98-C660-4C24-8C98-05BE7E7BDE41@silverica.com> References: <23C4EB98-C660-4C24-8C98-05BE7E7BDE41@silverica.com> Message-ID: <77e831100902151639l4c4d3a1fu3f5f40cadff539ed@mail.gmail.com> You probably have got 2.6 installed you just need to tell terminal to use 2.6, there should be a shell command inside the 2.6 folder that updates the terminal to use 2.6 otherwise you start python by referring directly to the "python" you need to use. Sorry I have no advise on mailman. Thanks Vincent Davis On Sun, Feb 15, 2009 at 5:24 PM, Sandra Quiles wrote: > > Hello. I have followed the instructions of a post on Installing mailman on > OS X 10.4, and got to step 7 and hit this error. > > The hard- and software involved is: OS X 10.4.x, Python 2.3.5, Mailman > 2.1.5 (using this outdated version because I don't know how to upgrade > Python despite going to the Python site. It wasn't obvious to me which > Linux package was an upgrade, and the installation of MacPython 2.6.1 was > not recognized by Terminal). > > So. illegal name error. it list listname as 'mailman@' > > that's in response to the 'bin/newlist mailman' command > > also, I purchased the Postfix Enabler, but have no clue what to do with the > software. > > Tips, advise, hand-holding welcomed. > > -- sandra > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From philip at semanchuk.com Sun Feb 15 20:35:17 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Sun, 15 Feb 2009 20:35:17 -0500 Subject: Pythonic way to determine if a string is a number In-Reply-To: References: <1234720016.23422.1300488109@webmail.messagingengine.com> <2B9BDEC0-5D49-4760-86D7-C36A5FC849C6@semanchuk.com> Message-ID: On Feb 15, 2009, at 1:27 PM, Christian Heimes wrote: > Philip Semanchuk schrieb: >> >> On Feb 15, 2009, at 12:46 PM, python at bdurham.com wrote: >> >>> What's the Pythonic way to determine if a string is a number? By >>> number I mean a valid integer or float. >> >> >> try: >> int(number) >> is_an_int = True >> except: >> is_an_int = False > > Please don't teach new Python developers to use bare excepts. Good point; my example is lazy. I should know better as I myself got burned on bare excepts a few times when I started with Python. From sjmachin at lexicon.net Sun Feb 15 20:37:19 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 15 Feb 2009 17:37:19 -0800 (PST) Subject: Pythonic way to determine if a string is a number References: <1234720016.23422.1300488109@webmail.messagingengine.com> <2B9BDEC0-5D49-4760-86D7-C36A5FC849C6@semanchuk.com> Message-ID: <6bdfeec3-b1f8-46d0-aeb3-d35b243f01b9@z6g2000pre.googlegroups.com> On Feb 16, 7:05?am, pyt... at bdurham.com wrote: > Thanks for everyone's feedback. I believe my original post's code > (updated following my signature) was in line with this list's feedback. > > Christian: Thanks for reminding me about exponential formats. My updated > code accounts for these type of numbers. I don't need to handle inf or > nan values. My original code's except catches an explicit ValueError > exception per your concern about bare excepts. > > Malcolm > > > # str_to_num.py > > def isnumber( input ): > ? ? try: > ? ? ? ? num = float( input ) > ? ? ? ? return True > > ? ? except ValueError: > ? ? ? ? return False > > if __name__ == '__main__': > ? ? tests = """ > ? ? ? ? 12 > ? ? ? ? -12 > ? ? ? ? -12.34 > ? ? ? ? .0 > ? ? ? ? . > ? ? ? ? 1 2 3 > ? ? ? ? 1 . 2 > > ? ? ? ? 1e10 > ? ? ? ? 1E10 > ? ? ? ? inf > ? ? ? ? nan > > ? ? ? ? 12 and text > ? ? ? ? just text > ? ? """ > > ? ? for test in tests.split( '\n' ): > ? ? ? ? print 'test (%0s), isnumber: %1s' % ( test.strip(), isnumber( > ? ? ? ? test ) ) > Do you care about numbers that are representable as an int, but are treated as inf by float()? For example: | >>> s = '1' * 310 | >>> float(s) | inf | >>> a = int(s) | >>> # OK From roy at panix.com Sun Feb 15 21:35:20 2009 From: roy at panix.com (Roy Smith) Date: Sun, 15 Feb 2009 21:35:20 -0500 Subject: Pythonic way to determine if a string is a number References: <1234720016.23422.1300488109@webmail.messagingengine.com> <2B9BDEC0-5D49-4760-86D7-C36A5FC849C6@semanchuk.com> Message-ID: In article , Mel wrote: > Christian Heimes wrote: > > Roy Smith wrote: > > >> They make sense when you need to recover from any error that may occur, > >> possibly as the last resort after catching and dealing with more specific > >> exceptions. In an unattended embedded system (think Mars Rover), the > >> top-level code might well be: > >> > >> while 1: > >> try: > >> main() > >> except: > >> reset() > > > > Do you really want to except SystemExit, KeyboardInterrupt, MemoryError > > and SyntaxError? Absolutely. Let's take my example -- you're writing software for a Mars Rover. I have no idea how you might get a MemoryError, but let's say you do. Which would you rather do, perform a system reset, or print a stack trace and wait for a friendly Martian to come along and reboot you? You may think I'm being silly, but I'm dead serious. The many layers of "It's impossible for this to happen, but if it does let's do something to try and recover" processing saved that mission several times over. In some applications, there's no such thing as "halt". From basu at archlinux.us Sun Feb 15 21:36:44 2009 From: basu at archlinux.us (member Basu) Date: Sun, 15 Feb 2009 21:36:44 -0500 Subject: Display a list using PyQt Message-ID: I'm writing an application with PyQt as the GUI toolkit. I have a function that returns a simple list and I would like to update a List View widget with it. However I can't get it to work. I'm not sure if I need to subclass one of the Model classes, because it is just a list. Can someone point me to a simple tutorial or give me instructions on how to go about doing this? Thanks, Basu -------------- next part -------------- An HTML attachment was scrubbed... URL: From bedouglas at earthlink.net Sun Feb 15 21:58:49 2009 From: bedouglas at earthlink.net (bruce) Date: Sun, 15 Feb 2009 18:58:49 -0800 Subject: testing xml against xpather with firefox Message-ID: <41de01c98fe2$8e8bb070$0301a8c0@tmesa.com> hi... got a short test against a website, and i'm using xpath (libxml2dom) in order to extract the data. in order to create the xpath function/query, i display the page in firefox, and use DOM/Xpather to get the xpath. i'm then attempting to implement the xpath in my test python script. my issue is that the xpath that appears to work in the XPather app, doesn't give me the same results in my test python script. my test app is below. it iterates through the list of rows in the tbl, and for each row, it's supposed to count (and then process) the number of the direct child "td" elements for the "tr". the xpath in XPather does this as expected. my test app doesn't... i can include the actual content from the page if needed. i'm including the test script, and the output of the test... any thoughts would be greatly appreciated... the XPather function works as expected. i've posted all the code/output/XPather xpath to pastebin to save space.. i can send everything i have to whoever can help!! http://pastebin.com/m26acf804 thanks! -bruce From nad at acm.org Sun Feb 15 22:15:17 2009 From: nad at acm.org (Ned Deily) Date: Sun, 15 Feb 2009 19:15:17 -0800 Subject: RELEASED Python 3.0.1 References: Message-ID: In article , Benjamin Kaplan wrote: > Any chance of getting a Mac installer for this one? BTW, I see the a link to the OS X installer has now been added to the 3.0.1 release page: It would be great if someone could add OS X links for the 3.0.1 and 2.6.1 to the main download page, too: -- Ned Deily, nad at acm.org From grante at visi.com Sun Feb 15 23:49:31 2009 From: grante at visi.com (Grant Edwards) Date: Sun, 15 Feb 2009 22:49:31 -0600 Subject: Can Python serial support run at 45.45 baud? References: <4996e984$0$1657$742ec2ed@news.sonic.net> <-rednU9RmNnrbwvUnZ2dnUVZ_sHinZ2d@posted.usinternet> <49970561$0$1642$742ec2ed@news.sonic.net> <49970ce7$0$1665$742ec2ed@news.sonic.net> <49972cf5$0$1612$742ec2ed@news.sonic.net> <499858c5$0$1618$742ec2ed@news.sonic.net> Message-ID: On 2009-02-15, John Nagle wrote: > Linux support for nonstandard baud rates is possible, but > needs a call to "setserial", Or use of a non-POSIX ioctl() call. > which is not standard POSIX. True -- there is no way to do non-standard baud rates using just POSIX calls. -- Grant From python at bdurham.com Mon Feb 16 00:17:37 2009 From: python at bdurham.com (python at bdurham.com) Date: Mon, 16 Feb 2009 00:17:37 -0500 Subject: Pythonic way to determine if one char of many in a string Message-ID: <1234761457.20683.1300568627@webmail.messagingengine.com> I need to test strings to determine if one of a list of chars is in the string. A simple example would be to test strings to determine if they have a vowel (aeiouAEIOU) present. I was hopeful that there was a built-in method that operated similar to startswith where I could pass a tuple of chars to be tested, but I could not find such a method. Which of the following techniques is most Pythonic or are there better ways to perform this type of match? # long and hard coded but short circuits as soon as match found if 'a' in word or 'e' in word or 'i' in word or 'u' in word or ... : -OR- # flexible, but no short circuit on first match if [ char for char in word if char in 'aeiouAEIOU' ]: -OR- # flexible, but no short circuit on first match if set( word ).intersection( 'aeiouAEIOU' ): Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Mon Feb 16 00:28:39 2009 From: python at bdurham.com (python at bdurham.com) Date: Mon, 16 Feb 2009 00:28:39 -0500 Subject: Pythonic way to determine if a string is a number In-Reply-To: <5--dnbQlAdqsMgXUnZ2dnUVZ_tmWnZ2d@pdx.net> References: <1234720016.23422.1300488109@webmail.messagingengine.com> <2B9BDEC0-5D49-4760-86D7-C36A5FC849C6@semanchuk.com> <5--dnbQlAdqsMgXUnZ2dnUVZ_tmWnZ2d@pdx.net> Message-ID: <1234762119.22230.1300571397@webmail.messagingengine.com> Scott, > Pretty good, but what about 0x23? > > num = int(input, 0) # Convert to int, base spec in arg > Very nice! I wasn't familiar with the use of 0 as a radix value. A quick visit back to the documentation and I'm an enlightened man :) Thanks for your feedback, Malcolm From Nicolas.Dandrimont at crans.org Mon Feb 16 00:28:46 2009 From: Nicolas.Dandrimont at crans.org (Nicolas Dandrimont) Date: Mon, 16 Feb 2009 00:28:46 -0500 Subject: Pythonic way to determine if one char of many in a string In-Reply-To: <1234761457.20683.1300568627@webmail.messagingengine.com> References: <1234761457.20683.1300568627@webmail.messagingengine.com> Message-ID: <20090216052846.GA12723@dirichlet.crans.org> * python at bdurham.com [2009-02-16 00:17:37 -0500]: > I need to test strings to determine if one of a list of chars is > in the string. A simple example would be to test strings to > determine if they have a vowel (aeiouAEIOU) present. > I was hopeful that there was a built-in method that operated > similar to startswith where I could pass a tuple of chars to be > tested, but I could not find such a method. > Which of the following techniques is most Pythonic or are there > better ways to perform this type of match? > # long and hard coded but short circuits as soon as match found > if 'a' in word or 'e' in word or 'i' in word or 'u' in word or > ... : > -OR- > # flexible, but no short circuit on first match > if [ char for char in word if char in 'aeiouAEIOU' ]: > -OR- > # flexible, but no short circuit on first match > if set( word ).intersection( 'aeiouAEIOU' ): I would go for something like: for char in word: if char in 'aeiouAEIUO': char_found = True break else: char_found = False (No, I did not forget to indent the else statement, see http://docs.python.org/reference/compound_stmts.html#for) It is clear (imo), and it is seems to be the intended idiom for a search loop, that short-circuits as soon as a match is found. Cheers, -- Nicolas Dandrimont linux: the choice of a GNU generation (ksh at cis.ufl.edu put this on Tshirts in '93) -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 204 bytes Desc: Digital signature URL: From python at bdurham.com Mon Feb 16 00:37:22 2009 From: python at bdurham.com (python at bdurham.com) Date: Mon, 16 Feb 2009 00:37:22 -0500 Subject: Pythonic way to determine if a string is a number In-Reply-To: <6bdfeec3-b1f8-46d0-aeb3-d35b243f01b9@z6g2000pre.googlegroups.com> References: <1234720016.23422.1300488109@webmail.messagingengine.com> <2B9BDEC0-5D49-4760-86D7-C36A5FC849C6@semanchuk.com> <6bdfeec3-b1f8-46d0-aeb3-d35b243f01b9@z6g2000pre.googlegroups.com> Message-ID: <1234762642.23958.1300571929@webmail.messagingengine.com> John, > Do you care about numbers that are representable as an int, but are treated as inf by float()? > > For example: > | >>> s = '1' * 310 > | >>> float(s) > | inf > | >>> a = int(s) > | >>> # OK My code range checks all numbers once they've been parsed, so I don't believe this will be a problem for me. However, I appreciate you pointing out this behavior because I was unaware of this subtle nuance. I'll make sure to add this to our code review checklist. Thanks for your feedback, Malcolm From python at bdurham.com Mon Feb 16 00:48:34 2009 From: python at bdurham.com (python at bdurham.com) Date: Mon, 16 Feb 2009 00:48:34 -0500 Subject: Pythonic way to determine if one char of many in a string In-Reply-To: <20090216052846.GA12723@dirichlet.crans.org> References: <1234761457.20683.1300568627@webmail.messagingengine.com> <20090216052846.GA12723@dirichlet.crans.org> Message-ID: <1234763314.25586.1300573535@webmail.messagingengine.com> Nicolas, > I would go for something like: > > for char in word: > if char in 'aeiouAEIUO': > char_found = True > break > else: > char_found = False > > It is clear (imo), and it is seems to be the intended idiom for a > search loop, that short-circuits as soon as a match is found. Thank you - that looks much better that my overly complicated attempts. Are there any reasons why I couldn't simplify your approach as follows? for char in word: if char in 'aeiouAEIUO': return True return False Cheers, Malcolm From clp2 at rebertia.com Mon Feb 16 00:56:00 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 15 Feb 2009 21:56:00 -0800 Subject: Pythonic way to determine if one char of many in a string In-Reply-To: <1234761457.20683.1300568627@webmail.messagingengine.com> References: <1234761457.20683.1300568627@webmail.messagingengine.com> Message-ID: <50697b2c0902152156n6ef16a8ao36a71e362120308f@mail.gmail.com> On Sun, Feb 15, 2009 at 9:17 PM, wrote: > I need to test strings to determine if one of a list of chars is in the > string. A simple example would be to test strings to determine if they have > a vowel (aeiouAEIOU) present. > > I was hopeful that there was a built-in method that operated similar to > startswith where I could pass a tuple of chars to be tested, but I could not > find such a method. > > Which of the following techniques is most Pythonic or are there better ways > to perform this type of match? > > # long and hard coded but short circuits as soon as match found > if 'a' in word or 'e' in word or 'i' in word or 'u' in word or ... : > > -OR- > > # flexible, but no short circuit on first match > if [ char for char in word if char in 'aeiouAEIOU' ]: Just use the fairly new builtin function any() to make it short-circuit: if any(char.lower() in 'aeiou' for char in word): do_whatever() Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From michele.simionato at gmail.com Mon Feb 16 01:12:32 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Sun, 15 Feb 2009 22:12:32 -0800 (PST) Subject: Turning a signature-changing decorator into a signature-preserving one References: <6b0518e3-142c-4555-8ad0-02c559f6b224@u13g2000yqg.googlegroups.com> <6b0874ad-4c30-4b3f-a559-f83465d332da@z1g2000yqn.googlegroups.com> <2610ff6e-d487-42e8-a619-aa4db6f9556f@h5g2000yqh.googlegroups.com> Message-ID: <1cfad349-033c-49a0-b9ad-213814638567@t13g2000yqc.googlegroups.com> On Feb 14, 3:27?pm, Michele Simionato wrote: > I should probably raise a clearer error message. Ok, I have uploaded version 3.0.1 of the decorator module, which raises a more meaningful message in case you try to decorate a method incorrectly. I have also added a discussion of that case in the "caveats" session. HTH, M. Simionato From laplacian42 at gmail.com Mon Feb 16 01:25:39 2009 From: laplacian42 at gmail.com (laplacian42 at gmail.com) Date: Sun, 15 Feb 2009 22:25:39 -0800 (PST) Subject: Found a very nice, small, cross-platform GUI toolkit for Python. Message-ID: <4a912328-2d60-4380-b440-8d4d94f79662@v19g2000yqn.googlegroups.com> I think I just found the GUI toolkit for Python I've been searching for. It seems to meet all of the following requirements: * free software * small (I don't need batteries -- Python already comes with those.) * easy to use * actively maintained * cross-platform * easy to install * based on a stable and actively-maintained C library * does not depend on an external scripting language (for example, Tcl) * well-documented * not too many dependencies * can easily integrate with PyOpenGL * support for accessibility and it's also written in Python. I have no idea how it's stayed under the radar in the Python community for this long, yet here it is: [OcempGUI](http://ocemp.sourceforge.net/ gui.html). The C library it depends upon? [SDL](http:// www.libsdl.org/) (via [PyGame](http://www.pygame.org/news.html)). The sf project page is . Installation only requires getting SDL installed, then PyGame, and then a `sudo python setup.py install` for OcempGUI. `cd` into its `doc/ examples` directory and run a few of the examples (ex. `python hello_world.py`). The part of [the manual](http://ocemp.sourceforge.net/manual/ocempgui- manual.html) that seems most like a beginner tutorial is . From matzke at berkeley.edu Mon Feb 16 01:44:11 2009 From: matzke at berkeley.edu (Nick Matzke) Date: Sun, 15 Feb 2009 22:44:11 -0800 Subject: hist without plotting Message-ID: <49990B3B.5070002@berkeley.edu> Hi, Is there a way to run the numpy hist function or something similar and get the outputs (bins, bar heights) without actually producing the plot on the screen? (R has a plot = false option, something like this is what I'm looking for...) Cheers! Nick -- ==================================================== Nicholas J. Matzke Ph.D. student, Graduate Student Researcher Huelsenbeck Lab Center for Theoretical Evolutionary Genomics 4151 VLSB (Valley Life Sciences Building) Department of Integrative Biology University of California, Berkeley Lab websites: http://ib.berkeley.edu/people/lab_detail.php?lab=54 http://fisher.berkeley.edu/cteg/hlab.html Dept. personal page: http://ib.berkeley.edu/people/students/person_detail.php?person=370 Lab personal page: http://fisher.berkeley.edu/cteg/members/matzke.html Lab phone: 510-643-6299 Dept. fax: 510-643-6264 Cell phone: 510-301-0179 Email: matzke at berkeley.edu Mailing address: Department of Integrative Biology 3060 VLSB #3140 Berkeley, CA 94720-3140 ----------------------------------------------------- "[W]hen people thought the earth was flat, they were wrong. When people thought the earth was spherical, they were wrong. But if you think that thinking the earth is spherical is just as wrong as thinking the earth is flat, then your view is wronger than both of them put together." Isaac Asimov (1989). "The Relativity of Wrong." The Skeptical Inquirer, 14(1), 35-44. Fall 1989. http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm ==================================================== From tino at wildenhain.de Mon Feb 16 02:01:39 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Mon, 16 Feb 2009 08:01:39 +0100 Subject: hist without plotting In-Reply-To: <49990B3B.5070002@berkeley.edu> References: <49990B3B.5070002@berkeley.edu> Message-ID: <49990F53.80709@wildenhain.de> Nick Matzke wrote: > Hi, > > Is there a way to run the numpy hist function or something similar and > get the outputs (bins, bar heights) without actually producing the plot > on the screen? > > (R has a plot = false option, something like this is what I'm looking > for...) something like scipy.histogram(a) ? Actually I don't see many plotting functions beside plot() anyway... Regards Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From timr at probo.com Mon Feb 16 02:04:38 2009 From: timr at probo.com (Tim Roberts) Date: Sun, 15 Feb 2009 23:04:38 -0800 Subject: illegal list name References: Message-ID: Sandra Quiles wrote: > >Hello. I have followed the instructions of a post on Installing >mailman on OS X 10.4, and got to step 7 and hit this error. > >The hard- and software involved is: OS X 10.4.x, Python 2.3.5, Mailman >2.1.5 (using this outdated version because I don't know how to upgrade >Python despite going to the Python site. It wasn't obvious to me >which Linux package was an upgrade, and the installation of MacPython >2.6.1 was not recognized by Terminal). > >So. illegal name error. it list listname as 'mailman@' > >that's in response to the 'bin/newlist mailman' command Did you read ANY of the documentation? Such as, for example, the part where it tells you that Mailman creates a special, hidden mailing list called "mailman"? In any case, the name of a mailing list should have some tenuous relationship to exactly what the list is for. Your name has no such relationship. >also, I purchased the Postfix Enabler, but have no clue what to do >with the software. > >Tips, advise, hand-holding welcomed. I'm sorry to be crude, but if you expect to be in the habit of purchasing software when you have no clue what to do with it, my best advice is that you should stop purchasing software. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From pythonnutter at gmail.com Mon Feb 16 02:04:54 2009 From: pythonnutter at gmail.com (Python Nutter) Date: Mon, 16 Feb 2009 18:04:54 +1100 Subject: Pythonic way to determine if a string is a number In-Reply-To: <1234720016.23422.1300488109@webmail.messagingengine.com> References: <1234720016.23422.1300488109@webmail.messagingengine.com> Message-ID: Type casting seems to be the wrong way to go about this. teststring = '15719' teststring.isdigit() returns True That takes care of integers. from string import digits digits '0123456789' now you have all the digits and you can do set testing in your logic to see if the teststring has anything in digits A dumb way to test is alphanumeric teststring2 = '105.22' teststring2.isalnum() returns True now you can go on from there and test to further to eliminate 'abcd385laf8' which on alnum() also returns true. Have fun, Cheers, PN 2009/2/16 : > What's the Pythonic way to determine if a string is a number? By > number I mean a valid integer or float. > > I searched the string and cMath libraries for a similar function > without success. I can think of at least 3 or 4 ways to build my > own function. > > Here's what I came up with as a proof-of-concept. Are there > 'better' ways to perform this type of test? > > Thanks, > Malcolm > > > def isnumber( input ): > try: > if '.' in input: > num = float( input ) > else: > num = int( input ) > return True > > except ValueError: > return False > > if __name__ == '__main__': > tests = """ > 12 > -12 > -12.34 > .0 > . > 1 2 3 > 1 . 2 > just text > """ > > for test in tests.split( '\n' ): > print 'test (%0s), isnumber: %1s' % \ > ( test.strip(), isnumber( test ) ) > > > -- > http://mail.python.org/mailman/listinfo/python-list > From pythonnutter at gmail.com Mon Feb 16 02:09:00 2009 From: pythonnutter at gmail.com (Python Nutter) Date: Mon, 16 Feb 2009 18:09:00 +1100 Subject: Pythonic way to determine if a string is a number In-Reply-To: References: <1234720016.23422.1300488109@webmail.messagingengine.com> Message-ID: silly me, forgot to mention build a set from digits + '.' and use that for testing. Cheers, PN 2009/2/16 Python Nutter : > Type casting seems to be the wrong way to go about this. > > teststring = '15719' > teststring.isdigit() > returns True > > That takes care of integers. > > from string import digits > digits > '0123456789' > > now you have all the digits and you can do set testing in your logic > to see if the teststring has anything in digits > > A dumb way to test is alphanumeric > > teststring2 = '105.22' > teststring2.isalnum() > returns True > > now you can go on from there and test to further to eliminate > 'abcd385laf8' which on alnum() also returns true. > > Have fun, > Cheers, > PN > > > 2009/2/16 : >> What's the Pythonic way to determine if a string is a number? By >> number I mean a valid integer or float. >> >> I searched the string and cMath libraries for a similar function >> without success. I can think of at least 3 or 4 ways to build my >> own function. >> >> Here's what I came up with as a proof-of-concept. Are there >> 'better' ways to perform this type of test? >> >> Thanks, >> Malcolm >> >> >> def isnumber( input ): >> try: >> if '.' in input: >> num = float( input ) >> else: >> num = int( input ) >> return True >> >> except ValueError: >> return False >> >> if __name__ == '__main__': >> tests = """ >> 12 >> -12 >> -12.34 >> .0 >> . >> 1 2 3 >> 1 . 2 >> just text >> """ >> >> for test in tests.split( '\n' ): >> print 'test (%0s), isnumber: %1s' % \ >> ( test.strip(), isnumber( test ) ) >> >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > From tino at wildenhain.de Mon Feb 16 02:14:33 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Mon, 16 Feb 2009 08:14:33 +0100 Subject: Pythonic way to determine if a string is a number In-Reply-To: References: <1234720016.23422.1300488109@webmail.messagingengine.com> Message-ID: <49991259.60305@wildenhain.de> Python Nutter wrote: > Type casting seems to be the wrong way to go about this. > > teststring = '15719' > teststring.isdigit() > returns True Actually its instantiating not type casting and it works by using the type's actual description of the data it accepts. This looks pretty good approach instead of trying to copy (incomplete as it has been shown not only digits and . constitute a float) already implemented code. Of course if you want to limit the range of accepted data even more, then isdigit and friends can be used - maybe you could time both approaches with a set of data. Regards Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From tino at wildenhain.de Mon Feb 16 02:18:42 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Mon, 16 Feb 2009 08:18:42 +0100 Subject: Pythonic way to determine if a string is a number In-Reply-To: References: <1234720016.23422.1300488109@webmail.messagingengine.com> <2B9BDEC0-5D49-4760-86D7-C36A5FC849C6@semanchuk.com> Message-ID: <49991352.1050801@wildenhain.de> Roy Smith wrote: > In article , > Mel wrote: > >> Christian Heimes wrote: >>> Roy Smith wrote: >>>> They make sense when you need to recover from any error that may occur, >>>> possibly as the last resort after catching and dealing with more specific >>>> exceptions. In an unattended embedded system (think Mars Rover), the >>>> top-level code might well be: >>>> >>>> while 1: >>>> try: >>>> main() >>>> except: >>>> reset() >>> Do you really want to except SystemExit, KeyboardInterrupt, MemoryError >>> and SyntaxError? > > Absolutely. Let's take my example -- you're writing software for a Mars > Rover. I have no idea how you might get a MemoryError, but let's say you > do. Which would you rather do, perform a system reset, or print a stack > trace and wait for a friendly Martian to come along and reboot you? > > You may think I'm being silly, but I'm dead serious. The many layers of > "It's impossible for this to happen, but if it does let's do something to > try and recover" processing saved that mission several times over. In some > applications, there's no such thing as "halt". Yeah, having your mars rower forever running in a loop to try to convert some random string to a number is sure something you want to achieve. Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From odeits at gmail.com Mon Feb 16 02:18:50 2009 From: odeits at gmail.com (odeits) Date: Sun, 15 Feb 2009 23:18:50 -0800 (PST) Subject: Changing the Image on a button Message-ID: <59253b2f-c90d-4308-835d-e81a2e602127@p23g2000prp.googlegroups.com> I want to be able to toggle if the button has an image or text. For some reason the following code gets the button to have an image but when i push the button i expect the image to go away but it does not. Am I missing something? from Tkinter import * def do(): btn.configure(image = None) root = Tk() img1 = PhotoImage(file="bacon.gif") btn = Button(image = img1, command = do, text = "hello" ) btn.img = img1 btn.pack() root.mainloop() From odeits at gmail.com Mon Feb 16 02:31:42 2009 From: odeits at gmail.com (odeits) Date: Sun, 15 Feb 2009 23:31:42 -0800 (PST) Subject: Pythonic way to determine if one char of many in a string References: <1234761457.20683.1300568627@webmail.messagingengine.com> Message-ID: <8666ef66-288d-426a-9622-9d68d1f7971c@b40g2000pri.googlegroups.com> On Feb 15, 9:56?pm, Chris Rebert wrote: > On Sun, Feb 15, 2009 at 9:17 PM, ? wrote: > > I need to test strings to determine if one of a list of chars is in the > > string. A simple example would be to test strings to determine if they have > > a vowel (aeiouAEIOU) present. > > > I was hopeful that there was a built-in method that operated similar to > > startswith where I could pass a tuple of chars to be tested, but I could not > > find such a method. > > > Which of the following techniques is most Pythonic or are there better ways > > to perform this type of match? > > > # long and hard coded but short circuits as soon as match found > > if 'a' in word or 'e' in word or 'i' in word or 'u' in word or ... : > > > -OR- > > > # flexible, but no short circuit on first match > > if [ char for char in word if char in 'aeiouAEIOU' ]: > > Just use the fairly new builtin function any() to make it short-circuit: > > if any(char.lower() in 'aeiou' for char in word): > ? ? do_whatever() > > Cheers, > Chris > > -- > Follow the path of the Iguana...http://rebertia.com If you want to generalize it you should look at sets http://docs.python.org/library/sets.html It seems what you are actually testing for is if the intersection of the two sets is not empty where the first set is the characters in your word and the second set is the characters in your defined string. From pythonnutter at gmail.com Mon Feb 16 02:34:55 2009 From: pythonnutter at gmail.com (Python Nutter) Date: Mon, 16 Feb 2009 18:34:55 +1100 Subject: Found a very nice, small, cross-platform GUI toolkit for Python. In-Reply-To: <4a912328-2d60-4380-b440-8d4d94f79662@v19g2000yqn.googlegroups.com> References: <4a912328-2d60-4380-b440-8d4d94f79662@v19g2000yqn.googlegroups.com> Message-ID: Had a look and it is still under my radar unfortunately because of TkInter. OceanGUI has a lot of large decencies (Pygame, SDL libraries, PyObjC, etc.) to install on my system to just to get a GUI thats no better loking than TkInter which comes pre-installed (no dependencies) on most every major platform. If I was writing a game I might be interested, but I'd want to do some serious skinning of that GUI to make it look better. For applications installing the full wxWidgets or Qt toolkits would be less disk space and dependcies than OceanGUI and performance would probably be higher. TkInter also has many skins/themes you can add that makes it rather, although not 100% native looking on target systems. For example, check out http://tclmacbag.autons.net/screenshots.phtml For 86K download/dependencies I can get a rather Mac looking GUI. Cheers, PN 2009/2/16 : > I think I just found the GUI toolkit for Python I've been searching > for. It seems to meet all of the following requirements: > > * free software > * small (I don't need batteries -- Python already comes with those.) > * easy to use > * actively maintained > * cross-platform > * easy to install > * based on a stable and actively-maintained C library > * does not depend on an external scripting language (for example, > Tcl) > * well-documented > * not too many dependencies > * can easily integrate with PyOpenGL > * support for accessibility > > and it's also written in Python. > > I have no idea how it's stayed under the radar in the Python community > for this long, yet here it is: [OcempGUI](http://ocemp.sourceforge.net/ > gui.html). The C library it depends upon? [SDL](http:// > www.libsdl.org/) (via [PyGame](http://www.pygame.org/news.html)). > > The sf project page is . > > Installation only requires getting SDL installed, then PyGame, and > then a `sudo python setup.py install` for OcempGUI. `cd` into its `doc/ > examples` directory and run a few of the examples (ex. `python > hello_world.py`). > > The part of [the manual](http://ocemp.sourceforge.net/manual/ocempgui- > manual.html) that seems most like a beginner tutorial is ocemp.sourceforge.net/manual/gui_applications.html>. > -- > http://mail.python.org/mailman/listinfo/python-list > From matzke at berkeley.edu Mon Feb 16 02:54:25 2009 From: matzke at berkeley.edu (Nick Matzke) Date: Sun, 15 Feb 2009 23:54:25 -0800 Subject: hist without plotting In-Reply-To: <49990B3B.5070002@berkeley.edu> References: <49990B3B.5070002@berkeley.edu> Message-ID: <49991BB1.7060903@berkeley.edu> Nevermind, I was running the pylab hist; the numpy.histogram function generates the bar counts etc. without plotting the histogram. Cheers! Nick Nick Matzke wrote: > Hi, > > Is there a way to run the numpy hist function or something similar and > get the outputs (bins, bar heights) without actually producing the plot > on the screen? > > (R has a plot = false option, something like this is what I'm looking > for...) > > Cheers! > Nick > > -- ==================================================== Nicholas J. Matzke Ph.D. student, Graduate Student Researcher Huelsenbeck Lab Center for Theoretical Evolutionary Genomics 4151 VLSB (Valley Life Sciences Building) Department of Integrative Biology University of California, Berkeley Lab websites: http://ib.berkeley.edu/people/lab_detail.php?lab=54 http://fisher.berkeley.edu/cteg/hlab.html Dept. personal page: http://ib.berkeley.edu/people/students/person_detail.php?person=370 Lab personal page: http://fisher.berkeley.edu/cteg/members/matzke.html Lab phone: 510-643-6299 Dept. fax: 510-643-6264 Cell phone: 510-301-0179 Email: matzke at berkeley.edu Mailing address: Department of Integrative Biology 3060 VLSB #3140 Berkeley, CA 94720-3140 ----------------------------------------------------- "[W]hen people thought the earth was flat, they were wrong. When people thought the earth was spherical, they were wrong. But if you think that thinking the earth is spherical is just as wrong as thinking the earth is flat, then your view is wronger than both of them put together." Isaac Asimov (1989). "The Relativity of Wrong." The Skeptical Inquirer, 14(1), 35-44. Fall 1989. http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm ==================================================== From __peter__ at web.de Mon Feb 16 02:56:14 2009 From: __peter__ at web.de (Peter Otten) Date: Mon, 16 Feb 2009 08:56:14 +0100 Subject: hist without plotting References: Message-ID: Nick Matzke wrote: > Is there a way to run the numpy hist function or something similar and > get the outputs (bins, bar heights) without actually producing the plot > on the screen? > > (R has a plot = false option, something like this is what I'm looking > for...) First hit googling for numpy hist led me to http://www.scipy.org/Tentative_NumPy_Tutorial#head-aa75ec76530ff51a2e98071adb7224a4b793519e So pylab.hist() plots and numpy.histogram() just calculates. Peter From gh at ghaering.de Mon Feb 16 03:28:41 2009 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Mon, 16 Feb 2009 09:28:41 +0100 Subject: Display a list using PyQt In-Reply-To: References: Message-ID: member Basu wrote: > I'm writing an application with PyQt as the GUI toolkit. I have a > function that returns a simple list and I would like to update a List > View widget with it. However I can't get it to work. I'm not sure if I > need to subclass one of the Model classes, because it is just a list. > Can someone point me to a simple tutorial or give me instructions on how > to go about doing this? The attached example should help. Also see the examples included with PyQt. -- Gerhard -------------- next part -------------- A non-text attachment was scrubbed... Name: qt_list.py Type: text/x-python Size: 1073 bytes Desc: not available URL: From loveshadowdog at yahoo.com Mon Feb 16 03:46:40 2009 From: loveshadowdog at yahoo.com (loveshadowdog at yahoo.com) Date: Mon, 16 Feb 2009 00:46:40 -0800 (PST) Subject: Windows vista Message-ID: Hi. My name is toru. I start learning python couple weeks ago. I install the compiler from python.org. but I cannot use the IDLE program. (command line works fine so far) the error screen says that the my personal fire wall is blocking the program to run. I am not sure how to fix this. By the way, I heard many people said that this is because I am using windows vista. Does anyone know how to use IDLE program on Windows Vista machine? thank you. From rushenaly at gmail.com Mon Feb 16 04:34:34 2009 From: rushenaly at gmail.com (rushenaly at gmail.com) Date: Mon, 16 Feb 2009 01:34:34 -0800 (PST) Subject: Will multithreading make python less popular? Message-ID: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> Hi everybody, I am an engineer. I am trying to improve my software development abilities. I have started programming with ruby. I like it very much but i want to add something more. According to my previous research i have designed a learning path for myself. It's like something below. 1. Ruby (Mastering as much as possible) 2. Python (Mastering as much as possible) 3. Basic C++ or Basic Java And the story begins here. As i search on the net, I have found that because of the natural characteristics of python such as GIL, we are not able to write multi threaded programs. Oooops, in a kind of time with lots of cpu cores and we are not able to write multi threaded programs. That is out of fashion. How a such powerful language doesn't support multi threading. That is a big minus for python. But there is something interesting, something like multi processing. But is it a real alternative for multi threading. As i searched it is not, it requires heavy hardware requirements (lots of memory, lots of cpu power). Also it is not easy to implement, too much extra code... After all of that, i start to think about omiting python from my carrier path and directly choosing c++ or java. But i know google or youtube uses python very much. How can they choose a language which will be killed by multi threading a time in near future. I like python and its syntax, its flexibility. What do you think about multi threading and its effect on python. Why does python have such a break and what is the fix. Is it worth to make investment of time and money to a language it can not take advantage of multi cores? Thank you... Rushen From zhangyunfan2 at gmail.com Mon Feb 16 04:39:01 2009 From: zhangyunfan2 at gmail.com (vimuser) Date: Mon, 16 Feb 2009 01:39:01 -0800 (PST) Subject: How to enum all the users from a windows domain via python win32net module? Message-ID: <3f2bd06b-8f50-4ac4-b023-7c0837490304@u1g2000pre.googlegroups.com> I tried the command "net user /DOMAIN" in windows console(cmd.exe), and it showed me all the usernames in my domain without any problems. But when I tried it in python with these commands : info=win32net.NetUserEnum("DOMAIN_NAME",1), info=win32net.NetUserEnum(r"\\DOMAIN_NAME",1),and info=win32net.NetUserEnum("\\\\DOMAIN_NAME",1), I all got the System Error 53 (The network path was not found) . What should I do, if I intend to enum all the users from a windows domain via python win32net module? From mail at timgolden.me.uk Mon Feb 16 05:00:54 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 16 Feb 2009 10:00:54 +0000 Subject: How to enum all the users from a windows domain via python win32net module? In-Reply-To: <3f2bd06b-8f50-4ac4-b023-7c0837490304@u1g2000pre.googlegroups.com> References: <3f2bd06b-8f50-4ac4-b023-7c0837490304@u1g2000pre.googlegroups.com> Message-ID: <49993956.8080100@timgolden.me.uk> vimuser wrote: > I tried the command "net user /DOMAIN" in windows console(cmd.exe), > and it showed me all the usernames in my domain without any problems. > But when I tried it in python with these commands : > info=win32net.NetUserEnum("DOMAIN_NAME",1), > info=win32net.NetUserEnum(r"\\DOMAIN_NAME",1),and > info=win32net.NetUserEnum("\\\\DOMAIN_NAME",1), I all got the System > Error 53 (The network path was not found) . > > What should I do, if I intend to enum all the users from a windows > domain via python win32net module? > -- > http://mail.python.org/mailman/listinfo/python-list import win32net import win32netcon dc = win32net.NetGetAnyDCName (None, None) resume = 0 while 1: (_users, total, resume) = \ win32net.NetUserEnum ( dc, 3, win32netcon.FILTER_NORMAL_ACCOUNT, resume, win32netcon.MAX_PREFERRED_LENGTH ) for _user in _users: print _user['name'], _user['home_dir'], _user['profile'] break if not resume: break TJG From mail at timgolden.me.uk Mon Feb 16 05:03:02 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 16 Feb 2009 10:03:02 +0000 Subject: [Fwd: Re: Pythonic way to determine if a string is a number] Message-ID: <499939D6.5060405@timgolden.me.uk> [Resending after a bounce from mailing list] python at bdurham.com wrote: >> try: >> float (input) >> except ValueError: >> return False >> else: >> return True > > I follow the semantics, but I don't know why I would prefer the try/else > technique over the simpler: > > try: > float( input ) > return True > except ValueError: > return False In this case, I don't think you would. At least I would say it's no more than 50/50 depending on taste and probably more like 60/40 in favour of your solution. However there are situations where try-except-else more naturally expresses the code intent. Of course I can't think of a single one now, and it's not an easy thing to search my codebase for so I'll just press send and then think of an example two seconds later! Really wanted to make sure you were aware of it as an option; the else clause on try-except (and its cousin the for-else clause) are easily overlooked / forgotten. TJG From kaiser.vocote at gmail.com Mon Feb 16 05:06:52 2009 From: kaiser.vocote at gmail.com (Andreas Kaiser) Date: Mon, 16 Feb 2009 02:06:52 -0800 (PST) Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> Message-ID: <47deb5f1-bfae-439d-8239-c6c824a531a3@f20g2000yqg.googlegroups.com> On 16 Feb., 10:34, rushen... at gmail.com wrote: > Hi everybody, > I am an engineer. I am trying to improve my software development > abilities. I have started programming with ruby. I like it very much > but i want to add something more. According to my previous research i > have designed a learning path for myself. It's like something below. > ? ? ? 1. Ruby (Mastering as much as possible) > ? ? ? 2. Python (Mastering as much as possible) > ? ? ? 3. Basic C++ or Basic Java > And the story begins here. As i search on the net, ?I have found that > because of the natural characteristics of python such as GIL, we are > not able to write multi threaded programs. Oooops, in a kind of time > with lots of cpu cores and we are not able to write multi threaded > programs. That is out of fashion. How a such powerful language doesn't > support multi threading. That is a big minus for python. On comp.lang.ruby David Masover wrote this at 29 Jul. 2008, 07:55: ----- Right now, Ruby shares a problem with Python called the GIL -- the Global (or Giant) Interpreter Lock. What this means is that only one Ruby instruction may execute at a time. So even though they're using separate OS threads, and even though different Ruby threads might run on different cores, the speed of your program (at least the Ruby part) is limited to the speed of a single core. ----- Please don't mix threads and parallel processing on more then one CPU core. Andreas From alexionne at gmail.com Mon Feb 16 05:10:46 2009 From: alexionne at gmail.com (Aleksa Todorovic) Date: Mon, 16 Feb 2009 11:10:46 +0100 Subject: Will multithreading make python less popular? In-Reply-To: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> Message-ID: <74e474ac0902160210t591d82d5qd03e0a538671bc0a@mail.gmail.com> Hi, Rushen! I'm also new to using Python but from what I've found, GIL is very intentional decision. It is one of the features of Python which make it so powerful. I believe that if it didn't have GIL, Python wouldn't be half near where it is now (regarding it as a language, community, platform support, popularity, ...). The most important question is do you really need multi-threading for what you do? There is lot of software which doesn't require mt at all, or could be written without mt. Also, if you haven't learnt C++ or Java yet, mt is not something you should be worried about in the near future - there are lot of other, more important things, you need to learn before opening door mt hell :-) Best, Aleksa On Mon, Feb 16, 2009 at 10:34, wrote: > Hi everybody, > I am an engineer. I am trying to improve my software development > abilities. I have started programming with ruby. I like it very much > but i want to add something more. According to my previous research i > have designed a learning path for myself. It's like something below. > 1. Ruby (Mastering as much as possible) > 2. Python (Mastering as much as possible) > 3. Basic C++ or Basic Java > And the story begins here. As i search on the net, I have found that > because of the natural characteristics of python such as GIL, we are > not able to write multi threaded programs. Oooops, in a kind of time > with lots of cpu cores and we are not able to write multi threaded > programs. That is out of fashion. How a such powerful language doesn't > support multi threading. That is a big minus for python. But there is > something interesting, something like multi processing. But is it a > real alternative for multi threading. As i searched it is not, it > requires heavy hardware requirements (lots of memory, lots of cpu > power). Also it is not easy to implement, too much extra code... > > After all of that, i start to think about omiting python from my > carrier path and directly choosing c++ or java. But i know google or > youtube uses python very much. How can they choose a language which > will be killed by multi threading a time in near future. I like python > and its syntax, its flexibility. > > What do you think about multi threading and its effect on python. Why > does python have such a break and what is the fix. Is it worth to make > investment of time and money to a language it can not take advantage > of multi cores? > > Thank you... > Rushen > -- > http://mail.python.org/mailman/listinfo/python-list > -- Aleksa Todorovic - Lead Programmer Eipix Entertainment http://www.eipix.com/ From si.422a at yahoo.com Mon Feb 16 05:16:51 2009 From: si.422a at yahoo.com (Saeed Iravani) Date: Mon, 16 Feb 2009 02:16:51 -0800 (PST) Subject: explain Message-ID: <654311.52341.qm@web111202.mail.gq1.yahoo.com> I download python 2.5.4 and install but I dont know that how perform python? I dont know from which directory perform python? Please explain for me. Thank you -------------- next part -------------- An HTML attachment was scrubbed... URL: From si.422a at yahoo.com Mon Feb 16 05:24:13 2009 From: si.422a at yahoo.com (Saeed Iravani) Date: Mon, 16 Feb 2009 02:24:13 -0800 (PST) Subject: explain Message-ID: <255795.88503.qm@web111210.mail.gq1.yahoo.com> I download python 2.5.4 and install but I dont know that how run python? I dont know from which directory run python? Please explain for me. Thank you -------------- next part -------------- An HTML attachment was scrubbed... URL: From asmodai at in-nomine.org Mon Feb 16 05:26:13 2009 From: asmodai at in-nomine.org (Jeroen Ruigrok van der Werven) Date: Mon, 16 Feb 2009 11:26:13 +0100 Subject: explain In-Reply-To: <654311.52341.qm@web111202.mail.gq1.yahoo.com> References: <654311.52341.qm@web111202.mail.gq1.yahoo.com> Message-ID: <20090216102613.GE39358@nexus.in-nomine.org> -On [20090216 11:17], Saeed Iravani (si.422a at yahoo.com) wrote: >I download python 2.5.4 and install but I dont know that how perform python? >I dont know from which directory perform python? It would help if you would clarify which operating system you are using. On Unix/Linux systems you make sure to 'rehash' your $PATH or add the appropriate directory to the $PATH variable. On Windows, you set your environment variable PATH to include the path to Python programs (typically something like C:\Python25), which you can find under the system control panel. -- Jeroen Ruigrok van der Werven / asmodai ????? ?????? ??? ?? ?????? http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B Earth to earth, ashes to ashes, dust to dust... From michele.simionato at gmail.com Mon Feb 16 05:27:11 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Mon, 16 Feb 2009 02:27:11 -0800 (PST) Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> Message-ID: <28e3612d-2e91-4a91-82cb-5fb2deda95fd@q9g2000yqc.googlegroups.com> On Feb 16, 10:34?am, rushen... at gmail.com wrote: > Hi everybody, > I am an engineer. I am trying to improve my software development > abilities. I have started programming with ruby. I like it very much > but i want to add something more. According to my previous research i > have designed a learning path for myself. It's like something below. > ? ? ? 1. Ruby (Mastering as much as possible) > ? ? ? 2. Python (Mastering as much as possible) > ? ? ? 3. Basic C++ or Basic Java > And the story begins here. As i search on the net, ?I have found that > because of the natural characteristics of python such as GIL, we are > not able to write multi threaded programs. Oooops, in a kind of time > with lots of cpu cores and we are not able to write multi threaded > programs. That is out of fashion. How a such powerful language doesn't > support multi threading. That is a big minus for python. But there is > something interesting, something like multi processing. But is it a > real alternative for multi threading. As i searched it is not, it > requires heavy hardware requirements (lots of memory, lots of cpu > power). Also it is not easy to implement, too much extra code... multiprocessing is already implemented for you in the standard library. Of course it does not require heavy hardware requirements. > After all of that, i start to think about omiting python from my > carrier path and directly choosing c++ or java. But i know google or > youtube uses python very much. How can they choose a language which > will be killed by multi threading a time in near future. I like python > and its syntax, its flexibility. > > What do you think about multi threading and its effect on python. Why > does python have such a break and what is the fix. Is it worth to make > investment of time and money to a language it can not take advantage > of multi cores? You can take advantage of multi cores, just not with threads but with processes, which BTW is the right way to go in most situations. So (assuming you are not a troll) you are just mistaken in thinking that the only way to use multicores is via multithreading. Michele Simionato From asmodai at in-nomine.org Mon Feb 16 05:29:16 2009 From: asmodai at in-nomine.org (Jeroen Ruigrok van der Werven) Date: Mon, 16 Feb 2009 11:29:16 +0100 Subject: Windows vista In-Reply-To: References: Message-ID: <20090216102916.GF39358@nexus.in-nomine.org> -On [20090216 09:50], loveshadowdog at yahoo.com (loveshadowdog at yahoo.com) wrote: >the error screen says that the my personal fire wall is blocking the >program to run. My default Windows Vista x64 installation is not blocking my IDLE at all, so it might be you're not using the standard Windows firewall but perhaps some third-party one. Most of the time in the firewall configuration windows you can add specific executables to be allowed access. As such you probably have to point it to the C:\Python25\Python.exe file, but that's just a guess. -- Jeroen Ruigrok van der Werven / asmodai ????? ?????? ??? ?? ?????? http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B Earth to earth, ashes to ashes, dust to dust... From greg.ewing at canterbury.ac.nz Mon Feb 16 05:45:50 2009 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Mon, 16 Feb 2009 23:45:50 +1300 Subject: ANN: Assembly Line 0.8.2 Message-ID: I have released an updated version of Assembly Line, my entry in PyWeek 6 and later the Pyggy Awards. http://media.pyweek.org/dl/1007/greg_pgF09/AssemblyLine-0.8.2.zip About Assembly Line ------------------- Become a FADE! That's Factory Automation Design Engineer for Pixall Manufacturing, the world leader in pixellated products. We give you product designs from our R&D department, and you design and build factories to manufacture them as efficiently possible. Make a good profit and you'll earn big bonuses and a huge salary! -- Greg From digitig at gmail.com Mon Feb 16 06:07:49 2009 From: digitig at gmail.com (Tim Rowe) Date: Mon, 16 Feb 2009 11:07:49 +0000 Subject: Will multithreading make python less popular? In-Reply-To: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> Message-ID: 2009/2/16 : > Hi everybody, > I am an engineer. I am trying to improve my software development > abilities. I have started programming with ruby. I like it very much > but i want to add something more. According to my previous research i > have designed a learning path for myself. It's like something below. > 1. Ruby (Mastering as much as possible) > 2. Python (Mastering as much as possible) > 3. Basic C++ or Basic Java > And the story begins here. As i search on the net, I have found that > because of the natural characteristics of python such as GIL, we are > not able to write multi threaded programs. Oooops, in a kind of time > with lots of cpu cores and we are not able to write multi threaded > programs. That is out of fashion. How a such powerful language doesn't > support multi threading. That is a big minus for python. In a way, you've answered your own question. Why are you learning three languages? Perhaps you've already realised that being Turing-complete isn't the last word in language choice; that different languages make different compromises, so the best language for one task may not be the best language for a different task. Ok, Python doesn't cope well with threading. It doesn't cope well with hard real-time, either. So what? A deep saucepan isn't much use for making an omlette (it can be done, but it's inefficient), but it's ideal for making soup. Just because multiple cores are available doesn't mean they will help your program significantly. Most real-world programs work just fine in a single core, and it usually just isn't worth all of the extra design effort, coding effort and debugging effort of threading to cut the user response time down from a tenth of a second to a twentieth. For *most* applications the single-thread Python programmer will have something written, shipped and doing the job whilst the multi-thread programmer is still trying to debug an intermittent livelock that goes away whenever instrumentation is added. For those few cases where threading is a genuine advantage, Python is not ideal. But in the real world I doubt they're enough to make a significant dent in Python's popularity. -- Tim Rowe From yanegomi at gmail.com Mon Feb 16 06:50:22 2009 From: yanegomi at gmail.com (Garrett Cooper) Date: Mon, 16 Feb 2009 03:50:22 -0800 Subject: Creating custom formatter function Message-ID: <364299f40902160350n8583e88o20f7799eca3934b6@mail.gmail.com> Hello Python folks, I have a function where I'd like to prefix a format string via a `prefix' string. The definition of the base method is as follows: #START CODE def print_message(prefix, out_stream, fmt, *args, **kwargs): """ Print out [prefix]: [message] """ message = fmt if 0 < len(kwargs.keys()): message = message % kwargs if 0 < len(args): message = message % args out_stream.write(message + "\n") #END CODE My python 2.4.5 interpreter fails at `message % args' claiming the following: File "logging.py", line 10, in print_message message = message % (args) TypeError: not all arguments converted during string formatting Thus I was wondering what the proper means was for formatting strings. I'm new to this portion of Python, so I obviously didn't apply the right syntax. TIA! -Garrett From rushenaly at gmail.com Mon Feb 16 07:24:27 2009 From: rushenaly at gmail.com (rushenaly at gmail.com) Date: Mon, 16 Feb 2009 04:24:27 -0800 (PST) Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> Message-ID: <9c001ccd-24cb-4bbd-af31-94ad0f255982@z1g2000yqn.googlegroups.com> Hi again, Dear Andreas I know about GIL in ruby interpreter, they are trying to solve problems because of GIL but it is not so important for me because i like ruby because of its esthetic and it helps me to grasp some programming concepts. As i know it is not so powerful language like java. (Powerful language : rich libraries, wide community, very variety of usage). why i want to learn python because it has syntax like ruby but it is also powerful language, not of course as much as java or c++ And also, i am trying to find an answer to the question mark in my head. Is there a way to use multi cores in python as much effective and easier as multi threading. Dear Aleksa Of course i have a long way to ago even if i am too old for these things. However, i think that being able to use both cores or more is a very big plus for execution time, speed like these. I believe many programs will be rewritten to be able to use multiple cores. Dear Michele As i know every process has own hardware sources like memory and cpu so i think it requires more source than multi threading. Dear Tim I want to learn python + c++ or java because of the desire of having python's felxibility and easiness and c++ or java's stability and speed and power together. Thank you Rushen From digitig at gmail.com Mon Feb 16 07:50:42 2009 From: digitig at gmail.com (Tim Rowe) Date: Mon, 16 Feb 2009 12:50:42 +0000 Subject: Will multithreading make python less popular? In-Reply-To: <9c001ccd-24cb-4bbd-af31-94ad0f255982@z1g2000yqn.googlegroups.com> References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <9c001ccd-24cb-4bbd-af31-94ad0f255982@z1g2000yqn.googlegroups.com> Message-ID: 2009/2/16 : > I want to learn python + c++ or java because of the desire of having > python's felxibility and easiness and c++ or java's stability and > speed and power together. Yes, that's what I mean by different tradeoffs. Python is much easier to program in than C++ or Java (in my experience, at least), but C++ and Java scale better and at least have the potential to be faster. I'm not convinced that library support is significantly better for C++ or Java -- Python's libraries seem pretty rich to me. And that extra speed might not be needed as often as you think. My postgrad dissertation involved heavy number-crunching on large data sets, and in my proposal I said I'd switch from Python to C++ when Python got too slow. In fact, Python never did get too slow (I didn't even have to switch to numpy), and plugging together ad-hoc modules, defined in an XML script, was a dream in Python when I'd probably still be coding it today in C++. Horses for courses. It's almost always wrong to say that language A is better than language B; the most you can say is that language A is better than language B for some specific task. -- Tim Rowe From tim.wintle at teamrubber.com Mon Feb 16 07:54:36 2009 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Mon, 16 Feb 2009 12:54:36 +0000 Subject: Module to read/write MIDI ? In-Reply-To: References: Message-ID: <1234788876.5567.2.camel@tim-laptop> > I had my first look around pypi.python.org/pypi yesterday and didn't > see anything. Is there a MIDI-module for Python ? If not, I'll > email Sean to ask if he'd mind me translating his module into Python3... This is the only project I have seen that aims to do that - I haven't actually used it, and there might be others out there (I believe pygame supports midi-output). > > Regards, Peter > From jldunn2000 at googlemail.com Mon Feb 16 07:59:32 2009 From: jldunn2000 at googlemail.com (loial) Date: Mon, 16 Feb 2009 04:59:32 -0800 (PST) Subject: replace ftp by local copy Message-ID: <2f223a64-4459-4905-b44a-07da12048895@c12g2000yqj.googlegroups.com> I have been given an old python application that calls ftplib in many places to copy files to a remote server. I have been given the task of cloneing this code so that ftp is not used, but files are just copied locally in a scenerio where ftp is not available. The code is not well structured which makes this more difficult. Before starting this just wondered if anyone has previously done anything like overriding the ftplib module so that I can leave the existing code largely unchanged but have the ftp commands just copy files locally? Just thought I'd ask before getting started. From fmaresca at gmail.com Mon Feb 16 08:02:06 2009 From: fmaresca at gmail.com (Fernando M. Maresca) Date: Mon, 16 Feb 2009 11:02:06 -0200 Subject: logging and daemons Message-ID: <20090216130206.GA20397@gmail.com> Hello. I'm in the process of replacing a custom logger class in one of my apps that has several daemons. In the last step of daemonizing a program, after closing fds, stderr and stdout are redirected to the logfile of the program. Now, I'm trying to use TimedRotatingFileHandler as the only channel when the programs run in daemon mode. My problem is: I can't see a goog way to redirect stderr/stdout both to the logger. Note that I don't have any print statements in any of my code, but I can't be sure about all the modules I'm importing, and I like to get any uncached exception info that may go to stderr/stdout to show up in the logfiles. Any ideas? Thanks a lot, -- Fernando -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 204 bytes Desc: Digital signature URL: From yanegomi at gmail.com Mon Feb 16 08:07:45 2009 From: yanegomi at gmail.com (Garrett Cooper) Date: Mon, 16 Feb 2009 05:07:45 -0800 Subject: logging and daemons In-Reply-To: <20090216130206.GA20397@gmail.com> References: <20090216130206.GA20397@gmail.com> Message-ID: <364299f40902160507g4eca4be2yda535199451ce5a8@mail.gmail.com> On Mon, Feb 16, 2009 at 5:02 AM, Fernando M. Maresca wrote: > > Hello. > > I'm in the process of replacing a custom logger class in one of my apps > that has several daemons. In the last step of daemonizing a program, > after closing fds, stderr and stdout are redirected to the logfile of > the program. > > Now, I'm trying to use TimedRotatingFileHandler as the only channel when > the programs run in daemon mode. My problem is: I can't see a goog way > to redirect stderr/stdout both to the logger. > > Note that I don't have any print statements in any of my code, but I > can't be sure about all the modules I'm importing, and I like to get any > uncached exception info that may go to stderr/stdout to show up in the > logfiles. > > Any ideas? > Thanks a lot, Hopefully this'll answer your question: You can actually set sys.std[err|out] to your ?file? descriptor of choice in python (it has to have read, write, and flush methods, IIRC to function). The only thing is (like all things dealing with multiple file descriptors like std[err|out]) the output may come in out of order due to flushing and insertion into the buffers, but it shouldn't be as much of an issue considering that the file descriptor for both items is the same descriptor, but this is just a note of forewarning. nose does something similar with the way that it scrapes stderr / stdout for exception data and messages. -Garrett From fmaresca at gmail.com Mon Feb 16 08:15:16 2009 From: fmaresca at gmail.com (Fernando M. Maresca) Date: Mon, 16 Feb 2009 11:15:16 -0200 Subject: logging and daemons In-Reply-To: <364299f40902160507g4eca4be2yda535199451ce5a8@mail.gmail.com> References: <20090216130206.GA20397@gmail.com> <364299f40902160507g4eca4be2yda535199451ce5a8@mail.gmail.com> Message-ID: <20090216131516.GA21655@gmail.com> Hello, thanks for the answer. On Mon, Feb 16, 2009 at 05:07:45AM -0800, Garrett Cooper wrote: > You can actually set sys.std[err|out] to your ?file? descriptor of > choice in python (it has to have read, write, and flush methods, IIRC > to function). The only thing is (like all things dealing with multiple > file descriptors like std[err|out]) the output may come in out of > order due to flushing and insertion into the buffers, but it shouldn't > be as much of an issue considering that the file descriptor for both > items is the same descriptor, but this is just a note of forewarning. Yes, but I'm trying to use *TimedRotating*FileHandler, which makes the fd of the logfile change in every rotation of the logfile. So the direct approach of std[out|err] redirection to the logfile fd obtained from the logger instance is unusable (it works fine with a simple file handler). I'm looking into this because I really need rotating, because when debugging is on, large amounts of data are logged, and because I like the logging module approach in every aspect. Also, may it be possible to derive the class and add a file-like write method? Anyone using logging in this manner? Cheers, -- Fernando -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 204 bytes Desc: Digital signature URL: From andrew at acooke.org Mon Feb 16 08:17:06 2009 From: andrew at acooke.org (andrew cooke) Date: Mon, 16 Feb 2009 10:17:06 -0300 (CLST) Subject: Will multithreading make python less popular? In-Reply-To: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> Message-ID: <977bad202990de5797c2efcf8d50ed81.squirrel@localhost> rushenaly at gmail.com wrote: > Hi everybody, > I am an engineer. I am trying to improve my software development > abilities. I have started programming with ruby. I like it very much > but i want to add something more. According to my previous research i > have designed a learning path for myself. It's like something below. > 1. Ruby (Mastering as much as possible) > 2. Python (Mastering as much as possible) > 3. Basic C++ or Basic Java > And the story begins here. As i search on the net, I have found that > because of the natural characteristics of python such as GIL, we are > not able to write multi threaded programs. Oooops, in a kind of time > with lots of cpu cores and we are not able to write multi threaded > programs. That is out of fashion. How a such powerful language doesn't > support multi threading. That is a big minus for python. But there is > something interesting, something like multi processing. But is it a > real alternative for multi threading. As i searched it is not, it > requires heavy hardware requirements (lots of memory, lots of cpu > power). Also it is not easy to implement, too much extra code... I understand why you are asking this question - you want to learn, and that is good - but as you say, you are a beginner, and you are focussing on one thing that has caught your eye when there are many other issues that are more important. The GIL is an implementation detail. I suspect that it could be largely removed if there was sufficient need. But that still wouldn't make Python a good language for programming on multiple cores. That's not as big a deal as you think, because we currently DON'T KNOW what would make a good language for programming on multiple cores - it's an open topic in the wider community. It may be, for example, that the best approaches for concurrent programming require a lot of automatic pre-processing that needs static type information. Or that mutable state is simply too much of a problem and pure functional programming is the only way forwards. Both of these would be much more serious problems for Python than the GIL. On the other hand, Python has inbuilt support for co-routines. Experience gained with that might lead towards a more actors-like solution that fits naturally within Python. So my first point is that you are worrying about a problem that no-one yet know how to solve, and worrying about a small and largely irrelevant part of that. Second, you are committing the common mistake of over-estimating the importance of efficiency. Python is not a fast language; it never has been. That does not stop it being extremely useful. This is largely because when it needs to do "hard work" it delegates to C libraries. Why can this not apply to concurrent programming too? Maybe the top level logic will stay in a single thread, because that is easier to program, but libraries will use multiple cores. So my second point is that you are being too restrictive in considering what a future solution might look like. In conclusion, then, I strongly suggest you stop worrying so much about things that you don't yet have the experience to see completely, and instead get more experience under your belt. That sounds more harsh than I really mean - obviously worrying about this kind of thing is part of learning. Incidentally, if you already know Ruby and want to improve your abilities I am not sure learning Python is the best use of your time. The two languages are very similar. You might be better taking a huge leap to something like Haskell or OCaml. Or, if you want to get hands-on experience of concurrency now, Erlang. Andrew > After all of that, i start to think about omiting python from my > carrier path and directly choosing c++ or java. But i know google or > youtube uses python very much. How can they choose a language which > will be killed by multi threading a time in near future. I like python > and its syntax, its flexibility. > > What do you think about multi threading and its effect on python. Why > does python have such a break and what is the fix. Is it worth to make > investment of time and money to a language it can not take advantage > of multi cores? > > Thank you... > Rushen > -- > http://mail.python.org/mailman/listinfo/python-list > > From andrew at acooke.org Mon Feb 16 08:21:47 2009 From: andrew at acooke.org (andrew cooke) Date: Mon, 16 Feb 2009 10:21:47 -0300 (CLST) Subject: Will multithreading make python less popular? In-Reply-To: <977bad202990de5797c2efcf8d50ed81.squirrel@localhost> References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <977bad202990de5797c2efcf8d50ed81.squirrel@localhost> Message-ID: <2f9b1132b1d38c74810f4021f6b3101b.squirrel@localhost> andrew cooke wrote: > something like Haskell or OCaml. Or, if you want to get hands-on > experience of concurrency now, Erlang. I think for once I said something useful there. I think you would probably enjoy Erlang, and it would be very useful for understanding concurrency. Also, Erlang is not as strange a language as Haskell or OCaml. You will probably find it quite familiar. And there's an excellent book (Joe Armstrong's "Programming Erlang"). At the risk of hastening Python's demise :o) I strongly encourage you to learn Erlang instead of Python. Andrew From yanegomi at gmail.com Mon Feb 16 08:23:05 2009 From: yanegomi at gmail.com (Garrett Cooper) Date: Mon, 16 Feb 2009 05:23:05 -0800 Subject: logging and daemons In-Reply-To: <20090216131516.GA21655@gmail.com> References: <20090216130206.GA20397@gmail.com> <364299f40902160507g4eca4be2yda535199451ce5a8@mail.gmail.com> <20090216131516.GA21655@gmail.com> Message-ID: <364299f40902160523l68ff57e4yac4ffbc828360d35@mail.gmail.com> On Mon, Feb 16, 2009 at 5:15 AM, Fernando M. Maresca wrote: > Hello, thanks for the answer. > > On Mon, Feb 16, 2009 at 05:07:45AM -0800, Garrett Cooper wrote: >> You can actually set sys.std[err|out] to your ?file? descriptor of >> choice in python (it has to have read, write, and flush methods, IIRC >> to function). The only thing is (like all things dealing with multiple >> file descriptors like std[err|out]) the output may come in out of >> order due to flushing and insertion into the buffers, but it shouldn't >> be as much of an issue considering that the file descriptor for both >> items is the same descriptor, but this is just a note of forewarning. > Yes, but I'm trying to use *TimedRotating*FileHandler, which makes the > fd of the logfile change in every rotation of the logfile. So the direct > approach of std[out|err] redirection to the logfile fd obtained from > the logger instance is unusable (it works fine with a simple file > handler). > I'm looking into this because I really need rotating, because when > debugging is on, large amounts of data are logged, and because I like > the logging module approach in every aspect. I cannot comment about this because I haven't used this module before. > Also, may it be possible to derive the class and add a file-like write > method? Anyone using logging in this manner? Indeed, yes. That's sort of what I was hinting at with my statement that you must have a read, write and flush method for your class. Now that I think back, other modules like pexpect implement simple logic to deal with writing to psuedo file descriptors as well. Locking the data streams may or may not be required -- I'm not sure what the underlaying portions of python expose or do not expose in terms of scheduling in output streams. HTH, -Garrett From rushenaly at gmail.com Mon Feb 16 08:26:52 2009 From: rushenaly at gmail.com (rushenaly at gmail.com) Date: Mon, 16 Feb 2009 05:26:52 -0800 (PST) Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> Message-ID: <0b304e24-1017-4c6b-8b94-6054f1dadc05@j38g2000yqa.googlegroups.com> Dear Andrew, I think reading "beating the averages" by paul graham before some experience is not a very good decision. :) Thank you Andrew From veerendra.jangid at gmail.com Mon Feb 16 08:39:23 2009 From: veerendra.jangid at gmail.com (VEERENDRA) Date: Mon, 16 Feb 2009 05:39:23 -0800 (PST) Subject: to access the gretest Message-ID: <2b89626e-e038-4eef-aa74-4405b4c3c6bb@s9g2000prg.googlegroups.com> Vjrocks.comhttp://www.vjrocks.com/ BCA BCA Ist YEARhttp://www.vjrocks.com/BCA_Ist_year.html BCA IInd YEARhttp://www.vjrocks.com/BCA_IInd_year.html BCA IIIrd YEARhttp://www.vjrocks.com/BCA_IIIrd_year.html LANGUAGE Introduction to Computershttp://www.vjrocks.com/Introduction to Computers.html Programming IN Chttp://www.vjrocks.com/Introduction to Computers.html C++http://www.vjrocks.com/CPlusPlus.html Javahttp://www.vjrocks.com/Java.htmlVisual Basic.html Visual Basichttp://www.vjrocks.com/Visual Basic.html From ndbecker2 at gmail.com Mon Feb 16 08:39:35 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Mon, 16 Feb 2009 08:39:35 -0500 Subject: logging and daemons References: <20090216130206.GA20397@gmail.com> <364299f40902160507g4eca4be2yda535199451ce5a8@mail.gmail.com> <20090216131516.GA21655@gmail.com> <364299f40902160523l68ff57e4yac4ffbc828360d35@mail.gmail.com> Message-ID: Garrett Cooper wrote: > On Mon, Feb 16, 2009 at 5:15 AM, Fernando M. Maresca > wrote: >> Hello, thanks for the answer. >> >> On Mon, Feb 16, 2009 at 05:07:45AM -0800, Garrett Cooper wrote: >>> You can actually set sys.std[err|out] to your ?file? descriptor of >>> choice in python (it has to have read, write, and flush methods, IIRC >>> to function). The only thing is (like all things dealing with multiple >>> file descriptors like std[err|out]) the output may come in out of >>> order due to flushing and insertion into the buffers, but it shouldn't >>> be as much of an issue considering that the file descriptor for both >>> items is the same descriptor, but this is just a note of forewarning. >> Yes, but I'm trying to use *TimedRotating*FileHandler, which makes the >> fd of the logfile change in every rotation of the logfile. So the direct >> approach of std[out|err] redirection to the logfile fd obtained from >> the logger instance is unusable (it works fine with a simple file >> handler). >> I'm looking into this because I really need rotating, because when >> debugging is on, large amounts of data are logged, and because I like >> the logging module approach in every aspect. > > I cannot comment about this because I haven't used this module before. > >> Also, may it be possible to derive the class and add a file-like write >> method? Anyone using logging in this manner? > > Indeed, yes. That's sort of what I was hinting at with my statement > that you must have a read, write and flush method for your class. Now > that I think back, other modules like pexpect implement simple logic > to deal with writing to psuedo file descriptors as well. > > Locking the data streams may or may not be required -- I'm not sure > what the underlaying portions of python expose or do not expose in > terms of scheduling in output streams. > > HTH, > -Garrett > -- > http://mail.python.org/mailman/listinfo/python-list I use this, but for my own specialized purpose: import atexit class logger (object): def __init__ (self, name): self.name = name # final file name self.f = open (self.name, 'w') atexit.register (self.__del__) def write (self, stuff): self.f.write (stuff) def close (self): self.f.close() def flush (self): self.f.flush() def reopen (self): self.f.flush() self.f.close() os.rename (self.name, self.name + '.old') self.f = open (self.name, 'w') def __del__ (self): try: os.remove (self.name + '.old') except: pass From a_modelo at yahoo.com Mon Feb 16 08:45:09 2009 From: a_modelo at yahoo.com (www.livtotravel.blogspot.com) Date: Mon, 16 Feb 2009 05:45:09 -0800 (PST) Subject: What is a phyton? Message-ID: is phyton a programming language? what can a python do? how is it different from others? From alan.isaac at gmail.com Mon Feb 16 08:47:11 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Mon, 16 Feb 2009 13:47:11 GMT Subject: Creating custom formatter function In-Reply-To: References: Message-ID: On 2/16/2009 6:50 AM Garrett Cooper apparently wrote: > I was wondering what the proper means was for formatting > strings. http://docs.python.org/library/string.html#string-formatting http://docs.python.org/library/string.html#template-strings http://docs.python.org/library/stdtypes.html#string-formatting As for the last: "values must be a tuple with exactly the number of items specified by the format string, or a single mapping object (for example, a dictionary)" unless you need only a single argument in your format string. hth, Alan Isaac From mamahitasela at yahoo.com Mon Feb 16 08:47:22 2009 From: mamahitasela at yahoo.com (Mamahita Sela) Date: Mon, 16 Feb 2009 05:47:22 -0800 (PST) Subject: Threads in PyGTK: keep typing while ping-ing Message-ID: <510115.40482.qm@web46216.mail.sp1.yahoo.com> Dear All, I have read several howtos for threading in PyGTK. I have tried some but with no luck. What i want is: i can keep typing in gtk.TextView while periodically doing ping some hosts. I think, the thread part is working since i can ping so fast (even for not reply host, around 3 s for 27 no-reply-host). But, when the ping action is running, i can not typing in textview. What i type while pinging will show up after ping action is done. (I am using 2.5.1, pygtk 2.10.6 on Linux x86) This is my code: import threading import commands import gtk import gobject gtk.gdk.threads_init() class PingHost(threading.Thread): def __init__(self, host): threading.Thread.__init__(self) self.host = host self.result = () def run(self): self.result = self.host, commands.getstatusoutput('ping %s -c1' %(self.host))[0] class Main: def __init__(self): self.win = gtk.Window() self.win.connect('destroy', gtk.main_quit) # self.textb = gtk.TextBuffer() self.textv = gtk.TextView(self.textb) self.textv.set_size_request(500, 500) # self.win.add(self.textv) self.win.show_all() # gobject.timeout_add(5000, self.do_ping) def do_ping(self): all_threads = [] # for h in range(100, 105): host = '192.168.0.%d' %(h) # worker = PingHost(host) worker.start() all_threads.append(worker) # for t in all_threads: t.join() print t.result # return True if __name__ == '__main__': app = Main() gtk.main() Any help would be appreciated :) Best regards, M From alexionne at gmail.com Mon Feb 16 09:05:26 2009 From: alexionne at gmail.com (Aleksa Todorovic) Date: Mon, 16 Feb 2009 15:05:26 +0100 Subject: Will multithreading make python less popular? In-Reply-To: <9c001ccd-24cb-4bbd-af31-94ad0f255982@z1g2000yqn.googlegroups.com> References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <9c001ccd-24cb-4bbd-af31-94ad0f255982@z1g2000yqn.googlegroups.com> Message-ID: <74e474ac0902160605g1cac34e5n387f22250be047ee@mail.gmail.com> Or the other way around :-) Little off-topic, but... After several months of fighting with Java threads, dead locks, live locks, race conditions, I've rewritten my game server synchronization so that threads are executed in concurrent way (with only exceptions being socket sending and recieving threads), and all synchronization is implemented on top of Java blocking structures (little blasphemy: the way Stackless does it). After that change, the game suddenly started working like a charm! On Mon, Feb 16, 2009 at 13:24, wrote: > Of course i have a long way to ago even if i am too old for these > things. However, i think that being able to use both cores or more is > a very big plus for execution time, speed like these. I believe many > programs will be rewritten to be able to use multiple cores. -- Aleksa Todorovic - Lead Programmer Eipix Entertainment http://www.eipix.com/ From rushenaly at gmail.com Mon Feb 16 09:18:35 2009 From: rushenaly at gmail.com (rushenaly at gmail.com) Date: Mon, 16 Feb 2009 06:18:35 -0800 (PST) Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <9c001ccd-24cb-4bbd-af31-94ad0f255982@z1g2000yqn.googlegroups.com> Message-ID: <6c29ea7b-d30e-4358-8a3f-54758b1f4cde@o11g2000yql.googlegroups.com> Dear Aleksa, As you mentioned, using multi cores makes programs more fast and more popular. But what about stackless python? Does it interpret same set of python libraries with Cpython or Does it have a special sub set? Thank you Rusen From python at rgbaz.eu Mon Feb 16 09:35:05 2009 From: python at rgbaz.eu (Python) Date: Mon, 16 Feb 2009 15:35:05 +0100 Subject: What is a phyton? In-Reply-To: References: Message-ID: <60C24207-5688-42E9-AD21-D07AB655AB76@rgbaz.eu> On 16 feb 2009, at 14:45, www.livtotravel.blogspot.com wrote: > is phyton a programming language? what can a python do? how is it > different from others? > -- If i were to replace 'python' with 'french' would you be willing to write the answer in one email? it's gonna be a loooooong email... if you want to know, type the same questions in google... or start by reading http://www.python.org if you don;t want that, then maybe go to a zoo and follow the signs ;) gr Arno From thorsten at thorstenkampe.de Mon Feb 16 09:37:29 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Mon, 16 Feb 2009 15:37:29 +0100 Subject: What is a phyton? References: Message-ID: * www.livtotravel.blogspot.com (Mon, 16 Feb 2009 05:45:09 -0800 (PST)) > is phyton a programming language? http://en.wikipedia.org/wiki/Phyton From exarkun at divmod.com Mon Feb 16 09:44:36 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Mon, 16 Feb 2009 09:44:36 -0500 Subject: Threads in PyGTK: keep typing while ping-ing In-Reply-To: <510115.40482.qm@web46216.mail.sp1.yahoo.com> Message-ID: <20090216144436.12853.561778781.divmod.quotient.10894@henry.divmod.com> On Mon, 16 Feb 2009 05:47:22 -0800 (PST), Mamahita Sela wrote: >Dear All, > >I have read several howtos for threading in PyGTK. I have tried some but with no luck. > >What i want is: i can keep typing in gtk.TextView while periodically doing ping some hosts. You don't need threads for this. The GTK mainloop supports socket event sources. This lets you deal with the GUI and with the network in a single thread without blocking anything. > >I think, the thread part is working since i can ping so fast (even for not reply host, around 3 s for 27 no-reply-host). But, when the ping action is running, i can not typing in textview. What i type while pinging will show up after ping action is done. This is because you're joining the threads in the GTK thread. Joining blocks until the thread being joined exits. While you're blocking the GTK thread like this, the GTK GUI is not updated. If you want to keep using threads, then you need a way to avoid joining the threads until you know they're done. Jean-Paul From me at gustavonarea.net Mon Feb 16 09:50:22 2009 From: me at gustavonarea.net (Gustavo Narea) Date: Mon, 16 Feb 2009 06:50:22 -0800 (PST) Subject: Turning a signature-changing decorator into a signature-preserving one References: <6b0518e3-142c-4555-8ad0-02c559f6b224@u13g2000yqg.googlegroups.com> <6b0874ad-4c30-4b3f-a559-f83465d332da@z1g2000yqn.googlegroups.com> <2610ff6e-d487-42e8-a619-aa4db6f9556f@h5g2000yqh.googlegroups.com> Message-ID: On Feb 14, 3:27 pm, Michele Simionato wrote: > I lack the context to see how this could be fixed in your case, but > this a not a show stopper, you can just keep the original decorator > and forget about making itsignature preserving. I'm sorry for the possibly dumb question, but how can I do that? Thanks for all the time you've spent on this, Michele. - Gustavo. From deets at nospam.web.de Mon Feb 16 09:52:55 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 16 Feb 2009 15:52:55 +0100 Subject: What is a phyton? In-Reply-To: References: Message-ID: <6vtcu7Flu37sU1@mid.uni-berlin.de> Thorsten Kampe schrieb: > * (Mon, 16 Feb 2009 05:45:09 -0800 (PST)) >> is phyton a programming language? > > http://en.wikipedia.org/wiki/Phyton Thanks for quoting the OPs spam name so that the visibility of his post is increased. Diez From michele.simionato at gmail.com Mon Feb 16 09:56:20 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Mon, 16 Feb 2009 06:56:20 -0800 (PST) Subject: Turning a signature-changing decorator into a signature-preserving one References: <6b0518e3-142c-4555-8ad0-02c559f6b224@u13g2000yqg.googlegroups.com> <6b0874ad-4c30-4b3f-a559-f83465d332da@z1g2000yqn.googlegroups.com> <2610ff6e-d487-42e8-a619-aa4db6f9556f@h5g2000yqh.googlegroups.com> Message-ID: <89d40e93-07b1-4761-9154-7c870981999c@v15g2000yqn.googlegroups.com> On Feb 16, 3:50?pm, Gustavo Narea wrote: > On Feb 14, 3:27 pm, Michele Simionato > wrote: > > > I lack the context to see how this could be fixed in your case, but > > this a not a show stopper, you can just keep the original decorator > > and forget about making itsignature preserving. > > I'm sorry for the possibly dumb question, but how can I do that? > > Thanks for all the time you've spent on this, Michele. > > ? - Gustavo. Let the original code as it is. If ain't broken, don't fix it. From me at gustavonarea.net Mon Feb 16 10:07:15 2009 From: me at gustavonarea.net (Gustavo Narea) Date: Mon, 16 Feb 2009 07:07:15 -0800 (PST) Subject: Turning a signature-changing decorator into a signature-preserving one References: <6b0518e3-142c-4555-8ad0-02c559f6b224@u13g2000yqg.googlegroups.com> <6b0874ad-4c30-4b3f-a559-f83465d332da@z1g2000yqn.googlegroups.com> <2610ff6e-d487-42e8-a619-aa4db6f9556f@h5g2000yqh.googlegroups.com> <89d40e93-07b1-4761-9154-7c870981999c@v15g2000yqn.googlegroups.com> Message-ID: <89bce53a-f5e9-4add-83f8-54522c900db6@n10g2000vbl.googlegroups.com> On Feb 16, 3:56 pm, Michele Simionato wrote: > On Feb 16, 3:50 pm, Gustavo Narea wrote: > > > On Feb 14, 3:27 pm, Michele Simionato > > wrote: > > > > I lack the context to see how this could be fixed in your case, but > > > this a not a show stopper, you can just keep the original decorator > > > and forget about making itsignature preserving. > > > I'm sorry for the possibly dumb question, but how can I do that? > > > Thanks for all the time you've spent on this, Michele. > > > - Gustavo. > > Let the original code as it is. If ain't broken, don't fix it. But the problem is that it is broken. That decorator is for controller actions in Pylons-powered web applications (which are instance methods). Pylons inspects the action's signature to find what parameters it's going to pass to its instance method, which fails because my current decorator changes the signature. From mail at microcorp.co.za Mon Feb 16 10:09:55 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Mon, 16 Feb 2009 17:09:55 +0200 Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <977bad202990de5797c2efcf8d50ed81.squirrel@localhost> Message-ID: <00c501c99049$361f40c0$0d00a8c0@hendrik> "andrew cooke" wrote: >The GIL is an implementation detail. I suspect that it could be largely >removed if there was sufficient need. But that still wouldn't make Python >a good language for programming on multiple cores. That's not as big a >deal as you think, because we currently DON'T KNOW what would make a good >language for programming on multiple cores - it's an open topic in the >wider community. Those who do not study history are doomed to repeat it. Occam was the language that should have won the marketing prize, but didn't. - Hendrik From michele.simionato at gmail.com Mon Feb 16 10:18:56 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Mon, 16 Feb 2009 07:18:56 -0800 (PST) Subject: Turning a signature-changing decorator into a signature-preserving one References: <6b0518e3-142c-4555-8ad0-02c559f6b224@u13g2000yqg.googlegroups.com> <6b0874ad-4c30-4b3f-a559-f83465d332da@z1g2000yqn.googlegroups.com> <2610ff6e-d487-42e8-a619-aa4db6f9556f@h5g2000yqh.googlegroups.com> <89d40e93-07b1-4761-9154-7c870981999c@v15g2000yqn.googlegroups.com> <89bce53a-f5e9-4add-83f8-54522c900db6@n10g2000vbl.googlegroups.com> Message-ID: <7845ce9e-5528-46fc-ab7d-1efc4df9009b@41g2000yqf.googlegroups.com> On Feb 16, 4:07?pm, Gustavo Narea wrote: > But the problem is that it is broken. > > That decorator is for controller actions in Pylons-powered web > applications (which are instance methods). Pylons inspects the > action's signature to find what parameters it's going to pass to its > instance method, which fails because my current decorator changes the > signature. Yes, I am saying don't mess with the internal mechanism of Pylons and leave it as it was. Or was it broken from the beginning? The only reason I see for you to touch those things is if you are a Pylons core developer. From germangutierrezg at yahoo.es Mon Feb 16 10:28:52 2009 From: germangutierrezg at yahoo.es (=?iso-8859-1?Q?Germ=E1n_Guti=E9rrez?=) Date: Mon, 16 Feb 2009 07:28:52 -0800 (PST) Subject: RedHat 4 Message-ID: <707520.41882.qm@web24601.mail.ird.yahoo.com> Hi, I need to confirm and certificate python 2.5 works in a RedHat Enterprise 4 and I don't know where I find that information. Please, if anybody knows some URL in RedHat or Python with this information email me. Thanks Germ?n Guti?rrez Gayoso Temuco -------------- next part -------------- An HTML attachment was scrubbed... URL: From me at gustavonarea.net Mon Feb 16 10:29:32 2009 From: me at gustavonarea.net (Gustavo Narea) Date: Mon, 16 Feb 2009 07:29:32 -0800 (PST) Subject: Turning a signature-changing decorator into a signature-preserving one References: <6b0518e3-142c-4555-8ad0-02c559f6b224@u13g2000yqg.googlegroups.com> <6b0874ad-4c30-4b3f-a559-f83465d332da@z1g2000yqn.googlegroups.com> <2610ff6e-d487-42e8-a619-aa4db6f9556f@h5g2000yqh.googlegroups.com> <89d40e93-07b1-4761-9154-7c870981999c@v15g2000yqn.googlegroups.com> <89bce53a-f5e9-4add-83f8-54522c900db6@n10g2000vbl.googlegroups.com> <7845ce9e-5528-46fc-ab7d-1efc4df9009b@41g2000yqf.googlegroups.com> Message-ID: <6a2018f2-cc90-443b-8021-c252095f4a2d@v42g2000yqj.googlegroups.com> On Feb 16, 4:18 pm, Michele Simionato wrote: > Yes, I am saying don't mess with the internal mechanism of Pylons and > leave it as > it was. Or was it broken from the beginning? The only reason I see for > you > to touch those things is if you are a Pylons core developer. It was broken from the beginning on Pylons. I'm a TurboGears 2 core developer, and TurboGears is powered by Pylons as of version 2. The decorator has always worked in TurboGears because of the way TG finds the action arguments, but now I'm working to make it work in Pylons too, but this is the only problem that has stopped me from making it work under Pylons. Thanks. From lie.1296 at gmail.com Mon Feb 16 10:38:58 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 16 Feb 2009 15:38:58 +0000 (UTC) Subject: Python interface to ODF documents? References: <880dece00902151203v2ba64befjb2d4b29a688143a5@mail.gmail.com> Message-ID: On Sun, 15 Feb 2009 22:03:25 +0200, Dotan Cohen wrote: > Is there a Python interface to ODF documents? I'm thinking of something > that will import, for example, an ADS spreadsheet into a > multidimensional array (including formulas and formatting) and let me > manipulate it, then save it back. > Since python is one of OpenOffice.org's Macro language, depending on your need, you might be able to use that as well. From michele.simionato at gmail.com Mon Feb 16 10:40:08 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Mon, 16 Feb 2009 07:40:08 -0800 (PST) Subject: Turning a signature-changing decorator into a signature-preserving one References: <6b0518e3-142c-4555-8ad0-02c559f6b224@u13g2000yqg.googlegroups.com> <6b0874ad-4c30-4b3f-a559-f83465d332da@z1g2000yqn.googlegroups.com> <2610ff6e-d487-42e8-a619-aa4db6f9556f@h5g2000yqh.googlegroups.com> <89d40e93-07b1-4761-9154-7c870981999c@v15g2000yqn.googlegroups.com> <89bce53a-f5e9-4add-83f8-54522c900db6@n10g2000vbl.googlegroups.com> <7845ce9e-5528-46fc-ab7d-1efc4df9009b@41g2000yqf.googlegroups.com> <6a2018f2-cc90-443b-8021-c252095f4a2d@v42g2000yqj.googlegroups.com> Message-ID: <2004688b-f3f1-4509-ac81-f3ae496547c1@t13g2000yqc.googlegroups.com> On Feb 16, 4:29?pm, Gustavo Narea wrote: > On Feb 16, 4:18 pm, Michele Simionato > wrote: > > > Yes, I am saying don't mess with the internal mechanism of Pylons and > > leave it as > > it was. Or was it broken from the beginning? The only reason I see for > > you > > to touch those things is if you are a Pylons core developer. > > It was broken from the beginning on Pylons. > > I'm a TurboGears 2 core developer, and TurboGears is powered by Pylons > as of version 2. The decorator has always worked in TurboGears because > of the way TG finds the action arguments, but now I'm working to make > it work in Pylons too, but this is the only problem that has stopped > me from making it work under Pylons. > > Thanks. I see. I would ask on the Pylons list. I suspect a bound method is passed and that you will need to extract the corresponding function with .im_func, then making sure that you pass the self argument correctly. But this is wild guess since I have no idea of how Pylons decorators work internally as compared to TurboGears decorators. From jcd at sdf.lonestar.org Mon Feb 16 10:51:49 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Mon, 16 Feb 2009 10:51:49 -0500 Subject: RedHat 4 In-Reply-To: <707520.41882.qm@web24601.mail.ird.yahoo.com> References: <707520.41882.qm@web24601.mail.ird.yahoo.com> Message-ID: <1234799509.23811.3.camel@aalcdl07.lib.unc.edu> It *works* in RHEL 4, but it doesn't come as a package. RHEL4 ships with Python 2.3, and RHEL 5 only ships with Python 2.4, even though 2.5 had been out for god knows how long when it came out. Though I haven't tested it, I wouldn't recommend replacing the system's python binary with 2.5 if you do install it yourself. Instead, install it to python2.5, and set the shebang line (#!) on your scripts to point to /usr/local/bin/python2.5 (or wherever you install it). Cheers, Cliff On Mon, 2009-02-16 at 07:28 -0800, Germ?n Guti?rrez wrote: > Hi, > > I need to confirm and certificate python 2.5 works in a RedHat > Enterprise 4 and I don't know where I find that information. Please, > if anybody knows some URL in RedHat or Python with this information > email me. > > Thanks > > Germ?n Guti?rrez Gayoso > Temuco > > > > -- > http://mail.python.org/mailman/listinfo/python-list From cd at okunah.de Mon Feb 16 10:54:10 2009 From: cd at okunah.de (Christof Donat) Date: Mon, 16 Feb 2009 16:54:10 +0100 Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> Message-ID: Hi, > But there is > something interesting, something like multi processing. But is it a > real alternative for multi threading. As i searched it is not, it > requires heavy hardware requirements (lots of memory, lots of cpu > power). Not necessarily. For the memory, modern operating Systems can ustilize a copy on write semantics in their Applications virtual memory space. That means that after starting a new process with fork(), the new Process shares all physical Memory Pages with the original one as long a none of them writes to wome Memory. The first write is cought by the OS. Then the Page will be copied and the writing process will in future use the new copy of that page while the other one (or eventually many) stay with the original. Multiprocessing needs more Memory than well optimized Multithreading, but it is not as bad as it is often said. For the CPU: There are two things that make the difference here. One ist Context Switching. When the OS switches between two threads of the same Process, it does not need to change the memory lookup table. When switching between Processes that is always necessary. Switching from a Thread of Process A to a Thread of Process B is just like switching from A to B. Using Threads just increases the probability that the OS can do a faster Context Switch. So Threads are faster here, but it is not a too big issue as well. The Second Thing is Communication. With Threds you can simply use variables to communicate between Threads. To Prevent conflicting access to those Variables you will use e.g. mutexes. That can be done with Shared Memory as well. Shared Memory is a bit more difficult to handle than simply using the heap, but again the impact is not really so big. Google uses Processes for the Tabs in Chrome, because that way they get around many Memory Management Problems they would have with Threads or with a singlethreaded reactor. Using Processes is not per se a bad Idea. You pay a bit with Memory and CPU but in many situations you get a much simpler programming model. Christof From me at gustavonarea.net Mon Feb 16 10:59:41 2009 From: me at gustavonarea.net (Gustavo Narea) Date: Mon, 16 Feb 2009 07:59:41 -0800 (PST) Subject: Turning a signature-changing decorator into a signature-preserving one References: <6b0518e3-142c-4555-8ad0-02c559f6b224@u13g2000yqg.googlegroups.com> <6b0874ad-4c30-4b3f-a559-f83465d332da@z1g2000yqn.googlegroups.com> <2610ff6e-d487-42e8-a619-aa4db6f9556f@h5g2000yqh.googlegroups.com> <89d40e93-07b1-4761-9154-7c870981999c@v15g2000yqn.googlegroups.com> <89bce53a-f5e9-4add-83f8-54522c900db6@n10g2000vbl.googlegroups.com> <7845ce9e-5528-46fc-ab7d-1efc4df9009b@41g2000yqf.googlegroups.com> <6a2018f2-cc90-443b-8021-c252095f4a2d@v42g2000yqj.googlegroups.com> <2004688b-f3f1-4509-ac81-f3ae496547c1@t13g2000yqc.googlegroups.com> Message-ID: <17034c1d-38d8-42c6-b331-826053cb1fd1@s36g2000vbp.googlegroups.com> On Feb 16, 4:40 pm, Michele Simionato wrote: > > It was broken from the beginning on Pylons. > > > I'm a TurboGears 2 core developer, and TurboGears is powered by Pylons > > as of version 2. The decorator has always worked in TurboGears because > > of the way TG finds the action arguments, but now I'm working to make > > it work in Pylons too, but this is the only problem that has stopped > > me from making it work under Pylons. > > > Thanks. > > I see. I would ask on the Pylons list. I suspect a bound method is > passed and that you will > need to extract the corresponding function with .im_func, then making > sure that you pass > the self argument correctly. But this is wild guess since I have no > idea of how Pylons decorators > work internally as compared to TurboGears decorators. I've not seen anything special in Pylons or TurboGears 2 decorators, except that they are all functions that use the decorator package -- while my decorator is a class that doesn't use the decorator package yet. My attempt to turn that decorator into a signature preserving one using the decorator packages fails even on TurboGears 2. As of decorator 3.0.1, I get this error: TypeError: You are decorating a non function: Isn't this caused by the fact that my decorator is a class, or the way such a class is defined (whose code is in the first post of the thread)? I can turn it into a function because I'm sure I'll work -- although I wanted a class to make it easier to customize. Thanks. From me at gustavonarea.net Mon Feb 16 11:13:52 2009 From: me at gustavonarea.net (Gustavo Narea) Date: Mon, 16 Feb 2009 08:13:52 -0800 (PST) Subject: Turning a signature-changing decorator into a signature-preserving one References: <6b0518e3-142c-4555-8ad0-02c559f6b224@u13g2000yqg.googlegroups.com> <6b0874ad-4c30-4b3f-a559-f83465d332da@z1g2000yqn.googlegroups.com> <2610ff6e-d487-42e8-a619-aa4db6f9556f@h5g2000yqh.googlegroups.com> <89d40e93-07b1-4761-9154-7c870981999c@v15g2000yqn.googlegroups.com> <89bce53a-f5e9-4add-83f8-54522c900db6@n10g2000vbl.googlegroups.com> <7845ce9e-5528-46fc-ab7d-1efc4df9009b@41g2000yqf.googlegroups.com> <6a2018f2-cc90-443b-8021-c252095f4a2d@v42g2000yqj.googlegroups.com> <2004688b-f3f1-4509-ac81-f3ae496547c1@t13g2000yqc.googlegroups.com> <17034c1d-38d8-42c6-b331-826053cb1fd1@s36g2000vbp.googlegroups.com> Message-ID: On Feb 16, 4:59 pm, Gustavo Narea wrote: > On Feb 16, 4:40 pm, Michele Simionato > wrote: > > > > > > It was broken from the beginning on Pylons. > > > > I'm a TurboGears 2 core developer, and TurboGears is powered by Pylons > > > as of version 2. The decorator has always worked in TurboGears because > > > of the way TG finds the action arguments, but now I'm working to make > > > it work in Pylons too, but this is the only problem that has stopped > > > me from making it work under Pylons. > > > > Thanks. > > > I see. I would ask on the Pylons list. I suspect a bound method is > > passed and that you will > > need to extract the corresponding function with .im_func, then making > > sure that you pass > > the self argument correctly. But this is wild guess since I have no > > idea of how Pylons decorators > > work internally as compared to TurboGears decorators. > > I've not seen anything special in Pylons or TurboGears 2 decorators, > except that they are all functions that use the decorator package -- > while my decorator is a class that doesn't use the decorator package > yet. > > My attempt to turn that decorator into a signature preserving one > using the decorator packages fails even on TurboGears 2. As of > decorator 3.0.1, I get this error: > TypeError: You are decorating a non function: SecurePanel.__before__> > > Isn't this caused by the fact that my decorator is a class, or the way > such a class is defined (whose code is in the first post of the > thread)? I can turn it into a function because I'm sure I'll work -- > although I wanted a class to make it easier to customize. > > Thanks. This is another attempt, where the decorator is a still a class but uses an auxiliary function: http://paste.chrisarndt.de/paste/38bf8a8443614464968d424e1f2d4182 However, that raises this exception: http://paste.chrisarndt.de/paste/f90bc9a058254e2ca5660882011752a7?wrap=no From michele.simionato at gmail.com Mon Feb 16 11:18:00 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Mon, 16 Feb 2009 08:18:00 -0800 (PST) Subject: Turning a signature-changing decorator into a signature-preserving one References: <6b0518e3-142c-4555-8ad0-02c559f6b224@u13g2000yqg.googlegroups.com> <6b0874ad-4c30-4b3f-a559-f83465d332da@z1g2000yqn.googlegroups.com> <2610ff6e-d487-42e8-a619-aa4db6f9556f@h5g2000yqh.googlegroups.com> <89d40e93-07b1-4761-9154-7c870981999c@v15g2000yqn.googlegroups.com> <89bce53a-f5e9-4add-83f8-54522c900db6@n10g2000vbl.googlegroups.com> <7845ce9e-5528-46fc-ab7d-1efc4df9009b@41g2000yqf.googlegroups.com> <6a2018f2-cc90-443b-8021-c252095f4a2d@v42g2000yqj.googlegroups.com> <2004688b-f3f1-4509-ac81-f3ae496547c1@t13g2000yqc.googlegroups.com> <17034c1d-38d8-42c6-b331-826053cb1fd1@s36g2000vbp.googlegroups.com> Message-ID: <13ae3295-912e-48a3-bd94-41186ff75b88@e18g2000vbe.googlegroups.com> On Feb 16, 4:59?pm, Gustavo Narea wrote: > I've not seen anything special in Pylons or TurboGears 2 decorators, > except that they are all functions that use the decorator package -- > while my decorator is a class that doesn't use the decorator package > yet. > > My attempt to turn that decorator into a signature preserving one > using the decorator packages fails even on TurboGears 2. As of > decorator 3.0.1, I get this error: > ? ? TypeError: You are decorating a non function: SecurePanel.__before__> > > Isn't this caused by the fact that my decorator is a class, or the way > such a class is defined (whose code is in the first post of the > thread)? I can turn it into a function because I'm sure I'll work -- > although I wanted a class to make it easier to customize. > > Thanks. The decorator class is fine, the error in clearly in what you pass to the decorator. You are trying to decorate an unbound method SecurePanel.__before__: are you sure this is really what you want to decorate? Are you decorating automatically all methods of SecurePanel? I have already mentioned it, but you can extract the underlying function from the method by using SecurePanel.__before__.im_func if you really want. From dotancohen at gmail.com Mon Feb 16 11:18:42 2009 From: dotancohen at gmail.com (Dotan Cohen) Date: Mon, 16 Feb 2009 18:18:42 +0200 Subject: Python interface to ODF documents? In-Reply-To: References: <880dece00902151203v2ba64befjb2d4b29a688143a5@mail.gmail.com> Message-ID: <880dece00902160818h77fc3509tf64e0c7788f72119@mail.gmail.com> > Since python is one of OpenOffice.org's Macro language, depending on your > need, you might be able to use that as well. > That's not a bad idea. Thanks! -- Dotan Cohen http://what-is-what.com http://gibberish.co.il ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-??-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-? From seb.binet at gmail.com Mon Feb 16 11:25:41 2009 From: seb.binet at gmail.com (seb.binet at gmail.com) Date: Mon, 16 Feb 2009 08:25:41 -0800 (PST) Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> Message-ID: hi there, [snip] > Google uses Processes for the Tabs in Chrome, because that way they get > around many Memory Management Problems they would have with Threads or with > a singlethreaded reactor. Using Processes is not per se a bad Idea. You pay > a bit with Memory and CPU but in many situations you get a much simpler > programming model. note also that one can bet on things like KSM [1] to further improve the memory situation. For example, we are investigating its use in the large (read heavy) application frameworks at CERN where the typical vmem footprint is ~2Gb. Running KSM together with a multiprocessing-based event loop manager, we managed to overcommit ~300% of the memory (ie: run 3 instances of our application on a 2Gb-per-core machine) cheers, sebastien [1] http://lwn.net/Articles/306642 From jjposner at snet.net Mon Feb 16 11:40:18 2009 From: jjposner at snet.net (John Posner) Date: Mon, 16 Feb 2009 11:40:18 -0500 Subject: Changing the Image on a button In-Reply-To: <59253b2f-c90d-4308-835d-e81a2e602127@p23g2000prp.googlegroups.com> References: <59253b2f-c90d-4308-835d-e81a2e602127@p23g2000prp.googlegroups.com> Message-ID: <40B38CF8ABFA49D297308E65A3426BD0@AMDUP> >> from Tkinter import * >> >> def do(): >> btn.configure(image = None) >> >> root = Tk() >> img1 = PhotoImage(file="bacon.gif") >> >> btn = Button(image = img1, command = do, text = "hello" ) >> btn.img = img1 >> btn.pack() >> root.mainloop() >> Try this change: from: btn.configure(image = None) to: img1.blank() -John E-mail message checked by Spyware Doctor (6.0.0.386) Database version: 5.11770 http://www.pctools.com/en/spyware-doctor-antivirus/ From rjohnson42 at gmail.com Mon Feb 16 11:50:20 2009 From: rjohnson42 at gmail.com (Dick) Date: Mon, 16 Feb 2009 08:50:20 -0800 (PST) Subject: Windows vista References: Message-ID: <87e1d911-9d6a-4c0d-8f8a-0b66d3356408@l38g2000vba.googlegroups.com> On Feb 16, 1:46?am, loveshadow... at yahoo.com wrote: > Hi. My name is toru. > I start learning python couple weeks ago. > > I install the compiler from python.org. > but I cannot use the IDLE program. > (command line works fine so far) > the error screen says that the my personal fire wall is blocking the > program to run. > I am not sure how to fix this. > By the way, I heard many people said that this is because I am using > windows vista. > Does anyone know how to use IDLE program on Windows Vista machine? > > thank you. On my Vista machine I reply to a firewall popup the first time I run IDLE and tell it to allow IDLE to open a port. The next time I run IDLE, all is OK. I still have the problem that sometimes IDLE does not properly cleanup hung processes, which means IDLE will not restart. Dick Johnson From benjamin at python.org Mon Feb 16 11:54:43 2009 From: benjamin at python.org (Benjamin Peterson) Date: Mon, 16 Feb 2009 10:54:43 -0600 Subject: [Python-Dev] RELEASED Python 3.0.1 In-Reply-To: References: Message-ID: <1afaf6160902160854u6cf8c81ck219cbc7fddafdd3f@mail.gmail.com> On Sun, Feb 15, 2009 at 9:15 PM, Ned Deily wrote: > > It would be great if someone could add OS X links for the 3.0.1 and > 2.6.1 to the main download page, too: > I've now added them to the main download page. -- Regards, Benjamin From bieffe62 at gmail.com Mon Feb 16 11:56:08 2009 From: bieffe62 at gmail.com (bieffe62 at gmail.com) Date: Mon, 16 Feb 2009 08:56:08 -0800 (PST) Subject: Threads in PyGTK: keep typing while ping-ing References: Message-ID: <9289e298-a123-47e9-855a-3df71d92e078@l1g2000yqj.googlegroups.com> On 16 Feb, 14:47, Mamahita Sela wrote: > Dear All, > > I have read several howtos for threading in PyGTK. I have tried some but with no luck. > > What i want is: i can keep typing in gtk.TextView while periodically doing ping some hosts. > > I think, the thread part is working since i can ping so fast (even for not reply host, around 3 s for 27 no-reply-host). But, when the ping action is running, i can not typing in textview. What i type while pinging will show up after ping action is done. > > (I am using 2.5.1, pygtk 2.10.6 on Linux x86) > > This is my code: > import threading > import commands > import gtk > import gobject > > gtk.gdk.threads_init() > > class PingHost(threading.Thread): > ? ? def __init__(self, host): > ? ? ? ? threading.Thread.__init__(self) > ? ? ? ? self.host = host > ? ? ? ? self.result = () > ? ? def run(self): > ? ? ? ? self.result = self.host, commands.getstatusoutput('ping %s -c1' %(self.host))[0] > > class Main: > ? ? def __init__(self): > ? ? ? ? self.win = gtk.Window() > ? ? ? ? self.win.connect('destroy', gtk.main_quit) > ? ? ? ? # > ? ? ? ? self.textb = gtk.TextBuffer() > ? ? ? ? self.textv = gtk.TextView(self.textb) > ? ? ? ? self.textv.set_size_request(500, 500) > ? ? ? ? # > ? ? ? ? self.win.add(self.textv) > ? ? ? ? self.win.show_all() > ? ? ? ? # > ? ? ? ? gobject.timeout_add(5000, self.do_ping) > > ? ? ? ? def do_ping(self): > ? ? ? ? all_threads = [] > ? ? ? ? # > ? ? ? ? for h in range(100, 105): > ? ? ? ? ? ? host = '192.168.0.%d' %(h) > ? ? ? ? ? ? # > ? ? ? ? ? ? worker = PingHost(host) > ? ? ? ? ? ? worker.start() > ? ? ? ? ? ? all_threads.append(worker) > ? ? ? ? # > ? ? ? ? for t in all_threads: > ? ? ? ? ? ? t.join() > ? ? ? ? ? ? print t.result > ? ? ? ? # > ? ? ? ? return True > > if __name__ == '__main__': > ? ? app = Main() > ? ? gtk.main() > > Any help would be appreciated :) > Best regards, > M As you have been already told, join() blocks until the thread is terminated. and you should avoid that. A simple fix could by add a timeout to t.join, doing something like : t.join(JOIN_TIMEOUT); if not t.isAlive(): print t.result Anywway, starting a thread for each ping is not very efficient, so you could do better by having a 'ping server thread' that repeatedly performs the following steps: - accepts ping command on a queue.Queue - ping the target and waits for the result - publish the result on another queue.Queue At this point, the do_ping action should: - send a ping command to the oping server - check (in non blocking mode) if there is any result on the ping results queue - display the result, if any Another big speedup would be to avoid spawning a subprocess fro each ping and instead using directly sockets to send ICMP packets, using recipes like this : http://code.activestate.com/recipes/409689/ Ciao ------ FB From me at gustavonarea.net Mon Feb 16 11:58:25 2009 From: me at gustavonarea.net (Gustavo Narea) Date: Mon, 16 Feb 2009 08:58:25 -0800 (PST) Subject: Turning a signature-changing decorator into a signature-preserving one References: <6b0518e3-142c-4555-8ad0-02c559f6b224@u13g2000yqg.googlegroups.com> <6b0874ad-4c30-4b3f-a559-f83465d332da@z1g2000yqn.googlegroups.com> <2610ff6e-d487-42e8-a619-aa4db6f9556f@h5g2000yqh.googlegroups.com> <89d40e93-07b1-4761-9154-7c870981999c@v15g2000yqn.googlegroups.com> <89bce53a-f5e9-4add-83f8-54522c900db6@n10g2000vbl.googlegroups.com> <7845ce9e-5528-46fc-ab7d-1efc4df9009b@41g2000yqf.googlegroups.com> <6a2018f2-cc90-443b-8021-c252095f4a2d@v42g2000yqj.googlegroups.com> <2004688b-f3f1-4509-ac81-f3ae496547c1@t13g2000yqc.googlegroups.com> <17034c1d-38d8-42c6-b331-826053cb1fd1@s36g2000vbp.googlegroups.com> <13ae3295-912e-48a3-bd94-41186ff75b88@e18g2000vbe.googlegroups.com> Message-ID: On Feb 16, 5:18 pm, Michele Simionato wrote: > On Feb 16, 4:59 pm, Gustavo Narea wrote: > > > > > I've not seen anything special in Pylons or TurboGears 2 decorators, > > except that they are all functions that use the decorator package -- > > while my decorator is a class that doesn't use the decorator package > > yet. > > > My attempt to turn that decorator into a signature preserving one > > using the decorator packages fails even on TurboGears 2. As of > > decorator 3.0.1, I get this error: > > TypeError: You are decorating a non function: > SecurePanel.__before__> > > > Isn't this caused by the fact that my decorator is a class, or the way > > such a class is defined (whose code is in the first post of the > > thread)? I can turn it into a function because I'm sure I'll work -- > > although I wanted a class to make it easier to customize. > > > Thanks. > > The decorator class is fine, the error in clearly in what you pass to > the decorator. > You are trying to decorate an unbound method SecurePanel.__before__: > are you > sure this is really what you want to decorate? Are you decorating > automatically all methods > of SecurePanel? I have already mentioned it, but you can extract the > underlying function > from the method by using SecurePanel.__before__.im_func if you really > want. Thank you very much, it works with SecurePanel.__before__.im_func! From deets at nospam.web.de Mon Feb 16 12:07:12 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 16 Feb 2009 18:07:12 +0100 Subject: logging and daemons In-Reply-To: References: Message-ID: <6vtkq4FidfdeU1@mid.uni-berlin.de> Fernando M. Maresca schrieb: > Hello. > > I'm in the process of replacing a custom logger class in one of my apps > that has several daemons. In the last step of daemonizing a program, > after closing fds, stderr and stdout are redirected to the logfile of > the program. > > Now, I'm trying to use TimedRotatingFileHandler as the only channel when > the programs run in daemon mode. My problem is: I can't see a goog way > to redirect stderr/stdout both to the logger. > > Note that I don't have any print statements in any of my code, but I > can't be sure about all the modules I'm importing, and I like to get any > uncached exception info that may go to stderr/stdout to show up in the > logfiles. why don't you just replace the sys.stdout/sys.stdin objects with something that is file-like (supports a write-method, that should be enough in this case), and then simply write the data arriving to the logger instance of your trust. If other modules don't get overly tricky to bypass sys.stdout, that should capture all you output, regardless of the file descriptor issues. In the end, if a 3rd-party-module choses to open a filedescriptor itself & write to that, there is nothing you can do about that. But usually, they don't behave that way. Diez From vinay_sajip at yahoo.co.uk Mon Feb 16 12:14:08 2009 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Mon, 16 Feb 2009 09:14:08 -0800 (PST) Subject: logging and daemons References: <20090216130206.GA20397@gmail.com> <364299f40902160507g4eca4be2yda535199451ce5a8@mail.gmail.com> Message-ID: <4aeaece7-a3ce-44e8-aa6f-c5d0165c109d@f20g2000yqg.googlegroups.com> On Feb 16, 1:15 pm, "Fernando M. Maresca" wrote: > Yes, but I'm trying to use *TimedRotating*FileHandler, which makes the > fd of the logfile change in every rotation of the logfile. So the direct > approach of std[out|err] redirection to the logfile fd obtained from > the logger instance is unusable (it works fine with a simple file > handler). That's fine with a FileHandler, as long as you don't use e.g. logrotate - that would cause the fd to change, too. > I'm looking into this because I really need rotating, because when > debugging is on, large amounts of data are logged, and because I like > the logging module approach in every aspect. > You can capture the stuff written to std[out|err] using any file-like object, so there are other options beyond redirecting to the fd of the handler's fd or adding a write method to the logger. For example, if you create a simple class which duck-types the file-like object, you could create two instances, for stdout and stderr, and wire them into sys. At any point you choose, you can choose to forward the information collected to the log. Is all your stuff pure Python, or do you have C extensions or subprocesses which are C-based? Also, I assume you have a separate rotating log file per daemon - is that right? Regards, Vinay Sajip From Scott.Daniels at Acm.Org Mon Feb 16 12:44:35 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 16 Feb 2009 09:44:35 -0800 Subject: Will multithreading make python less popular? In-Reply-To: References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> Message-ID: andrew cooke wrote: Thanks a lot for writing this, I'll be pointing to it from time to time. Were I writing such a thing I'd focus too much on the how (issues I know that non-GIL true concurrency faces), and not enough on the high level view. Bravo. --Scott David Daniels Scott.Daniels at Acm.Org From basilisk96 at gmail.com Mon Feb 16 12:45:54 2009 From: basilisk96 at gmail.com (Basilisk96) Date: Mon, 16 Feb 2009 09:45:54 -0800 (PST) Subject: how can this iterator be optimized? References: <727aabd1-9682-47aa-88e2-5dde96e4c32e@j1g2000yqi.googlegroups.com> <2b4e62a9-efa8-4656-98e4-4755a10e7cac@v5g2000pre.googlegroups.com> Message-ID: <1bd69222-6b94-42f6-ab52-844043b25ffa@q25g2000vbn.googlegroups.com> On Feb 14, 10:19?am, Paul McGuire wrote: > If func is expensive, you could try memoizing it. ?Then subsequent > "calls" just do arg lookups. ?Michele Simianato has posted a good > memoizing decorator on the Python wiki. > > -- Paul That's the trick! I almost forgot about that one. Thanks! -Basilisk96 From ts8807385 at gmail.com Mon Feb 16 12:55:41 2009 From: ts8807385 at gmail.com (ts8807385 at gmail.com) Date: Mon, 16 Feb 2009 09:55:41 -0800 (PST) Subject: chi squared (X2) in Python Message-ID: <7f4eff87-20e2-47b4-b5e2-1c62aebd8bbc@w34g2000yqm.googlegroups.com> I was wondering if anyone has done this in Python. I wrote two functions that do it (I think... see below), but I do not understand how to interpret the results. I'm doing an experiment to implement ent in Python. ent tests the randomness of files and chi squared is probably the best test for this purposes when compared to other tests. Many of the statistical tests are easy (like Arithmetic Mean, etc) and I have no problems interpreting the results from those, but chi squared has stumped me. Here are my two simple functions, run them if you like to better understand the output: import os import os.path def observed(f): # argument f is a filepath/filename # # Return a list of observed characters in decimal ord(char). # Decimal value of characters may be 0 through 255. # [43, 54, 0, 255, 4, etc.] chars = [] #print f fd = open(f, 'rb') bytes = fd.read(13312) fd.close() for byte in bytes: chars.append(ord(byte)) #print chars if len(chars) != 13312: print "Wait... chars does not equal 13312 in observed!!!" return None else: return chars def chi(char_list): # Expected frequency of characters. I arrived at this like so: # expected = number of observations/number of possibilities # 52 = 13312/256 expected = 52.0 print "observed\texpected\tx2" # 0 - 255 for x in range(0,256): observed = 0 for char in char_list: if x == char: observed +=1 # The three chi squared calculations # one = observed - expected # two = one squared # x2 = two/expected # x2 = (observed - expected) squared # ---------------------------- # expected one = observed - expected two = one * one x2 = two/expected print observed, "\t", expected, "\t", x2 chi(observed("filepath")) The output looks similar to this: observed expected x2 62 52.0 1.92307692308 46 52.0 0.692307692308 60 52.0 1.23076923077 68 52.0 4.92307692308 I know this is a bit off-topic here, just hoping someone could help me interpret the x2 variable. After that, I'll be OK. I need to sum up things to get an overall x2 for the bytes I've read, but before doing that, I wanted to post this note. Please feel free to comment on any aspect of this. If I've got something entirely wrong, let me know. BTW, I selected 13KB (13,312) as it seems to be efficient and a decent size to test, the data could be any amount (up to and including the whole file) above this. Thanks, Tiff From mal at egenix.com Mon Feb 16 13:05:37 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Mon, 16 Feb 2009 19:05:37 +0100 Subject: how to distribute python extensions independently of python In-Reply-To: <20090212173812.GH6522@subspacefield.org> References: <20090212173812.GH6522@subspacefield.org> Message-ID: <4999AAF1.5000206@egenix.com> On 2009-02-12 18:38, Travis wrote: > So, > > Recently I made a fix to the zlib module that I need for use at work. > > I would like other employees to be able to use it without recompiling python. > > I assume I can just rename it and distribute it as a python extension. > > I was wondering how I can provide a way for other employees to build it. > > I saw a "Universal Unix Makefile for Python extensions" that looks promising. > > Is this the accepted way to compile python extensions still? Not really. That approach was abandoned years ago in favor of a distutils approach: http://docs.python.org/distutils/index.html in particular: http://docs.python.org/distutils/setupscript.html#describing-extension-modules -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Feb 16 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From Nicolas.Dandrimont at crans.org Mon Feb 16 13:09:28 2009 From: Nicolas.Dandrimont at crans.org (Nicolas Dandrimont) Date: Mon, 16 Feb 2009 13:09:28 -0500 Subject: Pythonic way to determine if one char of many in a string In-Reply-To: <1234763314.25586.1300573535@webmail.messagingengine.com> References: <1234761457.20683.1300568627@webmail.messagingengine.com> <20090216052846.GA12723@dirichlet.crans.org> <1234763314.25586.1300573535@webmail.messagingengine.com> Message-ID: <20090216180928.GA14441@dirichlet.crans.org> * python at bdurham.com [2009-02-16 00:48:34 -0500]: > Nicolas, > > > I would go for something like: > > > > for char in word: > > if char in 'aeiouAEIUO': > > char_found = True > > break > > else: > > char_found = False > > > > It is clear (imo), and it is seems to be the intended idiom for a > > search loop, that short-circuits as soon as a match is found. > > Thank you - that looks much better that my overly complicated attempts. > > Are there any reasons why I couldn't simplify your approach as follows? > > for char in word: > if char in 'aeiouAEIUO': > return True > return False If you want to put this in its own function, this seems to be the way to go. Cheers, -- Nicolas Dandrimont The nice thing about Windows is - It does not just crash, it displays a dialog box and lets you press 'OK' first. (Arno Schaefer's .sig) -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 204 bytes Desc: Digital signature URL: From robert.kern at gmail.com Mon Feb 16 13:09:34 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 16 Feb 2009 12:09:34 -0600 Subject: how to distribute python extensions independently of python In-Reply-To: <20090212173812.GH6522@subspacefield.org> References: <20090212173812.GH6522@subspacefield.org> Message-ID: On 2009-02-12 11:38, Travis wrote: > So, > > Recently I made a fix to the zlib module that I need for use at work. Would you mind contributing this fix back to Python? http://bugs.python.org/ If you don't want to go to the effort of making a patch, at least a description of the problem you encountered and a description of your fix would be helpful. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From Scott.Daniels at Acm.Org Mon Feb 16 13:11:51 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 16 Feb 2009 10:11:51 -0800 Subject: logging and daemons In-Reply-To: References: <20090216130206.GA20397@gmail.com> <364299f40902160507g4eca4be2yda535199451ce5a8@mail.gmail.com> Message-ID: <34idnSxjvpdDNgTUnZ2dnUVZ_haWnZ2d@pdx.net> Fernando M. Maresca wrote: On Mon, Feb 16, 2009 at 05:07:45AM -0800, Garrett Cooper wrote: >> You can actually set sys.std[err|out] to your ?file? descriptor of >> choice in python .... > Yes, but I'm trying to use *TimedRotating*FileHandler, which makes the > fd of the logfile change in every rotation of the logfile. So the direct > approach of std[out|err] redirection to the logfile fd obtained from > the logger instance is unusable (it works fine with a simple file > handler). Right, so you stick something in as stderr/stdout that talks to the logfile. That is, something like: import sys class MyFakeStdout(object): def flush(self): pass def write(self, text): sys.stderr = sys.stdout = MyFakeStdout() --Scott David Daniels Scott.Daniels at Acm.Org From bedouglas at earthlink.net Mon Feb 16 13:25:52 2009 From: bedouglas at earthlink.net (bruce) Date: Mon, 16 Feb 2009 10:25:52 -0800 Subject: pythojn/xpath question... Message-ID: <445301c99064$00c80e50$0301a8c0@tmesa.com> hi... using libxml2dom as the xpath lib i've got a situation where i can have: foo=a.xpath( /html/body/table[2]/tr[45]/td) and i can get 11 as the number of returned td elements for the 45th row... this is as it should be. however, if i do: foo=a.xpath( /html/body/table[2]/tr) and then try to iterate through to the 45th "tr", and try to get the number of "td" elements.. i can't seem to get the additional xpath that has to be used, i've tried a number of the following with no luck... l1 = libxml2dom.toString(tmp_[0]) print "l1 = "+l1+"\n" ldx = 0 for l in tmp_: print "ld ="+str(ldx) if ldx==45: #needs to be a better way... #l1 = libxml2dom.toString(tmp_[0]) l1 = libxml2dom.toString(l) #print "1111 = ",l1 q1 = libxml2dom b1 = q1.parseString(l1, html=1) #dd1 = b1.xpath("//td[not(@width)]") #data = b1.xpath("//td/font") #data = b1.xpath("//td[@valign='top'][not(@width)]") #data = b1.xpath("//child::td[position()>0][@valign='top'][not(@width)]") #data = b1.xpath("//td/parent::*/td[@valign='top'][not(@width)]") #data = b1.xpath("//td[position()]") #data = b1.xpath("//parent::tr[position()=1]/td") data = b1.xpath("//td[@valign='top'][not(@width)]") it appears that i somehow need to get the direct child/node of the parent "tr" that's the "td"... it looks like using ("//td..." gets all the underlying child "td"... as opposed to the direct 1st level child/siblings... any thoughts/pointers would be appreciated... thanks... From jcd at sdf.lonestar.org Mon Feb 16 13:34:17 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Mon, 16 Feb 2009 13:34:17 -0500 Subject: Pythonic way to determine if one char of many in a string In-Reply-To: <20090216052846.GA12723@dirichlet.crans.org> References: <1234761457.20683.1300568627@webmail.messagingengine.com> <20090216052846.GA12723@dirichlet.crans.org> Message-ID: <1234809257.26675.14.camel@aalcdl07.lib.unc.edu> On Mon, 2009-02-16 at 00:28 -0500, Nicolas Dandrimont wrote: > * python at bdurham.com [2009-02-16 00:17:37 -0500]: > > > I need to test strings to determine if one of a list of chars is > > in the string. A simple example would be to test strings to > > determine if they have a vowel (aeiouAEIOU) present. > > I was hopeful that there was a built-in method that operated > > similar to startswith where I could pass a tuple of chars to be > > tested, but I could not find such a method. > > Which of the following techniques is most Pythonic or are there > > better ways to perform this type of match? > > # long and hard coded but short circuits as soon as match found > > if 'a' in word or 'e' in word or 'i' in word or 'u' in word or > > ... : > > -OR- > > # flexible, but no short circuit on first match > > if [ char for char in word if char in 'aeiouAEIOU' ]: > > -OR- > > # flexible, but no short circuit on first match > > if set( word ).intersection( 'aeiouAEIOU' ): > > I would go for something like: > > for char in word: > if char in 'aeiouAEIUO': > char_found = True > break > else: > char_found = False > > (No, I did not forget to indent the else statement, see > http://docs.python.org/reference/compound_stmts.html#for) > > It is clear (imo), and it is seems to be the intended idiom for a search > loop, that short-circuits as soon as a match is found. > If performance becomes an issue, you can tune this very easily, so it doesn't have to scan through the string 'aeiouAEIOU' every time, by making a set out of that: vowels = set('aeiouAEIOU') for char in word if char in vowels: return True return False Searching in a set runs in constant time. > Cheers, > -- > http://mail.python.org/mailman/listinfo/python-list From laplacian42 at gmail.com Mon Feb 16 13:43:12 2009 From: laplacian42 at gmail.com (laplacian42 at gmail.com) Date: Mon, 16 Feb 2009 10:43:12 -0800 (PST) Subject: Found a very nice, small, cross-platform GUI toolkit for Python. References: <4a912328-2d60-4380-b440-8d4d94f79662@v19g2000yqn.googlegroups.com> Message-ID: <66885dbe-72cd-46da-b59e-90e7f2dcf7da@m42g2000yqb.googlegroups.com> On Feb 16, 2:34?am, Python Nutter wrote: > Had a look and it is still under my radar unfortunately because of > TkInter. OceanGUI Note: spelling is "OcempGUI". Also, since google broke some of the links, here's that main link again: http://ocemp.sourceforge.net/gui.html > has a lot of large decencies (Pygame, SDL libraries, > PyObjC, etc.) to install on my system Well, to be fair, SDL is pretty commonly-used software and they offer binary downloads for Mac OS X and MS Windows. Pygame seems to provide the same. So, installation should be a breeze. > to just to get a GUI thats no > better loking than TkInter which comes pre-installed (no dependencies) > on most every major platform. Well, of course, there *is* a dependency: you need Tcl/Tk installed. > If I was writing a game I might be interested, but I'd want to do some > serious skinning of that GUI to make it look better. I suppose so, but the point of my post was that by default it makes quite a nice GUI toolkit. > For applications installing the full wxWidgets or Qt toolkits would be > less disk space and dependcies than OceanGUI What? Qt and wX are *huge* compared to OcempGUI. > and performance would > probably be higher. Probably, but wX and Qt are written in C++. OcempGUI is pure Python, which would make it easier for the Python community to help extend, optimize, and maintain. > TkInter also has many skins/themes you can add > that makes it rather, although not 100% native looking on target > systems. OcempGUI can also be "themed" as well. Though I'm not sure how much is out there yet. From dotancohen at gmail.com Mon Feb 16 13:52:41 2009 From: dotancohen at gmail.com (Dotan Cohen) Date: Mon, 16 Feb 2009 20:52:41 +0200 Subject: Found a very nice, small, cross-platform GUI toolkit for Python. In-Reply-To: <66885dbe-72cd-46da-b59e-90e7f2dcf7da@m42g2000yqb.googlegroups.com> References: <4a912328-2d60-4380-b440-8d4d94f79662@v19g2000yqn.googlegroups.com> <66885dbe-72cd-46da-b59e-90e7f2dcf7da@m42g2000yqb.googlegroups.com> Message-ID: <880dece00902161052j12cd2a64m3108ecd47c2bbbbe@mail.gmail.com> >> For applications installing the full wxWidgets or Qt toolkits would be >> less disk space and dependcies than OceanGUI > > What? Qt and wX are *huge* compared to OcempGUI. > Don't forget that many people will already have Qt already installed, such as KDE users, or those who use Skype, Google Earth, or Opera. Though KDE's Qt will likely be accessibily installed in a convinient place, though, I'm not so sure about those other examples. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-??-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-? From vedrandekovic at gmail.com Mon Feb 16 13:58:27 2009 From: vedrandekovic at gmail.com (vedrandekovic at gmail.com) Date: Mon, 16 Feb 2009 10:58:27 -0800 (PST) Subject: wxPython and Croatian characters Message-ID: <08c279c8-7934-4dff-b657-73dc12e3dfa3@o36g2000yqh.googlegroups.com> Hello, I have problem with configuring my wxPython script to work with Croatian characters like: ?,?,?,?,?. Here is my simple script without wxPython (this script works): # -*- coding: utf-8 -*- s = "hello normal string ?????" print s ..here is my snippet with wxPython: text = wx.StaticText(self, -1,"Mati?ni broj",(0,100)) # in this example,we have character "?" ...when I run this text, it looks something like: "Mati",some weird characters ,and "ni" Regards, John From deets at nospam.web.de Mon Feb 16 14:03:45 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 16 Feb 2009 20:03:45 +0100 Subject: pythojn/xpath question... In-Reply-To: References: Message-ID: <6vtrkiFltc8eU1@mid.uni-berlin.de> bruce schrieb: > hi... > > using libxml2dom as the xpath lib > > i've got a situation where i can have: > foo=a.xpath( /html/body/table[2]/tr[45]/td) > and i can get > 11 as the number of returned td elements for the 45th row... > > this is as it should be. > > however, if i do: > foo=a.xpath( /html/body/table[2]/tr) > > and then try to iterate through to the 45th "tr", and try to get the number > of "td" elements.. > i can't seem to get the additional xpath that has to be used, > > i've tried a number of the following with no luck... > l1 = libxml2dom.toString(tmp_[0]) > print "l1 = "+l1+"\n" > > ldx = 0 > for l in tmp_: > print "ld ="+str(ldx) > if ldx==45: > #needs to be a better way... > #l1 = libxml2dom.toString(tmp_[0]) > l1 = libxml2dom.toString(l) > #print "1111 = ",l1 > > q1 = libxml2dom > b1 = q1.parseString(l1, html=1) > #dd1 = b1.xpath("//td[not(@width)]") > #data = b1.xpath("//td/font") > #data = b1.xpath("//td[@valign='top'][not(@width)]") > #data = > b1.xpath("//child::td[position()>0][@valign='top'][not(@width)]") > #data = b1.xpath("//td/parent::*/td[@valign='top'][not(@width)]") > #data = b1.xpath("//td[position()]") > #data = b1.xpath("//parent::tr[position()=1]/td") > data = b1.xpath("//td[@valign='top'][not(@width)]") > > > it appears that i somehow need to get the direct child/node of the parent > "tr" that's the "td"... > it looks like using ("//td..." gets all the underlying child "td"... as > opposed to the direct > 1st level child/siblings... any thoughts/pointers would be appreciated... - you don't give enough information, as you don't provide the html - the above code is obviously not the one running, as I can't see anything that's increasing your running variable ldx - using l as variable names is extremely confusing, because it's hard to distinguish from 1 (the number). Using l1 is even worse. - xpath usually counts from 1, whereas python is 0-based. As is your code. So you most probably have a off-by-one-error. - you should read a xpath-tutorial, as "//td"'s purpose is to fetch *all* elements td from the document root, as it is clearly stated here: http://www.w3.org/TR/xpath#path-abbrev. So it's no wonder you get more than you expect. Direct child nodes are found by simply omitting the axis specifier. Diez From bdesth.quelquechose at free.quelquepart.fr Mon Feb 16 14:04:59 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Mon, 16 Feb 2009 20:04:59 +0100 Subject: Found a very nice, small, cross-platform GUI toolkit for Python. In-Reply-To: <00b55f86-c0ae-4611-972e-9bdb899efd44@l1g2000yqj.googlegroups.com> References: <4a912328-2d60-4380-b440-8d4d94f79662@v19g2000yqn.googlegroups.com> <66885dbe-72cd-46da-b59e-90e7f2dcf7da@m42g2000yqb.googlegroups.com> <00b55f86-c0ae-4611-972e-9bdb899efd44@l1g2000yqj.googlegroups.com> Message-ID: <4999c674$0$10270$426a74cc@news.free.fr> laplacian42 at gmail.com a ?crit : > On Feb 16, 1:52 pm, Dotan Cohen wrote: >> Don't forget that many people will already have Qt already installed, >> such as KDE users, or those who use Skype, Google Earth, or Opera. >> Though KDE's Qt will likely be accessibily installed in a convinient >> place, though, I'm not so sure about those other examples. >> > > Well, yes. KDE users will already have Qt installed (and maybe PyQt) > but may groan at the prospect of having to install GTK+ and PyGTK. > Gnome users will already have GTK+ installed (and maybe PyGTK), but > may groan at having to install Qt and PyQt. However, both will likely > have no qualms about installing SDL and Pygame (which are pretty small > and also allow them to play various games as well). FWIW (and servers set aside, of course), I can hardly remember of any of linux box I worked one not having both GTK and KDE installed. From deets at nospam.web.de Mon Feb 16 14:06:53 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 16 Feb 2009 20:06:53 +0100 Subject: wxPython and Croatian characters In-Reply-To: <08c279c8-7934-4dff-b657-73dc12e3dfa3@o36g2000yqh.googlegroups.com> References: <08c279c8-7934-4dff-b657-73dc12e3dfa3@o36g2000yqh.googlegroups.com> Message-ID: <6vtrqdFltc8eU2@mid.uni-berlin.de> vedrandekovic at gmail.com schrieb: > Hello, > > I have problem with configuring my wxPython script to work with > Croatian characters like: ?,?,?,?,?. > Here is my simple script without wxPython (this script works): > > # -*- coding: utf-8 -*- > s = "hello normal string ?????" > print s > > ..here is my snippet with wxPython: > > text = wx.StaticText(self, -1,"Mati?ni broj",(0,100)) # in this > example,we have character "?" > > ...when I run this text, it looks something like: "Mati",some weird > characters ,and "ni" Unless you are using python 3.0 (which I doubt, afaik no wx available), your above coding declaration is useless for the shown piece of code, as it only applies to unicode literals, which are written with a preceding u. So u"m?nsch ist doch nicht so schwer" gives you an unicode literal, that wx might work with (don't know wx) And of course you need to make sure your editor produces utf-8 as output, otherwise the exercise is futile as well. Diez From regebro at gmail.com Mon Feb 16 14:08:19 2009 From: regebro at gmail.com (Lennart Regebro) Date: Mon, 16 Feb 2009 20:08:19 +0100 Subject: To 3.0.2 or not to 3.0.2? Message-ID: <319e029f0902161108o5bb3506fq529525d35d0f35fe@mail.gmail.com> I discovered some remaining cmp() in 3.0.1, 38 minutes after Benjamin fixed them. :) Unfortunately, that means porting setuptools to 3.0.1 will be a bit difficult. So my question is: Will there be a 3.0.2 with those fixes, or should I add workaround code for 3.0.1? -- Lennart Regebro: Pythonista, Barista, Notsotrista. http://regebro.wordpress.com/ +33 661 58 14 64 From bdesth.quelquechose at free.quelquepart.fr Mon Feb 16 14:11:04 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Mon, 16 Feb 2009 20:11:04 +0100 Subject: illegal list name In-Reply-To: References: Message-ID: <4999c7e0$0$4785$426a74cc@news.free.fr> Sandra Quiles a ?crit : > Hello. I have followed the instructions of a post on Installing mailman > on OS X 10.4, and got to step 7 and hit this error. > (snip) > So. illegal name error. it list listname as 'mailman@' > > that's in response to the 'bin/newlist mailman' command Sorry, this has nothing to do with Python. Please refer to mailman's documentation, mailing list or whatever. > also, I purchased the Postfix Enabler, but have no clue what to do with > the software. Nor do I. > Tips, advise, hand-holding welcomed. Start here: http://catb.org/~esr/faqs/smart-questions.html HTH From laplacian42 at gmail.com Mon Feb 16 14:16:39 2009 From: laplacian42 at gmail.com (laplacian42 at gmail.com) Date: Mon, 16 Feb 2009 11:16:39 -0800 (PST) Subject: Found a very nice, small, cross-platform GUI toolkit for Python. References: <4a912328-2d60-4380-b440-8d4d94f79662@v19g2000yqn.googlegroups.com> <66885dbe-72cd-46da-b59e-90e7f2dcf7da@m42g2000yqb.googlegroups.com> Message-ID: <00b55f86-c0ae-4611-972e-9bdb899efd44@l1g2000yqj.googlegroups.com> On Feb 16, 1:52?pm, Dotan Cohen wrote: > > Don't forget that many people will already have Qt already installed, > such as KDE users, or those who use Skype, Google Earth, or Opera. > Though KDE's Qt will likely be accessibily installed in a convinient > place, though, I'm not so sure about those other examples. > Well, yes. KDE users will already have Qt installed (and maybe PyQt) but may groan at the prospect of having to install GTK+ and PyGTK. Gnome users will already have GTK+ installed (and maybe PyGTK), but may groan at having to install Qt and PyQt. However, both will likely have no qualms about installing SDL and Pygame (which are pretty small and also allow them to play various games as well). From fmaresca at gmail.com Mon Feb 16 14:19:35 2009 From: fmaresca at gmail.com (Fernando M. Maresca) Date: Mon, 16 Feb 2009 17:19:35 -0200 Subject: logging and daemons In-Reply-To: <34idnSxjvpdDNgTUnZ2dnUVZ_haWnZ2d@pdx.net> References: <20090216130206.GA20397@gmail.com> <364299f40902160507g4eca4be2yda535199451ce5a8@mail.gmail.com> <34idnSxjvpdDNgTUnZ2dnUVZ_haWnZ2d@pdx.net> Message-ID: <20090216191935.GA11254@gmail.com> On Mon, Feb 16, 2009 at 10:11:51AM -0800, Scott David Daniels wrote: > Fernando M. Maresca wrote: > On Mon, Feb 16, 2009 at 05:07:45AM -0800, Garrett Cooper wrote: >>> You can actually set sys.std[err|out] to your ?file? descriptor of >>> choice in python .... >> Yes, but I'm trying to use *TimedRotating*FileHandler, which makes the >> fd of the logfile change in every rotation of the logfile. So the direct >> approach of std[out|err] redirection to the logfile fd obtained from >> the logger instance is unusable (it works fine with a simple file >> handler). > > Right, so you stick something in as stderr/stdout that talks to the > logfile. That is, something like: > > import sys > > class MyFakeStdout(object): > def flush(self): > pass > def write(self, text): > > sys.stderr = sys.stdout = MyFakeStdout() > Thanks a lot for the input. That's pretty much what I'm doing right now, just wondered if were a cleanest way. Cheers, -- Fernando -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 204 bytes Desc: Digital signature URL: From stefaan.himpe at gmail.com Mon Feb 16 14:44:55 2009 From: stefaan.himpe at gmail.com (Stefaan Himpe) Date: Mon, 16 Feb 2009 20:44:55 +0100 Subject: Pythonic way to determine if one char of many in a string In-Reply-To: References: <1234761457.20683.1300568627@webmail.messagingengine.com> <20090216052846.GA12723@dirichlet.crans.org> Message-ID: An entirely different approach would be to use a regular expression: import re if re.search("[abc]", "nothing expekted"): print "a, b or c occurs in the string 'nothing expekted'" if re.search("[abc]", "something expected"): print "a, b or c occurs in the string 'something expected'" Best regards, Stefaan. From steve at holdenweb.com Mon Feb 16 14:45:21 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 16 Feb 2009 14:45:21 -0500 Subject: replace ftp by local copy In-Reply-To: <2f223a64-4459-4905-b44a-07da12048895@c12g2000yqj.googlegroups.com> References: <2f223a64-4459-4905-b44a-07da12048895@c12g2000yqj.googlegroups.com> Message-ID: loial wrote: > I have been given an old python application that calls ftplib in many > places to copy files to a remote server. > > I have been given the task of cloneing this code so that ftp is not > used, but files are just copied locally in a scenerio where ftp is not > available. The code is not well structured which makes this more > difficult. > > Before starting this just wondered if anyone has previously done > anything like overriding the ftplib module so that I can leave the > existing code largely unchanged but have the ftp commands just copy > files locally? > > Just thought I'd ask before getting started. > I don't remember anyone mentioning this, but it sounds like the soundest engineering approach, and the one least likely to induce breakage ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From hniksic at xemacs.org Mon Feb 16 14:48:02 2009 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Mon, 16 Feb 2009 20:48:02 +0100 Subject: Easier to wrap C or C++ libraries? References: <7baacd31-58c8-4e11-b25a-f827cc63d6ac@e18g2000yqo.googlegroups.com> <6vocf5Fkv5a9U1@mid.uni-berlin.de> <87vdrciysm.fsf@mulj.homelinux.net> Message-ID: <87d4dii2od.fsf@mulj.homelinux.net> Nick Craig-Wood writes: > Christian Heimes wrote: >> Hrvoje Niksic schrieb: >> > "Diez B. Roggisch" writes: >> > >> >> The answer is easy: if you use C, you can use ctypes to create a >> >> wrapper - with pure python, no compilation, no platform issues. >> > >> > The last part is not true. ctypes doesn't work on 64-bit >> > architectures, nor does it work when Python is built with non-gcc Unix >> > compilers >> >> ctypes works on 64bit systems, too. However it's a pain in the ... back >> to write code with ctypes that works across all platforms. I used to use >> ctypes for wrapper but eventually I switched to Cython. > > What sort of problems have you had? > > I find as long as I use the same types as the C code actually uses it > all works fine. If on a 64 bit platform long is 64 bits then it will > be under ctypes too. I apologize for the misinformation that ctypes doesn't work on 64-bit systems. The project I'm working on doesn't include ctypes, but it could be because we don't use GCC to build, or because we also need to support Win64. From santosdosreis at gmail.com Mon Feb 16 14:52:56 2009 From: santosdosreis at gmail.com (Jayson Santos) Date: Mon, 16 Feb 2009 11:52:56 -0800 (PST) Subject: Speedup Bitmap Parser Message-ID: <58aed622-cf81-4747-ac54-86badef1c8dc@s20g2000yqh.googlegroups.com> Hello people, I'm writing a Bitmap parser for study purposes, however when I parse a bitmap file and when I paint that file in a window, the script take to much time. How can I optimize my script loops to be faster ? Here is the script http://pastebin.com/m652b8d65 Best Regards Jayson Reis From Olivier.Darge at gmail.com Mon Feb 16 15:10:22 2009 From: Olivier.Darge at gmail.com (OdarR) Date: Mon, 16 Feb 2009 12:10:22 -0800 (PST) Subject: flexible find and replace ? Message-ID: <18d1b669-7a79-4295-a1e2-4693d361d0af@v13g2000yqm.googlegroups.com> Hi guys, how would you do a clever find and replace, where the value replacing the tag is changing on each occurence ? ".......TAG............TAG................TAG..........TAG....." is replaced by this : ".......REPL01............REPL02................REPL03..........REPL04..." A better and clever method than this snippet should exist I hope : counter = 1 while 'TAG' in mystring: mystring=mystring.replace('TAG', 'REPL'+str(counter), 1) counter+=1 ... (the find is always re-starting at the string beginning, this is not efficient. any ideas ? thanks, Olivier From dotancohen at gmail.com Mon Feb 16 15:19:25 2009 From: dotancohen at gmail.com (Dotan Cohen) Date: Mon, 16 Feb 2009 22:19:25 +0200 Subject: Found a very nice, small, cross-platform GUI toolkit for Python. In-Reply-To: <4999c674$0$10270$426a74cc@news.free.fr> References: <4a912328-2d60-4380-b440-8d4d94f79662@v19g2000yqn.googlegroups.com> <66885dbe-72cd-46da-b59e-90e7f2dcf7da@m42g2000yqb.googlegroups.com> <00b55f86-c0ae-4611-972e-9bdb899efd44@l1g2000yqj.googlegroups.com> <4999c674$0$10270$426a74cc@news.free.fr> Message-ID: <880dece00902161219h482ba846q42b9e4ec478facab@mail.gmail.com> > FWIW (and servers set aside, of course), I can hardly remember of any of > linux box I worked one not having both GTK and KDE installed. I don't think that those netbooks come with Qt. And for a Windows installer, where one may want to package the toolkit with the program, a small toolkit may be nice. There is such an issue today on the Zim list, where including GTK in the installer bloated it to four times it's size. So it may be more of a download size for Windows users, than an installed size for Linux users (disk space is cheap, at least with traditional rotating hard drives). -- Dotan Cohen http://what-is-what.com http://gibberish.co.il ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-??-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-? From bearophileHUGS at lycos.com Mon Feb 16 15:22:40 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Mon, 16 Feb 2009 12:22:40 -0800 (PST) Subject: flexible find and replace ? References: <18d1b669-7a79-4295-a1e2-4693d361d0af@v13g2000yqm.googlegroups.com> Message-ID: OdarR: > how would you do a clever find and replace, where the value replacing > the tag is changing on each occurence ? > ".......TAG............TAG................TAG..........TAG....." > is replaced by this : > ".......REPL01............REPL02................REPL03..........REPL04..." You may use something like this (tested) replacing XXXXXXXXXXXX with the correct re function: import re def replacer(mobj): replacer.counter += 1 return "REPL%02d" % replacer.counter replacer.counter = 0 print re.XXXXXXXXXXXX("TAG", replacer, s1) (If you have more than 99 replacements it will use more than two digits.) Bye, bearophile From jason.scheirer at gmail.com Mon Feb 16 15:27:54 2009 From: jason.scheirer at gmail.com (Jason Scheirer) Date: Mon, 16 Feb 2009 12:27:54 -0800 (PST) Subject: flexible find and replace ? References: <18d1b669-7a79-4295-a1e2-4693d361d0af@v13g2000yqm.googlegroups.com> Message-ID: <4a46c0dc-e78c-4bf0-8b6f-e80964ce4205@o40g2000prn.googlegroups.com> On Feb 16, 12:10?pm, OdarR wrote: > Hi guys, > > how would you do a clever find and replace, where the value replacing > the tag > is changing on each occurence ? > > ".......TAG............TAG................TAG..........TAG....." > > is replaced by this : > > ".......REPL01............REPL02................REPL03..........REPL04..." > > A better and clever method than this snippet should exist I hope : > > counter = 1 > while 'TAG' in mystring: > ? ? mystring=mystring.replace('TAG', 'REPL'+str(counter), 1) > ? ? counter+=1 > ? ? ... > > (the find is always re-starting at the string beginning, this is not > efficient. > > any ideas ? thanks, > > Olivier You could split on the string and interleave your new string in between: In [1]: def replmaker(): ...: index = 0 ...: while True: ...: index += 1 ...: yield "REPL%02i"%index ...: In [2]: def spliton(string, tag="TAG", sepgen=replmaker): ...: repl_iter = sepgen() ...: strlist = string.split(tag) ...: length = len(strlist) ...: for index, item in enumerate(strlist): ...: yield item ...: if index < length - 1: ...: yield repl_iter.next() ...: In [3]: ''.join(spliton (".......TAG............TAG................TAG..........TAG....." )) Out[3]: '.......REPL01............REPL02................REPL03..........REPL04.....' From jason.scheirer at gmail.com Mon Feb 16 15:32:39 2009 From: jason.scheirer at gmail.com (Jason Scheirer) Date: Mon, 16 Feb 2009 12:32:39 -0800 (PST) Subject: wxPython and Croatian characters References: <08c279c8-7934-4dff-b657-73dc12e3dfa3@o36g2000yqh.googlegroups.com> Message-ID: <14f11397-7db3-4cf2-9d19-5038ef86dc3b@o40g2000prn.googlegroups.com> On Feb 16, 10:58?am, vedrandeko... at gmail.com wrote: > Hello, > > I have problem with configuring my wxPython script to work with > Croatian characters like: ??,?,?,?,?. > Here is my simple script without wxPython (this script works): > > ? ? ? # -*- coding: utf-8 -*- > ? ? ? s = "hello normal string ?????" > ? ? ? print s > > ..here is my snippet with wxPython: > > ? ? text = wx.StaticText(self, -1,"Mati?ni broj",(0,100)) # in this > example,we have character "?" > > ...when I run this text, it looks something like: ?"Mati",some weird > characters ,and "ni" > > Regards, > John You may be using an ANSI build of wxWidgets instead of a unicode one. Make sure to enable Unicode when you run ./configure, or if in Windows, uninstall and download the win32-unicode version of the wxPython you want. From tjreedy at udel.edu Mon Feb 16 15:37:24 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 16 Feb 2009 15:37:24 -0500 Subject: explain In-Reply-To: <20090216102613.GE39358@nexus.in-nomine.org> References: <654311.52341.qm@web111202.mail.gq1.yahoo.com> <20090216102613.GE39358@nexus.in-nomine.org> Message-ID: Jeroen Ruigrok van der Werven wrote: > -On [20090216 11:17], Saeed Iravani (si.422a at yahoo.com) wrote: >> I download python 2.5.4 and install but I dont know that how perform python? >> I dont know from which directory perform python? > > It would help if you would clarify which operating system you are using. > > On Unix/Linux systems you make sure to 'rehash' your $PATH or add the > appropriate directory to the $PATH variable. > > On Windows, you set your environment variable PATH to include the path to > Python programs (typically something like C:\Python25), which you can find > under the system control panel. On windows, that is not necessary for many uses. Just use the entries in the start menu. From tjreedy at udel.edu Mon Feb 16 15:42:22 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 16 Feb 2009 15:42:22 -0500 Subject: Creating custom formatter function In-Reply-To: <364299f40902160350n8583e88o20f7799eca3934b6@mail.gmail.com> References: <364299f40902160350n8583e88o20f7799eca3934b6@mail.gmail.com> Message-ID: Garrett Cooper wrote: > Hello Python folks, > I have a function where I'd like to prefix a format string via a > `prefix' string. The definition of the base method is as follows: > > #START CODE > def print_message(prefix, out_stream, fmt, *args, **kwargs): > """ Print out [prefix]: [message] """ > > message = fmt > > if 0 < len(kwargs.keys()): > message = message % kwargs > > if 0 < len(args): To clarify error message, "print fmt, message, args" here > message = message % args This line > > out_stream.write(message + "\n") > #END CODE > > My python 2.4.5 interpreter fails at `message % args' claiming the > following: > > File "logging.py", line 10, in print_message > message = message % (args) does not quite match this one, so one is not copy/pasted. > TypeError: not all arguments converted during string formatting > > Thus I was wondering what the proper means was for formatting > strings. I'm new to this portion of Python, so I obviously didn't > apply the right syntax. > TIA! > -Garrett > -- > http://mail.python.org/mailman/listinfo/python-list > From tjreedy at udel.edu Mon Feb 16 16:15:42 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 16 Feb 2009 16:15:42 -0500 Subject: Speedup Bitmap Parser In-Reply-To: <58aed622-cf81-4747-ac54-86badef1c8dc@s20g2000yqh.googlegroups.com> References: <58aed622-cf81-4747-ac54-86badef1c8dc@s20g2000yqh.googlegroups.com> Message-ID: Jayson Santos wrote: > Hello people, I'm writing a Bitmap parser for study purposes, however > when I parse a bitmap file and when I paint that file in a window, the > script take to much time. 1. You turned constants into static methods called for every line, adding attribute lookup and function call time. 2. You read the image a line at a time and break each line into separate pixel objects. 3. You paint each pixel by drawing and filling a 1-pixel rectangle. > How can I optimize my script loops to be faster ? Don't do any of the above. Look at how other programs such as PIL or pygame read, store, and paint images. > Here is the script > http://pastebin.com/m652b8d65 tjr From rushenaly at gmail.com Mon Feb 16 16:20:11 2009 From: rushenaly at gmail.com (rushenaly at gmail.com) Date: Mon, 16 Feb 2009 13:20:11 -0800 (PST) Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> Message-ID: Hi again OpenERP and ERP5 was written in python as i know. I really wonder how they do this without threads. I want to see a real time graph at the same time while i am working on the same screen. What is the secret? Thanks Rushen From shreyas22 at gmail.com Mon Feb 16 16:27:14 2009 From: shreyas22 at gmail.com (shreyas shah) Date: Mon, 16 Feb 2009 16:27:14 -0500 Subject: Regarding Joystick In-Reply-To: <3de8e1f70902122036i2fc88f85h351370a9ddaababb@mail.gmail.com> References: <3de8e1f70902122036i2fc88f85h351370a9ddaababb@mail.gmail.com> Message-ID: Hi , I have figured out a code with the help of archives in pygame .... can anyone help me with controlling the speed of joystick ... i am going to integrate joystick with a PTZ camera ... i was wondering if there are any functions which can help me control the speed of camera and by controlling motion of joystick #! /usr/bin/env python import pygame from pygame import locals jlist = [] # global joystick list class Joystick: def __init__(self): pygame.init() self.nbJoy = pygame.joystick.get_count() for n in range(self.nbJoy): pygame.joystick.Joystick(n).init() try: for n in range(pygame.joystick.get_count()): # stick = pygame.joystick.Joystick(n) jlist.append(stick) # create a joystick instance stick.init() # init instance # report joystick charateristics # print '-'*20 print 'Enabled joystick: ' + stick.get_name() print 'it has the following devices :' print '--> buttons : '+ str(stick.get_numbuttons()) print '--> balls : '+ str(stick.get_numballs()) print '--> axes : '+ str(stick.get_numaxes()) print '--> hats : '+ str(stick.get_numhats()) print '-'*20 except pygame.error: print 'pygame.error, no joystick found.' def main(self): # init() # init pygame and joystick system while 1: # endless loop for e in pygame.event.get(): # iterate over event stack if e.type == pygame.locals.JOYAXISMOTION: # 7 for j in jlist: for n in range(j.get_numaxes()): print 'moved axe num '+str(n)+' : ' + str(j.get_axis(n)) print '-'*10 # separation elif e.type == pygame.locals.JOYBALLMOTION: # 8 for j in jlist: for n in range(j.get_numballs()): print 'moved ball num '+str(n)+' : '+ str(j.get_ball(n)) print '-'*10 # separation elif e.type == pygame.locals.JOYHATMOTION: # 9 for j in jlist: for n in range(j.get_numhats()): print 'moved hat num '+str(n)+' : '+ str(j.get_hat(n)) print '-'*10 # separation elif e.type == pygame.locals.JOYBUTTONDOWN: # 10 for j in jlist: for n in range(j.get_numbuttons()): if j.get_button(n) : # if this is down print 'down button num '+str(n)+' : '+ str(j.get_button(n)) print '-'*10 # separation elif e.type == pygame.locals.JOYBUTTONUP: # 11 for j in jlist: for n in range(j.get_numbuttons()): print 'up button num '+str(n)+' : '+ str(j.get_button(n)) print '-'*10 # separation if __name__ == '__main__': j = Joystick() j.main() thanks shreyas On Thu, Feb 12, 2009 at 11:36 PM, Banibrata Dutta wrote: > AFAIK, the mechanism / API / protocol to actuate the Camera's tilt, pan, > zoom functions are not standardized (happy to be corrected there!), so even > if you find something, it'd most likely be something very specific to a > particular device. > As for Joystick usage, I remember seeing one thread on that couple of > months back, so searching thru the archive should give you leads. > > On Fri, Feb 13, 2009 at 3:33 AM, shreyas shah wrote: > >> Hi , >> >> I am trying to control the motion of the camera with help of joystick , i >> need some basic functionality where if i move a joystick to left the camera >> moves to the left . Can anyone help me with that ? >> >> Thanks >> Shreyas >> >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > > > -- > regards, > Banibrata > http://www.linkedin.com/in/bdutta > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bearophileHUGS at lycos.com Mon Feb 16 16:29:11 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Mon, 16 Feb 2009 13:29:11 -0800 (PST) Subject: Speedup Bitmap Parser References: <58aed622-cf81-4747-ac54-86badef1c8dc@s20g2000yqh.googlegroups.com> Message-ID: Jayson Santos: > Hello people, I'm writing a Bitmap parser for study purposes, This code: x = 0 y = 0 for line in bmp.bitmap_lines.lines: for color in xrange(len(line.colors)): canvas.create_line(x, y, x+1, y, fill="#%02x%02x%02x" % (line.colors[color].red, line.colors[color].green, line.colors [color].blue)) x += 1 x = 0 y += 1 May be replaced with something like: for x, color in enumerate(line.colors): canvas.create_line(x, y, x+1, y, fill="#%02x%02x%02x" % (color.red, color.green, color.blue)) And maybe a RGBTriple may be replaced with an immutable namedtuple. Using nested classes may be overkill for this program. Use the Python profiler and profile your code with a real image, and show us/me the profiler results, so I can give you some suggestions to speed up your code. Bye, bearophile From nick at craig-wood.com Mon Feb 16 16:31:55 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Mon, 16 Feb 2009 15:31:55 -0600 Subject: Found a very nice, small, cross-platform GUI toolkit for Python. References: <4a912328-2d60-4380-b440-8d4d94f79662@v19g2000yqn.googlegroups.com> Message-ID: laplacian42 at gmail.com wrote: > I think I just found the GUI toolkit for Python I've been searching > for. It seems to meet all of the following requirements: > > * free software > * small (I don't need batteries -- Python already comes with those.) > * easy to use > * actively maintained > * cross-platform > * easy to install > * based on a stable and actively-maintained C library > * does not depend on an external scripting language (for example, > Tcl) > * well-documented > * not too many dependencies > * can easily integrate with PyOpenGL > * support for accessibility > > and it's also written in Python. > > I have no idea how it's stayed under the radar in the Python community > for this long, yet here it is: [OcempGUI](http://ocemp.sourceforge.net/ > gui.html). The C library it depends upon? [SDL](http:// > www.libsdl.org/) (via [PyGame](http://www.pygame.org/news.html)). Interesting! One of the commercial apps I'm involved (C++ not python) in uses SDL as its GUI with windows etc built on top of it. It means that it looks exactly the same on all supported platforms and since it usually runs full screen that is fine. I imagine this GUI toolkit fits the same niche. Presumably since it uses SDL then all the GUI will appear in one window? So windows within windows in the MDI style? -- Nick Craig-Wood -- http://www.craig-wood.com/nick From nick at craig-wood.com Mon Feb 16 16:31:55 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Mon, 16 Feb 2009 15:31:55 -0600 Subject: Pythonic way to determine if a string is a number References: <1234720016.23422.1300488109@webmail.messagingengine.com> <2B9BDEC0-5D49-4760-86D7-C36A5FC849C6@semanchuk.com> Message-ID: python at bdurham.com wrote: > Thanks for everyone's feedback. I believe my original post's code > (updated following my signature) was in line with this list's feedback. > > Christian: Thanks for reminding me about exponential formats. My updated > code accounts for these type of numbers. I don't need to handle inf or > nan values. My original code's except catches an explicit ValueError > exception per your concern about bare excepts. > > Malcolm > > > # str_to_num.py > > def isnumber( input ): > try: > num = float( input ) > return True > > except ValueError: > return False That is a fine solution. Last time I had to solve this I had a specific format of number to parse - I didn't want to include all the python formats. This is what I came up with... This particular code returns the converted number or 0.0 - adjust as you see fit! import re _float_pattern = re.compile(r"^\s*([-+]?(\d*\.)?\d+([eE][-+]?\d+)?)") def atof(value): """ Convert a string to an float in the same way the c-library atof() does. Ie only converting as much as it can and returning 0.0 for an error. """ match = _float_pattern.search(value) if match: return float(match.group(1)) return 0.0 >>> atof("15.5 Sausages") 15.5 >>> atof(" 17.2") 17.199999999999999 >>> atof("0x12") 0.0 >>> atof("8.3.2") 8.3000000000000007 >>> atof("potato") 0.0 >>> -- Nick Craig-Wood -- http://www.craig-wood.com/nick From python.list at tim.thechases.com Mon Feb 16 16:36:17 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 16 Feb 2009 15:36:17 -0600 Subject: flexible find and replace ? In-Reply-To: <18d1b669-7a79-4295-a1e2-4693d361d0af@v13g2000yqm.googlegroups.com> References: <18d1b669-7a79-4295-a1e2-4693d361d0af@v13g2000yqm.googlegroups.com> Message-ID: <4999DC51.3010004@tim.thechases.com> > how would you do a clever find and replace, where the value replacing > the tag > is changing on each occurence ? > > ".......TAG............TAG................TAG..........TAG....." > > is replaced by this : > > ".......REPL01............REPL02................REPL03..........REPL04..." This is a variant of the class I've used in the past for stateful replacements: import re class Counter(object): def __init__(self, prefix="REPL", start=1): self.prefix = prefix self.counter = start - 1 def __call__(self, matchobj): self.counter += 1 return "%s%02i" % (self.prefix, self.counter) r = re.compile("TAG") # the regexp to find what we want s = "some TAG stuff with TAG whatever more TAG stuff" print s # just use the counter print r.sub(Counter(), s) # demo a different starting number print r.sub(Counter(start=42), s) # maintain a single counter across calls c = Counter(prefix="Hello", start=42) print r.sub(c, s) print r.sub(c, s) > A better and clever method than this snippet should exist I hope : > > counter = 1 > while 'TAG' in mystring: > mystring=mystring.replace('TAG', 'REPL'+str(counter), 1) > counter+=1 > ... > > (the find is always re-starting at the string beginning, this is not > efficient. This also has problems if your search-string is a substring of your replacement string: search = "foo" replacement = "foobar#" You'll get s = "foo_foo" s = "foobar01_foo" s = "foobar02bar01_foo" ... which isn't quite what it looks like you want. -tkc From laplacian42 at gmail.com Mon Feb 16 16:44:07 2009 From: laplacian42 at gmail.com (laplacian42 at gmail.com) Date: Mon, 16 Feb 2009 13:44:07 -0800 (PST) Subject: Found a very nice, small, cross-platform GUI toolkit for Python. References: <4a912328-2d60-4380-b440-8d4d94f79662@v19g2000yqn.googlegroups.com> Message-ID: <588d2dad-ff75-499d-a4de-0b486e81f99f@p20g2000yqi.googlegroups.com> On Feb 16, 4:31?pm, Nick Craig-Wood wrote: > > Interesting! ?One of the commercial apps I'm involved (C++ not python) > in uses SDL as its GUI with windows etc built on top of it. ?It means > that it looks exactly the same on all supported platforms and since it > usually runs full screen that is fine. ?I imagine this GUI toolkit > fits the same niche. > > Presumably since it uses SDL then all the GUI will appear in one > window? ?So windows within windows in the MDI style? > > -- > Nick Craig-Wood --http://www.craig-wood.com/nick There is a `window.py` example that comes with the distribution. It has modal and non-modal windows within the main window. I haven't yet seen any examples where OcempGUI runs full-screen. The relevant portion of the manual re. subwindows is: http://ocemp.sourceforge.net/manual/windows_and_dialogs.html From dotancohen at gmail.com Mon Feb 16 16:46:31 2009 From: dotancohen at gmail.com (Dotan Cohen) Date: Mon, 16 Feb 2009 23:46:31 +0200 Subject: Found a very nice, small, cross-platform GUI toolkit for Python. In-Reply-To: References: <4a912328-2d60-4380-b440-8d4d94f79662@v19g2000yqn.googlegroups.com> Message-ID: <880dece00902161346v5e753d79x228cc4930fa76e49@mail.gmail.com> > Interesting! One of the commercial apps I'm involved (C++ not python) > in uses SDL as its GUI with windows etc built on top of it. It means > that it looks exactly the same on all supported platforms and since it > usually runs full screen that is fine. I imagine this GUI toolkit > fits the same niche. > Most cross-platform projects come to the conclusion that it is _not_ good to look the same on each supported platform, but rather to match the look of each individual platform. Open Office and Firefox come to mind. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-??-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-? From jcd at sdf.lonestar.org Mon Feb 16 17:06:21 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Mon, 16 Feb 2009 17:06:21 -0500 Subject: wxPython and Croatian characters In-Reply-To: <6vtrqdFltc8eU2@mid.uni-berlin.de> References: <08c279c8-7934-4dff-b657-73dc12e3dfa3@o36g2000yqh.googlegroups.com> <6vtrqdFltc8eU2@mid.uni-berlin.de> Message-ID: <1234821981.28977.4.camel@aalcdl07.lib.unc.edu> On Mon, 2009-02-16 at 20:06 +0100, Diez B. Roggisch wrote: > vedrandekovic at gmail.com schrieb: > > Hello, > > > > I have problem with configuring my wxPython script to work with > > Croatian characters like: ?,?,?,?,?. > > Here is my simple script without wxPython (this script works): > > > > # -*- coding: utf-8 -*- > > s = "hello normal string ?????" > > print s > > > > ..here is my snippet with wxPython: > > > > text = wx.StaticText(self, -1,"Mati?ni broj",(0,100)) # in this > > example,we have character "?" > > > > ...when I run this text, it looks something like: "Mati",some weird > > characters ,and "ni" > > Unless you are using python 3.0 (which I doubt, afaik no wx available), > your above coding declaration is useless for the shown piece of code, as > it only applies to unicode literals, which are written with a preceding u. > No. The coding declaration does nothing to unicode literals. It only affects how the python's source code parser reads the the source code. Without it, your source code will be parsed (or is it lexed?) by python as an ascii document. So if your document is UTF-8, it will choke as soon as it reaches a non ascii character. If it's encoded in UTF-16, however, it will choke right away, as it will immediately come across a \x00 byte, which is treated as the ascii NULL character, which is not legal in python source code. But print will still try to encode all unicode objects to the encoding of your terminal, and any file writing operations will try to decode as ASCII, unless explicitly told otherwise. Same as without the -*- coding -*- declaration. For the OP: When dealing with potentially non-ascii text, always use unicode objects instead of strings, and explicitly encode them to the encoding you want on output, unless your printing facility (here wx.StaticText) handles that for you. I also don't know how wxpython works in this regard. So: s = u"Mati?ni broj" # instead of "Mati?ni broj" text = wx.StaticText(self, -1, s,(0,100)) # or if that doesn't work try this: #text = wx.StaticText(self, -1, s.encode('utf-8'), (0,100)) Cheers, Cliff From martin at v.loewis.de Mon Feb 16 17:49:18 2009 From: martin at v.loewis.de (=?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=) Date: Mon, 16 Feb 2009 23:49:18 +0100 Subject: wxPython and Croatian characters In-Reply-To: References: <08c279c8-7934-4dff-b657-73dc12e3dfa3@o36g2000yqh.googlegroups.com> <6vtrqdFltc8eU2@mid.uni-berlin.de> Message-ID: <4999ED6E.1090804@v.loewis.de> >> Unless you are using python 3.0 (which I doubt, afaik no wx available), >> your above coding declaration is useless for the shown piece of code, as >> it only applies to unicode literals, which are written with a preceding u. >> > > No. The coding declaration does nothing to unicode literals. It only > affects how the python's source code parser reads the the source code. And, as such, it *only* affects Unicode literals, really nothing else (except for error checking). In 2.x, non-ASCII characters can occur only in these places: - comments. no effect on semantics of script - string literals. run-time representation is equal to on-disk representation, so no effect. - unicode literals. run-time representation is 2-byte or 4-byte UCS, so parser needs to decode on-disk representation to in-memory representation. This is the *only* place where the declared encoding matters. > Without it, your source code will be parsed (or is it lexed?) by python > as an ascii document. So if your document is UTF-8, it will choke as > soon as it reaches a non ascii character. So yes, it does an additional error check also. But the main reason for the encoding declaration (besides sanity for text editors also) is Unicode literals (in 3.x, also relevant for identifiers) Regards, Martin From invalid at example.invalid Mon Feb 16 17:57:28 2009 From: invalid at example.invalid (Greg Krohn) Date: Mon, 16 Feb 2009 16:57:28 -0600 Subject: time.strptime() and time.strftime() reciprocity Message-ID: [Apologies for the use of "reciprocity" in the subject - it's a little pompous, I know, but it fits so well. :)] Hello c.l.python! I'm trying to parse some dates of the form "01/29/09 12:55 PM" from a CSV file, but I'm having trouble with the format string in time.strptime() . In testing this I found that the time module chokes on a string that it created itself with the same format: ActivePython 2.6.1.1 (ActiveState Software Inc.) based on Python 2.6.1 (r261:67515, Dec 5 2008, 13:58:38) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import time >>> fmt = "%m/%d/%y %I:%M %p" >>> print time.strptime(fmt, time.strftime(fmt)) Traceback (most recent call last): File "", line 1, in File "C:\Python26\lib\_strptime.py", line 454, in _strptime_time return _strptime(data_string, format)[0] File "C:\Python26\lib\_strptime.py", line 325, in _strptime (data_string, format)) ValueError: time data '%m/%d/%y %I:%M %p' does not match format '02/16/09 04:52 PM' So, yeah, that seems weird to me. Does anyone get similar results, know why this is happening, and/or how to fix it? Thanks. -- ("%s at gmail com" % "Greg Krohn".lower()).replace(" ", ".") From santosdosreis at gmail.com Mon Feb 16 18:08:58 2009 From: santosdosreis at gmail.com (Jayson Santos) Date: Mon, 16 Feb 2009 15:08:58 -0800 (PST) Subject: Speedup Bitmap Parser References: <58aed622-cf81-4747-ac54-86badef1c8dc@s20g2000yqh.googlegroups.com> Message-ID: On 16 fev, 18:29, bearophileH... at lycos.com wrote: > Jayson Santos: > > > Hello people, I'm writing a Bitmap parser for study purposes, > > This code: > > ? ? ? ? x = 0 > ? ? ? ? y = 0 > ? ? ? ? for line in bmp.bitmap_lines.lines: > ? ? ? ? ? ? for color in xrange(len(line.colors)): > ? ? ? ? ? ? ? ? canvas.create_line(x, y, x+1, y, fill="#%02x%02x%02x" > % (line.colors[color].red, line.colors[color].green, line.colors > [color].blue)) > ? ? ? ? ? ? ? ? x += 1 > ? ? ? ? ? ? x = 0 > ? ? ? ? ? ? y += 1 > > May be replaced with something like: > > for x, color in enumerate(line.colors): > ? ? canvas.create_line(x, y, x+1, y, fill="#%02x%02x%02x" % > (color.red, color.green, color.blue)) > > And maybe a RGBTriple may be replaced with an immutable namedtuple. > Using nested classes may be overkill for this program. > > Use the Python profiler and profile your code with a real image, and > show us/me the profiler results, so I can give you some suggestions to > speed up your code. > > Bye, > bearophile Hello bearophile, Thank you and Terry for your answers. Here is the new code using your changes http://pastebin.com/m6dfe619d And here is the profiler http://pastebin.com/m74d282b8 Best Regards Jayson Reis From aleksandar27 at brisiovonet.hr Mon Feb 16 18:09:50 2009 From: aleksandar27 at brisiovonet.hr (alejandro) Date: Tue, 17 Feb 2009 00:09:50 +0100 Subject: wxPython and Croatian characters References: <08c279c8-7934-4dff-b657-73dc12e3dfa3@o36g2000yqh.googlegroups.com> <14f11397-7db3-4cf2-9d19-5038ef86dc3b@o40g2000prn.googlegroups.com> Message-ID: Provjeri da si nisi stavio ansii kada si instalirao wx.python. Mozes probat ubacit iznad svega u fajlu komentar u kojem pise da je fajl u UTF-8 i onda bi ti trebalo sljakat. Nadem sutra pa ti posaljem From bearophileHUGS at lycos.com Mon Feb 16 18:41:37 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Mon, 16 Feb 2009 15:41:37 -0800 (PST) Subject: Speedup Bitmap Parser References: <58aed622-cf81-4747-ac54-86badef1c8dc@s20g2000yqh.googlegroups.com> Message-ID: Jayson Santos: > Here is the new code using your changeshttp://pastebin.com/m6dfe619d > And here is the profilerhttp://pastebin.com/m74d282b8 I have suggested you to profile the program mostly for pedagogical purposes, it's often a good thing to do if you want to speed up a program. But now it's your job to read the output of the profiler and try to find where the performance problems are. The profiler output will be simpler for you to read if you sort lines according to something better than method name (something like the time used by functions sounds better) and you tell the profiler to show only the first few lines. But a profiler isn't enough, you also need to use the brain. Your code looks a bit too much OOP :-) So in Java your code may run fast enough, but in Python it may be too much slow. The suggestions by Terry are good if you want to speed up your code signifiantly. Creating a very large amount of objects inside inner loops a slow thing in Java too, not just in Python. Generally to create an object you need to allocate memory. Try to write your program (s) avoiding all or most memory allocations inside the inner loops, and you will see a big improvement in running speed. Bye, bearophile From santosdosreis at gmail.com Mon Feb 16 19:13:13 2009 From: santosdosreis at gmail.com (Jayson Santos) Date: Mon, 16 Feb 2009 16:13:13 -0800 (PST) Subject: Speedup Bitmap Parser References: <58aed622-cf81-4747-ac54-86badef1c8dc@s20g2000yqh.googlegroups.com> Message-ID: <4c467175-092f-423d-8c0c-cdbffc8579c4@c12g2000yqj.googlegroups.com> On 16 fev, 20:41, bearophileH... at lycos.com wrote: > Jayson Santos: > > > Here is the new code using your changeshttp://pastebin.com/m6dfe619d > > And here is the profilerhttp://pastebin.com/m74d282b8 > > I have suggested you to profile the program mostly for pedagogical > purposes, it's often a good thing to do if you want to speed up a > program. But now it's your job to read the output of the profiler and > try to find where the performance problems are. The profiler output > will be simpler for you to read if you sort lines according to > something better than method name (something like the time used by > functions sounds better) and you tell the profiler to show only the > first few lines. > > But a profiler isn't enough, you also need to use the brain. Your code > looks a bit too much OOP :-) So in Java your code may run fast enough, > but in Python it may be too much slow. > The suggestions by Terry are good if you want to speed up your code > signifiantly. Creating a very large amount of objects inside inner > loops a slow thing in Java too, not just in Python. Generally to > create an object you need to allocate memory. Try to write your program > (s) avoiding all or most memory allocations inside the inner loops, > and you will see a big improvement in running speed. > > Bye, > bearophile Hello bearophile, Thank you for all, I'm reviewing all my code. Do I need use some patters or others progamming conventions ? I tried PIL and PyGame source however they are in C and I can't understand read and draw functions. Do you know a python-only image library ? Best Regards Jayson From denis.kasak at gmail.com Mon Feb 16 19:26:04 2009 From: denis.kasak at gmail.com (Denis Kasak) Date: Mon, 16 Feb 2009 16:26:04 -0800 (PST) Subject: time.strptime() and time.strftime() reciprocity References: Message-ID: On Mon, Feb 16, 2009 at 11:57 PM, Greg Krohn wrote: > ActivePython 2.6.1.1 (ActiveState Software Inc.) based on > Python 2.6.1 (r261:67515, Dec 5 2008, 13:58:38) [MSC v.1500 32 bit (Intel)] > on > win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> import time >>>> fmt = "%m/%d/%y %I:%M %p" >>>> print time.strptime(fmt, time.strftime(fmt)) > Traceback (most recent call last): > File "", line 1, in > File "C:\Python26\lib\_strptime.py", line 454, in _strptime_time > return _strptime(data_string, format)[0] > File "C:\Python26\lib\_strptime.py", line 325, in _strptime > (data_string, format)) > ValueError: time data '%m/%d/%y %I:%M %p' does not match format '02/16/09 > 04:52 > PM' > > So, yeah, that seems weird to me. Does anyone get similar results, know why > this is happening, and/or how to fix it? It's actually pretty trivial to fix, which you would have also known if you had read the message of the exception more carefully. :P You passed the arguments for strptime() the wrong way around. Just pass them in reverse and your problem will be fixed. -- Denis Kasak From noama at answers.com Mon Feb 16 19:41:26 2009 From: noama at answers.com (Noam Aigerman) Date: Tue, 17 Feb 2009 02:41:26 +0200 Subject: Referencing resources from python Message-ID: <749CACF29BDFB64E9F80189ECD77868804E87711@jermail1.atomant.net> Hi, What is the best way to reference a non-python file's path from inside python ? Until now, I (stupidly) had such lines as: theFile=open('../somefile.txt') in my python files. Now I moved my python files to another dir, and all those relative filenames broke. On the other hand, the solution of writing the full path of each resource isn't welcome either, as we're working from a SVN repository and we sometimes checkout to different dir's. I am sure there is a third way which didn't occur to me... What do you recommend? Thanks, Noam -------------- next part -------------- An HTML attachment was scrubbed... URL: From kentandkat at sbcglobal.net Mon Feb 16 19:46:04 2009 From: kentandkat at sbcglobal.net (kentandkat at sbcglobal.net) Date: Mon, 16 Feb 2009 18:46:04 -0600 Subject: tkinter in python30 Message-ID: Does anyone know what happened to tkinter in Python3? There is a tkinter folder in the Lib folder, but there is no Tkinter.py that I can find. Both "from Tkinter import *" and "from _tkinter import *" result in "no such module" error messages. What gives? Kent From bearophileHUGS at lycos.com Mon Feb 16 19:47:08 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Mon, 16 Feb 2009 16:47:08 -0800 (PST) Subject: Speedup Bitmap Parser References: <58aed622-cf81-4747-ac54-86badef1c8dc@s20g2000yqh.googlegroups.com> <4c467175-092f-423d-8c0c-cdbffc8579c4@c12g2000yqj.googlegroups.com> Message-ID: <12765e3f-a324-4621-b110-b40bd57acff0@s20g2000yqh.googlegroups.com> Jayson Santos: > Do I need use some patters or others progamming conventions ? That's a strong question... Knowing OOP well is important, and it's often a good way to program, etc. But... You may try to rewrite your code with functions only and no classes (well, you may need to use classes for the TK gui). Feel free to not follow this suggestion of mine. Even if you follow it, it will not damage your brain :-) Bye, bearophile From laplacian42 at gmail.com Mon Feb 16 20:07:56 2009 From: laplacian42 at gmail.com (laplacian42 at gmail.com) Date: Mon, 16 Feb 2009 17:07:56 -0800 (PST) Subject: tkinter in python30 References: Message-ID: <8666c553-3c17-4917-866f-0ba8638eab4f@j35g2000yqh.googlegroups.com> On Feb 16, 7:46?pm, kentand... at sbcglobal.net wrote: > Does anyone know what happened to tkinter in Python3? There is a tkinter > folder in the Lib folder, but there is no Tkinter.py that I can > find. Both "from Tkinter import *" and "from _tkinter import *" result > in "no such module" error messages. What gives? > > Kent http://docs.python.org/3.0/library/tkinter.html From tony at medioh.com Mon Feb 16 20:10:58 2009 From: tony at medioh.com (Tony Arcieri) Date: Mon, 16 Feb 2009 18:10:58 -0700 Subject: What are your favorite Python features? Message-ID: I'm creating a new language which borrows from Python (among other languages), and I'm curious what features of Python its users enjoy the most. I posted a similar thread on ruby-talk with a poll, but unfortunately my background in Python is much weaker than it is in Ruby. That said, here are some of the features of Python that I'm considering adding to my language (or are already there): - list comprehensions - lambdas - keyword arguments - built-in help - decorators - docstrings - obtaining references to methods with var.method - UCS4 internal string representation What are *your* favorite features of Python? I'm particularly interested in ones not included in this list. I'm not looking for "Python exclusive" features so much as features you use frequently which make your life easier which aren't particularly common among the more popular languages. P.S. If you're curious about my language you can read about it here: http://wiki.reia-lang.org and see some working examples of the syntax (which borrows heavily from Python) here: http://github.com/tarcieri/reia/tree/master/examples -- Tony Arcieri -------------- next part -------------- An HTML attachment was scrubbed... URL: From rhodri at wildebst.demon.co.uk Mon Feb 16 20:25:14 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 17 Feb 2009 01:25:14 -0000 Subject: Referencing resources from python In-Reply-To: <749CACF29BDFB64E9F80189ECD77868804E87711@jermail1.atomant.net> References: <749CACF29BDFB64E9F80189ECD77868804E87711@jermail1.atomant.net> Message-ID: On Tue, 17 Feb 2009 00:41:26 -0000, Noam Aigerman wrote: > Hi, > > What is the best way to reference a non-python file's path from inside > python ? > > Until now, I (stupidly) had such lines as: > > > theFile=open('../somefile.txt') > > > in my python files. Now I moved my python files to another dir, and all > those relative filenames broke. > > On the other hand, the solution of writing the full path of each > resource isn't welcome either, as we're working from a SVN repository > and we sometimes checkout to different dir's. I am sure there is a third > way which didn't occur to me... > > What do you recommend? It rather depends on what the files are. Some (clearly not this) will be best coded as absolute paths. Probably your best bet otherwise is to set an environment variable outside Python to point to the appropriate directory, and read it out of the os.environ dictionary. -- Rhodri James *-* Wildebeeste Herder to the Masses From clp2 at rebertia.com Mon Feb 16 20:29:31 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 16 Feb 2009 17:29:31 -0800 Subject: tkinter in python30 In-Reply-To: <8666c553-3c17-4917-866f-0ba8638eab4f@j35g2000yqh.googlegroups.com> References: <8666c553-3c17-4917-866f-0ba8638eab4f@j35g2000yqh.googlegroups.com> Message-ID: <50697b2c0902161729u784802d6xa08b94214434ccdf@mail.gmail.com> On Mon, Feb 16, 2009 at 5:07 PM, wrote: > On Feb 16, 7:46 pm, kentand... at sbcglobal.net wrote: >> Does anyone know what happened to tkinter in Python3? There is a tkinter >> folder in the Lib folder, but there is no Tkinter.py that I can >> find. Both "from Tkinter import *" and "from _tkinter import *" result >> in "no such module" error messages. What gives? >> >> Kent > > http://docs.python.org/3.0/library/tkinter.html Or IOW, they fixed the capitalization of its name to bring it in line w/ PEP8, so it's now tkinter (with a lowercase t) rather than Tkinter. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From benjamin at python.org Mon Feb 16 20:29:37 2009 From: benjamin at python.org (Benjamin Peterson) Date: Mon, 16 Feb 2009 19:29:37 -0600 Subject: [Python-Dev] To 3.0.2 or not to 3.0.2? In-Reply-To: References: <319e029f0902161108o5bb3506fq529525d35d0f35fe@mail.gmail.com> Message-ID: <1afaf6160902161729x6c21679akdfb4998692108b67@mail.gmail.com> On Mon, Feb 16, 2009 at 5:50 PM, Guido van Rossum wrote: > Can you explain the difficulty with porting setuptools in more detail? Basically setuptools invokes a functions in distutils that was still using cmp(). (See the latest messages in issue #1717 for all the details.) -- Regards, Benjamin From hellyj at ucsd.edu Mon Feb 16 20:35:41 2009 From: hellyj at ucsd.edu (Helly John J.) Date: Mon, 16 Feb 2009 17:35:41 -0800 Subject: Problems with OS X 10.5.6 and Python 2.5 and GDAL 1.6 Message-ID: <60437775-ED63-469B-A2CC-913B0E77BC1E@ucsd.edu> Hi. I'm a newbie to python and am running: OS X 10.5.6 Python 2.5.4 and have run easy_install for gdal like this: /Library/Python/2.5/site-packages>sudo easy_install GDAL Password: Searching for GDAL Best match: GDAL 1.6.0 Processing GDAL-1.6.0-py2.5-macosx-10.5-i386.egg GDAL 1.6.0 is already the active version in easy-install.pth Using /Library/Python/2.5/site-packages/GDAL-1.6.0-py2.5-macosx-10.5- i386.egg Processing dependencies for GDAL Finished processing dependencies for GDAL However, when I run python and try to import gdal, this is what happens: Python 2.5.4 (r254:67917, Dec 23 2008, 14:57:27) [GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import gdal Traceback (most recent call last): File "", line 1, in ImportError: No module named gdal >>> Clearly, it's not being found but I don't understand how to debug this any further. I have the *.egg in the site-packages directory but don't understand if there is something else I have to do to make it usable. Any help would be much appreciated. Cheers. -------------- John Helly, University of California, San Diego San Diego Supercomputer Center, Mail Code 0527 Scripps Institution of Oceanography, Climate, Atmospheric Science, and Physical Oceanography, Mail Code 0224 9500 Gilman Dr., La Jolla CA 92093 +01 760 840 8660 mobile / stonesteps (Skype) / stonesteps7 (iChat) / URL (http://www.sdsc.edu/~hellyj) -------------- next part -------------- An HTML attachment was scrubbed... URL: From mamahitasela at yahoo.com Mon Feb 16 20:53:11 2009 From: mamahitasela at yahoo.com (Mamahita Sela) Date: Mon, 16 Feb 2009 17:53:11 -0800 (PST) Subject: Threads in PyGTK: keep typing while ping-ing In-Reply-To: <9289e298-a123-47e9-855a-3df71d92e078@l1g2000yqj.googlegroups.com> Message-ID: <983541.54614.qm@web46205.mail.sp1.yahoo.com> Dear FB, > As you have been already told, join() blocks until the > thread is > terminated. and you should avoid that. > A simple fix could by add a timeout to t.join, doing > something like : > t.join(JOIN_TIMEOUT); > if not t.isAlive(): > print t.result > Thanks for your great sample. And, thank you for your tips on speedup the ping stuff. However, i still have problem when adding timeout to join(). - It works, but only print out thread result that is not alive, as we put in the code. So, i never get result from unsuccessful ping action, which might take more time than timeout specified. - I still have little delay in GUI. Is it possible to make it smooth in GUI operation? When i put more timeout (say: 0.5 from 0.2), i will have to wait longer. PS: thanks for pointing out inefficient ping action :) I will follow the tips. But, another time I might need to do something else, like downloading files, or checking for serial devices. So, this thread thing, imho, is very important. Any help would be very appreciated. M. From sjmachin at lexicon.net Mon Feb 16 21:27:16 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 16 Feb 2009 18:27:16 -0800 (PST) Subject: flexible find and replace ? References: <18d1b669-7a79-4295-a1e2-4693d361d0af@v13g2000yqm.googlegroups.com> Message-ID: <1903b4e6-0ea1-4e34-a6af-2d69b6d75a72@i20g2000prf.googlegroups.com> On Feb 17, 7:10?am, OdarR wrote: > Hi guys, > > how would you do a clever find and replace, where the value replacing > the tag > is changing on each occurence ? > > ".......TAG............TAG................TAG..........TAG....." > > is replaced by this : > > ".......REPL01............REPL02................REPL03..........REPL04..." > > A better and clever method than this snippet should exist I hope : > > counter = 1 > while 'TAG' in mystring: > ? ? mystring=mystring.replace('TAG', 'REPL'+str(counter), 1) > ? ? counter+=1 > ? ? ... > > (the find is always re-starting at the string beginning, this is not > efficient. > > any ideas ? thanks, C:\junk>type fancyrepl.py def fancyrepl(tag, replfunc, input_string): count = 0 pieces = [] pos = 0 taglen = len(tag) while 1: try: newpos = input_string.index(tag, pos) except ValueError: pieces.append(input_string[pos:]) return ''.join(pieces) pieces.append(input_string[pos:newpos]) count += 1 pieces.append(replfunc(count)) pos = newpos + taglen tests = [ '', 'XXX', 'XXXXXX', 'abcdeXXX', 'XXXfghij', 'abcdeXXXfghij', 'abcdeXXXfghijXXXpqrst', ] for test in tests: print ' <', repr(test) result = fancyrepl('XXX', lambda n: 'SUB%d' % n, test) print ' >', repr(result) C:\junk>fancyrepl.py < '' > '' < 'XXX' > 'SUB1' < 'XXXXXX' > 'SUB1SUB2' < 'abcdeXXX' > 'abcdeSUB1' < 'XXXfghij' > 'SUB1fghij' < 'abcdeXXXfghij' > 'abcdeSUB1fghij' < 'abcdeXXXfghijXXXpqrst' > 'abcdeSUB1fghijSUB2pqrst' HTH, John From ironfroggy at gmail.com Mon Feb 16 21:29:20 2009 From: ironfroggy at gmail.com (Calvin Spealman) Date: Mon, 16 Feb 2009 21:29:20 -0500 Subject: [Python-Dev] To 3.0.2 or not to 3.0.2? In-Reply-To: <319e029f0902161108o5bb3506fq529525d35d0f35fe@mail.gmail.com> References: <319e029f0902161108o5bb3506fq529525d35d0f35fe@mail.gmail.com> Message-ID: <76fd5acf0902161829jd8966c1wc4eb0f9295948590@mail.gmail.com> FWIW; I think a 3.0.2 would be useful socially (even volunteer projects have marketting issues to consider). It says "we are committed to making 3.x work", while the quick jump to 3.1 with only a limited minor fix release to 3.0 says "we stumbled into this and have to just brush this under the rug. But we got it right this time! I hope.." On Feb 16, 2009 2:08 PM, "Lennart Regebro" wrote: I discovered some remaining cmp() in 3.0.1, 38 minutes after Benjamin fixed them. :) Unfortunately, that means porting setuptools to 3.0.1 will be a bit difficult. So my question is: Will there be a 3.0.2 with those fixes, or should I add workaround code for 3.0.1? -- Lennart Regebro: Pythonista, Barista, Notsotrista. http://regebro.wordpress.com/ +33 661 58 14 64 _______________________________________________ Python-Dev mailing list Python-Dev at python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/ironfroggy%40gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From odeits at gmail.com Mon Feb 16 22:04:38 2009 From: odeits at gmail.com (odeits) Date: Mon, 16 Feb 2009 19:04:38 -0800 (PST) Subject: Changing the Image on a button References: <59253b2f-c90d-4308-835d-e81a2e602127@p23g2000prp.googlegroups.com> Message-ID: On Feb 16, 8:40?am, John Posner wrote: > ?>> from Tkinter import * > ?>> > ?>> def do(): > ?>> ? ? btn.configure(image = None) > ?>> > ?>> root = Tk() > ?>> img1 = PhotoImage(file="bacon.gif") > ?>> > ?>> btn = Button(image = img1, command = do, text = "hello" ) > ?>> btn.img = img1 > ?>> btn.pack() > ?>> root.mainloop() > ?>> > > Try this change: > > ? from: btn.configure(image = None) > ? ? to: img1.blank() > > -John > > E-mail message checked by Spyware Doctor (6.0.0.386) > Database version: 5.11770http://www.pctools.com/en/spyware-doctor-antivirus/ This does in fact clear the image out, however it isn't causing the text to display... Do i have have to create a new button and swap it out? From aahz at pythoncraft.com Mon Feb 16 22:35:02 2009 From: aahz at pythoncraft.com (Aahz) Date: 16 Feb 2009 19:35:02 -0800 Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <977bad202990de5797c2efcf8d50ed81.squirrel@localhost> Message-ID: In article , Hendrik van Rooyen wrote: > >Occam was the language that should have won the marketing prize, but >didn't. It wasn't simple enough. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From bignose+hates-spam at benfinney.id.au Mon Feb 16 22:42:17 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Tue, 17 Feb 2009 14:42:17 +1100 Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <977bad202990de5797c2efcf8d50ed81.squirrel@localhost> Message-ID: <87fxidohk6.fsf@benfinney.id.au> aahz at pythoncraft.com (Aahz) writes: > In article , > Hendrik van Rooyen wrote: > >Occam was the language that should have won the marketing prize, > >but didn't. > > It wasn't simple enough. *bdom-tsssh* -- \ ?I guess we were all guilty, in a way. We all shot him, we all | `\ skinned him, and we all got a complimentary bumper sticker that | _o__) said, ?I helped skin Bob.?? ?Jack Handey | Ben Finney From gnewsg at gmail.com Mon Feb 16 23:18:15 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Mon, 16 Feb 2009 20:18:15 -0800 (PST) Subject: How to verify whether a process got hanged or still alive. References: Message-ID: <0f13a2e0-8aa9-46c8-bedf-023445fbe6c2@x9g2000yqk.googlegroups.com> On 16 Gen, 00:04, neel wrote: > Hi There, > > I want to check the health of IEprocessusing python. I am running an > application on IE. I have to verify that the application is not > crashing the IE. Is there any module which can help me in getting theprocessstatus? > > Thanks, > Neel By process status you mean knowing whether the process is running, sleeping has been suspended, [...]? Hopefully this should be implemented in psutil soon: http://code.google.com/p/psutil --- Giampaolo http://code.google.com/p/pyftpdlib From michele.simionato at gmail.com Mon Feb 16 23:53:39 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Mon, 16 Feb 2009 20:53:39 -0800 (PST) Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> Message-ID: On Feb 16, 10:20?pm, rushen... at gmail.com wrote: > Hi again > > OpenERP and ERP5 was written in python as i know. I really wonder how > they do this without threads. I want to see a real time graph at the > same time while i am working on the same screen. What is the secret? > > Thanks > Rushen Here is an example of using multiprocessing (which is included in Python 2.6 and easy_installable in older Python versions) to print a spin bar while a computation is running: import sys, time import multiprocessing DELAY = 0.1 DISPLAY = [ '|', '/', '-', '\\' ] def spinner_func(before='', after=''): write, flush = sys.stdout.write, sys.stdout.flush pos = -1 while True: pos = (pos + 1) % len(DISPLAY) msg = before + DISPLAY[pos] + after write(msg); flush() write('\x08' * len(msg)) time.sleep(DELAY) def long_computation(): # emulate a long computation time.sleep(3) if __name__ == '__main__': spinner = multiprocessing.Process( None, spinner_func, args=('Please wait ... ', '')) spinner.start() try: long_computation() print 'Computation done' finally: spinner.terminate() From peter at www.pjb.com.au Tue Feb 17 00:04:23 2009 From: peter at www.pjb.com.au (Peter Billam) Date: 17 Feb 2009 05:04:23 GMT Subject: printing bytes to stdout in Py3 Message-ID: Greetings. (Newbie warning as usual) In Python3, sys.stdout is a io.TextIOWrapper object; but I want to output bytes (e.g. muscript -midi t > t.mid ) and they're coming out stringified :-( How can I either change the encoding on sys.stdout, or close sys.stdout and reopen it in 'b' mode, or dup(fd) it first, or whatever the right thing to do is ? Regards, Peter -- Peter Billam www.pjb.com.au www.pjb.com.au/comp/contact.html From peter at www.pjb.com.au Tue Feb 17 00:15:09 2009 From: peter at www.pjb.com.au (Peter Billam) Date: 17 Feb 2009 05:15:09 GMT Subject: Module to read/write MIDI ? References: Message-ID: On 2009-02-16, Tim Wintle wrote: >> I had my first look around pypi.python.org/pypi yesterday and didn't >> see anything. Is there a MIDI-module for Python ? If not, I'll >> email Sean to ask if he'd mind me translating his module into Python3... > > > > This is the only project I have seen that aims to do that - I haven't > actually used it, and there might be others out there (I believe pygame > supports midi-output). That looks like it should do the job :-) I can't actually import MidiOutFile successfully from Python3.0.1 yet, but that must be a Py2 v. Py3 issue. Might have to investigate 2to3... Thanks, Peter -- Peter Billam www.pjb.com.au www.pjb.com.au/comp/contact.html From xi11west at gmail.com Tue Feb 17 00:21:16 2009 From: xi11west at gmail.com (Yuanxin Xi) Date: Mon, 16 Feb 2009 23:21:16 -0600 Subject: memory recycling/garbage collecting problem Message-ID: <57681bf10902162121y4aa9b40eue7d6560336468500@mail.gmail.com> I'm having some problems with the memory recycling/garbage collecting of the following testing code: >>> a=[str(i) for i in xrange(10000000)] This takes 635m/552m/2044 memory (VIRT/RES/SHR) >>> b={} >>> for i in xrange(10000000): ... b[str(i)]=i Then the memory usage increased to 1726m/1.6g/2048 >>> del b I expect the memory usage drop to the ammount before b was created(635m/552m/2044), but it's actually 1341m/1.2g/2048 Could anyone please explain why this happens? It seems some memory are not freed. I'm running into problems with this as my program is very memory cosuming and need to frequently free some object to reuse the memory. What is the best way to free the memory of b completely (i.e. back to the status as b was created)? I'm using Python 2.5.2 Thanks. Yuanxin From clp2 at rebertia.com Tue Feb 17 00:31:25 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 16 Feb 2009 21:31:25 -0800 Subject: memory recycling/garbage collecting problem In-Reply-To: <57681bf10902162121y4aa9b40eue7d6560336468500@mail.gmail.com> References: <57681bf10902162121y4aa9b40eue7d6560336468500@mail.gmail.com> Message-ID: <50697b2c0902162131j2d6790pf798bc9cdda871eb@mail.gmail.com> On Mon, Feb 16, 2009 at 9:21 PM, Yuanxin Xi wrote: > I'm having some problems with the memory recycling/garbage collecting > of the following testing code: > >>>> a=[str(i) for i in xrange(10000000)] > This takes 635m/552m/2044 memory (VIRT/RES/SHR) > >>>> b={} >>>> for i in xrange(10000000): > ... b[str(i)]=i > > Then the memory usage increased to 1726m/1.6g/2048 > >>>> del b > I expect the memory usage drop to the ammount before b was > created(635m/552m/2044), but it's actually 1341m/1.2g/2048 > > Could anyone please explain why this happens? It seems some memory > are not freed. I'm running into problems with this as my program is > very memory cosuming and need to frequently free some object to reuse > the memory. What is the best way to free the memory of b completely > (i.e. back to the status as b was created)? I'm using Python 2.5.2 My understanding is that for efficiency purposes Python hangs on to the extra memory even after the object has been GC-ed and doesn't give it back to the OS right away. This shouldn't matter to your program though, as the "extra" memory will still be available for its use. And assuming you're using CPython and a/b isn't referred to by anything else, I believe they should be GC-ed immediately by the refcount system after the 'del' s executed. So, in theory you shouldn't need to worry about any of this, unless your example is not accurate and you're dealing with cyclical references or C objects or something. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From sambit2005 at gmail.com Tue Feb 17 00:44:51 2009 From: sambit2005 at gmail.com (Sambit Samal) Date: Tue, 17 Feb 2009 18:44:51 +1300 Subject: Need an application sends from paricular port In-Reply-To: <9e680b420902112148r75abe35emb629d2d9ddb33b9c@mail.gmail.com> References: <9e680b420902112148r75abe35emb629d2d9ddb33b9c@mail.gmail.com> Message-ID: <9e680b420902162144o69e86806wd80383579e21d333@mail.gmail.com> Hi > > I am new to Python world > > I need a python script , which binds at a user defind port & sends to > other enity , which waits at particular port. > The other enity will respond & Python script should receive that at the > defined port > > The communication will happen over UDP > > e.g > > *Python Appl* > > IP: 10.116.78.90 > Port : 3000 > > > *Other Enity* : > > IP: 10.116.98.87 > Port : 3010 > > > Pyhon Appl ------------>UDP ----> Other Enity > <-------------------------- > > > Please help > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From matzke at berkeley.edu Tue Feb 17 01:15:40 2009 From: matzke at berkeley.edu (Nick Matzke) Date: Mon, 16 Feb 2009 22:15:40 -0800 Subject: pythonic array subsetting Message-ID: <499A560C.4000209@berkeley.edu> Hi, So I've got a square floating point array that is about 1000 x 1000. I need to subset this array as efficiently as possible based on an ordered sublist of the list of rownames/colnames (they are the same, this is a symmetric array). e.g., if sublist is of length 500, and matches the rownames list at every other entry, I need to pull out a 500x500 array holding every other row & column in the parent array. I have to do this hundreds of times, so speed would be useful. Cheers! Nick -- ==================================================== Nicholas J. Matzke Ph.D. student, Graduate Student Researcher Huelsenbeck Lab Center for Theoretical Evolutionary Genomics 4151 VLSB (Valley Life Sciences Building) Department of Integrative Biology University of California, Berkeley Lab websites: http://ib.berkeley.edu/people/lab_detail.php?lab=54 http://fisher.berkeley.edu/cteg/hlab.html Dept. personal page: http://ib.berkeley.edu/people/students/person_detail.php?person=370 Lab personal page: http://fisher.berkeley.edu/cteg/members/matzke.html Lab phone: 510-643-6299 Dept. fax: 510-643-6264 Cell phone: 510-301-0179 Email: matzke at berkeley.edu Mailing address: Department of Integrative Biology 3060 VLSB #3140 Berkeley, CA 94720-3140 ----------------------------------------------------- "[W]hen people thought the earth was flat, they were wrong. When people thought the earth was spherical, they were wrong. But if you think that thinking the earth is spherical is just as wrong as thinking the earth is flat, then your view is wronger than both of them put together." Isaac Asimov (1989). "The Relativity of Wrong." The Skeptical Inquirer, 14(1), 35-44. Fall 1989. http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm ==================================================== From pythonnutter at gmail.com Tue Feb 17 01:21:03 2009 From: pythonnutter at gmail.com (Python Nutter) Date: Tue, 17 Feb 2009 17:21:03 +1100 Subject: Found a very nice, small, cross-platform GUI toolkit for Python. In-Reply-To: <66885dbe-72cd-46da-b59e-90e7f2dcf7da@m42g2000yqb.googlegroups.com> References: <4a912328-2d60-4380-b440-8d4d94f79662@v19g2000yqn.googlegroups.com> <66885dbe-72cd-46da-b59e-90e7f2dcf7da@m42g2000yqb.googlegroups.com> Message-ID: > Note: spelling is "OcempGUI". Also, since google broke some of the > links, > here's that main link again: Thats my bad or more to the point my iPhone bad, typing fast with spellcheck changes words to real dictionary words. > Well, to be fair, SDL is pretty commonly-used software and they offer > binary downloads for Mac OS X and MS Windows. Pygame seems to provide > the same. So, installation should be a breeze. Not on Mac. To get SDL, PyObjC, PyGame and other dependencies installed on the platform you are talking on downloading and installing close to 50MB+ of packages before you get to the point where you install the OcempGUI package. Thats a lot to ask of a user just to run my one program on their system. If it was just myself and I wanted to go through the process for educational/self-benefit I wouldn't mind. But TkInter is already installed (0 dependencies) and on every Mac out there so when I said 87Kbytes for a widget set that looks rather Mac like I was saying compare 87Kbytes to 50+Megabytes to get a GUI for my python application. Along the same lines on my Linux boxes, GDK+/KDE are normally already installed, nothing for the entire user base to install additional or very little (additional) dependencies to install to get a wxWidget or Qt interface going on those systems. Python wrappers are small but the "additional" dependency installs above and beyond the base system is what I am pointing at as killing off any interest in OcempGUI. I also have this sneaking suspicion that the BDFL is secretly on the sidelines waiting for the Tk tile theming engine to mature as if it does and becomes standard in Python distributions I would say the justification for learning wx and qt would be diminished by an unknown quantity. > What? Qt and wX are *huge* compared to OcempGUI. > From paddy3118 at googlemail.com Tue Feb 17 01:27:15 2009 From: paddy3118 at googlemail.com (Paddy) Date: Mon, 16 Feb 2009 22:27:15 -0800 (PST) Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> Message-ID: <7941293b-8423-42f9-8290-c1ddd7b17bc3@j38g2000yqa.googlegroups.com> On Feb 16, 9:34?am, rushen... at gmail.com wrote: > Hi everybody, > I am an engineer. I am trying to improve my software development > abilities. I have started programming with ruby. I like it very much > but i want to add something more. According to my previous research i > have designed a learning path for myself. It's like something below. > ? ? ? 1. Ruby (Mastering as much as possible) > ? ? ? 2. Python (Mastering as much as possible) > ? ? ? 3. Basic C++ or Basic Java > And the story begins here. As i search on the net, ?I have found that > because of the natural characteristics of python such as GIL, we are > not able to write multi threaded programs. You are likely to find a lot of 'tick-list' type of comparison data on the web that either needs a lot of knowledge to interpret, or is misleading/wrong or all three! Their are several versions of Python out their such as Ironpython, Stackless Python, Jython as well as CPython - the main Python release. They have different threading capabilities, but compilers of feature comparison tick-lists tend to just stick to what CPython can do. As an aside; if you were thinking of using threading for performance reasons, then its best to first think of improving your general ability to explore different algorithms. A change to an algorithm often has the most impact on the performance of code. A better single threaded, single process algorithm can offer better performaance than throwing threadds or multiple processes alone when using a poor underlying algorithm. I was just exploring different ways of solving a problem on my blog: http://paddy3118.blogspot.com/2009/02/comparison-of-python-solutions-to.html (But no parallel solutions were attempted). Have fun programming! - Paddy. From paddy3118 at googlemail.com Tue Feb 17 01:34:49 2009 From: paddy3118 at googlemail.com (Paddy) Date: Mon, 16 Feb 2009 22:34:49 -0800 (PST) Subject: Pythonic way to determine if a string is a number References: Message-ID: On Feb 15, 5:46?pm, pyt... at bdurham.com wrote: > What's the Pythonic way to determine if a string is a number? By > number I mean a valid integer or float. > > I searched the string and cMath libraries for a similar function > without success. I can think of at least 3 or 4 ways to build my > own function. > > Here's what I came up with as a proof-of-concept. Are there > 'better' ways to perform this type of test? > > Thanks, > Malcolm > > > def isnumber( input ): > ? ? try: > ? ? ? ? if '.' in input: > ? ? ? ? ? ? num = float( input ) > ? ? ? ? else: > ? ? ? ? ? ? num = int( input ) > ? ? ? ? return True > > ? ? except ValueError: > ? ? ? ? return False > > if __name__ == '__main__': > ? ? tests = """ > ? ? ? ? 12 > ? ? ? ? -12 > ? ? ? ? -12.34 > ? ? ? ? .0 > ? ? ? ? . > ? ? ? ? 1 2 3 > ? ? ? ? 1 . 2 > ? ? ? ? just text > ? ? """ > > ? ? for test in tests.split( '\n' ): > ? ? ? ? print 'test (%0s), isnumber: %1s' % \ > ? ? ? ? ? ( test.strip(), isnumber( test ) ) > > Their is a good answer given on Rosetta Code here: http://www.rosettacode.org/wiki/IsNumeric#Python - Paddy. From laplacian42 at gmail.com Tue Feb 17 02:02:19 2009 From: laplacian42 at gmail.com (laplacian42 at gmail.com) Date: Mon, 16 Feb 2009 23:02:19 -0800 (PST) Subject: Found a very nice, small, cross-platform GUI toolkit for Python. References: <4a912328-2d60-4380-b440-8d4d94f79662@v19g2000yqn.googlegroups.com> <66885dbe-72cd-46da-b59e-90e7f2dcf7da@m42g2000yqb.googlegroups.com> Message-ID: On Feb 17, 1:21?am, Python Nutter wrote: > > Note: spelling is "OcempGUI". Also, since google broke some of the > > links, > > here's that main link again: > > Thats my bad or more to the point my iPhone bad, typing fast with > spellcheck changes words to real dictionary words. > > > Well, to be fair, SDL is pretty commonly-used software and they offer > > binary downloads for Mac OS X and MS Windows. Pygame seems to provide > > the same. So, installation should be a breeze. > > Not on Mac. To get SDL, PyObjC, PyGame and other dependencies > installed on the platform you are talking on downloading and > installing close to 50MB+ of packages before you get to the point > where you install the OcempGUI package. Funny you should mention this. I'd just been getting it installed on a Mac I have access to. Here's what it took: 1. Install a Python from python.org. Something about the Pygame installer not wanting to use the system Python. Also, it wants v2.5. Ok. (As an aside, that's about 19 MB.) This is a mpkg file in a dmg, so the install is trivial. 2. Now SDL. This one is just a drag-and-drop to your `/Library/ Frameworks` folder. Easy, but the user will have to look into the README to know what to do. (1 MB) 3. Now PyObjC. Another mpkg file. It's available at the pygame site. (6 MB) 4. Pygame. An mpkg in a zip file. (9 MB) 5. Whoops. Surprise. NumPy is required. mpkg in a dmg. (3 MB) 6. Finally, OcempGUI. This is a `sudo python setup.py install`. (4 MB) That's 42 MB all told, admin rights required, and the examples are running. Pretty neat. > Thats a lot to ask of a user [sigh] Probably. Unless maybe all the prereq's were gathered together with a script to run through and install them all one after another. > just to run my one program on their > system. Well, it will allow them to run *any* OcempGUI program thereafter, but I see your point. > If it was just myself and I wanted to go through the process > for educational/self-benefit I wouldn't mind. But TkInter is already installed (0 dependencies) and on every Mac out > there Just tried that. Didn't know it was all installed (Tcl/Tk too) and ready to go. Wow that's pretty darn convenient. > I also have this sneaking suspicion that the BDFL is secretly on the > sidelines waiting for the Tk tile theming engine to mature as if it > does and becomes standard in Python distributions I would say the > justification for learning wx and qt would be diminished by an unknown > quantity. > Aye. From bj_666 at gmx.net Tue Feb 17 02:26:28 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 17 Feb 2009 07:26:28 GMT Subject: memory recycling/garbage collecting problem References: Message-ID: <6vv754Flqs0mU1@mid.uni-berlin.de> On Mon, 16 Feb 2009 23:21:16 -0600, Yuanxin Xi wrote: > I'm having some problems with the memory recycling/garbage collecting of > the following testing code: > >>>> a=[str(i) for i in xrange(10000000)] > This takes 635m/552m/2044 memory (VIRT/RES/SHR) > >>>> b={} >>>> for i in xrange(10000000): > ... b[str(i)]=i > > Then the memory usage increased to 1726m/1.6g/2048 > >>>> del b > I expect the memory usage drop to the ammount before b was > created(635m/552m/2044), but it's actually 1341m/1.2g/2048 > > Could anyone please explain why this happens? It seems some memory are > not freed. It seems the memory is not given back to the operating system. This doesn't mean that it is not freed by Python and can't be used again by Python. Create the dictionary again and see if the memory usage rises again or if it stays stable. Ciao, Marc 'BlackJack' Rintsch From testisok at gmail.com Tue Feb 17 02:34:29 2009 From: testisok at gmail.com (testisok) Date: Mon, 16 Feb 2009 23:34:29 -0800 (PST) Subject: Thread control in thread pool for sending Message-ID: Hi, all: Here is a thread pool for sending as a client, all blocked at Semaphore. How can I choose these threads that is idle for some time and then send heartbeat messages to the server thru sockets of these threads? Thanks in advance. Best wishes From regebro at gmail.com Tue Feb 17 02:52:20 2009 From: regebro at gmail.com (Lennart Regebro) Date: Tue, 17 Feb 2009 08:52:20 +0100 Subject: [Python-Dev] To 3.0.2 or not to 3.0.2? In-Reply-To: References: <319e029f0902161108o5bb3506fq529525d35d0f35fe@mail.gmail.com> Message-ID: <319e029f0902162352l13da07b8r8b0aafba66e4e7a3@mail.gmail.com> On Tue, Feb 17, 2009 at 00:50, Guido van Rossum wrote: > Can you explain the difficulty with porting setuptools in more detail? Oh, it just exposes a bug in distutils. It probably means I'll have to make a test for python version, and if it is 3.0.1, monkey-patch distutils. I haven't really looked into if there is any other possibilities yet, I'm concentrating to make it run for 3.1 trunk first. -- Lennart Regebro: Pythonista, Barista, Notsotrista. http://regebro.wordpress.com/ +33 661 58 14 64 From grflanagan at gmail.com Tue Feb 17 03:17:41 2009 From: grflanagan at gmail.com (Gerard Flanagan) Date: Tue, 17 Feb 2009 08:17:41 +0000 Subject: flexible find and replace ? In-Reply-To: <18d1b669-7a79-4295-a1e2-4693d361d0af@v13g2000yqm.googlegroups.com> References: <18d1b669-7a79-4295-a1e2-4693d361d0af@v13g2000yqm.googlegroups.com> Message-ID: OdarR wrote: > Hi guys, > > how would you do a clever find and replace, where the value replacing > the tag > is changing on each occurence ? > > ".......TAG............TAG................TAG..........TAG....." > > is replaced by this : > > ".......REPL01............REPL02................REPL03..........REPL04..." > > > A better and clever method than this snippet should exist I hope : > > counter = 1 > while 'TAG' in mystring: > mystring=mystring.replace('TAG', 'REPL'+str(counter), 1) > counter+=1 > ... > > (the find is always re-starting at the string beginning, this is not > efficient. > > any ideas ? thanks, > The first thing that comes to mind is re.sub: import re def replace(s, patt, repls): def onmatch(m): onmatch.idx += 1 return repls[onmatch.idx] onmatch.idx = -1 return patt.sub(onmatch, s) test = """ abcTAG TAG asdTAGxyz """ REPLS = [ 'REPL1', 'REPL2', 'REPL3', ] print replace(test, re.compile('TAG'), REPLS) From duncan.booth at invalid.invalid Tue Feb 17 03:18:12 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 17 Feb 2009 08:18:12 GMT Subject: flexible find and replace ? References: <18d1b669-7a79-4295-a1e2-4693d361d0af@v13g2000yqm.googlegroups.com> <1903b4e6-0ea1-4e34-a6af-2d69b6d75a72@i20g2000prf.googlegroups.com> Message-ID: John Machin wrote: > def fancyrepl(tag, replfunc, input_string): > count = 0 > pieces = [] > pos = 0 > taglen = len(tag) > while 1: > try: > newpos = input_string.index(tag, pos) > except ValueError: > pieces.append(input_string[pos:]) > return ''.join(pieces) > pieces.append(input_string[pos:newpos]) > count += 1 > pieces.append(replfunc(count)) > pos = newpos + taglen > Or even: import re, itertools def fancyrepl(tag, replfunc, input_string): counter = itertools.count(1) return re.sub(re.escape(tag), lambda m: replfunc(counter.next()), input_string) which does exactly the same thing in rather less code. -- Duncan Booth http://kupuguy.blogspot.com From jldunn2000 at googlemail.com Tue Feb 17 03:21:38 2009 From: jldunn2000 at googlemail.com (loial) Date: Tue, 17 Feb 2009 00:21:38 -0800 (PST) Subject: Get file name from file handle Message-ID: Is there anyway, having been passed a file handle, to get the filename? I am assuming not, but thought I would ask From noprianto at gmail.com Tue Feb 17 03:28:13 2009 From: noprianto at gmail.com (Noprianto) Date: Tue, 17 Feb 2009 15:28:13 +0700 Subject: Get file name from file handle In-Reply-To: References: Message-ID: <8f0de1f0902170028r7d44da83p132e99a41dcbc68d@mail.gmail.com> On 2/17/09, loial wrote: > > Is there anyway, having been passed a file handle, to get the > filename? > > I am assuming not, but thought I would ask >>> a = open('/etc/passwd') >>> a.name '/etc/passwd' >>> Best regards, Nop -------------- next part -------------- An HTML attachment was scrubbed... URL: From castironpi at gmail.com Tue Feb 17 03:33:27 2009 From: castironpi at gmail.com (Aaron Brady) Date: Tue, 17 Feb 2009 00:33:27 -0800 (PST) Subject: memory recycling/garbage collecting problem References: Message-ID: On Feb 16, 11:21?pm, Yuanxin Xi wrote: > I'm having some problems with the memory recycling/garbage collecting > of the following testing code: > > >>> a=[str(i) for i in xrange(10000000)] > > This takes 635m/552m/2044 memory (VIRT/RES/SHR) > > >>> b={} > >>> for i in xrange(10000000): > > ... ? ? b[str(i)]=i > > Then the memory usage increased to 1726m/1.6g/2048 > > >>> del b > > I expect the memory usage drop to the ammount before b was > created(635m/552m/2044), but it's actually 1341m/1.2g/2048 snip 'gc.collect()' -- I believe, but I'm not the specialist in it. From gagsl-py2 at yahoo.com.ar Tue Feb 17 03:34:46 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 17 Feb 2009 06:34:46 -0200 Subject: Upgrading standard library module References: Message-ID: En Fri, 13 Feb 2009 20:17:35 -0200, Bryan escribi?: > On Feb 13, 1:52?pm, Jason Scheirer wrote: >> On Feb 13, 12:42?pm, Bryan wrote: >> >> > I have a Python v2.5.2 server running and I found some undesirable >> > behavior in the xmlrpclib module that is included with that version of >> > Python. ?The xmlrpclib version that is included with Python 2.6 >> > changes the behavior for the better. ?I nervous about upgrading my >> > Python install to 2.6 on this server because I remember reading in the >> > docs of a library I use that it targets the 2.5 branch. ?What is the >> > best way to only upgrade the xmlrpclib in my 2.5 install? >> What behavior, exactly, do you not like in xmlrpclib? Diffing the 2.5 >> and 2.6, only significant differences I see are checks for True/False >> as builtins left over from pre-2.4 and some datetime handling. > The xmlrpclib in my 2.5.2 install does not allow the marshaling of my > custom objects. It checks the type of my object, and if it isn't in a > hard-coded list of types, then a "Cannot marshal object of > type" exception message shows up. The version in my Windows 2.6 > install has a fall back case where if the type is not in the hard- > coded list, it simply calls Object.__dict__ to get a graph of the > object's values that can be marshaled into xmlrpc. > > I am using xmlrpc through Pylons. As a workaround, instead of > returning my custom objects in my xmlrpc server functions, I return > MyObject.__dict__ > > I also did not see anything in the revision log in the source file > about this change. It was rev.52790: http://svn.python.org/view?rev=52790&view=rev The tracker item has some background: http://bugs.python.org/issue1070046 -- Gabriel Genellina From clp2 at rebertia.com Tue Feb 17 03:40:29 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 17 Feb 2009 00:40:29 -0800 Subject: memory recycling/garbage collecting problem In-Reply-To: References: Message-ID: <50697b2c0902170040k2b2c211ew2a2ce3e4c5044c17@mail.gmail.com> On Tue, Feb 17, 2009 at 12:33 AM, Aaron Brady wrote: > On Feb 16, 11:21 pm, Yuanxin Xi wrote: >> I'm having some problems with the memory recycling/garbage collecting >> of the following testing code: >> >> >>> a=[str(i) for i in xrange(10000000)] >> >> This takes 635m/552m/2044 memory (VIRT/RES/SHR) >> >> >>> b={} >> >>> for i in xrange(10000000): >> >> ... b[str(i)]=i >> >> Then the memory usage increased to 1726m/1.6g/2048 >> >> >>> del b >> >> I expect the memory usage drop to the ammount before b was >> created(635m/552m/2044), but it's actually 1341m/1.2g/2048 > snip > > 'gc.collect()' -- I believe, but I'm not the specialist in it. If I understand correctly, that only effects objects that are part of a reference cycle and doesn't necessarily force the freed memory to be released to the OS. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From grflanagan at gmail.com Tue Feb 17 03:49:25 2009 From: grflanagan at gmail.com (Gerard Flanagan) Date: Tue, 17 Feb 2009 08:49:25 +0000 Subject: flexible find and replace ? In-Reply-To: References: <18d1b669-7a79-4295-a1e2-4693d361d0af@v13g2000yqm.googlegroups.com> Message-ID: Gerard Flanagan wrote: > > def replace(s, patt, repls): > def onmatch(m): > onmatch.idx += 1 > return repls[onmatch.idx] > onmatch.idx = -1 > return patt.sub(onmatch, s) > > test = """ > abcTAG TAG asdTAGxyz > """ > > REPLS = [ > 'REPL1', > 'REPL2', > 'REPL3', > ] > > print replace(test, re.compile('TAG'), REPLS) > > -- or better: import re def replace(s, patt, repls): repls = iter(repls) return patt.sub(lambda m: repls.next(), s) test = """ abcTAG TAG asdTAGxyz """ def repls(tag): i = 0 while True: i += 1 yield tag + str(i) print replace(test, re.compile('TAG'), repls('REPL')) From duncan.booth at invalid.invalid Tue Feb 17 03:55:54 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 17 Feb 2009 08:55:54 GMT Subject: Get file name from file handle References: Message-ID: loial wrote: > Is there anyway, having been passed a file handle, to get the > filename? > > I am assuming not, but thought I would ask > > If you mean a Python file object then file.name (but it may not exist on all file objects). If you mean a system file handle, then which filename would you like? On many filesystems the file exists independantly from the filenames, so a single file can have many names or none at all. On Linux you can use os.fstat() to get the inode number for the file but I think you would have to scan the relevant directories to find the names associated with the inode. -- Duncan Booth http://kupuguy.blogspot.com From mirko.dziadzka at gmail.com Tue Feb 17 04:03:29 2009 From: mirko.dziadzka at gmail.com (Mirko Dziadzka) Date: Tue, 17 Feb 2009 10:03:29 +0100 Subject: print string as raw string Message-ID: Hi all I'm trying to find a way to output strings in the raw-string format, e.g. print_as_raw_string(r"\.") should output r"\." instead of "\\." Is there a better way than writing your own print function? Some magic encoding? Mirko From tim.wintle at teamrubber.com Tue Feb 17 04:05:49 2009 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Tue, 17 Feb 2009 09:05:49 +0000 Subject: Speedup Bitmap Parser In-Reply-To: <12765e3f-a324-4621-b110-b40bd57acff0@s20g2000yqh.googlegroups.com> References: <58aed622-cf81-4747-ac54-86badef1c8dc@s20g2000yqh.googlegroups.com> <4c467175-092f-423d-8c0c-cdbffc8579c4@c12g2000yqj.googlegroups.com> <12765e3f-a324-4621-b110-b40bd57acff0@s20g2000yqh.googlegroups.com> Message-ID: <1234861549.6114.9.camel@tim-laptop> On Mon, 2009-02-16 at 16:47 -0800, bearophileHUGS at lycos.com wrote: > Jayson Santos: > > Do I need use some patters or others progamming conventions ? > > That's a strong question... > Knowing OOP well is important, and it's often a good way to program, > etc. But... You may try to rewrite your code with functions only and > no classes (well, you may need to use classes for the TK gui). > Feel free to not follow this suggestion of mine. Even if you follow > it, it will not damage your brain :-) I'd strongly agree with the above - object creation is overkill in inner-loops. Invoking functions and any kind of variable allocation is also going to slow it down. That's what bearophile's previous comment about accessing line.colors without the "." lookup by enumerating them was about. At the end of the day, image manipulation is often better left to C (or compiled extensions to python in Cython etc.) than done in Python - it's just too tough to do pointer-magic in Python. You may find that so much time is being spent by your application in the ".create_line" method that there's no other option - I'd highly recommend PIL though. Tim Wintle From bieffe62 at gmail.com Tue Feb 17 04:15:40 2009 From: bieffe62 at gmail.com (bieffe62 at gmail.com) Date: Tue, 17 Feb 2009 01:15:40 -0800 (PST) Subject: Get file name from file handle References: Message-ID: <9ccf2d4f-6c5e-49a0-b0c2-905f246e9cc9@r41g2000yqm.googlegroups.com> On Feb 17, 9:21?am, loial wrote: > Is there anyway, having been passed a file handle, to get the > filename? > > I am assuming not, but thought I would ask If by file handle you mean the object returned by 'file' and 'open' functions, it has a name attribute. If by file handle you mean the file descriptor, i.e. the integer used for low level I/O, then there is no way I know of. I believe that number is an index in an array of 'file descriptors' somewhere inside the C library ( below python interpreter level ), but I don't know if/how an user program can access it. Ciao ---- FB From mail at microcorp.co.za Tue Feb 17 04:18:36 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Tue, 17 Feb 2009 11:18:36 +0200 Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com><977bad202990de5797c2efcf8d50ed81.squirrel@localhost> Message-ID: <014201c990e2$fb49dba0$0d00a8c0@hendrik> "Aahz" wrote: > In article , > Hendrik van Rooyen wrote: > > > >Occam was the language that should have won the marketing prize, but > >didn't. > > It wasn't simple enough. I thought (at the time) that it was quite good at hiding some horrible complexities of communication between different processes on the same, and different processors. All done by the compiler, automagically. I think now that a hard look at the underlying techniques used then could add something to the debate referred to earlier - but there may be a barrier because the dataflow or systolic array type programming model is not one that is currently fashionable. - Hendrik From bearophileHUGS at lycos.com Tue Feb 17 04:27:04 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Tue, 17 Feb 2009 01:27:04 -0800 (PST) Subject: pythonic array subsetting References: Message-ID: <32c50024-2bb3-4fd4-bedb-c995e4ce97cb@f3g2000yqf.googlegroups.com> Nick Matzke: > I have to do this hundreds of times, so speed would be useful. Try to create a 2D array with NumPy, and then slice it. Note that slicing syntax has a "stride" too. Bye, bearophile From mail at microcorp.co.za Tue Feb 17 04:27:54 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Tue, 17 Feb 2009 11:27:54 +0200 Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com><977bad202990de5797c2efcf8d50ed81.squirrel@localhost> <87fxidohk6.fsf@benfinney.id.au> Message-ID: <014301c990e2$fbe0eb80$0d00a8c0@hendrik> "Ben Finney" wrote: aahz at pythoncraft.com (Aahz) writes: > In article , > Hendrik van Rooyen wrote: > >Occam was the language that should have won the marketing prize, > >but didn't. > > It wasn't simple enough. *bdom-tsssh* If Aahz was trolling, then he got me. I know about William of Occam, after whom the language was named, and his razor, but did not make the association, and answered seriously. If you play with razor blades, you get cut. :-) - Hendrik From gagsl-py2 at yahoo.com.ar Tue Feb 17 05:05:42 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 17 Feb 2009 08:05:42 -0200 Subject: Need an application sends from paricular port References: <9e680b420902112148r75abe35emb629d2d9ddb33b9c@mail.gmail.com> <9e680b420902162144o69e86806wd80383579e21d333@mail.gmail.com> Message-ID: En Tue, 17 Feb 2009 03:44:51 -0200, Sambit Samal escribi?: >> I am new to Python world >> >> I need a python script , which binds at a user defind port & sends to >> other enity , which waits at particular port. >> The other enity will respond & Python script should receive that at the >> defined port >> >> The communication will happen over UDP (I'm rather sure I replied to your first request, but I cannot find my own post anywhere, so I'll try again) See the SocketServer module: http://docs.python.org/library/socketserver.html -- you may want to use ForkingUDPServer or ThreadingUDPServer. There is a client/server example at the end. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Tue Feb 17 05:17:37 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 17 Feb 2009 08:17:37 -0200 Subject: printing bytes to stdout in Py3 References: Message-ID: En Tue, 17 Feb 2009 03:04:23 -0200, Peter Billam escribi?: > Greetings. (Newbie warning as usual) In Python3, sys.stdout is a > io.TextIOWrapper object; but I want to output bytes > (e.g. muscript -midi t > t.mid ) > and they're coming out stringified :-( How can I either change the > encoding on sys.stdout, or close sys.stdout and reopen it in 'b' > mode, or dup(fd) it first, or whatever the right thing to do is ? I cannot test this with Python 3 right now, but I think this should work (right at the start of your script): sys.stdout = os.fdopen(sys.stdout.fileno(), 'wb') -- Gabriel Genellina From tino at wildenhain.de Tue Feb 17 05:33:56 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Tue, 17 Feb 2009 11:33:56 +0100 Subject: print string as raw string In-Reply-To: References: Message-ID: <499A9294.2050505@wildenhain.de> Mirko Dziadzka wrote: > Hi all > > I'm trying to find a way to output strings in the raw-string format, e.g. > > print_as_raw_string(r"\.") should output r"\." instead of "\\." > > Is there a better way than writing your own print function? Some magic > encoding? Thats nonsense. print r"\." or in python3.0 print(r"\.") will just print: \. Regards Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From deets at nospam.web.de Tue Feb 17 05:39:48 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 17 Feb 2009 11:39:48 +0100 Subject: print string as raw string In-Reply-To: References: Message-ID: <6vvifkFm4k0vU1@mid.uni-berlin.de> Mirko Dziadzka schrieb: > Hi all > > I'm trying to find a way to output strings in the raw-string format, e.g. > > print_as_raw_string(r"\.") should output r"\." instead of "\\." > > Is there a better way than writing your own print function? Some magic > encoding? There is no need to do this. Rawstrings are only different wrt to their parsing, the resulting string is the exact same. r"\foo" == "\\foo" type(r"\foo") == type("\\foo") So there is no way to write something that distinguishes them. Can it be that you are fooled by the repr() of strings in the interpreter? >>> r"\foo" '\\foo' This is nothing to worry about, it's just the interpreter doing an implicit repr-call for the objects it displays. If instead you'd do >>> print r"\foo" \foo you get what you want. Diez From andrew at acooke.org Tue Feb 17 06:34:39 2009 From: andrew at acooke.org (andrew cooke) Date: Tue, 17 Feb 2009 08:34:39 -0300 (CLST) Subject: Will multithreading make python less popular? In-Reply-To: <014201c990e2$fb49dba0$0d00a8c0@hendrik> References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com><977bad202990de5797c2efcf8d50ed81.squirrel@localhost> <014201c990e2$fb49dba0$0d00a8c0@hendrik> Message-ID: why do you think that current work is ignorant of occam? occam itself was based on hoare's "communicating sequential processes" which is a classic of the field. the ideas behind occam are not unknown and it hasn't been forgotten (there are many libraries based on synchronous message passing; one for java called jcsp for example - http://www.cs.kent.ac.uk/projects/ofa/jcsp/ ; the "rendezvous model" (receiving tasks wait for messages) is used in ada). but really it did very little to hide the complexities of parallel computing - it's famous because it (and the transputer platform) was one of the first languages to take parallelism "seriously", not because it presented any kind of silver bullet (more generally, it was a pretty crude language, more suited to small embedded applications than large projects - it didn't even have dynamically sized arrays) there's a comment here http://lambda-the-ultimate.org/node/2437 that shows the limitations of occam: "I used Occam (the transputer implementation of CSP) very heavily in the 1980s and early 1990s, and eventually started referring to channels as "the return of the GOTO", since in any moderately complex application, you spent a lot of time wondering, "If I put bytes in *here*, who will they go to?" Addressable actors and/or tuple spaces both felt much more scalable (in the coding sense)." (disclaimer - i haven't used it personally. once i was asked to maintain an occam system, but somehow managed to dodge the responsibility) if you look at erlang, which is one of the more successful parallel languages at the moment, you'll see some similarity to occam (message passing is explicit), but shifting to asynchronous messages helps give a more robust system. andrew Hendrik van Rooyen wrote: > "Aahz" wrote: > > >> In article , >> Hendrik van Rooyen wrote: >> > >> >Occam was the language that should have won the marketing prize, but >> >didn't. >> >> It wasn't simple enough. > > I thought (at the time) that it was quite good at hiding some > horrible complexities of communication between different > processes on the same, and different processors. > > All done by the compiler, automagically. > > I think now that a hard look at the underlying techniques > used then could add something to the debate referred to > earlier - but there may be a barrier because the dataflow > or systolic array type programming model is not one > that is currently fashionable. > > - Hendrik > > > -- > http://mail.python.org/mailman/listinfo/python-list > > From bruno.42.desthuilliers at websiteburo.invalid Tue Feb 17 06:38:43 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 17 Feb 2009 12:38:43 +0100 Subject: Will multithreading make python less popular? In-Reply-To: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> Message-ID: <499aa1bb$0$29487$426a74cc@news.free.fr> rushenaly at gmail.com a ?crit : (snip) > And the story begins here. As i search on the net, I have found that > because of the natural characteristics of python such as GIL, we are > not able to write multi threaded programs. I'm surprised no one here corrected that point yet, so here we go: yes, Python does support multithreading. The fact that threads won't be executed concurrently on a multicore machine (due to the GIL) is a different problem (cf Andrew Cooke's answer on this - and his advice to study Erlang if you want to do concurrent programming). From mirko-usenet-200902 at gmail.com Tue Feb 17 06:54:01 2009 From: mirko-usenet-200902 at gmail.com (Mirko Dziadzka) Date: Tue, 17 Feb 2009 12:54:01 +0100 Subject: print string as raw string References: <6vvifkFm4k0vU1@mid.uni-berlin.de> Message-ID: Diez B. Roggisch wrote: >> I'm trying to find a way to output strings in the raw-string format, e.g. >> >> print_as_raw_string(r"\.") should output r"\." instead of "\\." >> >> Is there a better way than writing your own print function? Some magic >> encoding? > > There is no need to do this. Rawstrings are only different wrt to their > parsing, the resulting string is the exact same. I know. Maybe a little bit more eplaination from my site. I'm going to generate python source which contains lot of regex-strings and I want this code to be easy readable and editable. In fact, editing these regexes is the main reason for exporting them. So I would prefer the more compact and readable raw-string notation instead of the smantic equivalent string notation. So I'm going to write these couple of lines to convert a string in this raw-string format. Greetings Mirko -- "In C we had to code our own bugs. In C++ we can inherit them." From andrew at acooke.org Tue Feb 17 06:58:38 2009 From: andrew at acooke.org (andrew cooke) Date: Tue, 17 Feb 2009 08:58:38 -0300 (CLST) Subject: Will multithreading make python less popular? In-Reply-To: <499aa1bb$0$29487$426a74cc@news.free.fr> References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <499aa1bb$0$29487$426a74cc@news.free.fr> Message-ID: <860a74f95b30bd61dfa6240dc70bbf9e.squirrel@localhost> Bruno Desthuilliers wrote: > rushenaly at gmail.com a ?crit : > (snip) >> And the story begins here. As i search on the net, I have found that >> because of the natural characteristics of python such as GIL, we are >> not able to write multi threaded programs. > > I'm surprised no one here corrected that point yet, so here we go: yes, > Python does support multithreading. The fact that threads won't be > executed concurrently on a multicore machine (due to the GIL) is a > different problem (cf Andrew Cooke's answer on this - and his advice to > study Erlang if you want to do concurrent programming). ah, sorry, i noticed this last night in another comment from rushenaly, but forgot to say anything. in case it's still not clear: you can have threads even on a single core. this is done by "time slicing" - some cpu time is given to one thread, then to another. exactly who does the slicing can vary. in the case of a gui (which is what i was about to explain last night then got distracted) it's quite common for the gui library itself to do the scheduling of work. so even though the gui library uses a single thread, it can update several windows, handle user input, etc "in parallel". the next level is that the language itself does the scheduling - that's what is commonly called "threads". finally the operating system can share things out (and that's called processes). but these are all basically the same thing, can happen on a single core, and are not affected by the GIL (i have simplified above; threads can also be a service that the operating system provides to a language) andrew From mirko.dziadzka at gmail.com Tue Feb 17 07:03:16 2009 From: mirko.dziadzka at gmail.com (Mirko Dziadzka) Date: Tue, 17 Feb 2009 13:03:16 +0100 Subject: print string as raw string References: Message-ID: Mirko Dziadzka wrote: > Hi all > > I'm trying to find a way to output strings in the raw-string format, e.g. > > print_as_raw_string(r"\.") should output r"\." instead of "\\." Ok, lets make a better example: >>> re_list = {} >>> re_list['foo'] = r'\..*' >>> re_list['bar'] = r'.*bar.*' >>> print re_list {'foo': '\\..*', 'bar': '.*bar.*'} I would like to see a: {'foo': r'\..*', 'bar': '.*bar.*'} Greetings Mirko -- "Never attribute to malice what can be equally explained by stupidity." From steve at pearwood.info Tue Feb 17 07:09:50 2009 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 17 Feb 2009 23:09:50 +1100 Subject: Pythonic way to determine if one char of many in a string References: <1234761457.20683.1300568627@webmail.messagingengine.com> Message-ID: <01aa9ea5$0$20632$c3e8da3@news.astraweb.com> Nicolas Dandrimont wrote: > I would go for something like: > > for char in word: > if char in 'aeiouAEIUO': > char_found = True > break > else: > char_found = False > > (No, I did not forget to indent the else statement, see > http://docs.python.org/reference/compound_stmts.html#for) That might be better written as: char_found = False for char in word: if char in 'aeiouAEIUO': char_found = True break or even: char_found = False for char in word: if char.lower() in 'aeiou': char_found = True break but if word is potentially very large, it's probably better to reverse the test: rather than compare every char of word to see if it is a vowel, just search word for each vowel: char_found = any( vowel in word for vowel in 'aeiouAEIOU' ) This moves the for-loop out of slow Python into fast C and should be much, much faster for very large input. -- Steven From steve at pearwood.info Tue Feb 17 07:21:16 2009 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 17 Feb 2009 23:21:16 +1100 Subject: print string as raw string References: <6vvifkFm4k0vU1@mid.uni-berlin.de> Message-ID: <01aaa153$0$20629$c3e8da3@news.astraweb.com> Diez B. Roggisch wrote: > Mirko Dziadzka schrieb: >> Hi all >> >> I'm trying to find a way to output strings in the raw-string format, e.g. >> >> print_as_raw_string(r"\.") should output r"\." instead of "\\." >> >> Is there a better way than writing your own print function? Some magic >> encoding? > > There is no need to do this. How do you know? Perhaps the OP is writing a test suite where he needs to confirm that tens of thousands of raw strings are converted correctly, and he'd rather write a Python script to generate those raw strings than to type them up by hand. In this case though, the OP would be better off generating the raw strings systematically, rather than trying to go backwards. In any case, this is just a variation of what repr() does. >>> repr(r'\.') "'\\\\.'" What the OP seems to want is something like: >>> raw_repr('\\\\.') # or r'\.' or '\x5c.' etc. "r'\.'" I don't think that's necessarily a silly function to have, although what it is useful for (apart from my contrived example above), I don't know. Here is a barely tested version: def raw_repr(s): """Return the repr of string s as a raw-string.""" r = repr(s) if '\\\\' in r: r = "r" + r.replace('\\\\', '\\') assert not r.endswith('\\') return r >>> raw_repr('\x5c.') "r'\\.'" >>> print raw_repr('\x5c.') r'\.' -- Steven From steve at pearwood.info Tue Feb 17 07:23:32 2009 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 17 Feb 2009 23:23:32 +1100 Subject: Pythonic way to determine if a string is a number References: <1234720016.23422.1300488109@webmail.messagingengine.com> <2B9BDEC0-5D49-4760-86D7-C36A5FC849C6@semanchuk.com> Message-ID: <01aaa1da$0$20629$c3e8da3@news.astraweb.com> Roy Smith wrote: >> > Do you really want to except SystemExit, KeyboardInterrupt, MemoryError >> > and SyntaxError? > > Absolutely. Let's take my example -- you're writing software for a Mars > Rover. I have no idea how you might get a MemoryError, but let's say you > do. Which would you rather do, perform a system reset, or print a stack > trace and wait for a friendly Martian to come along and reboot you? > > You may think I'm being silly, but I'm dead serious. The many layers of > "It's impossible for this to happen, but if it does let's do something to > try and recover" processing saved that mission several times over. In > some applications, there's no such thing as "halt". Okay, but that surely falls under chapter 18 of the "Advanced Python Programming for the Mars Rover" book rather than chapter 5 of "Newbies Guide to Python". In general, the right thing to do for unexpected exemptions is to let them halt the program so you can find out about them and fix the bug, not to hide the exception. There may be exceptions (pun intended) to this general principle, but they're fairly unusual. -- Steven From newptcai at gmail.com Tue Feb 17 07:27:25 2009 From: newptcai at gmail.com (=?GB2312?B?0rvK18qr?=) Date: Tue, 17 Feb 2009 04:27:25 -0800 (PST) Subject: Is there something easier than ORM? Message-ID: <07cb23ac-3f67-45f2-a1ba-9fb80510db9b@z28g2000prd.googlegroups.com> Hi all, Recently I am studying some python ORM libraries, such as sqlalchemy. These are very powerful technologies to handle database. But I think my project are not complicated to enough to benefit from a complete ORM system. What I really want, is some easy ways to load data from database, and change rows of data to list of named tuple, then I could send these data to my client application. I don't think I want these subtle behavior such as lazy load, auto update, ect. in ORM. So is there some libraries like that? Or is there some tools that could generate code from database scheme as I want? From lists at cheimes.de Tue Feb 17 07:28:01 2009 From: lists at cheimes.de (Christian Heimes) Date: Tue, 17 Feb 2009 13:28:01 +0100 Subject: printing bytes to stdout in Py3 In-Reply-To: References: Message-ID: Peter Billam schrieb: > Greetings. (Newbie warning as usual) In Python3, sys.stdout is a > io.TextIOWrapper object; but I want to output bytes > (e.g. muscript -midi t > t.mid ) > and they're coming out stringified :-( How can I either change the > encoding on sys.stdout, or close sys.stdout and reopen it in 'b' > mode, or dup(fd) it first, or whatever the right thing to do is ? The official API to write binary data to stdout is: >>> count = sys.stdout.buffer.write(b"abc\n") abc Christian From smartpawn at gmail.com Tue Feb 17 07:31:38 2009 From: smartpawn at gmail.com (Deepak Rokade) Date: Tue, 17 Feb 2009 18:01:38 +0530 Subject: listing files by modification time Message-ID: <48224a820902170431g3711d4b6o8157580bb2f3b257@mail.gmail.com> Hi, I am using python 2.5 on sun solaris. I want to limit the number of files returned by os.listdir() to some number (say 1000), how can I do it ? Also I wan to list the files only if they are older than some x days, how can I do it? I can do this through shell script using command. find ${ DIR_PATH} -mtime +`expr ${PERIOD} - 1` -type f -exec ls -l {} \; I want to have similar functionality like above through python. I don't want to list the whole files in directory and go to each file for checking it's modification time. I am thankful for any pointer. -- Thanx & Regards, Deepak Rokade Do what u Enjoy & Enjoy what u Do........... -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Tue Feb 17 07:36:52 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 17 Feb 2009 04:36:52 -0800 Subject: listing files by modification time In-Reply-To: <48224a820902170431g3711d4b6o8157580bb2f3b257@mail.gmail.com> References: <48224a820902170431g3711d4b6o8157580bb2f3b257@mail.gmail.com> Message-ID: <50697b2c0902170436v3704add2gb1cab410607f7bdf@mail.gmail.com> On Tue, Feb 17, 2009 at 4:31 AM, Deepak Rokade wrote: > Hi, > > I am using python 2.5 on sun solaris. > > I want to limit the number of files returned by os.listdir() to some number > (say 1000), how can I do it ? > > Also I wan to list the files only if they are older than some x days, how > can I do it? You can filter the returned list of files by checking the results of os.stat() [http://docs.python.org/library/os.html#os.stat] on the files. The `stat` module [http://docs.python.org/library/stat.html] can help with the interpretation of the data returned from os.stat(). Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From n.kottiyath at gmail.com Tue Feb 17 07:40:33 2009 From: n.kottiyath at gmail.com (Kottiyath) Date: Tue, 17 Feb 2009 04:40:33 -0800 (PST) Subject: Is there something easier than ORM? References: <07cb23ac-3f67-45f2-a1ba-9fb80510db9b@z28g2000prd.googlegroups.com> Message-ID: ??? wrote: > Hi all, > > Recently I am studying some python ORM libraries, such as sqlalchemy. > > These are very powerful technologies to handle database. But I think > my project are not complicated to enough to benefit from a complete > ORM system. > > What I really want, is some easy ways to load data from database, and > change rows of data to list of named tuple, then I could send these > data to my client application. > > I don't think I want these subtle behavior such as lazy load, auto > update, ect. in ORM. > > So is there some libraries like that? > > Or is there some tools that could generate code from database scheme > as I want? If ORM is not used, you might have to contend with different tools for different databases - and will have to write SQL commands. Luckily everything follows DB-API2 properly. http://www.python.org/dev/peps/pep-0249/. So you mostly dont have to change the commands to access DB. For the different tools, this http://wiki.python.org/moin/DatabaseInterfaces might be a good starting point. For example - psycopg2 for postgresql is almost the default etc. From sjmachin at lexicon.net Tue Feb 17 08:02:34 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 17 Feb 2009 05:02:34 -0800 (PST) Subject: flexible find and replace ? References: <18d1b669-7a79-4295-a1e2-4693d361d0af@v13g2000yqm.googlegroups.com> <1903b4e6-0ea1-4e34-a6af-2d69b6d75a72@i20g2000prf.googlegroups.com> Message-ID: <917e504a-47dc-4ac3-b2ae-72d5cfb6d7df@m29g2000prd.googlegroups.com> On Feb 17, 7:18?pm, Duncan Booth wrote: > John Machin wrote: > > def fancyrepl(tag, replfunc, input_string): > > ? ? count = 0 > > ? ? pieces = [] > > ? ? pos = 0 > > ? ? taglen = len(tag) > > ? ? while 1: > > ? ? ? ? try: > > ? ? ? ? ? ? newpos = input_string.index(tag, pos) > > ? ? ? ? except ValueError: > > ? ? ? ? ? ? pieces.append(input_string[pos:]) > > ? ? ? ? ? ? return ''.join(pieces) > > ? ? ? ? pieces.append(input_string[pos:newpos]) > > ? ? ? ? count += 1 > > ? ? ? ? pieces.append(replfunc(count)) > > ? ? ? ? pos = newpos + taglen > > Or even: > > import re, itertools > def fancyrepl(tag, replfunc, input_string): > ? ? ? ? counter = itertools.count(1) > ? ? ? ? return re.sub(re.escape(tag), > ? ? ? ? ?lambda m: replfunc(counter.next()), input_string) > > which does exactly the same thing Not exactly; mine needs taglen = max(1, len(tag)) to stop an infinite loop when len(tag) == 0. > in rather less code. and with rather less execution speed [measured at about half] and rather less OP-explanation speed [guessed] :-) From deets at nospam.web.de Tue Feb 17 08:24:43 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 17 Feb 2009 14:24:43 +0100 Subject: Is there something easier than ORM? In-Reply-To: <07cb23ac-3f67-45f2-a1ba-9fb80510db9b@z28g2000prd.googlegroups.com> References: <07cb23ac-3f67-45f2-a1ba-9fb80510db9b@z28g2000prd.googlegroups.com> Message-ID: <6vvs4rFlvitlU1@mid.uni-berlin.de> ??? schrieb: > Hi all, > > Recently I am studying some python ORM libraries, such as sqlalchemy. > > These are very powerful technologies to handle database. But I think > my project are not complicated to enough to benefit from a complete > ORM system. > > What I really want, is some easy ways to load data from database, and > change rows of data to list of named tuple, then I could send these > data to my client application. > > I don't think I want these subtle behavior such as lazy load, auto > update, ect. in ORM. > > So is there some libraries like that? > > Or is there some tools that could generate code from database scheme > as I want? Sqlalchemy. You don't need to use the ORM-layer, and you can use reflection to create schema-objects like tables. Then you can use that to create SQL-queries simple & powerful, whilst being DB-agnostic and having a road to start using the ORM if you discover it is useful for you. To be honest: if you can control the schema, I'd still go for an orm. I for example use elixir. It makes the easy things *really* easy, and the complicated ones ar still possible. Diez From michele.simionato at gmail.com Tue Feb 17 08:37:43 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Tue, 17 Feb 2009 05:37:43 -0800 (PST) Subject: Is there something easier than ORM? References: <07cb23ac-3f67-45f2-a1ba-9fb80510db9b@z28g2000prd.googlegroups.com> Message-ID: <2aadd0f4-37a8-4e65-a447-4ef1f44eba74@v39g2000yqm.googlegroups.com> On Feb 17, 1:27 pm, ??? wrote: > Hi all, > > Recently I am studying some python ORM libraries, such as sqlalchemy. > > These are very powerful technologies to handle database. But I think > my project are not complicated to enough to benefit from a complete > ORM system. > > What I really want, is some easy ways to load data from database, and > change rows of data to list of named tuple, then I could send these > data to my client application. > > I don't think I want these subtle behavior such as lazy load, auto > update, ect. in ORM. > > So is there some libraries like that? > > Or is there some tools that could generate code from database scheme > as I want? I think there is room for a poor man toolkit, something in between SQLAlchemy and raw DB API. However, I am not aware of any, and for the moment I am using a custom made solution. From santosdosreis at gmail.com Tue Feb 17 08:47:07 2009 From: santosdosreis at gmail.com (Jayson Santos) Date: Tue, 17 Feb 2009 05:47:07 -0800 (PST) Subject: Speedup Bitmap Parser References: <58aed622-cf81-4747-ac54-86badef1c8dc@s20g2000yqh.googlegroups.com> <4c467175-092f-423d-8c0c-cdbffc8579c4@c12g2000yqj.googlegroups.com> <12765e3f-a324-4621-b110-b40bd57acff0@s20g2000yqh.googlegroups.com> Message-ID: <5b94254a-e8ea-469d-8e07-2f3dc778baa8@v39g2000yqm.googlegroups.com> On 16 fev, 21:47, bearophileH... at lycos.com wrote: > Jayson Santos: > > > Do I need use some patters or others progamming conventions ? > > That's a strong question... > Knowing OOP well is important, and it's often a good way to program, > etc. But... You may try to rewrite your code with functions only and > no classes (well, you may need to use classes for the TK gui). > Feel free to not follow this suggestion of mine. Even if you follow > it, it will not damage your brain :-) > > Bye, > bearophile Hello bearophile, Thank you for all. After changing my code to use only functions instead classes my code is too much faster. Here cProfile statistcs: Using old code : 633608 function calls in 1.361 CPU seconds Using new code: 475487 function calls in 0.800 CPU seconds Best Regards Jayson Reis From stef.mientki at gmail.com Tue Feb 17 08:58:24 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Tue, 17 Feb 2009 14:58:24 +0100 Subject: how to detect if an object is "simple" (not a pointer, unmutable ) ? Message-ID: <499AC280.80103@gmail.com> hello, I'm making a virtual machine, in which (small) pieces of software (called bricks) are connected, by connecting an output of a brick to the input of another brick. A connection between 2 bricks may be of any type, so it might be simple integer, or a multi-nested dictionary / list or whatsoever . Connections are made with the following statement (in simplified form) Brick2.In = Brick2.Out Now if the connection is a complex object, e.g. a list, Brick2.In and Brick2.Out points to the same object, and can automatically exchange information. Now if the connection consists of a simple integer, the statement Brick2.In = Brick2.Out just assigns once a value to Brick2, so there's no real communication anymore. I solved that by adding modify-flags and receiver lists. The problem is how can I determine if a connection is a pointer or not ? Which I'm not sure might be the same as mutable ? ( The type of connection need not be a standard Python type, but might be any type created by the user. ) thanks, Stef Mientki From tim.wintle at teamrubber.com Tue Feb 17 09:10:26 2009 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Tue, 17 Feb 2009 14:10:26 +0000 Subject: memory recycling/garbage collecting problem In-Reply-To: <50697b2c0902170040k2b2c211ew2a2ce3e4c5044c17@mail.gmail.com> References: <50697b2c0902170040k2b2c211ew2a2ce3e4c5044c17@mail.gmail.com> Message-ID: <1234879826.7672.11.camel@tim-laptop> On Tue, 2009-02-17 at 00:40 -0800, Chris Rebert wrote: > > > > 'gc.collect()' -- I believe, but I'm not the specialist in it. > > If I understand correctly, that only effects objects that are part of > a reference cycle and doesn't necessarily force the freed memory to be > released to the OS. I believe that's correct. If the OP is worrying about memory usage then they should also be aware that there are lots of very clever things done pre-assigning and keeping hold of memory with python's in-built types to let them scale well that can be confusing when you're looking at memory usage. Basically malloc() and free() are computationally expensive, so Python tries to call them as little as possible - but it's quite clever at knowing what to do - e.g. if a list has already grown large then python assumes it might grow large again and keeps hold of a percentage of the memory. The outcome is that trying to reduce memory usage can change what data structures you should use - tupples use less space than lists, etc. Tim W From newptcai at gmail.com Tue Feb 17 09:15:33 2009 From: newptcai at gmail.com (=?UTF-8?B?5LiA6aaW6K+X?=) Date: Tue, 17 Feb 2009 06:15:33 -0800 (PST) Subject: Is there something easier than ORM? References: <07cb23ac-3f67-45f2-a1ba-9fb80510db9b@z28g2000prd.googlegroups.com> <6vvs4rFlvitlU1@mid.uni-berlin.de> Message-ID: <70dc50d8-6e24-465f-83e8-fbb00177cddf@n5g2000prc.googlegroups.com> Thanks for your reply. With sqlalchemy, an mapped must living in a session, you have no way to disconnect it with its session. For example : #------------------------------------- user = session.query(User).first() session.expunge(user) print user.name #Error here #------------------------------------- I just want to get an read-only copy of user disconnected with session to avoid unexpected database operation. But after expunge, properties of user is not accessible anymore. BTW : why you choose elixir instead of sqlalchemy's own schema definition style? Doesn't including another library means more chances of bugs? On Feb 17, 9:24?pm, "Diez B. Roggisch" wrote: > ??? schrieb: > > > > > Hi all, > > > Recently I am studying some python ORM libraries, such as sqlalchemy. > > > These are very powerful technologies to handle database. ?But I think > > my project are not complicated to enough to benefit from a complete > > ORM system. > > > What I really want, is some easy ways to load data from database, and > > change rows of data to list of named tuple, then I could send these > > data to my client application. > > > I don't think I want these subtle behavior such as lazy load, auto > > update, ect. in ORM. > > > So is there some libraries like that? > > > Or is there some tools that could generate code from database scheme > > as I want? > > Sqlalchemy. You don't need to use the ORM-layer, and you can use > reflection to create schema-objects like tables. > > Then you can use that to create SQL-queries simple & powerful, whilst > being DB-agnostic and having a road to start using the ORM if you > discover it is useful for you. > > To be honest: if you can control the schema, I'd still go for an orm. I > for example use elixir. It makes the easy things *really* easy, and the > complicated ones ar still possible. > > Diez From smartpawn at gmail.com Tue Feb 17 09:16:07 2009 From: smartpawn at gmail.com (Deepak Rokade) Date: Tue, 17 Feb 2009 19:46:07 +0530 Subject: listing files by modification time In-Reply-To: <50697b2c0902170436v3704add2gb1cab410607f7bdf@mail.gmail.com> References: <48224a820902170431g3711d4b6o8157580bb2f3b257@mail.gmail.com> <50697b2c0902170436v3704add2gb1cab410607f7bdf@mail.gmail.com> Message-ID: <48224a820902170616p531c38c2pb4cb8a9245799b9d@mail.gmail.com> Yes I can do that but for that I will have to go through entire list of files and also I will have to first get the whole list of files present in directory. In case of my application this list can be huge and so want to list the files which suits my criteria. Similar to the unix find command I sent earlier or like below. find / -mtime +5 -type f -exec ls -l {} \; Otherwise can I limit the number of files in a list returned by os.listdir() ? On Tue, Feb 17, 2009 at 6:06 PM, Chris Rebert wrote: > On Tue, Feb 17, 2009 at 4:31 AM, Deepak Rokade > wrote: > > Hi, > > > > I am using python 2.5 on sun solaris. > > > > I want to limit the number of files returned by os.listdir() to some > number > > (say 1000), how can I do it ? > > > > Also I wan to list the files only if they are older than some x days, how > > can I do it? > > You can filter the returned list of files by checking the results of > os.stat() [http://docs.python.org/library/os.html#os.stat] on the > files. The `stat` module [http://docs.python.org/library/stat.html] > can help with the interpretation of the data returned from os.stat(). > > Cheers, > Chris > > -- > Follow the path of the Iguana... > http://rebertia.com > -- Thanx & Regards, Deepak Rokade Do what u Enjoy & Enjoy what u Do........... -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at nospam.web.de Tue Feb 17 09:17:33 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 17 Feb 2009 15:17:33 +0100 Subject: how to detect if an object is "simple" (not a pointer, unmutable ) ? In-Reply-To: References: Message-ID: <6vvv7tFlvv6jU1@mid.uni-berlin.de> Stef Mientki schrieb: > hello, > > I'm making a virtual machine, > in which (small) pieces of software (called bricks) are connected, > by connecting an output of a brick to the input of another brick. > > A connection between 2 bricks may be of any type, > so it might be simple integer, > or a multi-nested dictionary / list or whatsoever . > > Connections are made with the following statement (in simplified form) > > Brick2.In = Brick2.Out > > Now if the connection is a complex object, e.g. a list, > Brick2.In and Brick2.Out points to the same object, > and can automatically exchange information. > > Now if the connection consists of a simple integer, > the statement Brick2.In = Brick2.Out > just assigns once a value to Brick2, > so there's no real communication anymore. > I solved that by adding modify-flags and receiver lists. > > The problem is how can I determine > if a connection is a pointer or not ? > Which I'm not sure might be the same as mutable ? > ( The type of connection need not be a standard Python type, > but might be any type created by the user. ) AFAIK there is no distinction possible by some attribute or function. I guess your safest bet is to provide a discreet list of immutables, and check objects for them being subclass of these. If yes, create the needed communication channels. OTOH, the better option might even be to intercept the setting of objects on your bricks. If somebody sets a value on some brick's "slot", this is *always* something that needs to be communicated - it could be a new list, couldn't it? So knowing if that object is mutable is irrelevant I'd say. Diez From claird at lairds.us Tue Feb 17 09:30:27 2009 From: claird at lairds.us (Cameron Laird) Date: Tue, 17 Feb 2009 14:30:27 +0000 Subject: can multi-core improve single funciton? References: <2d09213e-8095-43d2-a067-6c2b301fa41a@x9g2000yqk.googlegroups.com> Message-ID: <39uq66-b7j.ln1@lairds.us> In article , Steven D'Aprano wrote: . . . >> And now for my version (which admitedly isn't really mine, and returns >> slightly incorrect fib(n) for large values of n, due to the limited >> floating point precision). > >The floating point version is nice, but it starts giving incorrect >answers relatively early, from n=71. But if you don't need accurate >results (a relative error of 3e-15 for n=71), it is very fast. . . . While my personal opinion is that it's silly to characterize an error of 3e-15 as not "accurate", I think more constructive is to focus on the fact that the closed-form solution can be touched up to give a precise integral solution, while re- taining its (approximately) O(log n) run-time cost. From floris.bruynooghe at gmail.com Tue Feb 17 09:30:45 2009 From: floris.bruynooghe at gmail.com (Floris Bruynooghe) Date: Tue, 17 Feb 2009 06:30:45 -0800 (PST) Subject: memory recycling/garbage collecting problem References: <57681bf10902162121y4aa9b40eue7d6560336468500@mail.gmail.com> Message-ID: On Feb 17, 5:31?am, Chris Rebert wrote: > My understanding is that for efficiency purposes Python hangs on to > the extra memory even after the object has been GC-ed and doesn't give > it back to the OS right away. Even if Python would free() the space no more used by it's own memory allocator (PyMem_Malloc(), PyMem_Free() & Co) the OS usually doesn't return this space to the global free memory pool but instead leaves it assigned to the process, again for performance reasons. Only when the OS is running out of memory it will go and get the free()ed memory of processes back. There might be a way to force your OS to do so earlier manually if you really want but I'm not sure how you'd do that. Regards Floris From david.russell at fdmgroup.com Tue Feb 17 09:35:05 2009 From: david.russell at fdmgroup.com (David Russell) Date: Tue, 17 Feb 2009 14:35:05 -0000 Subject: 2 very interesting python projects - Financial industry Message-ID: Dear Python experts, First of all sorry for the unsolicited email, I have attached two very interesting long term Python projects in the Frankfurt area, Financial industry. I am working exclusively with the client on both requirements, interviews and contracts can be arranged very quickly. You will be involved in a project to develop the next generation of financial trading systems, this will be the biggest, fastest trading system of its kind in the world and will be used on a global scale. Financial experience is not a must, they are looking more for technical skills here. If the projects look interesting to you please feel free to contact me on the contact details below. Thank you for your help, Best Regards David Large Financial Institution - Frankfurt Senior Python C/C++ Developer (f/m) Tasks/Responsibilities Software developer for a complex electronic trading system. The software developer will work in the implementation team of the trading system; tasks include: - Requirements Analysis - Development of a Scripting framework based on Python - Specification - Implementation Target platform will be Linux. Qualifications/Required Skills (Mandatory) Rock Solid Python and C/C++ knowledge Integration of Python with C/C++ libraries Automated Testing Good overview and knowledge of open source software Experience of software development in large projects Good communications skills Ability to work in project teams A good command of English is a must. Additional Domain & Business Skills Knowledge of derivatives trading an advantage, in particular U.S. options. Additional Information: Frankfurt am Main, Germany Start ASAP for a minimum of 6 months Rate - Negotiable This is an urgent requirement please contact me or send me your cv as soon as possible. Contact: David Russell - Account manager email: david.russell at fdmgroup.com Tel: +49 (0) 69 756 0050 Web: www.fdmgroup.com //////////////////////////////////////////////////////////////////////// /// Large Financial Institution - Frankfurt am Main Performance / High Availability Test Automation Engineer (f/m) Tasks/Responsibilities Developer of automated test procedures for a high-performance electronic trading system. The engineer will work in the Performance and Technical Test team of the project; tasks include: - Requirements Analysis - Development of distributed transaction feed procedures, mostly in Python - Implementation of automated result analysis - Design and implementation of test procedures for failover/recovery scenarios in a multi-tier environment - Supervision of regular runs of the automated performance test suite. Target platform will be Linux. Qualifications/Required Skills Python scripting Deep (>3 years) knowledge of Linux, with a focus in the areas - Performance monitoring and tuning - Messaging architectures Performance testing experience, for latency and throughput, incl. data aggregation and reporting Good communications skills Experience of software development in large projects Good overview and knowledge of open source software Ability to work in an international project team. A good command of English is a must. Additional Domain & Business Skills Knowledge of statistical data analysis methods would be an advantage. Experience in mechanisms of interfacing C/C++ and Python would also be advantageous. Frankfurt am Main, Germany Start ASAP to 31.12.09 with good extension prospects for 2010 Rate - Negotiable This is an urgent requirement please contact me or send me your cv as soon as possible. Contact: David Russell - Account manager email: david.russell at fdmgroup.com Tel: +49 (0) 69 756 0050 Web: www.fdmgroup.com David Russell Account Manager FDM Group Beethoven Strasse 4, 60325 Frankfurt am Main Germany david.russell at fdmgroup.com Tel: + 49 (0) 69 756 0050 Cell: + 49 (0) 173 3592288 Fax: + 49 (0) 69 756 00555 www.fdmgroup.com www.fdmacademy.com BRIGHTON, LONDON, MANCHESTER, LUXEMBOURG, FRANKFURT, ZURICH & NEW YORK This message is from FDM Group Plc, and may contain information that is confidential or privileged. If you are not the intended recipient, please delete the message and any attachments and notify the sender. This email is not intended to create legally binding commitments on behalf of FDM Group Plc, nor do its contents reflect the corporate views or policies of FDM. Any unauthorised disclosure, use or dissemination, either whole or partial, is prohibited. FDM Group Plc is a private limited company registered in England (Reg. No. 2542980). ________________________________________________________________________ This e-mail has been scanned for all viruses by Star Internet. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image001.jpg Type: image/jpeg Size: 3278 bytes Desc: image001.jpg URL: From marduk at letterboxes.org Tue Feb 17 09:38:41 2009 From: marduk at letterboxes.org (Albert Hopkins) Date: Tue, 17 Feb 2009 09:38:41 -0500 Subject: listing files by modification time In-Reply-To: <48224a820902170616p531c38c2pb4cb8a9245799b9d@mail.gmail.com> References: <48224a820902170431g3711d4b6o8157580bb2f3b257@mail.gmail.com> <48224a820902170616p531c38c2pb4cb8a9245799b9d@mail.gmail.com> Message-ID: <1234881521.5905.3.camel@centar.nbk> On Tue, 2009-02-17 at 19:46 +0530, Deepak Rokade wrote: > > Yes I can do that but for that I will have to go through entire list > of files and also I will have to first get the whole list of files > present in directory. > > In case of my application this list can be huge and so want to list > the files which suits my criteria. > Similar to the unix find command I sent earlier or like below. > In that case use a generator like os.walk. That's pretty much the same thing "find" does anyway. From stef.mientki at gmail.com Tue Feb 17 09:49:00 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Tue, 17 Feb 2009 15:49:00 +0100 Subject: how to detect if an object is "simple" (not a pointer, unmutable ) ? In-Reply-To: <6vvv7tFlvv6jU1@mid.uni-berlin.de> References: <6vvv7tFlvv6jU1@mid.uni-berlin.de> Message-ID: <499ACE5C.6040400@gmail.com> thanks Diez, Diez B. Roggisch wrote: > Stef Mientki schrieb: >> hello, >> >> I'm making a virtual machine, >> in which (small) pieces of software (called bricks) are connected, >> by connecting an output of a brick to the input of another brick. >> >> A connection between 2 bricks may be of any type, >> so it might be simple integer, >> or a multi-nested dictionary / list or whatsoever . >> >> Connections are made with the following statement (in simplified form) >> >> Brick2.In = Brick2.Out >> >> Now if the connection is a complex object, e.g. a list, >> Brick2.In and Brick2.Out points to the same object, >> and can automatically exchange information. >> >> Now if the connection consists of a simple integer, >> the statement Brick2.In = Brick2.Out >> just assigns once a value to Brick2, >> so there's no real communication anymore. >> I solved that by adding modify-flags and receiver lists. >> >> The problem is how can I determine >> if a connection is a pointer or not ? >> Which I'm not sure might be the same as mutable ? >> ( The type of connection need not be a standard Python type, >> but might be any type created by the user. ) > > AFAIK there is no distinction possible by some attribute or function. > I guess your safest bet is to provide a discreet list of immutables, > and check objects for them being subclass of these. Yes that's a reasonable approach. Still I find it strange that you can't detect if an object is immutable. > If yes, create the needed communication channels. > > OTOH, the better option might even be to intercept the setting of > objects on your bricks. If somebody sets a value on some brick's > "slot", this is *always* something that needs to be communicated if there are receivers / listeners, Yes > - it could be a new list, couldn't it? I've thought about that, but it makes the creation of the Bricks (which should be possible by novices) more complex. By not making it a list on default, the execution of a brick might be as simple as: Out = 3 * In But of course I could wrap that up, so it'll become a list, I'll think about that. thanks, Stef > So knowing if that object is mutable is irrelevant I'd say. > > Diez > -- > http://mail.python.org/mailman/listinfo/python-list From linuxguy123 at gmail.com Tue Feb 17 09:54:40 2009 From: linuxguy123 at gmail.com (Linuxguy123) Date: Tue, 17 Feb 2009 07:54:40 -0700 Subject: How do I declare global vars or class vars in Python ? Message-ID: <1234882480.4183.5.camel@localhost.localdomain> How do I do this in Python ? ############################# declare A,B function getA return A function getB return B function setA(value) A = value function setB(value) B = value main() getA getB dosomething setA(aValue) setB(aValue) ############################ The part I don't know to do is declare the variables, either as globals or as vars in a class. How is this done in Python without setting them to a value ? Thanks From roy at panix.com Tue Feb 17 09:55:15 2009 From: roy at panix.com (Roy Smith) Date: Tue, 17 Feb 2009 09:55:15 -0500 Subject: Pythonic way to determine if a string is a number References: <1234720016.23422.1300488109@webmail.messagingengine.com> <2B9BDEC0-5D49-4760-86D7-C36A5FC849C6@semanchuk.com> <01aaa1da$0$20629$c3e8da3@news.astraweb.com> Message-ID: In article <01aaa1da$0$20629$c3e8da3 at news.astraweb.com>, Steven D'Aprano wrote: > Okay, but that surely falls under chapter 18 of the "Advanced Python > Programming for the Mars Rover" book rather than chapter 5 of "Newbies > Guide to Python". Well, sure, but this thread started out with my taking, ahem, exception to the statement, "never use bare excepts at all". I agree that doing so is not typical, and not the kind of habit that new programmers should form because it's not the kind of situation new programmers are likely to be involved in. But, "never" was too strong a word. From kyosohma at gmail.com Tue Feb 17 10:02:53 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Tue, 17 Feb 2009 07:02:53 -0800 (PST) Subject: Is there something easier than ORM? References: <07cb23ac-3f67-45f2-a1ba-9fb80510db9b@z28g2000prd.googlegroups.com> <6vvs4rFlvitlU1@mid.uni-berlin.de> <70dc50d8-6e24-465f-83e8-fbb00177cddf@n5g2000prc.googlegroups.com> Message-ID: On Feb 17, 8:15?am, ??? wrote: > Thanks for your reply. > > With sqlalchemy, an mapped must living in a session, you have no way > to disconnect it with its session. > > For example : > > #------------------------------------- > user = session.query(User).first() > session.expunge(user) > print user.name ? #Error here > #------------------------------------- > > I just want to get an read-only copy of user disconnected with session > to avoid ?unexpected database operation. > But after expunge, properties of user is not accessible anymore. If you don't want any unexpected database operations, don't call flush () or commit() or just call rollback() BEFORE you do any real operations. There is a good sqlalchemy mailing list where even the developers hang out and answer questions. I'm sure they could point you in the right direction too. Mike > > BTW : why you choose elixir instead of sqlalchemy's own schema > definition style? > Doesn't including another library means more chances of bugs? > > On Feb 17, 9:24?pm, "Diez B. Roggisch" wrote: > > > ??? schrieb: > > > > Hi all, > > > > Recently I am studying some python ORM libraries, such as sqlalchemy. > > > > These are very powerful technologies to handle database. ?But I think > > > my project are not complicated to enough to benefit from a complete > > > ORM system. > > > > What I really want, is some easy ways to load data from database, and > > > change rows of data to list of named tuple, then I could send these > > > data to my client application. > > > > I don't think I want these subtle behavior such as lazy load, auto > > > update, ect. in ORM. > > > > So is there some libraries like that? > > > > Or is there some tools that could generate code from database scheme > > > as I want? > > > Sqlalchemy. You don't need to use the ORM-layer, and you can use > > reflection to create schema-objects like tables. > > > Then you can use that to create SQL-queries simple & powerful, whilst > > being DB-agnostic and having a road to start using the ORM if you > > discover it is useful for you. > > > To be honest: if you can control the schema, I'd still go for an orm. I > > for example use elixir. It makes the easy things *really* easy, and the > > complicated ones ar still possible. > > > Diez From google at mrabarnett.plus.com Tue Feb 17 10:07:37 2009 From: google at mrabarnett.plus.com (MRAB) Date: Tue, 17 Feb 2009 15:07:37 +0000 Subject: How do I declare global vars or class vars in Python ? In-Reply-To: <1234882480.4183.5.camel@localhost.localdomain> References: <1234882480.4183.5.camel@localhost.localdomain> Message-ID: <499AD2B9.5020001@mrabarnett.plus.com> Linuxguy123 wrote: > How do I do this in Python ? > > ############################# > declare A,B > > function getA > return A > > function getB > return B > > function setA(value) > A = value > > function setB(value) > B = value > > main() > getA > getB > dosomething > setA(aValue) > setB(aValue) > ############################ > > The part I don't know to do is declare the variables, either as globals > or as vars in a class. How is this done in Python without setting them > to a value ? > It isn't possible to have an uninitialised variable. If it doesn't have a value then it doesn't exist. From patrick.oloughlin at gmail.com Tue Feb 17 10:10:51 2009 From: patrick.oloughlin at gmail.com (Paddy O'Loughlin) Date: Tue, 17 Feb 2009 15:10:51 +0000 Subject: How do I declare global vars or class vars in Python ? In-Reply-To: <1234882480.4183.5.camel@localhost.localdomain> References: <1234882480.4183.5.camel@localhost.localdomain> Message-ID: Use the global statement. http://docs.python.org/reference/simple_stmts.html#the-global-statement A working example based on your pseudocode would be: #################################### def getA(): global A return A def getB(): global B return B def setA(value): global A A = value def setB(value): global B B = value def main(): setA(5) setB(6) print getA() print getB() if __name__ == '__main__': main() ##################################### Although honestly, I think you'd be best not coding like that (with gets and sets and all) in python. Paddy 2009/2/17 Linuxguy123 : > How do I do this in Python ? > > ############################# > declare A,B > > function getA > return A > > function getB > return B > > function setA(value) > A = value > > function setB(value) > B = value > > main() > getA > getB > dosomething > setA(aValue) > setB(aValue) > ############################ > > The part I don't know to do is declare the variables, either as globals > or as vars in a class. How is this done in Python without setting them > to a value ? > > Thanks > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- "Ray, when someone asks you if you're a god, you say YES!" From floris.bruynooghe at gmail.com Tue Feb 17 10:12:02 2009 From: floris.bruynooghe at gmail.com (Floris Bruynooghe) Date: Tue, 17 Feb 2009 07:12:02 -0800 (PST) Subject: Pythonic way to determine if a string is a number References: <1234720016.23422.1300488109@webmail.messagingengine.com> <2B9BDEC0-5D49-4760-86D7-C36A5FC849C6@semanchuk.com> Message-ID: On Feb 16, 12:05?am, Mel wrote: > Christian Heimes wrote: > > Roy Smith wrote: > >> They make sense when you need to recover from any error that may occur, > >> possibly as the last resort after catching and dealing with more specific > >> exceptions. In an unattended embedded system (think Mars Rover), the > >> top-level code might well be: > > >> while 1: > >> ? ?try: > >> ? ? ? main() > >> ? ?except: > >> ? ? ? reset() > > > Do you really want to except SystemExit, KeyboardInterrupt, MemoryError > > and SyntaxError? > > Exactly. ?A normal program should never do anything more comprehensive than > > try: > ? ? some_function () > except StandardError: > ? ? some_handling () Hmm, most places advocate or even outright recommend derriving your own exceptions from Exception and not from StandardError. So maybe your catch-all should be Exception? In that case you would be catching warnings though, no idea what influence that has on the warning system. Regards Floris PS: Does anybody know why StopIterantion derrives from Exception while GeneratorExit derrives from BaseException? This could be as annoying/ confusing as Warning. From patrick.oloughlin at gmail.com Tue Feb 17 10:13:38 2009 From: patrick.oloughlin at gmail.com (Paddy O'Loughlin) Date: Tue, 17 Feb 2009 15:13:38 +0000 Subject: How do I declare global vars or class vars in Python ? In-Reply-To: <499AD2B9.5020001@mrabarnett.plus.com> References: <1234882480.4183.5.camel@localhost.localdomain> <499AD2B9.5020001@mrabarnett.plus.com> Message-ID: 2009/2/17 MRAB : > It isn't possible to have an uninitialised variable. If it doesn't have > a value then it doesn't exist. True, but you can use the global statement to refer to the variable within a function and read from the variable there, without it being already initialised in the module. Of course, if you try to call that function before the global has been initialised, python will complain [and rightly so :)] Paddy -- "Ray, when someone asks you if you're a god, you say YES!" From jjposner at snet.net Tue Feb 17 10:14:06 2009 From: jjposner at snet.net (John Posner) Date: Tue, 17 Feb 2009 10:14:06 -0500 Subject: Changing the Image on a button In-Reply-To: References: <59253b2f-c90d-4308-835d-e81a2e602127@p23g2000prp.googlegroups.com> Message-ID: >> > Try this change: >> > >> > ? from: btn.configure(image = None) >> > ? ? to: img1.blank() >> > >> >> This does in fact clear the image out, however it isn't causing the >> text to display... Do i have have to create a new button and swap it >> out? I knew you were gonna ask that! :-) I haven't worked in this area before, but I found this at http://effbot.org/tkinterbook/button.htm: In earlier versions of Tkinter, the image option overrides the text option. If you specify both, only the image is displayed. In later versions, you can use the compound option to change this behavior. To display text on top of an image, set compound to CENTER: b = Button(master, text="Click me", image=pattern, compound=CENTER) So here's a reworking, in which the text and image are both toggled by pressing the button: ### button that toggles both text and image from Tkinter import * def pushed(): """callback: button push""" global toggle if toggle: btn.config(text="", image=img_empty) toggle = not toggle else: btn.config(text=msg, image=img_good) toggle = not toggle ### main program toggle = True msg = "hello" root = Tk() ### store two versions of an image in global variables: # 1. original image img_good = PhotoImage(file="bacon.gif") # 2. blank image, created by copying and erasing img_empty = img_good.copy() img_empty.blank() ### create toggle button btn = Button(root, compound=CENTER, text="hello", font="helvetica 14 bold", image=img_good, command=pushed) btn.pack() ### go root.mainloop() E-mail message checked by Spyware Doctor (6.0.0.386) Database version: 5.11780 http://www.pctools.com/en/spyware-doctor-antivirus/ From Ron.Barak at lsi.com Tue Feb 17 10:18:03 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Tue, 17 Feb 2009 15:18:03 +0000 Subject: Threads vs. processes, what to consider in choosing ? In-Reply-To: <20090217070546.5442B4A12D2@riobu.com> References: <20090217070546.5442B4A12D2@riobu.com> Message-ID: <7F0503CD69378F49BE0DC30661C6CCF60E687DA5@enbmail01.lsi.com> Hi, May I have your recommendations in choosing threads or processes for the following ? I have a wxPython application that builds an internal database from a list of files and then displays various aspects of that data, in response to user's requests. I want to add a module that finds events in a set of log files (LogManager). These log files are potentially huge, and the initial processing is lengthy (several minutes). Thus, when the user will choose LogManager, it would be unacceptable to block the other parts of the program, and so - the initial LogManager processing would need to be done separately from the normal run of the program. Once the initial processing is done, the main program would be notified and could display the results of LogManager processing. I was thinking of either using threads, or using separate processes, for the main programs and LogManager. What would you suggest I should consider in choosing between the two options ? Are there other options besides threads and multi-processing ? Thanks, Ron. From jcd at sdf.lonestar.org Tue Feb 17 10:27:57 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Tue, 17 Feb 2009 10:27:57 -0500 Subject: Is there something easier than ORM? In-Reply-To: <70dc50d8-6e24-465f-83e8-fbb00177cddf@n5g2000prc.googlegroups.com> References: <07cb23ac-3f67-45f2-a1ba-9fb80510db9b@z28g2000prd.googlegroups.com> <6vvs4rFlvitlU1@mid.uni-berlin.de> <70dc50d8-6e24-465f-83e8-fbb00177cddf@n5g2000prc.googlegroups.com> Message-ID: <1234884477.4608.1.camel@aalcdl07.lib.unc.edu> On Tue, 2009-02-17 at 06:15 -0800, ??? wrote: > Thanks for your reply. > > With sqlalchemy, an mapped must living in a session, you have no way > to disconnect it with its session. > > For example : > > #------------------------------------- > user = session.query(User).first() > session.expunge(user) > print user.name #Error here > #------------------------------------- > > I just want to get an read-only copy of user disconnected with session > to avoid unexpected database operation. > But after expunge, properties of user is not accessible anymore. For that, the Right Thing to Do(tm) is to log in to your session with read-only permissions. From floris.bruynooghe at gmail.com Tue Feb 17 10:29:49 2009 From: floris.bruynooghe at gmail.com (Floris Bruynooghe) Date: Tue, 17 Feb 2009 07:29:49 -0800 (PST) Subject: Pythonic way to determine if a string is a number References: <1234720016.23422.1300488109@webmail.messagingengine.com> Message-ID: <1de39f55-b42c-4d3e-8a9b-7d8f55f327d1@q18g2000vbn.googlegroups.com> On Feb 16, 7:09?am, Python Nutter wrote: > silly me, forgot to mention > > build a set from digits + '.' and use that for testing. `.' is locale dependent. Some locales might use `,' instead and maybe there's even more out there that I don't know of. So developing this yourself from scratch seems dangerous, let it bubble down to libc which should handle it correctly. Regards Floris From patrick.oloughlin at gmail.com Tue Feb 17 10:35:18 2009 From: patrick.oloughlin at gmail.com (Paddy O'Loughlin) Date: Tue, 17 Feb 2009 15:35:18 +0000 Subject: Pythonic way to determine if a string is a number In-Reply-To: References: <1234720016.23422.1300488109@webmail.messagingengine.com> Message-ID: 2009/2/16 Python Nutter : > silly me, forgot to mention > > build a set from digits + '.' and use that for testing. > > Cheers, > PN > > > 2009/2/16 Python Nutter : >> Type casting seems to be the wrong way to go about this. >> >> teststring = '15719' >> teststring.isdigit() >> returns True >> >> That takes care of integers. >> >> from string import digits >> digits >> '0123456789' >> >> now you have all the digits and you can do set testing in your logic >> to see if the teststring has anything in digits >> >> A dumb way to test is alphanumeric >> >> teststring2 = '105.22' >> teststring2.isalnum() >> returns True >> >> now you can go on from there and test to further to eliminate >> 'abcd385laf8' which on alnum() also returns true. Hmmm, this doesn't seem right to me. Unless I'm missing something, won't your code think that "123.123.123" is numeric? What about scientific or engineering notation with exponents? What's wrong with using python's own casting rules (given that you are trying to emulate the way python behaves? Or, alternatively, using a regular expression (as Nick Craig-Wood did). Given these solutions, type-conversion and catching the ValueError appears, to me, to be correct, the most concise, and the most readable solution. Of course, if you want to use your own set of rules for number encoding, then building your own regular expression would seem to be the right way to go. Paddy -- "Ray, when someone asks you if you're a god, you say YES!" From bryanvick at gmail.com Tue Feb 17 10:37:12 2009 From: bryanvick at gmail.com (Bryan) Date: Tue, 17 Feb 2009 07:37:12 -0800 (PST) Subject: Upgrading standard library module References: Message-ID: <08e76f94-7d31-4200-a774-c5c41d72f91f@r15g2000prd.googlegroups.com> On Feb 17, 12:34?am, "Gabriel Genellina" wrote: > En Fri, 13 Feb 2009 20:17:35 -0200, Bryan escribi?: > > > > > On Feb 13, 1:52?pm, Jason Scheirer wrote: > >> On Feb 13, 12:42?pm, Bryan wrote: > > >> > I have a Python v2.5.2 server running and I found some undesirable > >> > behavior in the xmlrpclib module that is included with that version of > >> > Python. ?The xmlrpclib version that is included with Python 2.6 > >> > changes the behavior for the better. ?I nervous about upgrading my > >> > Python install to 2.6 on this server because I remember reading in the > >> > docs of a library I use that it targets the 2.5 branch. ?What is the > >> > best way to only upgrade the xmlrpclib in my 2.5 install? > >> What behavior, exactly, do you not like in xmlrpclib? Diffing the 2.5 > >> and 2.6, only significant differences I see are checks for True/False > >> as builtins left over from pre-2.4 and some datetime handling. > > The xmlrpclib in my 2.5.2 install does not allow the marshaling of my > > custom objects. ?It checks the type of my object, and if it isn't in a > > hard-coded list of types, then a "Cannot marshal object of > > type" exception message shows up. ?The version in my Windows 2.6 > > install has a fall back case where if the type is not in the hard- > > coded list, it simply calls Object.__dict__ to get a graph of the > > object's values that can be marshaled into xmlrpc. > > > I am using xmlrpc through Pylons. ?As a workaround, instead of > > returning my custom objects in my xmlrpc server functions, I return > > MyObject.__dict__ > > > I also did not see anything in the revision log in the source file > > about this change. > > It was rev.52790:http://svn.python.org/view?rev=52790&view=rev > The tracker item has some background:http://bugs.python.org/issue1070046 > > -- > Gabriel Genellina Can you give me a quick run down of your process for researching this information? I don't spend much time looking at the svn or bug tracker. Should I be checking there before posting? Bryan From python at bdurham.com Tue Feb 17 10:45:48 2009 From: python at bdurham.com (python at bdurham.com) Date: Tue, 17 Feb 2009 10:45:48 -0500 Subject: Pythonic way to determine if a string is a number In-Reply-To: References: <1234720016.23422.1300488109@webmail.messagingengine.com> <2B9BDEC0-5D49-4760-86D7-C36A5FC849C6@semanchuk.com> <01aaa1da$0$20629$c3e8da3@news.astraweb.com> Message-ID: <1234885548.2747.1300870339@webmail.messagingengine.com> Original poster here: Just for the record, my *original* post did include an explicit trapping of the ValueError exception. :) My point is that the coaching offered by this forum does not always fall on deaf ears. Thanks for everyone's help on this and all the other posts in this forum. Regards, Malcolm In article <01aaa1da$0$20629$c3e8da3 at news.astraweb.com>, Steven D'Aprano wrote: > Okay, but that surely falls under chapter 18 of the "Advanced Python > Programming for the Mars Rover" book rather than chapter 5 of "Newbies > Guide to Python". Well, sure, but this thread started out with my taking, ahem, exception to the statement, "never use bare excepts at all". I agree that doing so is not typical, and not the kind of habit that new programmers should form because it's not the kind of situation new programmers are likely to be involved in. But, "never" was too strong a word. From sturlamolden at yahoo.no Tue Feb 17 10:50:33 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 17 Feb 2009 07:50:33 -0800 (PST) Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> Message-ID: On 16 Feb, 10:34, rushen... at gmail.com wrote: > And the story begins here. As i search on the net, I have found that > because of the natural characteristics of python such as GIL, we are > not able to write multi threaded programs. Oooops, in a kind of time > with lots of cpu cores and we are not able to write multi threaded > programs. The GIL does not prevent multithreaded programs. If it did, why does Python have a "threading" module? The GIL prevents one use of threads: parallel processing in plain Python. You can still do parallel processing using processes. Just import "multiprocessing" instead of "threading". The two modules have fairly similar APIs. You can still use threads to run tasks in the background. The GIL by the way, is an implementation detail. Nobody likes it very much. But it is used for making it easier to extend Python with C libraries (Python's raison d'etre). Not all C libraries are thread- safe. The GIL is also used to synchronize access to reference counts. In fact, Ruby is finally going to get a GIL as well. So it can't be that bad. As for parallel processing and multicore processors: 1. Even if a Python script can only exploit one core, we are always running more than one process on the computer. For some reason this obvious fact has to be repeated. 2. Parallel processing implies "need for speed". We have a 200x speed penalty form Python alone. The "need for speed" are better served by moving computational bottlenecks to C or Fortran. And in this case, the GIL does not prevent us from doing parallel processing. The GIL only affects the Python portion of the code. 3. Threads are not designed to be an abstraction for parallel processing. For this they are awkward, tedious, and error prone. Current threading APIs were designed for asynchronous tasks. Back in the 1990s when multithreading became popular, SMPs were luxury only few could afford, and multicore processors were unheard of. 4. The easy way to do parallel processing is not threads but OpenMP, MPI, or HPF. Threads are used internally by OpenMP and HPF, but those implementation details are taken care of by the compiler. Parallel computers have been used by scientists and engineers for three decades now, and threads have never been found a useful abstraction for manual coding. Unfortunately, this knowledge has not been passed on from physicists and engineers to the majority of computer programmers. Today, there is a whole generation of misguided computer scientists thinking that threads must be the way to use the new multicore processors. Take a lesson from those actually experienced with parallel computers and learn OpenMP! 5. If you still insist on parallel processing with Python threads -- ignoring what you can do with multiprocessing and native C/Fortran extensions -- you can still do that as well. Just compile your script with Cython or Pyrex and release the GIL manually. The drawback is that you cannot touch any Python objects (only C objects) in your GIL- free blocks. But after all, the GIL is used to synchronize reference counting, so you would have to synchronize access to the Python objects anyway. import threading def _threadproc(): with nogil: # we do not hold the GIL here pass # now we have got the GIL back return def foobar(): t = threading.Thread(target=_threadproc) t.start() t.join() That's it. Sturla Molden From sturlamolden at yahoo.no Tue Feb 17 10:57:44 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 17 Feb 2009 07:57:44 -0800 (PST) Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <9c001ccd-24cb-4bbd-af31-94ad0f255982@z1g2000yqn.googlegroups.com> <6c29ea7b-d30e-4358-8a3f-54758b1f4cde@o11g2000yql.googlegroups.com> Message-ID: <0d62cc8c-6a53-46ef-b989-32b13422ab0a@x38g2000yqj.googlegroups.com> On 16 Feb, 15:18, rushen... at gmail.com wrote: > As you mentioned, using multi cores makes programs more fast and more > popular. But what about stackless python? Does it interpret same set > of python libraries with Cpython or Does it have a special sub set? Stackless and CPython have a GIL, Jython and IronPython do not. S.M. From lists at cheimes.de Tue Feb 17 10:59:33 2009 From: lists at cheimes.de (Christian Heimes) Date: Tue, 17 Feb 2009 16:59:33 +0100 Subject: memory recycling/garbage collecting problem In-Reply-To: <57681bf10902162121y4aa9b40eue7d6560336468500@mail.gmail.com> References: <57681bf10902162121y4aa9b40eue7d6560336468500@mail.gmail.com> Message-ID: Yuanxin Xi wrote: > Could anyone please explain why this happens? It seems some memory > are not freed. I'm running into problems with this as my program is > very memory cosuming and need to frequently free some object to reuse > the memory. What is the best way to free the memory of b completely > (i.e. back to the status as b was created)? I'm using Python 2.5.2 Python uses malloc() and free() to allocate memory on the heap. Most malloc() implementations don't give back memory to the system. Instead the memory segment is still assigned to the process. In order to give back memory to the system pool, a memory manager has to use mapped memory (mmap()) instead of increasing the heap by changing the data segment size with brk(). This isn't a Python flaw but a general issue with malloc() based memory management. [1] By the way Python has its own memory management system on top of the system's malloc() system. The memory arena system is explained in great detail in the file obmalloc.c [2]. Christian [1] http://en.wikipedia.org/wiki/Malloc#Implementations [2] http://svn.python.org/view/python/branches/release25-maint/Objects/obmalloc.c?revision=65261&view=markup From mabdelkader at gmail.com Tue Feb 17 11:00:36 2009 From: mabdelkader at gmail.com (ma) Date: Tue, 17 Feb 2009 11:00:36 -0500 Subject: Will multithreading make python less popular? In-Reply-To: References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> Message-ID: <148918f0902170800p1c23d172rce5e6b9902ba07e9@mail.gmail.com> Very well written response! Thanks Sturla On Tue, Feb 17, 2009 at 10:50 AM, sturlamolden wrote: > On 16 Feb, 10:34, rushen... at gmail.com wrote: > > > And the story begins here. As i search on the net, I have found that > > because of the natural characteristics of python such as GIL, we are > > not able to write multi threaded programs. Oooops, in a kind of time > > with lots of cpu cores and we are not able to write multi threaded > > programs. > > The GIL does not prevent multithreaded programs. If it did, why does > Python have a "threading" module? > > The GIL prevents one use of threads: parallel processing in plain > Python. You can still do parallel processing using processes. Just > import "multiprocessing" instead of "threading". The two modules have > fairly similar APIs. You can still use threads to run tasks in the > background. > > The GIL by the way, is an implementation detail. Nobody likes it very > much. But it is used for making it easier to extend Python with C > libraries (Python's raison d'etre). Not all C libraries are thread- > safe. The GIL is also used to synchronize access to reference counts. > In fact, Ruby is finally going to get a GIL as well. So it can't be > that bad. > > As for parallel processing and multicore processors: > > 1. Even if a Python script can only exploit one core, we are always > running more than one process on the computer. For some reason this > obvious fact has to be repeated. > > 2. Parallel processing implies "need for speed". We have a 200x speed > penalty form Python alone. The "need for speed" are better served by > moving computational bottlenecks to C or Fortran. And in this case, > the GIL does not prevent us from doing parallel processing. The GIL > only affects the Python portion of the code. > > 3. Threads are not designed to be an abstraction for parallel > processing. For this they are awkward, tedious, and error prone. > Current threading APIs were designed for asynchronous tasks. Back in > the 1990s when multithreading became popular, SMPs were luxury only > few could afford, and multicore processors were unheard of. > > 4. The easy way to do parallel processing is not threads but OpenMP, > MPI, or HPF. Threads are used internally by OpenMP and HPF, but those > implementation details are taken care of by the compiler. Parallel > computers have been used by scientists and engineers for three decades > now, and threads have never been found a useful abstraction for manual > coding. Unfortunately, this knowledge has not been passed on from > physicists and engineers to the majority of computer programmers. > Today, there is a whole generation of misguided computer scientists > thinking that threads must be the way to use the new multicore > processors. Take a lesson from those actually experienced with > parallel computers and learn OpenMP! > > 5. If you still insist on parallel processing with Python threads -- > ignoring what you can do with multiprocessing and native C/Fortran > extensions -- you can still do that as well. Just compile your script > with Cython or Pyrex and release the GIL manually. The drawback is > that you cannot touch any Python objects (only C objects) in your GIL- > free blocks. But after all, the GIL is used to synchronize reference > counting, so you would have to synchronize access to the Python > objects anyway. > > > import threading > > def _threadproc(): > with nogil: > # we do not hold the GIL here > pass > # now we have got the GIL back > return > > def foobar(): > t = threading.Thread(target=_threadproc) > t.start() > t.join() > > That's it. > > > > > > Sturla Molden > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at cheimes.de Tue Feb 17 11:04:12 2009 From: lists at cheimes.de (Christian Heimes) Date: Tue, 17 Feb 2009 17:04:12 +0100 Subject: memory recycling/garbage collecting problem In-Reply-To: <1234879826.7672.11.camel@tim-laptop> References: <50697b2c0902170040k2b2c211ew2a2ce3e4c5044c17@mail.gmail.com> <1234879826.7672.11.camel@tim-laptop> Message-ID: Tim Wintle wrote: > Basically malloc() and free() are computationally expensive, so Python > tries to call them as little as possible - but it's quite clever at > knowing what to do - e.g. if a list has already grown large then python > assumes it might grow large again and keeps hold of a percentage of the > memory. You are almost right. Python's mutable container types like have a non-linear growth rate. >From the file listobject.c /* This over-allocates proportional to the list size, making room for additional growth. The over-allocation is mild, but is enough to give linear-time amortized behavior over a long sequence of appends() in the presence of a poorly-performing system realloc(). The growth pattern is: 0, 4, 8, 16, 25, 35, 46, 58, 72, 88, ... */ new_allocated = (newsize >> 3) + (newsize < 9 ? 3 : 6); From kurdayon at yahoo.com Tue Feb 17 11:19:10 2009 From: kurdayon at yahoo.com (Kurda Yon) Date: Tue, 17 Feb 2009 08:19:10 -0800 (PST) Subject: Python change a value of a variable by itself. Message-ID: <46b1d39a-3ff4-44fb-a23c-f334ce516862@t11g2000yqg.googlegroups.com> Hi, I have the following simple code: r = {} r[1] = [0.000000] r_new = {} print r[1][0] r_new[1] = r[1] r_new[1][0] = r[1][0] + 0.02 print r[1][0] It outputs: 0.0 0.02 it is something strange to me since in the first and second case I output the same variable (r[1][0]) and it the two cases it has different values (in spite on the fact, that between the 2 outputs I did not assign a new value to the variable). Can anybody pleas explain me this strange behavior? Thank you in advance. From duncan.booth at invalid.invalid Tue Feb 17 11:27:11 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 17 Feb 2009 16:27:11 GMT Subject: How do I declare global vars or class vars in Python ? References: <1234882480.4183.5.camel@localhost.localdomain> <499AD2B9.5020001@mrabarnett.plus.com> Message-ID: "Paddy O'Loughlin" wrote: > True, but you can use the global statement to refer to the variable > within a function and read from the variable there, without it being > already initialised in the module. You don't need the global statement unless you plan to *write* the variable from the function. -- Duncan Booth http://kupuguy.blogspot.com From apt.shansen at gmail.com Tue Feb 17 11:28:14 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 17 Feb 2009 08:28:14 -0800 Subject: Python change a value of a variable by itself. In-Reply-To: <46b1d39a-3ff4-44fb-a23c-f334ce516862@t11g2000yqg.googlegroups.com> References: <46b1d39a-3ff4-44fb-a23c-f334ce516862@t11g2000yqg.googlegroups.com> Message-ID: <7a9c25c20902170828y1573b381j171ccf8e676245b3@mail.gmail.com> On Tue, Feb 17, 2009 at 8:19 AM, Kurda Yon wrote: > r_new[1] = r[1] This is the problem. "r" is a dictionary, a set of key/object pairs in essence. You're making the object that "r[1]" is pointing to a list, a mutable sequence of items. The expression "r[1]" will then return that list object and assign it to "r_new[1]" -- but now both these two dictionaries are pointing to the *same* object. Its not a copy of the object, but the same object itself which you're storing in two different dictionaries. If you want to store a copy of that list in r_new[1], you can use the copy module, or something like: r_new[1] = r[1][:] which uses list slices to return a copy of the specified list. HTH, --Stephen From python.list at tim.thechases.com Tue Feb 17 11:29:57 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 17 Feb 2009 10:29:57 -0600 Subject: Python change a value of a variable by itself. In-Reply-To: <46b1d39a-3ff4-44fb-a23c-f334ce516862@t11g2000yqg.googlegroups.com> References: <46b1d39a-3ff4-44fb-a23c-f334ce516862@t11g2000yqg.googlegroups.com> Message-ID: <499AE605.2020605@tim.thechases.com> > I have the following simple code: > r = {} > r[1] = [0.000000] > r_new = {} > print r[1][0] > r_new[1] = r[1] > r_new[1][0] = r[1][0] + 0.02 > print r[1][0] > > It outputs: > 0.0 > 0.02 > > it is something strange to me since in the first and second case I > output the same variable (r[1][0]) and it the two cases it has > different values (in spite on the fact, that between the 2 outputs I > did not assign a new value to the variable). > > Can anybody pleas explain me this strange behavior? You're referencing into a single mutable object (a list): a = [1,2,3] b = a b[1] = 4 print a both r[1] and r_new[1] refer to the same list object, so when the contents of that single list object is changed ("r_new[1][0] = ...") accessing it by either name ("r[1][0]" or "r_new[1][0]") returns the same list. To create a new list in r_new, use r_new[1] = r[1][:] # copy the contents of the list -tkc From Caseyweb at gmail.com Tue Feb 17 11:31:28 2009 From: Caseyweb at gmail.com (Casey) Date: Tue, 17 Feb 2009 08:31:28 -0800 (PST) Subject: printing bytes to stdout in Py3 References: Message-ID: On Feb 17, 7:28?am, Christian Heimes wrote: > Peter Billam schrieb: > > > Greetings. (Newbie warning as usual) In Python3, sys.stdout is a > > io.TextIOWrapper object; but I want to output bytes > > ? (e.g. muscript -midi t > t.mid ) > > and they're coming out stringified :-( ?How can I either change the > > encoding on sys.stdout, or close sys.stdout and reopen it in 'b' > > mode, or dup(fd) it first, or whatever the right thing to do is ? > > The official API to write binary data to stdout is: > > >>> count = sys.stdout.buffer.write(b"abc\n") > > abc > > Christian Is this really the 'official' way to do this? This isn't meant to be confrontational or trolling; I honestly don't know the answer and I had similar questions when I first started with the 3.0 release candidates and I have yet to find a good answer in the Python v3.0 documentation. Why wouldn't you just use: print(bytes.decode(b'abc\n'), end='') From philip at semanchuk.com Tue Feb 17 11:35:00 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 17 Feb 2009 11:35:00 -0500 Subject: Is there something easier than ORM? In-Reply-To: <07cb23ac-3f67-45f2-a1ba-9fb80510db9b@z28g2000prd.googlegroups.com> References: <07cb23ac-3f67-45f2-a1ba-9fb80510db9b@z28g2000prd.googlegroups.com> Message-ID: <8C9A6CB8-80A6-4E10-8EA1-3C40EAED058D@semanchuk.com> On Feb 17, 2009, at 7:27 AM, ??? wrote: > Hi all, > > Recently I am studying some python ORM libraries, such as sqlalchemy. > > These are very powerful technologies to handle database. But I think > my project are not complicated to enough to benefit from a complete > ORM system. > > What I really want, is some easy ways to load data from database, and > change rows of data to list of named tuple, then I could send these > data to my client application. > > I don't think I want these subtle behavior such as lazy load, auto > update, ect. in ORM. > > So is there some libraries like that? > > Or is there some tools that could generate code from database scheme > as I want? As others have suggested, there are lower-level libraries for database access, like the sqlite library included with Python >= 2.5. The API wrapper I'm most familiar with (psycopg2) has some nice features like returning Postgres text as Python strings and Postgres ints as Python ints and Postgres arrays as Python lists. It can also return rows as dictionaries keyed by column names. You get some nice things for free. I read someone's advice that one doesn't need an ORM for simple projects but they become more useful as projects grow in complexity. I'm not so sure of that. I felt like the opposite could well be true -- the limitations inherent in a general purpose tool like an ORM are less likely to be a problem in a small, simple project than a larger one. In short, I gather that others on this list are a lot more fond of SqlAlchemy and ORMs in general than I am. Granted, my experience is very limited. I tried to integrate SqlAlchemy in one project, struggled for a long time to express how I wanted my tables joined, and finally found that performance was bad compared to our homegrown SQL. My boss and I were both very comfortable with SQL and were happy to go back to writing our own SQL statements and coding a data access layer. I don't intend this as a criticism of SqlAlchemy. On the contrary I am impressed by what it does. But I often see people promoting ORM as the solution to all database access problems, and I certainly don't feel like it is. Good luck, Philip From python-url at phaseit.net Tue Feb 17 11:36:23 2009 From: python-url at phaseit.net (Gabriel Genellina) Date: Tue, 17 Feb 2009 16:36:23 +0000 (UTC) Subject: Python-URL! - weekly Python news and links (Feb 17) Message-ID: QOTW: "The hardest part of design ...is keeping features out." - Donald Norman, design guru and former Apple exec https://www.technologyreview.com/business/18621/ Two short recipes: Determine whether a string is a number or not: http://groups.google.com/group/comp.lang.python/t/5a63299d426f99ef See if a word contains some given characters: http://groups.google.com/group/comp.lang.python/t/fb8c04c741e69f8f How to "peek" inside a decorated function to access the original one: http://groups.google.com/group/comp.lang.python/t/0fb2ee45dbc101b1 Optimizing recursive calls: http://groups.google.com/group/comp.lang.python/t/2d3664075ff1363b Python 3.0.1, the first bug fix release of Python 3.0, was released last Saturday: http://www.python.org/download/releases/3.0.1/ An attempt to define a generic "compress/decompress" interface (supporting zlib, bz2, maybe others): http://groups.google.com/group/comp.lang.python/t/ac2a57d661a3566c Long running processes and WSGI: http://groups.google.com/group/comp.lang.python/t/3d8a27fd5bb42842 Unicode and the Windows console: http://groups.google.com/group/comp.lang.python/t/94360d3a3abf3747 bool(some_generator) can't be used to check for "emptyness": http://groups.google.com/group/comp.lang.python/t/28cb5ad6cf9378bf An iterator class is the answer when a generator is not enough: http://groups.google.com/group/comp.lang.python/t/2bbd5daed05bb025 Using multiple processes as an alternative to multiple threads: http://groups.google.com/group/comp.lang.python/t/d068528be84ff8b5 Can a function like Fibonacci's benefit from multicore architectures? http://groups.google.com/group/comp.lang.python/t/f66417d64090ee67 Horrible algorithms have horrible performance -- don't count on automatic "optimizations": http://groups.google.com/group/comp.lang.python/t/3360de7fda1b7818 ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous daily python url http://www.pythonware.com/daily Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers The Python Papers aims to publish "the efforts of Python enthusiats": http://pythonpapers.org/ The Python Magazine is a technical monthly devoted to Python: http://pythonmagazine.com Readers have recommended the "Planet" sites: http://planetpython.org http://planet.python.org comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ The somewhat older Vaults of Parnassus ambitiously collects references to all sorts of Python resources. http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donations/ The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions. http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes. http://code.activestate.com/recipes/langs/python/ Many Python conferences around the world are in preparation. Watch this space for links to them. Among several Python-oriented RSS/RDF feeds available, see: http://www.python.org/channews.rdf For more, see: http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://www.python.org/dev/peps/pep-0042/ del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python *Py: the Journal of the Python Language* http://www.pyzine.com Dr.Dobb's Portal is another source of Python news and articles: http://www.ddj.com/TechSearch/searchResults.jhtml?queryText=python and Python articles regularly appear at IBM DeveloperWorks: http://www.ibm.com/developerworks/search/searchResults.jsp?searchSite=dW&searchScope=dW&encodedQuery=python&rankprofile=8 Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://search.gmane.org/?query=python+URL+weekly+news+links&group=gmane.comp.python.general&sort=date http://groups.google.com/groups/search?q=Python-URL!+group%3Acomp.lang.python&start=0&scoring=d& http://lwn.net/Search/DoSearch?words=python-url&ctype3=yes&cat_25=yes There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". Write to the same address to unsubscribe. -- The Python-URL! Team-- Phaseit, Inc. (http://phaseit.net) is pleased to participate in and sponsor the "Python-URL!" project. Watch this space for upcoming news about posting archives. From michele.simionato at gmail.com Tue Feb 17 11:46:02 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Tue, 17 Feb 2009 08:46:02 -0800 (PST) Subject: Is there something easier than ORM? References: <07cb23ac-3f67-45f2-a1ba-9fb80510db9b@z28g2000prd.googlegroups.com> Message-ID: On Feb 17, 5:35?pm, Philip Semanchuk wrote: > > I don't intend this as a criticism of SqlAlchemy. On the contrary I am ? > impressed by what it does. But I often see people promoting ORM as the ? > solution to all database access problems, and I certainly don't feel ? > like it is. I am also not a big fan of ORM, especially in situations where you have performance issues and you are using database specific features. In such situations you don't care about portability, but you care about having your SQL explicit, so that you can run it directly under the profiler. From mail at timgolden.me.uk Tue Feb 17 11:50:52 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 17 Feb 2009 16:50:52 +0000 Subject: Is there something easier than ORM? In-Reply-To: <8C9A6CB8-80A6-4E10-8EA1-3C40EAED058D@semanchuk.com> References: <07cb23ac-3f67-45f2-a1ba-9fb80510db9b@z28g2000prd.googlegroups.com> <8C9A6CB8-80A6-4E10-8EA1-3C40EAED058D@semanchuk.com> Message-ID: <499AEAEC.30902@timgolden.me.uk> Philip Semanchuk wrote: [... snip comments on SqlAlchemy which could likewise apply to other similar offerings ...] > I don't intend this as a criticism of SqlAlchemy. On the contrary I am > impressed by what it does. But I often see people promoting ORM as the > solution to all database access problems, and I certainly don't feel > like it is. I'm with you: I'm very glad that so many people find SA (and Storm and Mother & SQLObject etc. useful). Personally, I earn my living designing, maintaining and coding for relational databases and I'm simply more at home in native SQL. If you're on Windows, pyodbc offers you a general spread of databases and has quite a few conveniences such as named rows returned; it's fairly robust and is actively maintained. I imagine that most people who do this kind of thing long ago put together a simple wrapper module (mine's imaginatively called "sql") which does just enough to be useful but then gets out the way. All that said, if you don't *want* to have to think about SQL then something like SA + Elixir is about as useful a combination as I've found. TJG From andrew at acooke.org Tue Feb 17 11:52:56 2009 From: andrew at acooke.org (andrew cooke) Date: Tue, 17 Feb 2009 13:52:56 -0300 (CLST) Subject: Is there something easier than ORM? In-Reply-To: <8C9A6CB8-80A6-4E10-8EA1-3C40EAED058D@semanchuk.com> References: <07cb23ac-3f67-45f2-a1ba-9fb80510db9b@z28g2000prd.googlegroups.com> <8C9A6CB8-80A6-4E10-8EA1-3C40EAED058D@semanchuk.com> Message-ID: <49f712d8783aa02d9f76692f11e1b1b9.squirrel@localhost> Philip Semanchuk wrote: > In short, I gather that others on this list are a lot more fond of > SqlAlchemy and ORMs in general than I am. Granted, my experience is > very limited. I tried to integrate SqlAlchemy in one project, > struggled for a long time to express how I wanted my tables joined, > and finally found that performance was bad compared to our homegrown > SQL. My boss and I were both very comfortable with SQL and were happy > to go back to writing our own SQL statements and coding a data access > layer. > > I don't intend this as a criticism of SqlAlchemy. On the contrary I am > impressed by what it does. But I often see people promoting ORM as the > solution to all database access problems, and I certainly don't feel > like it is. the reason i, at least, like sqlalchemy so much is for exactly the reasons you outlined. unlike other orm solutions it doesn't force you to use orm. you can also use sql directly - either as simple strings or by constructing it via python methods (which can be a very powerful way of programatically constructing sql commands that would be a nightmare to write by hand). that gives you the flexibility to deal with each problem in the way that feels most natural, without having to switch between tools (in fact, i have mixed orm and "direct" sql in a single project with no problems using sqlalchemy - reading from one database using sql and writing to another using objects). andrew From gert.cuykens at gmail.com Tue Feb 17 11:55:13 2009 From: gert.cuykens at gmail.com (gert) Date: Tue, 17 Feb 2009 08:55:13 -0800 (PST) Subject: Threading and tkinter Message-ID: <492d5db9-3681-4ae8-827e-f2a4f66bee80@v39g2000yqm.googlegroups.com> After reading the docs and seeing a few examples i think this should work ? Am I forgetting something here or am I doing something stupid ? Anyway I see my yellow screen, that has to count for something :) from tkinter import * from threading import Thread class Weegbrug(Thread): def __init__(self,v): self.v=v Thread.__init__(self) def run(self): while True: with open('com1','r') as f: for line in f: self.v.set(line[2:-1]) root = Tk() v = StringVar() v.set("00000") w = Weegbrug(v) w.start() tx = Label(root, textvariable=v, width=800, height=600, bg="yellow", font=("Helvetica", 300)) tx.pack(expand=YES, fill=BOTH) root.title("Weegbrug") root.overrideredirect(1) root.geometry("%dx%d+0+0" % (root.winfo_screenwidth(), root.winfo_screenheight())) root.mainloop() From lists at cheimes.de Tue Feb 17 11:55:46 2009 From: lists at cheimes.de (Christian Heimes) Date: Tue, 17 Feb 2009 17:55:46 +0100 Subject: Will multithreading make python less popular? In-Reply-To: <6c29ea7b-d30e-4358-8a3f-54758b1f4cde@o11g2000yql.googlegroups.com> References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <9c001ccd-24cb-4bbd-af31-94ad0f255982@z1g2000yqn.googlegroups.com> <6c29ea7b-d30e-4358-8a3f-54758b1f4cde@o11g2000yql.googlegroups.com> Message-ID: rushenaly at gmail.com wrote: > As you mentioned, using multi cores makes programs more fast and more > popular. But what about stackless python? Does it interpret same set > of python libraries with Cpython or Does it have a special sub set? Your assumption is wrong. Multiple cores are able to speed up some kind of programs. But they don't necessarily increase the speed of every program. Lot's of programs are IO bound (hard disk IO, network IO, memory IO). Multiple CPU cores don't increase the speed of your hard disk! Lots of algorithms are not designed for parallel computing. New algorithms must be invented from the ground up. In fact multiple CPUs can decrease the speed of a program because every additional CPU increases the cost for house keeping and cache invalidation. Please don't believe in marketing lies, neither 64bit nor multiple CPUs magically increase the speed of your computer. It's going to take at least half a decade until the tools for multi core development are working properly and reliable. Christian From bearophileHUGS at lycos.com Tue Feb 17 12:00:49 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Tue, 17 Feb 2009 09:00:49 -0800 (PST) Subject: Speedup Bitmap Parser References: <58aed622-cf81-4747-ac54-86badef1c8dc@s20g2000yqh.googlegroups.com> <4c467175-092f-423d-8c0c-cdbffc8579c4@c12g2000yqj.googlegroups.com> <12765e3f-a324-4621-b110-b40bd57acff0@s20g2000yqh.googlegroups.com> <5b94254a-e8ea-469d-8e07-2f3dc778baa8@v39g2000yqm.googlegroups.com> Message-ID: <41a631e9-9e57-45f0-9ec1-835114e3f3de@l39g2000yqn.googlegroups.com> Jayson Santos: > After changing my code to use only functions instead classes > my code is too much faster. > Here cProfile statistcs: > Using old code : 633608 function calls in 1.361 CPU seconds > Using new code: 475487 function calls in 0.800 CPU seconds If you show a pastebin of the new version (you can also paste it, for reference for future people, when the pastebin will be deleted), probably there are ways to improve it more. And I also suggest you to try Psyco. (Someone recently has shown here a compiled version for Windows of Psyco for Python 2.6). Bye, bearophile From vedrandekovic at gmail.com Tue Feb 17 12:02:36 2009 From: vedrandekovic at gmail.com (vedrandekovic at gmail.com) Date: Tue, 17 Feb 2009 09:02:36 -0800 (PST) Subject: wxPython and Croatian characters References: <08c279c8-7934-4dff-b657-73dc12e3dfa3@o36g2000yqh.googlegroups.com> <14f11397-7db3-4cf2-9d19-5038ef86dc3b@o40g2000prn.googlegroups.com> Message-ID: <2a3da6d9-3725-4152-aff8-4bbb33e31cc0@v38g2000yqb.googlegroups.com> On 17 velj, 00:09, "alejandro" wrote: > Provjeri da si nisi stavio ansii kada si instalirao wx.python. > Mozes probat ubacit iznad svega u fajlu komentar u kojem pise da je fajl u > UTF-8 i onda bi ti trebalo sljakat. Nadem sutra pa ti posaljem Pozdrav / Hello, It works now, all post were very useful, but now i have same problem with python MySQLdb. I want data that I got from wxPython TextCtrl write to MySQL database, but I don't know how to configure it. Any examples? Regards, John From oamram at gmail.com Tue Feb 17 12:03:06 2009 From: oamram at gmail.com (oamram) Date: Tue, 17 Feb 2009 09:03:06 -0800 (PST) Subject: Reading from text Message-ID: <22061427.post@talk.nabble.com> Hi All, new to python. i have a directory with about 50 text file and i need to iterate through them and get line 7 to 11 from each file and write those lines into another file(one file that will contain all lines). Cheers, Omer. -- View this message in context: http://www.nabble.com/Reading-from-text-tp22061427p22061427.html Sent from the Python - python-list mailing list archive at Nabble.com. From philip at semanchuk.com Tue Feb 17 12:08:29 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 17 Feb 2009 12:08:29 -0500 Subject: Threads vs. processes, what to consider in choosing ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF60E687DA5@enbmail01.lsi.com> References: <20090217070546.5442B4A12D2@riobu.com> <7F0503CD69378F49BE0DC30661C6CCF60E687DA5@enbmail01.lsi.com> Message-ID: <8FEC3A08-25FA-421E-9FDA-F960A7AD99BC@semanchuk.com> On Feb 17, 2009, at 10:18 AM, Barak, Ron wrote: > I have a wxPython application that builds an internal database from > a list of files and then displays various aspects of that data, > in response to user's requests. > > I want to add a module that finds events in a set of log files > (LogManager). > These log files are potentially huge, and the initial processing is > lengthy (several minutes). > Thus, when the user will choose LogManager, it would be unacceptable > to block the other parts of the program, and so - the initial > LogManager processing > would need to be done separately from the normal run of the program. > Once the initial processing is done, the main program would be > notified and could display the results of LogManager processing. > > I was thinking of either using threads, or using separate processes, > for the main programs and LogManager. > > What would you suggest I should consider in choosing between the two > options ? > Are there other options besides threads and multi-processing ? Hi Ron, The general rule is that it is a lot easier to share data between threads than between processes. The multiprocessing library makes the latter easier but is only part of the standard library in Python >= 2.6. The design of your application matters a lot. For instance, will the processing code write its results to a database, ping the GUI code and then exit, allowing the GUI to read the database? That sounds like an excellent setup for processes. In addition, there's the GIL to consider. Multi-process applications aren't affected by it while multi-threaded applications may be. In these days where multi-processor/multi-core machines are more common, this fact is ever more important. Torrents of words have been written about the GIL on this list and elsewhere and I have nothing useful to add to the torrents. I encourage you to read some of those conversations. FWIW, when I was faced with a similar setup, I went with multiple processes rather than threads. Last but not least, since you asked about alternatives to threads and multiprocessing, I'll point you to some low level libraries I wrote for doing interprocess communication: http://semanchuk.com/philip/posix_ipc/ http://semanchuk.com/philip/sysv_ipc/ Good luck Philip From robert.kern at gmail.com Tue Feb 17 12:10:25 2009 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 17 Feb 2009 11:10:25 -0600 Subject: Is there something easier than ORM? In-Reply-To: <49f712d8783aa02d9f76692f11e1b1b9.squirrel@localhost> References: <07cb23ac-3f67-45f2-a1ba-9fb80510db9b@z28g2000prd.googlegroups.com> <8C9A6CB8-80A6-4E10-8EA1-3C40EAED058D@semanchuk.com> <49f712d8783aa02d9f76692f11e1b1b9.squirrel@localhost> Message-ID: On 2009-02-17 10:52, andrew cooke wrote: > Philip Semanchuk wrote: >> In short, I gather that others on this list are a lot more fond of >> SqlAlchemy and ORMs in general than I am. Granted, my experience is >> very limited. I tried to integrate SqlAlchemy in one project, >> struggled for a long time to express how I wanted my tables joined, >> and finally found that performance was bad compared to our homegrown >> SQL. My boss and I were both very comfortable with SQL and were happy >> to go back to writing our own SQL statements and coding a data access >> layer. >> >> I don't intend this as a criticism of SqlAlchemy. On the contrary I am >> impressed by what it does. But I often see people promoting ORM as the >> solution to all database access problems, and I certainly don't feel >> like it is. > > the reason i, at least, like sqlalchemy so much is for exactly the reasons > you outlined. unlike other orm solutions it doesn't force you to use orm. > you can also use sql directly - either as simple strings or by > constructing it via python methods (which can be a very powerful way of > programatically constructing sql commands that would be a nightmare to > write by hand). that gives you the flexibility to deal with each problem > in the way that feels most natural, without having to switch between tools > (in fact, i have mixed orm and "direct" sql in a single project with no > problems using sqlalchemy - reading from one database using sql and > writing to another using objects). Me, too! I have often used SQLAlchemy as "a better DB-API" even if I don't touch its ORM. I really don't know what I would have done in my past projects without SQLAlchemy's table reflection and metadata introspection capabilities. It does suffer some from TMTOWTDI, but there's usually a valid use case floating around somewhere for each WTDI. Its public image definitely suffers from the impression that it's "an ORM" that can be compared on equal terms with packages that actually are just ORMs. I describe it as a very powerful toolkit for solving a wide variety of problems involving SQL databases. One of those tools happens to be an ORM. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From zorro at chez.Com Tue Feb 17 12:12:07 2009 From: zorro at chez.Com (JB) Date: Tue, 17 Feb 2009 18:12:07 +0100 Subject: Reading from text In-Reply-To: References: Message-ID: <499aefe5$0$3510$426a74cc@news.free.fr> oamram a ?crit : > Hi All, > new to python. i have a directory with about 50 text file and i need to > iterate through them and get > line 7 to 11 from each file and write those lines into another file(one file > that will contain all lines). First create a function that read and parse one file Then create a loop that call this function for each file in a directory Modules to read : http://www.python.org/doc/2.5.2/tut/node9.html#SECTION009210000000000000000 http://docs.python.org/library/os.html Julien From Krzysztof.Retel at googlemail.com Tue Feb 17 12:16:08 2009 From: Krzysztof.Retel at googlemail.com (kretel) Date: Tue, 17 Feb 2009 09:16:08 -0800 (PST) Subject: A python versioning scheme for modules, patches, softwares etc. Message-ID: There exist a number of versioning schemes to keep track of software version. Each developer certainly have it's own style and preferred scheme. However, I am wonder if there is a specific versioning scheme for python modules. Regards, Krzysztof From peter at www.pjb.com.au Tue Feb 17 12:23:26 2009 From: peter at www.pjb.com.au (Peter Billam) Date: 17 Feb 2009 17:23:26 GMT Subject: printing bytes to stdout in Py3 References: Message-ID: On 2009-02-17, Christian Heimes wrote: > Peter Billam schrieb: >> Greetings. (Newbie warning as usual) In Python3, sys.stdout is a >> io.TextIOWrapper object; but I want to output bytes >> (e.g. muscript -midi t > t.mid ) >> and they're coming out stringified :-( How can I either change the >> encoding on sys.stdout, or close sys.stdout and reopen it in 'b' >> mode, or dup(fd) it first, or whatever the right thing to do is ? > > The official API to write binary data to stdout is: > >>>> count = sys.stdout.buffer.write(b"abc\n") > abc That's the one that works the best for me :-) Thanks for all the suggestions! Regards, Peter -- Peter Billam www.pjb.com.au www.pjb.com.au/comp/contact.html From robert.kern at gmail.com Tue Feb 17 12:31:00 2009 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 17 Feb 2009 11:31:00 -0600 Subject: A python versioning scheme for modules, patches, softwares etc. In-Reply-To: References: Message-ID: On 2009-02-17 11:16, kretel wrote: > There exist a number of versioning schemes to keep track of software > version. Each developer certainly have it's own style and preferred > scheme. However, I am wonder if there is a specific versioning scheme > for python modules. A number of Python tools that manipulate Python packages use the version number parsing code in distutils.version, so it would be a good idea to use version numbers it can parse. From the docstring of the StrictVersion class in that module: """Version numbering for anal retentives and software idealists. Implements the standard interface for version number classes as described above. A version number consists of two or three dot-separated numeric components, with an optional "pre-release" tag on the end. The pre-release tag consists of the letter 'a' or 'b' followed by a number. If the numeric components of two version numbers are equal, then one with a pre-release tag will always be deemed earlier (lesser) than one without. The following are valid version numbers (shown in the order that would be obtained by sorting according to the supplied cmp function): 0.4 0.4.0 (these two are equivalent) 0.4.1 0.5a1 0.5b3 0.5 0.9.6 1.0 1.0.4a3 1.0.4b1 1.0.4 The following are examples of invalid version numbers: 1 2.7.2.2 1.3.a4 1.3pl1 1.3c4 The rationale for this version numbering system will be explained in the distutils documentation. """ You probably want to do release candidates, too, and the "1.3c4" format is really quite useful for that. In reality, people usually use LooseVersion from that module to parse version numbers, and it will accept "1.3c4". But it also accepts a whole lot of version number formats that I would not recommend that you use. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From lists at cheimes.de Tue Feb 17 12:33:41 2009 From: lists at cheimes.de (Christian Heimes) Date: Tue, 17 Feb 2009 18:33:41 +0100 Subject: printing bytes to stdout in Py3 In-Reply-To: References: Message-ID: Casey wrote: > Is this really the 'official' way to do this? This isn't meant to be > confrontational or trolling; I honestly don't know the answer and I > had similar questions when I first started with the 3.0 release > candidates and I have yet to find a good answer in the Python v3.0 > documentation. Yes, it's really the official way. You can google up the discussion between me and Guido on the python-dev list if you don't trust me. ;) The docs concur with me, too. http://docs.python.org/3.0/library/sys.html#sys.stdin Note: The standard streams are in text mode by default. To write or read binary data to these, use the underlying binary buffer. For example, to write bytes to stdout, use sys.stdout.buffer.write(b'abc'). > Why wouldn't you just use: > > print(bytes.decode(b'abc\n'), end='') Because it doesn't work with binary data. You can't convert random bytes to unicode. Try that with a JPEG file or even the byte sequence that contains some invalid UTF-8 chars. >>> bytes((255, 255, 255)) b'\xff\xff\xff' >>> bytes((255, 255, 255)).decode() Traceback (most recent call last): File "", line 1, in UnicodeDecodeError: 'utf8' codec can't decode byte 0xff in position 0: unexpected code byte Christian From paul.lemelle at gmail.com Tue Feb 17 12:37:27 2009 From: paul.lemelle at gmail.com (pdl5000) Date: Tue, 17 Feb 2009 09:37:27 -0800 (PST) Subject: Posting multiple files via a web site. Message-ID: I would like to start write a Python script that upload multiple files to a web server. I research the methods, and I am somewhat confused between using the http & urllib2 modules. I assume (and could be wrong) that the most basic method would be to use a cgi-Python script on the web server then use a client script on the local host - is this a bad assumption? And from the cgi script, would it be possible to direct the files to a certain mount point? If so, what method to use? Thanks, Paul From bearophileHUGS at lycos.com Tue Feb 17 12:48:21 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Tue, 17 Feb 2009 09:48:21 -0800 (PST) Subject: Reading from text References: Message-ID: oamram: > i have a directory with about 50 text file and i need to > iterate through them and get > line 7 to 11 from each file and write those lines into another > file(one file that will contain all lines). Files can be iterated line-by-line, so this idiom: for line in file: ... will give you the lines, with newline. Once you have debugged that, you can use the standard module glob (http://docs.python.org/library/ glob.html#module-glob ) to iterate on files. If you have more problems, show use the code you have written and we may suggest improvements. Bye, bearophile From santosdosreis at gmail.com Tue Feb 17 12:52:53 2009 From: santosdosreis at gmail.com (Jayson Santos) Date: Tue, 17 Feb 2009 09:52:53 -0800 (PST) Subject: Speedup Bitmap Parser References: <58aed622-cf81-4747-ac54-86badef1c8dc@s20g2000yqh.googlegroups.com> <4c467175-092f-423d-8c0c-cdbffc8579c4@c12g2000yqj.googlegroups.com> <12765e3f-a324-4621-b110-b40bd57acff0@s20g2000yqh.googlegroups.com> <5b94254a-e8ea-469d-8e07-2f3dc778baa8@v39g2000yqm.googlegroups.com> <41a631e9-9e57-45f0-9ec1-835114e3f3de@l39g2000yqn.googlegroups.com> Message-ID: <5a3cfd4d-7a1c-4afe-a237-60533e8d4f8a@a12g2000yqm.googlegroups.com> On 17 fev, 14:00, bearophileH... at lycos.com wrote: > Jayson Santos: > > > After changing my code to use only functions instead classes > > my code is too much faster. > > Here cProfile statistcs: > > Using old code : 633608 function calls in 1.361 CPU seconds > > Using new code: 475487 function calls in 0.800 CPU seconds > > If you show a pastebin of the new version (you can also paste it, for > reference for future people, when the pastebin will be deleted), > probably there are ways to improve it more. > And I also suggest you to try Psyco. (Someone recently has shown here > a compiled version for Windows of Psyco for Python 2.6). > > Bye, > bearophile I'm using linux with python 2.5 Here is the result using psyco.full(): 93 function calls in 0.243 CPU seconds And here is the final code: http://pastebin.com/f3e20d669 Bye, Jayson From lists at cheimes.de Tue Feb 17 12:58:35 2009 From: lists at cheimes.de (Christian Heimes) Date: Tue, 17 Feb 2009 18:58:35 +0100 Subject: Threads vs. processes, what to consider in choosing ? In-Reply-To: <8FEC3A08-25FA-421E-9FDA-F960A7AD99BC@semanchuk.com> References: <20090217070546.5442B4A12D2@riobu.com> <7F0503CD69378F49BE0DC30661C6CCF60E687DA5@enbmail01.lsi.com> <8FEC3A08-25FA-421E-9FDA-F960A7AD99BC@semanchuk.com> Message-ID: Philip Semanchuk wrote: > The general rule is that it is a lot easier to share data between > threads than between processes. The multiprocessing library makes the > latter easier but is only part of the standard library in Python >= 2.6. > The design of your application matters a lot. For instance, will the > processing code write its results to a database, ping the GUI code and > then exit, allowing the GUI to read the database? That sounds like an > excellent setup for processes. A backport for Python 2.4 and 2.5 is available on pypi. Python 2.5.4 is recommended though. Christian From google at mrabarnett.plus.com Tue Feb 17 13:00:32 2009 From: google at mrabarnett.plus.com (MRAB) Date: Tue, 17 Feb 2009 18:00:32 +0000 Subject: Reading from text In-Reply-To: References: Message-ID: <499AFB40.6030403@mrabarnett.plus.com> bearophileHUGS at lycos.com wrote: > oamram: >> i have a directory with about 50 text file and i need to >> iterate through them and get >> line 7 to 11 from each file and write those lines into another >> file(one file that will contain all lines). > > Files can be iterated line-by-line, so this idiom: > > for line in file: ... > > will give you the lines, with newline. Once you have debugged that, > you can use the standard module glob (http://docs.python.org/library/ > glob.html#module-glob ) to iterate on files. > [snip] Or: for index, line in enumerate(my_file): ... where index will give you the line number (starting from 0, so you'll want lines 6 to 10). You can break out of the loop when you have all the lines you want. > If you have more problems, show use the code you have written and we > may suggest improvements. > From invalid at invalid Tue Feb 17 13:12:34 2009 From: invalid at invalid (Grant Edwards) Date: Tue, 17 Feb 2009 12:12:34 -0600 Subject: Reading from text References: Message-ID: <5OKdneXdBqSPYwfUnZ2dnUVZ_tPinZ2d@posted.visi> On 2009-02-17, oamram wrote: > i have a directory with about 50 text file and i need to > iterate through them and get line 7 to 11 from each file and > write those lines into another file(one file that will contain > all lines). Assuming this is a real task and not a homework problem, then I'd do it this way: $ cd [directory containing 50 test files] $ (for file in *; do head -n11 $file | tail -n5; done) >/path/to/results-file.txt -- Grant Edwards grante Yow! ... My pants just went at on a wild rampage through a visi.com Long Island Bowling Alley!! From Caseyweb at gmail.com Tue Feb 17 13:15:09 2009 From: Caseyweb at gmail.com (Casey) Date: Tue, 17 Feb 2009 10:15:09 -0800 (PST) Subject: printing bytes to stdout in Py3 References: Message-ID: <61d3c9df-0123-42ef-a5db-16842fffc25c@l37g2000vba.googlegroups.com> On Feb 17, 12:33?pm, Christian Heimes wrote: > Yes, it's really the official way. You can google up the discussion > between me and Guido on the python-dev list if you don't trust me. ;) > The docs concur with me, too. > > http://docs.python.org/3.0/library/sys.html#sys.stdin > > Note: The standard streams are in text mode by default. To write or read > binary data to these, use the underlying binary buffer. For example, to > write bytes to stdout, use sys.stdout.buffer.write(b'abc'). Thanks! Incidentally, the 'Note:' section you reference in the HTML docs doesn't appear to be in the .CHM file that installs with the windows version of 3.01. That would have made my search a lot easier :-% From lists at cheimes.de Tue Feb 17 13:28:47 2009 From: lists at cheimes.de (Christian Heimes) Date: Tue, 17 Feb 2009 19:28:47 +0100 Subject: printing bytes to stdout in Py3 In-Reply-To: <61d3c9df-0123-42ef-a5db-16842fffc25c@l37g2000vba.googlegroups.com> References: <61d3c9df-0123-42ef-a5db-16842fffc25c@l37g2000vba.googlegroups.com> Message-ID: Casey schrieb: > On Feb 17, 12:33 pm, Christian Heimes wrote: >> Yes, it's really the official way. You can google up the discussion >> between me and Guido on the python-dev list if you don't trust me. ;) >> The docs concur with me, too. >> >> http://docs.python.org/3.0/library/sys.html#sys.stdin >> >> Note: The standard streams are in text mode by default. To write or read >> binary data to these, use the underlying binary buffer. For example, to >> write bytes to stdout, use sys.stdout.buffer.write(b'abc'). > > Thanks! Incidentally, the 'Note:' section you reference in the HTML > docs doesn't appear to be in the .CHM file that installs with the > windows version of 3.01. That would have made my search a lot > easier :-% Oh, that should not happen. Please report this bug! Christian From Scott.Daniels at Acm.Org Tue Feb 17 13:31:07 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 17 Feb 2009 10:31:07 -0800 Subject: printing bytes to stdout in Py3 In-Reply-To: References: Message-ID: Casey wrote: > ... Is this the 'official' way to do this?... Why wouldn't you just use: > print(bytes.decode(b'abc\n'), end='') Because that code is incapable of sending bytes that cannot be interpreted as encoded in the "default" encoding. If you are sending a picture, for example, all possible byte sequences might show up. If the default encoding is "utf-8", for example, there are byte sequences which are illegal. I suspect you are confused by thinking each byte must map to a character; such an encoding could never suffice for Chinese, for example. --Scott David Daniels Scott.Daniels at Acm.Org From bearophileHUGS at lycos.com Tue Feb 17 13:35:40 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Tue, 17 Feb 2009 10:35:40 -0800 (PST) Subject: Speedup Bitmap Parser References: <58aed622-cf81-4747-ac54-86badef1c8dc@s20g2000yqh.googlegroups.com> <4c467175-092f-423d-8c0c-cdbffc8579c4@c12g2000yqj.googlegroups.com> <12765e3f-a324-4621-b110-b40bd57acff0@s20g2000yqh.googlegroups.com> <5b94254a-e8ea-469d-8e07-2f3dc778baa8@v39g2000yqm.googlegroups.com> <41a631e9-9e57-45f0-9ec1-835114e3f3de@l39g2000yqn.googlegroups.com> <5a3cfd4d-7a1c-4afe-a237-60533e8d4f8a@a12g2000yqm.googlegroups.com> Message-ID: <8344eb45-c8ed-4513-9eaf-4fb1a4eba87b@v42g2000yqj.googlegroups.com> Jayson Santos: > And here is the final code:http://pastebin.com/f3e20d669 Note that if you use Psyco this lookup trick isn't useful, but if the Psyco isn't available it can improve performance a little: append = BitmapList['lines'].append I suggest to replace this code: red, green, blue = struct.unpack('BBB', s[i:i+3]) append({ 'red': red, 'green': green, 'blue': blue, }) With something just like: rbg = struct.unpack('BBB', s[i:i+3]) Later you can access r g and b by their position, avoiding the allocation and creation of a new dict for each pixel. (array.array too is able to do that, but using unpack is probably fine too. Using an array.array you can probably decode many rbg triples in a single time, and slice it later, this looks faster). In the following code: if __name__ == '__main__': ... ... for line in BitmapList['lines']: for x, color in enumerate(line): ... note that Psyco is able to compile code only if it's inside functions or methods, so it may give a bit of improvement if you move such loops into a function. I don't know if Psyco is already able to compile enumerate(), if not, then replacing the enumerate with a manual counter speeds up the code. I think ShedSkin doesn't have the struct module yet, once someone has written such standard module, you can probably produce a compiled (C+ +) module with your code that 10-50 times faster than the original Python code, with no changes in the Python code itself :-) Bye, bearophile From python.list at tim.thechases.com Tue Feb 17 13:44:07 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 17 Feb 2009 12:44:07 -0600 Subject: Reading from text In-Reply-To: <5OKdneXdBqSPYwfUnZ2dnUVZ_tPinZ2d@posted.visi> References: <5OKdneXdBqSPYwfUnZ2dnUVZ_tPinZ2d@posted.visi> Message-ID: <499B0577.10807@tim.thechases.com> > Assuming this is a real task and not a homework problem, then > I'd do it this way: > > $ cd [directory containing 50 test files] > $ (for file in *; do head -n11 $file | tail -n5; done) >/path/to/results-file.txt I'd use sed: sed -ns 7,11p /source/path/*.txt >/path/to/results.txt hard to get much more concise than that with any common tool :) -tkc From sam at 2000soft.com Tue Feb 17 13:49:08 2009 From: sam at 2000soft.com (Sam Clark) Date: Tue, 17 Feb 2009 10:49:08 -0800 Subject: This application has failed to start because the application configuration is incorrect Message-ID: <822B0E83D23291469317E34324687437022249@production.2000soft.com> I am receiving the message "This application has failed to start because the application configuration is incorrect" when I attempt to run a compiled Python program on another machine. I have used py2exe on both a 2.6.1 and a 2.6.0 version of the .py and .pyw files. Everything works great on the machine where Python 2.6 is loaded, but fails on machines where I copy the .exe to the machine. I'm a beginner at python programming. In fact this is my first packaged program. Any thoughts at a beginners level would be helpful. Thank you, Sam Clark sam at 2000soft.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From noama at answers.com Tue Feb 17 13:53:40 2009 From: noama at answers.com (Noam Aigerman) Date: Tue, 17 Feb 2009 20:53:40 +0200 Subject: Kill a function while it's being executed In-Reply-To: <1233761152.373.14.camel@localhost.localdomain> References: <3eb685e5-dc80-41d0-acc2-2cafe0cb65c5@e18g2000yqo.googlegroups.com><6827582d-26ce-4245-88dd-d24955dc9f3a@x16g2000prn.googlegroups.com><1e7b7458-26f1-4ae6-b4d0-02dfbfc2cef3@l42g2000yqe.googlegroups.com><49897C95.1000301@wildenhain.de><749CACF29BDFB64E9F80189ECD77868804C00682@jermail1.atomant.net> <1233761152.373.14.camel@localhost.localdomain> Message-ID: <749CACF29BDFB64E9F80189ECD77868804E87A09@jermail1.atomant.net> Hi, Sorry for resurrecting an old thread, but it just bothers me that this is the best way that python has to deal with killing running functions... it's quite an ugly hack, no? Is it a feature that's needed bit missing from python, or is it left out on purpose (same way like java has deprecated thread.stop and thread.suspend because they were not safe)? Thanks, Noam -----Original Message----- From: python-list-bounces+noama=answers.com at python.org [mailto:python-list-bounces+noama=answers.com at python.org] On Behalf Of Albert Hopkins Sent: Wednesday, February 04, 2009 5:26 PM To: python-list at python.org Subject: Re: Kill a function while it's being executed On Wed, 2009-02-04 at 13:40 +0200, Noam Aigerman wrote: > Hi All, > I have a script in which I receive a list of functions. I iterate over > the list and run each function. This functions are created by some other > user who is using the lib I wrote. Now, there are some cases in which > the function I receive will never finish (stuck in infinite loop). > Suppose I use a thread which times the amount of time passed since the > function has started, Is there some way I can kill the function after a > certain amount of time has passed (without asking the user who's giving > me the list of functions to make them all have some way of notifying > them to finish)? > Thanks, Noam Noam, did you hijack a thread? You could decorate the functions with a timeout function. Here's one that I either wrote or copied from a recipe (can't recall): class FunctionTimeOut(Exception): pass def function_timeout(seconds): """Function decorator to raise a timeout on a function call""" import signal def decorate(f): def timeout(signum, frame): raise FunctionTimeOut() def funct(*args, **kwargs): old = signal.signal(signal.SIGALRM, timeout) signal.alarm(seconds) try: result = f(*args, **kwargs) finally: signal.signal(signal.SIGALRM, old) signal.alarm(0) return result return funct return decorate Then func_dec = function_timeout(TIMEOUT_SECS) for func in function_list: timeout_function = func_dec(func) try: timeout_function(...) except FunctionTimeout: ... -a -- http://mail.python.org/mailman/listinfo/python-list From martin at v.loewis.de Tue Feb 17 13:54:11 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 17 Feb 2009 19:54:11 +0100 Subject: Is there something easier than ORM? In-Reply-To: <07cb23ac-3f67-45f2-a1ba-9fb80510db9b@z28g2000prd.googlegroups.com> References: <07cb23ac-3f67-45f2-a1ba-9fb80510db9b@z28g2000prd.googlegroups.com> Message-ID: <499b07d3$0$677$9b622d9e@news.freenet.de> > So is there some libraries like that? I always use a DB-API implementation for the database I use, i.e. psycopg/psycopg2. Named tuples are really easy to provide: class NamedTuple: def __init__(self, names, values): for name, value in izip(names, values): setattr(self, name, value) person_rows = "first last age".split() def get_person(conn, id): conn.execute("select first, last, age from person where id=%d" % (id,)) return NamedTuple(person_rows, conn.fetchone()) Regards, Martin From Krzysztof.Retel at googlemail.com Tue Feb 17 14:00:15 2009 From: Krzysztof.Retel at googlemail.com (kretel) Date: Tue, 17 Feb 2009 11:00:15 -0800 (PST) Subject: A python versioning scheme for modules, patches, softwares etc. References: Message-ID: <2ccc7988-53ca-4329-b4ab-a63e95defaba@j1g2000yqi.googlegroups.com> On Feb 17, 5:31?pm, Robert Kern wrote: > On 2009-02-17 11:16, kretel wrote: > > > There exist a number of versioning schemes to keep track of software > > version. Each developer certainly have it's own style and preferred > > scheme. However, I am wonder if there is a specific versioning scheme > > for python modules. > > A number of Python tools that manipulate Python packages use the version number > parsing code in distutils.version, so it would be a good idea to use version > numbers it can parse. From the docstring of the StrictVersion class in that module: > > ? ? ?"""Version numbering for anal retentives and software idealists. > ? ? ?Implements the standard interface for version number classes as > ? ? ?described above. ?A version number consists of two or three > ? ? ?dot-separated numeric components, with an optional "pre-release" tag > ? ? ?on the end. ?The pre-release tag consists of the letter 'a' or 'b' > ? ? ?followed by a number. ?If the numeric components of two version > ? ? ?numbers are equal, then one with a pre-release tag will always > ? ? ?be deemed earlier (lesser) than one without. > > ? ? ?The following are valid version numbers (shown in the order that > ? ? ?would be obtained by sorting according to the supplied cmp function): > > ? ? ? ? ?0.4 ? ? ? 0.4.0 ?(these two are equivalent) > ? ? ? ? ?0.4.1 > ? ? ? ? ?0.5a1 > ? ? ? ? ?0.5b3 > ? ? ? ? ?0.5 > ? ? ? ? ?0.9.6 > ? ? ? ? ?1.0 > ? ? ? ? ?1.0.4a3 > ? ? ? ? ?1.0.4b1 > ? ? ? ? ?1.0.4 > > ? ? ?The following are examples of invalid version numbers: > > ? ? ? ? ?1 > ? ? ? ? ?2.7.2.2 > ? ? ? ? ?1.3.a4 > ? ? ? ? ?1.3pl1 > ? ? ? ? ?1.3c4 > > ? ? ?The rationale for this version numbering system will be explained > ? ? ?in the distutils documentation. > ? ? ?""" > > You probably want to do release candidates, too, and the "1.3c4" format is > really quite useful for that. In reality, people usually use LooseVersion from > that module to parse version numbers, and it will accept "1.3c4". But it also > accepts a whole lot of version number formats that I would not recommend that > you use. > > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless enigma > ? that is made terrible by our own mad attempt to interpret it as though it had > ? an underlying truth." > ? ?-- Umberto Eco Thanks for pointing this out. Krzysztof From Scott.Daniels at Acm.Org Tue Feb 17 14:01:00 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 17 Feb 2009 11:01:00 -0800 Subject: print string as raw string In-Reply-To: <01aaa153$0$20629$c3e8da3@news.astraweb.com> References: <6vvifkFm4k0vU1@mid.uni-berlin.de> <01aaa153$0$20629$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Diez B. Roggisch wrote: > >> Mirko Dziadzka schrieb: >>> I'm trying to find a way to output strings in the raw-string format, e.g. >>> print_as_raw_string(r"\.") should output r"\." instead of "\\." ... > In any case, this is just a variation of what repr() does. >>>> repr(r'\.') > "'\\\\.'" > > What the OP seems to want is something like:... a barely tested version: > > def raw_repr(s): > """Return the repr of string s as a raw-string.""" > r = repr(s) > if '\\\\' in r: > r = "r" + r.replace('\\\\', '\\') > assert not r.endswith('\\') > return r ... The big issue I see is that lots of values cannot be represented as raw strings. Your code checks for a final '\', but many "control" characters and the quote marks are also at issue. raw_repr('["\']a\x13\xfebc\\de') should contain several nasty cases. --Scott David Daniels Scott.Daniels at Acm.Org From invalid at invalid Tue Feb 17 14:03:00 2009 From: invalid at invalid (Grant Edwards) Date: Tue, 17 Feb 2009 13:03:00 -0600 Subject: Reading from text References: <5OKdneXdBqSPYwfUnZ2dnUVZ_tPinZ2d@posted.visi> Message-ID: On 2009-02-17, Tim Chase wrote: >> Assuming this is a real task and not a homework problem, then >> I'd do it this way: >> >> $ cd [directory containing 50 test files] >> $ (for file in *; do head -n11 $file | tail -n5; done) >/path/to/results-file.txt > > I'd use sed: > > sed -ns 7,11p /source/path/*.txt >/path/to/results.txt Well done. -- Grant Edwards grante Yow! does your DRESSING at ROOM have enough ASPARAGUS? visi.com From kyosohma at gmail.com Tue Feb 17 14:10:01 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Tue, 17 Feb 2009 11:10:01 -0800 (PST) Subject: wxPython and Croatian characters References: <08c279c8-7934-4dff-b657-73dc12e3dfa3@o36g2000yqh.googlegroups.com> <14f11397-7db3-4cf2-9d19-5038ef86dc3b@o40g2000prn.googlegroups.com> <2a3da6d9-3725-4152-aff8-4bbb33e31cc0@v38g2000yqb.googlegroups.com> Message-ID: <025d02e6-2b71-42e3-9ba2-f09ef293ac5f@o36g2000yqh.googlegroups.com> On Feb 17, 11:02?am, vedrandeko... at gmail.com wrote: > On 17 velj, 00:09, "alejandro" wrote: > > > Provjeri da si nisi stavio ansii kada si instalirao wx.python. > > Mozes probat ubacit iznad svega u fajlu komentar u kojem pise da je fajl u > > UTF-8 i onda bi ti trebalo sljakat. Nadem sutra pa ti posaljem > > Pozdrav / Hello, > > It works now, all post were very useful, but now i have same problem > with python MySQLdb. I want data that I got from > wxPython TextCtrl write to MySQL database, but I don't know how to > configure it. > > Any examples? > > Regards, > John You'll need to look at the python database connector's docs and/or MySQL's docs to know how to do that. It would help to know what you are using to connect to the database: pyodbc, adodb, sqlalchemy? Most of those packages have their own mailing lists, but you're welcome to post here too. Mike From robert.kern at gmail.com Tue Feb 17 14:25:09 2009 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 17 Feb 2009 13:25:09 -0600 Subject: Kill a function while it's being executed In-Reply-To: <749CACF29BDFB64E9F80189ECD77868804E87A09@jermail1.atomant.net> References: <3eb685e5-dc80-41d0-acc2-2cafe0cb65c5@e18g2000yqo.googlegroups.com><6827582d-26ce-4245-88dd-d24955dc9f3a@x16g2000prn.googlegroups.com><1e7b7458-26f1-4ae6-b4d0-02dfbfc2cef3@l42g2000yqe.googlegroups.com><49897C95.1000301@wildenhain.de><749CACF29BDFB64E9F80189ECD77868804C00682@jermail1.atomant.net> <1233761152.373.14.camel@localhost.localdomain> <749CACF29BDFB64E9F80189ECD77868804E87A09@jermail1.atomant.net> Message-ID: On 2009-02-17 12:53, Noam Aigerman wrote: > Hi, > Sorry for resurrecting an old thread, but it just bothers me that this > is the best way that python has to deal with killing running > functions... it's quite an ugly hack, no? > > Is it a feature that's needed bit missing from python, or is it left out > on purpose (same way like java has deprecated thread.stop and > thread.suspend because they were not safe)? Left out on purpose because it is not safe. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From Olivier.Darge at gmail.com Tue Feb 17 14:29:19 2009 From: Olivier.Darge at gmail.com (OdarR) Date: Tue, 17 Feb 2009 11:29:19 -0800 (PST) Subject: flexible find and replace ? References: <18d1b669-7a79-4295-a1e2-4693d361d0af@v13g2000yqm.googlegroups.com> Message-ID: <1d0c328a-17ce-483d-8b79-e098770df0db@o11g2000yql.googlegroups.com> Thanks to everybody. I need to test your propositions now :) Olivier From john106henry at hotmail.com Tue Feb 17 14:37:26 2009 From: john106henry at hotmail.com (John Henry) Date: Tue, 17 Feb 2009 11:37:26 -0800 (PST) Subject: Invoking CutePDF from within Python References: <590ed3f4-089a-41d7-aaa2-6d96f5ea1fa9@j39g2000yqn.googlegroups.com> Message-ID: On Feb 13, 3:15?am, cm wrote: > Hi John,> All I need is to say "Print this to CUTEPDF and store as xyz.pdf". > > I can't answer you question but let me make a suggestion: Try > PdfCreator. It lets you control all the process using an activex > control. It has events to tell you when the jobs has finish, or report > you of eventual errors. > > Download it from sf.net, and look into the samples. > > Best regards, > > Carlos. Thank you for your (and others') response. TJG's VB script translation was correct but the script failed to invoke CutePDF. So, I downloaded PDFCreator as suggested. I used the create test page example and it worked right away. Thanks for the help. From python at bdurham.com Tue Feb 17 15:00:19 2009 From: python at bdurham.com (python at bdurham.com) Date: Tue, 17 Feb 2009 15:00:19 -0500 Subject: List of locale values for locale.setlocale() under Windows Message-ID: <1234900820.29552.1300909493@webmail.messagingengine.com> I'm experimenting with the locale module and have been unable to get the documentation examples to run on Windows XP. (The examples run fine on Linux). In particular, none of the locale.setlocale( category, locale )'s sample locale parameter values are considered valid. Example: >>> locale.setlocale( locale.LC_ALL, 'fr_FR' ) Traceback (most recent call last): File "", line 1, in locale.setlocale( locale.LC_ALL, 'fr_FR' ) File "c:\python26\lib\locale.py", line 494, in setlocale return _setlocale(category, locale) Error: unsupported locale setting The documentation states that these values "may vary across platforms". Here's what I get for my current locale: >>> locale.getlocale() ('English_United States', '1252') Any suggestions on where I can find the official list of locale codes for Windows XP (or better yet, all versions of Windows XP or later)? Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From jervisau at gmail.com Tue Feb 17 15:08:04 2009 From: jervisau at gmail.com (Jervis Whitley) Date: Wed, 18 Feb 2009 07:08:04 +1100 Subject: Pythonic way to determine if one char of many in a string In-Reply-To: <01aa9ea5$0$20632$c3e8da3@news.astraweb.com> References: <1234761457.20683.1300568627@webmail.messagingengine.com> <01aa9ea5$0$20632$c3e8da3@news.astraweb.com> Message-ID: <8e63a5ce0902171208p321e8e11wd152a3df6f3680fe@mail.gmail.com> > > This moves the for-loop out of slow Python into fast C and should be much, > much faster for very large input. > _Should_ be faster. Here is my test on an XP system Python 2.5.4. I had similar results on python 2.7 trunk. WORD = 'g' * 100 WORD2 = 'g' * 50 + 'U' BIGWORD = 'g' * 10000 + 'U' def any_test(word): return any(vowel in word for vowel in 'aeiouAEIOU') def for_test(word): for vowel in 'aeiouAEIOU': if vowel in word: return True else: return False **no vowels** any: [0.36063678618957751, 0.36116506191682773, 0.36212355395824081] for: [0.24044885376801672, 0.2417684017413404, 0.24084797257163482] **vowel 'U' final char** any: [0.38218764069443112, 0.38431925474244588, 0.38238668882188831] for: [0.16398578356553717, 0.16433223810347286, 0.16593555537176385] **BIG word vowel 'U' final char** any: [8.0007259193539895, 7.9797344140269644, 7.8901742633514012] for: [7.6664422372764101, 7.6784683633957584, 7.6683055766498001] Cheers, From josh.dukes at microvu.com Tue Feb 17 15:19:15 2009 From: josh.dukes at microvu.com (Josh Dukes) Date: Tue, 17 Feb 2009 12:19:15 -0800 Subject: Scanning a file character by character In-Reply-To: <499203C6.9070501@tim.thechases.com> References: <557daab0-504f-47f4-84a7-e98000e7c3b1@y1g2000pra.googlegroups.com> <203f699b-de30-422a-aa7d-97eb62d6ebba@a12g2000pro.googlegroups.com> <499203C6.9070501@tim.thechases.com> Message-ID: <20090217121915.2bfd2859@microvu.com> In [401]: import shlex In [402]: shlex.split("""Joe went to 'the store' where he bought a "box of chocolates" and stuff.""") Out[402]: ['Joe', 'went', 'to', 'the store', 'where', 'he', 'bought', 'a', 'box of chocolates', 'and', 'stuff.'] how's that work for ya? http://docs.python.org/library/shlex.html On Tue, 10 Feb 2009 16:46:30 -0600 Tim Chase wrote: > >> Or for a slightly less simple minded splitting you could try > >> re.split: > >> > >>>>> re.split("(\w+)", "The quick brown fox jumps, and falls > >>>>> over.")[1::2] > >> ['The', 'quick', 'brown', 'fox', 'jumps', 'and', 'falls', 'over'] > > > > > > Perhaps I'm missing something, but the above regex does the exact > > same thing as line.split() except it is significantly slower and > > harder to read. > > > > Neither deal with quoted text, apostrophes, hyphens, punctuation or > > any other details of real-world text. That's what I mean by > > "simple-minded". > > >>> s = "The quick brown fox jumps, and falls over." > >>> import re > >>> re.split(r"(\w+)", s)[1::2] > ['The', 'quick', 'brown', 'fox', 'jumps', 'and', 'falls', 'over'] > >>> s.split() > ['The', 'quick', 'brown', 'fox', 'jumps,', 'and', 'falls', > 'over.'] > > Note the difference in "jumps" vs. "jumps," (extra comma in the > string.split() version) and likewise the period after "over". > Thus not quite "the exact same thing as line.split()". > > I think an easier-to-read variant would be > > >>> re.findall(r"\w+", s) > ['The', 'quick', 'brown', 'fox', 'jumps', 'and', 'falls', 'over'] > > which just finds words. One could also just limit it to letters with > > re.findall("[a-zA-Z]", s) > > as "\w" is a little more encompassing (letters and underscores) > if that's a problem. > > -tkc > > > > > -- > http://mail.python.org/mailman/listinfo/python-list -- Josh Dukes MicroVu IT Department From python.list at tim.thechases.com Tue Feb 17 15:26:17 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 17 Feb 2009 14:26:17 -0600 Subject: Scanning a file character by character In-Reply-To: <20090217121915.2bfd2859@microvu.com> References: <557daab0-504f-47f4-84a7-e98000e7c3b1@y1g2000pra.googlegroups.com> <203f699b-de30-422a-aa7d-97eb62d6ebba@a12g2000pro.googlegroups.com> <499203C6.9070501@tim.thechases.com> <20090217121915.2bfd2859@microvu.com> Message-ID: <499B1D69.3050409@tim.thechases.com> Josh Dukes wrote: > In [401]: import shlex > > In [402]: shlex.split("""Joe went to 'the store' where he bought a "box of chocolates" and stuff.""") > > how's that work for ya? It works great if that's the desired behavior. However, the OP wrote about splitting the lines into separate words, not "treating quoted items as a single word". (OP: "How would I do separate lines into words without scanning one character at a time?") But for pulling out quoted strings as units, the shlex is a great module. -tkc From josh.dukes at microvu.com Tue Feb 17 15:30:43 2009 From: josh.dukes at microvu.com (Josh Dukes) Date: Tue, 17 Feb 2009 12:30:43 -0800 Subject: Putting asterisks around text In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF60E687981@enbmail01.lsi.com> References: <20090209132046.091f5b8a.darcy@druid.net> <7F0503CD69378F49BE0DC30661C6CCF60E687981@enbmail01.lsi.com> Message-ID: <20090217123043.6ad2fb20@microvu.com> > while understand_problem is False: > study("textbook") > > complete("homework") > > if want_help is True: > study("http://www.catb.org/~esr/faqs/smart-questions.html") just a note but "if" and "while" evaluate variables as True or False without a verbose test. e.g.: while not understand_problem: study("textbook") complete("homework") if want_help: study("http://www.catb.org/~esr/faqs/smart-questions.html") Just fyi... -- Josh Dukes MicroVu IT Department From philip at semanchuk.com Tue Feb 17 15:30:52 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 17 Feb 2009 15:30:52 -0500 Subject: Problems with OS X 10.5.6 and Python 2.5 and GDAL 1.6 In-Reply-To: <60437775-ED63-469B-A2CC-913B0E77BC1E@ucsd.edu> References: <60437775-ED63-469B-A2CC-913B0E77BC1E@ucsd.edu> Message-ID: <3A6157F5-DBA7-46B5-89A8-621DF6AB1F56@semanchuk.com> On Feb 16, 2009, at 8:35 PM, Helly John J. wrote: > Hi. > > I'm a newbie to python and am running: > > OS X 10.5.6 > Python 2.5.4 Hi John, Are you using the system Python or have you installed another version? Cheers Philip > > > and have run easy_install for gdal like this: > > /Library/Python/2.5/site-packages>sudo easy_install GDAL > Password: > Searching for GDAL > Best match: GDAL 1.6.0 > Processing GDAL-1.6.0-py2.5-macosx-10.5-i386.egg > GDAL 1.6.0 is already the active version in easy-install.pth > > Using /Library/Python/2.5/site-packages/GDAL-1.6.0-py2.5-macosx-10.5- > i386.egg > Processing dependencies for GDAL > Finished processing dependencies for GDAL > > However, when I run python and try to import gdal, this is what > happens: > > Python 2.5.4 (r254:67917, Dec 23 2008, 14:57:27) > [GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > >>> import gdal > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named gdal > >>> > > Clearly, it's not being found but I don't understand how to debug > this any further. I have the *.egg in the site-packages directory > but don't understand if there is something else I have to do to make > it usable. Any help would be much appreciated. > Cheers. > -------------- > John Helly, University of California, San Diego > San Diego Supercomputer Center, Mail Code 0527 > Scripps Institution of Oceanography, Climate, Atmospheric Science, > and Physical Oceanography, Mail Code 0224 > 9500 Gilman Dr., La Jolla CA 92093 > +01 760 840 8660 mobile / stonesteps (Skype) / stonesteps7 (iChat) / > URL (http://www.sdsc.edu/~hellyj) > > -- > http://mail.python.org/mailman/listinfo/python-list From hyugaricdeau at gmail.com Tue Feb 17 15:31:50 2009 From: hyugaricdeau at gmail.com (Hyuga) Date: Tue, 17 Feb 2009 12:31:50 -0800 (PST) Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> Message-ID: <36f3db07-aede-46ab-9c09-f5f44f882f7c@t3g2000yqa.googlegroups.com> On Feb 16, 4:34?am, rushen... at gmail.com wrote: > Hi everybody, > I am an engineer. I am trying to improve my software development > abilities. I have started programming with ruby. I like it very much > but i want to add something more. According to my previous research i > have designed a learning path for myself. It's like something below. > ? ? ? 1. Ruby (Mastering as much as possible) > ? ? ? 2. Python (Mastering as much as possible) > ? ? ? 3. Basic C++ or Basic Java > And the story begins here. As i search on the net, ?I have found that > because of the natural characteristics of python such as GIL, we are > not able to write multi threaded programs. Oooops, in a kind of time > with lots of cpu cores and we are not able to write multi threaded > programs. That is out of fashion. How a such powerful language doesn't > support multi threading. That is a big minus for python. But there is > something interesting, something like multi processing. But is it a > real alternative for multi threading. As i searched it is not, it > requires heavy hardware requirements (lots of memory, lots of cpu > power). Also it is not easy to implement, too much extra code... > > After all of that, i start to think about omiting python from my > carrier path and directly choosing c++ or java. But i know google or > youtube uses python very much. How can they choose a language which > will be killed by multi threading a time in near future. I like python > and its syntax, its flexibility. > > What do you think about multi threading and its effect on python. Why > does python have such a break and what is the fix. Is it worth to make > investment of time and money to a language it can not take advantage > of multi cores? Though I'm sure this has already been shot to death, I would just add that maybe the better question would be: "Will Python make multithreading less popular?" My answer would be something along the lines of, that would be nice, but it just depends on how many people adopt Python for their applications, realize they can't use threads to take advantage of multiple CPUs, ask this same bloody question for the thousandth time, and are told to use the multiprocessing module. From matzke at berkeley.edu Tue Feb 17 15:36:07 2009 From: matzke at berkeley.edu (Nick Matzke) Date: Tue, 17 Feb 2009 12:36:07 -0800 Subject: pythonic array subsetting In-Reply-To: <499A5A73.4030905@islandtraining.com> References: <499A560C.4000209@berkeley.edu> <499A5A73.4030905@islandtraining.com> Message-ID: <499B1FB7.4000701@berkeley.edu> Looks like "compress" is the right numpy function, but it took forever for me to find it... x = array([[1,2,3], [4,5,6], [7,8,9]], dtype=float) compress([1,2], x, axis=1) result: array([[ 1., 2.], [ 4., 5.], [ 7., 8.]]) Gary Herron wrote: > Nick Matzke wrote: >> Hi, >> >> So I've got a square floating point array that is about 1000 x 1000. >> I need to subset this array as efficiently as possible based on an >> ordered sublist of the list of rownames/colnames (they are the same, >> this is a symmetric array). >> >> e.g., if sublist is of length 500, and matches the rownames list at >> every other entry, I need to pull out a 500x500 array holding every >> other row & column in the parent array. >> >> I have to do this hundreds of times, so speed would be useful. >> >> Cheers! >> Nick > > Check out numpy at http://numpy.scipy.org > > It can do what you want very efficiently. > > > Gary Herron > >> >> >> > > -- ==================================================== Nicholas J. Matzke Ph.D. student, Graduate Student Researcher Huelsenbeck Lab Center for Theoretical Evolutionary Genomics 4151 VLSB (Valley Life Sciences Building) Department of Integrative Biology University of California, Berkeley Lab websites: http://ib.berkeley.edu/people/lab_detail.php?lab=54 http://fisher.berkeley.edu/cteg/hlab.html Dept. personal page: http://ib.berkeley.edu/people/students/person_detail.php?person=370 Lab personal page: http://fisher.berkeley.edu/cteg/members/matzke.html Lab phone: 510-643-6299 Dept. fax: 510-643-6264 Cell phone: 510-301-0179 Email: matzke at berkeley.edu Mailing address: Department of Integrative Biology 3060 VLSB #3140 Berkeley, CA 94720-3140 ----------------------------------------------------- "[W]hen people thought the earth was flat, they were wrong. When people thought the earth was spherical, they were wrong. But if you think that thinking the earth is spherical is just as wrong as thinking the earth is flat, then your view is wronger than both of them put together." Isaac Asimov (1989). "The Relativity of Wrong." The Skeptical Inquirer, 14(1), 35-44. Fall 1989. http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm ==================================================== From josh.dukes at microvu.com Tue Feb 17 15:47:52 2009 From: josh.dukes at microvu.com (Josh Dukes) Date: Tue, 17 Feb 2009 12:47:52 -0800 Subject: Python 3D CAD -- need collaborators, or just brave souls :) In-Reply-To: <4993DE39.8030200@cosc.canterbury.ac.nz> References: <4993DE39.8030200@cosc.canterbury.ac.nz> Message-ID: <20090217124752.2d75f454@microvu.com> What kind of cad are you focused on? Mechanical cad, architecutal cad, or something else? If you're interested there have been some experiments with blender http://projects.blender.org/projects/blendercad/ http://blenderartists.org/forum/showthread.php?t=65559 Unfortunately I don't think anything ever came out of those. There's also a 2d cad called pythoncad, http://www.pythoncad.org/ There's also Salome, which seems to have a python interface. Basically though, there isn't anything good right now but I'd love to see this. On Thu, 12 Feb 2009 21:30:49 +1300 greg wrote: > rantingrick wrote: > > > It has long been my dream to create an open source 3D CAD program > > and > > > > I have a real good idea of the UI design > > Have you seen Sketchup? > > http://sketchup.google.com/ > > It has an amazingly intuitive user interface, much better > than any other 3D modeller I've seen. Anyone thinking of > designing a 3D app would do well to study it closely, IMO. > > Something with a Sketchup-like UI but designed for serious > CAD work would be an incredibly good thing to have. > > In any case, your project sounds interesting, and I'll > be happy to discuss ideas if you want. > -- Josh Dukes MicroVu IT Department From robert.kern at gmail.com Tue Feb 17 16:17:00 2009 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 17 Feb 2009 15:17:00 -0600 Subject: pythonic array subsetting In-Reply-To: <499B1FB7.4000701@berkeley.edu> References: <499A560C.4000209@berkeley.edu> <499A5A73.4030905@islandtraining.com> <499B1FB7.4000701@berkeley.edu> Message-ID: On 2009-02-17 14:36, Nick Matzke wrote: > Looks like "compress" is the right numpy function, but it took forever > for me to find it... > > x = array([[1,2,3], [4,5,6], [7,8,9]], dtype=float) > compress([1,2], x, axis=1) > > result: > array([[ 1., 2.], > [ 4., 5.], > [ 7., 8.]]) No, that's actually not correct. compress() takes a boolean mask, not integer indices. It just happens to be the case that compress() implicitly appends Falses to the end if the lengths don't match. Also, numpy indices are 0-indexed just like most Python sequences. If you need to specify integer indices, you need this: In [4]: x[:,[0,1]] Out[4]: array([[ 1., 2.], [ 4., 5.], [ 7., 8.]]) If you have more numpy questions, you should ask on the numpy mailing list. http://www.scipy.org/Mailing_Lists -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From thomasmallen at gmail.com Tue Feb 17 16:46:41 2009 From: thomasmallen at gmail.com (Thomas Allen) Date: Tue, 17 Feb 2009 13:46:41 -0800 (PST) Subject: "Maximum recursion depth exceeded"...why? Message-ID: <847153c1-579e-4e4f-a21d-dcf106f15636@r41g2000yqm.googlegroups.com> I must not be understanding something. This is a simple recursive function that prints all HTML files in argv[1] as its scans the directory's contents. Why do I get a RuntimeError for recursion depth exceeded? #!/usr/bin/env python import os, sys def main(): absToRel(sys.argv[1], sys.argv[2]) def absToRel(dir, root): for filename in os.listdir(dir): if os.path.isdir(filename): absToRel(filename, root) else: if(filename.endswith("html") or filename.endswith("htm")): print filename if __name__ == "__main__": main() From ntwrkd at gmail.com Tue Feb 17 16:55:28 2009 From: ntwrkd at gmail.com (ntwrkd) Date: Tue, 17 Feb 2009 13:55:28 -0800 Subject: Jython Dev in Eclipse Message-ID: Does anyone use Pydev or JyDT for Eclipse. Can you recommend one against the other? From martin at v.loewis.de Tue Feb 17 17:05:42 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 17 Feb 2009 23:05:42 +0100 Subject: "Maximum recursion depth exceeded"...why? In-Reply-To: <847153c1-579e-4e4f-a21d-dcf106f15636@r41g2000yqm.googlegroups.com> References: <847153c1-579e-4e4f-a21d-dcf106f15636@r41g2000yqm.googlegroups.com> Message-ID: <499b34b6$0$27922$9b622d9e@news.freenet.de> Thomas Allen wrote: > I must not be understanding something. This is a simple recursive > function that prints all HTML files in argv[1] as its scans the > directory's contents. Why do I get a RuntimeError for recursion depth > exceeded? > > def main(): > absToRel(sys.argv[1], sys.argv[2]) > > def absToRel(dir, root): > for filename in os.listdir(dir): > if os.path.isdir(filename): Perhaps you have a symlink somewhere that makes the tree appear to have infinite depth? Regards, Martin From lists at cheimes.de Tue Feb 17 17:08:01 2009 From: lists at cheimes.de (Christian Heimes) Date: Tue, 17 Feb 2009 23:08:01 +0100 Subject: "Maximum recursion depth exceeded"...why? In-Reply-To: <847153c1-579e-4e4f-a21d-dcf106f15636@r41g2000yqm.googlegroups.com> References: <847153c1-579e-4e4f-a21d-dcf106f15636@r41g2000yqm.googlegroups.com> Message-ID: Thomas Allen schrieb: > I must not be understanding something. This is a simple recursive > function that prints all HTML files in argv[1] as its scans the > directory's contents. Why do I get a RuntimeError for recursion depth > exceeded? > > #!/usr/bin/env python > > import os, sys > > def main(): > absToRel(sys.argv[1], sys.argv[2]) > > def absToRel(dir, root): > for filename in os.listdir(dir): > if os.path.isdir(filename): > absToRel(filename, root) > else: > if(filename.endswith("html") or filename.endswith("htm")): > print filename Why so complicated? for root, dirs, files in os.walk(directory): for filename in files: if filename.endswith((".htm"), (".html")): print os.path.join(root, filename) Christian From thomasmallen at gmail.com Tue Feb 17 17:08:39 2009 From: thomasmallen at gmail.com (Thomas Allen) Date: Tue, 17 Feb 2009 14:08:39 -0800 (PST) Subject: "Maximum recursion depth exceeded"...why? References: <847153c1-579e-4e4f-a21d-dcf106f15636@r41g2000yqm.googlegroups.com> Message-ID: On Feb 17, 4:46?pm, Thomas Allen wrote: > I must not be understanding something. This is a simple recursive > function that prints all HTML files in argv[1] as its scans the > directory's contents. Why do I get a RuntimeError for recursion depth > exceeded? > > #!/usr/bin/env python > > import os, sys > > def main(): > ? ? absToRel(sys.argv[1], sys.argv[2]) > > def absToRel(dir, root): > ? ? for filename in os.listdir(dir): > ? ? ? ? if os.path.isdir(filename): > ? ? ? ? ? ? absToRel(filename, root) > ? ? ? ? else: > ? ? ? ? ? ? if(filename.endswith("html") or filename.endswith("htm")): > ? ? ? ? ? ? ? ? print filename > > if __name__ == "__main__": > ? ? main() Please note that I'm not using os.walk(sys.argv[1]) because the current depth of recursion is relevant to the transformation I'm attempting. Basically, I'm transforming a live site to a local one and the live site uses all absolute paths (not my decision...). I planned on performing the replace like so for each line: line.replace(root, "../" * depth) So that a file in the top-level would simple remove all instances of root, one level down would sub "../", etc. From __peter__ at web.de Tue Feb 17 17:31:18 2009 From: __peter__ at web.de (Peter Otten) Date: Tue, 17 Feb 2009 23:31:18 +0100 Subject: "Maximum recursion depth exceeded"...why? References: <847153c1-579e-4e4f-a21d-dcf106f15636@r41g2000yqm.googlegroups.com> Message-ID: Thomas Allen wrote: > I must not be understanding something. This is a simple recursive > function that prints all HTML files in argv[1] as its scans the > directory's contents. Why do I get a RuntimeError for recursion depth > exceeded? > > #!/usr/bin/env python > > import os, sys > > def main(): > absToRel(sys.argv[1], sys.argv[2]) > > def absToRel(dir, root): > for filename in os.listdir(dir): filename = os.path.join(dir, filename) > if os.path.isdir(filename): > absToRel(filename, root) > else: > if(filename.endswith("html") or filename.endswith("htm")): > print filename > > if __name__ == "__main__": > main() Without the addition for a directory and a subdirectory of the same name, "dir/dir", os.listdir("dir") has "dir" (the child) in the result list which triggers an absToRel() call on "dir" (the parent) ad infinitum. Peter From mcfletch at vrplumber.com Tue Feb 17 17:37:05 2009 From: mcfletch at vrplumber.com (Mike C. Fletcher) Date: Tue, 17 Feb 2009 17:37:05 -0500 Subject: OpenGL in TK In-Reply-To: References: Message-ID: <499B3C11.8090605@vrplumber.com> Almar Klein wrote: > Hi list! > > I am using pyOpenGL to do some 3D rendering. For now I am > quite happy with the GLCanvas of wx, but I may want to publish > some stuff later, and it would be nice if people would not need wx. > > I found that there used to be a TK widget called Togl, but it is not > (anymore?) included in the TK package that comes with Python. Togl was never included with Python, it used to be included with PyOpenGL, but it was always a royal PITA to build as it had to be built against the dev versions of Tcl and Tk that matched the Python ones. There's now a Togl project on SourceForge that provides a Win32 build of Togl. There's a hacky script in PyOpenGL 3.x's "src/toglinstall" directory that tries to download the package from there and install it for you, but I'd expect it to be rather fragile and broken. You wind up with an external binary download requirement one way or another. Togl is pretty small compared to wxPython, of course, but you're looking a the same basic problem. > Have others been able to use Togl, or any other OpenGL widget in > TK? I installed it using the above-mentioned hacky script a few months ago, checked that the wrapper (OpenGL/Tk) still worked with it, and then promptly ceased to particularly worry about it any more. As has been the case for years, Togl needs an advocate who wants to work on the support in PyOpenGL, without that I just have no particular interest in maintaining it and the headache of maintenance has vastly outweighed my interest. HTH, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From thomasmallen at gmail.com Tue Feb 17 17:39:39 2009 From: thomasmallen at gmail.com (Thomas Allen) Date: Tue, 17 Feb 2009 14:39:39 -0800 (PST) Subject: "Maximum recursion depth exceeded"...why? References: <847153c1-579e-4e4f-a21d-dcf106f15636@r41g2000yqm.googlegroups.com> Message-ID: <99af8e87-784f-4373-8f3d-3244084290ae@o11g2000yql.googlegroups.com> On Feb 17, 5:31?pm, Peter Otten <__pete... at web.de> wrote: > Thomas Allen wrote: > > I must not be understanding something. This is a simple recursive > > function that prints all HTML files in argv[1] as its scans the > > directory's contents. Why do I get a RuntimeError for recursion depth > > exceeded? > > > #!/usr/bin/env python > > > import os, sys > > > def main(): > > ? ? absToRel(sys.argv[1], sys.argv[2]) > > > def absToRel(dir, root): > > ? ? for filename in os.listdir(dir): > > ? ? ? ? ? filename = os.path.join(dir, filename) > > > ? ? ? ? if os.path.isdir(filename): > > ? ? ? ? ? ? absToRel(filename, root) > > ? ? ? ? else: > > ? ? ? ? ? ? if(filename.endswith("html") or filename.endswith("htm")): > > ? ? ? ? ? ? ? ? print filename > > > if __name__ == "__main__": > > ? ? main() > > Without the addition for a directory and a subdirectory of the same > name, "dir/dir", os.listdir("dir") has "dir" (the child) in the result list > which triggers an absToRel() call on "dir" (the parent) ad infinitum. > > Peter I have two problems in this case: 1. I don't know how to reliably map the current filename to an absolute path beyond the top-most directory because my method of doing so would be to os.path.join(os.getcwd(), filename) 2. For some reason, only one folder in the directory gets marked as a directory itself when there are about nine others in the top-most directory. I don't even know where to begin to solve this one. I'm sure the first is an easy answer, but what do I need to do to solve the second? From semanticist at gmail.com Tue Feb 17 17:43:54 2009 From: semanticist at gmail.com (Miles) Date: Tue, 17 Feb 2009 17:43:54 -0500 Subject: Problems with OS X 10.5.6 and Python 2.5 and GDAL 1.6 In-Reply-To: <60437775-ED63-469B-A2CC-913B0E77BC1E@ucsd.edu> References: <60437775-ED63-469B-A2CC-913B0E77BC1E@ucsd.edu> Message-ID: On Mon, Feb 16, 2009 at 8:35 PM, Helly John J. wrote: > However, when I run python and try to import gdal, this is what happens: > Python 2.5.4 (r254:67917, Dec 23 2008, 14:57:27) > [GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> import gdal > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named gdal What about "from osgeo import gdal"? -Miles From skippy.hammond at gmail.com Tue Feb 17 17:44:13 2009 From: skippy.hammond at gmail.com (Mark Hammond) Date: Wed, 18 Feb 2009 09:44:13 +1100 Subject: This application has failed to start because the application configuration is incorrect In-Reply-To: <822B0E83D23291469317E34324687437022249@production.2000soft.com> References: <822B0E83D23291469317E34324687437022249@production.2000soft.com> Message-ID: <499B3DBD.90106@gmail.com> On 18/02/2009 5:49 AM, Sam Clark wrote: > I am receiving the message "This application has failed to start because > the application configuration is incorrect" when I attempt to run a > compiled Python program on another machine. I have used py2exe on both a > 2.6.1 and a 2.6.0 version of the .py and .pyw files. Everything works > great on the machine where Python 2.6 is loaded, but fails on machines > where I copy the .exe to the machine. I'm a beginner at python > programming. In fact this is my first packaged program. Any thoughts at > a beginners level would be helpful. This will be due to the C runtime library not being installed correctly on the target machine. Python 2.6 has this problem more than earlier versions (due to the compiler used to build it) and the best way to address it isn't really clear yet unless you are willing to have them install these libraries via another Microsoft supplied installer. Probably the easiest workaround is to use Python 2.5 in the short term... Mark From __peter__ at web.de Tue Feb 17 18:05:18 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 18 Feb 2009 00:05:18 +0100 Subject: "Maximum recursion depth exceeded"...why? References: <847153c1-579e-4e4f-a21d-dcf106f15636@r41g2000yqm.googlegroups.com> <99af8e87-784f-4373-8f3d-3244084290ae@o11g2000yql.googlegroups.com> Message-ID: Thomas Allen wrote: > On Feb 17, 5:31?pm, Peter Otten <__pete... at web.de> wrote: >> Thomas Allen wrote: >> > I must not be understanding something. This is a simple recursive >> > function that prints all HTML files in argv[1] as its scans the >> > directory's contents. Why do I get a RuntimeError for recursion depth >> > exceeded? >> >> > #!/usr/bin/env python >> >> > import os, sys >> >> > def main(): >> > absToRel(sys.argv[1], sys.argv[2]) >> >> > def absToRel(dir, root): >> > for filename in os.listdir(dir): >> >> filename = os.path.join(dir, filename) >> >> > if os.path.isdir(filename): >> > absToRel(filename, root) >> > else: >> > if(filename.endswith("html") or filename.endswith("htm")): >> > print filename >> >> > if __name__ == "__main__": >> > main() >> >> Without the addition for a directory and a subdirectory of the same >> name, "dir/dir", os.listdir("dir") has "dir" (the child) in the result >> list which triggers an absToRel() call on "dir" (the parent) ad >> infinitum. >> >> Peter > > I have two problems in this case: > > 1. I don't know how to reliably map the current filename to an > absolute path beyond the top-most directory because my method of doing > so would be to os.path.join(os.getcwd(), filename) Don't make things more complicated than necessary. If you can do os.listdir(somedir) you can also do [os.path.join(somedir, fn) for fn in os.listdir(somedir)]. > 2. For some reason, only one folder in the directory gets marked as a > directory itself when there are about nine others in the top-most > directory. I don't even know where to begin to solve this one. > > I'm sure the first is an easy answer, but what do I need to do to > solve the second? If you solve the first properly the second might magically disappear. This is what my crystal ball tells me because there is no code in sight... Peter From lionel.keene at gmail.com Tue Feb 17 18:08:31 2009 From: lionel.keene at gmail.com (Lionel) Date: Tue, 17 Feb 2009 15:08:31 -0800 (PST) Subject: numpy.memmap advice? Message-ID: Hello all, On a previous thread (http://groups.google.com/group/comp.lang.python/ browse_thread/thread/64da35b811e8f69d/67fa3185798ddd12? hl=en&lnk=gst&q=keene#67fa3185798ddd12) I was asking about reading in binary data. Briefly, my data consists of complex numbers, 32-bit floats for real and imaginary parts. The data is stored as 4 bytes Real1, 4 bytes Imaginary1, 4 bytes Real2, 4 bytes Imaginary2, etc. in row-major format. I needed to read the data in as two separate numpy arrays, one for real values and one for imaginary values. There were several very helpful performance tips offered, and one in particular I've started looking into. The author suggested a "numpy.memmap" object may be beneficial. It was suggested I use it as follows: descriptor = dtype([("r", "1Gb. I don't really see in the diocumentation how portions are loaded, however. They seem to create small arrays and then assign the entire array (i.e. file) to the memmap object. Let's assume I have a binary data file of complex numbers in the format described above, and let's assume that the size of the complex data array (that is, the entire file) is 100x100 (rows x columns). Could someone please post a few lines showing how to load the top-left 50 x 50 quadrant, and the lower- right 50 x 50 quadrant into memmap objects? Thank you very much in advance! -L From mike.barry at gmail.com Tue Feb 17 18:10:50 2009 From: mike.barry at gmail.com (mbarry) Date: Tue, 17 Feb 2009 15:10:50 -0800 (PST) Subject: _socket.so source? Message-ID: <7b5bcc07-7bfa-4537-b6e4-912e885cdda4@v15g2000yqn.googlegroups.com> Hello, The socket module in Python uses _socket.so for most of its behavior. I want to modify the code that generates the _socket.so file. I need the source file and instructions on how to compile and build _socket.so for Windows. Can anyone point me to where I can find the source and/or documentation for compiling a python shared object on Windows? Thanks -Mike From james at agentultra.com Tue Feb 17 18:12:57 2009 From: james at agentultra.com (J Kenneth King) Date: Tue, 17 Feb 2009 15:12:57 -0800 Subject: Musings: Using decorators to reduce duplicate exception handling Message-ID: <878wo4verq.fsf@agentultra.com> I recently started a project called TracShell (http://code.google.com/p/tracshell) where I make heavy use of the xmlrpclib core module. When the number of RPC calls was small, wrapping each call in try/except was acceptable. However, this obviously will duplicate code all over the place. There are only ever two exceptions that the module itself will throw: xmlrpclib.ProtocolError and xmlrpclib.Fault -- both very useful, but not show stoppers. To combat the duplication, my clever idea was to use a function decorator to wrap any function that used xmlrpclib calls: def catch_errors(fn): """ A decorator to catch typical xmlrpclib exceptions """ def wrapped(*args, **kwargs): try: return fn(*args, **kwargs) except xmlrpclib.ProtocolError, e: print "There was a problem communicating with the server." print "URL: %s" % e.url print "Headers: %s" % e.headers print "Error code: %d" % e.errcode print "Error message: %s" % e.errmsg print "Please file a report with the TracShell developers." pass except xmlrpclib.Fault, e: print "A fault ocurred" print "Fault code: %d" % e.faultCode print "Fault string: %s" % e.faultString print "If you think this message is the result of an error," print "please file a report with the TracShell developers." pass return wrapped Maybe I could rename the decorator to something meaningful, but besides that it works pretty well. Now any function I write in my class that uses RPC calls can be wrapped by this decorator and have the exception handling done in a uniform way for these particular exceptions. I was just curious if other Pythonistas out there used the same idea or have a better one. Thoughts? From rolf.oltmans at gmail.com Tue Feb 17 18:15:56 2009 From: rolf.oltmans at gmail.com (Oltmans) Date: Tue, 17 Feb 2009 15:15:56 -0800 (PST) Subject: Searching Google? Message-ID: <6d1caedf-7d94-49e6-8a34-d4037202b7c7@i24g2000prf.googlegroups.com> Hey all, I want to search Google.com using a specific keyword and I just want to read back the response using Pyhon. After some thorough Googling I realized that I probably need a Search API key to do that. Is that correct? Now, I don't have a search key so is there a workaround? Please enlighten me. Thanks, Oltmans From robert.kern at gmail.com Tue Feb 17 18:22:09 2009 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 17 Feb 2009 17:22:09 -0600 Subject: numpy.memmap advice? In-Reply-To: References: Message-ID: On 2009-02-17 17:08, Lionel wrote: > Hello all, > > On a previous thread (http://groups.google.com/group/comp.lang.python/ > browse_thread/thread/64da35b811e8f69d/67fa3185798ddd12? > hl=en&lnk=gst&q=keene#67fa3185798ddd12) I was asking about reading in > binary data. Briefly, my data consists of complex numbers, 32-bit > floats for real and imaginary parts. The data is stored as 4 bytes > Real1, 4 bytes Imaginary1, 4 bytes Real2, 4 bytes Imaginary2, etc. in > row-major format. I needed to read the data in as two separate numpy > arrays, one for real values and one for imaginary values. I don't have time to answer your questions now, so you should ask on the numpy mailing list where others can jump in. http://www.scipy.org/Mailing_Lists -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From semanticist at gmail.com Tue Feb 17 18:24:35 2009 From: semanticist at gmail.com (Miles) Date: Tue, 17 Feb 2009 18:24:35 -0500 Subject: print string as raw string In-Reply-To: References: <6vvifkFm4k0vU1@mid.uni-berlin.de> <01aaa153$0$20629$c3e8da3@news.astraweb.com> Message-ID: On Tue, Feb 17, 2009 at 2:01 PM, Scott David Daniels wrote: >>> Mirko Dziadzka schrieb: >>>> >>>> I'm trying to find a way to output strings in the raw-string format, >>>> e.g. >>>> print_as_raw_string(r"\.") should output r"\." instead of "\\." ... > > ... > The big issue I see is that lots of values cannot be represented > as raw strings. Your code checks for a final '\', but many "control" > characters and the quote marks are also at issue. > > raw_repr('["\']a\x13\xfebc\\de') should contain several nasty cases. It seems to me that a raw_repr should only be required to be able to encode strings that are representable as raw strings in the first place. Here's mine: def raw_repr(s): if s and s[-1] == '\\': raise ValueError('No raw string representation; ' 'string ends in backslash') # If you want to test for control and non-ASCII characters to raise # an exception, that's up to you quote = None if '\n' not in s: if "'" not in s: quote = "'" elif '"' not in s: quote = '"' if not quote: if "'''" not in s: quote = "'''" elif '"""' not in s: quote = '"""' if not quote: raise ValueError('No raw string representation; ' 'string contains unescapable quote characters') return 'r' + quote + s + quote >>> print raw_repr(r"1\2'3\n") r"1\2'3\n" >>> print raw_repr(r'''"What's up," he said.''') r'''"What's up," he said.''' >>> # valid raw string, left as an exercise for the reader: ... print raw_repr(r'"""'"'''") # ;) Traceback (most recent call last): File "", line 2, in ? File "", line 19, in raw_repr ValueError: No raw string representation; string contains unescapable quote characters -Miles From __peter__ at web.de Tue Feb 17 18:26:07 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 18 Feb 2009 00:26:07 +0100 Subject: Speedup Bitmap Parser References: <58aed622-cf81-4747-ac54-86badef1c8dc@s20g2000yqh.googlegroups.com> <4c467175-092f-423d-8c0c-cdbffc8579c4@c12g2000yqj.googlegroups.com> <12765e3f-a324-4621-b110-b40bd57acff0@s20g2000yqh.googlegroups.com> <5b94254a-e8ea-469d-8e07-2f3dc778baa8@v39g2000yqm.googlegroups.com> <41a631e9-9e57-45f0-9ec1-835114e3f3de@l39g2000yqn.googlegroups.com> <5a3cfd4d-7a1c-4afe-a237-60533e8d4f8a@a12g2000yqm.googlegroups.com> Message-ID: Jayson Santos wrote: > On 17 fev, 14:00, bearophileH... at lycos.com wrote: >> Jayson Santos: >> >> > After changing my code to use only functions instead classes >> > my code is too much faster. >> > Here cProfile statistcs: >> > Using old code : 633608 function calls in 1.361 CPU seconds >> > Using new code: 475487 function calls in 0.800 CPU seconds >> >> If you show a pastebin of the new version (you can also paste it, for >> reference for future people, when the pastebin will be deleted), >> probably there are ways to improve it more. >> And I also suggest you to try Psyco. (Someone recently has shown here >> a compiled version for Windows of Psyco for Python 2.6). >> >> Bye, >> bearophile > > I'm using linux with python 2.5 > Here is the result using psyco.full(): 93 function calls in 0.243 CPU > seconds > And here is the final code: http://pastebin.com/f3e20d669 I think you are heading in the wrong direction. Turning classes into dictionaries in code that runs just once (like the Bitmap class) makes your program harder to read, not faster. Adding globals makes it non-reentrant. You should really concentrate your optimization efforts on the inner loops. Here avoiding loops written in Python and using tuples instead of a custom class may offer significant speedups: def bitmap_line(s): a = array.array("B") a.fromstring(s) return zip(*(iter(a),)*3) Note that I didn't test or time it because your script requires other changes to run on AMD64. Peter From nick.bastin at gmail.com Tue Feb 17 18:29:46 2009 From: nick.bastin at gmail.com (Nicholas Bastin) Date: Tue, 17 Feb 2009 18:29:46 -0500 Subject: Making extension modules play nice with help()? Message-ID: <66d0a6e10902171529g53b0ac34h650ee03ace07ff28@mail.gmail.com> I've always provided doc strings through PyMethodDef in the past, without paying much attention to what happens in help() - they print fine when you just use the doc string. However, in help, you end up with methods that have an indeterminate signature. We generally make doc strings that look like: "get_root_calls() -> [ptv.Call, ...]" "Returns all root calls for transactions in the trace." Which works fine if you just print get_root_calls().__doc__ or somesuch, but works out quite lousy if you use help(): | get_root_calls(...) | get_root_calls() -> [ptv.Call, ...] | Returns all root calls for transactions in the trace. So we end up with the method signature twice - once from help(), which is meaningless (assuming a non-empty argument list), and once from the doc string, which is actually useful. Is there any way to either a) teach the proper method signature to help(), or b) override it. Also, while PyMethodDef has a nice place to put a doc string, PyMappingMethods and tp_iter have no such place, and so we end up with things like: | __getitem__(...) | x.__getitem__(y) <==> x[y] | | __iter__(...) | x.__iter__() <==> iter(x) Which is decidedly unhelpful. Can I grab the Type after it has been readied and replace some attributes somewhere to put new strings in these places? Of course, I can always cover the C extension module in a thin veneer of python, but that starts to become a significant performance problem (not to mention a maintenance nightmare). -- Nick -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Tue Feb 17 18:29:50 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 17 Feb 2009 21:29:50 -0200 Subject: Upgrading standard library module References: <08e76f94-7d31-4200-a774-c5c41d72f91f@r15g2000prd.googlegroups.com> Message-ID: En Tue, 17 Feb 2009 13:37:12 -0200, Bryan escribi?: > On Feb 17, 12:34?am, "Gabriel Genellina" > wrote: >> En Fri, 13 Feb 2009 20:17:35 -0200, Bryan >> escribi?: >> > On Feb 13, 1:52?pm, Jason Scheirer wrote: >> >> On Feb 13, 12:42?pm, Bryan wrote: >> >> >> > I have a Python v2.5.2 server running and I found some undesirable >> >> > behavior in the xmlrpclib module that is included with that >> > >> version of >> >> > Python. ?The xmlrpclib version that is included with Python 2.6 >> >> > changes the behavior for the better. ? >> >> > I also did not see anything in the revision log in the source file >> > about this change. >> >> It was rev.52790:http://svn.python.org/view?rev=52790&view=rev >> The tracker item has some background:http://bugs.python.org/issue1070046 > > Can you give me a quick run down of your process for researching this > information? I don't spend much time looking at the svn or bug > tracker. First, I looked the section in xmlrpclib.py that you were refering to. Then, over a checked out copy of the sources, I ran: svn blame xmlrpclib.py and I got the revision those lines were last modified. Then from the log message of rev. 52790 I got the reference to the tracker item. > Should I be checking there before posting? It's a good idea to check first, but don't refrain from posting here. -- Gabriel Genellina From lists at cheimes.de Tue Feb 17 18:47:16 2009 From: lists at cheimes.de (Christian Heimes) Date: Wed, 18 Feb 2009 00:47:16 +0100 Subject: _socket.so source? In-Reply-To: <7b5bcc07-7bfa-4537-b6e4-912e885cdda4@v15g2000yqn.googlegroups.com> References: <7b5bcc07-7bfa-4537-b6e4-912e885cdda4@v15g2000yqn.googlegroups.com> Message-ID: mbarry schrieb: > Hello, > > > The socket module in Python uses _socket.so for most of its behavior. > I want to modify the code that generates the _socket.so file. > I need the source file and instructions on how to compile and build > _socket.so for Windows. > Can anyone point me to where I can find the source and/or > documentation for compiling a python shared object on Windows? You need the Python source tree (download the .tar.gz) and the correct compiler in order to build a .dll / .pyd file on Windows. For Python 2.4 and 2.5 you need Visual Studio 2003 (VC7.1), for Python 2.6 and 3.0 you have to install Visual Studio 2008 (VC9). The code for the _socket extension is in the Modules/ subdirectory of the source tree. Christian From thomasmallen at gmail.com Tue Feb 17 18:52:56 2009 From: thomasmallen at gmail.com (Thomas Allen) Date: Tue, 17 Feb 2009 15:52:56 -0800 (PST) Subject: "Maximum recursion depth exceeded"...why? References: <847153c1-579e-4e4f-a21d-dcf106f15636@r41g2000yqm.googlegroups.com> <99af8e87-784f-4373-8f3d-3244084290ae@o11g2000yql.googlegroups.com> Message-ID: <912a40f6-0696-4f08-966a-bc3217f9ea34@u13g2000yqg.googlegroups.com> On Feb 17, 6:05?pm, Peter Otten <__pete... at web.de> wrote: > Thomas Allen wrote: > > On Feb 17, 5:31?pm, Peter Otten <__pete... at web.de> wrote: > >> Thomas Allen wrote: > >> > I must not be understanding something. This is a simple recursive > >> > function that prints all HTML files in argv[1] as its scans the > >> > directory's contents. Why do I get a RuntimeError for recursion depth > >> > exceeded? > > >> > #!/usr/bin/env python > > >> > import os, sys > > >> > def main(): > >> > absToRel(sys.argv[1], sys.argv[2]) > > >> > def absToRel(dir, root): > >> > for filename in os.listdir(dir): > > >> filename = os.path.join(dir, filename) > > >> > if os.path.isdir(filename): > >> > absToRel(filename, root) > >> > else: > >> > if(filename.endswith("html") or filename.endswith("htm")): > >> > print filename > > >> > if __name__ == "__main__": > >> > main() > > >> Without the addition for a directory and a subdirectory of the same > >> name, "dir/dir", os.listdir("dir") has "dir" (the child) in the result > >> list which triggers an absToRel() call on "dir" (the parent) ad > >> infinitum. > > >> Peter > > > I have two problems in this case: > > > 1. I don't know how to reliably map the current filename to an > > absolute path beyond the top-most directory because my method of doing > > so would be to os.path.join(os.getcwd(), filename) > > Don't make things more complicated than necessary. If you can do > os.listdir(somedir) you can also do [os.path.join(somedir, fn) for fn in > os.listdir(somedir)]. > > > 2. For some reason, only one folder in the directory gets marked as a > > directory itself when there are about nine others in the top-most > > directory. I don't even know where to begin to solve this one. > > > I'm sure the first is an easy answer, but what do I need to do to > > solve the second? > > If you solve the first properly the second might magically disappear. This > is what my crystal ball tells me because there is no code in sight... > > Peter I'm referring to the same code, but with a print: for file in os.listdir(dir): if os.path.isdir(file): print "D", file in place of the internal call to absToRel...and only one line prints such a message. I mean, if I can't trust my OS or its Python implementation (on a Windows box) to recognize a directory, I'm wasting everyone's time here. In any case, is this the best way to go about the problem in general? Or is there already a way to recursively walk a directory, aware of the current depth? Thanks, Thomas From gagsl-py2 at yahoo.com.ar Tue Feb 17 19:00:26 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 17 Feb 2009 22:00:26 -0200 Subject: List of locale values for locale.setlocale() under Windows References: <1234900820.29552.1300909493@webmail.messagingengine.com> Message-ID: En Tue, 17 Feb 2009 18:00:19 -0200, escribi?: >>>> locale.getlocale() > ('English_United States', '1252') > Any suggestions on where I can find the official list of locale > codes for Windows XP (or better yet, all versions of Windows XP > or later)? Are you looking for this? http://msdn.microsoft.com/en-us/library/hzz3tw78(VS.80).aspx -- Gabriel Genellina From google at mrabarnett.plus.com Tue Feb 17 19:04:08 2009 From: google at mrabarnett.plus.com (MRAB) Date: Wed, 18 Feb 2009 00:04:08 +0000 Subject: "Maximum recursion depth exceeded"...why? In-Reply-To: <847153c1-579e-4e4f-a21d-dcf106f15636@r41g2000yqm.googlegroups.com> References: <847153c1-579e-4e4f-a21d-dcf106f15636@r41g2000yqm.googlegroups.com> Message-ID: <499B5078.2050908@mrabarnett.plus.com> Thomas Allen wrote: > I must not be understanding something. This is a simple recursive > function that prints all HTML files in argv[1] as its scans the > directory's contents. Why do I get a RuntimeError for recursion depth > exceeded? > > #!/usr/bin/env python > > import os, sys > > def main(): > absToRel(sys.argv[1], sys.argv[2]) > > def absToRel(dir, root): > for filename in os.listdir(dir): os.listdir() returns a list of filenames, not filepaths. Create the filepath with os.path.join(dir, filename). > if os.path.isdir(filename): > absToRel(filename, root) > else: > if(filename.endswith("html") or filename.endswith("htm")): > print filename > > if __name__ == "__main__": > main() > From lists at cheimes.de Tue Feb 17 19:05:57 2009 From: lists at cheimes.de (Christian Heimes) Date: Wed, 18 Feb 2009 01:05:57 +0100 Subject: "Maximum recursion depth exceeded"...why? In-Reply-To: <912a40f6-0696-4f08-966a-bc3217f9ea34@u13g2000yqg.googlegroups.com> References: <847153c1-579e-4e4f-a21d-dcf106f15636@r41g2000yqm.googlegroups.com> <99af8e87-784f-4373-8f3d-3244084290ae@o11g2000yql.googlegroups.com> <912a40f6-0696-4f08-966a-bc3217f9ea34@u13g2000yqg.googlegroups.com> Message-ID: Thomas Allen wrote: > I'm referring to the same code, but with a print: > > for file in os.listdir(dir): > if os.path.isdir(file): > print "D", file > > in place of the internal call to absToRel...and only one line prints > such a message. I mean, if I can't trust my OS or its Python > implementation (on a Windows box) to recognize a directory, I'm > wasting everyone's time here. You are under a wrong assumption. You think os.listdir() returns a list of absolute path elements. In fact it returns just a list of names. You have to os.path.join(dir, file) to get an absolute path. Anyway stop reinventing the wheel and use os.walk() as I already explained. You can easily spot the depth with "directory.count(os.sep)". os.path.normpath() helps you to sanitize the path before counting the number of os.sep. Christian From curt.hash at gmail.com Tue Feb 17 19:43:31 2009 From: curt.hash at gmail.com (Curt Hash) Date: Tue, 17 Feb 2009 17:43:31 -0700 Subject: Searching Google? In-Reply-To: <6d1caedf-7d94-49e6-8a34-d4037202b7c7@i24g2000prf.googlegroups.com> References: <6d1caedf-7d94-49e6-8a34-d4037202b7c7@i24g2000prf.googlegroups.com> Message-ID: <736698790902171643l58828125q56829ce07b1c7e71@mail.gmail.com> On Tue, Feb 17, 2009 at 4:15 PM, Oltmans wrote: > > Hey all, > > I want to search Google.com using a specific keyword and I just want > to read back the response using Pyhon. After some thorough Googling I > realized that I probably need a Search API key to do that. Is that > correct? Now, I don't have a search key so is there a workaround? > Please enlighten me. > > Thanks, > Oltmans > -- > http://mail.python.org/mailman/listinfo/python-list You just need to change your User-Agent so that Google doesn't know a Python script is making the request: import urllib2 headers = {'User-Agent' : 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.6) Gecko/2009020911 Ubuntu/8.04 (hardy) Firefox/3.0.6'} query = 'foo' req = urllib2.Request('http://www.google.com/search?&q=' + query, headers=headers) response = urllib2.urlopen(req) results = response.read() From benjamin.kaplan at case.edu Tue Feb 17 19:59:09 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 17 Feb 2009 19:59:09 -0500 Subject: Jython Dev in Eclipse In-Reply-To: References: Message-ID: On Tue, Feb 17, 2009 at 4:55 PM, ntwrkd wrote: > Does anyone use Pydev or JyDT for Eclipse. > Can you recommend one against the other? JyDT hasn't had a release in the last few years. I don't think it will work with the new versions of eclipse or Jython. -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dotancohen at gmail.com Tue Feb 17 20:10:24 2009 From: dotancohen at gmail.com (Dotan Cohen) Date: Wed, 18 Feb 2009 03:10:24 +0200 Subject: Python 3D CAD -- need collaborators, or just brave souls :) In-Reply-To: References: Message-ID: <880dece00902171710v145d37a3j56166103aabecc5d@mail.gmail.com> > It has long been my dream to create an open source 3D CAD program and > i am starting to crawl my way into the first steps. If you are really serious, then I am waiting for a Linux-compatible Solidworks replacement. That means that I can work and collaborate with other Solidworks users in Solidworks' native format, with no excuses to the other engineers. If you come up with such a best, say in the next three years, then I will donate to your cause three times the cost of a Solidworks license at that time. There are literally hundreds of other engineers that would do the same as I would do. When you go for VC keep that in mind. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-??-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-? From gtill60 at gmail.com Tue Feb 17 20:18:11 2009 From: gtill60 at gmail.com (gtillmon) Date: Tue, 17 Feb 2009 17:18:11 -0800 (PST) Subject: Directory Message-ID: <6d92ee1b-75ba-4ba8-8dc3-625966b17835@d32g2000yqe.googlegroups.com> Hello. I am new to the Python language. I would like to know how to display and store the path of each mondule that is called. Similar to the old READY TRACE in COBOL of long ago. Thanks, George From http Tue Feb 17 20:36:07 2009 From: http (Paul Rubin) Date: 17 Feb 2009 17:36:07 -0800 Subject: "Maximum recursion depth exceeded"...why? References: <847153c1-579e-4e4f-a21d-dcf106f15636@r41g2000yqm.googlegroups.com> Message-ID: <7xr61w8r20.fsf@ruckus.brouhaha.com> Thomas Allen writes: > attempting. Basically, I'm transforming a live site to a local one and Something wrong with wget -R ? From thomasmallen at gmail.com Tue Feb 17 20:46:06 2009 From: thomasmallen at gmail.com (Thomas Allen) Date: Tue, 17 Feb 2009 17:46:06 -0800 (PST) Subject: "Maximum recursion depth exceeded"...why? References: <847153c1-579e-4e4f-a21d-dcf106f15636@r41g2000yqm.googlegroups.com> <99af8e87-784f-4373-8f3d-3244084290ae@o11g2000yql.googlegroups.com> <912a40f6-0696-4f08-966a-bc3217f9ea34@u13g2000yqg.googlegroups.com> Message-ID: <052caf2f-26c5-4602-8490-db80626c3dfd@w34g2000yqm.googlegroups.com> On Feb 17, 7:05?pm, Christian Heimes wrote: > Thomas Allen wrote: > > I'm referring to the same code, but with a print: > > > for file in os.listdir(dir): > > ? ? if os.path.isdir(file): > > ? ? ? ? print "D", file > > > in place of the internal call to absToRel...and only one line prints > > such a message. I mean, if I can't trust my OS or its Python > > implementation (on a Windows box) to recognize a directory, I'm > > wasting everyone's time here. > > You are under a wrong assumption. You think os.listdir() returns a list > of absolute path elements. In fact it returns just a list of names. You > have to os.path.join(dir, file) to get an absolute path. > > Anyway stop reinventing the wheel and use os.walk() as I already > explained. You can easily spot the depth with "directory.count(os.sep)". > ?os.path.normpath() helps you to sanitize the path before counting the > number of os.sep. > > Christian If you'd read the messages in this thread you'd understand why I'm not using os.walk(): I'm not using it because I need my code to be aware of the current recursion depth so that the correct number of "../" are substituted in. Also, somebody mentioned wget -R...did you mean wget -r? In any case, I have all of these files locally already and am trying to replace absolute paths with relative ones so that a colleague can present some website content at a location with no internet. Thomas From python at bdurham.com Tue Feb 17 20:53:59 2009 From: python at bdurham.com (python at bdurham.com) Date: Tue, 17 Feb 2009 20:53:59 -0500 Subject: List of locale values for locale.setlocale() under Windows In-Reply-To: References: <1234900820.29552.1300909493@webmail.messagingengine.com> Message-ID: <1234922039.4722.1300977805@webmail.messagingengine.com> Gabriel, > Are you looking for this? > http://msdn.microsoft.com/en-us/library/hzz3tw78(VS.80).aspx Yes! Wonderful! Thank you, Malcolm From lists at cheimes.de Tue Feb 17 21:08:58 2009 From: lists at cheimes.de (Christian Heimes) Date: Wed, 18 Feb 2009 03:08:58 +0100 Subject: "Maximum recursion depth exceeded"...why? In-Reply-To: <052caf2f-26c5-4602-8490-db80626c3dfd@w34g2000yqm.googlegroups.com> References: <847153c1-579e-4e4f-a21d-dcf106f15636@r41g2000yqm.googlegroups.com> <99af8e87-784f-4373-8f3d-3244084290ae@o11g2000yql.googlegroups.com> <912a40f6-0696-4f08-966a-bc3217f9ea34@u13g2000yqg.googlegroups.com> <052caf2f-26c5-4602-8490-db80626c3dfd@w34g2000yqm.googlegroups.com> Message-ID: Thomas Allen wrote: > If you'd read the messages in this thread you'd understand why I'm not > using os.walk(): I'm not using it because I need my code to be aware > of the current recursion depth so that the correct number of "../" are > substituted in. I'm well aware of your messages and your requirements. However you didn't either read or understand what I was trying to tell you. You don't need to know the recursion depths in order to find the correct number of "../". base = os.path.normpath(base) baselevel = root.count(os.sep) for root, dirs, files in os.walk(base): level = root.count(os.sep) - baselevel offset = level * "../" ... See? Christian From thomasmallen at gmail.com Tue Feb 17 21:19:55 2009 From: thomasmallen at gmail.com (Thomas Allen) Date: Tue, 17 Feb 2009 18:19:55 -0800 (PST) Subject: "Maximum recursion depth exceeded"...why? References: <847153c1-579e-4e4f-a21d-dcf106f15636@r41g2000yqm.googlegroups.com> <99af8e87-784f-4373-8f3d-3244084290ae@o11g2000yql.googlegroups.com> <912a40f6-0696-4f08-966a-bc3217f9ea34@u13g2000yqg.googlegroups.com> <052caf2f-26c5-4602-8490-db80626c3dfd@w34g2000yqm.googlegroups.com> Message-ID: On Feb 17, 9:08?pm, Christian Heimes wrote: > Thomas Allen wrote: > > If you'd read the messages in this thread you'd understand why I'm not > > using os.walk(): I'm not using it because I need my code to be aware > > of the current recursion depth so that the correct number of "../" are > > substituted in. > > I'm well aware of your messages and your requirements. However you > didn't either read or understand what I was trying to tell you. You > don't need to know the recursion depths in order to find the correct > number of "../". > > base = os.path.normpath(base) > baselevel = root.count(os.sep) > > for root, dirs, files in os.walk(base): > ? ? level = root.count(os.sep) - baselevel > ? ? offset = level * "../" > ? ? ... > > See? > > Christian Very clever (and now seemingly obvious)! That certainly is one way to measure directory depth; I hadn't thought of counting the separator. Sorry that I misunderstood what you meant there. Thanks, Thomas From python at bdurham.com Tue Feb 17 22:02:24 2009 From: python at bdurham.com (python at bdurham.com) Date: Tue, 17 Feb 2009 22:02:24 -0500 Subject: Questions on Python 2.6.1 locale module Message-ID: <1234926144.17948.1300984725@webmail.messagingengine.com> I've read the latest official locale documentation[1], googled for additional resources, and have the following questions: 1. Does the following warning still apply to recent releases of Python (and if so, is this a Python issue, a generic C runtime issue, or a platform specific C runtime issue) "... some implementation are broken in such a way that frequent locale changes may cause core dumps. This makes the locale somewhat painful to use correctly." 2. Is there a locale-like module that uses hardcoded/cached locale settings that might support the ability to have different locale objects? Use cases for such a module: - ability for threads to support independent locale-type formatting (via their own private locale object instances) - ability to generate multi-locale output without flipping between locales (expensive and potentially buggy) Note: I understand this wouldn't be a perfect solution given that the string module's 'constants' are locale sensitive. 3. Where can I find examples of how to use the locale.format() and locale.format_string() functions? (The documentation for these functions is too terse for me to understand). Thank you, Malcolm [1] http://docs.python.org/library/locale.html -------------- next part -------------- An HTML attachment was scrubbed... URL: From wuwei23 at gmail.com Tue Feb 17 22:03:51 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 17 Feb 2009 19:03:51 -0800 (PST) Subject: "Maximum recursion depth exceeded"...why? References: <847153c1-579e-4e4f-a21d-dcf106f15636@r41g2000yqm.googlegroups.com> <7xr61w8r20.fsf@ruckus.brouhaha.com> Message-ID: On Feb 18, 11:36?am, Paul Rubin wrote: > Thomas Allen writes: > > attempting. Basically, I'm transforming a live site to a local one and > > Something wrong with wget -R ? Did you mean wget -r ? That will just grab the entire site, though. I'm guessing that Thomas' function absToRel will eventually replace the print with something that changes links accordingly so the local version is traversable. From python at bdurham.com Tue Feb 17 22:09:15 2009 From: python at bdurham.com (python at bdurham.com) Date: Tue, 17 Feb 2009 22:09:15 -0500 Subject: Best practice for upgrading the version of SQLite bundled with Python 2.6.1 Message-ID: <1234926555.19179.1300986603@webmail.messagingengine.com> Are there best practice recommendations for upgrading the version of SQLite that comes bundled with versions of Python 2.5 and later? We're running Python 2.6.1 on Windows and Linux and using the default version of SQLite that ship with this release. Today, a new version of SQLite 3.6.11 was released. If we would like to use this newer version of SQLite, what steps should we follow for our Windows and Linux versions of Python 2.6.1? Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From wuwei23 at gmail.com Tue Feb 17 22:28:08 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 17 Feb 2009 19:28:08 -0800 (PST) Subject: Is there something easier than ORM? References: <07cb23ac-3f67-45f2-a1ba-9fb80510db9b@z28g2000prd.googlegroups.com> <8C9A6CB8-80A6-4E10-8EA1-3C40EAED058D@semanchuk.com> <49f712d8783aa02d9f76692f11e1b1b9.squirrel@localhost> Message-ID: <26c3659d-ce14-4375-9da7-d9fefc4748ac@a39g2000prl.googlegroups.com> On Feb 18, 3:10?am, Robert Kern wrote: > Its public image definitely suffers from the impression that it's "an ORM" that > can be compared on equal terms with packages that actually are just ORMs. I > describe it as a very powerful toolkit for solving a wide variety of problems > involving SQL databases. One of those tools happens to be an ORM. I'm going to have to steal that description the next time I try to sell a co-worker on the value of SQLAlchemy. There's always a strong reaction against the mention of ORMs, generally along the lines of it moving the programmer too far away from the real action. But my experience is identical to both andrew's and your's; there is far far more of value in SQLA than the ORM alone. From Graham.Dumpleton at gmail.com Tue Feb 17 22:34:39 2009 From: Graham.Dumpleton at gmail.com (Graham Dumpleton) Date: Tue, 17 Feb 2009 19:34:39 -0800 (PST) Subject: multiprocessing module and os.close(sys.stdin.fileno()) Message-ID: <3098ffc2-6884-4a35-99a5-ee917442af25@r37g2000prr.googlegroups.com> Why is the multiprocessing module, ie., multiprocessing/process.py, in _bootstrap() doing: os.close(sys.stdin.fileno()) rather than: sys.stdin.close() Technically it is feasible that stdin could have been replaced with something other than a file object, where the replacement doesn't have a fileno() method. In that sort of situation an AttributeError would be raised, which isn't going to be caught as either OSError or ValueError, which is all the code watches out for. Graham From Graham.Dumpleton at gmail.com Tue Feb 17 22:47:14 2009 From: Graham.Dumpleton at gmail.com (Graham Dumpleton) Date: Tue, 17 Feb 2009 19:47:14 -0800 (PST) Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <28e3612d-2e91-4a91-82cb-5fb2deda95fd@q9g2000yqc.googlegroups.com> Message-ID: On Feb 16, 9:27?pm, Michele Simionato wrote: > On Feb 16, 10:34?am, rushen... at gmail.com wrote: > > > > > Hi everybody, > > I am an engineer. I am trying to improve my software development > > abilities. I have started programming with ruby. I like it very much > > but i want to add something more. According to my previous research i > > have designed a learning path for myself. It's like something below. > > ? ? ? 1. Ruby (Mastering as much as possible) > > ? ? ? 2. Python (Mastering as much as possible) > > ? ? ? 3. Basic C++ or Basic Java > > And the story begins here. As i search on the net, ?I have found that > > because of the natural characteristics of python such as GIL, we are > > not able to write multi threaded programs. Oooops, in a kind of time > > with lots of cpu cores and we are not able to write multi threaded > > programs. That is out of fashion. How a such powerful language doesn't > > support multi threading. That is a big minus for python. But there is > > something interesting, something like multi processing. But is it a > > real alternative for multi threading. As i searched it is not, it > > requires heavy hardware requirements (lots of memory, lots of cpu > > power). Also it is not easy to implement, too much extra code... > > multiprocessing is already implemented for you in the standard > library. > Of course it does not require heavy hardware requirements. > > > After all of that, i start to think about omiting python from my > > carrier path and directly choosing c++ or java. But i know google or > > youtube uses python very much. How can they choose a language which > > will be killed by multi threading a time in near future. I like python > > and its syntax, its flexibility. > > > What do you think about multi threading and its effect on python. Why > > does python have such a break and what is the fix. Is it worth to make > > investment of time and money to a language it can not take advantage > > of multi cores? > > You can take advantage of multi cores, just not with threads but with > processes, > which BTW is the right way to go in most situations. So (assuming you > are not > a troll) you are just mistaken in thinking that the only way to > use multicores is via multithreading. It is also a mistaken belief that you cannot take advantage of multi cores with multiple threads inside of a single process using Python. What no one seems to remember is that when calls are made into Python extension modules implemented in C code, they have the option of releasing the Python GIL. By releasing the Python GIL at that point, it would allow other Python threads to run at the same time as operations are being done in C code in the extension module. Obviously if the extension module needs to manipulate Python objects it will not be able to release the GIL, but not all extension modules are going to be like this and could have quite sizable sections of code that can run with the GIL released. Thus, you could have many threads running at the same time in sections of C code, at same time as well as currently delegated thread within Python code. A very good example of this is when embeddeding Python inside of Apache. So much stuff is actually done inside of Apache C code with the GIL released, that there is more than ample opportunity for multiple threads to be running across cores at the same time. Graham From wuwei23 at gmail.com Tue Feb 17 22:56:21 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 17 Feb 2009 19:56:21 -0800 (PST) Subject: How do I declare global vars or class vars in Python ? References: Message-ID: On Feb 18, 12:54?am, Linuxguy123 wrote: > The part I don't know to do is declare the variables, either as globals > or as vars in a class. ?How is this done in Python without setting them > to a value ? Generally, you can use the object None to indicate that something has no value: class Something(object): def __init__(self, a=None, b=None): self.a, self.b = a, b def dosomething(self): # manipulate self.a & self.b here def main(): s = Something("value1", "value2") s.dosomething() From sri_annauni at yahoo.co.in Tue Feb 17 23:19:54 2009 From: sri_annauni at yahoo.co.in (srinivasan srinivas) Date: Wed, 18 Feb 2009 09:49:54 +0530 (IST) Subject: Python Module for console text formatting? Message-ID: <867965.2501.qm@web7903.mail.in.yahoo.com> Hi, Does anyone know any python module other than 'ConsoleFormat0.1.1' used to format text on console? For example, printing bold characters on console. Thanks, Srini Did you know? You can CHAT without downloading messenger. Go to http://in.webmessenger.yahoo.com/ From michele.simionato at gmail.com Tue Feb 17 23:33:46 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Tue, 17 Feb 2009 20:33:46 -0800 (PST) Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <28e3612d-2e91-4a91-82cb-5fb2deda95fd@q9g2000yqc.googlegroups.com> Message-ID: <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> On Feb 18, 4:47?am, Graham Dumpleton wrote: > It is also a mistaken belief that you cannot take advantage of multi > cores with multiple threads inside of a single process using Python. > > What no one seems to remember is that when calls are made into Python > extension modules implemented in C code, they have the option of > releasing the Python GIL. By releasing the Python GIL at that point, > it would allow other Python threads to run at the same time as > operations are being done in C code in the extension module. You are perfectly right and no one forgot this point, I am sure. However I think we were answering to the question "can pure Python code take advantage of multiple CPUs via multithreading" and the answer is no. Of course a C extension can do that, but that is beside the point. It is still worth noticing - as you did - that some well known Python (+C extension) library - such as mod_wsgi - is already well equipped to manage multithreading on multiple cores without any further effort from the user. This is a good point. Michele Simionato From cto at openmigration.net Tue Feb 17 23:34:34 2009 From: cto at openmigration.net (geremy condra) Date: Tue, 17 Feb 2009 23:34:34 -0500 Subject: Python Module for console text formatting? In-Reply-To: <867965.2501.qm@web7903.mail.in.yahoo.com> References: <867965.2501.qm@web7903.mail.in.yahoo.com> Message-ID: You can insert those codes just like you would any other character. If there's enough interest I can whip up a wrapper library for you. http://www.linux.gr/cgi-bin/man2html?console_codes+4 On Tue, Feb 17, 2009 at 11:19 PM, srinivasan srinivas < sri_annauni at yahoo.co.in> wrote: > > Hi, > Does anyone know any python module other than 'ConsoleFormat0.1.1' used to > format text on console? > For example, printing bold characters on console. > > Thanks, > Srini > > > Did you know? You can CHAT without downloading messenger. Go to > http://in.webmessenger.yahoo.com/ > -- > http://mail.python.org/mailman/listinfo/python-list > -- OpenMigration LLC- Open Source solutions for your business. Visit us at http://OpenMigration.net. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dhbaird at gmail.com Wed Feb 18 01:13:00 2009 From: dhbaird at gmail.com (David Baird) Date: Tue, 17 Feb 2009 22:13:00 -0800 (PST) Subject: Announcing CVExp: A library for making linear programming easier Message-ID: Here is the PyPI page: http://pypi.python.org/pypi/cvexp/0.1 And here is the homepage: http://www.aclevername.com/projects/cvexp/ CVExp currently supports solving linear, integer linear, and quadratic optimization problems via lpsolve55, GLPK, and CVXOPT. There are packages readily available in Debian and Ubuntu for python-glpk and python-cvxopt, so installation is easy on these platforms: apt-get install python-setuptools # for easy_install apt-get install python-glpk python-cvxopt easy_install cvexp Here is a quick example of using CVExp+GLPK to solve a problem: from cvexp.builders import var from cvexp.builders import integer from cvexp.builders import minimize from cvexp.translate_glpk import solve X = var('X') # the 'X' name is optional Y = var('Y') # ...and so is 'Y' sol = solve(( Y + 0.1 == X, Y >= 9.8 - X, integer(Y), minimize(Y), ), out_filename='problem.out') # out_filename is optional print 'X =', sol[X] # >>> 5.1 print 'Y =', sol[Y] # >>> 5 From gagsl-py2 at yahoo.com.ar Wed Feb 18 01:42:15 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 18 Feb 2009 04:42:15 -0200 Subject: Best practice for upgrading the version of SQLite bundled with Python 2.6.1 References: <1234926555.19179.1300986603@webmail.messagingengine.com> Message-ID: En Wed, 18 Feb 2009 01:09:15 -0200, escribi?: > Are there best practice recommendations for upgrading the version > of SQLite that comes bundled with versions of Python 2.5 and > later? At least on Windows, you only have to replace sqlite3.dll (in the DLLs directory) with the new one, and that's all. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Wed Feb 18 02:01:36 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 18 Feb 2009 05:01:36 -0200 Subject: Musings: Using decorators to reduce duplicate exception handling References: <878wo4verq.fsf@agentultra.com> Message-ID: En Tue, 17 Feb 2009 21:12:57 -0200, J Kenneth King escribi?: > I recently started a project called TracShell > (http://code.google.com/p/tracshell) where I make heavy use of the > xmlrpclib core module. > > When the number of RPC calls was small, wrapping each call in try/except > was acceptable. However, this obviously will duplicate code all over the > place. There are only ever two exceptions that the module itself will > throw: xmlrpclib.ProtocolError and xmlrpclib.Fault -- both very useful, > but not show stoppers. > > To combat the duplication, my clever idea was to use a function > decorator to wrap any function that used xmlrpclib calls: > > def catch_errors(fn): > """ > A decorator to catch typical xmlrpclib exceptions > """ > def wrapped(*args, **kwargs): > try: > return fn(*args, **kwargs) > except xmlrpclib.ProtocolError, e: > print "There was a problem communicating with the server." > print "URL: %s" % e.url > print "Headers: %s" % e.headers > print "Error code: %d" % e.errcode > print "Error message: %s" % e.errmsg > print "Please file a report with the TracShell developers." > pass > except xmlrpclib.Fault, e: > print "A fault ocurred" > print "Fault code: %d" % e.faultCode > print "Fault string: %s" % e.faultString > print "If you think this message is the result of an error," > print "please file a report with the TracShell developers." > pass > return wrapped I don't like the idea of "hiding" an exception. The caller code doesn't know an exception occurred, and just continue doing its work, with bogus results... is this what you want? Also, you don't include the stack trace - and usually it contains very valuable information. When your users start "filing a report with the TracShell developers" and you feel clueless, a stack trace is important (you don't have to show it on screen - a log file is even better). If all you want is to customize the error message, use sys.except_hook Looking into the code, those "pass" statement are useless; and error messages are usually written to stderr instead of stdout. -- Gabriel Genellina From steven at REMOVE.THIS.cybersource.com.au Wed Feb 18 02:24:35 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Feb 2009 07:24:35 GMT Subject: can multi-core improve single funciton? References: <2d09213e-8095-43d2-a067-6c2b301fa41a@x9g2000yqk.googlegroups.com> <39uq66-b7j.ln1@lairds.us> Message-ID: On Tue, 17 Feb 2009 14:30:27 +0000, Cameron Laird wrote: > In article , > Steven D'Aprano wrote: > . > . > . >>> And now for my version (which admitedly isn't really mine, and returns >>> slightly incorrect fib(n) for large values of n, due to the limited >>> floating point precision). >> >>The floating point version is nice, but it starts giving incorrect >>answers relatively early, from n=71. But if you don't need accurate >>results (a relative error of 3e-15 for n=71), it is very fast. > . > . > . > While my personal opinion is that it's silly to characterize an error of > 3e-15 as not "accurate", That's a *relative* error. The absolute error is 1 for n=71, 59 for n=80, 1196093 for n=100, and 1875662300654090482610609259 for n=200. As far as I can tell, the absolute error grows without bounds as n increases -- and it overflows at n=1475. I agree that a relative error is small, and if your use allows it, then by all means use the inexact floating point function. But if you need exact results, then you won't get it using floats. > I think more constructive is to focus on the > fact that the closed-form solution can be touched up to give a precise > integral solution, while re- taining its (approximately) O(log n) > run-time cost. I doubt that. Since both phi and sqrt(5) are irrational numbers, it would require an infinite number of integer digits to get precise integral solutions unless there was some sort of freakish cancellation. But you probably could get a very good integral solution which gives exact results up to whatever limit you wanted, bound only by the amount of memory and time you were willing to spend. -- Steven From mail at microcorp.co.za Wed Feb 18 02:25:24 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Wed, 18 Feb 2009 09:25:24 +0200 Subject: Threading and tkinter References: <492d5db9-3681-4ae8-827e-f2a4f66bee80@v39g2000yqm.googlegroups.com> Message-ID: <004901c9919a$284b89c0$0d00a8c0@hendrik> "gert" wrote: > After reading the docs and seeing a few examples i think this should > work ? > Am I forgetting something here or am I doing something stupid ? > Anyway I see my yellow screen, that has to count for something :) > > from tkinter import * > from threading import Thread > > class Weegbrug(Thread): > def __init__(self,v): > self.v=v > Thread.__init__(self) > def run(self): > while True: > with open('com1','r') as f: > for line in f: > self.v.set(line[2:-1]) It is in general not a good idea to directly access GUI variables from outside the GUI main loop. There is a recipe for doing this sort of thing, but as usual I have lost the reference. What it does is that instead of interfering directly as above, you put the data on a queue. Then, you use the after() call to set up a call to a routine that reads the queue, and configures the display, and then uses after again to call itself again after a time, thereby keeping the GUI stuff in the GUI mainloop. HTH - Hendrik From steven at REMOVE.THIS.cybersource.com.au Wed Feb 18 02:55:41 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Feb 2009 07:55:41 GMT Subject: Pythonic way to determine if one char of many in a string References: <1234761457.20683.1300568627@webmail.messagingengine.com> <01aa9ea5$0$20632$c3e8da3@news.astraweb.com> Message-ID: On Wed, 18 Feb 2009 07:08:04 +1100, Jervis Whitley wrote: >> This moves the for-loop out of slow Python into fast C and should be >> much, much faster for very large input. >> >> > _Should_ be faster. Yes, Python's timing results are often unintuitive. > Here is my test on an XP system Python 2.5.4. I had similar results on > python 2.7 trunk. ... > **no vowels** > any: [0.36063678618957751, 0.36116506191682773, 0.36212355395824081] > for: [0.24044885376801672, 0.2417684017413404, 0.24084797257163482] I get similar results. ... > **BIG word vowel 'U' final char** > any: [8.0007259193539895, 7.9797344140269644, 7.8901742633514012] for: > [7.6664422372764101, 7.6784683633957584, 7.6683055766498001] Well, I did say "for very large input". 10000 chars isn't "very large" -- that's only 9K. Try this instead: >>> BIGWORD = 'g' * 500000 + 'U' # less than 500K of text >>> >>> Timer("for_test(BIGWORD)", setup).repeat(number=1000) [4.7292280197143555, 4.633030891418457, 4.6327309608459473] >>> Timer("any_test(BIGWORD)", setup).repeat(number=1000) [4.7717428207397461, 4.6366970539093018, 4.6367099285125732] The difference is not significant. What about bigger? >>> BIGWORD = 'g' * 5000000 + 'U' # less than 5MB >>> >>> Timer("for_test(BIGWORD)", setup).repeat(number=100) [4.8875839710235596, 4.7698030471801758, 4.769787073135376] >>> Timer("any_test(BIGWORD)", setup).repeat(number=100) [4.8555209636688232, 4.8139419555664062, 4.7710208892822266] It seems to me that I was mistaken -- for large enough input, the running time of each version converges to approximately the same speed. What happens when you have hundreds of megabytes, I don't know. -- Steven From timr at probo.com Wed Feb 18 03:15:00 2009 From: timr at probo.com (Tim Roberts) Date: Wed, 18 Feb 2009 00:15:00 -0800 Subject: Found a very nice, small, cross-platform GUI toolkit for Python. References: <4a912328-2d60-4380-b440-8d4d94f79662@v19g2000yqn.googlegroups.com> <66885dbe-72cd-46da-b59e-90e7f2dcf7da@m42g2000yqb.googlegroups.com> Message-ID: laplacian42 at gmail.com wrote: > >> For applications installing the full wxWidgets or Qt toolkits would be >> less disk space and dependcies than OceanGUI > >What? Qt and wX are *huge* compared to OcempGUI. Well, not compared to OcempGUI + SDL + PyGame. Note that I'm not trying to run down the product at all, but if you're going to make comparisons like this, you really need to be fair about it. >> and performance would probably be higher. > >Probably, but wX and Qt are written in C++. OcempGUI is pure Python, >which would make it easier for the Python community to help extend, >optimize, and maintain. Again, that's hardly fair. OcempGUI is only pure Python because it requires the C libraries SDL and PyGame. wxPython is basically pure Python, also, if you don't count the C++ wxWidgets library underneath it. As you say, if you are already using SDL and PyGame, this sounds like a great solution. But for someone starting from scratch, it's not yet clear to me that OcempGUI substantially better than wx. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From tim--at-- at frontier--dot--.net Wed Feb 18 03:17:40 2009 From: tim--at-- at frontier--dot--.net (Tim H) Date: Wed, 18 Feb 2009 01:17:40 -0700 Subject: urllib confusion Message-ID: When I attempt to open 2 different pages on the same site I get 2 copies of the first page. ?? ie links = [ 'http://site.org/foo/1/bar', 'http://site.org/foo/2/bar' ] for url in links: print "url:", url f = urlopen(url, params) print "Actual url:", f.geturl() print f.read() f.close() results in: url: http://site.org/foo/1/bar Actual url: http://site.org/foo/1/bar page 1 contents url: http://site.org/foo/2/bar Actual url: http://site.org/foo/1/bar page 1 contents f.getinfo() shows two different session ID's Any thoughts? Thanks, Tim WinXP-x64 python 2.6.1 x64 From steven at REMOVE.THIS.cybersource.com.au Wed Feb 18 03:33:08 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Feb 2009 08:33:08 GMT Subject: urllib confusion References: Message-ID: On Wed, 18 Feb 2009 01:17:40 -0700, Tim H wrote: > When I attempt to open 2 different pages on the same site I get 2 copies > of the first page. ?? ... > Any thoughts? What does your browser do? What does your browser do if you turn off cookies, re-directions and/or referers? -- Steven From pavlovevidence at gmail.com Wed Feb 18 03:56:10 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 18 Feb 2009 00:56:10 -0800 (PST) Subject: numpy.memmap advice? References: Message-ID: <59449976-a334-411a-bdc8-7e6041bd4a37@g1g2000pra.googlegroups.com> On Feb 17, 3:08?pm, Lionel wrote: > Hello all, > > On a previous thread (http://groups.google.com/group/comp.lang.python/ > browse_thread/thread/64da35b811e8f69d/67fa3185798ddd12? > hl=en&lnk=gst&q=keene#67fa3185798ddd12) I was asking about reading in > binary data. Briefly, my data consists of complex numbers, 32-bit > floats for real and imaginary parts. The data is stored as 4 bytes > Real1, 4 bytes Imaginary1, 4 bytes Real2, 4 bytes Imaginary2, etc. in > row-major format. I needed to read the data in as two separate numpy > arrays, one for real values and one for imaginary values. > > There were several very helpful performance tips offered, and one in > particular I've started looking into. The author suggested a > "numpy.memmap" object may be beneficial. It was suggested I use it as > follows: > > descriptor = dtype([("r", " data = memmap(filename, dtype=descriptor, mode='r').view(recarray) > print "First 100 real values:", data.r[:100] > > I have two questions: > 1) What is "recarray"? Let's look: [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import numpy >>> numpy.recarray >>> help(numpy.recarray) Help on class recarray in module numpy.core.records: class recarray(numpy.ndarray) | recarray(shape, dtype=None, buf=None, **kwds) | | Subclass of ndarray that allows field access using attribute lookup. | | Parameters | ---------- | shape : tuple | shape of record array | dtype : data-type or None | The desired data-type. If this is None, then the data-type is determine | by the *formats*, *names*, *titles*, *aligned*, and *byteorder* keywords | buf : [buffer] or None | If this is None, then a new array is created of the given shape and data | If this is an object exposing the buffer interface, then the array will | use the memory from an existing buffer. In this case, the *offset* and | *strides* keywords can also be used. ... So there you have it. It's a subclass of ndarray that allows field access using attribute lookup. (IOW, you're creating a view of the memmap'ed data of type recarray, which is the type numpy uses to access structures by name. You need to create the view because regular numpy arrays, which numpy.memmap creates, can't access fields by attribute.) help() is a nice thing to use, and numpy is one of the better libraries when it comes to docstrings, so learn to use it. > 2) The documentation for numpy.memmap claims that it is meant to be > used in situations where it is beneficial to load only segments of a > file into memory, not the whole thing. This is definately something > I'd like to be able to do as my files are frequently >1Gb. I don't > really see in the diocumentation how portions are loaded, however. > They seem to create small arrays and then assign the entire array > (i.e. file) to the memmap object. Let's assume I have a binary data > file of complex numbers in the format described above, and let's > assume that the size of the complex data array (that is, the entire > file) is 100x100 (rows x columns). Could someone please post a few > lines showing how to load the top-left 50 x 50 quadrant, and the lower- > right 50 x 50 quadrant into memmap objects? Thank you very much in > advance! You would memmap the whole region in question (in this case the whole file), then take a slice. Actually you could get away with memmapping just the last 50 rows (bottom half). The offset into the file would be 50*100*8, so: data = memmap(filename, dtype=descriptor, mode='r',offset= (50*100*8)).view(recarray) reshaped_data = reshape(data,(50,100)) intersting_data = reshaped_data[:,50:100] A word of caution: Every instance of numpy.memmap creates its own mmap of the whole file (even if it only creates an array from part of the file). The implications of this are A) you can't use numpy.memmap's offset parameter to get around file size limitations, and B) you shouldn't create many numpy.memmaps of the same file. To work around B, you should create a single memmap, and dole out views and slices. Carl Banks From justinli79 at gmail.com Wed Feb 18 03:59:20 2009 From: justinli79 at gmail.com (Justin Li) Date: Wed, 18 Feb 2009 00:59:20 -0800 (PST) Subject: Building python with sqlite3 Message-ID: I'm building and installing Ptyhon 2.6.1 on Linux. After configure, make, make install, to import sqlite3 leads to ImportError. It looks like I have to build Python with sqlite. I have sqlite3 installed on my system. How should I build Python with it? I did not find any options relating with sqlite3 of configure and Makefile. Thanks in Advance! Justin From mzagursk at gmail.com Wed Feb 18 04:00:28 2009 From: mzagursk at gmail.com (mzagursk at gmail.com) Date: Wed, 18 Feb 2009 01:00:28 -0800 (PST) Subject: Calling a script requiring user input from another script Message-ID: <116dbdad-8d26-4597-aff4-73a0075890c3@v38g2000yqb.googlegroups.com> I'm kind of new to this so bear with me. I have a script made that requires user input (lets call it script A) while it's running. However, I would like to create another script (script B) that can batch process (i.e. run script A over and over with different user inputs based on script B). Is this possible? and how so? Thanks in advance. From rt8396 at gmail.com Wed Feb 18 04:02:22 2009 From: rt8396 at gmail.com (r) Date: Wed, 18 Feb 2009 01:02:22 -0800 (PST) Subject: Python 3D CAD -- need collaborators, or just brave souls :) References: <4993DE39.8030200@cosc.canterbury.ac.nz> Message-ID: <9ef65856-0f62-4434-a4b4-e15558e7c7b0@n2g2000vba.googlegroups.com> Hello Josh, Blender is a lost cause. It is a powerful app but the UI is horrible. Even the Blender folks admit only a complete rewrite could solve the major flaws that plague the design. So maybe i could salvage some code but for what i have in mind, Blender will look like a piece of software from the middle ages. And i am absolutly only looking to do this in 3D, 2D is boring. So, yes, i have looked at both the applications you offer. Thanks From rt8396 at gmail.com Wed Feb 18 04:10:31 2009 From: rt8396 at gmail.com (r) Date: Wed, 18 Feb 2009 01:10:31 -0800 (PST) Subject: Python 3D CAD -- need collaborators, or just brave souls :) References: Message-ID: <845c0b97-8644-448a-b5f7-06da727cf466@n10g2000vbl.googlegroups.com> Yes i want linux, windows, and mac support. I think you are good for a few years though :). Getting something up and working is the easy part. Adding all the features that are required to compete with something the likes of SolidWorks or ACAD takes time. One way or another i am going to build this, whether or not it takes off and gets to a professional level -- only time will tell. I know one thing for sure the need is there, the product is not. From catphive at catphive.net Wed Feb 18 04:11:09 2009 From: catphive at catphive.net (Brendan Miller) Date: Wed, 18 Feb 2009 01:11:09 -0800 Subject: PyYaml in standard library? Message-ID: I'm just curious whether PyYaml is likely to end up in the standard library at some point? From lists at cheimes.de Wed Feb 18 04:13:29 2009 From: lists at cheimes.de (Christian Heimes) Date: Wed, 18 Feb 2009 10:13:29 +0100 Subject: Building python with sqlite3 In-Reply-To: References: Message-ID: Justin Li schrieb: > I'm building and installing Ptyhon 2.6.1 on Linux. After configure, > make, make install, to import sqlite3 leads to ImportError. It looks > like I have to build Python with sqlite. I have sqlite3 installed on > my system. How should I build Python with it? I did not find any > options relating with sqlite3 of configure and Makefile. Do you have the development files installed as well? Run "make" again and look at the list of missing modules. Christian From clp2 at rebertia.com Wed Feb 18 04:18:33 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 18 Feb 2009 01:18:33 -0800 Subject: Calling a script requiring user input from another script In-Reply-To: <116dbdad-8d26-4597-aff4-73a0075890c3@v38g2000yqb.googlegroups.com> References: <116dbdad-8d26-4597-aff4-73a0075890c3@v38g2000yqb.googlegroups.com> Message-ID: <50697b2c0902180118qf4e02erb10fba5d4d3f0e46@mail.gmail.com> On Wed, Feb 18, 2009 at 1:00 AM, mzagursk at gmail.com wrote: > I'm kind of new to this so bear with me. > > I have a script made that requires user input (lets call it script A) > while it's running. However, I would like to create another script > (script B) that can batch process (i.e. run script A over and over > with different user inputs based on script B). Is this possible? and > how so? Thanks in advance. Define a function in A that lets its functionality be used programmatically. Then use the `if __name__ == "__main__"` trick to have A take input from the user and call the function you just defined with the user input if it's run as a script. In B, import A's function and call it repeatedly on the inputs. Example (assume addition is A's fancy functionality): #A.py BEFORE: while True: input_ = raw_input() if input_ == "exit": break x = int(input_) y = int(raw_input()) print x + y #A.py AFTER: #functionality refactored into a function def add(x, y): return x + y if __name__ == "__main__": while True: if input_ == "exit": break x = int(input_) y = int(raw_input()) print add(x, y)#use the function #B.py from A import add for i,j in some_input_pairs: add(i, j)#use the function Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From tomanishkb at gmail.com Wed Feb 18 04:31:13 2009 From: tomanishkb at gmail.com (M Kumar) Date: Wed, 18 Feb 2009 15:01:13 +0530 Subject: Python-list Digest, Vol 65, Issue 365 In-Reply-To: References: Message-ID: <783b47270902180131k3c14e190ocb3d2e5b546f32e@mail.gmail.com> I think the given statement below will give you what you r looking .__file__print On Wed, Feb 18, 2009 at 2:43 PM, wrote: > Send Python-list mailing list submissions to > python-list at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.python.org/mailman/listinfo/python-list > or, via email, send a message with subject or body 'help' to > python-list-request at python.org > > You can reach the person managing the list at > python-list-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Python-list digest..." > > Today's Topics: > > 1. Directory (gtillmon) > 2. Re: Is there something easier than ORM? (Michele Simionato) > 3. Re: flexible find and replace ? (OdarR) > 4. Re: urllib confusion (Steven D'Aprano) > 5. Re: numpy.memmap advice? (Carl Banks) > 6. Building python with sqlite3 (Justin Li) > 7. Calling a script requiring user input from another script > (mzagursk at gmail.com) > 8. Re: Python 3D CAD -- need collaborators, or just brave souls > :) (r) > 9. PyYaml in standard library? (Brendan Miller) > 10. Re: Building python with sqlite3 (Christian Heimes) > > > ---------- Forwarded message ---------- > From: gtillmon > To: > Date: Tue, 17 Feb 2009 17:18:11 -0800 (PST) > Subject: Directory > Hello. I am new to the Python language. > I would like to know how to display and store the path of each mondule > that is called. > Similar to the old READY TRACE in COBOL of long ago. > > Thanks, > George > > > > ---------- Forwarded message ---------- > From: Michele Simionato > To: > Date: Tue, 17 Feb 2009 08:46:02 -0800 (PST) > Subject: Re: Is there something easier than ORM? > On Feb 17, 5:35 pm, Philip Semanchuk wrote: > > > > I don't intend this as a criticism of SqlAlchemy. On the contrary I am > > impressed by what it does. But I often see people promoting ORM as the > > solution to all database access problems, and I certainly don't feel > > like it is. > > I am also not a big fan of ORM, especially in situations where you > have > performance issues and you are using database specific features. In > such situations > you don't care about portability, but you care about having your SQL > explicit, > so that you can run it directly under the profiler. > > > > ---------- Forwarded message ---------- > From: OdarR > To: > Date: Tue, 17 Feb 2009 11:29:19 -0800 (PST) > Subject: Re: flexible find and replace ? > Thanks to everybody. > I need to test your propositions now :) > > Olivier > > > > ---------- Forwarded message ---------- > From: Steven D'Aprano > To: python-list at python.org > Date: 18 Feb 2009 08:33:08 GMT > Subject: Re: urllib confusion > On Wed, 18 Feb 2009 01:17:40 -0700, Tim H wrote: > > > When I attempt to open 2 different pages on the same site I get 2 copies > > of the first page. ?? > ... > > Any thoughts? > > What does your browser do? > > What does your browser do if you turn off cookies, re-directions and/or > referers? > > > > -- > Steven > > > > ---------- Forwarded message ---------- > From: Carl Banks > To: python-list at python.org > Date: Wed, 18 Feb 2009 00:56:10 -0800 (PST) > Subject: Re: numpy.memmap advice? > On Feb 17, 3:08 pm, Lionel wrote: > > Hello all, > > > > On a previous thread (http://groups.google.com/group/comp.lang.python/ > > browse_thread/thread/64da35b811e8f69d/67fa3185798ddd12? > > hl=en&lnk=gst&q=keene#67fa3185798ddd12) I was asking about reading in > > binary data. Briefly, my data consists of complex numbers, 32-bit > > floats for real and imaginary parts. The data is stored as 4 bytes > > Real1, 4 bytes Imaginary1, 4 bytes Real2, 4 bytes Imaginary2, etc. in > > row-major format. I needed to read the data in as two separate numpy > > arrays, one for real values and one for imaginary values. > > > > There were several very helpful performance tips offered, and one in > > particular I've started looking into. The author suggested a > > "numpy.memmap" object may be beneficial. It was suggested I use it as > > follows: > > > > descriptor = dtype([("r", " > data = memmap(filename, dtype=descriptor, mode='r').view(recarray) > > print "First 100 real values:", data.r[:100] > > > > I have two questions: > > 1) What is "recarray"? > > Let's look: > > [GCC 4.3.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import numpy > >>> numpy.recarray > > >>> help(numpy.recarray) > > Help on class recarray in module numpy.core.records: > > class recarray(numpy.ndarray) > | recarray(shape, dtype=None, buf=None, **kwds) > | > | Subclass of ndarray that allows field access using attribute > lookup. > | > | Parameters > | ---------- > | shape : tuple > | shape of record array > | dtype : data-type or None > | The desired data-type. If this is None, then the data-type is > determine > | by the *formats*, *names*, *titles*, *aligned*, and > *byteorder* keywords > | buf : [buffer] or None > | If this is None, then a new array is created of the given > shape and data > | If this is an object exposing the buffer interface, then the > array will > | use the memory from an existing buffer. In this case, the > *offset* and > | *strides* keywords can also be used. > ... > > > So there you have it. It's a subclass of ndarray that allows field > access using attribute lookup. (IOW, you're creating a view of the > memmap'ed data of type recarray, which is the type numpy uses to > access structures by name. You need to create the view because > regular numpy arrays, which numpy.memmap creates, can't access fields > by attribute.) > > help() is a nice thing to use, and numpy is one of the better > libraries when it comes to docstrings, so learn to use it. > > > > 2) The documentation for numpy.memmap claims that it is meant to be > > used in situations where it is beneficial to load only segments of a > > file into memory, not the whole thing. This is definately something > > I'd like to be able to do as my files are frequently >1Gb. I don't > > really see in the diocumentation how portions are loaded, however. > > They seem to create small arrays and then assign the entire array > > (i.e. file) to the memmap object. Let's assume I have a binary data > > file of complex numbers in the format described above, and let's > > assume that the size of the complex data array (that is, the entire > > file) is 100x100 (rows x columns). Could someone please post a few > > lines showing how to load the top-left 50 x 50 quadrant, and the lower- > > right 50 x 50 quadrant into memmap objects? Thank you very much in > > advance! > > > You would memmap the whole region in question (in this case the whole > file), then take a slice. Actually you could get away with memmapping > just the last 50 rows (bottom half). The offset into the file would > be 50*100*8, so: > > data = memmap(filename, dtype=descriptor, mode='r',offset= > (50*100*8)).view(recarray) > reshaped_data = reshape(data,(50,100)) > intersting_data = reshaped_data[:,50:100] > > > A word of caution: Every instance of numpy.memmap creates its own mmap > of the whole file (even if it only creates an array from part of the > file). The implications of this are A) you can't use numpy.memmap's > offset parameter to get around file size limitations, and B) you > shouldn't create many numpy.memmaps of the same file. To work around > B, you should create a single memmap, and dole out views and slices. > > > Carl Banks > > > > ---------- Forwarded message ---------- > From: Justin Li > To: python-list at python.org > Date: Wed, 18 Feb 2009 00:59:20 -0800 (PST) > Subject: Building python with sqlite3 > > I'm building and installing Ptyhon 2.6.1 on Linux. After configure, > make, make install, to import sqlite3 leads to ImportError. It looks > like I have to build Python with sqlite. I have sqlite3 installed on > my system. How should I build Python with it? I did not find any > options relating with sqlite3 of configure and Makefile. > > Thanks in Advance! > Justin > > > > ---------- Forwarded message ---------- > From: "mzagursk at gmail.com" > To: python-list at python.org > Date: Wed, 18 Feb 2009 01:00:28 -0800 (PST) > Subject: Calling a script requiring user input from another script > I'm kind of new to this so bear with me. > > I have a script made that requires user input (lets call it script A) > while it's running. However, I would like to create another script > (script B) that can batch process (i.e. run script A over and over > with different user inputs based on script B). Is this possible? and > how so? Thanks in advance. > > > > ---------- Forwarded message ---------- > From: r > To: python-list at python.org > Date: Wed, 18 Feb 2009 01:02:22 -0800 (PST) > Subject: Re: Python 3D CAD -- need collaborators, or just brave souls :) > Hello Josh, > Blender is a lost cause. It is a powerful app but the UI is horrible. > Even the Blender folks admit only a complete rewrite could solve the > major flaws that plague the design. So maybe i could salvage some code > but for what i have in mind, Blender will look like a piece of > software from the middle ages. And i am absolutly only looking to do > this in 3D, 2D is boring. > > So, yes, i have looked at both the applications you offer. > > Thanks > > > > ---------- Forwarded message ---------- > From: Brendan Miller > To: python-list at python.org > Date: Wed, 18 Feb 2009 01:11:09 -0800 > Subject: PyYaml in standard library? > I'm just curious whether PyYaml is likely to end up in the standard > library at some point? > > > > ---------- Forwarded message ---------- > From: Christian Heimes > To: python-list at python.org > Date: Wed, 18 Feb 2009 10:13:29 +0100 > Subject: Re: Building python with sqlite3 > Justin Li schrieb: > > I'm building and installing Ptyhon 2.6.1 on Linux. After configure, > > make, make install, to import sqlite3 leads to ImportError. It looks > > like I have to build Python with sqlite. I have sqlite3 installed on > > my system. How should I build Python with it? I did not find any > > options relating with sqlite3 of configure and Makefile. > > Do you have the development files installed as well? Run "make" again > and look at the list of missing modules. > > Christian > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Regards, Maneesh KB Comat Technologies Bangalore Mob: 9740-192309 We work with the underprivileged and in rural India. If you are interested to be a part of it, please mail or call me. I will be happy to share and inform - http://www.comat.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From rdmurray at bitdance.com Wed Feb 18 04:34:07 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Wed, 18 Feb 2009 09:34:07 +0000 (UTC) Subject: "Maximum recursion depth exceeded"...why? References: <847153c1-579e-4e4f-a21d-dcf106f15636@r41g2000yqm.googlegroups.com> <7xr61w8r20.fsf@ruckus.brouhaha.com> Message-ID: alex23 wrote: > On Feb 18, 11:36=A0am, Paul Rubin wrote: > > Thomas Allen writes: > > > attempting. Basically, I'm transforming a live site to a local one and > > > > Something wrong with wget -R ? > > Did you mean wget -r ? > > That will just grab the entire site, though. I'm guessing that Thomas' > function absToRel will eventually replace the print with something > that changes links accordingly so the local version is traversable. Yeah, but wget -r -k will do that bit of it, too. --RDM From clp2 at rebertia.com Wed Feb 18 04:34:08 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 18 Feb 2009 01:34:08 -0800 Subject: PyYaml in standard library? In-Reply-To: References: Message-ID: <50697b2c0902180134gcb053w96002899356d3ad1@mail.gmail.com> On Wed, Feb 18, 2009 at 1:11 AM, Brendan Miller wrote: > I'm just curious whether PyYaml is likely to end up in the standard > library at some point? I don't personally have a direct answer to your question, but I can point out that JSON and YAML are mostly compatible (JSON is almost a perfect YAML subset) and the `json` module is already in the Python std lib. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From wuwei23 at gmail.com Wed Feb 18 04:51:34 2009 From: wuwei23 at gmail.com (alex23) Date: Wed, 18 Feb 2009 01:51:34 -0800 (PST) Subject: "Maximum recursion depth exceeded"...why? References: <847153c1-579e-4e4f-a21d-dcf106f15636@r41g2000yqm.googlegroups.com> <7xr61w8r20.fsf@ruckus.brouhaha.com> Message-ID: On Feb 18, 7:34?pm, rdmur... at bitdance.com wrote: > Yeah, but wget -r -k will do that bit of it, too. Wow, nice, I don't know why I never noticed that. Cheers! From mal at egenix.com Wed Feb 18 06:36:45 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Wed, 18 Feb 2009 12:36:45 +0100 Subject: Is there something easier than ORM? In-Reply-To: <07cb23ac-3f67-45f2-a1ba-9fb80510db9b@z28g2000prd.googlegroups.com> References: <07cb23ac-3f67-45f2-a1ba-9fb80510db9b@z28g2000prd.googlegroups.com> Message-ID: <499BF2CD.5060807@egenix.com> On 2009-02-17 13:27, ??? wrote: > Hi all, > > Recently I am studying some python ORM libraries, such as sqlalchemy. > > These are very powerful technologies to handle database. But I think > my project are not complicated to enough to benefit from a complete > ORM system. > > What I really want, is some easy ways to load data from database, and > change rows of data to list of named tuple, then I could send these > data to my client application. > > I don't think I want these subtle behavior such as lazy load, auto > update, ect. in ORM. > > So is there some libraries like that? Python has a DB-API standard for direct access to databases using a very simple cursor-based approach: http://www.python.org/dev/peps/pep-0249/ All the DB-API compatible modules provide such an interface: http://wiki.python.org/moin/DatabaseInterfaces > Or is there some tools that could generate code from database scheme > as I want? I am not aware of an automated tool for generating SQL queries in form of Python functions, but it is certainly possible to write one by tapping into the system tables of the database of your choice. Our database tools mxODBC and mxODBC Connect come with a set of catalog methods that make such introspection very easy across databases and platforms: http://www.egenix.com/products/python/mxODBC/ http://www.egenix.com/products/python/mxODBCConnect/ -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Feb 18 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From pofuk at email.t-com.hr Wed Feb 18 07:09:24 2009 From: pofuk at email.t-com.hr (SMALLp) Date: Wed, 18 Feb 2009 13:09:24 +0100 Subject: os.popen encoding! Message-ID: Hy. I'm playing with os.popen function. a = os.popen("somecmd").read() If one of the lines contains characters like "?", "?"or any other it loks line this "velja\xe8a 2009" with that "\xe8". It prints fine if i go: for i in a: print i: How to solve this and where exectly is problem with print or read! Windows XP, Python 2.5.4 Thanks! From tim.wintle at teamrubber.com Wed Feb 18 07:19:04 2009 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Wed, 18 Feb 2009 12:19:04 +0000 Subject: memory recycling/garbage collecting problem In-Reply-To: References: <50697b2c0902170040k2b2c211ew2a2ce3e4c5044c17@mail.gmail.com> <1234879826.7672.11.camel@tim-laptop> Message-ID: <1234959544.30417.8.camel@tim-laptop> On Tue, 2009-02-17 at 17:04 +0100, Christian Heimes wrote: > Tim Wintle wrote: > > Basically malloc() and free() are computationally expensive, so Python > > tries to call them as little as possible - but it's quite clever at > > knowing what to do - e.g. if a list has already grown large then python > > assumes it might grow large again and keeps hold of a percentage of the > > memory. > > You are almost right. Python's mutable container types like have a > non-linear growth rate. > > >From the file listobject.c > > /* > This over-allocates proportional to the list size, making room > for additional growth. The over-allocation is mild, but is > enough to give linear-time amortized behavior over a long > sequence of appends() in the presence of a poorly-performing > system realloc(). > The growth pattern is: 0, 4, 8, 16, 25, 35, 46, 58, 72, 88, ... > */ > > new_allocated = (newsize >> 3) + (newsize < 9 ? 3 : 6); Sorry, I think I didn't phrase myself very well - I was trying to explain that de-allocation of memory follows different scaling behaviour to allocation - so a large list that's shrunk is likely to take more memory than a small list that's grown i.e. the part just above your quote: /* Bypass realloc() when a previous overallocation is large enough to accommodate the newsize. If the newsize falls lower than half the allocated size, then proceed with the realloc() to shrink the list. */ if (allocated >= newsize && newsize >= (allocated >> 1)) { assert(self->ob_item != NULL || newsize == 0); Py_SIZE(self) = newsize; return 0; } it's all very clever stuff btw. From dfnsonfsduifb at gmx.de Wed Feb 18 07:36:17 2009 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Wed, 18 Feb 2009 13:36:17 +0100 Subject: Searching Google? In-Reply-To: References: <6d1caedf-7d94-49e6-8a34-d4037202b7c7@i24g2000prf.googlegroups.com> Message-ID: <702dm1FkrikgU1@mid.dfncis.de> Curt Hash schrieb: > You just need to change your User-Agent so that Google doesn't know a > Python script is making the request: Why would Google not send a response if the User-Agent header field is not a recognized browser? I doubt that's what's happening and the OP would just like the convenience of a search API instead of parsing the web page (like other applications do). Ugly, but it works. Regards, Johannes -- "Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit, verl?sterung von Gott, Bibel und mir und bewusster Blasphemie." -- Prophet und Vision?r Hans Joss aka HJP in de.sci.physik <48d8bf1d$0$7510$5402220f at news.sunrise.ch> From gagsl-py2 at yahoo.com.ar Wed Feb 18 07:38:54 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 18 Feb 2009 10:38:54 -0200 Subject: os.popen encoding! References: Message-ID: En Wed, 18 Feb 2009 10:09:24 -0200, SMALLp escribi?: > Hy. > I'm playing with os.popen function. > a = os.popen("somecmd").read() > > If one of the lines contains characters like "?", "?"or any other it loks > line this "velja\xe8a 2009" with that "\xe8". It prints fine if i go: > > for i in a: > print i: > '\xe8' is a *single* byte (not four). It is the 'LATIN SMALL LETTER E WITH GRAVE' Unicode code point u'?' encoded in the Windows-1252 encoding (and latin-1, and others too). This is the usual Windows encoding (in "Western Europe" but seems to cover a much larger part of the world... most of America, if not all). When you *look* at some string in the interpreter, you see its repr() (note the surrounding quotes). When you *print* some string, you get its contents: py> s = "ma m?re" py> s 'ma m\x8are' py> print s ma m?re py> print repr(s) 'ma m\x8are' > How to solve this and where exectly is problem with print or read! > Windows > XP, Python 2.5.4 There is *no* problem. You should read the Unicode howto: If you still think there is a problem, please provide more details. -- Gabriel Genellina From mad.vijay at gmail.com Wed Feb 18 08:23:26 2009 From: mad.vijay at gmail.com (SamG) Date: Wed, 18 Feb 2009 05:23:26 -0800 (PST) Subject: Crypto headaches. Message-ID: <093e5e7e-0f64-4737-8eae-bc6c9ecab1ee@q40g2000prh.googlegroups.com> Hi, Using the python's Crypto.Cipher.Blowfish is create and encrypted file in the CBC mode. Now... when try to decrypt it with OpenSSL i get an error stating "bad magic number". I tried $ cat encr-file | openssl bf-cbc -d -pass pass:sam > org-file or $ openssl bf-cbc -d -pass pass:sam -in encr-file -out org-file BTW, decryption using a python code works well. But i m of the impression a file encry with one program should/can be decrypt with another program (in my case openssl) using the same parameters. Pls help. SamG From gabriel.rossetti at arimaz.com Wed Feb 18 08:43:51 2009 From: gabriel.rossetti at arimaz.com (Gabriel Rossetti) Date: Wed, 18 Feb 2009 14:43:51 +0100 Subject: Python/environment problem with char encoding/decoding Message-ID: <499C1097.5000505@arimaz.com> Hello everyone, I originally posted this on the Twisted mailing list, but now it seams to be a more general python/environment problem. If I run the attached example in Eclipse, it works, if I run it from a terminal, it doesn't, I get : $ python xml_parser_test.py Traceback (most recent call last): File "xml_parser_test.py", line 30, in res = rawXmlToElement("re?u") File "xml_parser_test.py", line 21, in __call__ tmp.addRawXml(s) File "/usr/lib/python2.5/site-packages/twisted/words/xish/domish.py", line 538, in addRawXml self.children.append(SerializedXML(rawxmlstring)) UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 5: ordinal not in range(128) Does anyone understand why it doesn't work outside of Eclipse? My OS is Linux (Ubuntu 8.04). Thank you, Gabriel -------------- next part -------------- A non-text attachment was scrubbed... Name: xml_parser_test.py Type: text/x-python Size: 843 bytes Desc: not available URL: From hniksic at xemacs.org Wed Feb 18 09:00:17 2009 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Wed, 18 Feb 2009 15:00:17 +0100 Subject: os.popen encoding! References: Message-ID: <87ocwzzvym.fsf@mulj.homelinux.net> "Gabriel Genellina" writes: >> I'm playing with os.popen function. >> a = os.popen("somecmd").read() >> >> If one of the lines contains characters like "?", "?"or any other it loks >> line this "velja\xe8a 2009" with that "\xe8". It prints fine if i go: >> >> for i in a: >> print i: > > '\xe8' is a *single* byte (not four). It is the 'LATIN SMALL LETTER E > WITH GRAVE' Unicode code point u'?' encoded in the Windows-1252 > encoding (and latin-1, and others too). Note that it is also 'LATIN SMALL LETTER C WITH CARON' (U+010D or u'?'), encoded in Windows-1250, which is what the OP is likely using. The rest of your message stands regardless: there is no problem, at least as long as the OP only prints out the character received from somecmd to something else that also expects Windows-1250. The problem would arise if the OP wanted to store the string in a PyGTK label (which expects UTF8) or send it to a web browser (which expects explicit encoding, probably defaulting to UTF8), in which case he'd have to disambiguate whether '\xe8' refers to U+010D or to U+00E8 or something else entirely. That is the problem that Python 3 solves by requiring (or strongly suggesting) that such disambiguation be performed as early in the program as possible, preferrably while the characters are being read from the outside source. A similar approach is possible using Python 2 and its unicode type, but since the OP never specified exactly which problem he had (except for the repr/str confusion), it's hard to tell if using the unicode type would help. From mal at egenix.com Wed Feb 18 09:10:42 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Wed, 18 Feb 2009 15:10:42 +0100 Subject: Crypto headaches. In-Reply-To: <093e5e7e-0f64-4737-8eae-bc6c9ecab1ee@q40g2000prh.googlegroups.com> References: <093e5e7e-0f64-4737-8eae-bc6c9ecab1ee@q40g2000prh.googlegroups.com> Message-ID: <499C16E2.7060102@egenix.com> On 2009-02-18 14:23, SamG wrote: > Hi, > > Using the python's Crypto.Cipher.Blowfish is create and encrypted file > in the CBC mode. Now... when try to decrypt it with OpenSSL i get an > error stating "bad magic number". Are you getting the error message from openssl ? It looks a lot like an error message from Python. > I tried > $ cat encr-file | openssl bf-cbc -d -pass pass:sam > org-file > or > $ openssl bf-cbc -d -pass pass:sam -in encr-file -out org-file > > BTW, decryption using a python code works well. But i m of the > impression a file encry with one program should/can be decrypt with > another program (in my case openssl) using the same parameters. Ideally, that should work, but you also have to make sure that the following two details are the same for both applications: 1. the way padding is done (Blowfish is a block cipher) 2. the way the initialization vector is set Otherwise the two won't interoperate properly. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Feb 18 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From __peter__ at web.de Wed Feb 18 09:12:02 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 18 Feb 2009 15:12:02 +0100 Subject: Python/environment problem with char encoding/decoding References: Message-ID: Gabriel Rossetti wrote: > Hello everyone, > > I originally posted this on the Twisted mailing list, but now it seams > to be a more general python/environment problem. If I run the attached > example in Eclipse, it works, if I run it from a terminal, it doesn't, I > get : > > $ python xml_parser_test.py > Traceback (most recent call last): > File "xml_parser_test.py", line 30, in > res = rawXmlToElement("re?u") > File "xml_parser_test.py", line 21, in __call__ > tmp.addRawXml(s) > File "/usr/lib/python2.5/site-packages/twisted/words/xish/domish.py", > line 538, in addRawXml > self.children.append(SerializedXML(rawxmlstring)) > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 5: > ordinal not in range(128) > > Does anyone understand why it doesn't work outside of Eclipse? My OS is > Linux (Ubuntu 8.04). On the contrary, I don't understand why it would work in Eclipse ;) addRawXml(s) seems to be a fancy way to create a unicode string, and unicode(s) will work either if s is a bytestring that doesn't contain any non-ascii characters or if s is a unicode string (at least these are the relevant cases here). Try changing your program to use a unicode literal: # -*- coding: utf-8 -*- ... if ... res = rawXmlToElement(u"re?u") Peter From benjamin.kaplan at case.edu Wed Feb 18 09:14:39 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 18 Feb 2009 09:14:39 -0500 Subject: Python/environment problem with char encoding/decoding In-Reply-To: <499C1097.5000505@arimaz.com> References: <499C1097.5000505@arimaz.com> Message-ID: On Wed, Feb 18, 2009 at 8:43 AM, Gabriel Rossetti < gabriel.rossetti at arimaz.com> wrote: > Hello everyone, > > I originally posted this on the Twisted mailing list, but now it seams to > be a more general python/environment problem. If I run the attached example > in Eclipse, it works, if I run it from a terminal, it doesn't, I get : > > $ python xml_parser_test.py > Traceback (most recent call last): > File "xml_parser_test.py", line 30, in > res = rawXmlToElement("re?u") > File "xml_parser_test.py", line 21, in __call__ > tmp.addRawXml(s) > File "/usr/lib/python2.5/site-packages/twisted/words/xish/domish.py", line > 538, in addRawXml > self.children.append(SerializedXML(rawxmlstring)) > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 5: > ordinal not in range(128) > > Does anyone understand why it doesn't work outside of Eclipse? My OS is > Linux (Ubuntu 8.04). > > Thank you, > Gabriel > It's an encoding problem. My guess is that, in eclipse, the default encoding is UTF-8 or some other unicode-based encoding. In the console, it seems the encoding defaults to ascii. When twisted attempts to turn your byte string into a Unicode string, it sees a character that isn't in the encoding and choke up. Try using a unicode string instead of a byte string. > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Wed Feb 18 09:15:25 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 18 Feb 2009 09:15:25 -0500 Subject: Directory In-Reply-To: <6d92ee1b-75ba-4ba8-8dc3-625966b17835@d32g2000yqe.googlegroups.com> References: <6d92ee1b-75ba-4ba8-8dc3-625966b17835@d32g2000yqe.googlegroups.com> Message-ID: gtillmon wrote: > Hello. I am new to the Python language. > I would like to know how to display and store the path of each mondule > that is called. Modules are imported, not called. > Similar to the old READY TRACE in COBOL of long ago. > It's certainly possible to trace function calls, if that would help. sys.settrace allows you to establish a function that gets called whenever a Python function call is executed. The documentation is a little sparse, but you can find a rough example under "Crude Python Debugging" in http://www.st.ewi.tudelft.nl/~mol/snippets.php regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From mike.barry at gmail.com Wed Feb 18 09:23:43 2009 From: mike.barry at gmail.com (mbarry) Date: Wed, 18 Feb 2009 06:23:43 -0800 (PST) Subject: _socket.so source? References: <7b5bcc07-7bfa-4537-b6e4-912e885cdda4@v15g2000yqn.googlegroups.com> Message-ID: <3060eb09-a255-419a-a1f1-5a42ffd803ec@h5g2000yqh.googlegroups.com> On Feb 17, 6:47?pm, Christian Heimes wrote: > mbarry schrieb: > > > Hello, > > > The socket module in Python uses_socket.so for most of its behavior. > > I want to modify the code that generates the_socket.so file. > > I need the source file and instructions on how tocompileand build > >_socket.so for Windows. > > Can anyone point me to where I can find the source and/or > > documentation for compiling a python shared object on Windows? > > You need the Python source tree (download the .tar.gz) and the correct > compiler in order to build a .dll / .pyd file on Windows. For Python 2.4 > and 2.5 you need Visual Studio 2003 (VC7.1), for Python 2.6 and 3.0 you > have to install Visual Studio 2008 (VC9). > > The code for the_socketextension is in the Modules/ subdirectory of > the source tree. > > Christian Thanks that was very helpful. I was browsing the source tree and found socketmodule.c which I assume is the source for _socket.pyd. I also found http://docs.python.org/extending/windows.html which is some documentation for building python extensions in windows. The _socket module is a bit different as there seems to be code imported from the dll as well as having code written in python in socket.py. Also the naming convention is different with the socket module as well. Thanks -Mike Thanks -Mike From gabriel.rossetti at arimaz.com Wed Feb 18 09:24:35 2009 From: gabriel.rossetti at arimaz.com (Gabriel Rossetti) Date: Wed, 18 Feb 2009 15:24:35 +0100 Subject: Python/environment problem with char encoding/decoding In-Reply-To: References: Message-ID: <499C1A23.6060204@arimaz.com> Peter Otten wrote: > Gabriel Rossetti wrote: > > >> Hello everyone, >> >> I originally posted this on the Twisted mailing list, but now it seams >> to be a more general python/environment problem. If I run the attached >> example in Eclipse, it works, if I run it from a terminal, it doesn't, I >> get : >> >> $ python xml_parser_test.py >> Traceback (most recent call last): >> File "xml_parser_test.py", line 30, in >> res = rawXmlToElement("re?u") >> File "xml_parser_test.py", line 21, in __call__ >> tmp.addRawXml(s) >> File "/usr/lib/python2.5/site-packages/twisted/words/xish/domish.py", >> line 538, in addRawXml >> self.children.append(SerializedXML(rawxmlstring)) >> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 5: >> ordinal not in range(128) >> >> Does anyone understand why it doesn't work outside of Eclipse? My OS is >> Linux (Ubuntu 8.04). >> > > On the contrary, I don't understand why it would work in Eclipse ;) > > addRawXml(s) seems to be a fancy way to create a unicode string, and > unicode(s) will work either if s is a bytestring that doesn't contain any > non-ascii characters or if s is a unicode string (at least these are the > relevant cases here). > > Try changing your program to use a unicode literal: > > # -*- coding: utf-8 -*- > ... > if ... > res = rawXmlToElement(u"re?u") > > Peter > -- > > Hello Peter, that works, thanks! I was sure I had tried that at some point, but I must have had another problem that made me remove it. Thank you again! Gabriel From steve at holdenweb.com Wed Feb 18 09:27:25 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 18 Feb 2009 09:27:25 -0500 Subject: Python-list Digest, Vol 65, Issue 365 In-Reply-To: <783b47270902180131k3c14e190ocb3d2e5b546f32e@mail.gmail.com> References: <783b47270902180131k3c14e190ocb3d2e5b546f32e@mail.gmail.com> Message-ID: M Kumar wrote: > > I think the given statement below will give you what you r looking > .__file__print > [followed by a whole Python list digest] When replying to a question from a digest posting, PLEASE change the subject line and only quote the relevant piece of the original posting. Thank you. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From james at agentultra.com Wed Feb 18 10:15:51 2009 From: james at agentultra.com (J Kenneth King) Date: Wed, 18 Feb 2009 07:15:51 -0800 Subject: Musings: Using decorators to reduce duplicate exception handling References: <878wo4verq.fsf@agentultra.com> Message-ID: <874oyrvkrc.fsf@agentultra.com> "Gabriel Genellina" writes: > En Tue, 17 Feb 2009 21:12:57 -0200, J Kenneth King > escribi?: > >> I recently started a project called TracShell >> (http://code.google.com/p/tracshell) where I make heavy use of the >> xmlrpclib core module. >> >> When the number of RPC calls was small, wrapping each call in try/except >> was acceptable. However, this obviously will duplicate code all over the >> place. There are only ever two exceptions that the module itself will >> throw: xmlrpclib.ProtocolError and xmlrpclib.Fault -- both very useful, >> but not show stoppers. >> >> To combat the duplication, my clever idea was to use a function >> decorator to wrap any function that used xmlrpclib calls: >> >> def catch_errors(fn): >> """ >> A decorator to catch typical xmlrpclib exceptions >> """ >> def wrapped(*args, **kwargs): >> try: >> return fn(*args, **kwargs) >> except xmlrpclib.ProtocolError, e: >> print "There was a problem communicating with the server." >> print "URL: %s" % e.url >> print "Headers: %s" % e.headers >> print "Error code: %d" % e.errcode >> print "Error message: %s" % e.errmsg >> print "Please file a report with the TracShell developers." >> pass >> except xmlrpclib.Fault, e: >> print "A fault ocurred" >> print "Fault code: %d" % e.faultCode >> print "Fault string: %s" % e.faultString >> print "If you think this message is the result of an error," >> print "please file a report with the TracShell developers." >> pass >> return wrapped > > I don't like the idea of "hiding" an exception. The caller code > doesn't know an exception occurred, and just continue doing its work, > with bogus results... is this what you want? Also, you don't include > the stack trace - and usually it contains very valuable > information. When your users start "filing a report with the > TracShell developers" and you feel clueless, a stack trace is > important (you don't have to show it on screen - a log file is even > better). > > If all you want is to customize the error message, use sys.except_hook > > Looking into the code, those "pass" statement are useless; and error > messages are usually written to stderr instead of stdout. Thanks for the ideas. I haven't actually used this pattern in any projects before, I was just looking for a way to reduce the number of common try/except statements I needed to have in my code; especially when they all looked exactly the same and were catching every single xml-rpc call littered throughout my class. sys.except_hook looks more like what I was aiming for. I like Lisp's "restarts," where I can define error condition handlers in one place without having to litter my code with error handling statements. Cheers. From metallourlante at gmail.com Wed Feb 18 10:16:10 2009 From: metallourlante at gmail.com (Alex) Date: Wed, 18 Feb 2009 07:16:10 -0800 (PST) Subject: Searching Google? References: <6d1caedf-7d94-49e6-8a34-d4037202b7c7@i24g2000prf.googlegroups.com> <702dm1FkrikgU1@mid.dfncis.de> Message-ID: On Feb 18, 1:36?pm, Johannes Bauer wrote: > Curt Hash schrieb: > > > You just need to change your User-Agent so that Google doesn't know a > > Python script is making the request: > > Why would Google not send a response if the User-Agent header field is > not a recognized browser? Because making automated queries to Google is against its TOS so Google block any client that doesn't seam to be human. On the other hands Google's API does not return the same exact result as in a normal web query. My suggestion is: set a browser like User agent and accept gzipped content to be as friendly as possible and don't do too many queries in a small time span. Parsing Google result page with Beautifulsoup is a piece of cake. Alex From bieffe62 at gmail.com Wed Feb 18 10:19:20 2009 From: bieffe62 at gmail.com (bieffe62 at gmail.com) Date: Wed, 18 Feb 2009 07:19:20 -0800 (PST) Subject: Threads in PyGTK: keep typing while ping-ing References: Message-ID: <6f45d1c5-abce-4be1-81de-be47163d81ed@h5g2000yqh.googlegroups.com> On 17 Feb, 02:53, Mamahita Sela wrote: > Dear FB, > > > As you have been already told, join() blocks until the > > thread is > > terminated. and you should avoid that. > > A simple fix could by add a timeout to t.join, doing > > something like : > > ? ? ? ? t.join(JOIN_TIMEOUT); > > ? ? ? ? if not t.isAlive(): > > ? ? ? ? ? ? print t.result > > Thanks for your great sample. And, thank you for your tips on speedup the ping stuff. > > However, i still have problem when adding timeout to join(). > - It works, but only print out thread result that is not alive, as we put in the code. So, i never get result from unsuccessful ping action, which might take more time than timeout specified. > - I still have little delay in GUI. Is it possible to make it smooth in GUI operation? When i put more timeout (say: 0.5 from 0.2), i will have to wait ?longer. > > PS: thanks for pointing out inefficient ping action :) I will follow the tips. But, another time I might need to do something else, like downloading files, or checking for serial devices. So, this thread thing, imho, is very important. > > Any help would be very appreciated. > M. You could make all_threads an attribute of main instance, and use it to keep track of thread still alive. Therefore your do_ping code shoulds be somethiong like this (NOT TESTED): for h in range(100, 105): host = '192.168.0.%d' %(h) # worker = PingHost(host) worker.start() self.all_threads.append(worker) # for t in self.all_threads: t.join(JOIN_TIMEOUT); if not t.isAlive(): print t.result self.all_threads.remove(t) # return True In this way, you could use a small value for JOIN_TIMEOUT and make the GUI more responsive. The thread which are not found completed when do_ping is called will stay in self.all_threads and will be tested next time. I did not check the documentation, but assumed that gobject.timeout_add installs a _periodic_ timer. If it is not so, you have to reinstall the timer at the end of do_ping, if self.all_threads is not empty. And don't forget to initialize self.all_threads in __init__ ;) HTH Ciao ----- FB From python at bdurham.com Wed Feb 18 10:23:36 2009 From: python at bdurham.com (python at bdurham.com) Date: Wed, 18 Feb 2009 10:23:36 -0500 Subject: Best practice for upgrading the version of SQLite bundled with Python 2.6.1 In-Reply-To: References: <1234926555.19179.1300986603@webmail.messagingengine.com> Message-ID: <1234970616.27485.1301081573@webmail.messagingengine.com> Gabriel, > At least on Windows, you only have to replace sqlite3.dll (in the DLLs directory) with the new one, and that's all. That's easy! :) Thank you, Malcolm From mad.vijay at gmail.com Wed Feb 18 10:27:30 2009 From: mad.vijay at gmail.com (SamG) Date: Wed, 18 Feb 2009 07:27:30 -0800 (PST) Subject: Crypto headaches. References: <093e5e7e-0f64-4737-8eae-bc6c9ecab1ee@q40g2000prh.googlegroups.com> Message-ID: On Feb 18, 7:10 pm, "M.-A. Lemburg" wrote: > On 2009-02-18 14:23, SamG wrote: > > > Hi, > > > Using the python's Crypto.Cipher.Blowfish is create and encrypted file > > in the CBC mode. Now... when try to decrypt it with OpenSSL i get an > > error stating "bad magic number". > > Are you getting the error message from openssl ? It looks a lot > like an error message from Python. > > > I tried > > $ cat encr-file | openssl bf-cbc -d -pass pass:sam > org-file > > or > > $ openssl bf-cbc -d -pass pass:sam -in encr-file -out org-file > > > BTW, decryption using a python code works well. But i m of the > > impression a file encry with one program should/can be decrypt with > > another program (in my case openssl) using the same parameters. > > Ideally, that should work, but you also have to make sure that > the following two details are the same for both applications: > > 1. the way padding is done (Blowfish is a block cipher) > > 2. the way the initialization vector is set > > Otherwise the two won't interoperate properly. > > -- > Marc-Andre Lemburg > eGenix.com > > Professional Python Services directly from the Source (#1, Feb 18 2009)>>> Python/Zope Consulting and Support ... http://www.egenix.com/ > >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ > >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ > > ________________________________________________________________________ > > ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: > > eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 > D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg > Registered at Amtsgericht Duesseldorf: HRB 46611 > http://www.egenix.com/company/contact/ That must be it... But given a password how do i generate a (key, IV) pair??? SamG From oswald.harry at gmail.com Wed Feb 18 11:29:34 2009 From: oswald.harry at gmail.com (harryos) Date: Wed, 18 Feb 2009 08:29:34 -0800 (PST) Subject: how to list all installed modules Message-ID: hi Is there a way to list all the installed modules in my python installation.I recently installed pygame and when i tried to import it like >>import pygame it complained that no such module was found.I can see the pygame directory in F:\Python25\Lib\site-packages in my machine,but am unable to import the module.So I was wondering if there is a way to list all the installed modules any help much appreciated thanks harry From __peter__ at web.de Wed Feb 18 11:42:07 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 18 Feb 2009 17:42:07 +0100 Subject: how to list all installed modules References: Message-ID: harryos wrote: > Is there a way to list all the installed modules in my python > installation.I recently installed pygame and when i tried to import it > like >>>import pygame > it complained that no such module was found.I can see the pygame > directory in F:\Python25\Lib\site-packages in my machine,but am unable > to import the module.So I was wondering if there is a way to list all > the installed modules >>> help("modules") may help to get a list of modules (if it doesn't fail with an exception as over here). Regarding the original problem, do you have multiple Python installations? If so, you may accidentally be running the "wrong" python. Peter From zamnedix at gmail.com Wed Feb 18 11:45:16 2009 From: zamnedix at gmail.com (Zamnedix) Date: Wed, 18 Feb 2009 08:45:16 -0800 (PST) Subject: Python 3D CAD -- need collaborators, or just brave souls :) References: Message-ID: On Feb 9, 12:58?pm, rantingrick wrote: > Hello all, > > It has long been my dream to create an open source 3D CAD program and > i am starting to crawl my way into the first steps. I now believe i am > ready to start this endeavor and i am currently looking for fellow > Python programmers (no matter what skill level) to get started > brainstorming this design. > > I have a real good idea of the UI design and at this point i just want > to start simple and build this thing. I figure this will be a good > learning experience for myself and others and in the process i can > realize my dream. And if all this turns out to be is a learning > experience, well nobody lost. > > Of course Python will limit the speed here, but at this point i want > to get a template up and running. Speed does not matter at this point, > and optimizations can come along later as i am sure a few complete re- > writes are inevitable :) > > My initial start will cover a very simple user interface something > like VPython but much more usable as a CAD modeler. From the start > just a few simple primitives (faces, lines-segments) that will be the > building blocks for more complex models like (arcs, rectangles, > circles, polygons, cubes, spheres, etc..). > > There will need to be mouse picking as i see this application as a > very interactive environment. Of course in the beginning all > interaction will most likely be in a command line type manner until > the functionality can be worked out. > > There will need to be a hierarchy of instancing and grouping within > the model to facilitate easy transformation of entities within the > model. > > I am not too worried about any sort of texturing at this point. I want > to squeeze as much speed as possible and prettiness will come in due > course. I also have no plans for layering, or multiple scenes at this > time. Simple functionality is the end game here. > > Once the UI is there and the modeling work flow is worked out, > everything should be a component add-on from there. > > So the main points are... > > #-- Entities --# > ?face > ?line-segment > > #-- Hierarchy --# > ?Entity (one face, or line-segment) > ?Group (contained of multiple entities that can be translated, > rotated, scaled as one) > ?Instance (component definition) > > #-- Tools --# > ?line > ?rect > ?circle > ?arc > ?select > ?rotation > ?translation > ?scale > ?extrusion along path > ?measurement > > So there it is. Any takers? :) I realize this isn't necessarily CAD, but... http://www.blender.org/ From oswald.harry at gmail.com Wed Feb 18 12:08:14 2009 From: oswald.harry at gmail.com (harryos) Date: Wed, 18 Feb 2009 09:08:14 -0800 (PST) Subject: how to list all installed modules References: Message-ID: <48383a90-80a0-4c2f-a79c-47c9c480581c@g3g2000pre.googlegroups.com> On Feb 18, 9:42?pm, Peter Otten <__pete... at web.de> wrote: > >>> help("modules") thanks Peter.That helped. > Regarding the original problem, do you have multiple Python installations? > If so, you may accidentally be running the "wrong" python. I have only one installation.It shows all other modules.I will try reinstalling . regards, harry From sam at 2000soft.com Wed Feb 18 12:08:41 2009 From: sam at 2000soft.com (Sam Clark) Date: Wed, 18 Feb 2009 09:08:41 -0800 Subject: Revision Control Message-ID: <822B0E83D23291469317E3432468743702224B@production.2000soft.com> Any suggestions for a beginer on what to use for version control? It's just me, the lone person programming. I've already nailed one "version" of my code accidentaly. MS VSS is too expensive for the stuff I'm doing, plus I really don't like MS much... Any free open source stuff out there? Thank you, Sam Clark sam at 2000soft.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Wed Feb 18 12:12:03 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 18 Feb 2009 09:12:03 -0800 Subject: Revision Control In-Reply-To: <822B0E83D23291469317E3432468743702224B@production.2000soft.com> References: <822B0E83D23291469317E3432468743702224B@production.2000soft.com> Message-ID: <50697b2c0902180912n2ba49600md70eefd7cc2260@mail.gmail.com> On Wed, Feb 18, 2009 at 9:08 AM, Sam Clark wrote: > Any suggestions for a beginer on what to use for version control? It's > just me, the lone person programming. I've already nailed one "version" of > my code accidentaly. MS VSS is too expensive for the stuff I'm doing, plus > I really don't like MS much... Any free open source stuff out there? I like Mercurial (hg) personally: http://www.selenic.com/mercurial/wiki/ It's written in Python, works well on Windows, is a modern distributed VCS, and is simpler than Git. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From zaheer.agadi at gmail.com Wed Feb 18 12:13:17 2009 From: zaheer.agadi at gmail.com (zaheer.agadi at gmail.com) Date: Wed, 18 Feb 2009 09:13:17 -0800 (PST) Subject: why do I get name not defined error Message-ID: <092b37eb-1ac6-4cbb-8059-e0f8495de4f7@p2g2000prf.googlegroups.com> Hi, I have the following declared in my class, I am trying tp call a method defined in the same class I am not sure why I am getting name not defined error if options.uploadFile != None : print "This is path", the_rest filePath = the_rest UploadFile(None,filePath) def UploadFile(self,path): print "I wil upload now" os.chdir(homeFolder) config = ConfigParser.ConfigParser() ..... any ideas why the error name UploadFile not defined Thnaks From deets at nospam.web.de Wed Feb 18 12:17:00 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 18 Feb 2009 18:17:00 +0100 Subject: why do I get name not defined error In-Reply-To: <092b37eb-1ac6-4cbb-8059-e0f8495de4f7@p2g2000prf.googlegroups.com> References: <092b37eb-1ac6-4cbb-8059-e0f8495de4f7@p2g2000prf.googlegroups.com> Message-ID: <702u4dFmcsarU1@mid.uni-berlin.de> zaheer.agadi at gmail.com schrieb: > Hi, > > I have the following declared in my class, I am trying tp call a > method defined in the same class > I am not sure why I am getting name not defined error > > if options.uploadFile != None : > print "This is path", the_rest > filePath = the_rest > UploadFile(None,filePath) > > def UploadFile(self,path): > print "I wil upload now" > os.chdir(homeFolder) > config = ConfigParser.ConfigParser() > ..... > > any ideas why the error name UploadFile not defined > Because you need to define things *before* you use them the first time. This is not to be confused with forward-declarations, as they are needed in C for example - in python you can do def foo(): bar() def bar(): foo() (resulting in an endless loop of course) But you can't do def foo(): bar() foo() # this will fail def bar(): foo() Diez From __peter__ at web.de Wed Feb 18 12:22:36 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 18 Feb 2009 18:22:36 +0100 Subject: why do I get name not defined error References: <092b37eb-1ac6-4cbb-8059-e0f8495de4f7@p2g2000prf.googlegroups.com> Message-ID: zaheer.agadi at gmail.com wrote: > I have the following declared in my class, I am trying tp call a > method defined in the same class > I am not sure why I am getting name not defined error Assuming this is part of a method def method(self): > if options.uploadFile != None : > print "This is path", the_rest > filePath = the_rest > UploadFile(None,filePath) you have to change the above line to self.UploadFile(filePath) Now consider reading a tutorial before you proceed. Peter From benjamin.kaplan at case.edu Wed Feb 18 12:39:53 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 18 Feb 2009 12:39:53 -0500 Subject: Revision Control In-Reply-To: <822B0E83D23291469317E3432468743702224B@production.2000soft.com> References: <822B0E83D23291469317E3432468743702224B@production.2000soft.com> Message-ID: On Wed, Feb 18, 2009 at 12:08 PM, Sam Clark wrote: > Any suggestions for a beginer on what to use for version control? It's > just me, the lone person programming. I've already nailed one "version" of > my code accidentaly. MS VSS is too expensive for the stuff I'm doing, plus > I really don't like MS much... Any free open source stuff out there? > There's actually a lot of them. These are just the ones I can think of off the top of my head. -CVS (One of the first RCS, I think most projects are moving away from this one.) - Subversion-(pretty popular right now, but it is a client/server model.) -Git (originally created for Linux and now used by several very large projects) -Mercurial (this is a big up and coming RCS) -Bazaar (written in Python. Also pretty new. I don't know about Windows support) I have some experience with both Subversion and Mercurial and like them both. Since you're working alone, you'll probably want a distributed rcs, such as Mercurial, Git, and Bazaar, which allow you to do more stuff locally rather than on a central server. Like Chris, I'd suggest Mercurial especially if you're using Windows. Thank you, > > Sam Clark > sam at 2000soft.com > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From Scott.Daniels at Acm.Org Wed Feb 18 13:10:53 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 18 Feb 2009 10:10:53 -0800 Subject: how to list all installed modules In-Reply-To: References: Message-ID: <4-6dndjITMU90wHUnZ2dnUVZ_qvinZ2d@pdx.net> harryos wrote: > Is there a way to list all the installed modules in my python > installation.I recently installed pygame and when i tried to import it > like >>> import pygame > it complained that no such module was found.I can see the pygame > directory in F:\Python25\Lib\site-packages in my machine,but am unable > to import the module.So I was wondering if there is a way to list all > the installed modules Are you running F:\Python25\python.exe (or F:\Python25\pythonw.exe)? open a command window (run cmd), and type: C:\> python ... >>> import sys >>> for dirname in sys.path: print sys.path I suspect something you see printed will surprise you. Either the banner, identifying a Python version you were not expecting, or perhaps a bunch of C:-based directories. If this does not help you decipher the problem, try running python -v Python verbose mode (You will get a _lot_ of output). Then, when you (finally) get a ">>>" prompt, type: >>> import pygame and you will see eaxctly what lookups are tried. --Scott David Daniels Scott.Daniels at Acm.Org From thomasmallen at gmail.com Wed Feb 18 13:17:39 2009 From: thomasmallen at gmail.com (Thomas Allen) Date: Wed, 18 Feb 2009 10:17:39 -0800 (PST) Subject: "Maximum recursion depth exceeded"...why? References: <847153c1-579e-4e4f-a21d-dcf106f15636@r41g2000yqm.googlegroups.com> <7xr61w8r20.fsf@ruckus.brouhaha.com> Message-ID: <788cab73-b999-48e4-beb3-b9dd38c501de@j8g2000yql.googlegroups.com> On Feb 18, 4:51?am, alex23 wrote: > On Feb 18, 7:34?pm, rdmur... at bitdance.com wrote: > > > Yeah, but wget -r -k will do that bit of it, too. > > Wow, nice, I don't know why I never noticed that. Cheers! Hm...doesn't do that over here. I thought it may have been because of absolute links (not to site root), but it even leaves things like . Does it work for you guys? From skip at pobox.com Wed Feb 18 13:34:09 2009 From: skip at pobox.com (skip at pobox.com) Date: Wed, 18 Feb 2009 12:34:09 -0600 Subject: Revision Control In-Reply-To: <50697b2c0902180912n2ba49600md70eefd7cc2260@mail.gmail.com> References: <822B0E83D23291469317E3432468743702224B@production.2000soft.com> <50697b2c0902180912n2ba49600md70eefd7cc2260@mail.gmail.com> Message-ID: <18844.21665.189434.503197@montanaro.dyndns.org> >> Any suggestions for a beginer on what to use for version control? Chris> I like Mercurial (hg) personally... Me too. It's perfect for little one-person things. (It's probably good for other stuff as well, but I certainly like how easy it is to use for standalone stuff.) -- Skip Montanaro - skip at pobox.com - http://www.smontanaro.net/ From python.list at tim.thechases.com Wed Feb 18 13:36:17 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 18 Feb 2009 12:36:17 -0600 Subject: Revision Control In-Reply-To: References: <822B0E83D23291469317E3432468743702224B@production.2000soft.com> Message-ID: <499C5521.2040705@tim.thechases.com> > -CVS (One of the first RCS, I think most projects are moving away from this > one.) I wouldn't suggest starting a new project with CVS. Subversion (svn) resolves several of the main issues with it, so using SVN instead wins over CVS in just about every possible way. > - Subversion-(pretty popular right now, but it is a client/server model.) A good solid & popular choice, but the merging capabilities are a bit weak (the latest version just added some better capabilities for branching/merging, but it's a bit of a hack). It's also not the most efficient storage -- git and mercurial (hg) both have very efficient repository structures compared to SVN. The family DVCS tools (git, mercurial, bzr, darcs) are stronger in this area. My employer uses SVN for their primary repository. Documentation is outstandingly good (documentation for the others is also good, but SVN's is exceptional). > -Git (originally created for Linux and now used by several very large > projects) I've tried several times to like git -- some folks swear by it. The Win32 support has been a bit wanting, but growing. I find it a bit more complex but it's certainly not lacking for power. I'll continue to try it occasionally to see if it meets my needs better than Mercurial > -Mercurial (this is a big up and coming RCS) This is currently my favorite: good branching/merging, fast, written mostly in Python (one C extension module, IIRC), and a simple interface > -Bazaar (written in Python. Also pretty new. I don't know about Windows > support) I like Bazaar (bzr), but the last several times I've tried it, it's been a little slow. This has been steadily improving, and I like their emphasis on correctness foremost. It's a lot like mercurial, but is pure python (no C extension module) which makes it nice to deploy into environments such as my shared web-hosting service where I can't build extension C modules or install packages such as hg/git/svn from the repository. All of them have GUI interfaces if you need, but I tend to just use them from the command-line. For most of them, you can get by with a handful of commands without needing to learn every last corner. For what you (the OP) describe, I'd suggest SVN, Mercurial, or Bazaar as they're a little easier to wrap your head around -- SVN wins for documentation, Mercurial wins for speed and merging, and Bazaar wins for portability and merging. Git would win for sheer power, but if you're just beginning, I'd skip it for now. -tkc From lionel.keene at gmail.com Wed Feb 18 13:48:56 2009 From: lionel.keene at gmail.com (Lionel) Date: Wed, 18 Feb 2009 10:48:56 -0800 (PST) Subject: numpy.memmap advice? References: <59449976-a334-411a-bdc8-7e6041bd4a37@g1g2000pra.googlegroups.com> Message-ID: On Feb 18, 12:56?am, Carl Banks wrote: > On Feb 17, 3:08?pm, Lionel wrote: > > > > > > > Hello all, > > > On a previous thread (http://groups.google.com/group/comp.lang.python/ > > browse_thread/thread/64da35b811e8f69d/67fa3185798ddd12? > > hl=en&lnk=gst&q=keene#67fa3185798ddd12) I was asking about reading in > > binary data. Briefly, my data consists of complex numbers, 32-bit > > floats for real and imaginary parts. The data is stored as 4 bytes > > Real1, 4 bytes Imaginary1, 4 bytes Real2, 4 bytes Imaginary2, etc. in > > row-major format. I needed to read the data in as two separate numpy > > arrays, one for real values and one for imaginary values. > > > There were several very helpful performance tips offered, and one in > > particular I've started looking into. The author suggested a > > "numpy.memmap" object may be beneficial. It was suggested I use it as > > follows: > > > descriptor = dtype([("r", " > data = memmap(filename, dtype=descriptor, mode='r').view(recarray) > > print "First 100 real values:", data.r[:100] > > > I have two questions: > > 1) What is "recarray"? > > Let's look: > > [GCC 4.3.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information.>>> import numpy > >>> numpy.recarray > > > > >>> help(numpy.recarray) > > Help on class recarray in module numpy.core.records: > > class recarray(numpy.ndarray) > ?| ?recarray(shape, dtype=None, buf=None, **kwds) > ?| > ?| ?Subclass of ndarray that allows field access using attribute > lookup. > ?| > ?| ?Parameters > ?| ?---------- > ?| ?shape : tuple > ?| ? ? ?shape of record array > ?| ?dtype : data-type or None > ?| ? ? ?The desired data-type. ?If this is None, then the data-type is > determine > ?| ? ? ?by the *formats*, *names*, *titles*, *aligned*, and > *byteorder* keywords > ?| ?buf : [buffer] or None > ?| ? ? ?If this is None, then a new array is created of the given > shape and data > ?| ? ? ?If this is an object exposing the buffer interface, then the > array will > ?| ? ? ?use the memory from an existing buffer. ?In this case, the > *offset* and > ?| ? ? ?*strides* keywords can also be used. > ... > > So there you have it. ?It's a subclass of ndarray that allows field > access using attribute lookup. ?(IOW, you're creating a view of the > memmap'ed data of type recarray, which is the type numpy uses to > access structures by name. ?You need to create the view because > regular numpy arrays, which numpy.memmap creates, can't access fields > by attribute.) > > help() is a nice thing to use, and numpy is one of the better > libraries when it comes to docstrings, so learn to use it. > > > 2) The documentation for numpy.memmap claims that it is meant to be > > used in situations where it is beneficial to load only segments of a > > file into memory, not the whole thing. This is definately something > > I'd like to be able to do as my files are frequently >1Gb. I don't > > really see in the diocumentation how portions are loaded, however. > > They seem to create small arrays and then assign the entire array > > (i.e. file) to the memmap object. Let's assume I have a binary data > > file of complex numbers in the format described above, and let's > > assume that the size of the complex data array (that is, the entire > > file) is 100x100 (rows x columns). Could someone please post a few > > lines showing how to load the top-left 50 x 50 quadrant, and the lower- > > right 50 x 50 quadrant into memmap objects? Thank you very much in > > advance! > > You would memmap the whole region in question (in this case the whole > file), then take a slice. ?Actually you could get away with memmapping > just the last 50 rows (bottom half). ?The offset into the file would > be 50*100*8, so: > > data = memmap(filename, dtype=descriptor, mode='r',offset= > (50*100*8)).view(recarray) > reshaped_data = reshape(data,(50,100)) > intersting_data = reshaped_data[:,50:100] > > A word of caution: Every instance of numpy.memmap creates its own mmap > of the whole file (even if it only creates an array from part of the > file). ?The implications of this are A) you can't use numpy.memmap's > offset parameter to get around file size limitations, and B) you > shouldn't create many numpy.memmaps of the same file. ?To work around > B, you should create a single memmap, and dole out views and slices. > > Carl Banks- Hide quoted text - > > - Show quoted text - Thanks Carl, I like your solution. Am I correct in my understanding that memory is allocated at the slicing step in your example i.e. when "reshaped_data" is sliced using "interesting_data = reshaped_data[:, 50:100]"? In other words, given a huge (say 1Gb) file, a memmap object is constructed that memmaps the entire file. Some relatively small amount of memory is allocated for the memmap operation, but the bulk memory allocation occurs when I generate my final numpy sub-array by slicing, and this accounts for the memory efficiency of using memmap? From johnson at pharmacy.arizona.edu Wed Feb 18 14:28:15 2009 From: johnson at pharmacy.arizona.edu (bleah) Date: Wed, 18 Feb 2009 11:28:15 -0800 (PST) Subject: PIL install driving me mad! With solution! Message-ID: I'm trying to get PIL 1.16 installed on a SUSE SLES10 system, and cannot, for the life of me, get the thing to compile with jpeg support. The libjpeg-devel libraries are installed, and are present in /usr/lib JUST WHERE SPECIFIED in the setup.py file, and the jpeglib.h incliude file is present JUST WHERE SPECIFIED in the setup.py file. The build process proceeds without errors, yet selftest.py fails with the error: tonic:~/html2pdf_sources/Imaging-1.1.6 # python selftest.py ***************************************************************** Failure in example: _info(Image.open("Images/lena.jpg")) from line #24 of selftest.testimage Exception raised: Traceback (most recent call last): File "./doctest.py", line 499, in _run_examples_inner exec compile(source, "", "single") in globs File "", line 1, in File "./selftest.py", line 22, in _info im.load() File "PIL/ImageFile.py", line 180, in load d = Image._getdecoder(self.mode, d, a, self.decoderconfig) File "PIL/Image.py", line 375, in _getdecoder raise IOError("decoder %s not available" % decoder_name) IOError: decoder jpeg not available 1 items had failures: 1 of 57 in selftest.testimage ***Test Failed*** 1 failures. *** 1 tests of 57 failed. Again and again and again. I found this post http://blog.tlensing.org/2008/12/04/kill-pil-?-the-python-imaging-library-headache which provided the solution. When you run selftest.py in the Imaging-1.1.6 directory, python finds the PIL.pth and PIL file and directory, respectively and uses those instead of the properly compiled versions in the python directories. So PIL is installed, it IS working perfectly, it's selftest.py that's failing... From lionel.keene at gmail.com Wed Feb 18 14:43:09 2009 From: lionel.keene at gmail.com (Lionel) Date: Wed, 18 Feb 2009 11:43:09 -0800 (PST) Subject: PyGTK install Message-ID: Hello folks, I couldn't find a specific PyGTK forum so I thought I'd post here and hope someone new the answer. I feel it's a silly problem, maybe something to do with a path variable? The problem: I've downloaded the "all-in-one" windows binary installer for PyGTK from their website. After typing in their first tutorial program and trying to run from the command line, I get: "This application has failed to start because libglib-2.0-0.dll was not found" error dialog. The traceback indicates this is happening at the "import gtk" line. A quick search of my install directory for PyGTK indicates that the file is indeed resident and located in C:\Program files\PyGTK\GTK\bin. Is there some some sort of path variable for Python I need to modify and, if so, how is this done? Thanks so much, and my apologies if this is the wrong forum. -L From jervisau at gmail.com Wed Feb 18 14:44:02 2009 From: jervisau at gmail.com (Jervis Whitley) Date: Thu, 19 Feb 2009 06:44:02 +1100 Subject: Pythonic way to determine if one char of many in a string In-Reply-To: References: <1234761457.20683.1300568627@webmail.messagingengine.com> <01aa9ea5$0$20632$c3e8da3@news.astraweb.com> Message-ID: <8e63a5ce0902181144q6e5405a2y9b393a34cf4d7d58@mail.gmail.com> > > What happens when you have hundreds of megabytes, I don't know. > > I hope I never have to test a word that is hundreds of megabytes long for a vowel :) From steve at holdenweb.com Wed Feb 18 15:05:47 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 18 Feb 2009 15:05:47 -0500 Subject: Pythonic way to determine if one char of many in a string In-Reply-To: <8e63a5ce0902181144q6e5405a2y9b393a34cf4d7d58@mail.gmail.com> References: <1234761457.20683.1300568627@webmail.messagingengine.com> <01aa9ea5$0$20632$c3e8da3@news.astraweb.com> <8e63a5ce0902181144q6e5405a2y9b393a34cf4d7d58@mail.gmail.com> Message-ID: Jervis Whitley wrote: >> What happens when you have hundreds of megabytes, I don't know. >> >> > I hope I never have to test a word that is hundreds of megabytes long > for a vowel :) I see you don't speak German ;-) -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From __peter__ at web.de Wed Feb 18 15:12:45 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 18 Feb 2009 21:12:45 +0100 Subject: Pythonic way to determine if one char of many in a string References: <1234761457.20683.1300568627@webmail.messagingengine.com> <01aa9ea5$0$20632$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Wed, 18 Feb 2009 07:08:04 +1100, Jervis Whitley wrote: > > >>> This moves the for-loop out of slow Python into fast C and should be >>> much, much faster for very large input. >>> >>> >> _Should_ be faster. > > Yes, Python's timing results are often unintuitive. Indeed. > It seems to me that I was mistaken -- for large enough input, the running > time of each version converges to approximately the same speed. No, you were right. Both any_test() and for_test() use the improvement you suggested, i. e. loop over the vowels, not the characters of the word. Here's the benchmark as it should have been: $ python -m timeit -s'word = "g"*10000' 'any(v in word for v in "aeiouAEIOU")' 1000 loops, best of 3: 314 usec per loop $ python -m timeit -s'word = "g"*10000' 'any(c in "aeiouAEIOU" for c in word)' 100 loops, best of 3: 3.48 msec per loop Of course this shows only the worst case behaviour. The results will vary depending on the actual word e. g. "Ug..." or "g...a". Peter From eliben at gmail.com Wed Feb 18 15:18:27 2009 From: eliben at gmail.com (eliben) Date: Wed, 18 Feb 2009 12:18:27 -0800 (PST) Subject: number theory libraries / project euler Message-ID: Hello, What are some good & recommended number theory libs for Python (or accessible interfaces to C libs), for things like primes, factorization, etc. Naturally, speed is of utmost importance here. In other words, which Python libraries and tools to you use to help you solve Project Euler problems :-) ? Eli From __peter__ at web.de Wed Feb 18 15:22:45 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 18 Feb 2009 21:22:45 +0100 Subject: Pythonic way to determine if one char of many in a string References: <1234761457.20683.1300568627@webmail.messagingengine.com> <01aa9ea5$0$20632$c3e8da3@news.astraweb.com> <8e63a5ce0902181144q6e5405a2y9b393a34cf4d7d58@mail.gmail.com> Message-ID: Steve Holden wrote: > Jervis Whitley wrote: >>> What happens when you have hundreds of megabytes, I don't know. >>> >>> >> I hope I never have to test a word that is hundreds of megabytes long >> for a vowel :) > > I see you don't speak German ;-) I tried to come up with a funny way to point out that you're a fool. But because I'm German I failed. Peter From josh.dukes at microvu.com Wed Feb 18 15:27:04 2009 From: josh.dukes at microvu.com (Josh Dukes) Date: Wed, 18 Feb 2009 12:27:04 -0800 Subject: Python 3D CAD -- need collaborators, or just brave souls :) In-Reply-To: <9ef65856-0f62-4434-a4b4-e15558e7c7b0@n2g2000vba.googlegroups.com> References: <4993DE39.8030200@cosc.canterbury.ac.nz> <9ef65856-0f62-4434-a4b4-e15558e7c7b0@n2g2000vba.googlegroups.com> Message-ID: <20090218122704.30bfda77@microvu.com> You might also want to look in to open cascade. It supports a bunch of standard 3d model formats (stl, iges, step) and has python bindings. Salome is based on open cascade. http://www.pythonocc.org/ However, I'm not entirely clear on the license for this so that might be an issue. I know the Debian lawyers had some problems with Salome because it compiled against open cascade. I believe if you made open cascade an optional run-time dependency it could still be a valid gpl app. It's also important to keep in mind that what most people think of as cad/cam is really multiple things that can be broken up into modules (cad/cam/fea). Those can also be broken up into modules (fea can be broken into meshing, pre-processing, analysis, and post-processing). It seems like attacking things this way might be best. If you're really serious about this (there are lots of failed Linux cad packages) I'd suggest setting up a project on sourceforge and get a mailing list. Post a link to the mailing list and I'll join. I can probably find some other mailing lists that you should try to recruit from, but having a sourceforge page and a mailing list really helps your legitimacy. Another interesting project is FreeCAD, which is written in C++ but compiled against python, http://juergen-riegel.net/FreeCAD/Docu/index.php?title=Main_Page might be worth looking at. I look forward to joining your mailing list. On Wed, 18 Feb 2009 01:02:22 -0800 (PST) r wrote: > Hello Josh, > Blender is a lost cause. It is a powerful app but the UI is horrible. > Even the Blender folks admit only a complete rewrite could solve the > major flaws that plague the design. So maybe i could salvage some code > but for what i have in mind, Blender will look like a piece of > software from the middle ages. And i am absolutly only looking to do > this in 3D, 2D is boring. > > So, yes, i have looked at both the applications you offer. > > Thanks > -- > http://mail.python.org/mailman/listinfo/python-list -- Josh Dukes MicroVu IT Department From kwmsmith at gmail.com Wed Feb 18 15:31:55 2009 From: kwmsmith at gmail.com (Kurt Smith) Date: Wed, 18 Feb 2009 14:31:55 -0600 Subject: number theory libraries / project euler In-Reply-To: References: Message-ID: On Wed, Feb 18, 2009 at 2:18 PM, eliben wrote: > > Hello, > > What are some good & recommended number theory libs for Python (or > accessible interfaces to C libs), for things like primes, > factorization, etc. Naturally, speed is of utmost importance here. > > In other words, which Python libraries and tools to you use to help > you solve Project Euler problems :-) ? There's Sage: http://www.sagemath.org/ -- I believe it aims to do everything that Mathematica can do and more, and I know it has some number theory libs, too. I haven't had the occasion to use it myself. Much of the fun of project euler problems is 'rolling your own,' or implementing a classic algorithm from a description of it on Wikipedia. A good sieve of eratosthenes in pure Python (that I tend to use quite often) is here: http://code.activestate.com/recipes/117119/ You can find some combinatorics in numpy, I believe. Often the solutions are one-to-five liners, if you've thought the problem through. Too much dependence on external libraries robs the project euler problems of their fun, IMO. Best, Kurt From andrew at acooke.org Wed Feb 18 15:32:12 2009 From: andrew at acooke.org (andrew cooke) Date: Wed, 18 Feb 2009 17:32:12 -0300 (CLST) Subject: number theory libraries / project euler In-Reply-To: References: Message-ID: <1b7a4f36961f874388857ae7e8f2a3cc.squirrel@localhost> eliben wrote: > Hello, > > What are some good & recommended number theory libs for Python (or > accessible interfaces to C libs), for things like primes, > factorization, etc. Naturally, speed is of utmost importance here. i just read the project site and one of the things they say on their front page is that all problems have a solution that should run in "under a minute". the emphasis is on finding the right algorithm, not brute force number crunching. so i am not sure that speed is of much importance at all. > In other words, which Python libraries and tools to you use to help > you solve Project Euler problems :-) ? you may want to look at numpy and scipy, but looking at the first dozen questions i think ordinary python may be sufficient. andrew From pavlovevidence at gmail.com Wed Feb 18 15:35:55 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 18 Feb 2009 12:35:55 -0800 (PST) Subject: numpy.memmap advice? References: <59449976-a334-411a-bdc8-7e6041bd4a37@g1g2000pra.googlegroups.com> Message-ID: <66395359-fca2-4e31-8ff9-5fbf51654d1b@v38g2000yqb.googlegroups.com> On Feb 18, 10:48?am, Lionel wrote: > Thanks Carl, I like your solution. Am I correct in my understanding > that memory is allocated at the slicing step in your example i.e. when > "reshaped_data" is sliced using "interesting_data = reshaped_data[:, > 50:100]"? In other words, given a huge (say 1Gb) file, a memmap object > is constructed that memmaps the entire file. Some relatively small > amount of memory is allocated for the memmap operation, but the bulk > memory allocation occurs when I generate my final numpy sub-array by > slicing, and this accounts for the memory efficiency of using memmap? No, what accounts for the memory efficienty is there is no bulk allocation at all. The ndarray you have points to the memory that's in the mmap. There is no copying data or separate array allocation. Also, it's not any more memory efficient to use the offset parameter with numpy.memmap than it is to memmap the whole file and take a slice. Carl Banks From cs at zip.com.au Wed Feb 18 16:33:50 2009 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 19 Feb 2009 08:33:50 +1100 Subject: Musings: Using decorators to reduce duplicate exception handling In-Reply-To: <878wo4verq.fsf@agentultra.com> Message-ID: <20090218213350.GA23549@cskk.homeip.net> On 17Feb2009 15:12, J Kenneth King wrote: | I recently started a project called TracShell | (http://code.google.com/p/tracshell) where I make heavy use of the | xmlrpclib core module. | | When the number of RPC calls was small, wrapping each call in try/except | was acceptable. [...] | To combat the duplication, my clever idea was to use a function | decorator to wrap any function that used xmlrpclib calls: | def catch_errors(fn): [...] | Maybe I could rename the decorator to something meaningful, but besides | that it works pretty well. Now any function I write in my class that | uses RPC calls can be wrapped by this decorator and have the exception | handling done in a uniform way for these particular exceptions. My Python fu is still weak, but I had a similar issue last year and wrote a context manager, used thus: with NoExceptions(handler): ... do stuff that may break ... The constructor takes a handleException argument (which may be None, but it has to be explicit) to tune which exceptions are caught; default is everything. This was for a daemon thread that did RPC calls, so it was actually fairly important to never die; normally you'd want to catch only specific exceptions. Code: class NoExceptions(object): ''' A context manager to catch _all_ exceptions and log them. Arguably this should be a bare try...except but that's syntacticly noisy and separates the catch from the top. ''' def __init__(self, handleException): ''' Initialise the NoExceptions context manager. The handleException is a callable which expects (exc_type, exc_value, traceback) and returns True or False for the __exit__ method of the manager. If handleException is None, the __exit__ method always returns True, suppressing any exception. ''' self.__handler = handleException def __enter__(self): pass def __exit__(self, exc_type, exc_value, traceback): if self.__handler is not None: return self.__handler(exc_type, exc_value, traceback) if exc_type is not None: print >>sys.stderr, "ignore %s" % (exc_type,) return True It doesn't actually solve your duplication issue and is a bit of a niche application, but it's a lot shorter than an inline try/except and to my eye reads a little better, and it keeps the exception handling up front at the calling end where it is visible. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ From gagsl-py2 at yahoo.com.ar Wed Feb 18 16:39:24 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 18 Feb 2009 19:39:24 -0200 Subject: Directory References: <6d92ee1b-75ba-4ba8-8dc3-625966b17835@d32g2000yqe.googlegroups.com> Message-ID: En Wed, 18 Feb 2009 12:15:25 -0200, Steve Holden escribi?: > gtillmon wrote: >> I would like to know how to display and store the path of each mondule >> that is called. > It's certainly possible to trace function calls, if that would help. > sys.settrace allows you to establish a function that gets called If the OP is only interested in import statements, perhaps the -v flag is enough: python -v script_name.py It prints a line (on stderr) for each module imported, stating its name and source file. -- Gabriel Genellina From rgoldman23 at gmail.com Wed Feb 18 16:42:05 2009 From: rgoldman23 at gmail.com (Rudi Goldman) Date: Wed, 18 Feb 2009 13:42:05 -0800 Subject: Delete lines which contain string in a file Message-ID: <7cbf2f3a0902181342w20d3bcbfnf640a177b221c8a6@mail.gmail.com> Hi, Go easy on me as I am a new to Python and am trying to solve a practical problem that is driving me bananas. Basically I have 2 text files, a source and a target. I want to be able to delete all of the lines in the target file which contain text from any line in the source file. i.e. Source: Target: 111 xxx 111 yyy 222 xxx 333 sss 333 jjj 444 sss After executing this code the target file should only consist of the line: jjj 444 sss Any help on this one would be greatly appreciated. Thanks, Rudi -------------- next part -------------- An HTML attachment was scrubbed... URL: From castironpi at gmail.com Wed Feb 18 16:43:45 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 18 Feb 2009 13:43:45 -0800 (PST) Subject: PyTypeObject subclass Message-ID: Hi, Is it ok to subclass PyTypeObject, so that my custom 'tp_' fields can appear at the bottom of it? Is there anything like size requirements going on in its code? Or is it better to use 'tp_dict' or slots? Thanks. From tim.wintle at teamrubber.com Wed Feb 18 16:46:24 2009 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Wed, 18 Feb 2009 21:46:24 +0000 Subject: Searching Google? In-Reply-To: <702dm1FkrikgU1@mid.dfncis.de> References: <6d1caedf-7d94-49e6-8a34-d4037202b7c7@i24g2000prf.googlegroups.com> <702dm1FkrikgU1@mid.dfncis.de> Message-ID: <1234993584.7867.22.camel@tim-laptop> On Wed, 2009-02-18 at 13:36 +0100, Johannes Bauer wrote: > Curt Hash schrieb: > > > You just need to change your User-Agent so that Google doesn't know a > > Python script is making the request: > > Why would Google not send a response if the User-Agent header field is > not a recognized browser? I doubt that's what's happening and the OP > would just like the convenience of a search API instead of parsing the > web page (like other applications do). Ugly, but it works. I suspect that it's the other way around - Google has black-listed the standard python user-agent rather than whitelisting useragents. Think about how much power it takes to do a query on Google - if they provided a search API they would lose out on advertising on the results - which at the end of the day is their income-source. It's a pain not to have a search API, but you've got to understand it! From SiteContactUs at gmail.com Wed Feb 18 16:49:36 2009 From: SiteContactUs at gmail.com (beetlecube) Date: Wed, 18 Feb 2009 13:49:36 -0800 (PST) Subject: Can't get the IPYthon ipapi object working Message-ID: <64e1c5b4-efda-4a52-9b99-05762cb2bef5@t39g2000prh.googlegroups.com> Hi , I found out from a random google search that I could use IPython to automatically import modules so that I could test Django views. I downloaded it (WIN XP), installed it. I'm able to import it, but I just can't seem to get the object working. The code: ----------------------------------- try: import IPython.ipapi ip = IPython.ipapi.get() a = ip.options ip.ex('import os') except Exception,msg: print "Message: ", msg ------------------------------------------- I get: ' Message: 'NoneType' object has no attribute 'options' ' If I remove the ip.options statement, it will say the same thing about attribute 'ex' Does anyone know if there are configuration options necessary? I read the docs, and it described a profile module, but I just need to run this, for this single purpose ( at least, now, later I can see its usefulness definitely,) Steve From lionel.keene at gmail.com Wed Feb 18 17:08:53 2009 From: lionel.keene at gmail.com (Lionel) Date: Wed, 18 Feb 2009 14:08:53 -0800 (PST) Subject: PyGTK install References: Message-ID: <5e6ed314-3625-4a1a-b357-b27aabeb2f52@q30g2000prq.googlegroups.com> On Feb 18, 11:43?am, Lionel wrote: > Hello folks, I couldn't find a specific PyGTK forum so I thought I'd > post here and hope someone new the answer. I feel it's a silly > problem, maybe something to do with a path variable? The problem: I've > downloaded the "all-in-one" windows binary installer for PyGTK from > their website. After typing in their first tutorial program and trying > to run from the command line, I get: > > "This application has failed to start because libglib-2.0-0.dll was > not found" error dialog. > > The traceback indicates this is happening at the "import gtk" line. A > quick search of my install directory for PyGTK indicates that the file > is indeed resident and located in C:\Program files\PyGTK\GTK\bin. > > Is there some some sort of path variable for Python I need to modify > and, if so, how is this done? Thanks so much, and my apologies if this > is the wrong forum. > > -L Well, I tried uninstalling / reinstalling PyGTK and now I'm getting a different traceback error: "ImportError: no module named pygtk" I checked and pygtk.py is located in "c:\Python25\Lib\site-packages". Then I displaye the sys.path: IDLE 1.2 >>> import sys >>> sys.path ['C:\\Program Files\\PyGTK\\Python\\Lib\\idlelib', 'C:\\Program Files\ \PyGTK\\Python\\python25.zip', 'C:\\Program Files\\PyGTK\\Python\ \DLLs', 'C:\\Program Files\\PyGTK\\Python\\lib', 'C:\\Program Files\ \PyGTK\\Python\\lib\\plat-win', 'C:\\Program Files\\PyGTK\\Python\\lib\ \lib-tk', 'C:\\Program Files\\PyGTK\\Python', 'C:\\Program Files\\PyGTK \\Python\\lib\\site-packages'] Every single entry is related to PyGTK and nothing else. Something seems wrong here but I don't have enough Python experience to know just what. Anyone? From rubik_wizard at NO.SPAMhotmail.com Wed Feb 18 17:16:41 2009 From: rubik_wizard at NO.SPAMhotmail.com (Neil) Date: Wed, 18 Feb 2009 22:16:41 -0000 Subject: Newbie Q about Turtle Gfx Message-ID: Hello Sorry if this is not an appropriate newsgroup for this problem. I am very new to Python but not new to programming. I am hoping to use Python to teach a class and have been looking at the online book 'Snake Wrangling for Kids'. I have followed the example >>>import turtle >>>t=turtle.pen() which works fine and displays a turtle in a window. However whenever I try to use something like >>>t.forward(50) (taken from the book) i get the error... Traceback (most recent call last): File "", line 1, in t.forward(50) AttributeError: 'dict' object has no attribute 'forward' I get the same error with t.left(10) etc. etc. I have tried this with V2.6 and V3 Any ideas would be much appreciated. Thanks Neil From rubik_wizard at NO.SPAMhotmail.com Wed Feb 18 17:18:04 2009 From: rubik_wizard at NO.SPAMhotmail.com (Neil) Date: Wed, 18 Feb 2009 22:18:04 -0000 Subject: Newbie Q about Turtle Gfx References: Message-ID: Forgot to say, that after the error message the turtle window 'hangs' as unresponsive ... "Neil" wrote in message news:ifidnR_GysdMFQHUnZ2dneKdnZzinZ2d at bt.com... > Hello > > Sorry if this is not an appropriate newsgroup for this problem. I am very > new to Python but not new to programming. > > I am hoping to use Python to teach a class and have been looking at the > online book 'Snake Wrangling for Kids'. > > I have followed the example > >>>>import turtle >>>>t=turtle.pen() > > which works fine and displays a turtle in a window. > > However whenever I try to use something like > >>>>t.forward(50) (taken from the book) > > i get the error... > > Traceback (most recent call last): > File "", line 1, in > t.forward(50) > AttributeError: 'dict' object has no attribute 'forward' > > I get the same error with t.left(10) etc. etc. > > I have tried this with V2.6 and V3 > > Any ideas would be much appreciated. > > Thanks > Neil > > > From shandy.b at gmail.com Wed Feb 18 17:20:57 2009 From: shandy.b at gmail.com (sjbrown) Date: Wed, 18 Feb 2009 14:20:57 -0800 (PST) Subject: Newbie Q about Turtle Gfx References: Message-ID: <9ba48cb7-d32b-40ef-a6a6-d2250886379a@l33g2000pri.googlegroups.com> It looks like there may be a bug if you were expecting t to be some object other than a dict. You can apparently contact the authour here: http://www.briggs.net.nz/log/contact/ On Feb 18, 2:16?pm, "Neil" wrote: > Hello > > Sorry if this is not an appropriate newsgroup for this problem. I am very > new to Python but not new to programming. > > I am hoping to use Python to teach a class and have been looking at the > online book 'Snake Wrangling for Kids'. > > I have followed the example > > >>>import turtle > >>>t=turtle.pen() > > which works fine and displays a turtle in a window. > > However whenever I try to use something like > > >>>t.forward(50) ? (taken from the book) > > i get the error... > > Traceback (most recent call last): > ? File "", line 1, in > ? ? t.forward(50) > AttributeError: 'dict' object has no attribute 'forward' > > I get the same error with t.left(10) etc. etc. > > I have tried this with V2.6 and V3 > > Any ideas would be much appreciated. > > Thanks > Neil From tim.wintle at teamrubber.com Wed Feb 18 17:21:50 2009 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Wed, 18 Feb 2009 22:21:50 +0000 Subject: Revision Control In-Reply-To: <822B0E83D23291469317E3432468743702224B@production.2000soft.com> References: <822B0E83D23291469317E3432468743702224B@production.2000soft.com> Message-ID: <1234995710.7867.61.camel@tim-laptop> On Wed, 2009-02-18 at 09:08 -0800, Sam Clark wrote: > Any suggestions for a beginer on what to use for version control? > It's just me, the lone person programming. I've already nailed one > "version" of my code accidentaly. MS VSS is too expensive for the > stuff I'm doing, plus I really don't like MS much... Any free open > source stuff out there? I use svn (subversion) at work and it works fine, but I'm using bazaar on my own code, and even alongside svn to help with merging branches, porting code up-stream etc. bazaar is really great in my experience, although relatively new so you might prefer to stick to svn. I haven't tried using bazaar on windows. If you do go with svn, try the latest version, since merging support is much better in this. Tim From gtill60 at gmail.com Wed Feb 18 17:22:59 2009 From: gtill60 at gmail.com (gtillmon) Date: Wed, 18 Feb 2009 14:22:59 -0800 (PST) Subject: Directory References: <6d92ee1b-75ba-4ba8-8dc3-625966b17835@d32g2000yqe.googlegroups.com> Message-ID: <7d253b32-0a76-4a74-b524-6807322756e7@j35g2000yqh.googlegroups.com> On Feb 18, 3:39?pm, "Gabriel Genellina" wrote: > En Wed, 18 Feb 2009 12:15:25 -0200, Steve Holden ? > escribi?: > > > gtillmon wrote: > >> I would like to know how to display and store the path of each mondule > >> that is called. > > It's certainly possible to trace function calls, if that would help. > > sys.settrace allows you to establish a function that gets called > > If the OP is only interested in import statements, perhaps the -v flag is ? > enough: > > python -v script_name.py > > It prints a line (on stderr) for each module imported, stating its name ? > and source file. > > -- > Gabriel Genellina Thanks for the information. From gtill60 at gmail.com Wed Feb 18 17:23:15 2009 From: gtill60 at gmail.com (gtillmon) Date: Wed, 18 Feb 2009 14:23:15 -0800 (PST) Subject: Directory References: <6d92ee1b-75ba-4ba8-8dc3-625966b17835@d32g2000yqe.googlegroups.com> Message-ID: On Feb 18, 8:15?am, Steve Holden wrote: > gtillmon wrote: > > Hello. ?I am new to the Python language. > > I would like to know how to display and store the path of each mondule > > that is called. > > Modules are imported, not called. > > > Similar to the old READY TRACE in COBOL of long ago. > > It's certainly possible to trace function calls, if that would help. > sys.settrace allows you to establish a function that gets called > whenever a Python function call is executed. The documentation is a > little sparse, but you can find a rough example under "Crude Python > Debugging" in > > ?http://www.st.ewi.tudelft.nl/~mol/snippets.php > > regards > ?Steve > -- > Steve Holden ? ? ? ?+1 571 484 6266 ? +1 800 494 3119 > Holden Web LLC ? ? ? ? ? ? ?http://www.holdenweb.com/ Thanks for the information. From steve at holdenweb.com Wed Feb 18 17:24:20 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 18 Feb 2009 17:24:20 -0500 Subject: Delete lines which contain string in a file In-Reply-To: <7cbf2f3a0902181342w20d3bcbfnf640a177b221c8a6@mail.gmail.com> References: <7cbf2f3a0902181342w20d3bcbfnf640a177b221c8a6@mail.gmail.com> Message-ID: Rudi Goldman wrote: > Hi, > Go easy on me as I am a new to Python and am trying to solve a practical > problem that is driving me bananas. > Basically I have 2 text files, a source and a target. I want to be able > to delete all of the lines in the target file which contain text from > any line in the source file. > i.e. > Source: Target: > 111 xxx 111 yyy > 222 xxx 333 sss > 333 jjj 444 sss > > After executing this code the target file should only consist of the > line: jjj 444 sss > Any help on this one would be greatly appreciated. > Is this homework? How far have you got with your design? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From rubik_wizard at NO.SPAMhotmail.com Wed Feb 18 17:28:36 2009 From: rubik_wizard at NO.SPAMhotmail.com (Neil) Date: Wed, 18 Feb 2009 22:28:36 -0000 Subject: Newbie Q about Turtle Gfx References: <9ba48cb7-d32b-40ef-a6a6-d2250886379a@l33g2000pri.googlegroups.com> Message-ID: Thanks for the very speedy reply! Not sure what your reply means but I have emailed the author with the problem! Cheers Neil "sjbrown" wrote in message news:9ba48cb7-d32b-40ef-a6a6-d2250886379a at l33g2000pri.googlegroups.com... It looks like there may be a bug if you were expecting t to be some object other than a dict. You can apparently contact the authour here: http://www.briggs.net.nz/log/contact/ On Feb 18, 2:16 pm, "Neil" wrote: > Hello > > Sorry if this is not an appropriate newsgroup for this problem. I am very > new to Python but not new to programming. > > I am hoping to use Python to teach a class and have been looking at the > online book 'Snake Wrangling for Kids'. > > I have followed the example > > >>>import turtle > >>>t=turtle.pen() > > which works fine and displays a turtle in a window. > > However whenever I try to use something like > > >>>t.forward(50) (taken from the book) > > i get the error... > > Traceback (most recent call last): > File "", line 1, in > t.forward(50) > AttributeError: 'dict' object has no attribute 'forward' > > I get the same error with t.left(10) etc. etc. > > I have tried this with V2.6 and V3 > > Any ideas would be much appreciated. > > Thanks > Neil From http Wed Feb 18 17:29:06 2009 From: http (Paul Rubin) Date: 18 Feb 2009 14:29:06 -0800 Subject: number theory libraries / project euler References: Message-ID: <7xljs3751p.fsf@ruckus.brouhaha.com> eliben writes: > What are some good & recommended number theory libs for Python (or > accessible interfaces to C libs), for things like primes, > factorization, etc. Naturally, speed is of utmost importance here. The idea of Project Euler is you are supposed to find clever enough methods to solve the problems that speed of the software libs is NOT important. From catphive at catphive.net Wed Feb 18 17:31:16 2009 From: catphive at catphive.net (Brendan Miller) Date: Wed, 18 Feb 2009 14:31:16 -0800 Subject: PyYaml in standard library? In-Reply-To: <50697b2c0902180134gcb053w96002899356d3ad1@mail.gmail.com> References: <50697b2c0902180134gcb053w96002899356d3ad1@mail.gmail.com> Message-ID: On Wed, Feb 18, 2009 at 1:34 AM, Chris Rebert wrote: > On Wed, Feb 18, 2009 at 1:11 AM, Brendan Miller wrote: >> I'm just curious whether PyYaml is likely to end up in the standard >> library at some point? > > I don't personally have a direct answer to your question, but I can > point out that JSON and YAML are mostly compatible (JSON is almost a > perfect YAML subset) and the `json` module is already in the Python > std lib. > > Cheers, > Chris Yes, JSON is an (I think unintentional) subset of YAML... but a fairly small subset. A list in YAML looks like --- # my list - Elem 1 - Elem 2 Whereas in JSON you have ["Elem 1", "Elem 2"]. People say JSON is a subset because YAML will also accept the JSON style syntax if you want to do something inline for convenience: --- # my list containing a sublist in the second element. - Elem 1 - ["Sub elem 1", "Sub elem 2"] But this is really a special purpose syntax in the context of YAML. I think the json module sticks everything on the same line, which isn't readable for large data structures. My impression is YAML is that is is more readable than JSON, whereas JSON is mostly for browser interop. From mensanator at aol.com Wed Feb 18 17:36:21 2009 From: mensanator at aol.com (Mensanator) Date: Wed, 18 Feb 2009 14:36:21 -0800 (PST) Subject: number theory libraries / project euler References: Message-ID: On Feb 18, 2:18?pm, eliben wrote: > Hello, > > What are some good & recommended number theory libs for Python (or > accessible interfaces to C libs), for things like primes, > factorization, etc. Naturally, speed is of utmost importance here. > > In other words, which Python libraries and tools to you use to help > you solve Project Euler problems :-) ? > > Eli Also check out the gmpy library, lots of good number theory stuff like factorial, gcd, lcm, linear congruence, is_prime, next_prime, (I even found a use for the legendre function), etc. (no factorization, I have Python call the MIRACL factor program when I need that) gmpy is so vital to my work that if they ever stop supporting it, I will abandon Python. From jeff.dyke at gmail.com Wed Feb 18 17:44:03 2009 From: jeff.dyke at gmail.com (Jeff Dyke) Date: Wed, 18 Feb 2009 17:44:03 -0500 Subject: SVN/CVS and Branching Message-ID: <8496caf30902181444s5deb203ye0ff5654743999f5@mail.gmail.com> Hello. I am curious about different ideas on how you handle branching your python projects. With some other languages this is trivial, but since python uses these directories as modules and i have the top level module starting imports all over the place, i am wondering what others do. In the past we had retired the first branch and just moved towards the new, but that is not possible now. Thanks, jd From aisaac at american.edu Wed Feb 18 17:48:17 2009 From: aisaac at american.edu (Alan G Isaac) Date: Wed, 18 Feb 2009 17:48:17 -0500 Subject: get descriptor from instance Message-ID: <5didnW_7dfWlDQHUnZ2dnUVZ_q_inZ2d@rcn.net> What is a reliable way to get the the property object for an instance attribute? (Or more generally, to get the descriptor controlling an attribute?) If class ``A`` defines the property ``x`` and ``a`` in an instance of ``A``, then you can just use ``type(a).__dict__['x']`` to get the property object. But this will not work if the property is inherited. Thanks, Alan Isaac From Scott.Daniels at Acm.Org Wed Feb 18 17:57:32 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 18 Feb 2009 14:57:32 -0800 Subject: Newbie Q about Turtle Gfx In-Reply-To: References: Message-ID: Neil wrote: > Forgot to say, that after the error message the turtle window 'hangs' as > unresponsive ... > > "Neil" wrote in message > news:ifidnR_GysdMFQHUnZ2dneKdnZzinZ2d at bt.com... >> Hello >> I am hoping to use Python to teach a class and have been looking at the >> online book 'Snake Wrangling for Kids'. >> >> I have followed the example >>>>> import turtle >>>>> t=turtle.pen() >> which works fine and displays a turtle in a window. >> >> However whenever I try to use something like >>>>> t.forward(50) (taken from the book) >> i get the error... >> >> Traceback (most recent call last): >> File "", line 1, in >> t.forward(50) >> AttributeError: 'dict' object has no attribute 'forward' Well, if you >>> print(turtle.__doc__) You'll see that this is a re-implemetation, so expect a few hiccups. I see, from the following: >>> import turtle >>> t = turtle.pen() >>> print(repr(t)) The pen returned (which you named t) is a simple dictionary. You can, however, follow up with: >>> turtle.forward(23) >>> turtle.right(90) >>> turtle.forward(32) >>> turtle.right(90) >>> turtle.forward(23) >>> turtle.right(90) >>> turtle.forward(32) Or, if you prefer, you can go: >>> t = turtle.Turtle() >>> t.forward(30) >>> t.left(120) --Scott David Daniels Scott.Daniels at Acm.Org From lionel.keene at gmail.com Wed Feb 18 18:03:56 2009 From: lionel.keene at gmail.com (Lionel) Date: Wed, 18 Feb 2009 15:03:56 -0800 (PST) Subject: PyGTK install References: <5e6ed314-3625-4a1a-b357-b27aabeb2f52@q30g2000prq.googlegroups.com> Message-ID: <8ff4616a-ef10-4b57-937b-71402d97942d@z28g2000prd.googlegroups.com> On Feb 18, 2:08?pm, Lionel wrote: > On Feb 18, 11:43?am, Lionel wrote: > > > > > > > Hello folks, I couldn't find a specific PyGTK forum so I thought I'd > > post here and hope someone new the answer. I feel it's a silly > > problem, maybe something to do with a path variable? The problem: I've > > downloaded the "all-in-one" windows binary installer for PyGTK from > > their website. After typing in their first tutorial program and trying > > to run from the command line, I get: > > > "This application has failed to start because libglib-2.0-0.dll was > > not found" error dialog. > > > The traceback indicates this is happening at the "import gtk" line. A > > quick search of my install directory for PyGTK indicates that the file > > is indeed resident and located in C:\Program files\PyGTK\GTK\bin. > > > Is there some some sort of path variable for Python I need to modify > > and, if so, how is this done? Thanks so much, and my apologies if this > > is the wrong forum. > > > -L > > Well, I tried uninstalling / reinstalling PyGTK and now I'm getting a > different traceback error: > > "ImportError: no module named pygtk" > > I checked and pygtk.py is located in "c:\Python25\Lib\site-packages". > Then I displaye the sys.path: > > IDLE 1.2>>> import sys > >>> sys.path > > ['C:\\Program Files\\PyGTK\\Python\\Lib\\idlelib', 'C:\\Program Files\ > \PyGTK\\Python\\python25.zip', 'C:\\Program Files\\PyGTK\\Python\ > \DLLs', 'C:\\Program Files\\PyGTK\\Python\\lib', 'C:\\Program Files\ > \PyGTK\\Python\\lib\\plat-win', 'C:\\Program Files\\PyGTK\\Python\\lib\ > \lib-tk', 'C:\\Program Files\\PyGTK\\Python', 'C:\\Program Files\\PyGTK > \\Python\\lib\\site-packages'] > > Every single entry is related to PyGTK and nothing else. Something > seems wrong here but I don't have enough Python experience to know > just what. Anyone?- Hide quoted text - > > - Show quoted text - Okay, out of desperation and frustration I've wiped my Python/SciPy/ etc.. setup and reinstalled from scratch. I've tested it with my app and all the numpy and matplotlib functionality is there and working. My sys.path seems to be back to normal: IDLE 1.2.4 >>> import sys >>> sys.path ['C:\\Python25\\Lib\\idlelib', 'C:\\WINDOWS\\system32\\python25.zip', 'C:\\Python25\\DLLs', 'C:\\Python25\\lib', 'C:\\Python25\\lib\\plat- win', 'C:\\Python25\\lib\\lib-tk', 'C:\\Python25', 'C:\\Python25\\lib\ \site-packages'] I will now re-install PyGTK and see if it mysteriously decides to work this time. From superprad at gmail.com Wed Feb 18 18:08:55 2009 From: superprad at gmail.com (PK) Date: Wed, 18 Feb 2009 18:08:55 -0500 Subject: fcntl.fcntl breaking on 64bit Message-ID: <5b0681910902181508s7ce57487idd0bc21a350f7f56@mail.gmail.com> Hello Friends: I'm running into issues with using fcntl on a 64 bit servers. Python version: 2.4.3 system Arch: # uname -m x86_64 code keeps erroring out with: fcntl.fcntl(fd, rhn_fcntl.F_SETLKW, UNLOCK) IOError: [Errno 22] Invalid argument The same python code block runs fine on a i386/686. Does anyone have any thoughts? Is this a known issue? any workarounds? Any suggestions appreciated. Thanks, ~ PK -------------- next part -------------- An HTML attachment was scrubbed... URL: From lionel.keene at gmail.com Wed Feb 18 18:12:32 2009 From: lionel.keene at gmail.com (Lionel) Date: Wed, 18 Feb 2009 15:12:32 -0800 (PST) Subject: PyGTK install References: <5e6ed314-3625-4a1a-b357-b27aabeb2f52@q30g2000prq.googlegroups.com> <8ff4616a-ef10-4b57-937b-71402d97942d@z28g2000prd.googlegroups.com> Message-ID: <1198ef28-b2c0-4464-85ad-31798dc0c33f@r15g2000prh.googlegroups.com> On Feb 18, 3:03?pm, Lionel wrote: > On Feb 18, 2:08?pm, Lionel wrote: > > > > > > > On Feb 18, 11:43?am, Lionel wrote: > > > > Hello folks, I couldn't find a specific PyGTK forum so I thought I'd > > > post here and hope someone new the answer. I feel it's a silly > > > problem, maybe something to do with a path variable? The problem: I've > > > downloaded the "all-in-one" windows binary installer for PyGTK from > > > their website. After typing in their first tutorial program and trying > > > to run from the command line, I get: > > > > "This application has failed to start because libglib-2.0-0.dll was > > > not found" error dialog. > > > > The traceback indicates this is happening at the "import gtk" line. A > > > quick search of my install directory for PyGTK indicates that the file > > > is indeed resident and located in C:\Program files\PyGTK\GTK\bin. > > > > Is there some some sort of path variable for Python I need to modify > > > and, if so, how is this done? Thanks so much, and my apologies if this > > > is the wrong forum. > > > > -L > > > Well, I tried uninstalling / reinstalling PyGTK and now I'm getting a > > different traceback error: > > > "ImportError: no module named pygtk" > > > I checked and pygtk.py is located in "c:\Python25\Lib\site-packages". > > Then I displaye the sys.path: > > > IDLE 1.2>>> import sys > > >>> sys.path > > > ['C:\\Program Files\\PyGTK\\Python\\Lib\\idlelib', 'C:\\Program Files\ > > \PyGTK\\Python\\python25.zip', 'C:\\Program Files\\PyGTK\\Python\ > > \DLLs', 'C:\\Program Files\\PyGTK\\Python\\lib', 'C:\\Program Files\ > > \PyGTK\\Python\\lib\\plat-win', 'C:\\Program Files\\PyGTK\\Python\\lib\ > > \lib-tk', 'C:\\Program Files\\PyGTK\\Python', 'C:\\Program Files\\PyGTK > > \\Python\\lib\\site-packages'] > > > Every single entry is related to PyGTK and nothing else. Something > > seems wrong here but I don't have enough Python experience to know > > just what. Anyone?- Hide quoted text - > > > - Show quoted text - > > Okay, out of desperation and frustration I've wiped my Python/SciPy/ > etc.. setup and reinstalled from scratch. I've tested it with my app > and all the numpy and matplotlib functionality is there and working. > My sys.path seems to be back to normal: > > IDLE 1.2.4>>> import sys > >>> sys.path > > ['C:\\Python25\\Lib\\idlelib', 'C:\\WINDOWS\\system32\\python25.zip', > 'C:\\Python25\\DLLs', 'C:\\Python25\\lib', 'C:\\Python25\\lib\\plat- > win', 'C:\\Python25\\lib\\lib-tk', 'C:\\Python25', 'C:\\Python25\\lib\ > \site-packages'] > > I will now re-install PyGTK and see if it mysteriously decides to work > this time.- Hide quoted text - > > - Show quoted text - Nope. Now I'm getting: "The applciation has failed to start because MSVCR80.dll was not found." Don't know what else to try here. Anyone have any ideas? From robert.kern at gmail.com Wed Feb 18 18:12:41 2009 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 18 Feb 2009 17:12:41 -0600 Subject: Can't get the IPYthon ipapi object working In-Reply-To: <64e1c5b4-efda-4a52-9b99-05762cb2bef5@t39g2000prh.googlegroups.com> References: <64e1c5b4-efda-4a52-9b99-05762cb2bef5@t39g2000prh.googlegroups.com> Message-ID: On 2009-02-18 15:49, beetlecube wrote: > Hi , I found out from a random google search that I could use IPython > to automatically import modules so that I could test Django views. > > I downloaded it (WIN XP), installed it. I'm able to import it, but I > just can't seem to get the object working. > > The code: > ----------------------------------- > try: > import IPython.ipapi > ip = IPython.ipapi.get() > a = ip.options > ip.ex('import os') > > except Exception,msg: > print "Message: ", msg > ------------------------------------------- > > I get: ' Message: 'NoneType' object has no attribute 'options' ' > > If I remove the ip.options statement, it will say the same thing about > attribute 'ex' This needs to be run in the context of a running instance IPython, not just any other module. That kind of code is usually put into your c:\Documents and Settings\username\_ipython\ipy_user_conf.py file. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From gagsl-py2 at yahoo.com.ar Wed Feb 18 18:15:10 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 18 Feb 2009 21:15:10 -0200 Subject: get descriptor from instance References: <5didnW_7dfWlDQHUnZ2dnUVZ_q_inZ2d@rcn.net> Message-ID: En Wed, 18 Feb 2009 20:48:17 -0200, Alan G Isaac escribi?: > What is a reliable way to get the > the property object for an instance attribute? > (Or more generally, to get the descriptor > controlling an attribute?) > > If class ``A`` defines the property ``x`` and ``a`` > in an instance of ``A``, then you can just use > ``type(a).__dict__['x']`` to get the property object. > But this will not work if the property is inherited. type(a).x py> class A(object): ... def getx(self): return 1 ... x = property(getx) ... py> class B(A): ... pass ... py> b=B() py> b.x 1 py> B.x py> type(b).x py> getattr(type(b),'x') py> -- Gabriel Genellina From mensanator at aol.com Wed Feb 18 18:43:29 2009 From: mensanator at aol.com (Mensanator) Date: Wed, 18 Feb 2009 15:43:29 -0800 (PST) Subject: Newbie Q about Turtle Gfx References: Message-ID: On Feb 18, 4:16?pm, "Neil" wrote: > Hello > > Sorry if this is not an appropriate newsgroup for this problem. I am very > new to Python but not new to programming. > > I am hoping to use Python to teach a class and have been looking at the > online book 'Snake Wrangling for Kids'. > > I have followed the example > > >>>import turtle > >>>t=turtle.pen() You defined "t" to be a pen object, not a turtle object. > > which works fine and displays a turtle in a window. > > However whenever I try to use something like > > >>>t.forward(50) ? (taken from the book) Pens don't move, turtles move (and the pen the turtle is carrying draws a line, if down). > > i get the error... > > Traceback (most recent call last): > ? File "", line 1, in > ? ? t.forward(50) > AttributeError: 'dict' object has no attribute 'forward' > > I get the same error with t.left(10) etc. etc. Pens can't turn left, turtles turn left. > > I have tried this with V2.6 and V3 > > Any ideas would be much appreciated. > > Thanks > Neil Here's an example. It draws a Minimal Spanning Tree. If you don't need an MST, take note of how I use the turtle. import turtle import random import copy def build_sv(start,stop,limit,C): """Sequence Vector Generator build_sv(start,stop,limit,C) start: start of Collatz sequence (must be odd) stop: sequence termination limit: max length of [sv] if stop not found limit is sum(sv), not len(sv) C: C of 3n+C returns [] if invalid returns SequenceVector [sv] """ ONE = 1 TWO = 2 TWE = 3 sv = [] if (start % 2)==0: return sv done = 0 count = 0 while done==0: # # oops, power division may skip past stopping point # without seeing it # start = TWE*start + C f = 0 t = start while t%2==0: f += 1 t /= 2 g = 0 # stopping point may occur before f is reached while (not done) and g> 1 if start==stop: done = 1 count += 1 g += 1 if count==limit: done = 1 sv.append(g) return sv def Type12MH(k,i): """Find ith, kth Generation Type [1,2] Mersenne Hailstone using the closed form equation Type12MH(k,i) k: generation i: member of generation returns Hailstone (a) """ ONE = 1 TWO = 2 SIX = 6 NIN = 9 if (k<1) or (i<1): return 0 a = (i-ONE)*NIN**(k-ONE) + (NIN**(k-ONE) - ONE)/TWO + ONE return TWO**(SIX*a - ONE) - ONE turtle.clear() turtle.up() the_window = (turtle.window_width(),turtle.window_height()) print the_window, turtle.goto(0,0) tooter = turtle.position() buffer_L = -((the_window[0]-200)/2) buffer_R = (the_window[0]-200)/2 buffer_T = (the_window[1]-200)/2 buffer_B = -((the_window[1]-200)/2) print buffer_L,buffer_R,buffer_T,buffer_B turtle.tracer(False) turtle.down() turtle.speed('fastest') t = 0 turtle.setheading(t) for j in range(1): p = Type12MH(4,2) # Type12 Mersenne Hailstone (very big) sv = build_sv(p,1,10000000,1) # limit to 10 million numbers in vector # Minimal Spanning Tree stars = [] turtle.up() for d in sv: # random turtle crawl based on sv if d>1: # skip small sv values for movement for r in xrange(1): turtle.setheading(t+r*90) turtle.forward(d*4) # scale of grid tooter = turtle.position() if d>8: # create a star at really large sv values turtle.down() turtle.width(3) turtle.color('black') turtle.forward(1) # draw a blob turtle.backward(1) stars.append((int(tooter[0]),int(tooter[1]))) turtle.up() turtle.width(1) turtle.color('red') # color of MST spans whither_tooter = [] # build list of legal next turns if tooter[0]>buffer_L: # test for being too close to screen edge whither_tooter.append(180) if tooter[0]buffer_B: whither_tooter.append(270) t = random.choice(whither_tooter) # choose random direction from list of legal moves print 'stars:',len(stars) star_dist = [] # create list of spans between stars for i,src in enumerate(stars): for j,dst in enumerate(stars): dist = turtle.sqrt((src[0]-dst[0])**2 + (src[1]-dst[1])**2) if dist == 0: star_dist.append([9999,i,j]) else: star_dist.append([dist,i,j]) star_dist.sort() MST = [] # spans of MST MST2 = [] # only those spans that can connect to existing MST points_used = {} # list of stars that are currently on MST s = copy.deepcopy(star_dist[0]) # going to modify list element, so deep copy needed MST.append(s) # fist span always smallest absolute distance points_used[s[1]] = 1 points_used[s[2]] = 1 star_dist[0][0] = 9999 # overwrite distance so this span can't be used again found = False # also, overwrite complement span si = 0 while not found: ss = star_dist[si] if s[1]==ss[2] and s[2]==ss[1]: # the complement star_dist[si][0] = 9999 found = True else: si += 1 while len(MST)<(len(stars)-1): # an MST of n points always has n-1 spans for i,sd in enumerate(star_dist): # copy points matching s to MST2 # only spans that could connect to existing # tree points can be added at this stage # (only have to check for last added to MST) if (sd[0]!=9999) and \ ((sd[1]==s[1]) or \ (sd[1]==s[2]) or \ (sd[2]==s[1]) or \ (sd[2]==s[2])): MST2.append(copy.deepcopy(sd)) star_dist[i][0] = 9999 # once copied to MST2, overwrite original distance MST2.sort() close = 0 # # can't use a span if BOTH points already on MST, otherwise we get loops # and some stars remain disjoint # while ((MST2[close][1] in points_used) and (MST2[close][2] in points_used)): close += 1 s = copy.deepcopy(MST2[close]) MST.append(s) if s[1] in points_used: # only keys used to create tree, values points_used[s[1]] += 1 # will eventully be number of points else: # connected to this point points_used[s[1]] = 1 if s[2] in points_used: points_used[s[2]] += 1 else: points_used[s[2]] = 1 MST2[close][0] = 9999 # overwrite this point and its complement found = False si = 0 while not found: ss = MST2[si] if s[1]==ss[2] and s[2]==ss[1]: # the duplicate MST2[si][0] = 9999 found = True else: si += 1 if si == len(MST2): found = True for span in MST: # from an MST span srcx = stars[span[1]][0] # get coords of two endpoints srcy = stars[span[1]][1] dstx = stars[span[2]][0] dsty = stars[span[2]][1] turtle.up() # and draw a line between them turtle.goto(srcx,srcy) turtle.down() turtle.goto(dstx,dsty) From sturlamolden at yahoo.no Wed Feb 18 19:23:32 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 18 Feb 2009 16:23:32 -0800 (PST) Subject: numpy.memmap advice? References: Message-ID: <77c68ff8-d29d-4ada-9829-8f8f61c3ee4c@o36g2000yqh.googlegroups.com> On 18 Feb, 00:08, Lionel wrote: > 1) What is "recarray"? An ndarray of what C programmers know as a "struct", in which each field is accessible by its name. That is, struct rgba{ unsigned char r; unsigned char g; unsigned char b; unsigned char a; }; struct rgba arr[480][640]; is similar to: import numpy as np rbga = np.dtype({'names':list('rgba'), 'formats':[np.uint8]*4}) arr = np.array((480,640), dtype=rgba) Now you can access the r, g, b and a fields directly using arr['r'], arr['g'], arr['b'], and arr['a']. Internally the data will be represented compactly as with the C code above. If you want to view the data as an 480 x 640 array of 32 bit integers instead, it is as simple as arr.view(dtype=np.uint32). Formatted binary data can of course be read from files using np.fromfile with the specified dtype, and written to files by passing a recarray as buffer to file.write. You can thus see NumPy's recarray's as a more powerful alternative to Python's struct module. > I don't really see in the diocumentation how portions are loaded, however. Prior to Python 2.6, the mmap object (which numpy.memmap uses internally) does not take an offset parameter. But when NumPy are ported to newer version of Python this will be fixed. You should then be able to memory map with an ndarray from a certain offset. To make this work now, you must e.g. backport mmap from Python 2.6 and use that with NumPy. Not difficult, but nobody has bothered to do it (as far as I know). Sturla Molden From rubik_wizard at NO.SPAMhotmail.com Wed Feb 18 19:26:48 2009 From: rubik_wizard at NO.SPAMhotmail.com (Neil) Date: Thu, 19 Feb 2009 00:26:48 -0000 Subject: Newbie Q about Turtle Gfx References: Message-ID: Thanks everyone! It appears the info in the book is wrong. Trying what you have all suggested has got it to work! Many thanks, and I am sure I will be back here again with other newbie problems! Neil "Neil" wrote in message news:ifidnR_GysdMFQHUnZ2dneKdnZzinZ2d at bt.com... > Hello > > Sorry if this is not an appropriate newsgroup for this problem. I am very > new to Python but not new to programming. > > I am hoping to use Python to teach a class and have been looking at the > online book 'Snake Wrangling for Kids'. > > I have followed the example > >>>>import turtle >>>>t=turtle.pen() > > which works fine and displays a turtle in a window. > > However whenever I try to use something like > >>>>t.forward(50) (taken from the book) > > i get the error... > > Traceback (most recent call last): > File "", line 1, in > t.forward(50) > AttributeError: 'dict' object has no attribute 'forward' > > I get the same error with t.left(10) etc. etc. > > I have tried this with V2.6 and V3 > > Any ideas would be much appreciated. > > Thanks > Neil > > > From SiteContactUs at gmail.com Wed Feb 18 19:29:09 2009 From: SiteContactUs at gmail.com (beetlecube) Date: Wed, 18 Feb 2009 16:29:09 -0800 (PST) Subject: Can't get the IPYthon ipapi object working References: <64e1c5b4-efda-4a52-9b99-05762cb2bef5@t39g2000prh.googlegroups.com> Message-ID: <57ecb5ae-3348-40bd-8b32-51c33e706635@x29g2000prf.googlegroups.com> On Feb 18, 3:12?pm, Robert Kern wrote: > On 2009-02-18 15:49, beetlecube wrote: > > > > > Hi , I found out from a random google search that I could use IPython > > to automatically import modules so that I could test Django views. > > > I downloaded it (WIN XP), installed it. ?I'm able to import it, but I > > just can't seem to get the object working. > > > The code: > > ----------------------------------- > > try: > > ? ? ?import IPython.ipapi > > ? ? ?ip = IPython.ipapi.get() > > ? ? ?a = ip.options > > ? ? ?ip.ex('import os') > > > except Exception,msg: > > ? ? ?print "Message: ", msg > > ------------------------------------------- > > > I get: ' Message: ?'NoneType' object has no attribute 'options' ' > Shoulda know I was doing something fundamentally wrong. Thanks a lot! > > If I remove the ip.options statement, it will say the same thing about > > attribute 'ex' > > This needs to be run in the context of a running instance IPython, not just any > other module. That kind of code is usually put into your c:\Documents and > Settings\username\_ipython\ipy_user_conf.py file. > > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless enigma > ? that is made terrible by our own mad attempt to interpret it as though it had > ? an underlying truth." > ? ?-- Umberto Eco From bhood37 at hotmail.com Wed Feb 18 19:33:14 2009 From: bhood37 at hotmail.com (Uberman) Date: Wed, 18 Feb 2009 17:33:14 -0700 Subject: Calling a class instance like a function Message-ID: I'm wondering if there's a way to invoke a "function" operator on a Python class instance. For example, given a class instance: myClass = MyClass() I want to call that instance like a function, with an argument value: myClass(5.0) I can override the "()" operator in C++, so I'm wondering if there's a way to do it in Python as well. Thanks! From gert.cuykens at gmail.com Wed Feb 18 19:33:31 2009 From: gert.cuykens at gmail.com (gert) Date: Wed, 18 Feb 2009 16:33:31 -0800 (PST) Subject: Threading and tkinter References: <492d5db9-3681-4ae8-827e-f2a4f66bee80@v39g2000yqm.googlegroups.com> Message-ID: <90d5e669-e8d1-441e-adff-ddc501d21d26@u13g2000yqg.googlegroups.com> On Feb 18, 8:25?am, "Hendrik van Rooyen" wrote: > "gert" wrote: > > > After reading the docs and seeing a few examples i think this should > > work ? > > Am I forgetting something here or am I doing something stupid ? > > Anyway I see my yellow screen, that has to count for something :) > > > from tkinter import * > > from threading import Thread > > > class Weegbrug(Thread): > > ? ? def __init__(self,v): > > ? ? ? ? self.v=v > > ? ? ? ? Thread.__init__(self) > > ? ? def run(self): > > ? ? ? ? while True: > > ? ? ? ? ? ? with open('com1','r') as f: > > ? ? ? ? ? ? ? ? ?for line in f: > > ? ? ? ? ? ? ? ? ? ? ?self.v.set(line[2:-1]) > > It is in general not a good idea to directly > access GUI variables from outside the > GUI main loop. > There is a recipe for doing this sort of thing, > but as usual I have lost the reference. > What it does is that instead of interfering directly > as above, you put the data on a queue. > > Then, you use the after() call to set up a call > to a routine that reads the queue, and configures the > display, and then uses after again to call itself again > after a time, thereby keeping the GUI stuff in the GUI > mainloop. > from tkinter import * from threading import Thread class Weegbrug(Thread): def __init__(self): self.display='00000' Thread.__init__(self) def run(self): x=0 while True: x=x+1 self.display=x #with open('com1','r') as f: # for l in f: # self.display=l[2:-1] root = Tk() v = StringVar() v.set('00000') w = Weegbrug() w.start() tx = Label(root, textvariable=v, width=800, height=600, bg='yellow', font=('Helvetica', 300)) tx.pack(expand=YES, fill=BOTH) root.title('Weegbrug') root.overrideredirect(1) root.geometry('%dx%d+0+0' % (root.winfo_screenwidth(), root.winfo_screenheight())) root.after(500, v.set(w.display)) root.mainloop() Why does this not work ? It only shows one result ? From pofuk at email.t-com.hr Wed Feb 18 19:38:45 2009 From: pofuk at email.t-com.hr (SMALLp) Date: Thu, 19 Feb 2009 01:38:45 +0100 Subject: os.popen encoding! References: <87ocwzzvym.fsf@mulj.homelinux.net> Message-ID: Thanks for help! My problem was actualy: >>> a = ["velja\xe8a 2009"] >>> print a #will print ["velja\xe8a 2009"] >>> Print a[0] #will print velja?a 2009 "Hrvoje Niksic" wrote in message news:87ocwzzvym.fsf at mulj.homelinux.net... > "Gabriel Genellina" writes: > >>> I'm playing with os.popen function. >>> a = os.popen("somecmd").read() >>> >>> If one of the lines contains characters like "e", "a"or any other it >>> loks >>> line this "velja\xe8a 2009" with that "\xe8". It prints fine if i go: >>> >>> for i in a: >>> print i: >> >> '\xe8' is a *single* byte (not four). It is the 'LATIN SMALL LETTER E >> WITH GRAVE' Unicode code point u'e' encoded in the Windows-1252 >> encoding (and latin-1, and others too). > > Note that it is also 'LATIN SMALL LETTER C WITH CARON' (U+010D or > u'?'), encoded in Windows-1250, which is what the OP is likely using. > > The rest of your message stands regardless: there is no problem, at > least as long as the OP only prints out the character received from > somecmd to something else that also expects Windows-1250. The problem > would arise if the OP wanted to store the string in a PyGTK label > (which expects UTF8) or send it to a web browser (which expects > explicit encoding, probably defaulting to UTF8), in which case he'd > have to disambiguate whether '\xe8' refers to U+010D or to U+00E8 or > something else entirely. > > That is the problem that Python 3 solves by requiring (or strongly > suggesting) that such disambiguation be performed as early in the > program as possible, preferrably while the characters are being read > from the outside source. A similar approach is possible using Python > 2 and its unicode type, but since the OP never specified exactly which > problem he had (except for the repr/str confusion), it's hard to tell > if using the unicode type would help. From andrew at acooke.org Wed Feb 18 19:40:33 2009 From: andrew at acooke.org (andrew cooke) Date: Wed, 18 Feb 2009 21:40:33 -0300 (CLST) Subject: SVN/CVS and Branching In-Reply-To: <8496caf30902181444s5deb203ye0ff5654743999f5@mail.gmail.com> References: <8496caf30902181444s5deb203ye0ff5654743999f5@mail.gmail.com> Message-ID: maybe this is just me, but i don't have a clue what your problem is. what does "starting imports all over the place" mean? what do you mean by "retired"? i use svn with python in exactly the same way as with java (and, i thought, in the same way as anyone uses svn with any language; java uses the directory structure as a package structure too). maybe someone else will reply, but if not it might help to explain a little more detail. andrew Jeff Dyke wrote: > Hello. I am curious about different ideas on how you handle branching > your python projects. With some other languages this is trivial, but > since python uses these directories as modules and i have the top > level module starting imports all over the place, i am wondering what > others do. In the past we had retired the first branch and just moved > towards the new, but that is not possible now. From gruszczy at gmail.com Wed Feb 18 19:42:57 2009 From: gruszczy at gmail.com (=?UTF-8?Q?Filip_Gruszczy=C5=84ski?=) Date: Thu, 19 Feb 2009 01:42:57 +0100 Subject: Calling a class instance like a function In-Reply-To: References: Message-ID: <1be78d220902181642q4cbb1682rf27948eccf311271@mail.gmail.com> __call__ 2009/2/19 Uberman : > I'm wondering if there's a way to invoke a "function" operator on a Python > class instance. For example, given a class instance: > > myClass = MyClass() > > I want to call that instance like a function, with an argument value: > > myClass(5.0) > > I can override the "()" operator in C++, so I'm wondering if there's a way to > do it in Python as well. > > Thanks! > -- > http://mail.python.org/mailman/listinfo/python-list > -- Filip Gruszczy?ski From sturlamolden at yahoo.no Wed Feb 18 19:50:58 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 18 Feb 2009 16:50:58 -0800 (PST) Subject: can multi-core improve single funciton? References: <6a4f17690902092228i31fd1661n41c61c4037a289df@mail.gmail.com> Message-ID: <64c334d7-434f-4ec3-8ccb-35e8088a0cb2@u13g2000yqg.googlegroups.com> On Feb 10, 8:38?am, Paul McGuire wrote: > Even worse than linear, the function is recursive, which as I > understand it, is inherently a no-no when looking for code that is > parallel-friendly. There is no way to parallelize Fibonacci numbers computed with linear time complexity, as we must know fib(n-1) to compute fib(n). But if we were to use Oyster's recursive version, which has geometric complexity, one could parallelize with a 'forkjoin' scheme. Anyhow, this runs in amortized linear time and would be a lot faster: def fib(n): while True: try: return fib.seq[n] except AttributeError: fib.seq = [0, 1, 1] except IndexError: fib.seq.append( fib.seq[-2] + fib.seq[-1] ) S.M. From Scott.Daniels at Acm.Org Wed Feb 18 20:02:55 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 18 Feb 2009 17:02:55 -0800 Subject: Threading and tkinter In-Reply-To: <492d5db9-3681-4ae8-827e-f2a4f66bee80@v39g2000yqm.googlegroups.com> References: <492d5db9-3681-4ae8-827e-f2a4f66bee80@v39g2000yqm.googlegroups.com> Message-ID: gert wrote: > After reading the docs and seeing a few examples i think this should > work ? > Am I forgetting something here or am I doing something stupid ? > Anyway I see my yellow screen, that has to count for something :) > Try this: # tdh_show.py from __future__ import with_statement import time import Tkinter import Tkconstants as TK import threading class Weegbrug(threading.Thread): def __init__(self, frame, var, filename): self.frame = frame self.var = var self.filename = filename threading.Thread.__init__(self) def run(self): with open(self.filename, 'r') as f: for n, line in enumerate(f): # the tricky bit: self.frame.after(100, self.var.set, line.strip()) time.sleep(.5) def main(filename): root = Tkinter.Tk() svar = Tkinter.StringVar(root) frame = Tkinter.Frame(root, relief=TK.RIDGE, borderwidth=2) frame.pack(fill=TK.BOTH, expand=1) label = Tkinter.Label(frame, textvar=svar, bg='yellow', font=('Helvetica', 16)) label.pack(fill=TK.X, expand=1) button = Tkinter.Button(frame, text="Exit", command=root.destroy) button.pack(side=TK.BOTTOM) reader = Weegbrug(frame, svar, filename) button = Tkinter.Button(frame, text="Go", command=reader.start) button.pack(side=TK.BOTTOM) root.mainloop() if __name__ == '__main__': main(__file__) --Scott David Daniels Scott.Daniels at Acm.Org From http Wed Feb 18 20:31:58 2009 From: http (Paul Rubin) Date: 18 Feb 2009 17:31:58 -0800 Subject: PyYaml in standard library? References: <50697b2c0902180134gcb053w96002899356d3ad1@mail.gmail.com> Message-ID: <7x63j72ovl.fsf@ruckus.brouhaha.com> Brendan Miller writes: > I think the json module sticks everything on the same line, which > isn't readable for large data structures. It has a prettyprint option. From bhood37 at hotmail.com Wed Feb 18 20:32:11 2009 From: bhood37 at hotmail.com (Uberman) Date: Wed, 18 Feb 2009 18:32:11 -0700 Subject: Calling a class instance like a function In-Reply-To: References: Message-ID: Thank you very much, Filip!! :) Filip Gruszczy?ski wrote: > __call__ > > 2009/2/19 Uberman : >> I'm wondering if there's a way to invoke a "function" operator on a Python >> class instance. For example, given a class instance: >> >> myClass = MyClass() >> >> I want to call that instance like a function, with an argument value: >> >> myClass(5.0) >> >> I can override the "()" operator in C++, so I'm wondering if there's a way to >> do it in Python as well. >> >> Thanks! >> -- >> http://mail.python.org/mailman/listinfo/python-list From cokofreedom at gmail.com Wed Feb 18 20:35:16 2009 From: cokofreedom at gmail.com (cokofreedom at gmail.com) Date: Wed, 18 Feb 2009 17:35:16 -0800 (PST) Subject: Timeit Message-ID: <95457df7-57ac-4d5c-b68d-2bd804ae3c90@x38g2000yqj.googlegroups.com> I've having an annoying problem at the moment. I'm writing code for the travelling salesmen problem and comparing different techniques. But I've having a problem using timeit. I have a file called "testplatform.py" that contains 4 class: Test() - which is called first to create the cities/routes to be shared between the other classes AutoClone() - which uses the variables from Test() (normally test = Test()) Randomisation() - Ditto BruteForce() - Ditto if __name__ == '__main__': ....test = Test(5, 1000, 100, 100, 100, 14) ....example1 = AutoClone(test.citynames, test.cityroutes, test.seed, ........................test.generations, test.mutate) ....example2 = Randomisation(test.citynames, test.cityroutes, test.seed, ........................test.generations) ....example3 = BruteForce(test.citynames, test.cityroutes) I am really stuck trying to work out how to pass variables to timeit to allow me to run any of the examples... Any help would be great! From sturlamolden at yahoo.no Wed Feb 18 20:36:25 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 18 Feb 2009 17:36:25 -0800 (PST) Subject: can multi-core improve single funciton? References: Message-ID: <11edcd0d-ddaf-4c1a-8ec1-8214f2d86f18@w35g2000yqm.googlegroups.com> On Feb 10, 7:28?am, oyster wrote: > I mean this > [code] > def fib(n): > ? ? if n<=1: > ? ? ? ? return 1 > ? ? return fib(n-1)+fib(n-2) Let's rewrite that slightly and see... def fib(n, _map=None): if not _map: _map = map if n > 2: return sum(_map(fib, (n-1, n-2))) else: return 1 if __name__ == '__main__': from multiprocessing import Pool from time import clock p = Pool() n = 36 t0 = clock() fib(n, p.map) t1 = clock() print 'parallel t: %f seconds' % (t1-t0) t0 = clock() fib(n) t1 = clock() print 'sequential t: %f seconds' % (t1-t0) With two cores: E:\>python fibotest.py parallel t: 31.300226 seconds sequential t: 48.070695 seconds Yes it can! Sturla Molden From gert.cuykens at gmail.com Wed Feb 18 21:06:03 2009 From: gert.cuykens at gmail.com (gert) Date: Wed, 18 Feb 2009 18:06:03 -0800 (PST) Subject: Threading and tkinter References: <492d5db9-3681-4ae8-827e-f2a4f66bee80@v39g2000yqm.googlegroups.com> Message-ID: <6ef2c1d5-d742-4d4c-b1b6-2e685b9ff758@c12g2000yqj.googlegroups.com> Can you first explain why x stay's 0 please and how i should update x using threads ? from tkinter import * from _thread import start_new_thread from time import sleep x=0 def weegbrug(x): while True: x=x+1 sleep(0.5) start_new_thread(weegbrug,(x,)) root = Tk() v = StringVar() v.set("00000") txt = Label(root, textvariable=v, width=800, height=600, bg="yellow", font=("Helvetica", 300)) txt.pack(expand=YES, fill=BOTH) root.title("Weegbrug") root.after(500, lambda:v.set(x)) root.mainloop() From pavlovevidence at gmail.com Wed Feb 18 21:13:25 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 18 Feb 2009 18:13:25 -0800 (PST) Subject: numpy.memmap advice? References: <77c68ff8-d29d-4ada-9829-8f8f61c3ee4c@o36g2000yqh.googlegroups.com> Message-ID: On Feb 18, 4:23?pm, sturlamolden wrote: > On 18 Feb, 00:08, Lionel wrote: > > > 1) What is "recarray"? > > An ndarray of what C programmers know as a "struct", in which each > field is accessible by its name. > > That is, > > struct rgba{ > ? unsigned char r; > ? unsigned char g; > ? unsigned char b; > ? unsigned char a; > > }; > > struct rgba arr[480][640]; > > is similar to: > > import numpy as np > rbga = np.dtype({'names':list('rgba'), 'formats':[np.uint8]*4}) > arr = np.array((480,640), dtype=rgba) > > Now you can access the r, g, b and a fields directly using arr['r'], > arr['g'], arr['b'], and arr['a']. > Internally the data will be represented compactly as with the C code > above. If you want to view the data as an 480 x 640 array of 32 bit > integers instead, it is as simple as arr.view(dtype=np.uint32). > Formatted binary data can of course be read from files using > np.fromfile with the specified dtype, and written to files by passing > a recarray as buffer to file.write. You can thus see NumPy's > recarray's as a more powerful alternative to Python's struct module. > > > I don't really see in the diocumentation how portions are loaded, however. > > Prior to Python 2.6, the mmap object (which numpy.memmap uses > internally) does not take an offset parameter. But when NumPy are > ported to newer version of Python this will be fixed. You should then > be able to memory map with an ndarray from a certain offset. To make > this work now, you must e.g. backport mmap from Python 2.6 and use > that with NumPy. Not difficult, but nobody has bothered to do it (as > far as I know). You can use an offset with numpy.memmap today; it'll mmap the whole file, but start the array data at the given offset. The offset parameter of mmap itself would be useful to map small portions of gigabyte-sized files, and maybe numpy.memmap can take advantage of that if the user passes an offset parameter. One thing you can't do with mmap's offset, but you can do with numpy.memmap, is to set it to an arbitary value, since it has to be a multiple of some large number (something like 1 MB, depending on the OS). Carl Banks From jnoller at gmail.com Wed Feb 18 21:14:06 2009 From: jnoller at gmail.com (Jesse Noller) Date: Wed, 18 Feb 2009 21:14:06 -0500 Subject: PyYaml in standard library? In-Reply-To: References: Message-ID: <4222a8490902181814s48987502x394008858797d55@mail.gmail.com> On Wed, Feb 18, 2009 at 4:11 AM, Brendan Miller wrote: > I'm just curious whether PyYaml is likely to end up in the standard > library at some point? > -- > http://mail.python.org/mailman/listinfo/python-list > Personally, loving the hell out of yaml (and pyyaml) as much as I do, I'd love to see this; however interested people should pass the idea to python-ideas, and write a PEP. It would need a dedicated maintainer as well as the other things stdlib modules require. -jesse From jnoller at gmail.com Wed Feb 18 21:16:11 2009 From: jnoller at gmail.com (Jesse Noller) Date: Wed, 18 Feb 2009 21:16:11 -0500 Subject: multiprocessing module and os.close(sys.stdin.fileno()) In-Reply-To: <3098ffc2-6884-4a35-99a5-ee917442af25@r37g2000prr.googlegroups.com> References: <3098ffc2-6884-4a35-99a5-ee917442af25@r37g2000prr.googlegroups.com> Message-ID: <4222a8490902181816j708f0b5y81b246e5a0fa800d@mail.gmail.com> On Tue, Feb 17, 2009 at 10:34 PM, Graham Dumpleton wrote: > Why is the multiprocessing module, ie., multiprocessing/process.py, in > _bootstrap() doing: > > os.close(sys.stdin.fileno()) > > rather than: > > sys.stdin.close() > > Technically it is feasible that stdin could have been replaced with > something other than a file object, where the replacement doesn't have > a fileno() method. > > In that sort of situation an AttributeError would be raised, which > isn't going to be caught as either OSError or ValueError, which is all > the code watches out for. > > Graham > -- > http://mail.python.org/mailman/listinfo/python-list > I don't know why it was implemented that way. File an issue on the tracker and assign it to me (jnoller) please. From steve at holdenweb.com Wed Feb 18 21:20:13 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 18 Feb 2009 21:20:13 -0500 Subject: Threading and tkinter In-Reply-To: <6ef2c1d5-d742-4d4c-b1b6-2e685b9ff758@c12g2000yqj.googlegroups.com> References: <492d5db9-3681-4ae8-827e-f2a4f66bee80@v39g2000yqm.googlegroups.com> <6ef2c1d5-d742-4d4c-b1b6-2e685b9ff758@c12g2000yqj.googlegroups.com> Message-ID: gert wrote: > Can you first explain why x stay's 0 please and how i should update x > using threads ? > > from tkinter import * > from _thread import start_new_thread > from time import sleep > > x=0 > def weegbrug(x): > while True: > x=x+1 > sleep(0.5) > start_new_thread(weegbrug,(x,)) > > root = Tk() > v = StringVar() > v.set("00000") > txt = Label(root, textvariable=v, width=800, height=600, bg="yellow", > font=("Helvetica", 300)) > txt.pack(expand=YES, fill=BOTH) > root.title("Weegbrug") > root.after(500, lambda:v.set(x)) > root.mainloop() > The reason x stays at zero has nothing to do with threading. The statement x=x+1 (which, by the way, should stylistically be written x = x + 1 if you want your code to be readable) doesn't change anything outside the function. Function arguments are values: since x is a parameter of the function, it exists only inside the function call's namespace. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From justinli79 at gmail.com Wed Feb 18 21:29:02 2009 From: justinli79 at gmail.com (Justin Li) Date: Wed, 18 Feb 2009 18:29:02 -0800 (PST) Subject: Building python with sqlite3 References: Message-ID: <1c1605a8-006c-455d-9120-962a61c9082d@x29g2000prf.googlegroups.com> On Feb 18, 5:13?pm, Christian Heimes wrote: > Justin Li schrieb: > > > I'm building and installing Ptyhon 2.6.1 on Linux. After configure, > > make, make install, to import sqlite3 leads to ImportError. It looks > > like I have to build Python with sqlite. I have sqlite3 installed on > > my system. How should I build Python with it? I did not find any > > options relating with sqlite3 of configure and Makefile. > > Do you have the development files installed as well? Run "make" again > and look at the list of missing modules. > > Christian Thanks for your reply, Christian. And yes, I have. I looked into this. I'm working on a 64bit machine. And the sqlite3 is 64bit as well. Should I install a 32bit sqlite3? I think when I building python, the configure program should detect if my system 32bit or 64bit one and look for proper sqlite3 version. Is that the problem? Thanks again, Justin From steven at REMOVE.THIS.cybersource.com.au Wed Feb 18 21:58:32 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 19 Feb 2009 02:58:32 GMT Subject: Timeit References: <95457df7-57ac-4d5c-b68d-2bd804ae3c90@x38g2000yqj.googlegroups.com> Message-ID: On Wed, 18 Feb 2009 17:35:16 -0800, cokofreedom wrote: > I am really stuck trying to work out how to pass variables to timeit to > allow me to run any of the examples... setup = "from __main__ import example1, example2, example3" Timer("example1()", setup) In Python 2.6 you can also pass function objects directly. -- Steven From rdmurray at bitdance.com Wed Feb 18 22:15:59 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Thu, 19 Feb 2009 03:15:59 +0000 (UTC) Subject: "Maximum recursion depth exceeded"...why? References: <847153c1-579e-4e4f-a21d-dcf106f15636@r41g2000yqm.googlegroups.com> <7xr61w8r20.fsf@ruckus.brouhaha.com> <788cab73-b999-48e4-beb3-b9dd38c501de@j8g2000yql.googlegroups.com> Message-ID: Thomas Allen wrote: > On Feb 18, 4:51 am, alex23 wrote: > > On Feb 18, 7:34 pm, rdmur... at bitdance.com wrote: > > > > > Yeah, but wget -r -k will do that bit of it, too. > > > > Wow, nice, I don't know why I never noticed that. Cheers! > > Hm...doesn't do that over here. I thought it may have been because of > absolute links (not to site root), but it even leaves things like href="/">. Does it work for you guys? It works for me. The sample pages I just tested on it don't use any href="/" links, but my 'href="/about.html"' got properly converted to 'href="../about.html"'. (On the other hand my '/contact.html' got converted to a full external URL...but that's apparently because the contact.html file doesn't actually exist :) --RDM From alan.isaac at gmail.com Wed Feb 18 22:29:17 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Thu, 19 Feb 2009 03:29:17 GMT Subject: block dynamic attribute creation (was: get descriptor from instance) In-Reply-To: References: <5didnW_7dfWlDQHUnZ2dnUVZ_q_inZ2d@rcn.net> Message-ID: On 2/18/2009 6:15 PM Gabriel Genellina apparently wrote: > type(a).x OK, that's good. I'd like to sometimes lock attribute creation on instances of a class but still allow properties to function correctly. Will something like below be satisfactory? Thanks, Alan def __setattr__(self, attr, val): """If instance locked, allow no new attributes.""" try: #get the class attribute if it exists p = getattr(type(self),attr) #if it's a descriptor, use it to set val p.__set__(self, val) except AttributeError: #no descriptor if hasattr(self, attr): #update val self.__dict__[attr] = val elif getattr(self, '_attrlock', False): raise AttributeError( "Set _attrlock to False to add attributes.") else: #new attributes allowed self.__dict__[attr] = val From sri_annauni at yahoo.co.in Wed Feb 18 23:22:09 2009 From: sri_annauni at yahoo.co.in (srinivasan srinivas) Date: Thu, 19 Feb 2009 09:52:09 +0530 (IST) Subject: Python Module for console text formatting? References: <867965.2501.qm@web7903.mail.in.yahoo.com> Message-ID: <208530.16726.qm@web7908.mail.in.yahoo.com> Hi, Is it possible to apply more than one formatting to a string? For ex: the string 'test' has to be underlined and it should be bold. How to do that? Thanks, Srini ________________________________ From: geremy condra To: python-list at python.org Sent: Wednesday, 18 February, 2009 10:04:34 AM Subject: Re: Python Module for console text formatting? You can insert those codes just like you would any other character. If there's enough interest I can whip up a wrapper library for you. http://www.linux.gr/cgi-bin/man2html?console_codes+4 On Tue, Feb 17, 2009 at 11:19 PM, srinivasan srinivas wrote: Hi, Does anyone know any python module other than 'ConsoleFormat0.1.1' used to format text on console? For example, printing bold characters on console. Thanks, Srini ? ? ?Did you know? You can CHAT without downloading messenger. Go to http://in.webmessenger.yahoo.com/ -- http://mail.python.org/mailman/listinfo/python-list -- OpenMigration LLC- Open Source solutions for your business. Visit us at http://OpenMigration.net. Share files, take polls, and make new friends - all under one roof. Go to http://in.promos.yahoo.com/groups/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From Graham.Dumpleton at gmail.com Thu Feb 19 00:23:10 2009 From: Graham.Dumpleton at gmail.com (Graham Dumpleton) Date: Wed, 18 Feb 2009 21:23:10 -0800 (PST) Subject: multiprocessing module and os.close(sys.stdin.fileno()) References: <3098ffc2-6884-4a35-99a5-ee917442af25@r37g2000prr.googlegroups.com> Message-ID: On Feb 19, 1:16?pm, Jesse Noller wrote: > On Tue, Feb 17, 2009 at 10:34 PM, Graham Dumpleton > > > > wrote: > > Why is the multiprocessing module, ie., multiprocessing/process.py, in > > _bootstrap() doing: > > > ?os.close(sys.stdin.fileno()) > > > rather than: > > > ?sys.stdin.close() > > > Technically it is feasible that stdin could have been replaced with > > something other than a file object, where the replacement doesn't have > > a fileno() method. > > > In that sort of situation an AttributeError would be raised, which > > isn't going to be caught as either OSError or ValueError, which is all > > the code watches out for. > > > Graham > > -- > >http://mail.python.org/mailman/listinfo/python-list > > I don't know why it was implemented that way. File an issue on the > tracker and assign it to me (jnoller) please. Created as: http://bugs.python.org/issue5313 I don't see option to assign, so you are on nosy list to start with. Graham From mnordhoff at mattnordhoff.com Thu Feb 19 00:24:34 2009 From: mnordhoff at mattnordhoff.com (Matt Nordhoff) Date: Thu, 19 Feb 2009 05:24:34 +0000 Subject: Revision Control In-Reply-To: <499C5521.2040705@tim.thechases.com> References: <822B0E83D23291469317E3432468743702224B@production.2000soft.com> <499C5521.2040705@tim.thechases.com> Message-ID: <499CED12.3040802@mattnordhoff.com> Tim Chase wrote: >> -Mercurial (this is a big up and coming RCS) > > This is currently my favorite: good branching/merging, fast, written > mostly in Python (one C extension module, IIRC), and a simple interface > >> -Bazaar (written in Python. Also pretty new. I don't know about Windows >> support) > > I like Bazaar (bzr), but the last several times I've tried it, it's been > a little slow. This has been steadily improving, and I like their > emphasis on correctness foremost. It's a lot like mercurial, but is > pure python (no C extension module) which makes it nice to deploy into > environments such as my shared web-hosting service where I can't build > extension C modules or install packages such as hg/git/svn from the > repository. FWIW, Bazaar and Mercurial both have about half a dozen C modules. (Most of Bazaar's are Pyrex, though, not straight C.) The next release of Mercurial will add support for running without them. (Bazaar already supports that, of course.) -- From pavlovevidence at gmail.com Thu Feb 19 00:40:24 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 18 Feb 2009 21:40:24 -0800 (PST) Subject: Problem--Extending the behavior of an upstream package Message-ID: <60848752-2c3f-4512-bf61-0bc11c919f99@i20g2000prf.googlegroups.com> Ok, I think I know I want to do this, but I thought I'd run it by yins guys I have a fairly large and complex application with two top-level packages, which we'll call upstream and mine. The "upstream" package isn't really upstream. I own both packages, but I think of the upstream package as a third-party library relative to the mine package. The mine package contains code specific to the application. Anyway, the upstream modules provide lots of classes and other functionality, but I want to extend their behavior in various ways. Say for instance I have a class called Box defined in the module upstream.packaging. In this particular application, it makes sense for all boxes to have a certain behavior, such as a certain way of being drawn. So I define a module called mine.custom_packaging which defines a subclass of upstream.packaging.Box. That's straightforward enough. The problem comes when a different part of the upstream package also subclasses or creates a Box. When an upstream function creates a box, it creates an upstream.packaging.Box instead of a mine.custom_packaging.Box, but I'd want it to do the latter. If this were something that happened only once or twice, it'd be no big deal, I'd just work around it. However, it's very common. The upstream package is almost a complete application unto itself; it only needs data and a small amount of top-level code to run. The sort of tight internal coupling that exists within the upstream package makes it a logistical problem to extend it. And the thing is, I can't think of a convenient way to do it that's tolerably magical, and I am quite tolerant of homebrew magic in my code. A particularly troublesome situation is when a base class and subclass are defined in the same module, and I want to customize both. Even things like disambiguating nomenclature trip me up. It isn't just classes, BTW. Sometimes I want to override functions, or modify permanent data. So, how would you approach something like this? (After a little discussion--or not--I'll post some things I've considered, including a few approaches I've actually implemented. But I don't want to taint everyone's ideas just yet.) Carl Banks From justinli79 at gmail.com Thu Feb 19 00:49:03 2009 From: justinli79 at gmail.com (Justin Li) Date: Wed, 18 Feb 2009 21:49:03 -0800 (PST) Subject: Building python with sqlite3 References: <1c1605a8-006c-455d-9120-962a61c9082d@x29g2000prf.googlegroups.com> Message-ID: On Feb 18, 6:29 pm, Justin Li wrote: > On Feb 18, 5:13 pm, Christian Heimes wrote: > > > Justin Li schrieb: > > > > I'm building and installing Ptyhon 2.6.1 on Linux. After configure, > > > make, make install, to importsqlite3leads to ImportError. It looks > > > like I have to build Python with sqlite. I havesqlite3installed on > > > my system. How should I build Python with it? I did not find any > > > options relating withsqlite3of configure and Makefile. > > > Do you have the development files installed as well? Run "make" again > > and look at the list of missing modules. > > > Christian > > Thanks for your reply, Christian. > > And yes, I have. I looked into this. I'm working on a 64bit machine. > And thesqlite3is 64bit as well. Should I install a 32bitsqlite3? I > think when I building python, the configure program should detect if > my system 32bit or 64bit one and look for propersqlite3version. > > Is that the problem? > > Thanks again, > Justin I fixed it. I download sqlite3 from website and install it. As a result, it works fine now. From aleksandr.goretoy at gmail.com Thu Feb 19 01:13:38 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Thu, 19 Feb 2009 00:13:38 -0600 Subject: Python Module for console text formatting? In-Reply-To: <208530.16726.qm@web7908.mail.in.yahoo.com> References: <867965.2501.qm@web7903.mail.in.yahoo.com> <208530.16726.qm@web7908.mail.in.yahoo.com> Message-ID: I created a little script for doing stdout coloring for me a while back. Maybe this will get you closer to what you are looking for. It's kinda hackish, but it works. http://code.google.com/p/python-stdout-colors/ -Alex Goretoy http://www.goretoy.com On Wed, Feb 18, 2009 at 10:22 PM, srinivasan srinivas < sri_annauni at yahoo.co.in> wrote: > Hi, > Is it possible to apply more than one formatting to a string? > For ex: the string 'test' has to be underlined and it should be bold. How > to do that? > > Thanks, > Srini > ------------------------------ > *From:* geremy condra > *To:* python-list at python.org > *Sent:* Wednesday, 18 February, 2009 10:04:34 AM > *Subject:* Re: Python Module for console text formatting? > > You can insert those codes just like you would any other character. If > there's enough interest I can whip up a wrapper library for you. > > http://www.linux.gr/cgi-bin/man2html?console_codes+4 > > On Tue, Feb 17, 2009 at 11:19 PM, srinivasan srinivas < > sri_annauni at yahoo.co.in> wrote: > >> >> Hi, >> Does anyone know any python module other than 'ConsoleFormat0.1.1' used to >> format text on console? >> For example, printing bold characters on console. >> >> Thanks, >> Srini >> >> >> Did you know? You can CHAT without downloading messenger. Go to >> http://in.webmessenger.yahoo.com/ >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > > -- > OpenMigration LLC- Open Source solutions for your business. Visit us at > http://OpenMigration.net . > > ------------------------------ > Add more friends to your messenger and enjoy! Invite them now. > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From diresu at web.de Thu Feb 19 01:28:12 2009 From: diresu at web.de (Dietrich Bollmann) Date: Thu, 19 Feb 2009 15:28:12 +0900 Subject: How to convert between Japanese coding systems? Message-ID: <1235024892.3981.56.camel@pippi.pippi> Hi, Are there any functions in python to convert between different Japanese coding systems? I would like to convert between (at least) ISO-2022-JP, UTF-8, EUC-JP and SJIS. I also need some function to encode / decode base64 encoded strings. I get the strings (which actually are emails) from a server on the internet with: import urllib server = urllib.urlopen(serverURL, parameters) email = server.read() The coding systems are given in the response string: Example: email = '''[...] Subject: =?UTF-8?Q?romaji=E3=81=B2=E3=82=89=E3=81=8C=E3=81=AA=E3=82=AB=E3=82=BF?= =?UTF-8?Q?=E3=82=AB=E3=83=8A=E6=BC=A2=E5=AD=97?= [...] Content-Type: text/plain; charset=EUC-JP [...] Content-Transfer-Encoding: base64 [...] cm9tYWpppNKk6aSspMqlq6W/paulyrTBu/oNCg0K ''' My idea is to first parse the 'email' string and to extract the email body as well as the values of the 'Subject: ', the 'Content-Type: ' and the 'Content-Transfer-Encoding: ' attributes and to after use them to convert them to some other coding system: Something in the lines of: (subject, contentType, contentTransferEncoding, content) = parseEmail(email) to = 'utf-8' subjectUtf8 = decodeSubject(subject, to) from = contentType to = 'utf-8' contentUtf8 = convertCodingSystem(decodeBase64(content), from, to) The only problem is that I could not find any standard functionality to convert between different Japanese coding systems. Thanks, Dietrich Bollmann From nad at acm.org Thu Feb 19 02:02:53 2009 From: nad at acm.org (Ned Deily) Date: Wed, 18 Feb 2009 23:02:53 -0800 Subject: v 3.0 mpkg References: <2E75ECDE-6B15-471F-8747-ED4616EF4847@talktalk.net> <8c7f10c60902040337q617a37bfr9ec937b38e433fa9@mail.gmail.com> Message-ID: In article <8c7f10c60902040337q617a37bfr9ec937b38e433fa9 at mail.gmail.com>, Simon Brunning wrote: > 2009/2/4 John Forse : > > Does anyone know if Python v3.0 is available as an .mpkg installer for Mac > > 10.5.6. I have used 2.5 & updated to 2.6.1 this way, but can't find any > > reference to one on the Python.org download site. I've downloaded the Python > > 3.0 folder but can't follow how to install it without a .mpkg file. Any help > > would be really appreciated. > AFAIK there's no Python 3.0 installer for the Mac. You'll have to > build it yourself - see . Follow up: Python 3.0.1 has been released and, with it, an installer image for OS X: -- Ned Deily, nad at acm.org From apt.shansen at gmail.com Thu Feb 19 02:35:55 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Wed, 18 Feb 2009 23:35:55 -0800 Subject: v 3.0 mpkg In-Reply-To: References: <2E75ECDE-6B15-471F-8747-ED4616EF4847@talktalk.net> <8c7f10c60902040337q617a37bfr9ec937b38e433fa9@mail.gmail.com> Message-ID: <7a9c25c20902182335n226e4496vce023b1627baaf3a@mail.gmail.com> > Follow up: Python 3.0.1 has been released and, with it, an installer > image for OS X: > > > How doe the 3.0 installer on the mac interact with existing installs? I have the system install but more importantly the python.org one which I can't have messed up; will this install just as 'python3'? I wanna be sure it won't mess anything up on my system, as my company is still on 2.4 as a standard and barely preparing to move to 2.5 -- we only use it on our macs installs. Thanks.. --S From __peter__ at web.de Thu Feb 19 02:51:03 2009 From: __peter__ at web.de (Peter Otten) Date: Thu, 19 Feb 2009 08:51:03 +0100 Subject: How to convert between Japanese coding systems? References: Message-ID: Dietrich Bollmann wrote: > I get the strings (which actually are emails) from a server on the > internet with: > > import urllib > server = urllib.urlopen(serverURL, parameters) > email = server.read() > > The coding systems are given in the response string: > > Example: > > email = '''[...] > Subject: > =?UTF-8?Q?romaji=E3=81=B2=E3=82=89=E3=81=8C=E3=81=AA=E3=82=AB=E3=82=BF?= > =?UTF-8?Q?=E3=82=AB=E3=83=8A=E6=BC=A2=E5=AD=97?= > [...] > Content-Type: text/plain; charset=EUC-JP > [...] > Content-Transfer-Encoding: base64 > [...] > > cm9tYWpppNKk6aSspMqlq6W/paulyrTBu/oNCg0K > > ''' Is that an email? Maybe you can get it in a format that is supported by the email package in the standard library. > The only problem is that I could not find any standard functionality to > convert between different Japanese coding systems. Then you didn't look hard enough: >>> s = "????".decode("utf8") # i have no idea what that means >>> s.encode("iso-2022-jp") '\x1b$B2q>> s.encode("euc-jp") '\xb2\xf1\xbc\xd2\xb3\xb5\xcd\xd7' >>> s.encode("sjis") '\x89\xef\x8e\xd0\x8aT\x97v' See also http://www.amk.ca/python/howto/unicode Peter From cwitts at gmail.com Thu Feb 19 03:12:12 2009 From: cwitts at gmail.com (Chris) Date: Thu, 19 Feb 2009 00:12:12 -0800 (PST) Subject: Delete lines which contain string in a file References: <7cbf2f3a0902181342w20d3bcbfnf640a177b221c8a6@mail.gmail.com> Message-ID: <452cd8ba-392f-451d-8f51-f81bd1eb0d8b@j8g2000yql.googlegroups.com> On Feb 19, 12:24?am, Steve Holden wrote: > Rudi Goldman wrote: > > Hi, > > Go easy on me as I am a new to Python and am trying to solve a practical > > problem that is driving me bananas. > > Basically I have 2 text files, a source and a target. I want to be able > > to delete all of the lines in the target file which contain text from > > any line in the source file. > > i.e. > > Source: ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Target: > > 111 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? xxx 111 yyy ? > > 222 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? xxx ?333 sss > > 333 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? jjj ? 444 sss > > > After executing this code the target file should only consist of the > > line: ? ? jjj ? 444 sss > > Any help on this one would be greatly appreciated. > > Is this homework? > > How far have you got with your design? > > regards > ?Steve > -- > Steve Holden ? ? ? ?+1 571 484 6266 ? +1 800 494 3119 > Holden Web LLC ? ? ? ? ? ? ?http://www.holdenweb.com/ Who needs python for this... cwitts at cwitts-mint ~ $ cat src.txt [111,222,333] cwitts at cwitts-mint ~ $ cat tgt.txt xxx 111 yyy xxx 333 sss jjj 444 sss cwitts at cwitts-mint ~ $ grep -v -f src.txt tgt.txt jjj 444 sss From mail at microcorp.co.za Thu Feb 19 03:25:28 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Thu, 19 Feb 2009 10:25:28 +0200 Subject: PIL install driving me mad! With solution! References: Message-ID: <000c01c99270$f0bbc600$0d00a8c0@hendrik> "bleah" wrote: >I'm trying to get PIL 1.16 installed on a SUSE SLES10 system, and >cannot, for the life of me, get the thing to compile with jpeg >support. > >The libjpeg-devel libraries are installed, and are present in /usr/lib >JUST WHERE SPECIFIED in the setup.py file, and the jpeglib.h incliude >file is present JUST WHERE SPECIFIED in the setup.py file. > >The build process proceeds without errors, yet selftest.py fails with >the error: > >tonic:~/html2pdf_sources/Imaging-1.1.6 # python selftest.py >***************************************************************** >Failure in example: _info(Image.open("Images/lena.jpg")) This is the problem. Lena with the feathered hat is a shy girl, and she does not allow just anybody to look at her. :-) - Hendrik From Lie.1296 at gmail.com Thu Feb 19 03:29:53 2009 From: Lie.1296 at gmail.com (Lie) Date: Thu, 19 Feb 2009 00:29:53 -0800 (PST) Subject: Python 3D CAD -- need collaborators, or just brave souls :) References: <4993DE39.8030200@cosc.canterbury.ac.nz> <9ef65856-0f62-4434-a4b4-e15558e7c7b0@n2g2000vba.googlegroups.com> Message-ID: On Feb 18, 8:02?pm, r wrote: > Hello Josh, > Blender is a lost cause. It is a powerful app but the UI is horrible. > Even the Blender folks admit only a complete rewrite could solve the > major flaws that plague the design. So maybe i could salvage some code > but for what i have in mind, Blender will look like a piece of > software from the middle ages. And i am absolutly only looking to do > this in 3D, 2D is boring. Blender's UI is designed for effective and efficient 3D workflow, not for low learning curve. From bruno.42.desthuilliers at websiteburo.invalid Thu Feb 19 03:33:56 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 19 Feb 2009 09:33:56 +0100 Subject: Calling a class instance like a function In-Reply-To: References: Message-ID: <499d1960$0$18734$426a74cc@news.free.fr> Uberman a ?crit : > I'm wondering if there's a way to invoke a "function" operator on a Python > class instance. For example, given a class instance: > > myClass = MyClass() > > I want to call that instance like a function, with an argument value: > > myClass(5.0) > > I can override the "()" operator in C++, so I'm wondering if there's a way to > do it in Python as well. Filip already answered, but you may want to read this anyway: http://docs.python.org/reference/datamodel.html#special-method-names HTH From bruno.42.desthuilliers at websiteburo.invalid Thu Feb 19 03:47:48 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 19 Feb 2009 09:47:48 +0100 Subject: block dynamic attribute creation In-Reply-To: References: <5didnW_7dfWlDQHUnZ2dnUVZ_q_inZ2d@rcn.net> Message-ID: <499d1ca1$0$26184$426a74cc@news.free.fr> Alan G Isaac a ?crit : > On 2/18/2009 6:15 PM Gabriel Genellina apparently wrote: >> type(a).x > > OK, that's good. I'd like to sometimes lock attribute creation on > instances of a class but still allow properties to function > correctly. Will something like below be satisfactory? > > > def __setattr__(self, attr, val): > """If instance locked, allow no new attributes.""" > try: > #get the class attribute if it exists > p = getattr(type(self),attr) > #if it's a descriptor, use it to set val > p.__set__(self, val) > except AttributeError: #no descriptor > if hasattr(self, attr): #update val > self.__dict__[attr] = val > elif getattr(self, '_attrlock', False): > raise AttributeError( > "Set _attrlock to False to add attributes.") > else: > #new attributes allowed > self.__dict__[attr] = val Might be safer to call on the parent class __setattr__ instead of directly assigning to the instance's dict Also, your tests in the except clause could be simplified: if not hasattr(self, attr) and getattr(self, '_attrlock', False): raise AttributeError(yadda yadda) # NB: assume newstyle class super(YourClass, self).__setattr__(attr, val) My 2 cents. From gagsl-py2 at yahoo.com.ar Thu Feb 19 03:54:29 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 19 Feb 2009 06:54:29 -0200 Subject: os.popen encoding! References: <87ocwzzvym.fsf@mulj.homelinux.net> Message-ID: En Wed, 18 Feb 2009 22:38:45 -0200, SMALLp escribi?: > Thanks for help! > > My problem was actualy: >>>> a = ["velja\xe8a 2009"] >>>> print a #will print > ["velja\xe8a 2009"] >>>> Print a[0] #will print > velja?a 2009 And why is that a problem? Almost the only reason to print a list is when debugging a program. To print a list, Python uses repr() on each of its elements. Otherwise, [5, "5", u'5'] would be indistinguishable from [5, 5, 5], and you usually want to know exactly *what* the list contains. Perhaps if you tell us what do you want to do exactly someone can offer more advice. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Thu Feb 19 03:54:45 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 19 Feb 2009 06:54:45 -0200 Subject: can multi-core improve single funciton? References: <11edcd0d-ddaf-4c1a-8ec1-8214f2d86f18@w35g2000yqm.googlegroups.com> Message-ID: En Wed, 18 Feb 2009 23:36:25 -0200, sturlamolden escribi?: > On Feb 10, 7:28?am, oyster wrote: > Let's rewrite that slightly and see... > > def fib(n, _map=None): > if not _map: _map = map > if n > 2: > return sum(_map(fib, (n-1, n-2))) > else: > return 1 > > > With two cores: > > E:\>python fibotest.py > parallel t: 31.300226 seconds > sequential t: 48.070695 seconds > > > Yes it can! Are you kidding? This is like building a house one brick at a time, but before placing a new brick, you throw all the previous work and start again from start. Certainly two workers would help more than one - but the best way to do it is *NOT* to repeat all that additional work over and over in the first place. Even my Pentium I MMX 233MHz can compute fib(36) thousand of times faster than that with the right algorithm. So I don't see the point in parallelizing if you're going to get infinitely worse results... -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Thu Feb 19 03:54:53 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 19 Feb 2009 06:54:53 -0200 Subject: block dynamic attribute creation (was: get descriptor from instance) References: <5didnW_7dfWlDQHUnZ2dnUVZ_q_inZ2d@rcn.net> Message-ID: En Thu, 19 Feb 2009 01:29:17 -0200, Alan G Isaac escribi?: > OK, that's good. I'd like to sometimes lock attribute creation on > instances of a class but still allow properties to function > correctly. Will something like below be satisfactory? > > def __setattr__(self, attr, val): > """If instance locked, allow no new attributes.""" > try: > #get the class attribute if it exists > p = getattr(type(self),attr) > #if it's a descriptor, use it to set val > p.__set__(self, val) > except AttributeError: #no descriptor > if hasattr(self, attr): #update val > self.__dict__[attr] = val > elif getattr(self, '_attrlock', False): > raise AttributeError( > "Set _attrlock to False to add attributes.") > else: > #new attributes allowed > self.__dict__[attr] = val The problem with using __setattr__ is that is slows down *all* attribute writes considerably. In particular, your code prevents using class attributes as a default value for instance attributes (not a big deal, but I like it sometimes), and you must remember to set a value for all attributes (even the "hidden" ones used by any property). But if you feel OK with that, "just do it". I think there are a few recipes in the Python Cookbook about this topic too. -- Gabriel Genellina From nad at acm.org Thu Feb 19 03:58:23 2009 From: nad at acm.org (Ned Deily) Date: Thu, 19 Feb 2009 00:58:23 -0800 Subject: v 3.0 mpkg References: <2E75ECDE-6B15-471F-8747-ED4616EF4847@talktalk.net> <8c7f10c60902040337q617a37bfr9ec937b38e433fa9@mail.gmail.com> <7a9c25c20902182335n226e4496vce023b1627baaf3a@mail.gmail.com> Message-ID: In article <7a9c25c20902182335n226e4496vce023b1627baaf3a at mail.gmail.com>, Stephen Hansen wrote: > > Follow up: Python 3.0.1 has been released and, with it, an installer > > image for OS X: > > > How doe the 3.0 installer on the mac interact with existing installs? > I have the system install but more importantly the python.org one > which I can't have messed up; will this install just as 'python3'? > > I wanna be sure it won't mess anything up on my system, as my company > is still on 2.4 as a standard and barely preparing to move to 2.5 -- > we only use it on our macs installs. -- Ned Deily, nad at acm.org From justin.mailinglists at gmail.com Thu Feb 19 04:02:01 2009 From: justin.mailinglists at gmail.com (Justin Ezequiel) Date: Thu, 19 Feb 2009 01:02:01 -0800 (PST) Subject: How to convert between Japanese coding systems? References: Message-ID: <9132a12f-8ff5-4a5a-909d-fb322af42936@r3g2000vbp.googlegroups.com> On Feb 19, 2:28?pm, Dietrich Bollmann wrote: > Are there any functions in python to convert between different Japanese > coding systems? > > I would like to convert between (at least) ISO-2022-JP, UTF-8, EUC-JP > and SJIS. ?I also need some function to encode / decode base64 encoded > strings. > > Example: > > email = '''[...] > Subject: > =?UTF-8?Q?romaji=E3=81=B2=E3=82=89=E3=81=8C=E3=81=AA=E3=82=AB=E3=82=BF?= > =?UTF-8?Q?=E3=82=AB=E3=83=8A=E6=BC=A2=E5=AD=97?= > [...] > Content-Type: text/plain; charset=EUC-JP > [...] > Content-Transfer-Encoding: base64 > [...] > > cm9tYWpppNKk6aSspMqlq6W/paulyrTBu/oNCg0K > > ''' > > ? from = contentType > ? to = 'utf-8' > ? contentUtf8 = convertCodingSystem(decodeBase64(content), from, to) > > The only problem is that I could not find any standard functionality to > convert between different Japanese coding systems. > > Thanks, > > Dietrich Bollmann import base64 ENCODINGS = ['ISO-2022-JP', 'UTF-8', 'EUC-JP', 'SJIS'] def decodeBase64(content): return base64.decodestring(content) def convertCodingSystem(s, _from, _to): unicode = s.decode(_from) return unicode.encode(_to) if __name__ == '__main__': content = 'cm9tYWpppNKk6aSspMqlq6W/paulyrTBu/oNCg0K' _from = 'EUC-JP' for _to in ENCODINGS: x = convertCodingSystem(decodeBase64(content), _from, _to) print _to, repr(x) From sjmachin at lexicon.net Thu Feb 19 04:45:03 2009 From: sjmachin at lexicon.net (John Machin) Date: Thu, 19 Feb 2009 01:45:03 -0800 (PST) Subject: Pythonic way to determine if one char of many in a string References: <1234761457.20683.1300568627@webmail.messagingengine.com> <01aa9ea5$0$20632$c3e8da3@news.astraweb.com> <8e63a5ce0902181144q6e5405a2y9b393a34cf4d7d58@mail.gmail.com> <_uydneN7BuEGkwDUnZ2dnUVZ_tudnZ2d@earthlink.com> Message-ID: <84663b82-89f5-4f74-9091-b8fd65b92c5e@b38g2000prf.googlegroups.com> On Feb 19, 6:47?pm, Dennis Lee Bieber wrote: > On Wed, 18 Feb 2009 21:22:45 +0100, Peter Otten <__pete... at web.de> > declaimed the following in comp.lang.python: > > > Steve Holden wrote: > > > > Jervis Whitley wrote: > > >>> What happens when you have hundreds of megabytes, I don't know. > > > >> I hope I never have to test a word that is hundreds of megabytes long > > >> for a vowel :) > > > > I see you don't speak German ;-) > > > I tried to come up with a funny way to point out that you're a fool. > > > But because I'm German I failed. > > ? ? ? ? Yeah... the proper language to bemoan is Welsh > > Where "w" is vowel Better bemoaned is Czech which can go on and on using only L and R as "sonorant consonants" instead of vowels. From gert.cuykens at gmail.com Thu Feb 19 05:03:21 2009 From: gert.cuykens at gmail.com (gert) Date: Thu, 19 Feb 2009 02:03:21 -0800 (PST) Subject: Threading and tkinter References: <492d5db9-3681-4ae8-827e-f2a4f66bee80@v39g2000yqm.googlegroups.com> <6ef2c1d5-d742-4d4c-b1b6-2e685b9ff758@c12g2000yqj.googlegroups.com> Message-ID: <999bdec3-cf58-4e30-acac-e62d1b8ad340@k19g2000yqg.googlegroups.com> On Feb 19, 3:20?am, Steve Holden wrote: > gert wrote: > > Can you first explain why x stay's 0 please and how i should update x > > using threads ? > > > fromtkinterimport * > > from _thread import start_new_thread > > from time import sleep > > > x=0 > > def weegbrug(x): > > ? ? while True: > > ? ? ? ? x=x+1 > > ? ? ? ? sleep(0.5) > > start_new_thread(weegbrug,(x,)) > > > root = Tk() > > v = StringVar() > > v.set("00000") > > txt = Label(root, textvariable=v, width=800, height=600, bg="yellow", > > font=("Helvetica", 300)) > > txt.pack(expand=YES, fill=BOTH) > > root.title("Weegbrug") > > root.after(500, lambda:v.set(x)) > > root.mainloop() > > The reason x stays at zero has nothing to do withthreading. > > The statement > > ? ? x=x+1 > > (which, by the way, should stylistically be written > > ? ? x = x + 1 > > if you want your code to be readable) doesn't change anything outside > the function. Function arguments are values: since x is a parameter of > the function, it exists only inside the function call's namespace. > Oeps :) Anyway will this x work in tkinter from _thread import start_new_thread from time import sleep x=0 def weegbrug(): global x while True: x=x+1 sleep(0.5) start_new_thread(weegbrug,()) while True: print(x) From mail at microcorp.co.za Thu Feb 19 05:08:22 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Thu, 19 Feb 2009 12:08:22 +0200 Subject: Threading and tkinter References: <492d5db9-3681-4ae8-827e-f2a4f66bee80@v39g2000yqm.googlegroups.com> <90d5e669-e8d1-441e-adff-ddc501d21d26@u13g2000yqg.googlegroups.com> Message-ID: <009901c9927a$de95e280$0d00a8c0@hendrik> "gert" wrote: >On Feb 18, 8:25 am, "Hendrik van Rooyen" wrote: >> "gert" wrote: >> >> > After reading the docs and seeing a few examples i think this should >> > work ? >> > Am I forgetting something here or am I doing something stupid ? >> > Anyway I see my yellow screen, that has to count for something :) >> >> > from tkinter import * >> > from threading import Thread >> >> > class Weegbrug(Thread): >> > def __init__(self,v): .> > self.v=v >> > Thread.__init__(self) >> > def run(self): >> > while True: >> > with open('com1','r') as f: >> > for line in f: >> > self.v.set(line[2:-1]) >> >> It is in general not a good idea to directly >> access GUI variables from outside the >> GUI main loop. >> There is a recipe for doing this sort of thing, >> but as usual I have lost the reference. >> What it does is that instead of interfering directly >> as above, you put the data on a queue. >> >> Then, you use the after() call to set up a call >> to a routine that reads the queue, and configures the >> display, and then uses after again to call itself again >> after a time, thereby keeping the GUI stuff in the GUI >> mainloop. >> > >from tkinter import * >from threading import Thread > >class Weegbrug(Thread): > def __init__(self): > self.display='00000' > Thread.__init__(self) > def run(self): > x=0 > while True: > x=x+1 > self.display=x Still mucking around from outside the GUI. > #with open('com1','r') as f: > # for l in f: > # self.display=l[2:-1] > >root = Tk() >v = StringVar() >v.set('00000') >w = Weegbrug() >w.start() >tx = Label(root, textvariable=v, width=800, height=600, bg='yellow', >font=('Helvetica', 300)) >tx.pack(expand=YES, fill=BOTH) >root.title('Weegbrug') >root.overrideredirect(1) >root.geometry('%dx%d+0+0' % (root.winfo_screenwidth(), >root.winfo_screenheight())) >root.after(500, v.set(w.display)) root.after(500,displayer(q)) # You set up a "stutter thread" like this >root.mainloop() > >Why does this not work ? >It only shows one result ? You are only calling it once. Read my story above again. (And Again) Specially the bit about putting the values into a queue. You need to do something like this: def displayer(q): # stuff to read the queue and update the display root.after(500, displayer(q)) # This makes sure it keeps on stuttering Where q is an instance of Queue.Queue There is a nice recipe by Thomas Haeller (?) but I have lost the link. - Hendrik From justin.mailinglists at gmail.com Thu Feb 19 05:12:18 2009 From: justin.mailinglists at gmail.com (Justin Ezequiel) Date: Thu, 19 Feb 2009 02:12:18 -0800 (PST) Subject: How to convert between Japanese coding systems? References: <9132a12f-8ff5-4a5a-909d-fb322af42936@r3g2000vbp.googlegroups.com> Message-ID: import email from email.Header import decode_header from unicodedata import name as un MS = '''\ Subject: =?UTF-8?Q? romaji=E3=81=B2=E3=82=89=E3=81=8C=E3=81=AA=E3=82=AB=E3=82=BF?= Date: Thu, 19 Feb 2009 09:34:56 -0000 MIME-Version: 1.0 Content-Type: text/plain; charset=EUC-JP Content-Transfer-Encoding: base64 cm9tYWpppNKk6aSspMqlq6W/paulyrTBu/oNCg0K ''' def get_header(msg, name): (value, charset), = decode_header(msg.get(name)) if not charset: return value return value.decode(charset) if __name__ == '__main__': msg = email.message_from_string(MS) s = get_header(msg, 'Subject') print repr(s) for c in s: try: print un(c) except ValueError: print repr(c) print e = msg.get_content_charset() b = msg.get_payload(decode=True).decode(e) print repr(b) for c in b: try: print un(c) except ValueError: print repr(c) print From oswald.harry at gmail.com Thu Feb 19 05:21:51 2009 From: oswald.harry at gmail.com (harryos) Date: Thu, 19 Feb 2009 02:21:51 -0800 (PST) Subject: how to list all installed modules References: <4-6dndjITMU90wHUnZ2dnUVZ_qvinZ2d@pdx.net> Message-ID: On Feb 18, 11:10?pm, Scott David Daniels > Are you running F:\Python25\python.exe (or F:\Python25\pythonw.exe)? > open a command window (run cmd), and type: > ? ? ?C:\> python > ? ? ?... > ? ? ?>>> import sys > ? ? ?>>> for dirname in ?sys.path: > ? ? ? ? ? ? ?print sys.path > > I suspect something you see printed will surprise you. > Either the banner, identifying a Python version you were > not expecting, or perhaps a bunch of C:-based directories. > If this does not help you decipher the problem, try running > ? ? ? python -v > Python verbose mode (You will get a _lot_ of output). > Then, when you (finally) get a ">>>" prompt, type: > ? ? >>> import pygame > and you will see eaxctly what lookups are tried. thanks Scott for the detailed reply.. I reinstalled python and pygame and now things are working..:-) thanks again harry From rubik_wizard at NO.SPAMhotmail.com Thu Feb 19 05:33:30 2009 From: rubik_wizard at NO.SPAMhotmail.com (Neil) Date: Thu, 19 Feb 2009 10:33:30 -0000 Subject: Newbie Q about Turtle Gfx References: Message-ID: <0bCdnXbPLcAYqADUnZ2dnUVZ8i2WnZ2d@bt.com> Hi It turns out I should have used t=turtle.Pen() and not t=turtle.pen() My stupid mistake! "Neil" wrote in message news:jYydnb8XE8HPOgHUnZ2dnUVZ8juWnZ2d at bt.com... > Thanks everyone! > > It appears the info in the book is wrong. Trying what you have all > suggested > has got it to work! > > Many thanks, and I am sure I will be back here again with other newbie > problems! > > Neil > > "Neil" wrote in message > news:ifidnR_GysdMFQHUnZ2dneKdnZzinZ2d at bt.com... >> Hello >> >> Sorry if this is not an appropriate newsgroup for this problem. I am very >> new to Python but not new to programming. >> >> I am hoping to use Python to teach a class and have been looking at the >> online book 'Snake Wrangling for Kids'. >> >> I have followed the example >> >>>>>import turtle >>>>>t=turtle.pen() >> >> which works fine and displays a turtle in a window. >> >> However whenever I try to use something like >> >>>>>t.forward(50) (taken from the book) >> >> i get the error... >> >> Traceback (most recent call last): >> File "", line 1, in >> t.forward(50) >> AttributeError: 'dict' object has no attribute 'forward' >> >> I get the same error with t.left(10) etc. etc. >> >> I have tried this with V2.6 and V3 >> >> Any ideas would be much appreciated. >> >> Thanks >> Neil >> >> >> > > From slafs.e at gmail.com Thu Feb 19 05:53:56 2009 From: slafs.e at gmail.com (Slafs) Date: Thu, 19 Feb 2009 02:53:56 -0800 (PST) Subject: cx Oracle privileges Message-ID: <1f0cae7c-d842-488c-a37e-cc4d799360e5@t11g2000yqg.googlegroups.com> Hello On my Debian server I'm using cx Oracle 5.1 (installation from a package made from rpm by alien) with Python 2.5.2 and Oracle Instant Client 10.2.0.4.0. Installation went well but simple test such as connecting to the db shows that only user root can make a connection to a database, but any other user can't do this becuse >>> import cx_Oracle >>> connection = cx_Oracle.Connection('user/pass at 1.2.3.4/dbsid') hangs :/ I've checked privileges to instant client and cx_Oracle.so in site- packages and they are fine. Did anyone came across with similar problem or maybe can show me where I should look for the cause? Thanks in advance. From http Thu Feb 19 05:57:34 2009 From: http (Paul Rubin) Date: 19 Feb 2009 02:57:34 -0800 Subject: can multi-core improve single funciton? References: <11edcd0d-ddaf-4c1a-8ec1-8214f2d86f18@w35g2000yqm.googlegroups.com> Message-ID: <7x1vtuiti9.fsf@ruckus.brouhaha.com> "Gabriel Genellina" writes: > Even my Pentium I MMX 233MHz can compute fib(36) thousand of times faster > than that with the right algorithm. So I don't see the point in > parallelizing if you're going to get infinitely worse results... The point is to test the parallelization scheme. Recursive fibonacci is a standard benchmark for this sort of thing. Sturlamolden's test may be inspired by a recent similar GHC test: http://donsbot.wordpress.com/2007/11/29/ From rushenaly at gmail.com Thu Feb 19 06:36:13 2009 From: rushenaly at gmail.com (rushenaly at gmail.com) Date: Thu, 19 Feb 2009 03:36:13 -0800 (PST) Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <28e3612d-2e91-4a91-82cb-5fb2deda95fd@q9g2000yqc.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> Message-ID: <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> Thank you for all your answers... I think i am going to pick Java instead of Python... Rushen From cdsd at d.com Thu Feb 19 06:39:45 2009 From: cdsd at d.com (ssd) Date: Thu, 19 Feb 2009 12:39:45 +0100 Subject: py test Message-ID: test b From jeff.dyke at gmail.com Thu Feb 19 07:10:35 2009 From: jeff.dyke at gmail.com (Jeff Dyke) Date: Thu, 19 Feb 2009 07:10:35 -0500 Subject: SVN/CVS and Branching In-Reply-To: References: <8496caf30902181444s5deb203ye0ff5654743999f5@mail.gmail.com> Message-ID: <8496caf30902190410y3e4d5edcgba846704cab87d13@mail.gmail.com> Fair enough. Say my project is called foo, and it has many submodules. So there are imports that may look like `import foo.bar` or `from foo.bar import baz`, if i change the top level directory, it is no longer foo and then those imports do not work as originally written. The way i currently do this is to create a branch, say foo2, and create a symbolic link named foo pointing at foo2, after renaming foo, when i want to work on the branch and remove the link when i want to work on the head. This actually works fine, but thought there may be a better way. Jeff On Wed, Feb 18, 2009 at 7:40 PM, andrew cooke wrote: > > maybe this is just me, but i don't have a clue what your problem is. what > does "starting imports all over the place" mean? what do you mean by > "retired"? > > i use svn with python in exactly the same way as with java (and, i > thought, in the same way as anyone uses svn with any language; java uses > the directory structure as a package structure too). > > maybe someone else will reply, but if not it might help to explain a > little more detail. > > andrew > > > Jeff Dyke wrote: >> Hello. I am curious about different ideas on how you handle branching >> your python projects. With some other languages this is trivial, but >> since python uses these directories as modules and i have the top >> level module starting imports all over the place, i am wondering what >> others do. In the past we had retired the first branch and just moved >> towards the new, but that is not possible now. > > > -- > http://mail.python.org/mailman/listinfo/python-list > From andrew at acooke.org Thu Feb 19 07:20:05 2009 From: andrew at acooke.org (andrew cooke) Date: Thu, 19 Feb 2009 09:20:05 -0300 (CLST) Subject: SVN/CVS and Branching In-Reply-To: <8496caf30902190410y3e4d5edcgba846704cab87d13@mail.gmail.com> References: <8496caf30902181444s5deb203ye0ff5654743999f5@mail.gmail.com> <8496caf30902190410y3e4d5edcgba846704cab87d13@mail.gmail.com> Message-ID: Ah, OK. I have never worked like that. The only helpful comment I can think of is that I believe svn will store links correctly (while CVS doesn't). However, I do find the whole approach a bit odd. You seem to be doing your own versioning "by hand" (having two packages that are equivalent with different names), where I would leave that to SVN/CVS. So what I would do, and what seems to me a more natural way to use version control, is to branch the entire project (the whole tree), leave the foo module name the same, and work on two separate projects. If changes (ie on modules other than foo) need to be made to both projects I would use svnmerge to make sure that merges made to one also apply to the other. But if that is a common situation then it suggests the other modules might be better treated as a separate library, with their own project. On the other hand, svnmerge is a bit of a pain and I can see how your approach might make more sense (particularly on smaller projects). Andrew Jeff Dyke wrote: > Fair enough. Say my project is called foo, and it has many > submodules. So there are imports that may look like `import foo.bar` > or `from foo.bar import baz`, if i change the top level directory, it > is no longer foo and then those imports do not work as originally > written. The way i currently do this is to create a branch, say > foo2, and create a symbolic link named foo pointing at foo2, after > renaming foo, when i want to work on the branch and remove the link > when i want to work on the head. This actually works fine, but > thought there may be a better way. > > Jeff > > On Wed, Feb 18, 2009 at 7:40 PM, andrew cooke wrote: >> >> maybe this is just me, but i don't have a clue what your problem is. >> what >> does "starting imports all over the place" mean? what do you mean by >> "retired"? >> >> i use svn with python in exactly the same way as with java (and, i >> thought, in the same way as anyone uses svn with any language; java uses >> the directory structure as a package structure too). >> >> maybe someone else will reply, but if not it might help to explain a >> little more detail. >> >> andrew >> >> >> Jeff Dyke wrote: >>> Hello. I am curious about different ideas on how you handle branching >>> your python projects. With some other languages this is trivial, but >>> since python uses these directories as modules and i have the top >>> level module starting imports all over the place, i am wondering what >>> others do. In the past we had retired the first branch and just moved >>> towards the new, but that is not possible now. >> >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > -- > http://mail.python.org/mailman/listinfo/python-list > > From google at mrabarnett.plus.com Thu Feb 19 07:39:42 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 19 Feb 2009 12:39:42 +0000 Subject: Pythonic way to determine if one char of many in a string In-Reply-To: <_uydneN7BuEGkwDUnZ2dnUVZ_tudnZ2d@earthlink.com> References: <1234761457.20683.1300568627@webmail.messagingengine.com> <01aa9ea5$0$20632$c3e8da3@news.astraweb.com> <8e63a5ce0902181144q6e5405a2y9b393a34cf4d7d58@mail.gmail.com> <_uydneN7BuEGkwDUnZ2dnUVZ_tudnZ2d@earthlink.com> Message-ID: <499D530E.4090702@mrabarnett.plus.com> Dennis Lee Bieber wrote: > On Wed, 18 Feb 2009 21:22:45 +0100, Peter Otten <__peter__ at web.de> > declaimed the following in comp.lang.python: > >> Steve Holden wrote: >> >>> Jervis Whitley wrote: >>>>> What happens when you have hundreds of megabytes, I don't know. >>>>> >>>>> >>>> I hope I never have to test a word that is hundreds of megabytes long >>>> for a vowel :) >>> I see you don't speak German ;-) >> I tried to come up with a funny way to point out that you're a fool. >> >> But because I'm German I failed. >> > Yeah... the proper language to bemoan is Welsh > > Where "w" is vowel > So is "y", but then it is in English too, sometimes. From johnforse at talktalk.net Thu Feb 19 07:46:52 2009 From: johnforse at talktalk.net (John Forse) Date: Thu, 19 Feb 2009 12:46:52 +0000 Subject: string to list conversion Message-ID: I need to convert an input string say 'xxxx' to a list of the form ['xxxx' ,]. If I use list(stringname), I get ['x','x','x','x'] ; list.join() is an error; and str.join() won't use lists. I do need the comma after the string. Is there a simple solution? Regards John From urbangabo at gmail.com Thu Feb 19 07:50:23 2009 From: urbangabo at gmail.com (Gabor Urban) Date: Thu, 19 Feb 2009 13:50:23 +0100 Subject: Porting to new Python version Message-ID: Hi, I have a tough issue: we are using a Python application written quite a time ago for version 2.4. The code is mature, and there are no bugs. My bosses came up with the idea to port it to the latest release... I am not really convinced that it's a good step. I wellcome any information pro and contra. I would like to get the background as precisely as possible. Thanks in advance and good day to You! Gabor From xng at xs4all.nl Thu Feb 19 07:50:57 2009 From: xng at xs4all.nl (Martin P. Hellwig) Date: Thu, 19 Feb 2009 12:50:57 +0000 Subject: Pythonic way to determine if one char of many in a string In-Reply-To: References: <1234761457.20683.1300568627@webmail.messagingengine.com> <01aa9ea5$0$20632$c3e8da3@news.astraweb.com> <8e63a5ce0902181144q6e5405a2y9b393a34cf4d7d58@mail.gmail.com> <_uydneN7BuEGkwDUnZ2dnUVZ_tudnZ2d@earthlink.com> Message-ID: <499d55b1$0$188$e4fe514c@news.xs4all.nl> MRAB wrote: > Dennis Lee Bieber wrote: >> On Wed, 18 Feb 2009 21:22:45 +0100, Peter Otten <__peter__ at web.de> >> declaimed the following in comp.lang.python: >> >>> Steve Holden wrote: >>> >>>> Jervis Whitley wrote: >>>>>> What happens when you have hundreds of megabytes, I don't know. >>>>>> >>>>>> >>>>> I hope I never have to test a word that is hundreds of megabytes long >>>>> for a vowel :) >>>> I see you don't speak German ;-) >>> I tried to come up with a funny way to point out that you're a fool. >>> >>> But because I'm German I failed. >>> >> Yeah... the proper language to bemoan is Welsh >> Where "w" is vowel >> > So is "y", but then it is in English too, sometimes. Heh, born and raised in Germany, moved to the Netherlands and now live in the UK, speak a bit of French too. No wonder the only language that makes actually sense to me is Python. -- mph From KGeraghty at 360i.com Thu Feb 19 07:55:37 2009 From: KGeraghty at 360i.com (Kevin Geraghty) Date: Thu, 19 Feb 2009 07:55:37 -0500 Subject: Creating a request for ZSI Message-ID: Folks, I am trying to access a WSDL and I used wsdl2py to create the needed files. My problem is that when I try to create a request object I get a request Holder object instead. >>> get_rates_by_profile_name=ns0.get_rates_by_profile_name_Dec().pyclass >>> req=get_rates_by_profile_name() >>> req._username = username >>> req._org_id = org_id >>> req._profile_name = profile_name >>> req When I try to get a response the isinstance() test rejects the request holder object as being of the wrong type. >>> resp = portType.get_rates_by_profile_name(req) Traceback (most recent call last): File "", line 1, in ? File "HotelWebService_services.py", line 487, in get_rates_by_profile_name raise TypeError, "%s incorrect request type" % (request.__class__) TypeError: incorrect request type How do I get a req object that ZSI will let me use to get a response? Thanks Kevin -------------- next part -------------- An HTML attachment was scrubbed... URL: From dstanek at dstanek.com Thu Feb 19 07:57:37 2009 From: dstanek at dstanek.com (David Stanek) Date: Thu, 19 Feb 2009 07:57:37 -0500 Subject: SVN/CVS and Branching In-Reply-To: <8496caf30902190410y3e4d5edcgba846704cab87d13@mail.gmail.com> References: <8496caf30902181444s5deb203ye0ff5654743999f5@mail.gmail.com> <8496caf30902190410y3e4d5edcgba846704cab87d13@mail.gmail.com> Message-ID: On Thu, Feb 19, 2009 at 7:10 AM, Jeff Dyke wrote: > Fair enough. Say my project is called foo, and it has many > submodules. So there are imports that may look like `import foo.bar` > or `from foo.bar import baz`, if i change the top level directory, it > is no longer foo and then those imports do not work as originally > written. The way i currently do this is to create a branch, say > foo2, and create a symbolic link named foo pointing at foo2, after > renaming foo, when i want to work on the branch and remove the link > when i want to work on the head. This actually works fine, but > thought there may be a better way. > > Jeff > I think that your project structure is faulty. In Subversion I do something like: * FooProject/trunk/foo * FooProject/branches/TRY-foo2 TRY-foo2 is an svn cp of trunk so checking out TRY-foo2 gives you a TRY-foo2 directory containing a foo package. My DVCS projects go essentially the same thing. -- David http://www.traceback.org From oliverpeng at gmail.com Thu Feb 19 07:57:46 2009 From: oliverpeng at gmail.com (O Peng) Date: Thu, 19 Feb 2009 04:57:46 -0800 (PST) Subject: urllib2 httplib.BadStatusLine exception while opening a page on an Oracle HTTP Server References: <728a06bb-2faa-4a61-b988-ff3d9809aa28@w39g2000prb.googlegroups.com> Message-ID: <54eb2670-6636-41a4-9a6a-d2ba7b3fa158@m29g2000prd.googlegroups.com> I'm running into a similar problem with the BadStatusLine. The source code for httplib.py in the problem is as follows: class HTTPResponse: ... def _read_status(self): line = self.fp.readline() ... if not line: # Presumably, the server closed the connection before # sending a valid response. raise BadStatusLine(line) However, I found that right before the 'raise BadStatusLine(line)' when I ran the following: restOfResponse = self.fp.read() print restOfResponse restOfResponse is NOT empty. In fact, when I run self.fp.read() at the beginning of the begin() function, it is not empty at all. This leads me to believe there is a bug with the self.fp.readline() (socket._fileobject.readline()) function. For me it only fails sometimes. This behavior is only observed on Windows, Python 2.5. Running it on Mac OS X, Python 2.5 yielded no problems. On Jan 19, 3:48?pm, ak wrote: > On Jan 19, 10:00?pm, ak wrote: > > > > > Hi everyone, > > > I have a problem with urllib2 on this particular url, hosted on an > > Oracle HTTP Server > > >http://www.orange.sk/eshop/sk/portal/catalog.html?type=post&subtype=p... > > > which gets 302 redirected tohttps://www.orange.sk/eshop/sk/catalog/post/phones.html, > > after setting a cookie through the Set-Cookie header field in the 302 > > reply. This works fin with firefox. > > > However, with urllib2 and the following code snippet, it doesn't work > > > -------- > > import cookiejar > > import urllib2 > > > cookiejar = cookielib.LWPCookieJar() > > opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar)) > > url = 'http://www.orange.sk/eshop/sk/portal/catalog.html? > > type=post&subtype=phone&null' > > req = urllib2.Request(url, None) > > s=opener.open(req) > > -------- > > > Traceback (most recent call last): > > ? File "", line 1, in > > ? File "/usr/lib/python2.5/urllib2.py", line 387, in open > > ? ? response = meth(req, response) > > ? File "/usr/lib/python2.5/urllib2.py", line 498, in http_response > > ? ? 'http', request, response, code, msg, hdrs) > > ? File "/usr/lib/python2.5/urllib2.py", line 419, in error > > ? ? result = self._call_chain(*args) > > ? File "/usr/lib/python2.5/urllib2.py", line 360, in _call_chain > > ? ? result = func(*args) > > ? File "/usr/lib/python2.5/urllib2.py", line 582, in http_error_302 > > ? ? return self.parent.open(new) > > ? File "/usr/lib/python2.5/urllib2.py", line 381, in open > > ? ? response = self._open(req, data) > > ? File "/usr/lib/python2.5/urllib2.py", line 399, in _open > > ? ? '_open', req) > > ? File "/usr/lib/python2.5/urllib2.py", line 360, in _call_chain > > ? ? result = func(*args) > > ? File "/usr/lib/python2.5/urllib2.py", line 1115, in https_open > > ? ? return self.do_open(httplib.HTTPSConnection, req) > > ? File "/usr/lib/python2.5/urllib2.py", line 1080, in do_open > > ? ? r = h.getresponse() > > ? File "/usr/lib/python2.5/httplib.py", line 928, in getresponse > > ? ? response.begin() > > ? File "/usr/lib/python2.5/httplib.py", line 385, in begin > > ? ? version, status, reason = self._read_status() > > ? File "/usr/lib/python2.5/httplib.py", line 349, in _read_status > > ? ? raise BadStatusLine(line) > > httplib.BadStatusLine > > > Trying the redirected url directly doesn't work either (trying with > > Firefox will give an HTML error page, as the cookie is not set yet, > > but trying with urllib2 gives the same exception as previously, > > whereas it should return the HTML error page) > > This works correctly on other urls on this website (http(s)://www.orange.sk). > > > Am I doing anything wrong or is this a bug in urllib2 ? > > > -- ak > > Actually, I was wrong on the last point, this does *not* work onhttps://www.orange.sk(but does onhttp://www.orange.sk). IMHO, this > means either urllib2 or the server misimplemented HTTPS. > > Here's some output with debuglevel=1 : > > >>> opener.open(urllib2.Request('http://www.orange.sk/', None, headers)) > > reply: 'HTTP/1.1 200 OK\r\n' > header: Date: Mon, 19 Jan 2009 21:44:03 GMT > header: Server: Oracle-Application-Server-10g/10.1.3.1.0 Oracle-HTTP- > Server > header: Set-Cookie: > JSESSIONID=0a19055a30d630c427bda71d4e26a37ca604b9f590dc.e3eNaNiRah4Pe3aSch8 Sc3yOc40; > path=/web > header: Expires: Mon, 19 Jan 2009 21:44:13 GMT > header: Surrogate-Control: max-age="10" > header: Content-Type: text/html; charset=ISO-8859-2 > header: X-Cache: MISS fromwww.orange.sk > header: Connection: close > header: Transfer-Encoding: chunked > 0x831348c>> > > >>> opener.open(urllib2.Request('https://www.orange.sk/', None, headers)) > > reply: '' > Traceback (most recent call last): > ? File "", line 1, in > ? File "/usr/lib/python2.5/urllib2.py", line 381, in open > ? ? response = self._open(req, data) > ? File "/usr/lib/python2.5/urllib2.py", line 399, in _open > ? ? '_open', req) > ? File "/usr/lib/python2.5/urllib2.py", line 360, in _call_chain > ? ? result = func(*args) > ? File "/usr/lib/python2.5/urllib2.py", line 1115, in https_open > ? ? return self.do_open(httplib.HTTPSConnection, req) > ? File "/usr/lib/python2.5/urllib2.py", line 1080, in do_open > ? ? r = h.getresponse() > ? File "/usr/lib/python2.5/httplib.py", line 928, in getresponse > ? ? response.begin() > ? File "/usr/lib/python2.5/httplib.py", line 385, in begin > ? ? version, status, reason = self._read_status() > ? File "/usr/lib/python2.5/httplib.py", line 349, in _read_status > ? ? raise BadStatusLine(line) > httplib.BadStatusLine > > As you can see the reply from the server seems empty (which results in > the BadStatusLine exception) > > Any help greatly appreciated. > > -- ak From steve at holdenweb.com Thu Feb 19 07:57:59 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 19 Feb 2009 07:57:59 -0500 Subject: Will multithreading make python less popular? In-Reply-To: <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <28e3612d-2e91-4a91-82cb-5fb2deda95fd@q9g2000yqc.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> Message-ID: rushenaly at gmail.com wrote: > Thank you for all your answers... > > I think i am going to pick Java instead of Python... > Well, good luck. See what a helpful bunch of people you meet in the Python world? Glad you found all the advice helpful. Come back when you want to try Python! regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From Ron.Barak at lsi.com Thu Feb 19 08:01:07 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Thu, 19 Feb 2009 13:01:07 +0000 Subject: "metaclass conflict" error: where is noconflict ? In-Reply-To: References: Message-ID: <7F0503CD69378F49BE0DC30661C6CCF60E68800F@enbmail01.lsi.com> Hi, I have a class derived from two parents (in blue below), which gives me the following error: $ python -u ./failover_pickle_demo09.py Traceback (most recent call last): File "./failover_pickle_demo09.py", line 291, in class ListControl(wx.Frame, CopyAndPaste): TypeError: Error when calling the metaclass bases metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases Googling suggested I should add from noconflict import classmaker and __metaclass__=classmaker() to this class. However, I don't seem able to find where to get the noconflict module from. Do any of you where noconflict could be downloaded/installed from ? Thanks, Ron. P.S.: I use Windows XP/cygwin, Python 2.5.2, wx-2.8-msw-unicode -------------- next part -------------- An HTML attachment was scrubbed... URL: From Srinivas.Irigi at adaptit.co.za Thu Feb 19 08:03:51 2009 From: Srinivas.Irigi at adaptit.co.za (Srinivas) Date: Thu, 19 Feb 2009 15:03:51 +0200 Subject: string to list conversion In-Reply-To: References: Message-ID: <200902191503.51851.Srinivas.Irigi@adaptit.co.za> John, Try the following code .. hope this helps and solves your problem . I have run in the interactive mode >>> s='xxxx' >>> a=[s,'12'] >>> print a ['xxxx', '12'] regards Srinivas From jeff.dyke at gmail.com Thu Feb 19 08:05:00 2009 From: jeff.dyke at gmail.com (Jeff Dyke) Date: Thu, 19 Feb 2009 08:05:00 -0500 Subject: SVN/CVS and Branching In-Reply-To: References: <8496caf30902181444s5deb203ye0ff5654743999f5@mail.gmail.com> <8496caf30902190410y3e4d5edcgba846704cab87d13@mail.gmail.com> Message-ID: <8496caf30902190505i4ff0b990pe8ca5fa13491dce5@mail.gmail.com> On Thu, Feb 19, 2009 at 7:57 AM, David Stanek wrote: > On Thu, Feb 19, 2009 at 7:10 AM, Jeff Dyke wrote: >> Fair enough. Say my project is called foo, and it has many >> submodules. So there are imports that may look like `import foo.bar` >> or `from foo.bar import baz`, if i change the top level directory, it >> is no longer foo and then those imports do not work as originally >> written. The way i currently do this is to create a branch, say >> foo2, and create a symbolic link named foo pointing at foo2, after >> renaming foo, when i want to work on the branch and remove the link >> when i want to work on the head. This actually works fine, but >> thought there may be a better way. >> >> Jeff >> > > I think that your project structure is faulty. In Subversion I do > something like: > > * FooProject/trunk/foo > * FooProject/branches/TRY-foo2 > > TRY-foo2 is an svn cp of trunk so checking out TRY-foo2 gives you a > TRY-foo2 directory containing a foo package. My DVCS projects go > essentially the same thing. I think your correct. I picked up this habit from someone else and blindly kept going. Thanks to both you and Andrew for the comments. I think i'll work on making a switch. > > > -- > David > http://www.traceback.org > From n.kottiyath at gmail.com Thu Feb 19 08:05:39 2009 From: n.kottiyath at gmail.com (Kottiyath) Date: Thu, 19 Feb 2009 05:05:39 -0800 (PST) Subject: Porting to new Python version References: Message-ID: <67b23877-3292-4c99-83e5-244f29b76e58@k36g2000pri.googlegroups.com> On Feb 19, 5:50?pm, Gabor Urban wrote: > Hi, > > I have a tough issue: we are using a Python application written quite > a time ago for version 2.4. The code is mature, and there are no bugs. > ?My bosses came up with the idea to port it to the latest release... I > am not really convinced that it's a good step. > > I wellcome any information pro and contra. I would like to get the > background as precisely as possible. > > Thanks in advance and good day to You! > > Gabor It might be helpful if you can provide more information regarding your application. For example, does it use lot of 3rd party code, What is the reason behind porting to latest version etc. All said, 2.4 to 2.5 or even 2.6 should not be much of an issue - it even has the advantage that performance is improved and some memory leaks are no longer there. Python 3* should be a problem since many 3rd party applications are not yet ported to it. From steve at holdenweb.com Thu Feb 19 08:07:51 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 19 Feb 2009 08:07:51 -0500 Subject: string to list conversion In-Reply-To: References: Message-ID: John Forse wrote: > I need to convert an input string say 'xxxx' to a list of the form > ['xxxx' ,]. If I use list(stringname), I get ['x','x','x','x'] ; > list.join() is an error; and str.join() won't use lists. I do need the > comma after the string. Is there a simple solution? Suppose your input string is s. Just say s = [s] Bingo, s is now a list containing the input string as its only element. But I suspect that's not what you mean ... because you say "I do need the comma after the string". Do you mean that you want to produce a string containing "['xxxx', ]"? You might try s = "['%s', ]" % s But that's potentially going to give you problems if s contains either an apostrophe or a quote mark. It depends how you plan to use it. So what is it you want, exactly, and (if it's not asking too much) why? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From google at mrabarnett.plus.com Thu Feb 19 08:09:53 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 19 Feb 2009 13:09:53 +0000 Subject: string to list conversion In-Reply-To: References: Message-ID: <499D5A21.9000308@mrabarnett.plus.com> John Forse wrote: > I need to convert an input string say 'xxxx' to a list of the form > ['xxxx' ,]. If I use list(stringname), I get ['x','x','x','x'] ; > list.join() is an error; and str.join() won't use lists. I do need the > comma after the string. Is there a simple solution? > Have you tried [stringname], eg ['xxxx' ,]? :-) Why do you need the comma? Python permits it but it isn't necessary: >>> ['xxxx' ,] ['xxxx'] From steve at holdenweb.com Thu Feb 19 08:10:02 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 19 Feb 2009 08:10:02 -0500 Subject: Porting to new Python version In-Reply-To: References: Message-ID: Gabor Urban wrote: > Hi, > > I have a tough issue: we are using a Python application written quite > a time ago for version 2.4. The code is mature, and there are no bugs. > My bosses came up with the idea to port it to the latest release... I > am not really convinced that it's a good step. > > I wellcome any information pro and contra. I would like to get the > background as precisely as possible. > > Thanks in advance and good day to You! > As long as you don't plan to migrate to 3.0 you may well be surprised at how easy the port is. Python's backwards compatibility has been pretty good. Moving to 3.0 will demand more thought and testing. One might ask what the advantages are supposed to be, of course, but generally bosses aren't interested in explaining themselves ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From andrew at acooke.org Thu Feb 19 08:12:36 2009 From: andrew at acooke.org (andrew cooke) Date: Thu, 19 Feb 2009 10:12:36 -0300 (CLST) Subject: Porting to new Python version In-Reply-To: References: Message-ID: <0d42b340554c6ecbfa7fe6f487b8d92c.squirrel@localhost> i don't know what the context is, so it's hard for me to comment on the decision (i assume there are commerical pressures like customers not wanting to install old versions). however,if you go ahead, you need to think about exactly what you want to target. the latest version is really 3.0.1. moving to 3 is probably not that hard (and there are tools to automate the process). also, 2.6 is largely compatible with 3. so moving to something that works with 2.6 and 3 is probably a reasonable target. but that code will not work, without more significant effort, on 2.5 and earlier. so one idea would be to keep your existing code for 2.4, and update for 3. for some time (years) you will need to support two versions, but if it is stable then that may not be much work. alternatively, you could ignore 3, which is not going to be mainstream for some time, and simply run against 2.6 and 2.5. that should be even less work because you're staying with 2. you could then say that your code works on 2.4 through 2.6 or, finally, you could do the second step above (to get code that works on 2.4 to 2.6) and then the first step (to get a separate version that works on 3). doing things in that order (with staged releases) lets you get most bug fixes for 2.5/6 into the code before branching for 3. hope that makes sense. disclaimer - i have not done the above; this is from reading various newsgroups and attempting to backport a project written in 3 to 2 (it was easy to go to 2.6, but i failed to get the same code to run on 2.5). andrew Gabor Urban wrote: > Hi, > > I have a tough issue: we are using a Python application written quite > a time ago for version 2.4. The code is mature, and there are no bugs. > My bosses came up with the idea to port it to the latest release... I > am not really convinced that it's a good step. > > I wellcome any information pro and contra. I would like to get the > background as precisely as possible. > > Thanks in advance and good day to You! > > Gabor > -- > http://mail.python.org/mailman/listinfo/python-list > > From andrew at acooke.org Thu Feb 19 08:20:16 2009 From: andrew at acooke.org (andrew cooke) Date: Thu, 19 Feb 2009 10:20:16 -0300 (CLST) Subject: Porting to new Python version In-Reply-To: <0d42b340554c6ecbfa7fe6f487b8d92c.squirrel@localhost> References: <0d42b340554c6ecbfa7fe6f487b8d92c.squirrel@localhost> Message-ID: maybe i should clarify that "easy" below is going to be relative. the process may end up being very hard due to various other reasons. what i was trying to explain is that (1) 3 is probably going to require a separate branch from 2; (2) that 2.6 and 3 can both be considered "latest"; (3) moving from 2.4 to 2.6 is probably best done before branching for 3; (4) moving from 2.4 to 2.6 is probably easier than moving from 2 to 3. andrew andrew cooke wrote: > > i don't know what the context is, so it's hard for me to comment on the > decision (i assume there are commerical pressures like customers not > wanting to install old versions). > > however,if you go ahead, you need to think about exactly what you want to > target. > > the latest version is really 3.0.1. moving to 3 is probably not that hard > (and there are tools to automate the process). also, 2.6 is largely > compatible with 3. so moving to something that works with 2.6 and 3 is > probably a reasonable target. but that code will not work, without more > significant effort, on 2.5 and earlier. > > so one idea would be to keep your existing code for 2.4, and update for 3. > for some time (years) you will need to support two versions, but if it is > stable then that may not be much work. > > alternatively, you could ignore 3, which is not going to be mainstream for > some time, and simply run against 2.6 and 2.5. that should be even less > work because you're staying with 2. you could then say that your code > works on 2.4 through 2.6 > > or, finally, you could do the second step above (to get code that works on > 2.4 to 2.6) and then the first step (to get a separate version that works > on 3). doing things in that order (with staged releases) lets you get > most bug fixes for 2.5/6 into the code before branching for 3. > > hope that makes sense. > > disclaimer - i have not done the above; this is from reading various > newsgroups and attempting to backport a project written in 3 to 2 (it was > easy to go to 2.6, but i failed to get the same code to run on 2.5). > > andrew > > > > > > Gabor Urban wrote: >> Hi, >> >> I have a tough issue: we are using a Python application written quite >> a time ago for version 2.4. The code is mature, and there are no bugs. >> My bosses came up with the idea to port it to the latest release... I >> am not really convinced that it's a good step. >> >> I wellcome any information pro and contra. I would like to get the >> background as precisely as possible. >> >> Thanks in advance and good day to You! >> >> Gabor >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > > > -- > http://mail.python.org/mailman/listinfo/python-list > > From dikkie at nospam.org Thu Feb 19 08:30:53 2009 From: dikkie at nospam.org (Dikkie Dik) Date: Thu, 19 Feb 2009 14:30:53 +0100 Subject: Revision Control In-Reply-To: References: <822B0E83D23291469317E3432468743702224B@production.2000soft.com> Message-ID: <499d5f0e$0$444$bf4948fe@news.tele2.nl> Funny how everybody is speaking about the ease of merging. It is the very least feature I have ever needed from source code control. Most version control system are really brilliant in creating a version mess of intertwined branches, but off course I use version control to *PREVENT* such a mess. So I really would like better linking possibilities to other projects or standard libraries. That said: - MS-Source-Safe did a great job here. But I stopped using it after version 6.0. The linking feature of VSS was great, but the stability of VSS was awful. - CVS is a hell. Only administrators seem to be able to create a link. - Linking is subversion is not exactly user-friendly, but it "kinda" works. See http://www.howtoforge.org/set-up-a-modular-svn-repository-for-php-websites for how I managed to do so with PHP. I don't have a real Python library yet, but I would use it the same way. Also, the latest subversion should support relative links. - I have no experience with mercurial. - I searched through the documentation of git and bzr, and could not find much. If anyone has more info on linking with Mercurial, bzr or git, please share it! From lie.1296 at gmail.com Thu Feb 19 08:42:42 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Thu, 19 Feb 2009 13:42:42 +0000 (UTC) Subject: How to convert between Japanese coding systems? References: <1235024892.3981.56.camel@pippi.pippi> Message-ID: On Thu, 19 Feb 2009 15:28:12 +0900, Dietrich Bollmann wrote: > Hi, > > Are there any functions in python to convert between different Japanese > coding systems? If I'm not mistaken, the email standard specifies that only 7-bit ASCII- encoded bytes can be transported safely and reliably. The highest bit may be stripped by email server or client. Thus, to transport non-ASCII data safely, they cannot use "regular" encodings (e.g. utf-8, shift-jis, etc). I'm not sure what the standard is for Japanese character, but it seems that from reading the email header, the encoding used is a modified UTF-8. Try checking python's email module, they might have something for decoding 7-bit email-utf to 8-bit regular-utf or unicode string. After decoding the email-utf to regular-utf or unicode string, converting to other encoding should be trivial. From Scott.Daniels at Acm.Org Thu Feb 19 09:10:54 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 19 Feb 2009 06:10:54 -0800 Subject: Revision Control In-Reply-To: <499d5f0e$0$444$bf4948fe@news.tele2.nl> References: <822B0E83D23291469317E3432468743702224B@production.2000soft.com> <499d5f0e$0$444$bf4948fe@news.tele2.nl> Message-ID: Dikkie Dik wrote: > Funny how everybody is speaking about the ease of merging. It is the > very least feature I have ever needed from source code control.... Ah yes, but with a distributed VCS, merging becomes _much_ more common. The model is developers pull, develop (checking in frequently), and merge back. Most checkins to the central repository _are_ merges. That is why everyone talks about merge speed. --Scott David Daniels Scott.Daniels at Acm.Org From mrkafk at gmail.com Thu Feb 19 09:21:14 2009 From: mrkafk at gmail.com (mk) Date: Thu, 19 Feb 2009 15:21:14 +0100 Subject: CSV readers and UTF-8 files Message-ID: Hello everyone, Is it just me or CSV reader/DictReader and UTF-8 files do not work correctly in Python 2.6.1 (Windows)? That is, when I open UTF-8 file in a csv reader (after passing plain file object), I get fields as plain strings ('str'). Since this has been mangled, I can't get the non-ascii characters back. When I do: csvfo = codecs.open(csvfname, 'rb', 'utf-8') dl = csv.excel dl.delimiter=';' #rd = csv.DictReader(csvfo, dialect=dl) rd = csv.reader(csvfo, dialect=dl) ..I get plain strings as well (I get when calling type(field)), on top of error: Traceback (most recent call last): File "C:/Python26/converter3.py", line 99, in fill_sqla(session,columnlist,rd) File "C:/Python26/converter3.py", line 73, in fill_sqla for row in rd: UnicodeEncodeError: 'ascii' codec can't encode character u'\u0144' in position 74: ordinal not in range(128) ..when doing: for row in rd: ... Regards, mk From notvalid2 at sbcglobal.net Thu Feb 19 09:22:21 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Thu, 19 Feb 2009 06:22:21 -0800 Subject: Which Version of wxPython for Win XP Message-ID: I'm going to try out wxPython 2.8.92 for py25. It seems like the ansi version is the choice for me. The other choice has unicode. Do I care? -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From python.list at tim.thechases.com Thu Feb 19 09:28:53 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 19 Feb 2009 08:28:53 -0600 Subject: Revision Control In-Reply-To: <499CED12.3040802@mattnordhoff.com> References: <822B0E83D23291469317E3432468743702224B@production.2000soft.com> <499C5521.2040705@tim.thechases.com> <499CED12.3040802@mattnordhoff.com> Message-ID: <499D6CA5.3000802@tim.thechases.com> > FWIW, Bazaar and Mercurial both have about half a dozen C modules. (Most > of Bazaar's are Pyrex, though, not straight C.) Thanks for the update -- it's been about 6 months since I played much with Bazaar. Hopefully these C module help with some of the speed issues that plagued bzr in my past experimentations. > The next release of Mercurial will add support for running without them. > (Bazaar already supports that, of course.) Wonderful to hear...I'd love to be able to install mercurial on my web-host's machine, but it's currently not readily possible. A pure-python implementation (or at least fallback) will give me this option. Thanks! -tkc From michele.simionato at gmail.com Thu Feb 19 09:32:04 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Thu, 19 Feb 2009 06:32:04 -0800 (PST) Subject: Porting to new Python version References: Message-ID: <72aa7a5e-195d-45c1-923f-30a2b049f45b@n30g2000vba.googlegroups.com> On Feb 19, 1:50?pm, Gabor Urban wrote: > Hi, > > I have a tough issue: we are using a Python application written quite > a time ago for version 2.4. The code is mature, and there are no bugs. > ?My bosses came up with the idea to port it to the latest release... I > am not really convinced that it's a good step. > > I wellcome any information pro and contra. I would like to get the > background as precisely as possible. > > Thanks in advance and good day to You! > > Gabor I am a fan of smooth upgrades. Just move to Python 2.5 and you should have little troubles. You can wait one year or so for Python 2.6. As a rule of thumb, I think it is safe to upgrade to a newer Python versions after one year from its first release, to give time to third party packages. There are of course exceptions. For instance I remember Zope being far behind Python releases. I have currently a Zope application running in Python 2.4 that I cannot upgrade. It all depends from your external dependencies. If you do not have any, and you do not anticipate the need for any, you can probably upgrade to Python 2.6 with no effort. Michele Simionato From claird at lairds.us Thu Feb 19 09:33:02 2009 From: claird at lairds.us (Cameron Laird) Date: Thu, 19 Feb 2009 14:33:02 +0000 Subject: can multi-core improve single funciton? References: <39uq66-b7j.ln1@lairds.us> Message-ID: In article , Steven D'Aprano wrote: >> . >> . >> . >>>> And now for my version (which admitedly isn't really mine, and returns >>>> slightly incorrect fib(n) for large values of n, due to the limited >>>> floating point precision). >>> >>>The floating point version is nice, but it starts giving incorrect >>>answers relatively early, from n=71. But if you don't need accurate >>>results (a relative error of 3e-15 for n=71), it is very fast. >> . >> . >> . >> While my personal opinion is that it's silly to characterize an error of >> 3e-15 as not "accurate", > >That's a *relative* error. The absolute error is 1 for n=71, 59 for n=80, >1196093 for n=100, and 1875662300654090482610609259 for n=200. As far as >I can tell, the absolute error grows without bounds as n increases -- and >it overflows at n=1475. > >I agree that a relative error is small, and if your use allows it, then >by all means use the inexact floating point function. But if you need >exact results, then you won't get it using floats. > > > >> I think more constructive is to focus on the >> fact that the closed-form solution can be touched up to give a precise >> integral solution, while re- taining its (approximately) O(log n) >> run-time cost. > >I doubt that. Since both phi and sqrt(5) are irrational numbers, it would >require an infinite number of integer digits to get precise integral >solutions unless there was some sort of freakish cancellation. But you >probably could get a very good integral solution which gives exact >results up to whatever limit you wanted, bound only by the amount of >memory and time you were willing to spend. . . . There *is* freakish cancellation. I entirely recognize that Python builds in floating-point calculations of limited precision. The closed-form expres- sion for Fibonacci, though, is exact, and can be coded in terms of, for example, Python infinite-precision integers. If there's sufficient interest, I'll cheerfully do so, al- though only after meeting my own deadlines for February for commitments outside comp.lang.python. From fabiofz at gmail.com Thu Feb 19 09:38:45 2009 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Thu, 19 Feb 2009 11:38:45 -0300 Subject: Why deepcopy with class with __getattr__ makes the tracing go nuts? Message-ID: Anyone has any idea why the code attached does not work? Basically, after doing the deepcopy of the class that has __getattr__ overridden, the python tracing facilities don't seem to work anymore. In the code-attached, if the deepcopy is removed, all works as expected (or if __deepcopy__ is overridden too). Thanks, Fabio p.s. I've discovered this while trying to debug a real-world application and the debugger stopped working after making that deepcopy. -------------- next part -------------- A non-text attachment was scrubbed... Name: fast_tests2.py Type: application/octet-stream Size: 877 bytes Desc: not available URL: From roy at panix.com Thu Feb 19 09:57:05 2009 From: roy at panix.com (Roy Smith) Date: Thu, 19 Feb 2009 09:57:05 -0500 Subject: Revision Control References: <822B0E83D23291469317E3432468743702224B@production.2000soft.com> <499d5f0e$0$444$bf4948fe@news.tele2.nl> Message-ID: In article <499d5f0e$0$444$bf4948fe at news.tele2.nl>, Dikkie Dik wrote: > Funny how everybody is speaking about the ease of merging. It is the > very least feature I have ever needed from source code control. It depends on what you're doing. In a big commercial project, sometimes you don't have the luxury of just continuing to work on the latest. You have to maintain multiple branches. When big customers refuse to upgrade, you're stuck with maintaining old stuff, and then good merge tools become essential. From alan.isaac at gmail.com Thu Feb 19 10:20:25 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Thu, 19 Feb 2009 15:20:25 GMT Subject: block dynamic attribute creation In-Reply-To: References: <5didnW_7dfWlDQHUnZ2dnUVZ_q_inZ2d@rcn.net> Message-ID: >> if hasattr(self, attr): #update val >> self.__dict__[attr] = val On 2/19/2009 3:54 AM Gabriel Genellina apparently wrote: > In particular, your code prevents using class attributes as a default > value for instance attributes Doesn't the above allow that? Thanks, Alan From james at agentultra.com Thu Feb 19 10:28:52 2009 From: james at agentultra.com (J Kenneth King) Date: Thu, 19 Feb 2009 07:28:52 -0800 Subject: Musings: Using decorators to reduce duplicate exception handling References: Message-ID: <87zlgitphn.fsf@agentultra.com> Cameron Simpson writes: > On 17Feb2009 15:12, J Kenneth King wrote: > | I recently started a project called TracShell > | (http://code.google.com/p/tracshell) where I make heavy use of the > | xmlrpclib core module. > | > | When the number of RPC calls was small, wrapping each call in try/except > | was acceptable. [...] > | To combat the duplication, my clever idea was to use a function > | decorator to wrap any function that used xmlrpclib calls: > | def catch_errors(fn): > [...] > | Maybe I could rename the decorator to something meaningful, but besides > | that it works pretty well. Now any function I write in my class that > | uses RPC calls can be wrapped by this decorator and have the exception > | handling done in a uniform way for these particular exceptions. > > My Python fu is still weak, but I had a similar issue last year and > wrote a context manager, used thus: > > with NoExceptions(handler): > ... do stuff that may break ... > > The constructor takes a handleException argument (which may be None, but it > has to be explicit) to tune which exceptions are caught; default is > everything. This was for a daemon thread that did RPC calls, so it was > actually fairly important to never die; normally you'd want to catch only > specific exceptions. > > Code: > > class NoExceptions(object): > ''' A context manager to catch _all_ exceptions and log them. > Arguably this should be a bare try...except but that's syntacticly > noisy and separates the catch from the top. > ''' > > def __init__(self, handleException): > ''' Initialise the NoExceptions context manager. > The handleException is a callable which > expects (exc_type, exc_value, traceback) > and returns True or False for the __exit__ > method of the manager. > If handleException is None, the __exit__ method > always returns True, suppressing any exception. > ''' > self.__handler = handleException > > def __enter__(self): > pass > > def __exit__(self, exc_type, exc_value, traceback): > if self.__handler is not None: > return self.__handler(exc_type, exc_value, traceback) > if exc_type is not None: > print >>sys.stderr, "ignore %s" % (exc_type,) > return True > > It doesn't actually solve your duplication issue and is a bit of a niche > application, but it's a lot shorter than an inline try/except and to my eye > reads a little better, and it keeps the exception handling up front at the > calling end where it is visible. > > Cheers, Ah, that's pretty interesting. I've found a couple other decorator-style recipes in the cookbooks online (http://code.activestate.com/recipes/408937/). I think you see my point: every single RPC call needs to be caught just in case because they are so volatile -- yet you're always looking for the exact same exception everywhere... too noisy to have inline try/except. I wonder if there are other use cases where Python developers have found the need to abstract away repetitive exception handling. I think this is the first I've seen the newer Python context managers being used (though it sneakily looks a lot like what Lisp calls, "unwind-protect"). Neat idea. From rushenaly at gmail.com Thu Feb 19 10:39:01 2009 From: rushenaly at gmail.com (rushenaly at gmail.com) Date: Thu, 19 Feb 2009 07:39:01 -0800 (PST) Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <28e3612d-2e91-4a91-82cb-5fb2deda95fd@q9g2000yqc.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> Message-ID: <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> Thank you Steve, I really wanted to learn python, but as i said i don't want to make a dead investment. I hope someone can fix these design errors and maybe can write an interpreter in python :) Thank you so much great community... Rushen From __peter__ at web.de Thu Feb 19 10:39:42 2009 From: __peter__ at web.de (Peter Otten) Date: Thu, 19 Feb 2009 16:39:42 +0100 Subject: Why deepcopy with class with __getattr__ makes the tracing go nuts? References: Message-ID: Fabio Zadrozny wrote: > Anyone has any idea why the code attached does not work? > > Basically, after doing the deepcopy of the class that has __getattr__ > overridden, the python tracing facilities don't seem to work anymore. > > In the code-attached, if the deepcopy is removed, all works as > expected (or if __deepcopy__ is overridden too). > > Thanks, > > Fabio > > p.s. I've discovered this while trying to debug a real-world > application and the debugger stopped working after making that > deepcopy. The problem seems to be a recursion error that implicitly switches off tracing: $ cat trace_test.py import sys def blowup(): blowup() def f(): print "f called" def trace(frame, event, arg): try: if frame.f_code.co_name == 'f': print "f seen", event finally: return trace sys.settrace(trace) if "-b" in sys.argv: try: blowup() except: pass f() $ python trace_test.py f seen call f seen line f called f seen return $ python trace_test.py -b f called deepcopy() probably triggers such a recursion by accessing the type_name attribute on a CppType instance with an empty __dict__. You can fix that with def __getattr__(self, attr): if attr == 'type_name': return super(CppType, self).__getattr__(attr) # ... I don't know why the exception is caught silently, nor how to make tracing survive the stack overflow. Peter From digitig at gmail.com Thu Feb 19 10:59:36 2009 From: digitig at gmail.com (Tim Rowe) Date: Thu, 19 Feb 2009 15:59:36 +0000 Subject: Will multithreading make python less popular? In-Reply-To: <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <28e3612d-2e91-4a91-82cb-5fb2deda95fd@q9g2000yqc.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> Message-ID: 2009/2/19 : > Thank you Steve, > > I really wanted to learn python, but as i said i don't want to make a > dead investment. I hope someone can fix these design errors and maybe > can write an interpreter in python :) Good luck with Java, and with your search for a perfect language. I think it will be a long search. -- Tim Rowe From Eric_Dexter at msn.com Thu Feb 19 11:03:13 2009 From: Eric_Dexter at msn.com (Eric_Dexter at msn.com) Date: Thu, 19 Feb 2009 08:03:13 -0800 (PST) Subject: Which Version of wxPython for Win XP References: Message-ID: On Feb 19, 8:22?am, "W. eWatson" wrote: > I'm going to try out wxPython 2.8.92 for py25. It seems like the ansi > version is the choice for me. The other choice has unicode. Do I care? > -- > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? W. eWatson > > ? ? ? ? ? ? ? (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) > ? ? ? ? ? ? ? ?Obz Site: ?39? 15' 7" N, 121? 2' 32" W, 2700 feet > > ? ? ? ? ? ? ? ? ? ? ?Web Page: There is a good chance you don't care... I think the other is for internationalization... best to look.. It would be easier to answer the question if you said what you are going to do with it, and who needed to use your software. It's even possible that you might want to try pygame depending on what you want to use it for and who the audience is (and how good thier computers are) http://pypi.python.org/simple/Dex%20Tracker/ From lists at cheimes.de Thu Feb 19 11:08:32 2009 From: lists at cheimes.de (Christian Heimes) Date: Thu, 19 Feb 2009 17:08:32 +0100 Subject: Will multithreading make python less popular? In-Reply-To: <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <28e3612d-2e91-4a91-82cb-5fb2deda95fd@q9g2000yqc.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> Message-ID: rushenaly at gmail.com schrieb: > Thank you Steve, > > I really wanted to learn python, but as i said i don't want to make a > dead investment. I hope someone can fix these design errors and maybe > can write an interpreter in python :) Good luck with Java! You have just traded one "design flaw" for another, more fatal design error. Please read this paper from a Berkely professor for CS why people think that threads are evil and not the right solution for concurrency on multi core systems. http://www.eecs.berkeley.edu/Pubs/TechRpts/2006/EECS-2006-1.pdf Quote: [...] non-trivial multi-threaded programs are incomprehensible for humans. HTH Christian From rushenaly at gmail.com Thu Feb 19 11:10:56 2009 From: rushenaly at gmail.com (rushenaly at gmail.com) Date: Thu, 19 Feb 2009 08:10:56 -0800 (PST) Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <28e3612d-2e91-4a91-82cb-5fb2deda95fd@q9g2000yqc.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> Message-ID: Thank you Tim... It is not a search for perfect language. It is a search for a capable language to modern worlds' needs. Rushen From garrickp at gmail.com Thu Feb 19 11:11:16 2009 From: garrickp at gmail.com (Falcolas) Date: Thu, 19 Feb 2009 08:11:16 -0800 (PST) Subject: CSV readers and UTF-8 files References: Message-ID: <59de6aff-ed5f-40ca-8900-f8da908f7578@u39g2000prn.googlegroups.com> On Feb 19, 7:21?am, mk wrote: > Hello everyone, > > Is it just me or CSV reader/DictReader and UTF-8 files do not work > correctly in Python 2.6.1 (Windows)? I would point out in the CSV module documentation (http:// docs.python.org/library/csv.html) it explicitly mentions that it can't handle unicode. You can use their workaround in the examples section for UTF-8, or with another form of encoding (I used MIME) for UTF-16. ~G From Eric_Dexter at netzero.net Thu Feb 19 11:13:39 2009 From: Eric_Dexter at netzero.net (Eric_Dexter at netzero.net) Date: Thu, 19 Feb 2009 08:13:39 -0800 (PST) Subject: PyGTK install References: <5e6ed314-3625-4a1a-b357-b27aabeb2f52@q30g2000prq.googlegroups.com> <8ff4616a-ef10-4b57-937b-71402d97942d@z28g2000prd.googlegroups.com> <1198ef28-b2c0-4464-85ad-31798dc0c33f@r15g2000prh.googlegroups.com> Message-ID: On Feb 18, 5:12?pm, Lionel wrote: > On Feb 18, 3:03?pm, Lionel wrote: > > > > > > > On Feb 18, 2:08?pm, Lionel wrote: > > > > On Feb 18, 11:43?am, Lionel wrote: > > > > > Hello folks, I couldn't find a specific PyGTK forum so I thought I'd > > > > post here and hope someone new the answer. I feel it's a silly > > > > problem, maybe something to do with a path variable? The problem: I've > > > > downloaded the "all-in-one" windows binary installer for PyGTK from > > > > their website. After typing in their first tutorial program and trying > > > > to run from the command line, I get: > > > > > "This application has failed to start because libglib-2.0-0.dll was > > > > not found" error dialog. > > > > > The traceback indicates this is happening at the "import gtk" line. A > > > > quick search of my install directory for PyGTK indicates that the file > > > > is indeed resident and located in C:\Program files\PyGTK\GTK\bin. > > > > > Is there some some sort of path variable for Python I need to modify > > > > and, if so, how is this done? Thanks so much, and my apologies if this > > > > is the wrong forum. > > > > > -L > > > > Well, I tried uninstalling / reinstalling PyGTK and now I'm getting a > > > different traceback error: > > > > "ImportError: no module named pygtk" > > > > I checked and pygtk.py is located in "c:\Python25\Lib\site-packages". > > > Then I displaye the sys.path: > > > > IDLE 1.2>>> import sys > > > >>> sys.path > > > > ['C:\\Program Files\\PyGTK\\Python\\Lib\\idlelib', 'C:\\Program Files\ > > > \PyGTK\\Python\\python25.zip', 'C:\\Program Files\\PyGTK\\Python\ > > > \DLLs', 'C:\\Program Files\\PyGTK\\Python\\lib', 'C:\\Program Files\ > > > \PyGTK\\Python\\lib\\plat-win', 'C:\\Program Files\\PyGTK\\Python\\lib\ > > > \lib-tk', 'C:\\Program Files\\PyGTK\\Python', 'C:\\Program Files\\PyGTK > > > \\Python\\lib\\site-packages'] > > > > Every single entry is related to PyGTK and nothing else. Something > > > seems wrong here but I don't have enough Python experience to know > > > just what. Anyone?- Hide quoted text - > > > > - Show quoted text - > > > Okay, out of desperation and frustration I've wiped my Python/SciPy/ > > etc.. setup and reinstalled from scratch. I've tested it with my app > > and all the numpy and matplotlib functionality is there and working. > > My sys.path seems to be back to normal: > > > IDLE 1.2.4>>> import sys > > >>> sys.path > > > ['C:\\Python25\\Lib\\idlelib', 'C:\\WINDOWS\\system32\\python25.zip', > > 'C:\\Python25\\DLLs', 'C:\\Python25\\lib', 'C:\\Python25\\lib\\plat- > > win', 'C:\\Python25\\lib\\lib-tk', 'C:\\Python25', 'C:\\Python25\\lib\ > > \site-packages'] > > > I will now re-install PyGTK and see if it mysteriously decides to work > > this time.- Hide quoted text - > > > - Show quoted text - > > Nope. Now I'm getting: > > "The applciation has failed to start because MSVCR80.dll was not > found." > > Don't know what else to try here. Anyone have any ideas?- Hide quoted text - > > - Show quoted text - you can try downloading an older version... I haven't updated mine for over a year. I am using the version that goes with python 2.5 and windows (I perfer to try wxwindows first usualy..) and it seems to work o.k. .... I don't know if that will help or not.. From tim.wintle at teamrubber.com Thu Feb 19 11:37:49 2009 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Thu, 19 Feb 2009 16:37:49 +0000 Subject: os.fdopen giving "Invalid Argument" from pipes Message-ID: <1235061469.22757.33.camel@tim-laptop> Was wondering if someone could point out what the stupid thing I'm doing wrong is: {{{ import os, time def run_multi_proc(): server_send, logger_recieve = os.pipe() pid = os.fork() if pid == 0: # we are the logger #os.close(server_send) logger_recieve = os.fdopen(logger_recieve) time.sleep(20) else: # we are the server #os.close(logger_recieve) server_send = os.fdopen(server_send,"w") time.sleep(3) os.kill(pid,signal.SIGTERM) if __name__ == "__main__": run_multi_proc() }}} > python test.py Traceback (most recent call last): File "test.py", line 20, in run_multi_proc() File "test.py", line 9, in run_multi_proc logger_recieve = os.fdopen(logger_recieve) OSError: [Errno 22] Invalid argument Traceback (most recent call last): File "test.py", line 20, in run_multi_proc() File "test.py", line 15, in run_multi_proc server_send = os.fdopen(server_send,"w") OSError: [Errno 22] Invalid argument really confused about why this isn't working - running on Linux with python 2.5.2 Tim W From notvalid2 at sbcglobal.net Thu Feb 19 11:38:07 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Thu, 19 Feb 2009 08:38:07 -0800 Subject: Which Version of wxPython for Win XP In-Reply-To: References: Message-ID: <0Vfnl.5624$%54.4038@nlpi070.nbdc.sbc.com> Eric_Dexter at msn.com wrote: > On Feb 19, 8:22 am, "W. eWatson" wrote: >> I'm going to try out wxPython 2.8.92 for py25. It seems like the ansi >> version is the choice for me. The other choice has unicode. Do I care? >> -- >> W. eWatson >> >> (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) >> Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet >> >> Web Page: > > > There is a good chance you don't care... I think the other is for > internationalization... best to look.. It would be easier to answer > the question if you said what you are going to do with it, and who > needed to use your software. It's even possible that you might want > to try pygame depending on what you want to use it for and who the > audience is (and how good thier computers are) > > http://pypi.python.org/simple/Dex%20Tracker/ Thanks. I think I'll take the chance. Somewhat simple programming. Off I go to install it. It can always be un-installed. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From digitig at gmail.com Thu Feb 19 11:48:52 2009 From: digitig at gmail.com (Tim Rowe) Date: Thu, 19 Feb 2009 16:48:52 +0000 Subject: Will multithreading make python less popular? In-Reply-To: References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <28e3612d-2e91-4a91-82cb-5fb2deda95fd@q9g2000yqc.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> Message-ID: 2009/2/19 : > Thank you Tim... > > It is not a search for perfect language. It is a search for a capable > language to modern worlds' needs. That would be just about any of the ones you mentioned, then. Unless you mean the needs of a specific project, in which case the suitability will depend on the project. -- Tim Rowe From exarkun at divmod.com Thu Feb 19 11:50:04 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Thu, 19 Feb 2009 11:50:04 -0500 Subject: os.fdopen giving "Invalid Argument" from pipes In-Reply-To: <1235061469.22757.33.camel@tim-laptop> Message-ID: <20090219165004.12853.832529843.divmod.quotient.11854@henry.divmod.com> On Thu, 19 Feb 2009 16:37:49 +0000, Tim Wintle wrote: >Was wondering if someone could point out what the stupid thing I'm doing >wrong is: > > >{{{ >import os, time >def run_multi_proc(): > server_send, logger_recieve = os.pipe() You got server_send and logger_receive backwards (also, i before e *except* after c et cetera). Flip 'em around and all is well. > pid = os.fork() > if pid == 0: > # we are the logger > #os.close(server_send) > logger_recieve = os.fdopen(logger_recieve) > time.sleep(20) > else: > # we are the server > #os.close(logger_recieve) > server_send = os.fdopen(server_send,"w") > time.sleep(3) > os.kill(pid,signal.SIGTERM) > >if __name__ == "__main__": > run_multi_proc() >}}} > > >> python test.py > >Traceback (most recent call last): > File "test.py", line 20, in > run_multi_proc() > File "test.py", line 9, in run_multi_proc > logger_recieve = os.fdopen(logger_recieve) >OSError: [Errno 22] Invalid argument >Traceback (most recent call last): > File "test.py", line 20, in > run_multi_proc() > File "test.py", line 15, in run_multi_proc > server_send = os.fdopen(server_send,"w") >OSError: [Errno 22] Invalid argument > > >really confused about why this isn't working - running on Linux with >python 2.5.2 Jean-Paul From tim.wintle at teamrubber.com Thu Feb 19 11:53:25 2009 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Thu, 19 Feb 2009 16:53:25 +0000 Subject: os.fdopen giving "Invalid Argument" from pipes In-Reply-To: <20090219165004.12853.832529843.divmod.quotient.11854@henry.divmod.com> References: <20090219165004.12853.832529843.divmod.quotient.11854@henry.divmod.com> Message-ID: <1235062405.22757.35.camel@tim-laptop> On Thu, 2009-02-19 at 11:50 -0500, Jean-Paul Calderone wrote: > You got server_send and logger_receive backwards Doh! > (also, i before e *except* after c et cetera). Flip 'em around and > all is well. Thanks - never was great at speling :-) Tim From sturlamolden at yahoo.no Thu Feb 19 11:55:00 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Thu, 19 Feb 2009 08:55:00 -0800 (PST) Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <28e3612d-2e91-4a91-82cb-5fb2deda95fd@q9g2000yqc.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> Message-ID: On Feb 19, 4:39?pm, rushen... at gmail.com wrote: > I really wanted to learn python, but as i said i don't want to make a > dead investment. I hope someone can fix these design errors and maybe > can write an interpreter in python :) Java and Python has different strengths and weaknesses. There is no such thing as "the perfect language". It all depends on what you want to do. Just be aware that scientists and engineers who need parallel computers do not use Java or C#. A combination of a scripting language with C or Fortran seems to be preferred. Popular scripting languages numerical computing include Python, R, IDL, Perl, and Matlab. You will find that in the Java community, threads are generally used for other tasks than parallel computing, and mainly asynchronous I/O. Java does not have a GIL, nor does Jython or Microsoft's IronPython. But if you use threads for I/O, the GIL does not matter. Having more than one CPU does not make your harddisk or network connection any faster. The GIL does not matter before crunching numbers on the CPU becomes the bottleneck. And when you finally get there, perhaps it is time to look into some C programming? Those that complain about CPython's GIL (or the GIL of Perl/PHP/Ruby for that matter) seem to be developers who have no or little experience with parallel computers. Yes, the GIL prevents Python threads from being used in a certain way. But do you really need to use threads like that? Or do you just think you do? S.M. From R.Brodie at rl.ac.uk Thu Feb 19 12:07:33 2009 From: R.Brodie at rl.ac.uk (Richard Brodie) Date: Thu, 19 Feb 2009 17:07:33 -0000 Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <28e3612d-2e91-4a91-82cb-5fb2deda95fd@q9g2000yqc.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> Message-ID: "sturlamolden" wrote in message news:d544d846-15ac-446e-a77f-cede8fcf9f27 at m40g2000yqh.googlegroups.com... > The GIL does not matter before crunching numbers on the CPU > becomes the bottleneck. And when you finally get there, perhaps it is > time to look into some C programming? Or numpy on a 512 core GPGPU processor, because using the CPU for crunching numbers is just *so* dated. ;) From Tribulations at Paralleles.invalid Thu Feb 19 12:15:15 2009 From: Tribulations at Paralleles.invalid (TP) Date: Thu, 19 Feb 2009 18:15:15 +0100 Subject: setattr question Message-ID: <3mg076-fl5.ln1@rama.fbx.proxad.net> Hi everybody, I try to make a "link" (or shortcut, if you want) so that len(b_instance) computes in fact len(a) (see the code below). I could write a method __len__ to b, but I wonder if it is possible to make it with a setattr/getattr trick, as I do below. Thanks in advance, Julien ###################### class b( object ): def __init__( self ): super( b, self ).__init__() a = [5,4,7] b_instance = b() setattr( b_instance, "__len__", getattr( a, "__len__") ) print len( a ) print id( a.__len__ ) print hasattr( b_instance, "__len__" ) print id( b.__len__ ) print len( b_instance ) ######################## I obtain: $ p test_setattr.py 3 3083822540 True Traceback (most recent call last): File "test_setattr.py", line 14, in print id( b.__len__ ) AttributeError: type object 'b' has no attribute '__len__' Command failure: error 1 ! -- python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\ 9&1+,\'Z4(55l4('])" "When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong." (first law of AC Clarke) From amgusarov at gmail.com Thu Feb 19 12:17:56 2009 From: amgusarov at gmail.com (Alex Gusarov) Date: Thu, 19 Feb 2009 23:17:56 +0600 Subject: Search in list of dictionaries Message-ID: <549d7a20902190917t10eed64dt71965ddc4bc7889f@mail.gmail.com> Hello everybody! I've a list of dictionaries with 'shorcut' and 'command' keys. When user types a word program must search this list for a typed shortcut and then run linked command. What I've wrote: for cmd in self.commands: if cmd['shortcut'] == input: os.popen(cmd['command']) break else: os.popen(input) But it's a brute-force method and I think there is another way in searching items through a list by dictionary key. Please give me advice how can I implement fast search in list of dictionaries by some dictionary key. In my mind language: list.get({'shortcut' == input}) Thanks a lot, Alex -------------- next part -------------- An HTML attachment was scrubbed... URL: From hellyj at ucsd.edu Thu Feb 19 12:28:42 2009 From: hellyj at ucsd.edu (Helly John J.) Date: Thu, 19 Feb 2009 09:28:42 -0800 Subject: Problems with OS X 10.5.6 and Python 2.5 and GDAL 1.6 In-Reply-To: References: <60437775-ED63-469B-A2CC-913B0E77BC1E@ucsd.edu> Message-ID: <3BD0C017-E443-4E46-9BFE-3B399686CB5D@ucsd.edu> Hi Miles. Same result from that as well. Cheers. -------------- John Helly, University of California, San Diego San Diego Supercomputer Center Scripps Institution of Oceanography 9500 Gilman Dr. Mail Code, La Jolla CA 92093 Phone: Voice +01 760 840 8660 mobile / stonesteps (Skype) / stonesteps7 (iChat) http://www.sdsc.edu/~hellyj On Feb 17, 2009, at 2:43 PM, Miles wrote: On Mon, Feb 16, 2009 at 8:35 PM, Helly John J. wrote: > However, when I run python and try to import gdal, this is what > happens: > Python 2.5.4 (r254:67917, Dec 23 2008, 14:57:27) > [GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> import gdal > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named gdal What about "from osgeo import gdal"? -Miles -- http://mail.python.org/mailman/listinfo/python-list From notvalid2 at sbcglobal.net Thu Feb 19 12:29:22 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Thu, 19 Feb 2009 09:29:22 -0800 Subject: Which Version of wxPython for Win XP In-Reply-To: <0Vfnl.5624$%54.4038@nlpi070.nbdc.sbc.com> References: <0Vfnl.5624$%54.4038@nlpi070.nbdc.sbc.com> Message-ID: W. eWatson wrote: > Eric_Dexter at msn.com wrote: >> On Feb 19, 8:22 am, "W. eWatson" wrote: >>> I'm going to try out wxPython 2.8.92 for py25. It seems like the ansi >>> version is the choice for me. The other choice has unicode. Do I care? >>> -- >>> W. eWatson >>> >>> (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) >>> Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet >>> >>> Web Page: >> >> >> There is a good chance you don't care... I think the other is for >> internationalization... best to look.. It would be easier to answer >> the question if you said what you are going to do with it, and who >> needed to use your software. It's even possible that you might want >> to try pygame depending on what you want to use it for and who the >> audience is (and how good thier computers are) >> >> http://pypi.python.org/simple/Dex%20Tracker/ > Thanks. I think I'll take the chance. Somewhat simple programming. > Off I go to install it. It can always be un-installed. > Well, that was an interesting experience. It appears to have recompiled a lot of stuff, and probably some libraries. IDLE is still with me as the way to open py files. Apparently, if I want to get around IDLE, I may have to install some other editor. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From hellyj at ucsd.edu Thu Feb 19 12:30:29 2009 From: hellyj at ucsd.edu (Helly John J.) Date: Thu, 19 Feb 2009 09:30:29 -0800 Subject: Problems with OS X 10.5.6 and Python 2.5 and GDAL 1.6 In-Reply-To: <3A6157F5-DBA7-46B5-89A8-621DF6AB1F56@semanchuk.com> References: <60437775-ED63-469B-A2CC-913B0E77BC1E@ucsd.edu> <3A6157F5-DBA7-46B5-89A8-621DF6AB1F56@semanchuk.com> Message-ID: Hi Philip. I installed the 2.5.4 binary from the python.org site. I did this because NumPy and SciPy currently only work with 2.5 and the system version was 2.4. Cheers. -------------- John Helly, University of California, San Diego San Diego Supercomputer Center Scripps Institution of Oceanography 9500 Gilman Dr. Mail Code, La Jolla CA 92093 Phone: Voice +01 760 840 8660 mobile / stonesteps (Skype) / stonesteps7 (iChat) http://www.sdsc.edu/~hellyj On Feb 17, 2009, at 12:30 PM, Philip Semanchuk wrote: On Feb 16, 2009, at 8:35 PM, Helly John J. wrote: > Hi. > > I'm a newbie to python and am running: > > OS X 10.5.6 > Python 2.5.4 Hi John, Are you using the system Python or have you installed another version? Cheers Philip > > > and have run easy_install for gdal like this: > > /Library/Python/2.5/site-packages>sudo easy_install GDAL > Password: > Searching for GDAL > Best match: GDAL 1.6.0 > Processing GDAL-1.6.0-py2.5-macosx-10.5-i386.egg > GDAL 1.6.0 is already the active version in easy-install.pth > > Using /Library/Python/2.5/site-packages/GDAL-1.6.0-py2.5-macosx-10.5- > i386.egg > Processing dependencies for GDAL > Finished processing dependencies for GDAL > > However, when I run python and try to import gdal, this is what > happens: > > Python 2.5.4 (r254:67917, Dec 23 2008, 14:57:27) > [GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > >>> import gdal > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named gdal > >>> > > Clearly, it's not being found but I don't understand how to debug > this any further. I have the *.egg in the site-packages directory > but don't understand if there is something else I have to do to make > it usable. Any help would be much appreciated. > Cheers. > -------------- > John Helly, University of California, San Diego > San Diego Supercomputer Center, Mail Code 0527 > Scripps Institution of Oceanography, Climate, Atmospheric Science, > and Physical Oceanography, Mail Code 0224 > 9500 Gilman Dr., La Jolla CA 92093 > +01 760 840 8660 mobile / stonesteps (Skype) / stonesteps7 (iChat) / > URL (http://www.sdsc.edu/~hellyj) > > -- > http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list From lionel.keene at gmail.com Thu Feb 19 12:34:43 2009 From: lionel.keene at gmail.com (Lionel) Date: Thu, 19 Feb 2009 09:34:43 -0800 (PST) Subject: numpy.memmap advice? References: <59449976-a334-411a-bdc8-7e6041bd4a37@g1g2000pra.googlegroups.com> <66395359-fca2-4e31-8ff9-5fbf51654d1b@v38g2000yqb.googlegroups.com> Message-ID: On Feb 18, 12:35?pm, Carl Banks wrote: > On Feb 18, 10:48?am, Lionel wrote: > > > Thanks Carl, I like your solution. Am I correct in my understanding > > that memory is allocated at the slicing step in your example i.e. when > > "reshaped_data" is sliced using "interesting_data = reshaped_data[:, > > 50:100]"? In other words, given a huge (say 1Gb) file, a memmap object > > is constructed that memmaps the entire file. Some relatively small > > amount of memory is allocated for the memmap operation, but the bulk > > memory allocation occurs when I generate my final numpy sub-array by > > slicing, and this accounts for the memory efficiency of using memmap? > > No, what accounts for the memory efficienty is there is no bulk > allocation at all. ?The ndarray you have points to the memory that's > in the mmap. ?There is no copying data or separate array allocation. > > Also, it's not any more memory efficient to use the offset parameter > with numpy.memmap than it is to memmap the whole file and take a > slice. > > Carl Banks Does this mean that everytime I iterate through an ndarray that is sourced from a memmap, the data is read from the disc? The sliced array is at no time wholly resident in memory? What are the performance implications of this? From __peter__ at web.de Thu Feb 19 12:38:46 2009 From: __peter__ at web.de (Peter Otten) Date: Thu, 19 Feb 2009 18:38:46 +0100 Subject: setattr question References: <3mg076-fl5.ln1@rama.fbx.proxad.net> Message-ID: TP wrote: > Hi everybody, > > I try to make a "link" (or shortcut, if you want) so that len(b_instance) > computes in fact len(a) (see the code below). I could write a method > __len__ to b, but I wonder if it is possible to make it with a > setattr/getattr trick, as I do below. > > Thanks in advance, > > Julien > > ###################### > class b( object ): > > def __init__( self ): > > super( b, self ).__init__() > > a = [5,4,7] > b_instance = b() > > setattr( b_instance, "__len__", getattr( a, "__len__") ) Invoking setattr() or getattr() with a constant name is bogus. The above can be written as b_instance.__len__ = a.__len__ > print len( a ) > print id( a.__len__ ) > print hasattr( b_instance, "__len__" ) > print id( b.__len__ ) > print len( b_instance ) > ######################## > > I obtain: > $ p test_setattr.py > 3 > 3083822540 > True > Traceback (most recent call last): > File "test_setattr.py", line 14, in > print id( b.__len__ ) > AttributeError: type object 'b' has no attribute '__len__' > Command failure: error 1 ! > __special__ methods in newstyle classes are looked up in the class, not the instance: >>> class B(object): pass ... >>> items = [1,2,3] >>> b = B() >>> len(b) Traceback (most recent call last): File "", line 1, in TypeError: object of type 'B' has no len() >>> B.__len__ = items.__len__ >>> len(b) 3 Now that doesn't make much sense because all instances of B now share the same length. If you want a useful per-instance length function you have to delegate: >>> class B(object): ... def __len__(self): return self._len() ... >>> a = B() >>> b = B() >>> a._len = [1,2,3].__len__ >>> b._len = [].__len__ >>> len(a), len(b) (3, 0) Peter From google at mrabarnett.plus.com Thu Feb 19 12:39:04 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 19 Feb 2009 17:39:04 +0000 Subject: Search in list of dictionaries In-Reply-To: <549d7a20902190917t10eed64dt71965ddc4bc7889f@mail.gmail.com> References: <549d7a20902190917t10eed64dt71965ddc4bc7889f@mail.gmail.com> Message-ID: <499D9938.5010207@mrabarnett.plus.com> Alex Gusarov wrote: > Hello everybody! > > I've a list of dictionaries with 'shorcut' and 'command' keys. When user > types a word program must search this list for a typed shortcut and then > run linked command. What I've wrote: > > for cmd in self.commands: > if cmd['shortcut'] == input: > os.popen(cmd['command']) > break > else: > os.popen(input) > > But it's a brute-force method and I think there is another way in > searching items through a list by dictionary key. Please give me advice > how can I implement fast search in list of dictionaries by some > dictionary key. In my mind language: > > list.get({'shortcut' == input}) > If want to go from the shortcut to the command (cmd['shortcut'] -> cmd['command']) the quickest way is using a dict, where cmd['shortcut'] is the key and cmd['command'] is the value: self.command_dict = {} for cmd in self.commands: self.command_dict[cmd['shortcut']] = cmd['command'] and then: os.popen(self.command_dict[input]) This will raise a KeyError if it's unknown. The equivalent of your code above is: os.popen(self.command_dict.get(input, input)) From pavlovevidence at gmail.com Thu Feb 19 12:51:57 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 19 Feb 2009 09:51:57 -0800 (PST) Subject: numpy.memmap advice? References: <59449976-a334-411a-bdc8-7e6041bd4a37@g1g2000pra.googlegroups.com> <66395359-fca2-4e31-8ff9-5fbf51654d1b@v38g2000yqb.googlegroups.com> Message-ID: <10c6209b-5f23-4709-840f-ade7b734be8b@s24g2000vbp.googlegroups.com> On Feb 19, 9:34?am, Lionel wrote: > On Feb 18, 12:35?pm, Carl Banks wrote: > > > > > > > On Feb 18, 10:48?am, Lionel wrote: > > > > Thanks Carl, I like your solution. Am I correct in my understanding > > > that memory is allocated at the slicing step in your example i.e. when > > > "reshaped_data" is sliced using "interesting_data = reshaped_data[:, > > > 50:100]"? In other words, given a huge (say 1Gb) file, a memmap object > > > is constructed that memmaps the entire file. Some relatively small > > > amount of memory is allocated for the memmap operation, but the bulk > > > memory allocation occurs when I generate my final numpy sub-array by > > > slicing, and this accounts for the memory efficiency of using memmap? > > > No, what accounts for the memory efficienty is there is no bulk > > allocation at all. ?The ndarray you have points to the memory that's > > in the mmap. ?There is no copying data or separate array allocation. > > Does this mean that everytime I iterate through an ndarray that is > sourced from a memmap, the data is read from the disc? The sliced > array is at no time wholly resident in memory? What are the > performance implications of this? Ok, sorry for the confusion. What I should have said is that there is no bulk allocation *by numpy* at all. The call to mmap does allocate a chunk of RAM to reflect file contents, but the numpy arrays don't allocate any memory of their own: they use the same memory as was allocated by the mmap call. Carl Banks From gagsl-py2 at yahoo.com.ar Thu Feb 19 12:52:13 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 19 Feb 2009 15:52:13 -0200 Subject: block dynamic attribute creation References: <5didnW_7dfWlDQHUnZ2dnUVZ_q_inZ2d@rcn.net> Message-ID: En Thu, 19 Feb 2009 13:20:25 -0200, Alan G Isaac escribi?: >>> if hasattr(self, attr): #update val >>> self.__dict__[attr] = val > On 2/19/2009 3:54 AM Gabriel Genellina apparently wrote: >> In particular, your code prevents using class attributes as a default >> value for instance attributes > > Doesn't the above allow that? Sorry, yes, sure! -- Gabriel Genellina From amgusarov at gmail.com Thu Feb 19 12:53:19 2009 From: amgusarov at gmail.com (Alex Gusarov) Date: Thu, 19 Feb 2009 23:53:19 +0600 Subject: Search in list of dictionaries In-Reply-To: <499D9938.5010207@mrabarnett.plus.com> References: <549d7a20902190917t10eed64dt71965ddc4bc7889f@mail.gmail.com> <499D9938.5010207@mrabarnett.plus.com> Message-ID: <549d7a20902190953o46684ca0k76f974cec8bb77d9@mail.gmail.com> Thanks! This example is quite simple and works exactly the way I wanted. On Thu, Feb 19, 2009 at 11:39 PM, MRAB wrote: > Alex Gusarov wrote: > >> Hello everybody! >> >> I've a list of dictionaries with 'shorcut' and 'command' keys. When user >> types a word program must search this list for a typed shortcut and then run >> linked command. What I've wrote: >> >> for cmd in self.commands: >> if cmd['shortcut'] == input: >> os.popen(cmd['command']) >> break >> else: >> os.popen(input) >> >> But it's a brute-force method and I think there is another way in >> searching items through a list by dictionary key. Please give me advice how >> can I implement fast search in list of dictionaries by some dictionary key. >> In my mind language: >> >> list.get({'shortcut' == input}) >> >> If want to go from the shortcut to the command (cmd['shortcut'] -> > cmd['command']) the quickest way is using a dict, where cmd['shortcut'] > is the key and cmd['command'] is the value: > > self.command_dict = {} > for cmd in self.commands: > self.command_dict[cmd['shortcut']] = cmd['command'] > > and then: > > os.popen(self.command_dict[input]) > > This will raise a KeyError if it's unknown. The equivalent of your code > above is: > > os.popen(self.command_dict.get(input, input)) > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sturlamolden at yahoo.no Thu Feb 19 13:00:27 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Thu, 19 Feb 2009 10:00:27 -0800 (PST) Subject: numpy.memmap advice? References: <77c68ff8-d29d-4ada-9829-8f8f61c3ee4c@o36g2000yqh.googlegroups.com> Message-ID: <5dd3bccc-ebcd-4af0-bedd-2ca0a7b331fc@j8g2000yql.googlegroups.com> On 19 Feb, 03:13, Carl Banks wrote: > The offset parameter of mmap itself would be useful to map small > portions of gigabyte-sized files, and maybe numpy.memmap can take > advantage of that if the user passes an offset parameter. ? NumPy's memmap is just a wrapper for Python 2.5's mmap. The offset parameter does not affect the amount that is actually memory mapped. S.M. From philip at semanchuk.com Thu Feb 19 13:07:28 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Thu, 19 Feb 2009 13:07:28 -0500 Subject: Problems with OS X 10.5.6 and Python 2.5 and GDAL 1.6 In-Reply-To: References: <60437775-ED63-469B-A2CC-913B0E77BC1E@ucsd.edu> <3A6157F5-DBA7-46B5-89A8-621DF6AB1F56@semanchuk.com> Message-ID: <3378BF84-0A38-42E2-9541-01B959333288@semanchuk.com> On Feb 19, 2009, at 12:30 PM, Helly John J. wrote: > Hi Philip. > I installed the 2.5.4 binary from the python.org site. I did this > because NumPy and SciPy currently only work with 2.5 and the system > version was 2.4. It looks like you're using the same Python at the command line as the Python to which you installed GDAL. There shouldn't be anything else you have to do once easy-install is complete. As Miles pointed out, you should probably try this: from osgeo import gdal instead of this: import gdal Although I gather the latter should work based on the documentation here: http://trac.osgeo.org/gdal/wiki/GdalOgrInPython#imports I can't see what went wrong with your installation. You can try an uninstall and reinstall. (`easy_install -m GDAL` might do the uninstall for you.) If you're feeling adventurous, you can try to unwind the installation by hand. Edit easy-install.pth and delete the line that refers to GDAL, and then blow away the GDAL directory in site-packages. I see that you originally ran the easy_install from the directory '/ Library/Python/2.5/site-packages'. Don't do that. I don't have a logical reason for why, but Python given that the current directory is part of Python's import search path, you might be giving easy_install a different "environment" than your regular Python session. It's just a shot in the dark, but worth a try. Sorry I couldn't be of more help. > On Feb 17, 2009, at 12:30 PM, Philip Semanchuk wrote: > > On Feb 16, 2009, at 8:35 PM, Helly John J. wrote: > >> Hi. >> >> I'm a newbie to python and am running: >> >> OS X 10.5.6 >> Python 2.5.4 > > Hi John, > Are you using the system Python or have you installed another version? > > Cheers > Philip > > > > >> >> >> and have run easy_install for gdal like this: >> >> /Library/Python/2.5/site-packages>sudo easy_install GDAL >> Password: >> Searching for GDAL >> Best match: GDAL 1.6.0 >> Processing GDAL-1.6.0-py2.5-macosx-10.5-i386.egg >> GDAL 1.6.0 is already the active version in easy-install.pth >> >> Using /Library/Python/2.5/site-packages/GDAL-1.6.0-py2.5- >> macosx-10.5-i386.egg >> Processing dependencies for GDAL >> Finished processing dependencies for GDAL >> >> However, when I run python and try to import gdal, this is what >> happens: >> >> Python 2.5.4 (r254:67917, Dec 23 2008, 14:57:27) >> [GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin >> Type "help", "copyright", "credits" or "license" for more >> information. >> >>> import gdal >> Traceback (most recent call last): >> File "", line 1, in >> ImportError: No module named gdal >> >>> >> >> Clearly, it's not being found but I don't understand how to debug >> this any further. I have the *.egg in the site-packages directory >> but don't understand if there is something else I have to do to >> make it usable. Any help would be much appreciated. >> Cheers. >> -------------- >> John Helly, University of California, San Diego >> San Diego Supercomputer Center, Mail Code 0527 >> Scripps Institution of Oceanography, Climate, Atmospheric Science, >> and Physical Oceanography, Mail Code 0224 >> 9500 Gilman Dr., La Jolla CA 92093 >> +01 760 840 8660 mobile / stonesteps (Skype) / stonesteps7 >> (iChat) / URL (http://www.sdsc.edu/~hellyj) >> From kyosohma at gmail.com Thu Feb 19 13:17:23 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Thu, 19 Feb 2009 10:17:23 -0800 (PST) Subject: Which Version of wxPython for Win XP References: <0Vfnl.5624$%54.4038@nlpi070.nbdc.sbc.com> Message-ID: On Feb 19, 11:29?am, "W. eWatson" wrote: > W. eWatson wrote: > > Eric_Dex... at msn.com wrote: > >> On Feb 19, 8:22 am, "W. eWatson" wrote: > >>> I'm going to try out wxPython 2.8.92 for py25. It seems like the ansi > >>> version is the choice for me. The other choice has unicode. Do I care? > >>> -- > >>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? W. eWatson > > >>> ? ? ? ? ? ? ? (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) > >>> ? ? ? ? ? ? ? ?Obz Site: ?39? 15' 7" N, 121? 2' 32" W, 2700 feet > > >>> ? ? ? ? ? ? ? ? ? ? ?Web Page: > > >> There is a good chance you don't care... ?I think the other is for > >> internationalization... ?best to look.. ?It would be easier to answer > >> the question if you said what you are going to do with it, and who > >> needed to use your software. ?It's even possible that you might want > >> to try pygame depending on what you want to use it for and who the > >> audience is (and how good thier computers are) > > >>http://pypi.python.org/simple/Dex%20Tracker/ > > Thanks. I think I'll take the chance. Somewhat simple programming. > > Off I go to install it. It can always be un-installed. > > Well, that was an interesting experience. It appears to have recompiled a > lot of stuff, and probably some libraries. IDLE is still with me as the way > to open py files. Apparently, if I want to get around IDLE, I may have to > install some other editor. > > -- > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? W. eWatson > The compiling you are referring to is just making the py files into pyc files. This is normal and is a speed improvement. In fact, a lot of the scripts you write will create a pyc file when first run. In other words, wxPython does not affect your Python install in any way other than making itself available as a 3rd party package (i.e. adding itself to the path), just like any other good 3rd party package. I'm not sure why you're even talking about IDLE...wxPython is a GUI toolkit, not an IDE. Mike From pavlovevidence at gmail.com Thu Feb 19 13:28:47 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 19 Feb 2009 10:28:47 -0800 (PST) Subject: numpy.memmap advice? References: <77c68ff8-d29d-4ada-9829-8f8f61c3ee4c@o36g2000yqh.googlegroups.com> <5dd3bccc-ebcd-4af0-bedd-2ca0a7b331fc@j8g2000yql.googlegroups.com> Message-ID: <06e42c29-4d2d-4960-a448-6fbcda9607e4@v4g2000vbb.googlegroups.com> On Feb 19, 10:00?am, sturlamolden wrote: > On 19 Feb, 03:13, Carl Banks wrote: > > > The offset parameter of mmap itself would be useful to map small > > portions of gigabyte-sized files, and maybe numpy.memmap can take > > advantage of that if the user passes an offset parameter. ? > > NumPy's memmap is just a wrapper for Python 2.5's mmap. The offset > parameter does not affect the amount that is actually memory mapped. Yes, that's what I said, but in future numpy.mmap could be updated to take advantage of mmap's new offset parameter. Carl Banks From steven.oldner at gmail.com Thu Feb 19 13:32:00 2009 From: steven.oldner at gmail.com (steven.oldner) Date: Thu, 19 Feb 2009 10:32:00 -0800 (PST) Subject: Newby Question for reading a file Message-ID: <05bacf78-1398-464a-8d0c-651157f7579c@w34g2000yqm.googlegroups.com> Simple question but I haven't found an answer. I program in ABAP, and in ABAP you define the data structure of the file and move the file line into the structure, and then do something to the fields. That's my mental reference. How do I separate or address each field in the file line with PYTHON? What's the correct way of thinking? Thanks! From gert.cuykens at gmail.com Thu Feb 19 13:35:40 2009 From: gert.cuykens at gmail.com (gert) Date: Thu, 19 Feb 2009 10:35:40 -0800 (PST) Subject: Threading and tkinter References: <492d5db9-3681-4ae8-827e-f2a4f66bee80@v39g2000yqm.googlegroups.com> <90d5e669-e8d1-441e-adff-ddc501d21d26@u13g2000yqg.googlegroups.com> Message-ID: Hope you do not mind ignoring part of answers, so I can figure out more why things work the way they are. This two examples work, what i do not understand is that in function display i do not have to declare root, v or x ? ---------- example 1 ---------- from tkinter import * from _thread import start_new_thread from time import sleep x=0 def weegbrug(): global x while True: x=x+1 sleep(0.5) start_new_thread(weegbrug,()) def display(): v.set(x) root.after(500, lambda:display()) root = Tk() v = StringVar() txt = Label(root, textvariable=v, width=800, height=600, bg='yellow', font=('Helvetica', 300)) txt.pack(expand=YES, fill=BOTH) root.title('Weegbrug') root.overrideredirect(1) root.geometry('%dx%d+0+0' % (root.winfo_screenwidth(), root.winfo_screenheight())) root.after(500, lambda:display()) root.mainloop() ---------- example 2 ---------- from tkinter import * from threading import Thread from time import sleep class Weegbrug(Thread): def __init__(self): self.x=0 Thread.__init__(self) def run(self): while True: self.x=self.x+1 sleep(0.5) w = Weegbrug() w.start() def display(): v.set(w.x) root.after(500, lambda:display()) root = Tk() v = StringVar() txt = Label(root, textvariable=v, width=800, height=600, bg='yellow', font=('Helvetica', 300)) txt.pack(expand=YES, fill=BOTH) root.title('Weegbrug') root.overrideredirect(1) root.geometry('%dx%d+0+0' % (root.winfo_screenwidth(), root.winfo_screenheight())) root.after(500, lambda:display()) root.mainloop() From lionel.keene at gmail.com Thu Feb 19 13:36:49 2009 From: lionel.keene at gmail.com (Lionel) Date: Thu, 19 Feb 2009 10:36:49 -0800 (PST) Subject: numpy.memmap advice? References: <59449976-a334-411a-bdc8-7e6041bd4a37@g1g2000pra.googlegroups.com> <66395359-fca2-4e31-8ff9-5fbf51654d1b@v38g2000yqb.googlegroups.com> <10c6209b-5f23-4709-840f-ade7b734be8b@s24g2000vbp.googlegroups.com> Message-ID: <3008b9b3-9e23-4fc2-bd5d-286da7c0953f@u39g2000prn.googlegroups.com> On Feb 19, 9:51?am, Carl Banks wrote: > On Feb 19, 9:34?am, Lionel wrote: > > > > > > > On Feb 18, 12:35?pm, Carl Banks wrote: > > > > On Feb 18, 10:48?am, Lionel wrote: > > > > > Thanks Carl, I like your solution. Am I correct in my understanding > > > > that memory is allocated at the slicing step in your example i.e. when > > > > "reshaped_data" is sliced using "interesting_data = reshaped_data[:, > > > > 50:100]"? In other words, given a huge (say 1Gb) file, a memmap object > > > > is constructed that memmaps the entire file. Some relatively small > > > > amount of memory is allocated for the memmap operation, but the bulk > > > > memory allocation occurs when I generate my final numpy sub-array by > > > > slicing, and this accounts for the memory efficiency of using memmap? > > > > No, what accounts for the memory efficienty is there is no bulk > > > allocation at all. ?The ndarray you have points to the memory that's > > > in the mmap. ?There is no copying data or separate array allocation. > > > Does this mean that everytime I iterate through an ndarray that is > > sourced from a memmap, the data is read from the disc? The sliced > > array is at no time wholly resident in memory? What are the > > performance implications of this? > > Ok, sorry for the confusion. ?What I should have said is that there is > no bulk allocation *by numpy* at all. ?The call to mmap does allocate > a chunk of RAM to reflect file contents, but the numpy arrays don't > allocate any memory of their own: they use the same memory as was > allocated by the mmap call. > > Carl Banks- Hide quoted text - > > - Show quoted text - Thanks for the explanations Carl. I'm sorry, but it's me who's the confused one here, not anyone else :-) I hate to waste everyone's time again, but something is just not "clicking" in that black-hole I call a brain. So..."numpy.memmap" allocates a chunk off the heap to coincide with the file contents. If I memmap the entire 1 Gb file, a corresponding amount (approx. 1 Gb) is allocated? That seems to contradict what is stated in the numpy documentation: "class numpy.memmap Create a memory-map to an array stored in a file on disk. Memory-mapped files are used for accessing small segments of large files on disk, without reading the entire file into memory." In my previous example that we were working with (100x100 data file), you used an offset to memmap the "lower-half" of the array. Does this mean that in the process of memmapping that lower half, RAM was set aside for 50x100 32-bit complex numbers? If so, and I decide to memmap an entire file, there is no memory benefit in doing so. At this point do you (or anyone else) recommend I just write a little function for my class that takes the coords I intend to load and "roll my own" function? Seems like the best way to keep memory to a minimum, I'm just worried about performance. On the other hand, the most I'd be loading would be around 1k x 1k worth of data. From kyosohma at gmail.com Thu Feb 19 13:40:36 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Thu, 19 Feb 2009 10:40:36 -0800 (PST) Subject: Newby Question for reading a file References: 05bacf78-1398-464a-8d0c-651157f7579c@w34g2000yqm.googlegroups.com Message-ID: <6b15ccff-7d39-42fc-b49e-35deb9098873@c12g2000yqj.googlegroups.com> On Feb 19, 12:32?pm, "steven.oldner" wrote: > Simple question but I haven't found an answer. ?I program in ABAP, and > in ABAP you define the data structure of the file and move the file > line into the structure, and then do something to the fields. ?That's > my mental reference. > > How do I separate or address each field in the file line with PYTHON? > What's the correct way of thinking? > > Thanks! I don't really follow what you mean since I've never used ABAP, but here's how I typically read a file in Python: f = open("someFile.txt") for line in f: # do something with the line print line f.close() Of course, you can read just portions of the file too, using something like this: f.read(64) Which will read 64 bytes. For more info, check the following out: http://www.diveintopython.org/file_handling/file_objects.html - Mike From alan.isaac at gmail.com Thu Feb 19 13:42:19 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Thu, 19 Feb 2009 18:42:19 GMT Subject: block dynamic attribute creation In-Reply-To: <499d1ca1$0$26184$426a74cc@news.free.fr> References: <5didnW_7dfWlDQHUnZ2dnUVZ_q_inZ2d@rcn.net> <499d1ca1$0$26184$426a74cc@news.free.fr> Message-ID: On 2/19/2009 3:47 AM Bruno Desthuilliers apparently wrote: > if not hasattr(self, attr) and getattr(self, '_attrlock', False): > raise AttributeError(yadda yadda) > # NB: assume newstyle class > super(YourClass, self).__setattr__(attr, val) Thanks. Alan PS Thanks also to all who restrained themselves from saying, "don't do this". ;-) From harijay at gmail.com Thu Feb 19 13:51:39 2009 From: harijay at gmail.com (harijay) Date: Thu, 19 Feb 2009 10:51:39 -0800 (PST) Subject: reading binary data from a 32 bit machine on 64 bit machine Message-ID: <5698de3a-1796-4e40-8bdb-2a35dae7895f@j8g2000yql.googlegroups.com> Hi I am very confused with the use of the struct module to read binary data from a file. ( I have only worked with ascii files so far) I have a file spec for a Data-logger (http://www.dataq.com/support/ techinfo/ff.htm) I am collecting some voltage , time traces on one channel and they are written to the binary file on a 32 bit windows machine The file spec says that the number of header bytes in the data file header is stored as a 16 bit eye "I" at bits 6-7 Now I want to get at that number. When I try format !h I get a meaningful number If f is my file handle opened with "rb" mode >>> f.seek(5) >>> (Integer,) = struct.unpack('!h',f.read(2)) >>> (Integer,) (9348,) I am assuming that means that there are 9348 header bytes . Can someone look at the format spec and tell me if I am on the right track. Also if a binary guru can point me in the direction of a single line format pythonic way to get at the header that will be great Thanks a tonne hari From nad at acm.org Thu Feb 19 13:51:46 2009 From: nad at acm.org (Ned Deily) Date: Thu, 19 Feb 2009 10:51:46 -0800 Subject: Problems with OS X 10.5.6 and Python 2.5 and GDAL 1.6 References: <60437775-ED63-469B-A2CC-913B0E77BC1E@ucsd.edu> <3A6157F5-DBA7-46B5-89A8-621DF6AB1F56@semanchuk.com> Message-ID: In article , "Helly John J." wrote: > I installed the 2.5.4 binary from the python.org site. I did this > because NumPy and SciPy currently only work with 2.5 and the system > version was 2.4. >[...] > On Feb 16, 2009, at 8:35 PM, Helly John J. wrote: > > I'm a newbie to python and am running: > > OS X 10.5.6 > > Python 2.5.4 >[...] > > and have run easy_install for gdal like this: > > > > /Library/Python/2.5/site-packages>sudo easy_install GDAL > > Password: > > Searching for GDAL > > Best match: GDAL 1.6.0 > > Processing GDAL-1.6.0-py2.5-macosx-10.5-i386.egg > > GDAL 1.6.0 is already the active version in easy-install.pth > > > > Using /Library/Python/2.5/site-packages/GDAL-1.6.0-py2.5-macosx-10.5- > > i386.egg > > Processing dependencies for GDAL > > Finished processing dependencies for GDAL > > > > However, when I run python and try to import gdal, this is what > > happens: > > > > Python 2.5.4 (r254:67917, Dec 23 2008, 14:57:27) > > [GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin > > Type "help", "copyright", "credits" or "license" for more information. > > >>> import gdal > > Traceback (most recent call last): > > File "", line 1, in > > ImportError: No module named gdal > > >>> It looks like you have installed GDAL to the site-packages directory of the Apple-supplied python 2.5 (which, for 10.5, is 2.5.1, not 2.4). That site-packages directory is /Library/Python/2.5. The Apple-supplied python comes with a sym link from /usr/bin/python. If you launch it, you'll probably find GDAL is there as expected. If you do want to use the python.org python, which is somewhat newer, you need to install its own version of setuptools/easy_install and use it to install GDAL to the site-packages directory of that python which is located here: /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-pack ages. The two python instances co-exist. To install another easy_install, ensure the python.org python come first first on your PATH, then follow the instructions here: -- Ned Deily, nad at acm.org From mkhitrov at gmail.com Thu Feb 19 13:52:54 2009 From: mkhitrov at gmail.com (Maxim Khitrov) Date: Thu, 19 Feb 2009 13:52:54 -0500 Subject: Strange array.array performance Message-ID: <26ddd1750902191052i4e5caa21s2a4e32ff2d2d6e45@mail.gmail.com> Hello all, I'm currently writing a Python <-> MATLAB interface with ctypes and array.array class, using which I'll need to push large amounts of data to MATLAB. Everything is working well, but there was one strange performance-related issue that I ran into and wanted to ask about. Here's some example code to illustrate my point (this is developed on Windows, hence the use of clock): --- from array import array from time import clock input = array('B', range(256) * 10000) # Case 1 start = clock() data1 = array('B', input) print format(clock() - start, '.10f') # Case 2 start = clock() data2 = array('B') data2[:] = input print format(clock() - start, '.10f') # Case 3 start = clock() data3 = array('B') data3.extend(input) print format(clock() - start, '.10f') print input == data1 == data2 == data3 --- The output from this on my machine is as follows: 0.7080547730 0.0029827034 0.0028685943 True That seems very wrong. In the end, all arrays have the same data, but by specifying it in the constructor the creation process takes over 350x longer than the other two methods. Is this a bug, or is there some valid reason for it? In the latter case, it would be a good idea to mention this in the documentation, since that can be a significant performance improvement in some applications. Currently the documentation states "Otherwise, the iterable initializer is passed to the extend() method," which doesn't seem to be the case, based on the third example. - Max From rNOSPAMon at flownet.com Thu Feb 19 13:55:01 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Thu, 19 Feb 2009 10:55:01 -0800 Subject: Regular expression bug? Message-ID: I'm trying to split a CamelCase string into its constituent components. This kind of works: >>> re.split('[a-z][A-Z]', 'fooBarBaz') ['fo', 'a', 'az'] but it consumes the boundary characters. To fix this I tried using lookahead and lookbehind patterns instead, but it doesn't work: >>> re.split('((?<=[a-z])(?=[A-Z]))', 'fooBarBaz') ['fooBarBaz'] However, it does seem to work with findall: >>> re.findall('(?<=[a-z])(?=[A-Z])', 'fooBarBaz') ['', ''] So the regular expression seems to be doing the Right Thing. Is this a bug in re.split, or am I missing something? (BTW, I tried looking at the source code for the re module, but I could not find the relevant code. re.split calls sre_compile.compile().split, but the string 'split' does not appear in sre_compile.py. So where does this method come from?) I'm using Python2.5. Thanks, rg From albert at spenarnc.xs4all.nl Thu Feb 19 13:56:42 2009 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 19 Feb 2009 18:56:42 GMT Subject: programming by evolution? References: <42a2e3fc-ec2e-4c09-b456-95a5fc4ce5a2@g39g2000pri.googlegroups.com> <6uuc4eFhc1u1U1@mid.individual.net> <11809792-676f-4d95-87c1-26666cc46b3b@w24g2000prd.googlegroups.com> <03db1c69-828a-4961-914d-62fe10ed88fb@w39g2000prb.googlegroups.com> Message-ID: In article <03db1c69-828a-4961-914d-62fe10ed88fb at w39g2000prb.googlegroups.com>, Xah Lee wrote: > >Pascal Constanza wrote: >> Yes. There are actually complete software development methodologies >> built around these ideas. Google for "extreme programming" and "agile >> software methodologies". > >Pascal Constanza is a Common Lisp fanatic. Note here, that eXtreme >Programing is one of the snake oil, that ran like rampant wild fire in >the industry around 2002, with many books published on it on the >supposed motherfucking hip Software Engineering practices, but today >you don't hear much of it. I haven't looked at =E2=80=9CAgile programing=E2= >=80=9D >agile my ass, but it is probably a waste of time. > >... what society overwhelmingly asks for is snake oil. Of course, the >snake oil has the most impressive names =E2=80=94otherwise you would be >selling nothing=E2=80=94 like =E2=80=9CStructured Analysis and Design=E2=80= >=9D, =E2=80=9CSoftware >Engineering=E2=80=9D, =E2=80=9CMaturity Models=E2=80=9D, =E2=80=9CManagemen= >t Information Systems=E2=80=9D, >=E2=80=9CIntegrated Project Support Environments=E2=80=9D =E2=80=9CObject O= >rientation=E2=80=9D and >=E2=80=9CBusiness Process Re-engineering=E2=80=9D (the latter three being k= >nown as >IPSE, OO and BPR, respectively).=E2=80=9D =E2=80=94 Edsger W Dijkstra (1930= >-2002), in >EWD 1175: The strengths of the academic enterprise. > A couple of weeks ago, a collegue of mine held a lecture about a company where he is hired, building paper-folding and envelope-handling machines. (We are hired hands). Real time, and real time simulators. Full regression tests after each change. Agile scrum all the way down. It looks impressive especially from where I stand. ( Formal procedures that take 6 months, and bad fixes because approved changes were no good after all.) So not dead by a margin, and less snake oil than most methodologies I know of. > Xah Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- like all pyramid schemes -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From steven.oldner at gmail.com Thu Feb 19 14:07:21 2009 From: steven.oldner at gmail.com (steven.oldner) Date: Thu, 19 Feb 2009 11:07:21 -0800 (PST) Subject: Newby Question for reading a file References: 05bacf78-1398-464a-8d0c-651157f7579c@w34g2000yqm.googlegroups.com <6b15ccff-7d39-42fc-b49e-35deb9098873@c12g2000yqj.googlegroups.com> Message-ID: <3eafb3c3-01a2-423b-985a-1ca17f6e82b1@p13g2000yqc.googlegroups.com> On Feb 19, 12:40?pm, Mike Driscoll wrote: > On Feb 19, 12:32?pm, "steven.oldner" wrote: > > > Simple question but I haven't found an answer. ?I program in ABAP, and > > in ABAP you define the data structure of the file and move the file > > line into the structure, and then do something to the fields. ?That's > > my mental reference. > > > How do I separate or address each field in the file line with PYTHON? > > What's the correct way of thinking? > > > Thanks! > > I don't really follow what you mean since I've never used ABAP, but > here's how I typically read a file in Python: > > f = open("someFile.txt") > for line in f: > ? ? # do something with the line > ? ? print line > f.close() > > Of course, you can read just portions of the file too, using something > like this: > > f.read(64) > > Which will read 64 bytes. For more info, check the following out: > > http://www.diveintopython.org/file_handling/file_objects.html > > ?- Mike Hi Mike, ABAP is loosely based on COBOL. Here is what I was trying to do, but ended up just coding in ABAP. Read a 4 column text file of about 1,000 lines and compare the 2 middle field of each line. If there is a difference, output the line. The line's definition in ABAP is PERNR(8) type c, ENDDA(10) type c, BEGDA(10) type c, and LGART(4) type c. In ABAP the code is: LOOP AT in_file. IF in_file-endda <> in_file-begda. WRITE:\ in_file. " that's same as python's print ENDIF. ENDLOOP. I can read the file, but didn't know how to look st the fields in the line. From what you wrote, I need to read each segment/field of the line? Thanks, Steve From nad at acm.org Thu Feb 19 14:16:45 2009 From: nad at acm.org (Ned Deily) Date: Thu, 19 Feb 2009 11:16:45 -0800 Subject: Problems with OS X 10.5.6 and Python 2.5 and GDAL 1.6 References: <60437775-ED63-469B-A2CC-913B0E77BC1E@ucsd.edu> <3A6157F5-DBA7-46B5-89A8-621DF6AB1F56@semanchuk.com> Message-ID: In article , Ned Deily wrote: > It looks like you have installed GDAL to the site-packages directory of > the Apple-supplied python 2.5 (which, for 10.5, is 2.5.1, not 2.4). > That site-packages directory is /Library/Python/2.5. The Apple-supplied > python comes with a sym link from /usr/bin/python. If you launch it, > you'll probably find GDAL is there as expected. > > If you do want to use the python.org python, which is somewhat newer, > you need to install its own version of setuptools/easy_install and use > it to install GDAL to the site-packages directory of that python which > is located here: > /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-pack > ages. The two python instances co-exist. To install another easy_install, ensure the python.org python comes first on your > PATH, then follow the instructions here: > BTW, that easy_install will itself be installed into the bin directory of the python.org python framework. So to ensure you are using that easy_install and that python, make sure that bin directory is on your PATH before "/usr/bin", so, if necessary, something like: export PATH="/Library/Frameworks/Python.framework/Versions/2.5/bin:$PATH" -- Ned Deily, nad at acm.org From gagsl-py2 at yahoo.com.ar Thu Feb 19 14:23:14 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 19 Feb 2009 17:23:14 -0200 Subject: Strange array.array performance References: <26ddd1750902191052i4e5caa21s2a4e32ff2d2d6e45@mail.gmail.com> Message-ID: En Thu, 19 Feb 2009 16:52:54 -0200, Maxim Khitrov escribi?: > input = array('B', range(256) * 10000) > > # Case 1 > start = clock() > data1 = array('B', input) > print format(clock() - start, '.10f') > That seems very wrong. In the end, all arrays have the same data, but > by specifying it in the constructor the creation process takes over > 350x longer than the other two methods. Is this a bug, or is there > some valid reason for it? It's a known issue: http://bugs.python.org/issue5109 -- Gabriel Genellina From andreas.schawo at googlemail.com Thu Feb 19 14:23:52 2009 From: andreas.schawo at googlemail.com (Andy) Date: Thu, 19 Feb 2009 11:23:52 -0800 (PST) Subject: Regression test test_site failed on current trunk Message-ID: Hi, I checked out the python trunk (curently 2.7a0), compiled it on my linux machine and run the regression test suit. Below is the output of the failed part: test_site [14871 refs] test test_site failed -- Traceback (most recent call last): File "/mybook/storage/python_lnx/Lib/test/test_site.py", line 105, in test_s_option self.assertEqual(rc, 1) AssertionError: 0 != 1 Is this something serious. I compiled python with: ./configure --prefix=/dev/null --with-pydebug make -s Further I've got problems with moving the cursor when I started python (2.7a0). There are only esc sequences displayed. My Local installation (2.5.2) works fine. From marduk at letterboxes.org Thu Feb 19 14:26:46 2009 From: marduk at letterboxes.org (Albert Hopkins) Date: Thu, 19 Feb 2009 14:26:46 -0500 Subject: Regular expression bug? In-Reply-To: References: Message-ID: <1235071606.26110.18.camel@localhost.localdomain> On Thu, 2009-02-19 at 10:55 -0800, Ron Garret wrote: > I'm trying to split a CamelCase string into its constituent components. > This kind of works: > > >>> re.split('[a-z][A-Z]', 'fooBarBaz') > ['fo', 'a', 'az'] > > but it consumes the boundary characters. To fix this I tried using > lookahead and lookbehind patterns instead, but it doesn't work: That's how re.split works, same as str.split... > >>> re.split('((?<=[a-z])(?=[A-Z]))', 'fooBarBaz') > ['fooBarBaz'] > > However, it does seem to work with findall: > > >>> re.findall('(?<=[a-z])(?=[A-Z])', 'fooBarBaz') > ['', ''] Wow! To tell you the truth, I can't even read that... but one wonders why don't you just do def ccsplit(s): cclist = [] current_word = '' for char in s: if char in string.uppercase: if current_word: cclist.append(current_word) current_word = char else: current_word += char if current_word: ccl.append(current_word) return cclist >>> ccsplit('fooBarBaz') --> ['foo', 'Bar', 'Baz'] This is arguably *much* more easy to read than the re example doesn't require one to look ahead in the string. -a From robert.kern at gmail.com Thu Feb 19 14:35:45 2009 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 19 Feb 2009 13:35:45 -0600 Subject: Strange array.array performance In-Reply-To: <26ddd1750902191052i4e5caa21s2a4e32ff2d2d6e45@mail.gmail.com> References: <26ddd1750902191052i4e5caa21s2a4e32ff2d2d6e45@mail.gmail.com> Message-ID: On 2009-02-19 12:52, Maxim Khitrov wrote: > Hello all, > > I'm currently writing a Python<-> MATLAB interface with ctypes and > array.array class, using which I'll need to push large amounts of data > to MATLAB. Have you taken a look at mlabwrap? http://mlabwrap.sourceforge.net/ At the very least, you will probably want to use numpy arrays instead of array.array. http://numpy.scipy.org/ -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From __peter__ at web.de Thu Feb 19 14:38:11 2009 From: __peter__ at web.de (Peter Otten) Date: Thu, 19 Feb 2009 20:38:11 +0100 Subject: Newby Question for reading a file References: <6b15ccff-7d39-42fc-b49e-35deb9098873@c12g2000yqj.googlegroups.com> <3eafb3c3-01a2-423b-985a-1ca17f6e82b1@p13g2000yqc.googlegroups.com> Message-ID: steven.oldner wrote: > On Feb 19, 12:40?pm, Mike Driscoll wrote: >> On Feb 19, 12:32?pm, "steven.oldner" wrote: >> >> > Simple question but I haven't found an answer. ?I program in ABAP, and >> > in ABAP you define the data structure of the file and move the file >> > line into the structure, and then do something to the fields. ?That's >> > my mental reference. >> >> > How do I separate or address each field in the file line with PYTHON? >> > What's the correct way of thinking? >> >> > Thanks! >> >> I don't really follow what you mean since I've never used ABAP, but >> here's how I typically read a file in Python: >> >> f = open("someFile.txt") >> for line in f: >> # do something with the line >> print line >> f.close() >> >> Of course, you can read just portions of the file too, using something >> like this: >> >> f.read(64) >> >> Which will read 64 bytes. For more info, check the following out: >> >> http://www.diveintopython.org/file_handling/file_objects.html >> >> - Mike > > Hi Mike, > > ABAP is loosely based on COBOL. > > Here is what I was trying to do, but ended up just coding in ABAP. > > Read a 4 column text file of about 1,000 lines and compare the 2 > middle field of each line. If there is a difference, output the line. > > The line's definition in ABAP is PERNR(8) type c, ENDDA(10) type c, > BEGDA(10) type c, and LGART(4) type c. > In ABAP the code is: > LOOP AT in_file. > IF in_file-endda <> in_file-begda. > WRITE:\ in_file. " that's same as python's print > ENDIF. > ENDLOOP. > > I can read the file, but didn't know how to look st the fields in the > line. From what you wrote, I need to read each segment/field of the > line? Yes you can get portions of the line by slicing: for line in open("infile"): if line[8:18] != line[18:28]: print line, Or you can use the struct module: import struct for line in open("infile"): pernr, endda, begda, lgart, dummy = struct.unpack("8s10s10s4s1s", line) if endda != begda: print line, I'm assuming that a row in your input file is just the fields glued together followed by a newline. Peter From kwmsmith at gmail.com Thu Feb 19 14:41:17 2009 From: kwmsmith at gmail.com (Kurt Smith) Date: Thu, 19 Feb 2009 13:41:17 -0600 Subject: Regular expression bug? In-Reply-To: References: Message-ID: On Thu, Feb 19, 2009 at 12:55 PM, Ron Garret wrote: > I'm trying to split a CamelCase string into its constituent components. > This kind of works: > >>>> re.split('[a-z][A-Z]', 'fooBarBaz') > ['fo', 'a', 'az'] > > but it consumes the boundary characters. To fix this I tried using > lookahead and lookbehind patterns instead, but it doesn't work: > >>>> re.split('((?<=[a-z])(?=[A-Z]))', 'fooBarBaz') > ['fooBarBaz'] > > However, it does seem to work with findall: > >>>> re.findall('(?<=[a-z])(?=[A-Z])', 'fooBarBaz') > ['', ''] > > So the regular expression seems to be doing the Right Thing. Is this a > bug in re.split, or am I missing something? >From what I can tell, re.split can't split on zero-length boundaries. It needs something to split on, like str.split. Is this a bug? Possibly. The docs for re.split say: Split the source string by the occurrences of the pattern, returning a list containing the resulting substrings. Note that it does not say that zero-length matches won't work. I can work around the problem thusly: re.sub(r'(?<=[a-z])(?=[A-Z])', '_', 'fooBarBaz').split('_') Which is ugly. I reckon you can use re.findall with a pattern that matches the components and not the boundaries, but you have to take care of the beginning and end as special cases. Kurt From curt.hash at gmail.com Thu Feb 19 14:44:12 2009 From: curt.hash at gmail.com (Curt Hash) Date: Thu, 19 Feb 2009 12:44:12 -0700 Subject: Newby Question for reading a file In-Reply-To: <3eafb3c3-01a2-423b-985a-1ca17f6e82b1@p13g2000yqc.googlegroups.com> References: <6b15ccff-7d39-42fc-b49e-35deb9098873@c12g2000yqj.googlegroups.com> <3eafb3c3-01a2-423b-985a-1ca17f6e82b1@p13g2000yqc.googlegroups.com> Message-ID: <736698790902191144p4f5a250dud6c2fa83787942ae@mail.gmail.com> On Thu, Feb 19, 2009 at 12:07 PM, steven.oldner wrote: > > On Feb 19, 12:40 pm, Mike Driscoll wrote: > > On Feb 19, 12:32 pm, "steven.oldner" wrote: > > > > > Simple question but I haven't found an answer. I program in ABAP, and > > > in ABAP you define the data structure of the file and move the file > > > line into the structure, and then do something to the fields. That's > > > my mental reference. > > > > > How do I separate or address each field in the file line with PYTHON? > > > What's the correct way of thinking? > > > > > Thanks! > > > > I don't really follow what you mean since I've never used ABAP, but > > here's how I typically read a file in Python: > > > > f = open("someFile.txt") > > for line in f: > > # do something with the line > > print line > > f.close() > > > > Of course, you can read just portions of the file too, using something > > like this: > > > > f.read(64) > > > > Which will read 64 bytes. For more info, check the following out: > > > > http://www.diveintopython.org/file_handling/file_objects.html > > > > - Mike > > Hi Mike, > > ABAP is loosely based on COBOL. > > Here is what I was trying to do, but ended up just coding in ABAP. > > Read a 4 column text file of about 1,000 lines and compare the 2 > middle field of each line. If there is a difference, output the line. > > The line's definition in ABAP is PERNR(8) type c, ENDDA(10) type c, > BEGDA(10) type c, and LGART(4) type c. > In ABAP the code is: > LOOP AT in_file. > IF in_file-endda <> in_file-begda. > WRITE:\ in_file. " that's same as python's print > ENDIF. > ENDLOOP. > > I can read the file, but didn't know how to look st the fields in the > line. From what you wrote, I need to read each segment/field of the > line? > > Thanks, > > Steve > -- > http://mail.python.org/mailman/listinfo/python-list You could do something like this: f = open('file.txt', 'r') for line in f: a,b = line.split()[1:-1] # tokenize the string into sequence of length 4 and store two middle values in a and b if a != b: print line f.close() From schumann at fnal.gov Thu Feb 19 14:47:09 2009 From: schumann at fnal.gov (Carl Schumann) Date: Thu, 19 Feb 2009 13:47:09 -0600 Subject: Explanation for trailing comma in example from Learning Python? Message-ID: <499DB73D.1010208@fnal.gov> Hi, I am surprised at the trailing comma in the following example from "Learning Python": > Python 2.3.4 (#1, Dec 10 2007, 15:05:56) > [GCC 3.4.5 20051201 (Red Hat 3.4.5-2)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> def f(*args): print args > ... > >>> f() > () > >>> f(1) > (1,) > >>> f(1,2) > (1, 2) > >>> f(1,2,3) > (1, 2, 3) > >>> f(1,2,3,4) > (1, 2, 3, 4) > >>> I could see the logic in always or never having a trailing comma. What I don't understand here is why only the single element case has a trailing comma. Any explanations please? Thanks, Carl Schumann From andrew at acooke.org Thu Feb 19 14:51:06 2009 From: andrew at acooke.org (andrew cooke) Date: Thu, 19 Feb 2009 16:51:06 -0300 (CLST) Subject: Regular expression bug? In-Reply-To: References: Message-ID: <34b34b7c7b3c5d5230212d26837fc039.squirrel@localhost> i wonder what fraction of people posting with "bug?" in their titles here actually find bugs? anyway, how about: re.findall('[A-Z]?[a-z]*', 'fooBarBaz') or re.findall('([A-Z][a-z]*|[a-z]+)', 'fooBarBaz') (you have to specify what you're matching and lookahead/back doesn't do that). andrew Ron Garret wrote: > I'm trying to split a CamelCase string into its constituent components. > This kind of works: > >>>> re.split('[a-z][A-Z]', 'fooBarBaz') > ['fo', 'a', 'az'] > > but it consumes the boundary characters. To fix this I tried using > lookahead and lookbehind patterns instead, but it doesn't work: > >>>> re.split('((?<=[a-z])(?=[A-Z]))', 'fooBarBaz') > ['fooBarBaz'] > > However, it does seem to work with findall: > >>>> re.findall('(?<=[a-z])(?=[A-Z])', 'fooBarBaz') > ['', ''] > > So the regular expression seems to be doing the Right Thing. Is this a > bug in re.split, or am I missing something? > > (BTW, I tried looking at the source code for the re module, but I could > not find the relevant code. re.split calls sre_compile.compile().split, > but the string 'split' does not appear in sre_compile.py. So where does > this method come from?) > > I'm using Python2.5. > > Thanks, > rg > -- > http://mail.python.org/mailman/listinfo/python-list > > From __peter__ at web.de Thu Feb 19 14:52:58 2009 From: __peter__ at web.de (Peter Otten) Date: Thu, 19 Feb 2009 20:52:58 +0100 Subject: Regular expression bug? References: Message-ID: Ron Garret wrote: > I'm trying to split a CamelCase string into its constituent components. How about >>> re.compile("[A-Za-z][a-z]*").findall("fooBarBaz") ['foo', 'Bar', 'Baz'] > This kind of works: > >>>> re.split('[a-z][A-Z]', 'fooBarBaz') > ['fo', 'a', 'az'] > > but it consumes the boundary characters. To fix this I tried using > lookahead and lookbehind patterns instead, but it doesn't work: > >>>> re.split('((?<=[a-z])(?=[A-Z]))', 'fooBarBaz') > ['fooBarBaz'] > > However, it does seem to work with findall: > >>>> re.findall('(?<=[a-z])(?=[A-Z])', 'fooBarBaz') > ['', ''] > > So the regular expression seems to be doing the Right Thing. Is this a > bug in re.split, or am I missing something? IRC the split pattern must consume at least one character, but I can't find the reference. > (BTW, I tried looking at the source code for the re module, but I could > not find the relevant code. re.split calls sre_compile.compile().split, > but the string 'split' does not appear in sre_compile.py. So where does > this method come from?) It's coded in C. The source is Modules/sremodule.c. Peter From mkhitrov at gmail.com Thu Feb 19 14:53:21 2009 From: mkhitrov at gmail.com (Maxim Khitrov) Date: Thu, 19 Feb 2009 14:53:21 -0500 Subject: Strange array.array performance In-Reply-To: References: <26ddd1750902191052i4e5caa21s2a4e32ff2d2d6e45@mail.gmail.com> Message-ID: <26ddd1750902191153lb1b5efaj783f1c75596d900c@mail.gmail.com> On Thu, Feb 19, 2009 at 2:35 PM, Robert Kern wrote: > On 2009-02-19 12:52, Maxim Khitrov wrote: >> >> Hello all, >> >> I'm currently writing a Python<-> MATLAB interface with ctypes and >> array.array class, using which I'll need to push large amounts of data >> to MATLAB. > > Have you taken a look at mlabwrap? > > http://mlabwrap.sourceforge.net/ > > At the very least, you will probably want to use numpy arrays instead of > array.array. > > http://numpy.scipy.org/ I have, but numpy is not currently available for python 2.6, which is what I need for some other features, and I'm trying to keep the dependencies down in any case. Mlabwrap description doesn't mention if it is thread-safe, and that's another one of my requirements. The only feature that I'm missing with array.array is the ability to quickly pre-allocate large chunks of memory. To do that right now I'm using array('d', (0,) * size). It would be nice if array accepted an int as the second argument indicating how much memory to allocate and initialize to 0. - Max From mkhitrov at gmail.com Thu Feb 19 14:53:59 2009 From: mkhitrov at gmail.com (Maxim Khitrov) Date: Thu, 19 Feb 2009 14:53:59 -0500 Subject: Strange array.array performance In-Reply-To: References: <26ddd1750902191052i4e5caa21s2a4e32ff2d2d6e45@mail.gmail.com> Message-ID: <26ddd1750902191153q621d94f5xcf32ecf8e4513503@mail.gmail.com> On Thu, Feb 19, 2009 at 2:23 PM, Gabriel Genellina wrote: > En Thu, 19 Feb 2009 16:52:54 -0200, Maxim Khitrov > escribi?: > >> input = array('B', range(256) * 10000) >> >> # Case 1 >> start = clock() >> data1 = array('B', input) >> print format(clock() - start, '.10f') > >> That seems very wrong. In the end, all arrays have the same data, but >> by specifying it in the constructor the creation process takes over >> 350x longer than the other two methods. Is this a bug, or is there >> some valid reason for it? > > It's a known issue: http://bugs.python.org/issue5109 I see, thanks. From google at mrabarnett.plus.com Thu Feb 19 14:56:53 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 19 Feb 2009 19:56:53 +0000 Subject: reading binary data from a 32 bit machine on 64 bit machine In-Reply-To: <5698de3a-1796-4e40-8bdb-2a35dae7895f@j8g2000yql.googlegroups.com> References: <5698de3a-1796-4e40-8bdb-2a35dae7895f@j8g2000yql.googlegroups.com> Message-ID: <499DB985.2040107@mrabarnett.plus.com> harijay wrote: > Hi I am very confused with the use of the struct module to read binary > data from a file. > ( I have only worked with ascii files so far) > > I have a file spec for a Data-logger (http://www.dataq.com/support/ > techinfo/ff.htm) > > I am collecting some voltage , time traces on one channel and they are > written to the binary file on a 32 bit windows machine > > The file spec says that the number of header bytes in the data file > header is stored as a 16 bit eye "I" at bits 6-7 > > Now I want to get at that number. When I try format !h I get a > meaningful number > If f is my file handle opened with "rb" mode > >>>> f.seek(5) >>>> (Integer,) = struct.unpack('!h',f.read(2)) >>>> (Integer,) > (9348,) > > I am assuming that means that there are 9348 header bytes . Can > someone look at the format spec and tell me if I am on the right > track. > > Also if a binary guru can point me in the direction of a single line > format pythonic way to get at the header that will be great > The number of header bytes is stored in bytes 6-7, so you need seek(6), and the 16-bit value is little-endian as far as I can tell: f.seek(6) header_bytes, = struct.unpack(' <7xr61w8r20.fsf@ruckus.brouhaha.com> <788cab73-b999-48e4-beb3-b9dd38c501de@j8g2000yql.googlegroups.com> Message-ID: On Feb 18, 10:15?pm, rdmur... at bitdance.com wrote: > Thomas Allen wrote: > > On Feb 18, 4:51 am, alex23 wrote: > > > On Feb 18, 7:34 pm, rdmur... at bitdance.com wrote: > > > > > Yeah, but wget -r -k will do that bit of it, too. > > > > Wow, nice, I don't know why I never noticed that. Cheers! > > > Hm...doesn't do that over here. I thought it may have been because of > > absolute links (not to site root), but it even leaves things like > href="/">. Does it work for you guys? > > It works for me. ?The sample pages I just tested on it don't use > any href="/" links, but my 'href="/about.html"' got properly > converted to 'href="../about.html"'. ?(On the other hand my '/contact.html' > got converted to a full external URL...but that's apparently because the > contact.html file doesn't actually exist :) > > --RDM Thanks for the help everyone. The idea of counting the slashes was the linchpin of this little script, and with a little trial and error, I successfully generated a local copy of the site. I don't think my colleague knows what went into this, but he seemed appreciative :^) Thomas From google at mrabarnett.plus.com Thu Feb 19 15:03:45 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 19 Feb 2009 20:03:45 +0000 Subject: Regular expression bug? In-Reply-To: References: Message-ID: <499DBB21.9080600@mrabarnett.plus.com> Ron Garret wrote: > I'm trying to split a CamelCase string into its constituent components. > This kind of works: > >>>> re.split('[a-z][A-Z]', 'fooBarBaz') > ['fo', 'a', 'az'] > > but it consumes the boundary characters. To fix this I tried using > lookahead and lookbehind patterns instead, but it doesn't work: > >>>> re.split('((?<=[a-z])(?=[A-Z]))', 'fooBarBaz') > ['fooBarBaz'] > > However, it does seem to work with findall: > >>>> re.findall('(?<=[a-z])(?=[A-Z])', 'fooBarBaz') > ['', ''] > > So the regular expression seems to be doing the Right Thing. Is this a > bug in re.split, or am I missing something? > > (BTW, I tried looking at the source code for the re module, but I could > not find the relevant code. re.split calls sre_compile.compile().split, > but the string 'split' does not appear in sre_compile.py. So where does > this method come from?) > > I'm using Python2.5. > I, amongst others, think it's a bug (or 'misfeature'); Guido thinks it might be intentional, but changing it could break some existing code. You could do this instead: >>> re.sub('(?<=[a-z])(?=[A-Z])', '@', 'fooBarBaz').split('@') ['foo', 'Bar', 'Baz'] From steven.oldner at gmail.com Thu Feb 19 15:10:22 2009 From: steven.oldner at gmail.com (steven.oldner) Date: Thu, 19 Feb 2009 12:10:22 -0800 (PST) Subject: Newby Question for reading a file References: <6b15ccff-7d39-42fc-b49e-35deb9098873@c12g2000yqj.googlegroups.com> <3eafb3c3-01a2-423b-985a-1ca17f6e82b1@p13g2000yqc.googlegroups.com> Message-ID: <95d6b271-88a4-4c04-b582-d7ed665b44d4@f3g2000yqf.googlegroups.com> On Feb 19, 1:44?pm, Curt Hash wrote: > On Thu, Feb 19, 2009 at 12:07 PM, steven.oldner wrote: > > > On Feb 19, 12:40 pm, Mike Driscoll wrote: > > > On Feb 19, 12:32 pm, "steven.oldner" wrote: > > > > > Simple question but I haven't found an answer. ?I program in ABAP, and > > > > in ABAP you define the data structure of the file and move the file > > > > line into the structure, and then do something to the fields. ?That's > > > > my mental reference. > > > > > How do I separate or address each field in the file line with PYTHON? > > > > What's the correct way of thinking? > > > > > Thanks! > > > > I don't really follow what you mean since I've never used ABAP, but > > > here's how I typically read a file in Python: > > > > f = open("someFile.txt") > > > for line in f: > > > ? ? # do something with the line > > > ? ? print line > > > f.close() > > > > Of course, you can read just portions of the file too, using something > > > like this: > > > > f.read(64) > > > > Which will read 64 bytes. For more info, check the following out: > > > >http://www.diveintopython.org/file_handling/file_objects.html > > > > ?- Mike > > > Hi Mike, > > > ABAP is loosely based on COBOL. > > > Here is what I was trying to do, but ended up just coding in ABAP. > > > Read a 4 column text file of about 1,000 lines and compare the 2 > > middle field of each line. ?If there is a difference, output the line. > > > The line's definition in ABAP is PERNR(8) type c, ENDDA(10) type c, > > BEGDA(10) type c, and LGART(4) type c. > > In ABAP the code is: > > LOOP AT in_file. > > ?IF in_file-endda <> in_file-begda. > > ? ?WRITE:\ in_file. " that's same as python's print > > ?ENDIF. > > ENDLOOP. > > > I can read the file, but didn't know how to look st the fields in the > > line. ?From what you wrote, I need to read each segment/field of the > > line? > > > Thanks, > > > Steve > > -- > >http://mail.python.org/mailman/listinfo/python-list > > You could do something like this: > > f = open('file.txt', 'r') > for line in f: > ? ? a,b = line.split()[1:-1] ? # tokenize the string into sequence of > length 4 and store two middle values in a and b > ? ? if a != b: > ? ? ? ? print line > f.close()- Hide quoted text - > > - Show quoted text - Peter, you are correct, just fields glued together. I did not know there was a struc module and that code looks real good. This is something I will use in the future. Thanks! Curt, that looks good also. I just need to test the 2 middle values. I didn't know how to store line.split values into variables and this is simple. Thanks! Again, thanks Mike, Peter and Curt. Now if you ever need to know ABAP... ;) From http Thu Feb 19 15:18:04 2009 From: http (Paul Rubin) Date: 19 Feb 2009 12:18:04 -0800 Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <28e3612d-2e91-4a91-82cb-5fb2deda95fd@q9g2000yqc.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> Message-ID: <7x8wo2kwoz.fsf@ruckus.brouhaha.com> sturlamolden writes: > Yes, the GIL prevents Python threads from being used in a certain way. > But do you really need to use threads like that? Or do you just think > you do? How old is your computer, why did you buy it, and is it the first one you ever owned? For most of us, I suspect, it is not our first one, and we bought it to get a processing speedup relative to the previous one. If such speedups were useless or unimportant, we would not have blown our hard earned cash replacing perfectly good older hardware, so we have to accept the concept that speed matters and ignore those platitudes that say otherwise. It used to be that new computers were faster than the old ones because they ran at higher clock rates. That was great, no software changes at all were required to benefit from the higher speed. Now, they get the additional speed by having more cores. That's better than nothing but making use of it requires fixing the GIL. From pavlovevidence at gmail.com Thu Feb 19 15:26:33 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 19 Feb 2009 12:26:33 -0800 (PST) Subject: numpy.memmap advice? References: <59449976-a334-411a-bdc8-7e6041bd4a37@g1g2000pra.googlegroups.com> <66395359-fca2-4e31-8ff9-5fbf51654d1b@v38g2000yqb.googlegroups.com> <10c6209b-5f23-4709-840f-ade7b734be8b@s24g2000vbp.googlegroups.com> <3008b9b3-9e23-4fc2-bd5d-286da7c0953f@u39g2000prn.googlegroups.com> Message-ID: On Feb 19, 10:36?am, Lionel wrote: > On Feb 19, 9:51?am, Carl Banks wrote: > > > > > > > On Feb 19, 9:34?am, Lionel wrote: > > > > On Feb 18, 12:35?pm, Carl Banks wrote: > > > > > On Feb 18, 10:48?am, Lionel wrote: > > > > > > Thanks Carl, I like your solution. Am I correct in my understanding > > > > > that memory is allocated at the slicing step in your example i.e. when > > > > > "reshaped_data" is sliced using "interesting_data = reshaped_data[:, > > > > > 50:100]"? In other words, given a huge (say 1Gb) file, a memmap object > > > > > is constructed that memmaps the entire file. Some relatively small > > > > > amount of memory is allocated for the memmap operation, but the bulk > > > > > memory allocation occurs when I generate my final numpy sub-array by > > > > > slicing, and this accounts for the memory efficiency of using memmap? > > > > > No, what accounts for the memory efficienty is there is no bulk > > > > allocation at all. ?The ndarray you have points to the memory that's > > > > in the mmap. ?There is no copying data or separate array allocation. > > > > Does this mean that everytime I iterate through an ndarray that is > > > sourced from a memmap, the data is read from the disc? The sliced > > > array is at no time wholly resident in memory? What are the > > > performance implications of this? > > > Ok, sorry for the confusion. ?What I should have said is that there is > > no bulk allocation *by numpy* at all. ?The call to mmap does allocate > > a chunk of RAM to reflect file contents, but the numpy arrays don't > > allocate any memory of their own: they use the same memory as was > > allocated by the mmap call. > > > Carl Banks- Hide quoted text - > > > - Show quoted text - > > Thanks for the explanations Carl. I'm sorry, but it's me who's the > confused one here, not anyone else :-) > > I hate to waste everyone's time again, but something is just not > "clicking" in that black-hole I call a brain. So..."numpy.memmap" > allocates a chunk off the heap to coincide with the file contents. If > I memmap the entire 1 Gb file, a corresponding amount (approx. 1 Gb) > is allocated? That seems to contradict what is stated in the numpy > documentation: > > "class numpy.memmap > Create a memory-map to an array stored in a file on disk. > > Memory-mapped files are used for accessing small segments of large > files on disk, without reading the entire file into memory." Yes, it allocates room for the whole file in your process's LOGICAL address space. However, it doesn't actually reserve any PHYSICAL memory, or read in any data from the disk, until you've actually access the data. And then it only reads small chunks in, not the whole file. So when you mmap your 1GB file, the OS sets aside a 1 GB chunk of address to use for your memory map. That's all it does: it doesn't read anything from disk, it doesn't reserve any physical RAM. Later, when you access a byte in the mmap via a pointer, the OS notes that it hasn't yet loaded the data at that address, so it grabs a small chunk of physical ram and reads in the a small amount of data from the disk containing the byte you are accessing. This all happens automatically and transparently to you. > In my previous example that we were working with (100x100 data file), > you used an offset to memmap the "lower-half" of the array. Does this > mean that in the process of memmapping that lower half, RAM was set > aside for 50x100 32-bit complex numbers? If so, and I decide to memmap > an entire file, there is no memory benefit in doing so. The mmap call sets aside room for all 100x100 32-bit complex numbers in logical address space, regardless of whether you use the offset parameter or not. However, it might only read in part of the file in from disk, and will only reserve physical RAM for the parts it reads in. > At this point do you (or anyone else) recommend I just write a little > function for my class that takes the coords I intend to load and "roll > my own" function? Seems like the best way to keep memory to a minimum, > I'm just worried about performance. On the other hand, the most I'd be > loading would be around 1k x 1k worth of data.- No, if your file is not too large to mmap, just do it the way you've been doing it. The documentation you've been reading is pretty much correct, even if you approach it naively. It is both memory and I/O efficient. You're overthinking things here; don't try to outsmart the operating system. It'll take care of the performance issues satisfactorily. The only thing you have to worry about is if the file is too large to fit into your process's logical address space, which on a typical 32- bit system is 2-3 GB (depending on configuration) minus the space occupied by Python and other heap objects, which is probably only a few MB. Carl Banks From gagsl-py2 at yahoo.com.ar Thu Feb 19 15:31:25 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 19 Feb 2009 18:31:25 -0200 Subject: reading binary data from a 32 bit machine on 64 bit machine References: <5698de3a-1796-4e40-8bdb-2a35dae7895f@j8g2000yql.googlegroups.com> Message-ID: En Thu, 19 Feb 2009 16:51:39 -0200, harijay escribi?: > Hi I am very confused with the use of the struct module to read binary > data from a file. > ( I have only worked with ascii files so far) > > I have a file spec for a Data-logger (http://www.dataq.com/support/ > techinfo/ff.htm) That format is rather convoluted -- due to historical reasons, I imagine... > I am collecting some voltage , time traces on one channel and they are > written to the binary file on a 32 bit windows machine > > The file spec says that the number of header bytes in the data file > header is stored as a 16 bit eye "I" at bits 6-7 If it says "at *byte* positions 6-7" you need a seek(6) to start reading from there, not seek(5). > Now I want to get at that number. When I try format !h I get a > meaningful number > If f is my file handle opened with "rb" mode > >>>> f.seek(5) >>>> (Integer,) = struct.unpack('!h',f.read(2)) >>>> (Integer,) > (9348,) > > I am assuming that means that there are 9348 header bytes . Can > someone look at the format spec and tell me if I am on the right > track. Not exactly. Why '!' (network byte order)? The spec doesn't say about byte order, but since it's a Windows program we can assume little endian, '<' or just '=' (native). But instead of multiple seeks + micro-reads I'd read the whole header and decode it at once (the fixed part is only 110 bytes long): fixed_header_fmt = struct.Struct(" H, I -> h, B -> B, UL -> L, L -> l, D -> d, F -> f. -- Gabriel Genellina From steve at holdenweb.com Thu Feb 19 15:33:59 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 19 Feb 2009 15:33:59 -0500 Subject: Will multithreading make python less popular? In-Reply-To: <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <28e3612d-2e91-4a91-82cb-5fb2deda95fd@q9g2000yqc.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> Message-ID: <499DC237.9010301@holdenweb.com> rushenaly at gmail.com wrote: > Thank you Steve, > > I really wanted to learn python, but as i said i don't want to make a > dead investment. I hope someone can fix these design errors and maybe > can write an interpreter in python :) > > Thank you so much great community... > Rushen By the way, since you have chosen Java you might be interested to know that the JPython implementation (also open source) generates JVM bytecode, and allows you to freely mix Java and Python classes. There is no Global Interpreter Lock in JPython ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Thu Feb 19 15:33:59 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 19 Feb 2009 15:33:59 -0500 Subject: Will multithreading make python less popular? In-Reply-To: <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <28e3612d-2e91-4a91-82cb-5fb2deda95fd@q9g2000yqc.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> Message-ID: <499DC237.9010301@holdenweb.com> rushenaly at gmail.com wrote: > Thank you Steve, > > I really wanted to learn python, but as i said i don't want to make a > dead investment. I hope someone can fix these design errors and maybe > can write an interpreter in python :) > > Thank you so much great community... > Rushen By the way, since you have chosen Java you might be interested to know that the JPython implementation (also open source) generates JVM bytecode, and allows you to freely mix Java and Python classes. There is no Global Interpreter Lock in JPython ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From invalid at invalid Thu Feb 19 15:44:00 2009 From: invalid at invalid (Grant Edwards) Date: Thu, 19 Feb 2009 14:44:00 -0600 Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <28e3612d-2e91-4a91-82cb-5fb2deda95fd@q9g2000yqc.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> Message-ID: <19idnYERhNYNWQDUnZ2dnUVZ_vqdnZ2d@posted.visi> On 2009-02-19, Steve Holden wrote: > By the way, since you have chosen Java you might be interested > to know that the JPython implementation (also open source) > generates JVM bytecode, and allows you to freely mix Java and > Python classes. > > There is no Global Interpreter Lock in JPython ... I think somebody should propose adding one. It would be a nice change of pace from the standard never-ending thread(s) on the GIL. -- Grant Edwards grante Yow! I'm into SOFTWARE! at visi.com From steve at holdenweb.com Thu Feb 19 15:47:48 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 19 Feb 2009 15:47:48 -0500 Subject: Regression test test_site failed on current trunk In-Reply-To: References: Message-ID: Andy wrote: > Hi, > > I checked out the python trunk (curently 2.7a0), compiled it on my > linux machine and run the regression test suit. Below is the output of > the failed part: > > test_site > [14871 refs] > test test_site failed -- Traceback (most recent call last): > File "/mybook/storage/python_lnx/Lib/test/test_site.py", line 105, > in test_s_option > self.assertEqual(rc, 1) > AssertionError: 0 != 1 > > Is this something serious. > I'd say any test failure without an obvious explanation is serious enough to report as a bug. See http://bugs.python.org/ > I compiled python with: > ./configure --prefix=/dev/null --with-pydebug > make -s > > Further I've got problems with moving the cursor when I started python > (2.7a0). There are only esc sequences displayed. My Local installation > (2.5.2) works fine. Do you mean you can't get previous lines in your Python command history to show up? This sounds as though you may not have built the readline support in to your experimental build. I can't remember exactly what the deal is, but I know that readline is GPL licensed, so it may not come as part of the standard distribution. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From garrickp at gmail.com Thu Feb 19 15:48:37 2009 From: garrickp at gmail.com (Falcolas) Date: Thu, 19 Feb 2009 12:48:37 -0800 (PST) Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <28e3612d-2e91-4a91-82cb-5fb2deda95fd@q9g2000yqc.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> <7x8wo2kwoz.fsf@ruckus.brouhaha.com> Message-ID: <975d0b81-0810-43c2-9734-b7a5a890e431@k19g2000prh.googlegroups.com> On Feb 19, 1:18?pm, Paul Rubin wrote: > ... ?If such > speedups were useless or unimportant, we would not have blown our hard > earned cash replacing perfectly good older hardware, so we have to > accept the concept that speed matters and ignore those platitudes that > say otherwise. That's fair, but by using a high level language in the first place, you've already made the conscious decision to sacrifice speed for ease of programming. Otherwise, you would probably be programming in C. The question really is "Is it fast enough", and the answer usually is "Yes". And when the answer is "No", there are many things which can be done before the need to multi-thread the whole script comes about. It's a proposition that used to bother me, until I did some actual programming of real world problems in Python. I've yet to really find a case where the application was slow enough to justify the cost of using multiple Python processes. ~G From frankrentef at yahoo.com Thu Feb 19 15:50:27 2009 From: frankrentef at yahoo.com (frankrentef) Date: Thu, 19 Feb 2009 12:50:27 -0800 (PST) Subject: Newbie request assistance....Python - PAMIE - Java Message-ID: Greetings all... Newbie here to the Python world. I've written some basic script with the purpose of automating testing of an application via Python / Pamie. I've had pretty good success until a spot I'm testing displays a Java pop up. I need to have Pamie access the fields in the window (i.e. add a value and activate the "enter" button.) Can someone assist. Some of the code I have currently is as follows...when the script I've written gets to the end the java window pops up automatically....I don't understand how to interface with it. THNX ie.textBoxSet('_ctl0_ContentPlaceHolder1_Bocarc1_txtMAX', '5000.00') time.sleep(2) ie.textBoxSet('_ctl0_ContentPlaceHolder1_Bocarc1_txtMIN', '0') time.sleep(2) ie.buttonClick('_ctl0_ContentPlaceHolder1_Bocarc1_ckCheckMicr') time.sleep(2) ie.buttonClick('_ctl0_ContentPlaceHolder1_Bocarc1_ckCheckMicr') ie.timesleep(2) ie.textBoxSet('_ctl0_ContentPlaceHolder1_Bocarc1_txtMaxMicrRejects', '1') time.sleep(2) ie.buttonClick('_ctl0_ContentPlaceHolder1_arc1_btnUpdate') time.sleep2 From lists at cheimes.de Thu Feb 19 15:54:34 2009 From: lists at cheimes.de (Christian Heimes) Date: Thu, 19 Feb 2009 21:54:34 +0100 Subject: Explanation for trailing comma in example from Learning Python? In-Reply-To: <499DB73D.1010208@fnal.gov> References: <499DB73D.1010208@fnal.gov> Message-ID: Carl Schumann wrote: > I could see the logic in always or never having a trailing comma. What > I don't understand here is why only the single element case has a > trailing comma. Any explanations please? Does this code shad some light on the trailing comma? :) >>> (1) == 1 True >>> (1,) == 1 False >>> type((1)) >>> type((1,)) >>> a = 1 >>> a 1 >>> a = (1) >>> a 1 >>> a = (1,) >>> a (1,) >>> a = 1, >>> a (1,) From rt8396 at gmail.com Thu Feb 19 15:54:34 2009 From: rt8396 at gmail.com (r) Date: Thu, 19 Feb 2009 12:54:34 -0800 (PST) Subject: Python 3D CAD -- need collaborators, or just brave souls :) References: <4993DE39.8030200@cosc.canterbury.ac.nz> <9ef65856-0f62-4434-a4b4-e15558e7c7b0@n2g2000vba.googlegroups.com> Message-ID: <5764d607-e323-4996-aa6f-a7f04c779110@i38g2000yqd.googlegroups.com> On Feb 19, 2:29?am, Lie wrote: > On Feb 18, 8:02?pm, r wrote: > Blender's UI is designed for effective and efficient 3D workflow, not > for low learning curve. And that will be it's downfall! I know what what Blenders UI is designed for. However not too many people get religious about learning a UI, which is the only way you will ever learn Blenders UI. This is why although Blender has a cult following, it will never grow into a tool that the mainstream world knows about, or for that matter cares about. I have been using Blender on and off for almost a year and i still cannot get comfortable with the UI. For instance adding a material to a object involves multiple steps between multiple windows (WHAT!). Go take a look at SketchUp's UI and you will see how the future will look. Even 3DS or Maya is easier to learn that Blender. From aleksandr.goretoy at gmail.com Thu Feb 19 15:57:54 2009 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Thu, 19 Feb 2009 14:57:54 -0600 Subject: Explanation for trailing comma in example from Learning Python? In-Reply-To: References: <499DB73D.1010208@fnal.gov> Message-ID: Thank you for clerification Christian, when using trailing comma with print statement/function, does it not mean to output newline after printed data? -Alex Goretoy http://www.goretoy.com On Thu, Feb 19, 2009 at 2:54 PM, Christian Heimes wrote: > Carl Schumann wrote: > > I could see the logic in always or never having a trailing comma. What > > I don't understand here is why only the single element case has a > > trailing comma. Any explanations please? > > Does this code shad some light on the trailing comma? :) > > >>> (1) == 1 > True > >>> (1,) == 1 > False > >>> type((1)) > > >>> type((1,)) > > > >>> a = 1 > >>> a > 1 > >>> a = (1) > >>> a > 1 > >>> a = (1,) > >>> a > (1,) > >>> a = 1, > >>> a > (1,) > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Thu Feb 19 15:58:29 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 19 Feb 2009 12:58:29 -0800 Subject: "metaclass conflict" error: where is noconflict ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF60E68800F@enbmail01.lsi.com> References: <7F0503CD69378F49BE0DC30661C6CCF60E68800F@enbmail01.lsi.com> Message-ID: <50697b2c0902191258ye5aa478gecaf7b7b097e3eba@mail.gmail.com> On Thu, Feb 19, 2009 at 5:01 AM, Barak, Ron wrote: > Hi, > > I have a class derived from two parents (in blue below), which gives me the > following error: > > $ python -u ./failover_pickle_demo09.py > Traceback (most recent call last): > File "./failover_pickle_demo09.py", line 291, in > class ListControl(wx.Frame, CopyAndPaste): > TypeError: Error when calling the metaclass bases > metaclass conflict: the metaclass of a derived class must be a > (non-strict) subclass of the metaclasses of all its bases > Googling suggested I should add > from noconflict import classmaker > and > > __metaclass__=classmaker() > to this class. > > However, I don't seem able to find where to get the noconflict module from. > > Do any of you where noconflict could be downloaded/installed from ? >From what I could google, you should in theory be able to fix the problem (without using any 3rd party module) by doing: class ListControlMeta(type(wx.Frame), type(CopyAndPaste)): pass class ListControl(wx.Frame, CopyAndPaste): __metaclass__ = ListControlMeta #rest of class... Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From mabdelkader at gmail.com Thu Feb 19 16:01:55 2009 From: mabdelkader at gmail.com (ma) Date: Thu, 19 Feb 2009 16:01:55 -0500 Subject: Explanation for trailing comma in example from Learning Python? In-Reply-To: References: <499DB73D.1010208@fnal.gov> Message-ID: <148918f0902191301n362878dbo20d868c662db168e@mail.gmail.com> A comma is what generates a tuple. It's not the parenthesis;) http://docs.python.org/library/stdtypes.html#typesseq "A single item tuple must have a trailing comma, such as (d,)." On Thu, Feb 19, 2009 at 3:57 PM, alex goretoy wrote: > Thank you for clerification Christian, > when using trailing comma with print statement/function, does it not mean > to output newline after printed data? > > -Alex Goretoy > http://www.goretoy.com > > > > > On Thu, Feb 19, 2009 at 2:54 PM, Christian Heimes wrote: > >> Carl Schumann wrote: >> > I could see the logic in always or never having a trailing comma. What >> > I don't understand here is why only the single element case has a >> > trailing comma. Any explanations please? >> >> Does this code shad some light on the trailing comma? :) >> >> >>> (1) == 1 >> True >> >>> (1,) == 1 >> False >> >>> type((1)) >> >> >>> type((1,)) >> >> >> >>> a = 1 >> >>> a >> 1 >> >>> a = (1) >> >>> a >> 1 >> >>> a = (1,) >> >>> a >> (1,) >> >>> a = 1, >> >>> a >> (1,) >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rNOSPAMon at flownet.com Thu Feb 19 16:02:39 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Thu, 19 Feb 2009 13:02:39 -0800 Subject: Regular expression bug? References: Message-ID: In article , MRAB wrote: > Ron Garret wrote: > > I'm trying to split a CamelCase string into its constituent components. > > This kind of works: > > > >>>> re.split('[a-z][A-Z]', 'fooBarBaz') > > ['fo', 'a', 'az'] > > > > but it consumes the boundary characters. To fix this I tried using > > lookahead and lookbehind patterns instead, but it doesn't work: > > > >>>> re.split('((?<=[a-z])(?=[A-Z]))', 'fooBarBaz') > > ['fooBarBaz'] > > > > However, it does seem to work with findall: > > > >>>> re.findall('(?<=[a-z])(?=[A-Z])', 'fooBarBaz') > > ['', ''] > > > > So the regular expression seems to be doing the Right Thing. Is this a > > bug in re.split, or am I missing something? > > > > (BTW, I tried looking at the source code for the re module, but I could > > not find the relevant code. re.split calls sre_compile.compile().split, > > but the string 'split' does not appear in sre_compile.py. So where does > > this method come from?) > > > > I'm using Python2.5. > > > I, amongst others, think it's a bug (or 'misfeature'); Guido thinks it > might be intentional, but changing it could break some existing code. That seems unlikely. It would only break where people had code invoking re.split on empty matches, which at the moment is essentially a no-op. It's hard to imagine there's a lot of code like that around. What would be the point? > You could do this instead: > > >>> re.sub('(?<=[a-z])(?=[A-Z])', '@', 'fooBarBaz').split('@') > ['foo', 'Bar', 'Baz'] Blech! ;-) But thanks for the suggestion. rg From rNOSPAMon at flownet.com Thu Feb 19 16:03:59 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Thu, 19 Feb 2009 13:03:59 -0800 Subject: Regular expression bug? References: Message-ID: In article , Peter Otten <__peter__ at web.de> wrote: > Ron Garret wrote: > > > I'm trying to split a CamelCase string into its constituent components. > > How about > > >>> re.compile("[A-Za-z][a-z]*").findall("fooBarBaz") > ['foo', 'Bar', 'Baz'] That's very clever. Thanks! > > (BTW, I tried looking at the source code for the re module, but I could > > not find the relevant code. re.split calls sre_compile.compile().split, > > but the string 'split' does not appear in sre_compile.py. So where does > > this method come from?) > > It's coded in C. The source is Modules/sremodule.c. Ah. Thanks! rg From clp2 at rebertia.com Thu Feb 19 16:04:34 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 19 Feb 2009 13:04:34 -0800 Subject: Explanation for trailing comma in example from Learning Python? In-Reply-To: References: <499DB73D.1010208@fnal.gov> Message-ID: <50697b2c0902191304u5dc6cf4dj797fc724faac2b74@mail.gmail.com> > On Thu, Feb 19, 2009 at 2:54 PM, Christian Heimes wrote: >> >> Carl Schumann wrote: >> > I could see the logic in always or never having a trailing comma. What >> > I don't understand here is why only the single element case has a >> > trailing comma. Any explanations please? >> >> Does this code shad some light on the trailing comma? :) >> >> >>> (1) == 1 >> True >> >>> (1,) == 1 >> False >> >>> type((1)) >> >> >>> type((1,)) >> >> >> >>> a = 1 >> >>> a >> 1 >> >>> a = (1) >> >>> a >> 1 >> >>> a = (1,) >> >>> a >> (1,) >> >>> a = 1, >> >>> a >> (1,) >> On Thu, Feb 19, 2009 at 12:57 PM, alex goretoy wrote: > Thank you for clerification Christian, > when using trailing comma with print statement/function, does it not mean to > output newline after printed data? > > -Alex Goretoy > http://www.goretoy.com Yes it does (it outputs a space instead of a newline), but only with the print-statement, not the print() function. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From rNOSPAMon at flownet.com Thu Feb 19 16:06:32 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Thu, 19 Feb 2009 13:06:32 -0800 Subject: Regular expression bug? References: Message-ID: In article , "andrew cooke" wrote: > i wonder what fraction of people posting with "bug?" in their titles here > actually find bugs? IMHO it ought to be an invariant that len(r.split(s)) should always be one more than len(r.findall(s)). > anyway, how about: > > re.findall('[A-Z]?[a-z]*', 'fooBarBaz') > > or > > re.findall('([A-Z][a-z]*|[a-z]+)', 'fooBarBaz') That will do it. Thanks! rg From rNOSPAMon at flownet.com Thu Feb 19 16:08:19 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Thu, 19 Feb 2009 13:08:19 -0800 Subject: Regular expression bug? References: Message-ID: In article , Albert Hopkins wrote: > On Thu, 2009-02-19 at 10:55 -0800, Ron Garret wrote: > > I'm trying to split a CamelCase string into its constituent components. > > This kind of works: > > > > >>> re.split('[a-z][A-Z]', 'fooBarBaz') > > ['fo', 'a', 'az'] > > > > but it consumes the boundary characters. To fix this I tried using > > lookahead and lookbehind patterns instead, but it doesn't work: > > That's how re.split works, same as str.split... I think one could make the argument that 'foo'.split('') ought to return ['f','o','o'] > > > >>> re.split('((?<=[a-z])(?=[A-Z]))', 'fooBarBaz') > > ['fooBarBaz'] > > > > However, it does seem to work with findall: > > > > >>> re.findall('(?<=[a-z])(?=[A-Z])', 'fooBarBaz') > > ['', ''] > > > Wow! > > To tell you the truth, I can't even read that... It's a regexp. Of course you can't read it. ;-) rg From steve at holdenweb.com Thu Feb 19 16:08:37 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 19 Feb 2009 16:08:37 -0500 Subject: Explanation for trailing comma in example from Learning Python? In-Reply-To: References: <499DB73D.1010208@fnal.gov> Message-ID: alex goretoy wrote: > Thank you for clerification Christian, > when using trailing comma with print statement/function, does it not > mean to output newline after printed data? > It does (in Python before 3.0) - but that has nothing to do with the original question. You will find you get quite different results for print 1, # print integer 1 followed by no newline and print (1, ) # print the one-element tuple whose element # is the integer 1, followed by a newline. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From lionel.keene at gmail.com Thu Feb 19 16:31:51 2009 From: lionel.keene at gmail.com (Lionel) Date: Thu, 19 Feb 2009 13:31:51 -0800 (PST) Subject: numpy.memmap advice? References: <59449976-a334-411a-bdc8-7e6041bd4a37@g1g2000pra.googlegroups.com> <66395359-fca2-4e31-8ff9-5fbf51654d1b@v38g2000yqb.googlegroups.com> <10c6209b-5f23-4709-840f-ade7b734be8b@s24g2000vbp.googlegroups.com> <3008b9b3-9e23-4fc2-bd5d-286da7c0953f@u39g2000prn.googlegroups.com> Message-ID: <32a9bd0a-4355-4a02-819c-8ed90b7e8256@g1g2000pra.googlegroups.com> On Feb 19, 12:26?pm, Carl Banks wrote: > On Feb 19, 10:36?am, Lionel wrote: > > > > > > > On Feb 19, 9:51?am, Carl Banks wrote: > > > > On Feb 19, 9:34?am, Lionel wrote: > > > > > On Feb 18, 12:35?pm, Carl Banks wrote: > > > > > > On Feb 18, 10:48?am, Lionel wrote: > > > > > > > Thanks Carl, I like your solution. Am I correct in my understanding > > > > > > that memory is allocated at the slicing step in your example i.e. when > > > > > > "reshaped_data" is sliced using "interesting_data = reshaped_data[:, > > > > > > 50:100]"? In other words, given a huge (say 1Gb) file, a memmap object > > > > > > is constructed that memmaps the entire file. Some relatively small > > > > > > amount of memory is allocated for the memmap operation, but the bulk > > > > > > memory allocation occurs when I generate my final numpy sub-array by > > > > > > slicing, and this accounts for the memory efficiency of using memmap? > > > > > > No, what accounts for the memory efficienty is there is no bulk > > > > > allocation at all. ?The ndarray you have points to the memory that's > > > > > in the mmap. ?There is no copying data or separate array allocation. > > > > > Does this mean that everytime I iterate through an ndarray that is > > > > sourced from a memmap, the data is read from the disc? The sliced > > > > array is at no time wholly resident in memory? What are the > > > > performance implications of this? > > > > Ok, sorry for the confusion. ?What I should have said is that there is > > > no bulk allocation *by numpy* at all. ?The call to mmap does allocate > > > a chunk of RAM to reflect file contents, but the numpy arrays don't > > > allocate any memory of their own: they use the same memory as was > > > allocated by the mmap call. > > > > Carl Banks- Hide quoted text - > > > > - Show quoted text - > > > Thanks for the explanations Carl. I'm sorry, but it's me who's the > > confused one here, not anyone else :-) > > > I hate to waste everyone's time again, but something is just not > > "clicking" in that black-hole I call a brain. So..."numpy.memmap" > > allocates a chunk off the heap to coincide with the file contents. If > > I memmap the entire 1 Gb file, a corresponding amount (approx. 1 Gb) > > is allocated? That seems to contradict what is stated in the numpy > > documentation: > > > "class numpy.memmap > > Create a memory-map to an array stored in a file on disk. > > > Memory-mapped files are used for accessing small segments of large > > files on disk, without reading the entire file into memory." > > Yes, it allocates room for the whole file in your process's LOGICAL > address space. ?However, it doesn't actually reserve any PHYSICAL > memory, or read in any data from the disk, until you've actually > access the data. ?And then it only reads small chunks in, not the > whole file. > > So when you mmap your 1GB file, the OS sets aside a 1 GB chunk of > address to use for your memory map. ?That's all it does: it doesn't > read anything from disk, it doesn't reserve any physical RAM. ?Later, > when you access a byte in the mmap via a pointer, the OS notes that it > hasn't yet loaded the data at that address, so it grabs a small chunk > of physical ram and reads in the a small amount of data from the disk > containing the byte you are accessing. ?This all happens automatically > and transparently to you. > > > In my previous example that we were working with (100x100 data file), > > you used an offset to memmap the "lower-half" of the array. Does this > > mean that in the process of memmapping that lower half, RAM was set > > aside for 50x100 32-bit complex numbers? If so, and I decide to memmap > > an entire file, there is no memory benefit in doing so. > > The mmap call sets aside room for all 100x100 32-bit complex numbers > in logical address space, regardless of whether you use the offset > parameter or not. ?However, it might only read in part of the file in > from disk, and will only reserve physical RAM for the parts it reads > in. > > > At this point do you (or anyone else) recommend I just write a little > > function for my class that takes the coords I intend to load and "roll > > my own" function? Seems like the best way to keep memory to a minimum, > > I'm just worried about performance. On the other hand, the most I'd be > > loading would be around 1k x 1k worth of data.- > > No, if your file is not too large to mmap, just do it the way you've > been doing it. ?The documentation you've been reading is pretty much > correct, even if you approach it naively. ?It is both memory and I/O > efficient. ?You're overthinking things here; don't try to outsmart the > operating system. ?It'll take care of the performance issues > satisfactorily. > > The only thing you have to worry about is if the file is too large to > fit into your process's logical address space, which on a typical 32- > bit system is 2-3 GB (depending on configuration) minus the space > occupied by Python and other heap objects, which is probably only a > few MB. > > Carl Banks- Hide quoted text - > > - Show quoted text - I see. That was very well explained Carl, thank you. From andreas.schawo at googlemail.com Thu Feb 19 16:47:23 2009 From: andreas.schawo at googlemail.com (Andy) Date: Thu, 19 Feb 2009 13:47:23 -0800 (PST) Subject: Regression test test_site failed on current trunk References: Message-ID: On 19 Feb., 21:47, Steve Holden wrote: > Do you mean you can't get previous lines in your Python command history > to show up? This sounds as though you may not have built the readline > support in to your experimental build. I can't remember exactly what the > deal is, but I know that readline is GPL licensed, so it may not come as > part of the standard distribution. Thanks for your reply. I just want to move left and right with the cursor keys. Thats it. I installed libreadline5-dev and rerun ./configure and make ...now it works. From oamram at gmail.com Thu Feb 19 16:56:38 2009 From: oamram at gmail.com (oamram) Date: Thu, 19 Feb 2009 13:56:38 -0800 (PST) Subject: iterating through files Message-ID: <22048070.post@talk.nabble.com> Hi Pythonist, new to python. i have a directory with about 50 text file and i need to iterate through them and get line 7 to 11 from each file and write those lines into another file(one file that will contain all lines). Cheers, Omer. -- View this message in context: http://www.nabble.com/iterating-through-files-tp22048070p22048070.html Sent from the Python - python-list mailing list archive at Nabble.com. From woodygar at sky.com Thu Feb 19 17:07:01 2009 From: woodygar at sky.com (Gary Wood) Date: Thu, 19 Feb 2009 22:07:01 -0000 Subject: No subject Message-ID: <6307CF549D1943C0802D29730A70BD99@Woodygar> I'm stuck on a tutorial Hands on Python3 Exercise 1.13.7.3. ** Complete the following function. This starting code is in joinAllStub.py. Save it to the new name joinAll.py. Note the way an example is given in the documentation string. It simulates the use of the function in the Shell. This is a common convention: import string '''exercise to complete and test this function''' def joinStrings(sentance): '''Join all the strings in stringList into one string, and return the result. For example: >>> print joinStrings(['very', 'hot', 'day']) 'veryhotday' ''' # finish the code for this function # i tried this but not sure whats mising for i in sentance: print(i) #this worked for numbers # def sumList(nums): #1 # '''Return the sum of the numbers in nums.''' #sum = 0 #2 # for num in nums: #3 # sum = sum + num #4 # return sum def main(): print(joinStrings(['very','hot' ,'day'])) print(joinStrings(['this', 'is', 'it'])) print(joinStrings(['1', '2', '3', '4', '5'])) main() -------------- next part -------------- An HTML attachment was scrubbed... URL: From http Thu Feb 19 17:11:31 2009 From: http (Paul Rubin) Date: 19 Feb 2009 14:11:31 -0800 Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <28e3612d-2e91-4a91-82cb-5fb2deda95fd@q9g2000yqc.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> <7x8wo2kwoz.fsf@ruckus.brouhaha.com> <975d0b81-0810-43c2-9734-b7a5a890e431@k19g2000prh.googlegroups.com> Message-ID: <7x3aeadqlo.fsf@ruckus.brouhaha.com> Falcolas writes: > That's fair, but by using a high level language in the first place, > you've already made the conscious decision to sacrifice speed for ease > of programming. Otherwise, you would probably be programming in C. That Python is so much slower than C is yet another area where Python can use improvement. > It's a proposition that used to bother me, until I did some actual > programming of real world problems in Python. I've yet to really find > a case where the application was slow enough to justify the cost of > using multiple Python processes. Right, that's basically the issue here: the cost of using multiple Python processes is unnecessarily high. If that cost were lower then we could more easily use multiple cores to make oru apps faster. From clp2 at rebertia.com Thu Feb 19 17:11:48 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 19 Feb 2009 14:11:48 -0800 Subject: No subject In-Reply-To: <6307CF549D1943C0802D29730A70BD99@Woodygar> References: <6307CF549D1943C0802D29730A70BD99@Woodygar> Message-ID: <50697b2c0902191411q61ef08d2tb3de31aaf152b78a@mail.gmail.com> On Thu, Feb 19, 2009 at 2:07 PM, Gary Wood wrote: > I'm stuck on a tutorial Hands on Python3 > > Exercise 1.13.7.3. ** Complete the following function. This starting code is > in joinAllStub.py. Save it to the new name joinAll.py. Note the way an > example is given in the documentation string. It simulates the use of the > function in the Shell. This is a common convention: > > import string > '''exercise to complete and test this function''' > def joinStrings(sentance): > '''Join all the strings in stringList into one string, > and return the result. For example: > >>> print joinStrings(['very', 'hot', 'day']) > 'veryhotday' > ''' > # finish the code for this function > # i tried this but not sure whats mising > for i in sentance: > print(i) You're not supposed to output the strings, you've supposed to combine them and return the single combined string (it's nearly identical to how you summed the numbers). The printing is done by the calls to print() outside of this function. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From rushenaly at gmail.com Thu Feb 19 17:18:34 2009 From: rushenaly at gmail.com (rushenaly at gmail.com) Date: Thu, 19 Feb 2009 14:18:34 -0800 (PST) Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <28e3612d-2e91-4a91-82cb-5fb2deda95fd@q9g2000yqc.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> <7x8wo2kwoz.fsf@ruckus.brouhaha.com> <975d0b81-0810-43c2-9734-b7a5a890e431@k19g2000prh.googlegroups.com> Message-ID: Hi again I really want to imply that i am not in search of a perfect language. Python for programming productivity is a great language but there are some real world facts. Some people want a language that provides great flexibility. A language can provide threads and processes and programmer choose the way. I really believe that GIL is a design error. Thanks. Rushen From vriolk at gmail.com Thu Feb 19 17:20:14 2009 From: vriolk at gmail.com (coldpizza) Date: Thu, 19 Feb 2009 14:20:14 -0800 (PST) Subject: Tkinter: stopping a background thread on demand Message-ID: <03c4679e-014d-4fc7-976e-ba52312f99c2@41g2000yqf.googlegroups.com> I am writing a Tk GUI for a console script. I start a background thread and pass it a callback function which writes debug info to a Text widget in the main Tk loop. I tried to find what is the established way to cleanly abort a child thread when the user clicks the Stop button, but apparently Python does not allow the parent process to explicitly stop a child thread. Also I could not figure out how a parent can send a signal for a child to stop and let it cleanup and exit cleanly. I finally figured out a solution which was to set a 'TERMINATE' flag on the `func_dict` property of the callback function, and then check for the flag in the child module, but I still have doubts that this is the proper way to do this sort of thing. This works fine but it looks more like a dirty hack to me so my question is: what is the proper way to send a signal to a child thread to gracefully terminate, assuming the user decided to cancel an operation? from Tkinter import * import threading root = Tk() class ConverterThread(threading.Thread): def __init__(self, source, target, callbackFunc): threading.Thread.__init__(self, name='converterThread') self.infile = srcName self.outfile = destName self.callbackFunc = callbackFunc def run(self): import myconverter myconverter.convert(self.infile, self.outfile, self.callbackFunc) def stopConversion(event=None): global job if (job and job.isAlive()): callbackFunc.func_dict['TERMINATE'] = True job = None def updateLogCallback(data=None): log.insert(END, str(data)) log.see('end') job = ConverterThread(src='file1', dest='file2, updateLogCallback) job.start() stopBtn = Button(root, text="Stop", command=stopConversion) stopBtn.pack() log = Text(root) root.mainloop() And the callbackFunc in myConverter.py looks like this: def printCallback(data): if (callback): callback(data) if callback.func_dict['TERMINATE'] == True: clean_up() sys.exit() else: print data From kyosohma at gmail.com Thu Feb 19 17:22:21 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Thu, 19 Feb 2009 14:22:21 -0800 (PST) Subject: iterating through files References: Message-ID: <8bba10d2-ac74-4ba0-a731-744238b77139@l39g2000yqn.googlegroups.com> On Feb 19, 3:56?pm, oamram wrote: > Hi Pythonist, > new to python. i have a directory with about 50 text file and i need to > iterate through them and get > line 7 to 11 from each file and write those lines into another file(one file > that will contain all lines). > > Cheers, Omer. > -- > View this message in context:http://www.nabble.com/iterating-through-files-tp22048070p22048070.html > Sent from the Python - python-list mailing list archive at Nabble.com. I would recommend using the glob module to grab a list of the files you want or you can just create your own list. Then use a loop to grab the lines you want. Something like this: f = open(textFile) newFile = open(newFileName, "a") x = 1 for line in f.readlines(): if x >=7 and x <=11: newFile.write(line + "\n") You could even put the above inside a loop that loops over the list of files. Anyway, that's one approach. I'm sure there are many others. Mike From kyosohma at gmail.com Thu Feb 19 17:28:25 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Thu, 19 Feb 2009 14:28:25 -0800 (PST) Subject: iterating through files References: <8bba10d2-ac74-4ba0-a731-744238b77139@l39g2000yqn.googlegroups.com> Message-ID: On Feb 19, 4:22?pm, Mike Driscoll wrote: > On Feb 19, 3:56?pm, oamram wrote: > > > Hi Pythonist, > > new to python. i have a directory with about 50 text file and i need to > > iterate through them and get > > line 7 to 11 from each file and write those lines into another file(one file > > that will contain all lines). > > > Cheers, Omer. > > -- > > View this message in context:http://www.nabble.com/iterating-through-files-tp22048070p22048070.html > > Sent from the Python - python-list mailing list archive at Nabble.com. > > I would recommend using the glob module to grab a list of the files > you want or you can just create your own list. Then use a loop to grab > the lines you want. Something like this: > > f = open(textFile) > newFile = open(newFileName, "a") > x = 1 > for line in f.readlines(): > ? ? if x >=7 and x <=11: > ? ? ? ? ?newFile.write(line + "\n") > > You could even put the above inside a loop that loops over the list of > files. Anyway, that's one approach. I'm sure there are many others. > > Mike Oops...I forgot to iterate the counter. The code should look like this: f = open(textFile) newFile = open(newFileName, "a") x = 1 for line in f.readlines(): if x >=7 and x <=11: newFile.write(line + "\n") x +=1 Sorry about that. Mike From clp2 at rebertia.com Thu Feb 19 17:33:55 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 19 Feb 2009 14:33:55 -0800 Subject: iterating through files In-Reply-To: References: <8bba10d2-ac74-4ba0-a731-744238b77139@l39g2000yqn.googlegroups.com> Message-ID: <50697b2c0902191433k572b4c90v9bd05d815ae72eee@mail.gmail.com> On Thu, Feb 19, 2009 at 2:28 PM, Mike Driscoll wrote: > On Feb 19, 4:22 pm, Mike Driscoll wrote: >> On Feb 19, 3:56 pm, oamram wrote: >> >> > Hi Pythonist, >> > new to python. i have a directory with about 50 text file and i need to >> > iterate through them and get >> > line 7 to 11 from each file and write those lines into another file(one file >> > that will contain all lines). >> >> > Cheers, Omer. >> > -- >> > View this message in context:http://www.nabble.com/iterating-through-files-tp22048070p22048070.html >> > Sent from the Python - python-list mailing list archive at Nabble.com. >> >> I would recommend using the glob module to grab a list of the files >> you want or you can just create your own list. Then use a loop to grab >> the lines you want. Something like this: >> >> f = open(textFile) >> newFile = open(newFileName, "a") >> x = 1 >> for line in f.readlines(): >> if x >=7 and x <=11: >> newFile.write(line + "\n") >> >> You could even put the above inside a loop that loops over the list of >> files. Anyway, that's one approach. I'm sure there are many others. >> >> Mike > > Oops...I forgot to iterate the counter. The code should look like > this: > > > > f = open(textFile) > newFile = open(newFileName, "a") > x = 1 > for line in f.readlines(): > if x >=7 and x <=11: > newFile.write(line + "\n") > x +=1 > > Or you could use enumerate(); also, readlines() isn't necessary: f = open(textFile) newFile = open(newFileName, "a") for x, line in enumerate(f): if x >=7 and x <=11: newFile.write(line + "\n") Sounds a bit like homework to me though... Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From tim.wintle at teamrubber.com Thu Feb 19 17:35:19 2009 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Thu, 19 Feb 2009 22:35:19 +0000 Subject: Will multithreading make python less popular? In-Reply-To: <975d0b81-0810-43c2-9734-b7a5a890e431@k19g2000prh.googlegroups.com> References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <28e3612d-2e91-4a91-82cb-5fb2deda95fd@q9g2000yqc.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> <7x8wo2kwoz.fsf@ruckus.brouhaha.com> <975d0b81-0810-43c2-9734-b7a5a890e431@k19g2000prh.googlegroups.com> Message-ID: <1235082919.21735.30.camel@tim-laptop> On Thu, 2009-02-19 at 12:48 -0800, Falcolas wrote: > That's fair, but by using a high level language in the first place, > you've already made the conscious decision to sacrifice speed for ease > of programming. Otherwise, you would probably be programming in C. My parents would have gone mad at me for saying that when I was young - C is just about the highest-level language they ever used - Assembly/hex all the way! So if you really want speed then why don't you write your code in assembly? That's the only "perfect language" - it's capable of doing everything in the most efficient way possible on your machine. Of course that's a hassle, so I guess you may as well use C, since that's almost certainly only linearly worse than using assembly, and it takes far less time to use. Oh, but then you may as well use python, since (again) that's probably only linearly worse than C, and well-programmed C at that - I certainly wouldn't end up with some of the optimisations that have gone into the python interpreter! That's basically what my mind goes through whenever I choose a language to use for a task - and why I almost always end up with Python. > It's a proposition that used to bother me, until I did some actual > programming of real world problems in Python. I've yet to really find > a case where the application was slow enough to justify the cost of > using multiple Python processes. I deal with those situations a fair bit - but the solutions are normally easy - if it's limited by waiting for IO then I use threads, if it's limited by waiting for CPU time then I use multiple processes, or share the job over another application (such as MySQL), or run a task over a cluster. If you have a task where the linear optimisation offered by multiple cores is really important then you can either: * Run it over multiple processes, or multiple machines in Python or * spend a year writing it in C or assembly, by which time you can buy a new machine that will run it fine in Python. Yes, we're coming to a point where we're going to have tens of cores in a chip, but by that time someone far cleverer than me (possibly someone who's on this list) will have solved that problem. The top experts in many fields use Python, and if they weren't able to make use of multiple core chips, then there wouldn't be any demand for them. Tim Wintle > > ~G > -- > http://mail.python.org/mailman/listinfo/python-list From digitig at gmail.com Thu Feb 19 17:35:38 2009 From: digitig at gmail.com (Tim Rowe) Date: Thu, 19 Feb 2009 22:35:38 +0000 Subject: Will multithreading make python less popular? In-Reply-To: <7x3aeadqlo.fsf@ruckus.brouhaha.com> References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> <7x8wo2kwoz.fsf@ruckus.brouhaha.com> <975d0b81-0810-43c2-9734-b7a5a890e431@k19g2000prh.googlegroups.com> <7x3aeadqlo.fsf@ruckus.brouhaha.com> Message-ID: 2009/2/19 Paul Rubin : > That Python is so much slower than C is yet another area where Python > can use improvement. No, because we don't use Python where C would be more appropriate. Sure nobody would complain if Python were faster, but it's not for speed that we choose Python. Not speed of /execution/ that is. Different languages have different trade-offs. Python's trade-offs suit us. If they don't suit you, use a language with trade-offs that do. -- Tim Rowe From digitig at gmail.com Thu Feb 19 17:37:02 2009 From: digitig at gmail.com (Tim Rowe) Date: Thu, 19 Feb 2009 22:37:02 +0000 Subject: Will multithreading make python less popular? In-Reply-To: References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> <7x8wo2kwoz.fsf@ruckus.brouhaha.com> <975d0b81-0810-43c2-9734-b7a5a890e431@k19g2000prh.googlegroups.com> Message-ID: 2009/2/19 : > Hi again > > I really want to imply that i am not in search of a perfect language. > Python for programming productivity is a great language but there are > some real world facts. Some people want a language that provides great > flexibility. A language can provide threads and processes and > programmer choose the way. I really believe that GIL is a design > error. It's only an error if it gets in the way. It's the experience of a lot of programmers that it doesn't, so it's not an error. -- Tim Rowe From steve at holdenweb.com Thu Feb 19 17:53:40 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 19 Feb 2009 17:53:40 -0500 Subject: Will multithreading make python less popular? In-Reply-To: References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> <7x8wo2kwoz.fsf@ruckus.brouhaha.com> <975d0b81-0810-43c2-9734-b7a5a890e431@k19g2000prh.googlegroups.com> Message-ID: Tim Rowe wrote: > 2009/2/19 : >> Hi again >> >> I really want to imply that i am not in search of a perfect language. >> Python for programming productivity is a great language but there are >> some real world facts. Some people want a language that provides great >> flexibility. A language can provide threads and processes and >> programmer choose the way. I really believe that GIL is a design >> error. > > It's only an error if it gets in the way. It's the experience of a lot > of programmers that it doesn't, so it's not an error. > And it's not a feature of the language, rather of one or two implementations. Neither JPython not IronPython use a GIL to the best of my knowledge, so you are still quite at liberty to use them. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Thu Feb 19 17:56:30 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 19 Feb 2009 17:56:30 -0500 Subject: iterating through files In-Reply-To: <50697b2c0902191433k572b4c90v9bd05d815ae72eee@mail.gmail.com> References: <8bba10d2-ac74-4ba0-a731-744238b77139@l39g2000yqn.googlegroups.com> <50697b2c0902191433k572b4c90v9bd05d815ae72eee@mail.gmail.com> Message-ID: Chris Rebert wrote: > On Thu, Feb 19, 2009 at 2:28 PM, Mike Driscoll wrote: >> On Feb 19, 4:22 pm, Mike Driscoll wrote: >>> On Feb 19, 3:56 pm, oamram wrote: >>> >>>> Hi Pythonist, >>>> new to python. i have a directory with about 50 text file and i need to >>>> iterate through them and get >>>> line 7 to 11 from each file and write those lines into another file(one file >>>> that will contain all lines). >>>> Cheers, Omer. >>>> -- >>>> View this message in context:http://www.nabble.com/iterating-through-files-tp22048070p22048070.html >>>> Sent from the Python - python-list mailing list archive at Nabble.com. >>> I would recommend using the glob module to grab a list of the files >>> you want or you can just create your own list. Then use a loop to grab >>> the lines you want. Something like this: >>> >>> f = open(textFile) >>> newFile = open(newFileName, "a") >>> x = 1 >>> for line in f.readlines(): >>> if x >=7 and x <=11: >>> newFile.write(line + "\n") >>> >>> You could even put the above inside a loop that loops over the list of >>> files. Anyway, that's one approach. I'm sure there are many others. >>> >>> Mike >> Oops...I forgot to iterate the counter. The code should look like >> this: >> >> >> >> f = open(textFile) >> newFile = open(newFileName, "a") >> x = 1 >> for line in f.readlines(): >> if x >=7 and x <=11: >> newFile.write(line + "\n") >> x +=1 >> >> > > Or you could use enumerate(); also, readlines() isn't necessary: > > f = open(textFile) > newFile = open(newFileName, "a") > for x, line in enumerate(f): > if x >=7 and x <=11: > newFile.write(line + "\n") > > Sounds a bit like homework to me though... > But all these solutions read the whole file. You should really read six lines throwing them away then read five lines to keep. Since this might be homework I'll not write the code, but it will involve f.next() ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From mensanator at aol.com Thu Feb 19 18:05:22 2009 From: mensanator at aol.com (Mensanator) Date: Thu, 19 Feb 2009 15:05:22 -0800 (PST) Subject: iterating through files References: <8bba10d2-ac74-4ba0-a731-744238b77139@l39g2000yqn.googlegroups.com> <50697b2c0902191433k572b4c90v9bd05d815ae72eee@mail.gmail.com> Message-ID: <3c5040c1-a130-4c51-94f0-08248d6193b6@j10g2000prn.googlegroups.com> On Feb 19, 4:56?pm, Steve Holden wrote: > Chris Rebert wrote: > > On Thu, Feb 19, 2009 at 2:28 PM, Mike Driscoll wrote: > >> On Feb 19, 4:22 pm, Mike Driscoll wrote: > >>> On Feb 19, 3:56 pm, oamram wrote: > > >>>> Hi Pythonist, > >>>> new to python. i have a directory with about 50 text file and i need to > >>>> iterate through them and get > >>>> line 7 to 11 from each file and write those lines into another file(one file > >>>> that will contain all lines). > >>>> Cheers, Omer. > >>>> -- > >>>> View this message in context:http://www.nabble.com/iterating-through-files-tp22048070p22048070.html > >>>> Sent from the Python - python-list mailing list archive at Nabble.com. > >>> I would recommend using the glob module to grab a list of the files > >>> you want or you can just create your own list. Then use a loop to grab > >>> the lines you want. Something like this: > > >>> f = open(textFile) > >>> newFile = open(newFileName, "a") > >>> x = 1 > >>> for line in f.readlines(): > >>> ? ? if x >=7 and x <=11: > >>> ? ? ? ? ?newFile.write(line + "\n") > > >>> You could even put the above inside a loop that loops over the list of > >>> files. Anyway, that's one approach. I'm sure there are many others. > > >>> Mike > >> Oops...I forgot to iterate the counter. The code should look like > >> this: > > >> > > >> f = open(textFile) > >> newFile = open(newFileName, "a") > >> x = 1 > >> for line in f.readlines(): > >> ? ?if x >=7 and x <=11: > >> ? ? ? ? newFile.write(line + "\n") > >> ? ?x +=1 > > >> > > > Or you could use enumerate(); also, readlines() isn't necessary: > > > f = open(textFile) > > newFile = open(newFileName, "a") > > for x, line in enumerate(f): > > ? ? if x >=7 and x <=11: > > ? ? ? ? newFile.write(line + "\n") > > > Sounds a bit like homework to me though... > > But all these solutions read the whole file. ?You should really read six > lines throwing them away then read five lines to keep. It might be useful not to assume every file has at least 11 lines and program accordingly. > > Since this might be homework I'll not write the code, but it will > involve f.next() ... > > regards > ? Steve > -- > Steve Holden ? ? ? ?+1 571 484 6266 ? +1 800 494 3119 > Holden Web LLC ? ? ? ? ? ? ?http://www.holdenweb.com/- Hide quoted text - > > - Show quoted text - From fabiofz at gmail.com Thu Feb 19 18:11:19 2009 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Thu, 19 Feb 2009 20:11:19 -0300 Subject: Pydev 1.4.3 Released Message-ID: Hi All, Pydev and Pydev Extensions 1.4.3 have been released Details on Pydev Extensions: http://www.fabioz.com/pydev Details on Pydev: http://pydev.sf.net Details on its development: http://pydev.blogspot.com Release Highlights in Pydev Extensions: ----------------------------------------------------------------- * Fixed racing conditions in the context-insensitive indexing which could corrupt the index. * Search references working on Eclipse 3.3 and Eclipse 3.4 * Lambda properly treated as a new context for code-analysis * Analysis is now recognizing __name__ * Analysis now marks variables used when accessed with augstore (+=) * Some definitions were not properly indexed on some assign cases Release Highlights in Pydev: ---------------------------------------------- * Interactive console The interpreter to be used can be chosen * New modules can be created from templates * Interpreter configuration improved! o Environment variables can be specified for a given interpreter o Canceling operation now works correctly * Debugger o Variables correctly gotten on Jython 2.1 / 2.2 o Using globals as an union of original globals+locals so that generator expressions can be evaluated o Breakpoints only opened on double-click (no longer on select) * The project preferences are now applied even if the page to configure the project is not visible. * Jython 2.5b1 working (problem with sitecustomize) * Wrap paragraph fixed * Set comprehension working on Python 3.0 parsing * Find definition working when a module outside of the known pythonpath is found * Source folders were not properly found sometimes -- when workspace was not properly refreshed * Invalid modules could get in the memory * Getting the grammar version for a project could be wrong (and could loose its indexing at that time) * Multiple external zip files can be added at once to the pythonpath * nonlocal added to keywords * Fixed annoying problem where cursor was jumping when it shouldn't (outline) * Fixed problem where the breakpoint could be lost (now, playing safe and matching anything in the file if the context cannot be gotten) * Ctrl + 2 + --reindex can be used to reindex all the opened projects if the indexing becomes corrupt * Changing nothing on project config and pressing OK no longer reanalyzes the modules What is PyDev? --------------------------- PyDev is a plugin that enables users to use Eclipse for Python and Jython development -- making Eclipse a first class Python IDE -- It comes with many goodies such as code completion, syntax highlighting, syntax analysis, refactor, debug and many others. Cheers, -- Fabio Zadrozny ------------------------------------------------------ Software Developer Aptana http://aptana.com/python Pydev Extensions http://www.fabioz.com/pydev Pydev - Python Development Enviroment for Eclipse http://pydev.sf.net http://pydev.blogspot.com From tim.wintle at teamrubber.com Thu Feb 19 18:16:32 2009 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Thu, 19 Feb 2009 23:16:32 +0000 Subject: Will multithreading make python less popular? In-Reply-To: <7x8wo2kwoz.fsf@ruckus.brouhaha.com> References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <28e3612d-2e91-4a91-82cb-5fb2deda95fd@q9g2000yqc.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> <7x8wo2kwoz.fsf@ruckus.brouhaha.com> Message-ID: <1235085392.21735.57.camel@tim-laptop> On Thu, 2009-02-19 at 12:18 -0800, Paul Rubin wrote: > If such > speedups were useless or unimportant, we would not have blown our hard > earned cash replacing perfectly good older hardware, so we have to > accept the concept that speed matters and ignore those platitudes that > say otherwise. Kind of agree (although I use a netbook at lot at the moment, and I don't use that because of speed-ups!) > It used to be that new computers were faster than the old ones because > they ran at higher clock rates. That was great, no software changes > at all were required to benefit from the higher speed. Now, they get > the additional speed by having more cores. That's better than nothing > but making use of it requires fixing the GIL. My opinion on this (when talking about personal computers rather than servers) is that: (1) Computers *appear* faster now because they have more cores - you can have one doing the fancy GUI effects of Compiz etc. in the background, while the other core actually does the work. (2) Actual speedups aren't that related to either clock speed or cores at the moment, they're related to the switch to 64-bit processors, the massive increases in RAM and the increase in system bus speeds and other IO (and of course graphics cards). I suspect that the next common increase will be solid state hard disks. e.g. I used to expect my computer to be paging all the time, although I'd try to reduce it - these days I'm really upset when I see I've had to page *anything* to disk! Another massive increase (which I am willing to pay more for with the work I do) is the processor cache - at first it was amazing when we got significant level2 cache advertised on pc equipment, now I can fit massive amounts of code into my 4mb level-2 cache *on my laptop*! That's a huge impact for numerical work. (3) Multiple cores scale processing power linearly at best with the number of cores (since you're normally going to be IO based at some point). Perhaps the GIL will be relaxed a bit, but it's not going to have a massive effect. Tim Wintle From Scott.Daniels at Acm.Org Thu Feb 19 18:19:42 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 19 Feb 2009 15:19:42 -0800 Subject: Threading and tkinter In-Reply-To: References: <492d5db9-3681-4ae8-827e-f2a4f66bee80@v39g2000yqm.googlegroups.com> <90d5e669-e8d1-441e-adff-ddc501d21d26@u13g2000yqg.googlegroups.com> Message-ID: gert wrote: > Hope you do not mind ignoring part of answers, so I can figure out > more why things work the way they are. > This two examples work, what i do not understand is that in function > display i do not have to declare root, v or x ? ... > > x=0 > def weegbrug(): > global x > while True: > x=x+1 > sleep(0.5) > start_new_thread(weegbrug,()) > > def display(): > v.set(x) > root.after(500, lambda:display()) 1) Note that x, v, and root are read and manipulated, but not written. So, they do not need to be declared global (global is only needed to declare writable global names). 2) The last statement could more easily be written: root.after(500, display) ... > root.after(500, lambda:display()) Again you can write this: root.after(500, display) --Scott David Daniels Scott.Daniels at Acm.Org From mensanator at aol.com Thu Feb 19 18:19:51 2009 From: mensanator at aol.com (Mensanator) Date: Thu, 19 Feb 2009 15:19:51 -0800 (PST) Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <28e3612d-2e91-4a91-82cb-5fb2deda95fd@q9g2000yqc.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> <7x8wo2kwoz.fsf@ruckus.brouhaha.com> Message-ID: <52a0375d-4fad-4caa-8328-47b8f30f2395@40g2000prx.googlegroups.com> On Feb 19, 2:18?pm, Paul Rubin wrote: > sturlamolden writes: > > Yes, the GIL prevents Python threads from being used in a certain way. > > But do you really need to use threads like that? Or do you just think > > you do? > > How old is your computer, why did you buy it, and is it the first one > you ever owned? > > For most of us, I suspect, it is not our first one, and we bought it > to get a processing speedup relative to the previous one. ?If such > speedups were useless or unimportant, we would not have blown our hard > earned cash replacing perfectly good older hardware, so we have to > accept the concept that speed matters and ignore those platitudes that > say otherwise. > > It used to be that new computers were faster than the old ones because > they ran at higher clock rates. ?That was great, no software changes > at all were required to benefit from the higher speed. ?Now, they get > the additional speed by having more cores. ?That's better than nothing > but making use of it requires fixing the GIL. When I run I Python program, the Windows task manager shows both cores running (usually a 60/40 split) for an overall 50% usage. What am I actually seeing? If Python only uses one of the cores, why do both light up? Is everything much more complicated (due to OS scheduling, etc.) than the simple explanations of GIL? From http Thu Feb 19 18:20:51 2009 From: http (Paul Rubin) Date: 19 Feb 2009 15:20:51 -0800 Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> <7x8wo2kwoz.fsf@ruckus.brouhaha.com> <975d0b81-0810-43c2-9734-b7a5a890e431@k19g2000prh.googlegroups.com> <7x3aeadqlo.fsf@ruckus.brouhaha.com> Message-ID: <7xmyci3tf0.fsf@ruckus.brouhaha.com> Tim Rowe writes: > > That Python is so much slower than C is yet another area where Python > > can use improvement. > > No, because we don't use Python where C would be more appropriate. C is basically never appropriate. C should be outlawed by Congress with the ban enforced by roving pie-throwing squads . If a Python program is too slow, making Python faster is far preferable to switching to C. > Sure nobody would complain if Python were faster, but it's not for > speed that we choose Python. Not speed of /execution/ that is. I would say, slow execution is a drawback that we put up with in order to gain benefits of Python programming that are mostly unrelated to the causes of the slowness. The slowness itself can be addressed by technical means, such as native-code compilation and eliminating the GIL. I believe (for example) that the PyPy project is doing both of these. > Different languages have different trade-offs. Python's trade-offs > suit us. If they don't suit you, use a language with trade-offs that > do. I don't think Python's slowness is inherent in the language. It's mostly a shortcoming of the implementation that should be fixed like any other such shortcoming. From garrickp at gmail.com Thu Feb 19 18:23:40 2009 From: garrickp at gmail.com (Falcolas) Date: Thu, 19 Feb 2009 15:23:40 -0800 (PST) Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <28e3612d-2e91-4a91-82cb-5fb2deda95fd@q9g2000yqc.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> <7x8wo2kwoz.fsf@ruckus.brouhaha.com> <975d0b81-0810-43c2-9734-b7a5a890e431@k19g2000prh.googlegroups.com> <7x3aeadqlo.fsf@ruckus.brouhaha.com> Message-ID: <33017207-bc5c-45e5-8795-516329ac172c@p2g2000prf.googlegroups.com> On Feb 19, 3:11?pm, Paul Rubin wrote: > Falcolas writes: > > It's a proposition that used to bother me, until I did some actual > > programming of real world problems in Python. I've yet to really find > > a case where the application was slow enough to justify the cost of > > using multiple Python processes. > > Right, that's basically the issue here: the cost of using multiple > Python processes is unnecessarily high. ?If that cost were lower then > we could more easily use multiple cores to make oru apps faster. I was actually referring to the time cost of researching or developing a parallel execution algorithm which would be suitable for multiple processes. The system overhead of using the Python multiprocess module is fairly negligible for the systems I work on. > Different languages have different trade-offs. Python's trade-offs > suit us. If they don't suit you, use a language with trade-offs that > do. +1 ~G From http Thu Feb 19 18:29:40 2009 From: http (Paul Rubin) Date: 19 Feb 2009 15:29:40 -0800 Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> <7x8wo2kwoz.fsf@ruckus.brouhaha.com> <975d0b81-0810-43c2-9734-b7a5a890e431@k19g2000prh.googlegroups.com> Message-ID: <7xiqn63t0b.fsf@ruckus.brouhaha.com> Tim Rowe writes: > > I really believe that GIL is a design error. > It's only an error if it gets in the way. It's the experience of a lot > of programmers that it doesn't, so it's not an error. It does get in the way of quite a few of us, but I wouldn't exactly call it an error. It was a sensible decision at the time it was made. Changing technology and changing requirements have turned it into a problem since then. A sensible decision later becoming a problem is a fairly normal occurrence, not just in software but in just about every area of human endeavor. The sensible response to the changed landscape is to recognize the problem and figure out what to do about it. Denying the problem's existence is not sensible. From Scott.Daniels at Acm.Org Thu Feb 19 18:31:00 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 19 Feb 2009 15:31:00 -0800 Subject: os.fdopen giving "Invalid Argument" from pipes In-Reply-To: References: <20090219165004.12853.832529843.divmod.quotient.11854@henry.divmod.com> Message-ID: <-c2dnbTIibu4dgDUnZ2dnUVZ_vCdnZ2d@pdx.net> Tim Wintle wrote: > On Thu, 2009-02-19 at 11:50 -0500, Jean-Paul Calderone wrote: ... >> (also, i before e *except* after c et cetera). Flip 'em around and >> all is well. > > Thanks - never was great at speling :-) I used to be great at spelling until I became a programmer. Programming rewards consistency in spelling over correctness. Spelling "recievers" the same way 1000 times is better than getting it correct 999 times and "wrong" once. :-) --Scott David Daniels Scott.Daniels at Acm.Org From steve at holdenweb.com Thu Feb 19 18:34:28 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 19 Feb 2009 18:34:28 -0500 Subject: Will multithreading make python less popular? In-Reply-To: <1235085392.21735.57.camel@tim-laptop> References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <28e3612d-2e91-4a91-82cb-5fb2deda95fd@q9g2000yqc.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> <7x8wo2kwoz.fsf@ruckus.brouhaha.com> <1235085392.21735.57.camel@tim-laptop> Message-ID: Tim Wintle wrote: > On Thu, 2009-02-19 at 12:18 -0800, Paul Rubin wrote: >> If such >> speedups were useless or unimportant, we would not have blown our hard >> earned cash replacing perfectly good older hardware, so we have to >> accept the concept that speed matters and ignore those platitudes that >> say otherwise. > > Kind of agree (although I use a netbook at lot at the moment, and I > don't use that because of speed-ups!) [...] > (3) > Multiple cores scale processing power linearly at best with the number > of cores (since you're normally going to be IO based at some point). > Perhaps the GIL will be relaxed a bit, but it's not going to have a > massive effect. > There are significant classes of problems which *are* compute bound, and as computers are applied more and more to planning and design problems it seems likely that kind of application will become more significant. In twenty years time our laptops will probably be continually optimizing aspects of our lives using advanced linear algebra algorithms over matrices with hundreds or thousands of millions of elements. I wouldn't like Python to be excluded from solving such problems, and others we currently fail to foresee. Though my own interest does tend to lie in the areas where interaction of various kinds dominates the need for large chunks of processing power, I can't ignore the obvious. Many compute-bound problems do exist, and they are important. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From lists at cheimes.de Thu Feb 19 18:38:21 2009 From: lists at cheimes.de (Christian Heimes) Date: Fri, 20 Feb 2009 00:38:21 +0100 Subject: Will multithreading make python less popular? In-Reply-To: <52a0375d-4fad-4caa-8328-47b8f30f2395@40g2000prx.googlegroups.com> References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <28e3612d-2e91-4a91-82cb-5fb2deda95fd@q9g2000yqc.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> <7x8wo2kwoz.fsf@ruckus.brouhaha.com> <52a0375d-4fad-4caa-8328-47b8f30f2395@40g2000prx.googlegroups.com> Message-ID: Mensanator wrote: > When I run I Python program, the Windows task manager shows both > cores running (usually a 60/40 split) for an overall 50% usage. > > What am I actually seeing? If Python only uses one of the cores, > why do both light up? Is everything much more complicated (due to > OS scheduling, etc.) than the simple explanations of GIL? A Python *program* can utilize more than one core, just Python *code* can't run on multiple cores in parallel. Everytime a C function calls code that doesn't use the Python API it can chose to release the GIL. That way a Python program can wrap a library and use as many cores as possible. Christian From steve at holdenweb.com Thu Feb 19 18:45:30 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 19 Feb 2009 18:45:30 -0500 Subject: Will multithreading make python less popular? In-Reply-To: <7xmyci3tf0.fsf@ruckus.brouhaha.com> References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> <7x8wo2kwoz.fsf@ruckus.brouhaha.com> <975d0b81-0810-43c2-9734-b7a5a890e431@k19g2000prh.googlegroups.com> <7x3aeadqlo.fsf@ruckus.brouhaha.com> <7xmyci3tf0.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Tim Rowe writes: >>> That Python is so much slower than C is yet another area where Python >>> can use improvement. >> No, because we don't use Python where C would be more appropriate. > > C is basically never appropriate. C should be outlawed by Congress > with the ban enforced by roving pie-throwing squads . If a > Python program is too slow, making Python faster is far preferable to > switching to C. > Unfortunately it's also far more difficult. I speak with the experience of the "Need for Speed" sprint behind me: the accumulated brainpower at that event should have been able to pick all the low-hanging fruit, and yet the resultant net speedup was worthwhile, but definitely not immense. >> Sure nobody would complain if Python were faster, but it's not for >> speed that we choose Python. Not speed of /execution/ that is. > > I would say, slow execution is a drawback that we put up with in order > to gain benefits of Python programming that are mostly unrelated to > the causes of the slowness. The slowness itself can be addressed by > technical means, such as native-code compilation and eliminating the > GIL. I believe (for example) that the PyPy project is doing both of > these. > And IronPython and JPython already have. (How many times do I have to say this before somebody with access to decent multi-processor hardware runs some actual benchmarks? Where's snakebite.org when you need it? ;-) >> Different languages have different trade-offs. Python's trade-offs >> suit us. If they don't suit you, use a language with trade-offs that >> do. > > I don't think Python's slowness is inherent in the language. It's > mostly a shortcoming of the implementation that should be fixed like > any other such shortcoming. Reasonable, and true. Some people talk about the GIL as though it were something other than an implementation artifact. What Guido doesn't seem to have accepted yet is that slowing [C]Python down by 50% on a single-processor CPU will actually be a worthwhile tradeoff in ten years time, when nothing will have less than eight cores and the big boys will be running at 64 kilo-cores. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From google at mrabarnett.plus.com Thu Feb 19 18:52:12 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 19 Feb 2009 23:52:12 +0000 Subject: Will multithreading make python less popular? In-Reply-To: <1235082919.21735.30.camel@tim-laptop> References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <28e3612d-2e91-4a91-82cb-5fb2deda95fd@q9g2000yqc.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> <7x8wo2kwoz.fsf@ruckus.brouhaha.com> <975d0b81-0810-43c2-9734-b7a5a890e431@k19g2000prh.googlegroups.com> <1235082919.21735.30.camel@tim-laptop> Message-ID: <499DF0AC.2030306@mrabarnett.plus.com> Tim Wintle wrote: [snip] > Yes, we're coming to a point where we're going to have tens of cores in > a chip, but by that time someone far cleverer than me (possibly someone > who's on this list) will have solved that problem. The top experts in > many fields use Python, and if they weren't able to make use of multiple > core chips, then there wouldn't be any demand for them. > Perhaps we should ask Guido who it is; after all, he's the one with the time machine! :-) From tjreedy at udel.edu Thu Feb 19 18:58:57 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 19 Feb 2009 18:58:57 -0500 Subject: Will multithreading make python less popular? In-Reply-To: <7xmyci3tf0.fsf@ruckus.brouhaha.com> References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> <7x8wo2kwoz.fsf@ruckus.brouhaha.com> <975d0b81-0810-43c2-9734-b7a5a890e431@k19g2000prh.googlegroups.com> <7x3aeadqlo.fsf@ruckus.brouhaha.com> <7xmyci3tf0.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > I would say, slow execution is a drawback that we put up with in order > to gain benefits of Python programming that are mostly unrelated to > the causes of the slowness. The slowness itself can be addressed by > technical means, such as native-code compilation and eliminating the > GIL. Given that the GIL remains to make Python run faster in the usual (up to now, at least) case of 1 processor, that seems a strange statement. From Scott.Daniels at Acm.Org Thu Feb 19 19:01:34 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 19 Feb 2009 16:01:34 -0800 Subject: Strange array.array performance In-Reply-To: References: <26ddd1750902191052i4e5caa21s2a4e32ff2d2d6e45@mail.gmail.com> Message-ID: <-MKdnYEu_r3SbwDUnZ2dnUVZ_gSWnZ2d@pdx.net> Maxim Khitrov wrote: > On Thu, Feb 19, 2009 at 2:35 PM, Robert Kern wrote: > I have, but numpy is not currently available for python 2.6, which is > what I need for some other features, and I'm trying to keep the > dependencies down in any case.... > The only feature that I'm missing with array.array is the ability to > quickly pre-allocate large chunks of memory. To do that right now I'm > using array('d', (0,) * size). It would be nice if array accepted an > int as the second argument indicating how much memory to allocate and > initialize to 0. In the meantime, you could write a function (to ease the shift to numpy) and reduce your interface problem to a very small set of lines: def zeroes_d(n): '''Allocate a n-element vector of 'd' elements''' vector = array.array('d') # fromstring has no performance bug vector.fromstring(n * 8 * '\0') return vector Once numpy is up and running on 2.6, this should be easy to convert to a call to zeroes. --Scott David Daniels Scott.Daniels at Acm.Org From steve at holdenweb.com Thu Feb 19 19:13:57 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 19 Feb 2009 19:13:57 -0500 Subject: Will multithreading make python less popular? In-Reply-To: References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> <7x8wo2kwoz.fsf@ruckus.brouhaha.com> <975d0b81-0810-43c2-9734-b7a5a890e431@k19g2000prh.googlegroups.com> <7x3aeadqlo.fsf@ruckus.brouhaha.com> <7xmyci3tf0.fsf@ruckus.brouhaha.com> Message-ID: Terry Reedy wrote: > Paul Rubin wrote: > >> I would say, slow execution is a drawback that we put up with in order >> to gain benefits of Python programming that are mostly unrelated to >> the causes of the slowness. The slowness itself can be addressed by >> technical means, such as native-code compilation and eliminating the >> GIL. > > Given that the GIL remains to make Python run faster in the usual (up to > now, at least) case of 1 processor, that seems a strange statement. > >From a historical perspective, that's going to seem like a very parochial PoV in (say) twenty years. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Thu Feb 19 19:15:22 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 19 Feb 2009 19:15:22 -0500 Subject: Will multithreading make python less popular? In-Reply-To: <7xiqn63t0b.fsf@ruckus.brouhaha.com> References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> <7x8wo2kwoz.fsf@ruckus.brouhaha.com> <975d0b81-0810-43c2-9734-b7a5a890e431@k19g2000prh.googlegroups.com> <7xiqn63t0b.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Tim Rowe writes: >>> I really believe that GIL is a design error. >> It's only an error if it gets in the way. It's the experience of a lot >> of programmers that it doesn't, so it's not an error. > > [...] Denying the > problem's existence is not sensible. And if wishes were horses then beggars would ride :-) -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From http Thu Feb 19 19:16:24 2009 From: http (Paul Rubin) Date: 19 Feb 2009 16:16:24 -0800 Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> <7x8wo2kwoz.fsf@ruckus.brouhaha.com> <975d0b81-0810-43c2-9734-b7a5a890e431@k19g2000prh.googlegroups.com> <7x3aeadqlo.fsf@ruckus.brouhaha.com> <7xmyci3tf0.fsf@ruckus.brouhaha.com> Message-ID: <7xbpsyj73b.fsf@ruckus.brouhaha.com> Terry Reedy writes: > > The slowness itself can be addressed by technical means, such as > > native-code compilation and eliminating the GIL. > > Given that the GIL remains to make Python run faster in the usual (up > to now, at least) case of 1 processor, that seems a strange statement. We've had this discussion before. The 1-processor slowdown that you refer to comes from replacing the GIL with the blunt instrument of a lock around each reference count operation. That has the advantage of not breaking CPython in a million places, but has the drawback of taking a big performance hit. The long term fix is to replace reference counts with a tracing GC. That is apparently not feasible in the framework of CPython and the many extension modules that have been written for it, so it would have to be accompanied by an implementation switch (e.g. PyPy). Steve Holden has mentioned Jython and Ironpython a few times in this thread. Those are reasonable proofs of the concept of a GIL-less Python, but for various reasons (spelled J-V-M and W-i-n-d-o-w-s) are not all that suitable for many current Python users. From steve at holdenweb.com Thu Feb 19 19:17:12 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 19 Feb 2009 19:17:12 -0500 Subject: Will multithreading make python less popular? In-Reply-To: <499DF0AC.2030306@mrabarnett.plus.com> References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <28e3612d-2e91-4a91-82cb-5fb2deda95fd@q9g2000yqc.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> <7x8wo2kwoz.fsf@ruckus.brouhaha.com> <975d0b81-0810-43c2-9734-b7a5a890e431@k19g2000prh.googlegroups.com> <1235082919.21735.30.camel@tim-laptop> <499DF0AC.2030306@mrabarnett.plus.com> Message-ID: <499DF688.2050303@holdenweb.com> MRAB wrote: > Tim Wintle wrote: > [snip] >> Yes, we're coming to a point where we're going to have tens of cores in >> a chip, but by that time someone far cleverer than me (possibly someone >> who's on this list) will have solved that problem. The top experts in >> many fields use Python, and if they weren't able to make use of multiple >> core chips, then there wouldn't be any demand for them. >> > Perhaps we should ask Guido who it is; after all, he's the one with the > time machine! :-) But he clearly hasn't been using it lately. Perhaps it's time Python stopped being a dictatorship? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From wuwei23 at gmail.com Thu Feb 19 19:44:18 2009 From: wuwei23 at gmail.com (alex23) Date: Thu, 19 Feb 2009 16:44:18 -0800 (PST) Subject: Newby Question for reading a file References: <6b15ccff-7d39-42fc-b49e-35deb9098873@c12g2000yqj.googlegroups.com> <3eafb3c3-01a2-423b-985a-1ca17f6e82b1@p13g2000yqc.googlegroups.com> Message-ID: On Feb 20, 5:38?am, Peter Otten <__pete... at web.de> wrote: > Yes you can get portions of the line by slicing: > > for line in open("infile"): > ? ? if line[8:18] != line[18:28]: > ? ? ? ? ? ? print line, You can also name the slices, which makes the code more clear (IMO): endda = slice(8,18) begda = slice(18,28) for line in open("infile"): if line[endda] != line[begda]: print line, > Or you can use the struct module: But this is the approach I'd take. From steve at holdenweb.com Thu Feb 19 20:18:32 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 19 Feb 2009 20:18:32 -0500 Subject: Will multithreading make python less popular? In-Reply-To: <52a0375d-4fad-4caa-8328-47b8f30f2395@40g2000prx.googlegroups.com> References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <28e3612d-2e91-4a91-82cb-5fb2deda95fd@q9g2000yqc.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> <7x8wo2kwoz.fsf@ruckus.brouhaha.com> <52a0375d-4fad-4caa-8328-47b8f30f2395@40g2000prx.googlegroups.com> Message-ID: Mensanator wrote: > On Feb 19, 2:18 pm, Paul Rubin wrote: [...] > When I run I Python program, the Windows task manager shows both > cores running (usually a 60/40 split) for an overall 50% usage. > > What am I actually seeing? If Python only uses one of the cores, > why do both light up? Is everything much more complicated (due to > OS scheduling, etc.) than the simple explanations of GIL? You are seeing your Python program running on one core, and the usual Windows crap keeping the other one busy. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From brent.r.nash at jpl.nasa.gov Thu Feb 19 20:22:53 2009 From: brent.r.nash at jpl.nasa.gov (Nash, Brent R) Date: Thu, 19 Feb 2009 17:22:53 -0800 Subject: matplotlib issue: cannot auto-scale X axis of plop properly Message-ID: Hey everyone, I'm fairly new to matplotlib, but have read through tons of the documentation today and have a decent understanding of it. All the auto-scaling, xlim, and x_bound stuff works fine for me with the examples, but as soon as I try to use it on my data, it's not working for me. I've attached a demo script, 2 input files of data, and a PNG showing the resulting chart I get. The numbers on my Y-axis range from 7656 to 59928 (a difference of 52272) and the numbers on my X-axis range from 1.22896144017e+12 to 1.22896155012e+12 (a difference of 109950). The plot should look like a monotonically increasing line, but the resulting plot always comes out looking like a vertical line. I realize that the plot is actually correct, the problem is the default scaling on the ouptut. The easy way to justify this to yourself is to take the line "ert = float(i)" in the script and replace it with "ert = float(i) - 1228960000000" to reduce the ert #'s to a manageable size and then everything plots very nicely. The data is all linear, not logarithmic or anything, so I don't think writing a custom scaler is the solution. I left commented out sections in my script of all the different methods I've tried to scale this thing. I've tried all permutations I could think of for the following functions: matplotlib.pyplot.axes().autoscale_view(...) matplotlib.pyplot.axes().set_xbound(...) matplotlib.pyplot.axes().set_xlim(...) matplotlib.pyplot.axes().set_aspect(...) matplotlib.pyplot.axis(...) matplotlib.pyplot.axes().set_xscale(...) Can anyone catch what I'm doing wrong here? I'm hoping it's just something obvious due to my unfamiliarity with the tool. Is there any way to write my own custom autoscale algorithm? Thanks very much for your time/help! ~Brent PS ~ Here's my OS info: MacBook Pro Laptop Mac O X 10.5.6 2.6 GHz Intel Core 2 Duo 4GB 667 MHz DDR2 SDRAM -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: erts.txt Type: application/octet-stream Size: 9100 bytes Desc: erts.txt URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: matplotlib_scale_problem.png Type: application/octet-stream Size: 38320 bytes Desc: matplotlib_scale_problem.png URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: matplotlib_scale_problem.py Type: application/octet-stream Size: 1400 bytes Desc: matplotlib_scale_problem.py URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: samples.txt Type: application/octet-stream Size: 5419 bytes Desc: samples.txt URL: From hellyj at ucsd.edu Thu Feb 19 20:32:25 2009 From: hellyj at ucsd.edu (Helly John J.) Date: Thu, 19 Feb 2009 17:32:25 -0800 Subject: Problems with OS X 10.5.6 and Python 2.5 and GDAL 1.6 In-Reply-To: References: <60437775-ED63-469B-A2CC-913B0E77BC1E@ucsd.edu> <3A6157F5-DBA7-46B5-89A8-621DF6AB1F56@semanchuk.com> Message-ID: <454D3724-D479-4B73-8BFB-FDA9A8E54EE7@ucsd.edu> Thanks very much. I'll give it a go. Cheers. -------------- John Helly, University of California, San Diego San Diego Supercomputer Center, Mail Code 0527 Scripps Institution of Oceanography, Climate, Atmospheric Science, and Physical Oceanography, Mail Code 0224 9500 Gilman Dr., La Jolla CA 92093 +01 760 840 8660 mobile / stonesteps (Skype) / stonesteps7 (iChat) / URL (http://www.sdsc.edu/~hellyj) On Feb 19, 2009, at 11:16 AM, Ned Deily wrote: In article , Ned Deily wrote: > It looks like you have installed GDAL to the site-packages directory > of > the Apple-supplied python 2.5 (which, for 10.5, is 2.5.1, not 2.4). > That site-packages directory is /Library/Python/2.5. The Apple- > supplied > python comes with a sym link from /usr/bin/python. If you launch it, > you'll probably find GDAL is there as expected. > > If you do want to use the python.org python, which is somewhat newer, > you need to install its own version of setuptools/easy_install and use > it to install GDAL to the site-packages directory of that python which > is located here: > /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site- > pack > ages. The two python instances co-exist. To install another easy_install, ensure the python.org python comes first on your > PATH, then follow the instructions here: > BTW, that easy_install will itself be installed into the bin directory of the python.org python framework. So to ensure you are using that easy_install and that python, make sure that bin directory is on your PATH before "/usr/bin", so, if necessary, something like: export PATH="/Library/Frameworks/Python.framework/Versions/2.5/bin: $PATH" -- Ned Deily, nad at acm.org -- http://mail.python.org/mailman/listinfo/python-list From mkhitrov at gmail.com Thu Feb 19 20:39:08 2009 From: mkhitrov at gmail.com (Maxim Khitrov) Date: Thu, 19 Feb 2009 20:39:08 -0500 Subject: Strange array.array performance In-Reply-To: <-MKdnYEu_r3SbwDUnZ2dnUVZ_gSWnZ2d@pdx.net> References: <26ddd1750902191052i4e5caa21s2a4e32ff2d2d6e45@mail.gmail.com> <-MKdnYEu_r3SbwDUnZ2dnUVZ_gSWnZ2d@pdx.net> Message-ID: <26ddd1750902191739j5bcab830l865d6f04b869cd9a@mail.gmail.com> On Thu, Feb 19, 2009 at 7:01 PM, Scott David Daniels wrote: > Maxim Khitrov wrote: >> >> On Thu, Feb 19, 2009 at 2:35 PM, Robert Kern >> wrote: >> I have, but numpy is not currently available for python 2.6, which is >> what I need for some other features, and I'm trying to keep the >> dependencies down in any case.... >> The only feature that I'm missing with array.array is the ability to >> quickly pre-allocate large chunks of memory. To do that right now I'm >> using array('d', (0,) * size). It would be nice if array accepted an >> int as the second argument indicating how much memory to allocate and >> initialize to 0. > > In the meantime, you could write a function (to ease the shift to numpy) > and reduce your interface problem to a very small set of lines: > def zeroes_d(n): > '''Allocate a n-element vector of 'd' elements''' > vector = array.array('d') # fromstring has no performance bug > vector.fromstring(n * 8 * '\0') > return vector > Once numpy is up and running on 2.6, this should be easy to convert > to a call to zeroes. If I do decide to transition at any point, it will require much greater modification. For example, to speed-up retrieval of data from Matlab, which is returned to me as an mxArray structure, I allocate an array.array for it and then use ctypes.memmove to copy data directly into the array's buffer (address obtained through buffer_info()). Same thing for sending data, rather than allocate a separate mxArray, copy data, and then send, I create an empty mxArray and set its data pointer to the array's buffer. I'm sure that there are equivalents in numpy, but the point is that the transition, which currently would not benefit my code in any significant way, will not be a quick change. On the other hand, I have to thank you for the fromstring example. For some reason, it never occurred to me that creating a string of nulls would be much faster than a tuple of zeros. In fact, you can pass the string to the constructor and it calls fromstring automatically. For an array of 1 million elements, using a string to initialize is 18x faster. :) - Max From steve at holdenweb.com Thu Feb 19 20:52:59 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 19 Feb 2009 20:52:59 -0500 Subject: Newby Question for reading a file In-Reply-To: References: <6b15ccff-7d39-42fc-b49e-35deb9098873@c12g2000yqj.googlegroups.com> <3eafb3c3-01a2-423b-985a-1ca17f6e82b1@p13g2000yqc.googlegroups.com> Message-ID: <499E0CFB.2090203@holdenweb.com> alex23 wrote: > On Feb 20, 5:38 am, Peter Otten <__pete... at web.de> wrote: >> Yes you can get portions of the line by slicing: >> >> for line in open("infile"): >> if line[8:18] != line[18:28]: >> print line, > > You can also name the slices, which makes the code more clear (IMO): > > endda = slice(8,18) > begda = slice(18,28) > for line in open("infile"): > if line[endda] != line[begda]: > print line, > >> Or you can use the struct module: > > But this is the approach I'd take. This is one of the lesser-appreciated aspects of Python. I anticipate a flood of "Named Slices" blog posts round about now. Wonder if I'll be the first? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Thu Feb 19 20:52:59 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 19 Feb 2009 20:52:59 -0500 Subject: Newby Question for reading a file In-Reply-To: References: <6b15ccff-7d39-42fc-b49e-35deb9098873@c12g2000yqj.googlegroups.com> <3eafb3c3-01a2-423b-985a-1ca17f6e82b1@p13g2000yqc.googlegroups.com> Message-ID: <499E0CFB.2090203@holdenweb.com> alex23 wrote: > On Feb 20, 5:38 am, Peter Otten <__pete... at web.de> wrote: >> Yes you can get portions of the line by slicing: >> >> for line in open("infile"): >> if line[8:18] != line[18:28]: >> print line, > > You can also name the slices, which makes the code more clear (IMO): > > endda = slice(8,18) > begda = slice(18,28) > for line in open("infile"): > if line[endda] != line[begda]: > print line, > >> Or you can use the struct module: > > But this is the approach I'd take. This is one of the lesser-appreciated aspects of Python. I anticipate a flood of "Named Slices" blog posts round about now. Wonder if I'll be the first? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From mensanator at aol.com Thu Feb 19 20:57:52 2009 From: mensanator at aol.com (Mensanator) Date: Thu, 19 Feb 2009 17:57:52 -0800 (PST) Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <28e3612d-2e91-4a91-82cb-5fb2deda95fd@q9g2000yqc.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> <7x8wo2kwoz.fsf@ruckus.brouhaha.com> <52a0375d-4fad-4caa-8328-47b8f30f2395@40g2000prx.googlegroups.com> Message-ID: <0e6659fa-348b-4f76-b6fb-b18af08a6ab6@w24g2000prd.googlegroups.com> On Feb 19, 7:18?pm, Steve Holden wrote: > Mensanator wrote: > > On Feb 19, 2:18 pm, Paul Rubin wrote: > [...] > > When I run I Python program, the Windows task manager shows both > > cores running (usually a 60/40 split) for an overall 50% usage. > > > What am I actually seeing? If Python only uses one of the cores, > > why do both light up? Is everything much more complicated (due to > > OS scheduling, etc.) than the simple explanations of GIL? > > You are seeing your Python program running on one core, and the usual > Windows crap keeping the other one busy. I thought of that, but the usual Windows crap accounts for only a couple percent prior to the Python program running. Christian Heimes answer sounds more realistic. But what do I know? > > regards > ?Steve > -- > Steve Holden ? ? ? ?+1 571 484 6266 ? +1 800 494 3119 > Holden Web LLC ? ? ? ? ? ? ?http://www.holdenweb.com/ From mkhitrov at gmail.com Thu Feb 19 21:08:43 2009 From: mkhitrov at gmail.com (Maxim Khitrov) Date: Thu, 19 Feb 2009 21:08:43 -0500 Subject: Strange array.array performance In-Reply-To: <-MKdnYEu_r3SbwDUnZ2dnUVZ_gSWnZ2d@pdx.net> References: <26ddd1750902191052i4e5caa21s2a4e32ff2d2d6e45@mail.gmail.com> <-MKdnYEu_r3SbwDUnZ2dnUVZ_gSWnZ2d@pdx.net> Message-ID: <26ddd1750902191808x329881e2lde249be20571ab06@mail.gmail.com> On Thu, Feb 19, 2009 at 7:01 PM, Scott David Daniels wrote: > Maxim Khitrov wrote: >> >> On Thu, Feb 19, 2009 at 2:35 PM, Robert Kern >> wrote: >> I have, but numpy is not currently available for python 2.6, which is >> what I need for some other features, and I'm trying to keep the >> dependencies down in any case.... >> The only feature that I'm missing with array.array is the ability to >> quickly pre-allocate large chunks of memory. To do that right now I'm >> using array('d', (0,) * size). It would be nice if array accepted an >> int as the second argument indicating how much memory to allocate and >> initialize to 0. > > In the meantime, you could write a function (to ease the shift to numpy) > and reduce your interface problem to a very small set of lines: > def zeroes_d(n): > '''Allocate a n-element vector of 'd' elements''' > vector = array.array('d') # fromstring has no performance bug > vector.fromstring(n * 8 * '\0') > return vector > Once numpy is up and running on 2.6, this should be easy to convert > to a call to zeroes. Here's the function that I'll be using from now on. It gives me exactly the behavior I need, with an int initializer being treated as array size. Still not as efficient as it could be if supported natively by array (one malloc instead of two + memmove + extra function call), but very good performance nevertheless: from array import array as _array array_null = dict((tc, '\0' * _array(tc).itemsize) for tc in 'cbBuhHiIlLfd') def array(typecode, init): if isinstance(init, int): return _array(typecode, array_null[typecode] * init) return _array(typecode, init) - Max From sjmachin at lexicon.net Thu Feb 19 21:15:51 2009 From: sjmachin at lexicon.net (John Machin) Date: Thu, 19 Feb 2009 18:15:51 -0800 (PST) Subject: Strange array.array performance References: <26ddd1750902191052i4e5caa21s2a4e32ff2d2d6e45@mail.gmail.com> Message-ID: <91af5ae1-bb76-405a-af28-f65ead4e847f@i18g2000prf.googlegroups.com> On Feb 20, 6:53?am, Maxim Khitrov wrote: > On Thu, Feb 19, 2009 at 2:35 PM, Robert Kern wrote: > > On 2009-02-19 12:52, Maxim Khitrov wrote: > > >> Hello all, > > >> I'm currently writing a Python<-> ?MATLAB interface with ctypes and > >> array.array class, using which I'll need to push large amounts of data > >> to MATLAB. > > > Have you taken a look at mlabwrap? > > > ?http://mlabwrap.sourceforge.net/ > > > At the very least, you will probably want to use numpy arrays instead of > > array.array. > > > ?http://numpy.scipy.org/ > > I have, but numpy is not currently available for python 2.6, which is > what I need for some other features, and I'm trying to keep the > dependencies down in any case. Mlabwrap description doesn't mention if > it is thread-safe, and that's another one of my requirements. > > The only feature that I'm missing with array.array is the ability to > quickly pre-allocate large chunks of memory. To do that right now I'm > using array('d', (0,) * size). It would go somewhat faster if you gave it a float instead of an int. > It would be nice if array accepted an > int as the second argument indicating how much memory to allocate and > initialize to 0. While you're waiting for that to happen, you'll have to use the fromstring trick, or another gimmick that is faster and is likely not to use an extra temp 8Mb for a 1M-element array, as I presume the fromstring does. [Python 2.6.1 on Windows XP SP3] [Processor: x86 Family 15 Model 36 Stepping 2 AuthenticAMD ~1994 Mhz] C:\junk>\python26\python -mtimeit -s"from array import array" "x=array ('d',(0,)* 1000000)" 10 loops, best of 3: 199 msec per loop C:\junk>\python26\python -mtimeit -s"from array import array" "x=array ('d',(0.,)*1000000)" 10 loops, best of 3: 158 msec per loop C:\junk>\python26\python -mtimeit -s"from array import array" "x=array ('d');x.fromstring('\0'*8*1000000)" 10 loops, best of 3: 36 msec per loop C:\junk>\python26\python -mtimeit -s"from array import array" "x=array ('d','\0'*8*1000000)" 10 loops, best of 3: 35.7 msec per loop C:\junk>\python26\python -mtimeit -s"from array import array" "array ('d',(0.,))*1000000" 10 loops, best of 3: 19.5 msec per loop HTH, John From lists at cheimes.de Thu Feb 19 21:19:15 2009 From: lists at cheimes.de (Christian Heimes) Date: Fri, 20 Feb 2009 03:19:15 +0100 Subject: Will multithreading make python less popular? In-Reply-To: <0e6659fa-348b-4f76-b6fb-b18af08a6ab6@w24g2000prd.googlegroups.com> References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <28e3612d-2e91-4a91-82cb-5fb2deda95fd@q9g2000yqc.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> <7x8wo2kwoz.fsf@ruckus.brouhaha.com> <52a0375d-4fad-4caa-8328-47b8f30f2395@40g2000prx.googlegroups.com> <0e6659fa-348b-4f76-b6fb-b18af08a6ab6@w24g2000prd.googlegroups.com> Message-ID: Mensanator wrote: > I thought of that, but the usual Windows crap accounts for only a > couple percent prior to the Python program running. Christian Heimes > answer sounds more realistic. > > But what do I know? Be happy that your program makes use of both cores? :] You can restrict your program from using more than one core by setting the cpu affinity. On Windows the pywin32 packages wraps all necessary calls: phandle = win32process.GetCurrentProcess() win32process.SetProcessAffinityMask(phandle, mask) Past week I've written a wrapper for the Linux syscalls sched_setaffinity and friends. I may be able and allowed to release the stuff in a few weeks. Christian From cournape at gmail.com Thu Feb 19 21:34:48 2009 From: cournape at gmail.com (David Cournapeau) Date: Fri, 20 Feb 2009 11:34:48 +0900 Subject: Strange array.array performance In-Reply-To: <26ddd1750902191153lb1b5efaj783f1c75596d900c@mail.gmail.com> References: <26ddd1750902191052i4e5caa21s2a4e32ff2d2d6e45@mail.gmail.com> <26ddd1750902191153lb1b5efaj783f1c75596d900c@mail.gmail.com> Message-ID: <5b8d13220902191834v3c6224baoa810a87650cad464@mail.gmail.com> On Fri, Feb 20, 2009 at 4:53 AM, Maxim Khitrov wrote: > On Thu, Feb 19, 2009 at 2:35 PM, Robert Kern wrote: >> On 2009-02-19 12:52, Maxim Khitrov wrote: >>> >>> Hello all, >>> >>> I'm currently writing a Python<-> MATLAB interface with ctypes and >>> array.array class, using which I'll need to push large amounts of data >>> to MATLAB. >> >> Have you taken a look at mlabwrap? >> >> http://mlabwrap.sourceforge.net/ >> >> At the very least, you will probably want to use numpy arrays instead of >> array.array. >> >> http://numpy.scipy.org/ > > I have, but numpy is not currently available for python 2.6, which is > what I need for some other features, and I'm trying to keep the > dependencies down in any case. Mlabwrap description doesn't mention if > it is thread-safe, and that's another one of my requirements. What do you mean by thread-safe ? Different threads calling the same matlab engine handle ? David From steve at holdenweb.com Thu Feb 19 21:36:07 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 19 Feb 2009 21:36:07 -0500 Subject: Will multithreading make python less popular? In-Reply-To: <0e6659fa-348b-4f76-b6fb-b18af08a6ab6@w24g2000prd.googlegroups.com> References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <28e3612d-2e91-4a91-82cb-5fb2deda95fd@q9g2000yqc.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> <7x8wo2kwoz.fsf@ruckus.brouhaha.com> <52a0375d-4fad-4caa-8328-47b8f30f2395@40g2000prx.googlegroups.com> <0e6659fa-348b-4f76-b6fb-b18af08a6ab6@w24g2000prd.googlegroups.com> Message-ID: Mensanator wrote: > On Feb 19, 7:18 pm, Steve Holden wrote: >> Mensanator wrote: >>> On Feb 19, 2:18 pm, Paul Rubin wrote: >> [...] >>> When I run I Python program, the Windows task manager shows both >>> cores running (usually a 60/40 split) for an overall 50% usage. >>> What am I actually seeing? If Python only uses one of the cores, >>> why do both light up? Is everything much more complicated (due to >>> OS scheduling, etc.) than the simple explanations of GIL? >> You are seeing your Python program running on one core, and the usual >> Windows crap keeping the other one busy. > > I thought of that, but the usual Windows crap accounts for only a > couple percent prior to the Python program running. Christian Heimes > answer sounds more realistic. > > But what do I know? > At least as much as I do, probably. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From hellyj at ucsd.edu Thu Feb 19 21:38:07 2009 From: hellyj at ucsd.edu (Helly John J.) Date: Thu, 19 Feb 2009 18:38:07 -0800 Subject: Problems with OS X 10.5.6 and Python 2.5 and GDAL 1.6 In-Reply-To: References: <60437775-ED63-469B-A2CC-913B0E77BC1E@ucsd.edu> <3A6157F5-DBA7-46B5-89A8-621DF6AB1F56@semanchuk.com> Message-ID: <2FE1A73A-5BDD-45CD-8323-CCDF68DF3269@ucsd.edu> Hi. You are correct about finding the module, Ned. Thanks for that although I don't understand why it works. However, there are complications. 1. Using '/usr/bin/python' and 'from osgeo import gdal' works but throws an error the first time it's invoked. NeptuneDesk.local:/Volumes/B2_160GB/PALSAR_200902/Geotiffs>/usr/bin/ python Python 2.5.1 (r251:54863, Apr 15 2008, 22:57:26) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from osgeo import gdal Python(21061) malloc: *** error for object 0xa00696d8: Non-aligned pointer being freed *** set a breakpoint in malloc_error_break to debug >>> from osgeo import gdal >>> 2. Since I'm trying to use gdal_merge.py this causes a second attempt within gdal_merge.py, after the error above, to be made with the old (now wrong) syntax: try: from osgeo import gdal except ImportError: osgeo import gdal 3. I changed the gdal_merge.py code so it uses the correct syntax even after the error but then find that I get the original 'no module' error, I think, because gdal_merge.py starts with the line: #!/usr/bin/env python I don't understand this usage but when I run it alone (i.e., /usr/bin/ env) I see that it forces the PATH, and the environment in general, to be something different than what I have set in my .bash_profile. For example, it puts PATH=/Library/Frameworks/Python.framework/Versions/Current/bin: in the beginning in front of /usr/bin which I had moved up in the path in my .bash_profile. I overcame this by getting rid of /usr/bin/env and substituting /usr/bin/python. So, there are three issues: 1. the malloc error 2. the interaction with the gdal_merge.py error handling 3. the environment setup and where that's coming from. Otherwise, everything's peachy. Cheers. -------------- John Helly, University of California, San Diego San Diego Supercomputer Center, Mail Code 0527 Scripps Institution of Oceanography, Climate, Atmospheric Science, and Physical Oceanography, Mail Code 0224 9500 Gilman Dr., La Jolla CA 92093 +01 760 840 8660 mobile / stonesteps (Skype) / stonesteps7 (iChat) / URL (http://www.sdsc.edu/~hellyj) On Feb 19, 2009, at 11:16 AM, Ned Deily wrote: In article , Ned Deily wrote: > It looks like you have installed GDAL to the site-packages directory > of > the Apple-supplied python 2.5 (which, for 10.5, is 2.5.1, not 2.4). > That site-packages directory is /Library/Python/2.5. The Apple- > supplied > python comes with a sym link from /usr/bin/python. If you launch it, > you'll probably find GDAL is there as expected. > > If you do want to use the python.org python, which is somewhat newer, > you need to install its own version of setuptools/easy_install and use > it to install GDAL to the site-packages directory of that python which > is located here: > /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site- > pack > ages. The two python instances co-exist. To install another easy_install, ensure the python.org python comes first on your > PATH, then follow the instructions here: > BTW, that easy_install will itself be installed into the bin directory of the python.org python framework. So to ensure you are using that easy_install and that python, make sure that bin directory is on your PATH before "/usr/bin", so, if necessary, something like: export PATH="/Library/Frameworks/Python.framework/Versions/2.5/bin: $PATH" -- Ned Deily, nad at acm.org -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From mkhitrov at gmail.com Thu Feb 19 21:43:08 2009 From: mkhitrov at gmail.com (Maxim Khitrov) Date: Thu, 19 Feb 2009 21:43:08 -0500 Subject: Strange array.array performance In-Reply-To: <5b8d13220902191834v3c6224baoa810a87650cad464@mail.gmail.com> References: <26ddd1750902191052i4e5caa21s2a4e32ff2d2d6e45@mail.gmail.com> <26ddd1750902191153lb1b5efaj783f1c75596d900c@mail.gmail.com> <5b8d13220902191834v3c6224baoa810a87650cad464@mail.gmail.com> Message-ID: <26ddd1750902191843j76e2df31nfb56ac18fe023c52@mail.gmail.com> On Thu, Feb 19, 2009 at 9:34 PM, David Cournapeau wrote: > On Fri, Feb 20, 2009 at 4:53 AM, Maxim Khitrov wrote: >> On Thu, Feb 19, 2009 at 2:35 PM, Robert Kern wrote: >>> On 2009-02-19 12:52, Maxim Khitrov wrote: >>>> >>>> Hello all, >>>> >>>> I'm currently writing a Python<-> MATLAB interface with ctypes and >>>> array.array class, using which I'll need to push large amounts of data >>>> to MATLAB. >>> >>> Have you taken a look at mlabwrap? >>> >>> http://mlabwrap.sourceforge.net/ >>> >>> At the very least, you will probably want to use numpy arrays instead of >>> array.array. >>> >>> http://numpy.scipy.org/ >> >> I have, but numpy is not currently available for python 2.6, which is >> what I need for some other features, and I'm trying to keep the >> dependencies down in any case. Mlabwrap description doesn't mention if >> it is thread-safe, and that's another one of my requirements. > > What do you mean by thread-safe ? Different threads calling the same > matlab engine handle ? Yes, I may have a case where one thread is still sending data, while another tries to close the connection, or two threads trying to close the connection at the same time. In both cases, I need some parts of the code to be atomic to prevent errors. - Max From johnforse at talktalk.net Thu Feb 19 21:46:19 2009 From: johnforse at talktalk.net (John Forse) Date: Fri, 20 Feb 2009 02:46:19 +0000 Subject: IDLE error on 3.0.1 Message-ID: <1C3FA0D1-D744-47AD-B9C5-684C1D045BE3@talktalk.net> Occaisionally, if I mistype in python shell or try to copy & paste a line there, I get a permanent hang with the error below. It isn't corrected by quitting IDLE, but is put right with a restart. I am running 3.0.1 on Mac 10.5.6. Is this a bug, as it never happened on the same system with 2.5 &2.6.1 ? Is there another way to prevent this? Regards John Forse -------------- next part -------------- A non-text attachment was scrubbed... Name: pastedGraphic.jpg Type: image/jpeg Size: 63532 bytes Desc: not available URL: -------------- next part -------------- From benjamin.kaplan at case.edu Thu Feb 19 21:53:23 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 19 Feb 2009 21:53:23 -0500 Subject: Will multithreading make python less popular? In-Reply-To: <7xbpsyj73b.fsf@ruckus.brouhaha.com> References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> <7x8wo2kwoz.fsf@ruckus.brouhaha.com> <975d0b81-0810-43c2-9734-b7a5a890e431@k19g2000prh.googlegroups.com> <7x3aeadqlo.fsf@ruckus.brouhaha.com> <7xmyci3tf0.fsf@ruckus.brouhaha.com> <7xbpsyj73b.fsf@ruckus.brouhaha.com> Message-ID: On Thu, Feb 19, 2009 at 7:16 PM, Paul Rubin wrote: > Terry Reedy writes: > > > The slowness itself can be addressed by technical means, such as > > > native-code compilation and eliminating the GIL. > > > > Given that the GIL remains to make Python run faster in the usual (up > > to now, at least) case of 1 processor, that seems a strange statement. > > We've had this discussion before. The 1-processor slowdown that you > refer to comes from replacing the GIL with the blunt instrument of a > lock around each reference count operation. That has the advantage of > not breaking CPython in a million places, but has the drawback of > taking a big performance hit. The long term fix is to replace > reference counts with a tracing GC. That is apparently not feasible > in the framework of CPython and the many extension modules that have > been written for it, so it would have to be accompanied by an > implementation switch (e.g. PyPy). > > Steve Holden has mentioned Jython and Ironpython a few times in this > thread. Those are reasonable proofs of the concept of a GIL-less > Python, but for various reasons (spelled J-V-M and W-i-n-d-o-w-s) are > not all that suitable for many current Python users. Actually, Mono supports IronPython so it will work on M-a-c, L-i-n-u-x, S-o-l-a-r-i-s, and possibly even W-i-i and P-l-a-y-s-t-a-t-i-o-n-3. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rNOSPAMon at flownet.com Thu Feb 19 21:57:13 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Thu, 19 Feb 2009 18:57:13 -0800 Subject: To unicode or not to unicode Message-ID: I'm writing a little wiki that I call ?Wiki. That's a lowercase Greek mu at the beginning (it's pronounced micro-wiki). It's working, except that I can't actually enter the name of the wiki into the wiki itself because the default unicode encoding on my Python installation is "ascii". So I'm trying to decide on a course of action. There seem to be three possibilities: 1. Change the code to properly support unicode. Preliminary investigations indicate that this is going to be a colossal pain in the ass. 2. Change the default encoding on my Python installation to be latin-1 or UTF8. The disadvantage to this is that no one else will be able to run my code without making the same change to their installation, since you can't change default encodings once Python has started. 3. Punt and spell it 'uwiki' instead. I'm feeling indecisive so I thought I'd ask other people's opinion. What should I do? rg From mkhitrov at gmail.com Thu Feb 19 21:58:42 2009 From: mkhitrov at gmail.com (Maxim Khitrov) Date: Thu, 19 Feb 2009 21:58:42 -0500 Subject: Strange array.array performance In-Reply-To: <91af5ae1-bb76-405a-af28-f65ead4e847f@i18g2000prf.googlegroups.com> References: <26ddd1750902191052i4e5caa21s2a4e32ff2d2d6e45@mail.gmail.com> <91af5ae1-bb76-405a-af28-f65ead4e847f@i18g2000prf.googlegroups.com> Message-ID: <26ddd1750902191858p2b84cedeicbaebbe29cc9af42@mail.gmail.com> On Thu, Feb 19, 2009 at 9:15 PM, John Machin wrote: > On Feb 20, 6:53 am, Maxim Khitrov wrote: >> On Thu, Feb 19, 2009 at 2:35 PM, Robert Kern wrote: >> > On 2009-02-19 12:52, Maxim Khitrov wrote: >> >> >> Hello all, >> >> >> I'm currently writing a Python<-> MATLAB interface with ctypes and >> >> array.array class, using which I'll need to push large amounts of data >> >> to MATLAB. >> >> > Have you taken a look at mlabwrap? >> >> > http://mlabwrap.sourceforge.net/ >> >> > At the very least, you will probably want to use numpy arrays instead of >> > array.array. >> >> > http://numpy.scipy.org/ >> >> I have, but numpy is not currently available for python 2.6, which is >> what I need for some other features, and I'm trying to keep the >> dependencies down in any case. Mlabwrap description doesn't mention if >> it is thread-safe, and that's another one of my requirements. >> >> The only feature that I'm missing with array.array is the ability to >> quickly pre-allocate large chunks of memory. To do that right now I'm >> using array('d', (0,) * size). > > It would go somewhat faster if you gave it a float instead of an int. > >> It would be nice if array accepted an >> int as the second argument indicating how much memory to allocate and >> initialize to 0. > > While you're waiting for that to happen, you'll have to use the > fromstring trick, or another gimmick that is faster and is likely not > to use an extra temp 8Mb for a 1M-element array, as I presume the > fromstring does. > > [Python 2.6.1 on Windows XP SP3] > [Processor: x86 Family 15 Model 36 Stepping 2 AuthenticAMD ~1994 Mhz] > > C:\junk>\python26\python -mtimeit -s"from array import array" "x=array > ('d',(0,)* > 1000000)" > 10 loops, best of 3: 199 msec per loop > > C:\junk>\python26\python -mtimeit -s"from array import array" "x=array > ('d',(0.,)*1000000)" > 10 loops, best of 3: 158 msec per loop > > C:\junk>\python26\python -mtimeit -s"from array import array" "x=array > ('d');x.fromstring('\0'*8*1000000)" > 10 loops, best of 3: 36 msec per loop > > C:\junk>\python26\python -mtimeit -s"from array import array" "x=array > ('d','\0'*8*1000000)" > 10 loops, best of 3: 35.7 msec per loop > > C:\junk>\python26\python -mtimeit -s"from array import array" "array > ('d',(0.,))*1000000" > 10 loops, best of 3: 19.5 msec per loop Interesting, though I'm not able to replicate that last outcome. The string method is still the fastest on my machine. Furthermore, it looks like the order in which you do the multiplication also matters - (8 * size * '\0') is faster than ('\0' * 8 * size). Here is my test and outcome: --- from array import array from timeit import repeat print repeat(lambda: array('d', (0,) * 100000), number = 100) print repeat(lambda: array('d', (0.0,) * 100000), number = 100) print repeat(lambda: array('d', (0.0,)) * 100000, number = 100) print repeat(lambda: array('d', '\0' * 100000 * 8), number = 100) print repeat(lambda: array('d', '\0' * 8 * 100000), number = 100) print repeat(lambda: array('d', 8 * 100000 * '\0'), number = 100) --- [0.91048107424534941, 0.88766983642377162, 0.88312824645684618] [0.72164595848486179, 0.72038338197219343, 0.72346024633711981] [0.10763947529894136, 0.1047547164728595, 0.10461521722863232] [0.05856873793382178, 0.058508825334111947, 0.058361838698573365] [0.057632016342657799, 0.057521392119007864, 0.057227118035289237] [0.056006643320014149, 0.056331811311153501, 0.056187433215103333] The array('d', (0.0,)) * 100000 method is a good compromise between performance and amount of memory used, so maybe I'll use that instead. - Max From johnforse at talktalk.net Thu Feb 19 22:00:01 2009 From: johnforse at talktalk.net (John Forse) Date: Fri, 20 Feb 2009 03:00:01 +0000 Subject: Fwd: IDLE error on 3.0.1 References: <1C3FA0D1-D744-47AD-B9C5-684C1D045BE3@talktalk.net> Message-ID: <3F795AB3-9BA5-4833-971C-9A442CEF7D7F@talktalk.net> Regards John Begin forwarded message: > From: John Forse > Date: 20 February 2009 02:46:19 GMT > To: python-list at python.org > Subject: IDLE error on 3.0.1 > > Occaisionally, if I mistype in python shell or try to copy & paste a > line there, I get a permanent hang with the error below. It isn't > corrected by quitting IDLE, but is put right with a restart. I am > running 3.0.1 on Mac 10.5.6. Is this a bug, as it never happened on > the same system with 2.5 &2.6.1 ? > Is there another way to prevent this? > Regards > John Forse > > IDLE cant bind TCP/IP port 8833 which is necessary to communicate > with it's python execution server. Either no networking is installed > on this computer or another process(another IDLE?) is using the > port. Run IDLE with the -n command line switch to start without a > sub-process and refer to help/IDLE Help 'Running without a sub- > process' for further details > PS I AM connected to the network at the time and Help/Idle help is greyed-out on my IDLE. I've tried entering -n to IDLE on the initial blank window, but it seems to make no difference to the problem. I don't understand what is happening. -------------- next part -------------- An HTML attachment was scrubbed... URL: From nad at acm.org Thu Feb 19 22:02:41 2009 From: nad at acm.org (Ned Deily) Date: Thu, 19 Feb 2009 19:02:41 -0800 Subject: Problems with OS X 10.5.6 and Python 2.5 and GDAL 1.6 References: <60437775-ED63-469B-A2CC-913B0E77BC1E@ucsd.edu> <3A6157F5-DBA7-46B5-89A8-621DF6AB1F56@semanchuk.com> <2FE1A73A-5BDD-45CD-8323-CCDF68DF3269@ucsd.edu> Message-ID: In article <2FE1A73A-5BDD-45CD-8323-CCDF68DF3269 at ucsd.edu>, "Helly John J." wrote: >[...] > 3. I changed the gdal_merge.py code so it uses the correct syntax > even after the error but then find that I get the original 'no module' > error, I think, because gdal_merge.py starts with the line: > > #!/usr/bin/env python > > I don't understand this usage but when I run it alone (i.e., /usr/bin/ > env) I see that it forces the PATH, and the environment in general, to > be something different than what I have set in my .bash_profile. For > example, it puts > > PATH=/Library/Frameworks/Python.framework/Versions/Current/bin: > > in the beginning in front of /usr/bin which I had moved up in the path > in my .bash_profile. I overcame this by getting rid of /usr/bin/env > and substituting /usr/bin/python. See . The idea behind /usr/bin/env usage is to allow scripts to get around absolute paths and to be able to find the interpreter for the script by using the search order of $PATH. So, if the script with /usr/bin/env python was invoking the wrong python, it sounds like your $PATH wasn't really what you thought it was, despite changing your .bash_profile. Did you start a new terminal session or login shell? What does "echo $PATH" say? > So, there are three issues: > > 1. the malloc error > 2. the interaction with the gdal_merge.py error handling No suggestions on the first two, other than to perhaps install easy_install and GDAL and friends using the python.org 2.5 and/or to ask in a more specialized forum. > Otherwise, everything's peachy. Good luck! -- Ned Deily, nad at acm.org From cournape at gmail.com Thu Feb 19 22:06:13 2009 From: cournape at gmail.com (David Cournapeau) Date: Fri, 20 Feb 2009 12:06:13 +0900 Subject: Strange array.array performance In-Reply-To: <26ddd1750902191843j76e2df31nfb56ac18fe023c52@mail.gmail.com> References: <26ddd1750902191052i4e5caa21s2a4e32ff2d2d6e45@mail.gmail.com> <26ddd1750902191153lb1b5efaj783f1c75596d900c@mail.gmail.com> <5b8d13220902191834v3c6224baoa810a87650cad464@mail.gmail.com> <26ddd1750902191843j76e2df31nfb56ac18fe023c52@mail.gmail.com> Message-ID: <5b8d13220902191906g328084e7j4e4f2067e8d7f92@mail.gmail.com> On Fri, Feb 20, 2009 at 11:43 AM, Maxim Khitrov wrote: > > Yes, I may have a case where one thread is still sending data, while > another tries to close the connection, or two threads trying to close > the connection at the same time. In both cases, I need some parts of > the code to be atomic to prevent errors. That does not sound like the right approach, then. Matlab engine is not thread safe in that sense: http://www.mathworks.fr/support/solutions/data/1-YR98I.html?product=ML&solution=1-YR98I cheers, David From hellyj at ucsd.edu Thu Feb 19 22:07:57 2009 From: hellyj at ucsd.edu (Helly John J.) Date: Thu, 19 Feb 2009 19:07:57 -0800 Subject: Problems with OS X 10.5.6 and Python 2.5 and GDAL 1.6 In-Reply-To: References: <60437775-ED63-469B-A2CC-913B0E77BC1E@ucsd.edu> <3A6157F5-DBA7-46B5-89A8-621DF6AB1F56@semanchuk.com> <2FE1A73A-5BDD-45CD-8323-CCDF68DF3269@ucsd.edu> Message-ID: Thanks, Ned. Despite the problems, your help has given me something to work with. Cheers. -------------- John Helly, University of California, San Diego San Diego Supercomputer Center Scripps Institution of Oceanography 9500 Gilman Dr. Mail Code, La Jolla CA 92093 Phone: Voice +01 760 840 8660 mobile / stonesteps (Skype) / stonesteps7 (iChat) http://www.sdsc.edu/~hellyj On Feb 19, 2009, at 7:02 PM, Ned Deily wrote: In article <2FE1A73A-5BDD-45CD-8323-CCDF68DF3269 at ucsd.edu>, "Helly John J." wrote: > [...] > 3. I changed the gdal_merge.py code so it uses the correct syntax > even after the error but then find that I get the original 'no module' > error, I think, because gdal_merge.py starts with the line: > > #!/usr/bin/env python > > I don't understand this usage but when I run it alone (i.e., /usr/bin/ > env) I see that it forces the PATH, and the environment in general, to > be something different than what I have set in my .bash_profile. For > example, it puts > > PATH=/Library/Frameworks/Python.framework/Versions/Current/bin: > > in the beginning in front of /usr/bin which I had moved up in the path > in my .bash_profile. I overcame this by getting rid of /usr/bin/env > and substituting /usr/bin/python. See . The idea behind /usr/bin/env usage is to allow scripts to get around absolute paths and to be able to find the interpreter for the script by using the search order of $PATH. So, if the script with /usr/bin/env python was invoking the wrong python, it sounds like your $PATH wasn't really what you thought it was, despite changing your .bash_profile. Did you start a new terminal session or login shell? What does "echo $PATH" say? > So, there are three issues: > > 1. the malloc error > 2. the interaction with the gdal_merge.py error handling No suggestions on the first two, other than to perhaps install easy_install and GDAL and friends using the python.org 2.5 and/or to ask in a more specialized forum. > Otherwise, everything's peachy. Good luck! -- Ned Deily, nad at acm.org -- http://mail.python.org/mailman/listinfo/python-list From nad at acm.org Thu Feb 19 22:18:18 2009 From: nad at acm.org (Ned Deily) Date: Thu, 19 Feb 2009 19:18:18 -0800 Subject: Fwd: IDLE error on 3.0.1 References: <1C3FA0D1-D744-47AD-B9C5-684C1D045BE3@talktalk.net> <3F795AB3-9BA5-4833-971C-9A442CEF7D7F@talktalk.net> Message-ID: In article <3F795AB3-9BA5-4833-971C-9A442CEF7D7F at talktalk.net>, John Forse wrote: > > Occaisionally, if I mistype in python shell or try to copy & paste a > > line there, I get a permanent hang with the error below. It isn't > > corrected by quitting IDLE, but is put right with a restart. I am > > running 3.0.1 on Mac 10.5.6. Is this a bug, as it never happened on > > the same system with 2.5 &2.6.1 ? > > Is there another way to prevent this? > > Regards > > John Forse > > > > IDLE cant bind TCP/IP port 8833 which is necessary to communicate > > with it's python execution server. Either no networking is installed > > on this computer or another process(another IDLE?) is using the > > port. Run IDLE with the -n command line switch to start without a > > sub-process and refer to help/IDLE Help 'Running without a sub- > > process' for further details > > > PS I AM connected to the network at the time and Help/Idle help is > greyed-out on my IDLE. I've tried entering -n to IDLE on the initial > blank window, but it seems to make no difference to the problem. I > don't understand what is > happening.-------------------------------------------------------------------- The error message means that there is another IDLE still running so I assume you get this when you try to launch IDLE again after the first one hangs? If the first IDLE is hung, there should be either an IDLE or Python icon in your dock and, if IDLE is not responding to menu items or type-ins, you should be able to cause it to quit by pressing Option while clicking on the icon in the dock and selecting Force Quit. It would be very helpful if you could outline the steps to reproduce this (in particular, how you launch IDLE) and open an issue on the Python bug tracker: http://bugs.python.org/ -- Ned Deily, nad at acm.org From benjamin at python.org Thu Feb 19 22:21:57 2009 From: benjamin at python.org (Benjamin Peterson) Date: Fri, 20 Feb 2009 03:21:57 +0000 (UTC) Subject: To unicode or not to unicode References: Message-ID: Ron Garret flownet.com> writes: > > I'm writing a little wiki that I call ?Wiki. That's a lowercase Greek > mu at the beginning (it's pronounced micro-wiki). It's working, except > that I can't actually enter the name of the wiki into the wiki itself > because the default unicode encoding on my Python installation is > "ascii". So I'm trying to decide on a course of action. There seem to > be three possibilities: You should never have to rely on the default encoding. You should explicitly decode and encode data. > > 1. Change the code to properly support unicode. Preliminary > investigations indicate that this is going to be a colossal pain in the > ass. Properly handling unicode may be painful at first, but it will surely pay off in the future. From mkhitrov at gmail.com Thu Feb 19 22:31:05 2009 From: mkhitrov at gmail.com (Maxim Khitrov) Date: Thu, 19 Feb 2009 22:31:05 -0500 Subject: Strange array.array performance In-Reply-To: <5b8d13220902191906g328084e7j4e4f2067e8d7f92@mail.gmail.com> References: <26ddd1750902191052i4e5caa21s2a4e32ff2d2d6e45@mail.gmail.com> <26ddd1750902191153lb1b5efaj783f1c75596d900c@mail.gmail.com> <5b8d13220902191834v3c6224baoa810a87650cad464@mail.gmail.com> <26ddd1750902191843j76e2df31nfb56ac18fe023c52@mail.gmail.com> <5b8d13220902191906g328084e7j4e4f2067e8d7f92@mail.gmail.com> Message-ID: <26ddd1750902191931t148724bchc9fdb2d583f170f1@mail.gmail.com> On Thu, Feb 19, 2009 at 10:06 PM, David Cournapeau wrote: > On Fri, Feb 20, 2009 at 11:43 AM, Maxim Khitrov wrote: >> >> Yes, I may have a case where one thread is still sending data, while >> another tries to close the connection, or two threads trying to close >> the connection at the same time. In both cases, I need some parts of >> the code to be atomic to prevent errors. > > That does not sound like the right approach, then. Matlab engine is > not thread safe in that sense: > > http://www.mathworks.fr/support/solutions/data/1-YR98I.html?product=ML&solution=1-YR98I > > cheers, > > David > "One option is to use MUTEXes around every call into the MATLAB Engine" - that's exactly what I'm doing. Some setup work, like creating mxArrays is done without a lock, but all eng* calls are mutually exclusive. I've been doing a lot of my own testing, and so far have seen no problems with this approach. - Max From dean.wheatley at gmail.com Thu Feb 19 22:34:32 2009 From: dean.wheatley at gmail.com (dean.wheatley at gmail.com) Date: Thu, 19 Feb 2009 19:34:32 -0800 (PST) Subject: Matplotlib change xticks and retain xticks changing during zoom Message-ID: Hello, I execute the following code: try: from math import * import pylab as p except: print "Couldn't import all dependent libraries" sys.exit() dataLength = 100 data = [sin(2*pi*x/dataLength) for x in range(0,dataLength)] p.plot(data) p.show() This produces a figure window. When I zoom in regions of the plot, the xticks change correctly to the zoomed region. This is in contrast to the effect of the following code: try: from math import * import pylab as p except: print "Couldn't import all dependent libraries" sys.exit() dataLength = 100 data = [sin(2*pi*x/dataLength) for x in range(0,dataLength)] p.plot(data) newXTicks= [str(x/2.0) for x in p.xticks()[0]] p.xticks(p.xticks()[0], newXTicks) p.show() This code produces tick marks [0, 10, 20, 30, 40, 50]. However when zooming, the xtick marks do not adjust correctly to the zoomed regions. Your help on this issue would be great, thanks! From timr at probo.com Thu Feb 19 22:35:36 2009 From: timr at probo.com (Tim Roberts) Date: Thu, 19 Feb 2009 19:35:36 -0800 Subject: Will multithreading make python less popular? References: <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> <7x8wo2kwoz.fsf@ruckus.brouhaha.com> <975d0b81-0810-43c2-9734-b7a5a890e431@k19g2000prh.googlegroups.com> <7x3aeadqlo.fsf@ruckus.brouhaha.com> <7xmyci3tf0.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > >C is basically never appropriate. C should be outlawed by Congress >with the ban enforced by roving pie-throwing squads . One of my favorite quotes: The last good thing written in C was Schubert's Ninth Symphony. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From notvalid2 at sbcglobal.net Thu Feb 19 23:03:56 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Thu, 19 Feb 2009 20:03:56 -0800 Subject: Which Version of wxPython for Win XP In-Reply-To: References: <0Vfnl.5624$%54.4038@nlpi070.nbdc.sbc.com> Message-ID: Mike Driscoll wrote: > On Feb 19, 11:29 am, "W. eWatson" wrote: >> W. eWatson wrote: >>> Eric_Dex... at msn.com wrote: >>>> On Feb 19, 8:22 am, "W. eWatson" wrote: >>>>> I'm going to try out wxPython 2.8.92 for py25. It seems like the ansi >>>>> version is the choice for me. The other choice has unicode. Do I care? >>>>> -- >>>>> W. eWatson >>>>> (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) >>>>> Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet >>>>> Web Page: >>>> There is a good chance you don't care... I think the other is for >>>> internationalization... best to look.. It would be easier to answer >>>> the question if you said what you are going to do with it, and who >>>> needed to use your software. It's even possible that you might want >>>> to try pygame depending on what you want to use it for and who the >>>> audience is (and how good thier computers are) >>>> http://pypi.python.org/simple/Dex%20Tracker/ >>> Thanks. I think I'll take the chance. Somewhat simple programming. >>> Off I go to install it. It can always be un-installed. >> Well, that was an interesting experience. It appears to have recompiled a >> lot of stuff, and probably some libraries. IDLE is still with me as the way >> to open py files. Apparently, if I want to get around IDLE, I may have to >> install some other editor. >> >> -- >> W. eWatson >> > > The compiling you are referring to is just making the py files into > pyc files. This is normal and is a speed improvement. In fact, a lot > of the scripts you write will create a pyc file when first run. > > In other words, wxPython does not affect your Python install in any > way other than making itself available as a 3rd party package (i.e. > adding itself to the path), just like any other good 3rd party > package. I'm not sure why you're even talking about IDLE...wxPython is > a GUI toolkit, not an IDE. > > Mike Thanks. Yes, I finally discovered that the need here was not what I wanted afterall. Un-installed now. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From notvalid2 at sbcglobal.net Thu Feb 19 23:06:42 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Thu, 19 Feb 2009 20:06:42 -0800 Subject: Keeping the Console Open with IDLE Message-ID: I'm using IDLE for editing, but execute programs directly. If there are execution or "compile" errors, the console closes before I can see what it contains. How do I prevent that? -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From jitu.icfai at gmail.com Thu Feb 19 23:58:24 2009 From: jitu.icfai at gmail.com (jitendra gupta) Date: Fri, 20 Feb 2009 10:28:24 +0530 Subject: email varification using smtplib or any method Message-ID: hello here is my code for sending the mail, using this code email is going ''''''''''''''''''''''''''''''''''''''''''''''''''''''''' CODE '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' import smtplib from time import strftime from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.Utils import COMMASPACE, formatdate # Create message container - the correct MIME type is multipart/alternative. msg = MIMEMultipart('alternative') msg['Subject'] = " is sending the mail" msg['From'] = 'jitu.icfai at myprivatedomain.com ' msg['Date'] = formatdate(localtime=True) msg['To'] = 'jitu.icfai at gmail.com' # Create the body of the message (a plain-text and an HTML version). #text = "jitendra kya huy a!\nHow are you?\nHere is the link you wanted:\nhttp://www.python.org" html = """\

Hi!
How are you?
This mail is send by wjitenrda Here is the
link you wanted.

""" part2 = MIMEText(html, 'html') msg.attach(part2) # Send the message via local SMTP server. s = smtplib.SMTP('smtp.myprivatedomain.com ') s.login("user","password") s.sendmail(msg['From'], msg['To'], msg.as_string()) s.close() ''''''''''''''''''''''''''''''''''''''''''''''''''''''''' CODE END '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' using this code i am able to send the email , but problem is when i am changing msg['To'] = "wronguser at wrongdomain.comddsdjsdsdsjdh" some wrong email then i am getting back failure notice in my inbox, which i dont want.. is there any way so that i can identify wrong email during the run time (when i am sending the email) -------------- next part -------------- An HTML attachment was scrubbed... URL: From michele.simionato at gmail.com Fri Feb 20 00:22:49 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Thu, 19 Feb 2009 21:22:49 -0800 (PST) Subject: "metaclass conflict" error: where is noconflict ? References: <7F0503CD69378F49BE0DC30661C6CCF60E68800F@enbmail01.lsi.com> Message-ID: On Feb 19, 9:58?pm, Chris Rebert wrote: > On Thu, Feb 19, 2009 at 5:01 AM, Barak, Ron wrote: > > Hi, > > > I have a class derived from two parents (in blue below), which gives me the > > following error: > > > $ python -u ./failover_pickle_demo09.py > > Traceback (most recent call last): > > ? File "./failover_pickle_demo09.py", line 291, in > > ? ? class ListControl(wx.Frame, CopyAndPaste): > > TypeError: Error when calling the metaclass bases > > ? ? metaclass conflict: the metaclass of a derived class must be a > > (non-strict) subclass of the metaclasses of all its bases > > Googling suggested I should add > > from noconflict import classmaker > > and > > > __metaclass__=classmaker() > > to this class. > > > However, I don't seem able to find where to get the noconflict module from. > > > Do any of you where noconflict ?could be downloaded/installed from ? It refers to this cookbook recipe: http://code.activestate.com/recipes/204197/ See also the printed cookbook: http://books.google.it/books?id=1Shx_VXS6ioC&pg=PA786&lpg=PA786&dq=python+cookbook+noconflict&source=bl&ots=BB413AZ8R7&sig=cnAB-E9rNFolHBEZQTIm_d4Mj3o&hl=it&ei=GT2eSfCtBdWa_gadppHYCw&sa=X&oi=book_result&resnum=2&ct=result#PPA786,M1 However, there is no module to download, and this is on purpose: instead of blindly apply a "fix" one should understand what the conflict is: then it is quite easy to solve it by hand. The recipe discussion explains it all. From mccredie at gmail.com Fri Feb 20 00:42:08 2009 From: mccredie at gmail.com (Matimus) Date: Thu, 19 Feb 2009 21:42:08 -0800 (PST) Subject: Keeping the Console Open with IDLE References: Message-ID: <54c56179-6f92-41e9-bad7-afa8b28d0671@l38g2000vba.googlegroups.com> On Feb 19, 8:06?pm, "W. eWatson" wrote: > I'm using IDLE for editing, but execute programs directly. If there are > execution or "compile" errors, the console closes before I can see what it > contains. How do I prevent that? > -- > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? W. eWatson > > ? ? ? ? ? ? ? (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) > ? ? ? ? ? ? ? ?Obz Site: ?39? 15' 7" N, 121? 2' 32" W, 2700 feet > > ? ? ? ? ? ? ? ? ? ? ?Web Page: Open a console window and type in the name of the script rather than just double clicking on it. Or, you can terminate your script with a 'raw_input("press enter to quit")'. Matt From timr at probo.com Fri Feb 20 01:37:10 2009 From: timr at probo.com (Tim Roberts) Date: Thu, 19 Feb 2009 22:37:10 -0800 Subject: Which Version of wxPython for Win XP References: Message-ID: "W. eWatson" wrote: > >I'm going to try out wxPython 2.8.92 for py25. It seems like the ansi >version is the choice for me. The other choice has unicode. Do I care? Well, there's a subtle point that gives me an opportunity to point out a lesser-known "feature" of the NT-based systems (XP, Vista, etc). The core Win32 APIs on the NT-based systems are all Unicode. When you call an ANSI API, the system converts all of your ANSI strings to Unicode, then calls the Unicode API, then converts any output strings back to ANSI. So, there is, actually, a (small) performance advantage in using the Unicode APIs instead of the ANSI APIs. Unless you need your wx programs to run on Windows 98, I recommend you use the Unicode version of wxPython. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From steve at pearwood.info Fri Feb 20 01:57:07 2009 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 20 Feb 2009 17:57:07 +1100 Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> <7x8wo2kwoz.fsf@ruckus.brouhaha.com> <975d0b81-0810-43c2-9734-b7a5a890e431@k19g2000prh.googlegroups.com> Message-ID: <01ae49c5$0$20662$c3e8da3@news.astraweb.com> Steve Holden wrote: >> It's only an error if it gets in the way. It's the experience of a lot >> of programmers that it doesn't, so it's not an error. >> > And it's not a feature of the language, rather of one or two > implementations. Neither JPython not IronPython use a GIL to the best of > my knowledge, so you are still quite at liberty to use them. I found this interesting benchmark on the relative speeds of CPython 2.3, IronPython 0.1 and Jython 2.1. It's from six years ago, so not exactly reporting on the state of the art, but it suggests to me that IronPython is faster at the fundamentals but much slower at some things. http://www.python.org/~jeremy/weblog/031209a.html -- Steven From s.selvamsiva at gmail.com Fri Feb 20 02:03:35 2009 From: s.selvamsiva at gmail.com (S.Selvam Siva) Date: Fri, 20 Feb 2009 12:33:35 +0530 Subject: Levenshtein word comparison -performance issue In-Reply-To: References: Message-ID: On Sat, Feb 14, 2009 at 3:01 PM, Peter Otten <__peter__ at web.de> wrote: > Gabriel Genellina wrote: > > > En Fri, 13 Feb 2009 08:16:00 -0200, S.Selvam Siva < > s.selvamsiva at gmail.com> > > escribi?: > > > >> I need some help. > >> I tried to find top n(eg. 5) similar words for a given word, from a > >> dictionary of 50,000 words. > >> I used python-levenshtein module,and sample code is as follow. > >> > >> def foo(searchword): > >> disdict={} > >> for word in self.dictionary-words: > >> distance=Levenshtein.ratio(searchword,word) > >> disdict[word]=distance > >> """ > >> sort the disdict dictionary by values in descending order > >> """ > >> similarwords=sorted(disdict, key=disdict.__getitem__, reverse=True) > >> > >> return similarwords[:5] > > > > You may replace the last steps (sort + slice top 5) by heapq.nlargest - > at > > least you won't waste time sorting 49995 irrelevant words... > > Anyway you should measure the time taken by the first part (Levenshtein), > > it may be the most demanding. I think there is a C extension for this, > > should be much faster than pure Python calculations. > > > > [I didn't see the original post] > > You can use the distance instead of the ratio and put the words into bins > of > the same length. Then if you find enough words with a distance <= 1 in the > bin with the same length as the search word you can stop looking. > > You might be able to generalize this approach to other properties that are > fast to calculate and guarantee a minimum distance, e. g. set(word). > > Peter > -- > http://mail.python.org/mailman/listinfo/python-list > Thank you all for your response, [sorry,I was away for a while.] I used functools,heapq modules but that helped me a little, then i categorized the words depending on the length and compares with a small set(each set 50000/4=12,500), so now its taking quarter of time as compared to older method. Further, can i use Thread to achieve parallel comparison ?,as i have little knowledge on python-thread. Will the following code achive parallelism? thread1= threading.Thread(target=self.findsimilar, args=("1",searchword,dic-word-set1) thread2= threading.Thread(target=self.findsimilar, args=("2",searchword,dic-word-set1) thread3= threading.Thread(target=self.findsimilar, args=("3",searchword,dic-word-set1) thread1.start() thread2.start() thread3.start() thread1.join() thread2.join() thread3.join() I would like to hear suggestion. Note:The issue is i am developing spell checker for my local languge,i may use more than 2.5 lakh words,so i need to have a best way to find out alternative wordlist -- Yours, S.Selvam -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at pearwood.info Fri Feb 20 02:11:26 2009 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 20 Feb 2009 18:11:26 +1100 Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <28e3612d-2e91-4a91-82cb-5fb2deda95fd@q9g2000yqc.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> <7x8wo2kwoz.fsf@ruckus.brouhaha.com> Message-ID: <01ae4d21$0$20647$c3e8da3@news.astraweb.com> Paul Rubin wrote: > How old is your computer, why did you buy it, and is it the first one > you ever owned? > > For most of us, I suspect, it is not our first one, and we bought it > to get a processing speedup relative to the previous one. My computer is about eight months old, and I bought it because the previous one died. > If such > speedups were useless or unimportant, we would not have blown our hard > earned cash replacing perfectly good older hardware, Oh the assumptions in that statement... "Blowing hard-earned cash" assumes that people buy computers only when they need to. That's certainly not true -- there's a lot of irrational purchases involved. I have a friend who has just recently spent $2000 on storage so he can store more games and videos, which he cheerfully admits he'll never play or watch. He describes it as his "dragon's horde": it is for knowing it's there, not for using. Often hardware is upgraded because it's broken, or because you can't get parts, or because the software you need will only run on newer machines. I say *newer* rather than *faster*, because speed is only sometimes a factor in why software won't run on old machines. My old Mac running a 68030 in 1990 ran Microsoft Word perfectly fast enough for even advanced word processing needs, and nearly twenty years later, there's nothing I need from a word processor that I couldn't do in 1990. > so we have to > accept the concept that speed matters and ignore those platitudes that > say otherwise. The *perception* that speed matters, matters. The reality is that the majority of computing tasks outside of certain specialist niches are I/O bound, not CPU. Office server software is rarely CPU bound, and when it is, in my experience there's one rogue process using all the CPU: the software is broken, and a faster CPU would just let it be broken at a faster speed. Gamers need better graphics cards and more memory, not faster CPUs. Internet surfers need faster ethernet, more bandwidth and more memory, not faster CPUs. Graphics designers need bigger hard drives and more memory, not faster CPUs. (Hmm. There seems to be a pattern there...) Of course, there are a few niches that do require faster CPUs: video editing, some (but by no means all) Photoshop filters, number crunching, etc. But even for them, you can often get more bang-for-your-buck performance increase by adding more memory. Speaking for myself, I'd happily take a 20% slower CPU for more reliable, faster DVD/CD burning. What do I care if it takes my computer 120ms to open a window instead of 100ms, but I care a lot if it takes me 10 minutes to make a coaster instead of 7 minutes to make a good disc. -- Steven From steve at pearwood.info Fri Feb 20 02:19:14 2009 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 20 Feb 2009 18:19:14 +1100 Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> <7x8wo2kwoz.fsf@ruckus.brouhaha.com> <975d0b81-0810-43c2-9734-b7a5a890e431@k19g2000prh.googlegroups.com> <7x3aeadqlo.fsf@ruckus.brouhaha.com> <7xmyci3tf0.fsf@ruckus.brouhaha.com> Message-ID: <01ae4ef4$0$20660$c3e8da3@news.astraweb.com> Steve Holden wrote: > What Guido doesn't seem to have accepted yet is that slowing [C]Python > down by 50% on a single-processor CPU will actually be a worthwhile > tradeoff in ten years time, when nothing will have less than eight cores > and the big boys will be running at 64 kilo-cores. Ten years? There's no guarantee that Python will still even be around in ten years. It probably will be, I see no reason why it won't, but who knows? Maybe we'll have mandatory software warranties tailored to suit the Microsofts and Apples, and Guido and the PSF will be forced to abandon the language. I think a design mistake would be to hamstring Python now for a hypothetical benefit in a decade. But, well, in five years time, or three? Don't know. -- Steven From steve at pearwood.info Fri Feb 20 02:19:45 2009 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 20 Feb 2009 18:19:45 +1100 Subject: Regular expression bug? References: Message-ID: <01ae4f13$0$20660$c3e8da3@news.astraweb.com> andrew cooke wrote: > > i wonder what fraction of people posting with "bug?" in their titles here > actually find bugs? About 99.99%. Unfortunately, 99.98% have found bugs in their code, not in Python. -- Steven From clp2 at rebertia.com Fri Feb 20 02:35:50 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 19 Feb 2009 23:35:50 -0800 Subject: CSV readers and UTF-8 files In-Reply-To: <59de6aff-ed5f-40ca-8900-f8da908f7578@u39g2000prn.googlegroups.com> References: <59de6aff-ed5f-40ca-8900-f8da908f7578@u39g2000prn.googlegroups.com> Message-ID: <50697b2c0902192335w51f03c23vcedd12dbd1567dd0@mail.gmail.com> On Thu, Feb 19, 2009 at 8:11 AM, Falcolas wrote: > On Feb 19, 7:21 am, mk wrote: >> Hello everyone, >> >> Is it just me or CSV reader/DictReader and UTF-8 files do not work >> correctly in Python 2.6.1 (Windows)? > > I would point out in the CSV module documentation (http:// > docs.python.org/library/csv.html) it explicitly mentions that it can't > handle unicode. > > You can use their workaround in the examples section for UTF-8, or > with another form of encoding (I used MIME) for UTF-16. > > ~G This really ought to be fixed for 3.0+ (seems to still be ASCII-only according to the 3.0 docs...) Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From mail at microcorp.co.za Fri Feb 20 02:42:16 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Fri, 20 Feb 2009 09:42:16 +0200 Subject: Threading and tkinter References: <492d5db9-3681-4ae8-827e-f2a4f66bee80@v39g2000yqm.googlegroups.com><90d5e669-e8d1-441e-adff-ddc501d21d26@u13g2000yqg.googlegroups.com> Message-ID: <000e01c99332$bdc19c80$0d00a8c0@hendrik> "gert" > Hope you do not mind ignoring part of answers, so I can figure out > more why things work the way they are. > This two examples work, what i do not understand is that in function > display i do not have to declare root, v or x ? > x is easy - it was declared outside, in module scope, and you modified it after declaring it global. The others are more subtle, and have to do with how the interpreter searches for stuff - first in the local scope, then up the stack in the callers scope, up to finally in the module global scope. That also explains why, if it is not found, you get an error message that says "Global variable xxxxx not defined" (try it and see) - Hendrik From Scott.Daniels at Acm.Org Fri Feb 20 02:42:19 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 19 Feb 2009 23:42:19 -0800 Subject: Strange array.array performance In-Reply-To: References: <26ddd1750902191052i4e5caa21s2a4e32ff2d2d6e45@mail.gmail.com> <-MKdnYEu_r3SbwDUnZ2dnUVZ_gSWnZ2d@pdx.net> Message-ID: Maxim Khitrov wrote: > ... Here's the function that I'll be using from now on. It gives me > exactly the behavior I need, with an int initializer being treated as > array size. Still not as efficient as it could be if supported > natively by array (one malloc instead of two + memmove + extra > function call), but very good performance nevertheless: > > from array import array as _array > array_null = dict((tc, '\0' * _array(tc).itemsize) for tc in 'cbBuhHiIlLfd') How about: array_null = dict((tc, _array(tc, (0,)).tostring() for tc in 'cbBuhHiIlLfd') ... (some ancient floating points did not use all-0 bytes for 0.0). --Scott David Daniels Scott.Daniels at Acm.Org From robin at alldunn.com Fri Feb 20 02:44:54 2009 From: robin at alldunn.com (Robin Dunn) Date: Thu, 19 Feb 2009 23:44:54 -0800 Subject: ANN: wxPython 2.8.9.2 release Message-ID: <499E5F76.2080803@alldunn.com> The wxWidgets team is in the early stages of preparing for a 2.8.10 release, but I already had a set of 2.8.9.2 release candidate files that I made a few days ago. Since it's still possible that there could be delays in the 2.8.10 release I thought that it would be nice to go ahead and release the 2.8.9.2 binaries. So... Announcing ---------- The 2.8.9.2 release of wxPython is now available for download at http://wxpython.org/download.php. This release adds the wx.lib.agw package, adds an event watcher to the widget inspection tool, and fixes a bunch of bugs. A summary of changes is listed below and also at http://wxpython.org/recentchanges.php. Source code is available as a tarball and a source RPM, as well as binaries for Python 2.4, 2.5 and 2.6[1], for Windows and Mac, as well some packages for various Linux distributions. [1] If installing the Python 2.6 version of wxPython on 64-bit XP or Vista then please read the README presented by the installer for instructions on how to enable the themed controls. (If anybody has a better solution for this please let Robin know.) What is wxPython? ----------------- wxPython is a GUI toolkit for the Python programming language. It allows Python programmers to create programs with a robust, highly functional graphical user interface, simply and easily. It is implemented as a Python extension module that wraps the GUI components of the popular wxWidgets cross platform library, which is written in C++. wxPython is a cross-platform toolkit. This means that the same program will usually run on multiple platforms without modifications. Currently supported platforms are 32-bit and 64-bit Microsoft Windows, most Linux or other Unix-like systems using GTK2, and Mac OS X 10.4+. In most cases the native widgets are used on each platform to provide a 100% native look and feel for the application. Changes in 2.8.9.2 ------------------ Added the wx.lib.agw package, which contiains most of the widgets from http://xoomer.alice.it/infinity77/main/freeware.html written by Andrea Gavana. Andrea's widgets that were already in wx.lib were also moved to the wx.lib.agw package, with a small stub module left in wx.lib. As part of this addition the demo framework was given the ability to load demo modules from a sub-folder of the demo directory, to make it easier to maintain collections of demo samples as a group. Added the wx.PyPickerBase class which can be used to derive new picker classes in Python. Used it to implement a color picker for Mac that uses a wx.BitmapButton instead of a normal wx.Button. This makes the color picker look and behave lots better on Mac than before. You can now pass the handler function to the Unbind method. If it is given then Unbind will only disconenct the event handler that uses the same handler function, so if there are multiple bindings for the same event type you'll now be able to selectively unbind specific instances. Added a new tool to the Widget Inspection Tool that allows you to watch the events passing through a widget. It can also be used independently, see wx.lib.eventwatcher. -- Robin Dunn Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython! From mail at microcorp.co.za Fri Feb 20 03:04:39 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Fri, 20 Feb 2009 10:04:39 +0200 Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <28e3612d-2e91-4a91-82cb-5fb2deda95fd@q9g2000yqc.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> <7x8wo2kwoz.fsf@ruckus.brouhaha.com> <975d0b81-0810-43c2-9734-b7a5a890e431@k19g2000prh.googlegroups.com> <1235082919.21735.30.camel@tim-laptop><499DF0AC.2030306@mrabarnett.plus.com> <499DF688.2050303@holdenweb.com> Message-ID: <000f01c99332$be58ac60$0d00a8c0@hendrik> "Steve Holden" wrote: > Perhaps it's time Python stopped being a dictatorship? This will need a wholesale switch to the worship of Freya - It is rumoured that She is capable of herding cats. - Hendrik From bj_666 at gmx.net Fri Feb 20 03:08:36 2009 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: 20 Feb 2009 08:08:36 GMT Subject: iterating through files References: Message-ID: <7076o4Fn42niU1@mid.uni-berlin.de> On Thu, 19 Feb 2009 13:56:38 -0800, oamram wrote: > new to python. i have a directory with about 50 text file and i need to > iterate through them and get > line 7 to 11 from each file and write those lines into another file(one > file that will contain all lines). Untested: from __future__ import with_statement from glob import glob from itertools import islice def main(): with open('result.txt', 'w') as out_file: for filename in glob('foo/*.txt'): with open(filename, 'r') as lines: out_file.writelines(islice(lines, 7, 12)) if __name__ == "__main__": main() Ciao, Marc 'BlackJack' Rintsch From astan.chee at al.com.au Fri Feb 20 03:50:08 2009 From: astan.chee at al.com.au (Astan Chee) Date: Fri, 20 Feb 2009 19:50:08 +1100 Subject: get most common number in a list with tolerance Message-ID: <499E6EC0.8090509@al.com.au> Hi, I have a list that has a bunch of numbers in it and I want to get the most common number that appears in the list. This is trivial because i can do a max on each unique number. What I want to do is to have a tolerance to say that each number is not quite unique and if the difference from other numbers is small, than it can be counted together. This is what I have to get the common number (taken from the internet somewhere): l = [10,30,20,20,11,12] d = {} tolerance = 5 for elm in l: d[elm] = d.get(elm, 0) + 1 counts = [(j,i) for i,j in d.items()] This of course returns a list where each of them is unique [(1, 12), (1, 10), (1, 11), (2, 20), (1, 30)] but I am expecting a list that looks like this: [(3, 10), (2, 20), (1, 30)] What do I need to add? Thanks for any help. Cheers Astan From rushenaly at gmail.com Fri Feb 20 04:25:43 2009 From: rushenaly at gmail.com (rushenaly at gmail.com) Date: Fri, 20 Feb 2009 01:25:43 -0800 (PST) Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> <7x8wo2kwoz.fsf@ruckus.brouhaha.com> <975d0b81-0810-43c2-9734-b7a5a890e431@k19g2000prh.googlegroups.com> <7x3aeadqlo.fsf@ruckus.brouhaha.com> <7xmyci3tf0.fsf@ruckus.brouhaha.com> Message-ID: On 20 ?ubat, 01:20, Paul Rubin wrote: > I would say, slow execution is a drawback that we put up with in order > to gain benefits of Python programming that are mostly unrelated to > the causes of the slowness. ?The slowness itself can be addressed by > technical means, such as native-code compilation and eliminating the > GIL. ?I believe (for example) that the PyPy project is doing both of > these. Do you believe that there is an effort for removing gil with pypy. As i know there is not an intend to remove gil with pypy. GIL will be possibly used in PyPy. There is a mistake in your reply or mine. Thank you Rushen From grflanagan at gmail.com Fri Feb 20 05:15:42 2009 From: grflanagan at gmail.com (Gerard Flanagan) Date: Fri, 20 Feb 2009 10:15:42 +0000 Subject: get most common number in a list with tolerance In-Reply-To: <499E6EC0.8090509@al.com.au> References: <499E6EC0.8090509@al.com.au> Message-ID: Astan Chee wrote: > Hi, > I have a list that has a bunch of numbers in it and I want to get the > most common number that appears in the list. This is trivial because i > can do a max on each unique number. What I want to do is to have a > tolerance to say that each number is not quite unique and if the > difference from other numbers is small, than it can be counted together. > This is what I have to get the common number (taken from the internet > somewhere): > > l = [10,30,20,20,11,12] > d = {} > tolerance = 5 > for elm in l: > d[elm] = d.get(elm, 0) + 1 > counts = [(j,i) for i,j in d.items()] > > > > This of course returns a list where each of them is unique > > [(1, 12), (1, 10), (1, 11), (2, 20), (1, 30)] > > but I am expecting a list that looks like this: > > [(3, 10), (2, 20), (1, 30)] > Maybe check for this number: tolerance * ( X / tolerance) or a variation if tolerance is non-integer? Eg. (rough): from itertools import groupby def tmax(seq, alpha): longest = [] for k, g in groupby(sorted(seq), lambda x: alpha * (x / alpha)): g = list(g) if len(g) > len(longest): longest = g return longest[0] a = [10, 30, 20, 20, 11, 12] assert tmax(a, 5) == 10 assert tmax(a, 1) == 20 From sturlamolden at yahoo.no Fri Feb 20 05:36:14 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Fri, 20 Feb 2009 02:36:14 -0800 (PST) Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <28e3612d-2e91-4a91-82cb-5fb2deda95fd@q9g2000yqc.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> <7x8wo2kwoz.fsf@ruckus.brouhaha.com> <52a0375d-4fad-4caa-8328-47b8f30f2395@40g2000prx.googlegroups.com> Message-ID: On Feb 20, 12:19 am, Mensanator wrote: > What am I actually seeing? If Python only uses one of the cores, > why do both light up? Because of OS scheduling. You have more than one process running. The Python process does not stay on one core. Try to put CPython into a tight loop ("while 1: pass"). You will see ~50% use of both cores. If you had 4 cores, you would see ~25% use. > Is everything much more complicated (due to > OS scheduling, etc.) than the simple explanations of GIL? No. Your Python code cannot use more than one core simultaneously. It's just that scheduling happens so fast and so often that you don't notice it. From nick at craig-wood.com Fri Feb 20 06:31:54 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Fri, 20 Feb 2009 05:31:54 -0600 Subject: How do I declare global vars or class vars in Python ? References: Message-ID: Linuxguy123 wrote: > How do I do this in Python ? > > ############################# > declare A,B > > function getA > return A > > function getB > return B > > function setA(value) > A = value > > function setB(value) > B = value > > main() > getA > getB > dosomething > setA(aValue) > setB(aValue) > ############################ > > The part I don't know to do is declare the variables, either as globals > or as vars in a class. How is this done in Python without setting them > to a value ? Variables can have any value in python so if you want to pre-declare then you set them to None normally. As a class :- class Stuff(object): def __init__(self): self.A = None self.B = None def getA(self): return self.A def getB(self): return self.B def setA(self, value): self.A = value def setB(self, value): self.B = value >>> a = Stuff() >>> print a.getA() None >>> print a.getB() None >>> # dosomething ... a.setA("aValue") >>> a.setB("aValue") >>> print a.getA() aValue >>> print a.getB() aValue >>> Note that in python we don't normally bother with getA/setA normally, just use self.A, eg class Stuff(object): def __init__(self): self.A = None self.B = None def main(self): print self.A print self.B # dosomething self.A = "aValue" self.B = "aValue" print self.A print self.B >>> a = Stuff() >>> a.main() None None aValue aValue >>> If you need (later) A to be a computed value then you turn it into a property, which would look like this. (Note the main method is identical to that above). class Stuff(object): def __init__(self): self._A = None self.B = None def _getA(self): print "Getting A" return self._A def _setA(self, value): print "Setting A" self._A = value A = property(_getA, _setA) def main(self): print self.A print self.B # dosomething self.A = "aValue" self.B = "aValue" print self.A print self.B >>> a = Stuff() >>> a.main() Getting A None None Setting A Getting A aValue aValue >>> -- Nick Craig-Wood -- http://www.craig-wood.com/nick From gagsl-py2 at yahoo.com.ar Fri Feb 20 07:13:59 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 20 Feb 2009 10:13:59 -0200 Subject: email varification using smtplib or any method References: Message-ID: En Fri, 20 Feb 2009 02:58:24 -0200, jitendra gupta escribi?: > when i am changing > msg['To'] = "wronguser at wrongdomain.comddsdjsdsdsjdh" > some wrong email then i am getting back failure notice in my inbox, > which i > dont want.. > is there any way so that i can identify wrong email during the run time > (when i am sending the email) In practice, no, due to spam. If you connect directly to the destination SMTP (instead of your own), you could try the VRFY command (if supported by the server); but most servers just return a generic 252 response. -- Gabriel Genellina From mkhitrov at gmail.com Fri Feb 20 07:23:09 2009 From: mkhitrov at gmail.com (Maxim Khitrov) Date: Fri, 20 Feb 2009 07:23:09 -0500 Subject: Strange array.array performance In-Reply-To: References: <26ddd1750902191052i4e5caa21s2a4e32ff2d2d6e45@mail.gmail.com> <-MKdnYEu_r3SbwDUnZ2dnUVZ_gSWnZ2d@pdx.net> Message-ID: <26ddd1750902200423k6ede957arf6976ced8e835e01@mail.gmail.com> On Fri, Feb 20, 2009 at 2:42 AM, Scott David Daniels wrote: > Maxim Khitrov wrote: >> >> ... Here's the function that I'll be using from now on. It gives me >> exactly the behavior I need, with an int initializer being treated as >> array size. Still not as efficient as it could be if supported >> natively by array (one malloc instead of two + memmove + extra >> function call), but very good performance nevertheless: >> >> from array import array as _array >> array_null = dict((tc, '\0' * _array(tc).itemsize) for tc in >> 'cbBuhHiIlLfd') > > How about: > array_null = dict((tc, _array(tc, (0,)).tostring() for tc in > 'cbBuhHiIlLfd') > ... > (some ancient floating points did not use all-0 bytes for 0.0). Didn't know that, thanks. I actually got rid of the dict, since benchmarks showed access time to itemsize in the function itself is not any slower than dict access. After going through all the different speed tests yesterday the function now looks like this: from array import array as _array def array(typecode, init): if isinstance(init, int): a = _array(typecode, (0,)) if a.itemsize * init > 1048576: return a * init else: a.fromstring((init - 1) * a.tostring()) return a return _array(typecode, init) This uses the fast fromstring operation when creating an array that is less than 1MB in size. Over that, array multiplication is used, which is slower, but doesn't require the extra memory. - Max From notvalid2 at sbcglobal.net Fri Feb 20 07:30:21 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Fri, 20 Feb 2009 04:30:21 -0800 Subject: Keeping the Console Open with IDLE In-Reply-To: <54c56179-6f92-41e9-bad7-afa8b28d0671@l38g2000vba.googlegroups.com> References: <54c56179-6f92-41e9-bad7-afa8b28d0671@l38g2000vba.googlegroups.com> Message-ID: Matimus wrote: > On Feb 19, 8:06 pm, "W. eWatson" wrote: >> I'm using IDLE for editing, but execute programs directly. If there are >> execution or "compile" errors, the console closes before I can see what it >> contains. How do I prevent that? >> -- >> W. eWatson >> >> (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) >> Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet >> >> Web Page: > > Open a console window and type in the name of the script rather than > just double clicking on it. Or, you can terminate your script with a > 'raw_input("press enter to quit")'. > > Matt I can open the Python command line from Start, but how do I navigate to the folder where the program is? -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From lie.1296 at gmail.com Fri Feb 20 08:03:50 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Fri, 20 Feb 2009 13:03:50 +0000 (UTC) Subject: Regular expression bug? References: Message-ID: On Thu, 19 Feb 2009 13:03:59 -0800, Ron Garret wrote: > In article , > Peter Otten <__peter__ at web.de> wrote: > >> Ron Garret wrote: >> >> > I'm trying to split a CamelCase string into its constituent >> > components. >> >> How about >> >> >>> re.compile("[A-Za-z][a-z]*").findall("fooBarBaz") >> ['foo', 'Bar', 'Baz'] > > That's very clever. Thanks! > >> > (BTW, I tried looking at the source code for the re module, but I >> > could not find the relevant code. re.split calls >> > sre_compile.compile().split, but the string 'split' does not appear >> > in sre_compile.py. So where does this method come from?) >> >> It's coded in C. The source is Modules/sremodule.c. > > Ah. Thanks! > > rg This re.split() doesn't consume character: >>> re.split('([A-Z][a-z]*)', 'fooBarBaz') ['foo', 'Bar', '', 'Baz', ''] it does what the OP wants, albeit with extra blank strings. From bruno.42.desthuilliers at websiteburo.invalid Fri Feb 20 08:04:15 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 20 Feb 2009 14:04:15 +0100 Subject: How do I declare global vars or class vars in Python ? In-Reply-To: References: Message-ID: <499eaa34$0$21372$426a74cc@news.free.fr> Nick Craig-Wood a ?crit : (snip) > Note that in python we don't normally bother with getA/setA normally, > just use self.A, eg > > class Stuff(object): > def __init__(self): > self.A = None > self.B = None > def main(self): > print self.A > print self.B > # dosomething > self.A = "aValue" > self.B = "aValue" > print self.A > print self.B > >>>> a = Stuff() >>>> a.main() > None > None > aValue > aValue >>>> > > If you need (later) A to be a computed value then you turn it into a > property, which would look like this. (Note the main method is > identical to that above). > > class Stuff(object): > def __init__(self): > self._A = None Note that while you *can* do direct access to the implementation attribute (here, '_A' for property 'A'), you don't *need* to so (and usually shouldn't - unless you have a very compelling reason). From alainpoint at yahoo.fr Fri Feb 20 08:12:03 2009 From: alainpoint at yahoo.fr (alain) Date: Fri, 20 Feb 2009 05:12:03 -0800 (PST) Subject: import bug? Message-ID: Hi all, Running python 2.5, i experience a strange behaviour with the following code:import imputil def handle_pye(fullpath, fileinfo, name): # Print a debugging message print 'Importing "%s" from "%s"' % (name,fullpath) data = open(fullpath).read() return 0, compile(data,fullpath,'exec'),{} im = imputil.ImportManager() im.add_suffix('.pye',handle_pye) im.install() # THIS SEEMS TO DO WEIRD THINGS TO SUBSEQUENT IMPORTS !!!! import functools I then get the following traceback: Traceback (most recent call last): File "D:\deleteme\New1.py", line 12, in import functools File "C:\Python25\lib\imputil.py", line 103, in _import_hook top_module = self._import_top_module(parts[0]) File "C:\Python25\lib\imputil.py", line 190, in _import_top_module module = self.fs_imp.import_from_dir(item, name) File "C:\Python25\lib\imputil.py", line 545, in import_from_dir return self._process_result(result, fqname) File "C:\Python25\lib\imputil.py", line 304, in _process_result exec code in module.__dict__ File "C:\Python25\lib\functools.py", line 10, in from _functools import partial File "C:\Python25\lib\imputil.py", line 106, in _import_hook raise ImportError, 'No module named ' + fqname ImportError: No module named _functools The mere fact of installing a custom importer seems to break the import functionality. Alain From dns4 at cornell.edu Fri Feb 20 08:14:34 2009 From: dns4 at cornell.edu (David Smith) Date: Fri, 20 Feb 2009 08:14:34 -0500 Subject: Keeping the Console Open with IDLE In-Reply-To: References: <54c56179-6f92-41e9-bad7-afa8b28d0671@l38g2000vba.googlegroups.com> Message-ID: W. eWatson wrote: > Matimus wrote: >> On Feb 19, 8:06 pm, "W. eWatson" wrote: >>> I'm using IDLE for editing, but execute programs directly. If there are >>> execution or "compile" errors, the console closes before I can see >>> what it >>> contains. How do I prevent that? >>> -- >>> W. eWatson >>> >>> (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) >>> Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet >>> >>> Web Page: >> >> Open a console window and type in the name of the script rather than >> just double clicking on it. Or, you can terminate your script with a >> 'raw_input("press enter to quit")'. >> >> Matt > I can open the Python command line from Start, but how do I navigate to > the folder where the program is? > I'm not sure whether I should feel old or write a smart alec comment -- I suppose there are people in the world who don't know what to do with a command prompt.... Assuming a Windows system: 2. Type 'cd ' (as in Change Directory) in the command prompt window (w/o the single quote characters) 3. Drag/drop the folder containing your python script to your command prompt window 4. Hit enter in your command prompt window. 5. Type python my_script_name.py to execute my_script_name.py. --David From bblais at bryant.edu Fri Feb 20 08:32:36 2009 From: bblais at bryant.edu (Brian Blais) Date: Fri, 20 Feb 2009 08:32:36 -0500 Subject: Keeping the Console Open with IDLE In-Reply-To: References: Message-ID: On Feb 19, 2009, at 23:06 , W. eWatson wrote: > I'm using IDLE for editing, but execute programs directly. Is there a reason you are executing them directly? Why not just run the script from IDLE with Run/Run Module (F5) until you are sure there are no errors? You can follow the advice already posted, by running it directly from the commandline. Another hack is to put: x=raw_input("pausing...") at the end of your script, but this is really a hack and it would be better to use a different solution. bb -- Brian Blais bblais at bryant.edu http://web.bryant.edu/~bblais -------------- next part -------------- An HTML attachment was scrubbed... URL: From notvalid2 at sbcglobal.net Fri Feb 20 08:49:29 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Fri, 20 Feb 2009 05:49:29 -0800 Subject: Keeping the Console Open with IDLE In-Reply-To: References: <54c56179-6f92-41e9-bad7-afa8b28d0671@l38g2000vba.googlegroups.com> Message-ID: > > I'm not sure whether I should feel old or write a smart alec comment -- > I suppose there are people in the world who don't know what to do with a > command prompt.... > > Assuming a Windows system: > > 2. Type 'cd ' (as in Change Directory) in the command prompt window (w/o > the single quote characters) > 3. Drag/drop the folder containing your python script to your command > prompt window > 4. Hit enter in your command prompt window. > 5. Type python my_script_name.py to execute my_script_name.py. > > --David If I enter just cd, then it tells me cd is not defined. If I enter c:/python25, it tells me I have a syntax error at c in c:. The title of the black background window I have up with a >>> prompt shown in it is "Python(command line)". Maybe this isn't the real Python console window? What I want is that if I execute the program by double clicking on its name to display the console window with the program or syntax errors shown without it closing in a split second. Putting read_raw in it doesn't work, since some error prevents it from ever being seen. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From catherine.heathcote at gmail.com Fri Feb 20 09:01:08 2009 From: catherine.heathcote at gmail.com (Catherine Heathcote) Date: Fri, 20 Feb 2009 14:01:08 GMT Subject: Keeping the Console Open with IDLE In-Reply-To: References: <54c56179-6f92-41e9-bad7-afa8b28d0671@l38g2000vba.googlegroups.com> Message-ID: W. eWatson wrote: > >> >> I'm not sure whether I should feel old or write a smart alec comment -- >> I suppose there are people in the world who don't know what to do with a >> command prompt.... >> >> Assuming a Windows system: >> >> 2. Type 'cd ' (as in Change Directory) in the command prompt window (w/o >> the single quote characters) >> 3. Drag/drop the folder containing your python script to your command >> prompt window >> 4. Hit enter in your command prompt window. >> 5. Type python my_script_name.py to execute my_script_name.py. >> >> --David > If I enter just cd, then it tells me cd is not defined. If I enter > c:/python25, it tells me I have a syntax error at c in c:. The title of > the black background window I have up with a >>> prompt shown in it is > "Python(command line)". Maybe this isn't the real Python console window? > > What I want is that if I execute the program by double clicking on its > name to display the console window with the program or syntax errors > shown without it closing in a split second. Putting read_raw in it > doesn't work, since some error prevents it from ever being seen. > you need to open a dos prompt before doing the steps above. Go to start->run and hit "cmd" without the quotes. From notvalid2 at sbcglobal.net Fri Feb 20 09:05:08 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Fri, 20 Feb 2009 06:05:08 -0800 Subject: Keeping the Console Open with IDLE In-Reply-To: References: <54c56179-6f92-41e9-bad7-afa8b28d0671@l38g2000vba.googlegroups.com> Message-ID: W. eWatson wrote: > >> >> I'm not sure whether I should feel old or write a smart alec comment -- >> I suppose there are people in the world who don't know what to do with a >> command prompt.... >> >> Assuming a Windows system: >> >> 2. Type 'cd ' (as in Change Directory) in the command prompt window (w/o >> the single quote characters) >> 3. Drag/drop the folder containing your python script to your command >> prompt window >> 4. Hit enter in your command prompt window. >> 5. Type python my_script_name.py to execute my_script_name.py. >> >> --David > If I enter just cd, then it tells me cd is not defined. If I enter > c:/python25, it tells me I have a syntax error at c in c:. The title of > the black background window I have up with a >>> prompt shown in it is > "Python(command line)". Maybe this isn't the real Python console window? > > What I want is that if I execute the program by double clicking on its > name to display the console window with the program or syntax errors > shown without it closing in a split second. Putting read_raw in it > doesn't work, since some error prevents it from ever being seen. > Whoa! What's going on here? I just looked at About IDLE, and it shows 1.2.2, but yet the second edition of Learning Python talks about going to 2.3 as the book is about to go to press, 2004. I thought IDLE came bundled with Python. I have Py 2.5. 1.2.2??? Puzzled. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From gagsl-py2 at yahoo.com.ar Fri Feb 20 09:18:20 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 20 Feb 2009 12:18:20 -0200 Subject: Keeping the Console Open with IDLE References: <54c56179-6f92-41e9-bad7-afa8b28d0671@l38g2000vba.googlegroups.com> Message-ID: En Fri, 20 Feb 2009 12:05:08 -0200, W. eWatson escribi?: > Whoa! What's going on here? I just looked at About IDLE, and it shows > 1.2.2, but yet the second edition of Learning Python talks about going > to 2.3 as the book is about to go to press, 2004. I thought IDLE came > bundled with Python. I have Py 2.5. 1.2.2??? Puzzled. IDLE is a separate product; the version of IDLE that comes with Python 2.5.4 is 1.2.4 -- Gabriel Genellina From thomasmallen at gmail.com Fri Feb 20 09:22:29 2009 From: thomasmallen at gmail.com (Thomas Allen) Date: Fri, 20 Feb 2009 06:22:29 -0800 (PST) Subject: FTP libs for Python? Message-ID: <031c6600-b8fb-49d6-bf24-aa12ff494376@p20g2000yqi.googlegroups.com> I'm interested in writing a script to ease deployment of minor changes on some websites here, and it would involve some SFTP transfers. Do you know of good alternatives to ftplib, which is relatively low- level? Thomas From notvalid2 at sbcglobal.net Fri Feb 20 09:29:35 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Fri, 20 Feb 2009 06:29:35 -0800 Subject: Keeping the Console Open with IDLE In-Reply-To: References: <54c56179-6f92-41e9-bad7-afa8b28d0671@l38g2000vba.googlegroups.com> Message-ID: <81znl.13277$D32.3772@flpi146.ffdc.sbc.com> Gabriel Genellina wrote: > En Fri, 20 Feb 2009 12:05:08 -0200, W. eWatson > escribi?: > >> Whoa! What's going on here? I just looked at About IDLE, and it shows >> 1.2.2, but yet the second edition of Learning Python talks about going >> to 2.3 as the book is about to go to press, 2004. I thought IDLE came >> bundled with Python. I have Py 2.5. 1.2.2??? Puzzled. > > IDLE is a separate product; the version of IDLE that comes with Python > 2.5.4 is 1.2.4 > Where do I get 2.x.x, or the latest? -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From evert.rol at gmail.com Fri Feb 20 09:30:26 2009 From: evert.rol at gmail.com (Evert Rol) Date: Fri, 20 Feb 2009 15:30:26 +0100 Subject: Framework installation of 2.6 on OS X, with specified prefix Message-ID: Hi, I'm trying to install Python 2.6 from source on Mac OS X.5, in its own directory using a framework install. That goes fine, up to the point where it wants to install the applications that come with it (eg, the Wish shell): it tries to install things into /Applications, instead of eg /Applications. Here's my configure line (the flags are there just to let it find my own installed readline): CPPFLAGS=-I/sw/include LDFLAGS=-L/sw/lib ./configure --prefix=/sw -- enable-shared --enable-framework=/sw/Library/Frameworks --with- readline=/sw --with-pth CC=gcc-4.2 MACOSX_DEPLOYMENT_TARGET=10.5 And the last part of the output of 'make install': ../python.exe ./scripts/BuildApplet.py \ --destroot "" \ --python=/sw/Library/Frameworks/Python.framework/Versions/2.6/ Resources/Python.app/Contents/MacOS/Python`test -f "/sw/Library/ Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/ MacOS/Python-32" && echo "-32"` \ --output "/sw/Applications/Python 2.6/Build Applet.app" \ ./scripts/BuildApplet.py cd PythonLauncher && make install DESTDIR= test -d "/Applications/Python 2.6" || mkdir -p "/Applications/Python 2.6" mkdir: /Applications/Python 2.6: Permission denied make[2]: *** [install] Error 1 make[1]: *** [install_PythonLauncher] Error 2 make: *** [frameworkinstallapps] Error 2 Is there an option on the configure line that I need to set, or something in setup.py? Or perhaps hack the Makefile? Evert From luke.dunn at gmail.com Fri Feb 20 09:31:03 2009 From: luke.dunn at gmail.com (Trip Technician) Date: Fri, 20 Feb 2009 06:31:03 -0800 (PST) Subject: code challenge: generate minimal expressions using only digits 1,2,3 Message-ID: <941be713-2789-48c7-911b-422313f232d5@o36g2000yqh.googlegroups.com> anyone interested in looking at the following problem. we are trying to express numbers as minimal expressions using only the digits one two and three, with conventional arithmetic. so for instance 33 = 2^(3+2)+1 = 3^3+(3*2) are both minimal, using 4 digits but 33 = ((3+2)*2+1)*3 using 5 is not. I have tried coding a function to return the minimal representation for any integer, but haven't cracked it so far. The naive first attempt is to generate lots of random strings, eval() them and sort by size and value. this is inelegant and slow. I have a dim intuition that it could be done with a very clever bit of recursion, but the exact form so far eludes me. From notvalid2 at sbcglobal.net Fri Feb 20 09:39:14 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Fri, 20 Feb 2009 06:39:14 -0800 Subject: Keeping the Console Open with IDLE In-Reply-To: References: <54c56179-6f92-41e9-bad7-afa8b28d0671@l38g2000vba.googlegroups.com> Message-ID: Catherine Heathcote wrote: > W. eWatson wrote: >> >>> >>> I'm not sure whether I should feel old or write a smart alec comment -- >>> I suppose there are people in the world who don't know what to do with a >>> command prompt.... >>> >>> Assuming a Windows system: >>> >>> 2. Type 'cd ' (as in Change Directory) in the command prompt window (w/o >>> the single quote characters) >>> 3. Drag/drop the folder containing your python script to your command >>> prompt window >>> 4. Hit enter in your command prompt window. >>> 5. Type python my_script_name.py to execute my_script_name.py. >>> >>> --David >> If I enter just cd, then it tells me cd is not defined. If I enter >> c:/python25, it tells me I have a syntax error at c in c:. The title >> of the black background window I have up with a >>> prompt shown in it >> is "Python(command line)". Maybe this isn't the real Python console >> window? >> >> What I want is that if I execute the program by double clicking on its >> name to display the console window with the program or syntax errors >> shown without it closing in a split second. Putting read_raw in it >> doesn't work, since some error prevents it from ever being seen. >> > > you need to open a dos prompt before doing the steps above. Go to > start->run and hit "cmd" without the quotes. Something is amiss here. There's the MS Command Prompt, which I'm looking at right now. Yes, it has cd, and so on. I'm also looking at the Python command line window. It allow one to run interactively. If I write a simple python program with just raw_input, by clicking on the file name, I get a window with the the title "\Python25\pythonexe" that shows the prompt. If I deliberately put a syntax error in the program, and run it by clicking the file, then A window appears and disappears so quickly that I have no idea what it said. How do I keep that window up? Which, if any, of these is the real Python console? What is the window called in the example I gave with raw_input? -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From vriolk at gmail.com Fri Feb 20 09:41:51 2009 From: vriolk at gmail.com (coldpizza) Date: Fri, 20 Feb 2009 06:41:51 -0800 (PST) Subject: Newbie request assistance....Python - PAMIE - Java References: Message-ID: This is not a Pamie issue. Pamie can only see the HTML part of the page. Any object embedded in the page using the or tags is not accessible to the browser, and the browser has no idea what is inside those objects - it simply passes control to the corresponding plugin, such as Java, Flash, ActiveX, etc. To script user interaction with an applet you will probably need some expensive commercial software such as QuickTestPro or SilkTest. Pamie is IE-only and does not seem to be actively developed. If you need a good and robust HTML testing framework look into Selenium, especially Selenium Remote Control, which can be used with a number of languages including Python. As for embedded stuff like Flash or Java applets, there is no freeware tool that I am aware of which would be able to work with both HTML and stuff like Flash or Java applets. Best, cp On Feb 19, 10:50?pm, frankrentef wrote: > Greetings all... > > Newbie here to the Python world. ?I've written some basic script with > the purpose of automating testing of an application via Python / > Pamie. ?I've had pretty good success until a spot I'm testing displays > a Java pop up. ?I need to have Pamie access the fields in the window > (i.e. add a value and activate the "enter" button.) ?Can someone > assist. > > Some of the code I have currently is as follows...when the script I've > written gets to the end the java window pops up automatically....I > don't understand how to interface with it. > > THNX > > ie.textBoxSet('_ctl0_ContentPlaceHolder1_Bocarc1_txtMAX', '5000.00') > time.sleep(2) > ie.textBoxSet('_ctl0_ContentPlaceHolder1_Bocarc1_txtMIN', '0') > time.sleep(2) > ie.buttonClick('_ctl0_ContentPlaceHolder1_Bocarc1_ckCheckMicr') > time.sleep(2) > ie.buttonClick('_ctl0_ContentPlaceHolder1_Bocarc1_ckCheckMicr') > ie.timesleep(2) > ie.textBoxSet('_ctl0_ContentPlaceHolder1_Bocarc1_txtMaxMicrRejects', > '1') > time.sleep(2) > ie.buttonClick('_ctl0_ContentPlaceHolder1_arc1_btnUpdate') > time.sleep2 From catherine.heathcote at gmail.com Fri Feb 20 09:43:50 2009 From: catherine.heathcote at gmail.com (Catherine Heathcote) Date: Fri, 20 Feb 2009 14:43:50 GMT Subject: Keeping the Console Open with IDLE In-Reply-To: References: <54c56179-6f92-41e9-bad7-afa8b28d0671@l38g2000vba.googlegroups.com> Message-ID: W. eWatson wrote: > Catherine Heathcote wrote: >> W. eWatson wrote: >>> >>>> >>>> I'm not sure whether I should feel old or write a smart alec comment -- >>>> I suppose there are people in the world who don't know what to do >>>> with a >>>> command prompt.... >>>> >>>> Assuming a Windows system: >>>> >>>> 2. Type 'cd ' (as in Change Directory) in the command prompt window >>>> (w/o >>>> the single quote characters) >>>> 3. Drag/drop the folder containing your python script to your command >>>> prompt window >>>> 4. Hit enter in your command prompt window. >>>> 5. Type python my_script_name.py to execute my_script_name.py. >>>> >>>> --David >>> If I enter just cd, then it tells me cd is not defined. If I enter >>> c:/python25, it tells me I have a syntax error at c in c:. The title >>> of the black background window I have up with a >>> prompt shown in >>> it is "Python(command line)". Maybe this isn't the real Python >>> console window? >>> >>> What I want is that if I execute the program by double clicking on >>> its name to display the console window with the program or syntax >>> errors shown without it closing in a split second. Putting read_raw >>> in it doesn't work, since some error prevents it from ever being seen. >>> >> >> you need to open a dos prompt before doing the steps above. Go to >> start->run and hit "cmd" without the quotes. > Something is amiss here. There's the MS Command Prompt, which I'm > looking at right now. Yes, it has cd, and so on. I'm also looking at the > Python command line window. It allow one to run interactively. > > If I write a simple python program with just raw_input, by clicking on > the file name, I get a window with the the title "\Python25\pythonexe" > that shows the prompt. If I deliberately put a syntax error in the > program, and run it by clicking the file, then A window appears and > disappears so quickly that I have no idea what it said. How do I keep > that window up? > > Which, if any, of these is the real Python console? What is the window > called in the example I gave with raw_input? > Run the program from within the MS command line, not by double clicking it. From vriolk at gmail.com Fri Feb 20 09:45:23 2009 From: vriolk at gmail.com (coldpizza) Date: Fri, 20 Feb 2009 06:45:23 -0800 (PST) Subject: FTP libs for Python? References: <031c6600-b8fb-49d6-bf24-aa12ff494376@p20g2000yqi.googlegroups.com> Message-ID: Why don't you just use Curl? It does a dozen of protocols including SFTP. And if the command line version is not enough for you then there are Python bindings for Curl. On Feb 20, 4:22?pm, Thomas Allen wrote: > I'm interested in writing a script to ease deployment of minor changes > on some websites here, and it would involve some SFTP transfers. Do > you know of good alternatives to ftplib, which is relatively low- > level? > > Thomas From mensanator at aol.com Fri Feb 20 09:47:12 2009 From: mensanator at aol.com (Mensanator) Date: Fri, 20 Feb 2009 06:47:12 -0800 (PST) Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <28e3612d-2e91-4a91-82cb-5fb2deda95fd@q9g2000yqc.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> <7x8wo2kwoz.fsf@ruckus.brouhaha.com> <52a0375d-4fad-4caa-8328-47b8f30f2395@40g2000prx.googlegroups.com> Message-ID: On Feb 20, 4:36?am, sturlamolden wrote: > On Feb 20, 12:19 am, Mensanator wrote: > > > What am I actually seeing? If Python only uses one of the cores, > > why do both light up? > > Because of OS scheduling. You have more than one process running. The > Python process does not stay on one core. Try to put CPython into a > tight loop ("while 1: pass"). You will see ~50% use of both cores. If > you had 4 cores, you would see ~25% use. Saw that once when I had access to a four core machine. > > > Is everything much more complicated (due to > > OS scheduling, etc.) than the simple explanations of GIL? > > No. Don't you mean "yes"? > Your Python code cannot use more than one core simultaneously. > It's just that scheduling happens so fast and so often that you don't > notice it. Or that the Task Manager can't track the switches fast enough to show the interleaving giving the illusion that both cores are operating simultaneously. From bsk16 at case.edu Fri Feb 20 09:47:17 2009 From: bsk16 at case.edu (Ben Kaplan) Date: Fri, 20 Feb 2009 09:47:17 -0500 Subject: Framework installation of 2.6 on OS X, with specified prefix In-Reply-To: References: Message-ID: <927B41A1-E800-4D8C-B9C5-480531B8DA68@case.edu> On Feb 20, 2009, at 9:30 AM, Evert Rol wrote: > Hi, > > I'm trying to install Python 2.6 from source on Mac OS X.5, in its > own directory using a framework install. That goes fine, up to the > point where it wants to install the applications that come with it > (eg, the Wish shell): it tries to install things into /Applications, > instead of eg /Applications. > Here's my configure line (the flags are there just to let it find my > own installed readline): > > CPPFLAGS=-I/sw/include LDFLAGS=-L/sw/lib ./configure --prefix=/sw -- > enable-shared --enable-framework=/sw/Library/Frameworks --with- > readline=/sw --with-pth CC=gcc-4.2 MACOSX_DEPLOYMENT_TARGET=10.5 > > > And the last part of the output of 'make install': > > ../python.exe ./scripts/BuildApplet.py \ > --destroot "" \ > --python=/sw/Library/Frameworks/Python.framework/Versions/2.6/ > Resources/Python.app/Contents/MacOS/Python`test -f "/sw/Library/ > Frameworks/Python.framework/Versions/2.6/Resources/Python.app/ > Contents/MacOS/Python-32" && echo "-32"` \ > --output "/sw/Applications/Python 2.6/Build Applet.app" \ > ./scripts/BuildApplet.py > cd PythonLauncher && make install DESTDIR= > test -d "/Applications/Python 2.6" || mkdir -p "/Applications/Python > 2.6" > mkdir: /Applications/Python 2.6: Permission denied > make[2]: *** [install] Error 1 > make[1]: *** [install_PythonLauncher] Error 2 > make: *** [frameworkinstallapps] Error 2 > > > Is there an option on the configure line that I need to set, or > something in setup.py? Or perhaps hack the Makefile? > > Evert > It's a security thing- only root can write to directories like / Applications. You need to run " sudo make install". You'll be promoted for your password and then it will install. > -- > http://mail.python.org/mailman/listinfo/python-list From mrmakent at cox.net Fri Feb 20 09:48:07 2009 From: mrmakent at cox.net (Mike Kent) Date: Fri, 20 Feb 2009 06:48:07 -0800 (PST) Subject: FTP libs for Python? References: <031c6600-b8fb-49d6-bf24-aa12ff494376@p20g2000yqi.googlegroups.com> Message-ID: I use Fabric (http://www.nongnu.org/fab/) as my Python-based deployment tool, but it uses ssh/scp, not sftp. From exarkun at divmod.com Fri Feb 20 10:02:39 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Fri, 20 Feb 2009 10:02:39 -0500 Subject: FTP libs for Python? In-Reply-To: <031c6600-b8fb-49d6-bf24-aa12ff494376@p20g2000yqi.googlegroups.com> Message-ID: <20090220150239.12853.960662794.divmod.quotient.12154@henry.divmod.com> On Fri, 20 Feb 2009 06:22:29 -0800 (PST), Thomas Allen wrote: >I'm interested in writing a script to ease deployment of minor changes >on some websites here, and it would involve some SFTP transfers. Do >you know of good alternatives to ftplib, which is relatively low- >level? Twisted includes FTP and SFTP support. Jean-Paul From gagsl-py2 at yahoo.com.ar Fri Feb 20 10:03:41 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 20 Feb 2009 13:03:41 -0200 Subject: Keeping the Console Open with IDLE References: <54c56179-6f92-41e9-bad7-afa8b28d0671@l38g2000vba.googlegroups.com> <81znl.13277$D32.3772@flpi146.ffdc.sbc.com> Message-ID: En Fri, 20 Feb 2009 12:29:35 -0200, W. eWatson escribi?: > Gabriel Genellina wrote: >> En Fri, 20 Feb 2009 12:05:08 -0200, W. eWatson >> escribi?: >> >>> Whoa! What's going on here? I just looked at About IDLE, and it shows >>> 1.2.2, but yet the second edition of Learning Python talks about going >>> to 2.3 as the book is about to go to press, 2004. I thought IDLE came >>> bundled with Python. I have Py 2.5. 1.2.2??? Puzzled. >> IDLE is a separate product; the version of IDLE that comes with Python >> 2.5.4 is 1.2.4 >> > Where do I get 2.x.x, or the latest? You may update your Python version to 2.5.4 (the latest release in the 2.5 series). Then IDLE will report 1.2.4. They are separate products, their version numbers are uncorrelated. -- Gabriel Genellina From kom2 at centrum.cz Fri Feb 20 10:10:13 2009 From: kom2 at centrum.cz (Kom2) Date: Fri, 20 Feb 2009 07:10:13 -0800 (PST) Subject: Running script in module initialization Message-ID: <56d0c8e4-c7cd-4b3b-aef0-7dc92996efb3@m15g2000vbp.googlegroups.com> Hello, I'm trying to convert my project from python 2.5 to python 3.0 and I have the following problem. My project is PYD library written in C++. So I have this PyInit_ModuleName function containing PyModule_Create call and this function also call some script with declarations: PyObject* m; m = PyModule_Create(&PyVRDAModule); if (m == NULL) { return NULL; } PyObject *d, *v; d = PyModule_GetDict(m); v = PyRun_StringFlags(txtPyPredefinedConstants), Py_file_input, d, d, NULL); ...... txtPyPredefinedConstants is string with this content: class CursorMoveType: First = 0 Last = 1 Next = 2 Previous = 3 Bookmark = 4 NewRecord = 5 In Python 2.5 everything works fine, now in python3.0 PyRun_StringFlags returns NULL and I get error "__build_class__ not found". Can anybody tell mi please, what is wrong? thanks Kom2 From patrick.oloughlin at gmail.com Fri Feb 20 10:16:13 2009 From: patrick.oloughlin at gmail.com (Paddy O'Loughlin) Date: Fri, 20 Feb 2009 15:16:13 +0000 Subject: How do I declare global vars or class vars in Python ? In-Reply-To: <499eaa34$0$21372$426a74cc@news.free.fr> References: <499eaa34$0$21372$426a74cc@news.free.fr> Message-ID: 2009/2/20 Bruno Desthuilliers : > Note that while you *can* do direct access to the implementation attribute > (here, '_A' for property 'A'), you don't *need* to so (and usually shouldn't > - unless you have a very compelling reason). Interesting. Why shouldn't you? I haven't used the property() function before and probably have no call to, but when you say "usually shouldn't", what is there against it? -- "Ray, when someone asks you if you're a god, you say YES!" From thomasmallen at gmail.com Fri Feb 20 10:24:37 2009 From: thomasmallen at gmail.com (Thomas Allen) Date: Fri, 20 Feb 2009 07:24:37 -0800 (PST) Subject: FTP libs for Python? References: <031c6600-b8fb-49d6-bf24-aa12ff494376@p20g2000yqi.googlegroups.com> Message-ID: <19a392ba-1ecd-4e92-8636-c684281ed93f@x10g2000yqk.googlegroups.com> On Feb 20, 9:45 am, coldpizza wrote: > Why don't you just use Curl? It does a dozen of protocols including > SFTP. And if the command line version is not enough for you then there > are Python bindings for Curl. I'm actually hoping to eventually package these tools using py2exe for some co-workers, which is why I'm not looking to Unix utilities On Feb 20, 9:48?am, Mike Kent wrote: > I use Fabric (http://www.nongnu.org/fab/) as my Python-based > deployment tool, but it uses ssh/scp, not sftp. I'm looking at Paramiko right now which I saw some people recommending, as SSH utils are required as well.... Thomas From vincent at vincentdavis.net Fri Feb 20 10:25:51 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Fri, 20 Feb 2009 08:25:51 -0700 Subject: code challenge: generate minimal expressions using only digits 1,2,3 In-Reply-To: <941be713-2789-48c7-911b-422313f232d5@o36g2000yqh.googlegroups.com> References: <941be713-2789-48c7-911b-422313f232d5@o36g2000yqh.googlegroups.com> Message-ID: <77e831100902200725s505be71exa4726f72ac849a9f@mail.gmail.com> Having looked long at this how does the prime factorization play into this. I would consider an approach similar to factoring a number. Of course the issue with prime factoring is your ned to know the primes. I assume this would be a similar problem you may need to know the solutions to the factors. I might look closer at this please post if you come across a solution. Thanks Vincent Davis 720-301-3003 On Fri, Feb 20, 2009 at 7:31 AM, Trip Technician wrote: > anyone interested in looking at the following problem. > > we are trying to express numbers as minimal expressions using only the > digits one two and three, with conventional arithmetic. so for > instance > > 33 = 2^(3+2)+1 = 3^3+(3*2) > > are both minimal, using 4 digits but > > 33 = ((3+2)*2+1)*3 > > using 5 is not. > > I have tried coding a function to return the minimal representation > for any integer, but haven't cracked it so far. The naive first > attempt is to generate lots of random strings, eval() them and sort by > size and value. this is inelegant and slow. > > I have a dim intuition that it could be done with a very clever bit of > recursion, but the exact form so far eludes me. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Fri Feb 20 10:26:09 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 20 Feb 2009 13:26:09 -0200 Subject: Keeping the Console Open with IDLE References: <54c56179-6f92-41e9-bad7-afa8b28d0671@l38g2000vba.googlegroups.com> Message-ID: En Fri, 20 Feb 2009 12:39:14 -0200, W. eWatson escribi?: > Catherine Heathcote wrote: >> you need to open a dos prompt before doing the steps above. Go to >> start->run and hit "cmd" without the quotes. > Something is amiss here. There's the MS Command Prompt, which I'm > looking at right now. Yes, it has cd, and so on. I'm also looking at the > Python command line window. It allow one to run interactively. Open a command prompt ("CMD", "Console"), that black window you were looking at. Use the cd command to change directory to wherever your Python script is saved. Execute "python -V" (without the quotes). You should get a response, including the Python version number. If you get an error like "command not found" or similar, you'll have to use the whole path to python.exe -- try with "c:\python25\python -V" (again, no quotes). Once you know how to launch Python, you can: a) Enter the interactive interpreter: Just launch Python as above but without the -V argument. The prompt is now >>> You can type Python expressions and the interpreter evaluates them. You type 2+3, the interpreter answers 5; you type len("abc"), the interpreter answers 3... b) Or, from the command prompt, you can execute a script by launching Python the same way as above, passing the script name as an argument: c:\foo>python script_name.py This is what you were looking for - in case of syntax errors or something, you can see the output on the console. It stays open because it was open *before* you launched Python. Just keep the window open. See http://docs.python.org/using/windows.html for more info. If Python doesn't start just by typing "python", you may want to set your PATH environment variable as described there. -- Gabriel Genellina From steve at holdenweb.com Fri Feb 20 10:27:43 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 20 Feb 2009 10:27:43 -0500 Subject: Running script in module initialization In-Reply-To: <56d0c8e4-c7cd-4b3b-aef0-7dc92996efb3@m15g2000vbp.googlegroups.com> References: <56d0c8e4-c7cd-4b3b-aef0-7dc92996efb3@m15g2000vbp.googlegroups.com> Message-ID: Kom2 wrote: > Hello, > I'm trying to convert my project from python 2.5 to python 3.0 and I > have the following problem. My project is PYD library written in C++. > So I have this PyInit_ModuleName function containing PyModule_Create > call and this function also call some script with declarations: > > > PyObject* m; > > m = PyModule_Create(&PyVRDAModule); > if (m == NULL) { > return NULL; > } > PyObject *d, *v; > d = PyModule_GetDict(m); > v = PyRun_StringFlags(txtPyPredefinedConstants), Py_file_input, d, > d, NULL); > ...... > > > > txtPyPredefinedConstants is string with this content: > > class CursorMoveType: > First = 0 > Last = 1 > Next = 2 > Previous = 3 > Bookmark = 4 > NewRecord = 5 > > > In Python 2.5 everything works fine, now in python3.0 > PyRun_StringFlags returns NULL and I get error "__build_class__ not > found". > > Can anybody tell mi please, what is wrong? > Presumably you haven't upgraded your extension module to use the new API? http://wiki.python.org/moin/PortingExtensionModulesToPy3k regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From notvalid2 at sbcglobal.net Fri Feb 20 10:37:06 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Fri, 20 Feb 2009 07:37:06 -0800 Subject: Keeping the Console Open with IDLE In-Reply-To: References: <54c56179-6f92-41e9-bad7-afa8b28d0671@l38g2000vba.googlegroups.com> Message-ID: Catherine Heathcote wrote: > W. eWatson wrote: >> Catherine Heathcote wrote: >>> W. eWatson wrote: >>>> >>>>> >>>>> I'm not sure whether I should feel old or write a smart alec >>>>> comment -- >>>>> I suppose there are people in the world who don't know what to do >>>>> with a >>>>> command prompt.... >>>>> >>>>> Assuming a Windows system: >>>>> >>>>> 2. Type 'cd ' (as in Change Directory) in the command prompt window >>>>> (w/o >>>>> the single quote characters) >>>>> 3. Drag/drop the folder containing your python script to your command >>>>> prompt window >>>>> 4. Hit enter in your command prompt window. >>>>> 5. Type python my_script_name.py to execute my_script_name.py. >>>>> >>>>> --David >>>> If I enter just cd, then it tells me cd is not defined. If I enter >>>> c:/python25, it tells me I have a syntax error at c in c:. The title >>>> of the black background window I have up with a >>> prompt shown in >>>> it is "Python(command line)". Maybe this isn't the real Python >>>> console window? >>>> >>>> What I want is that if I execute the program by double clicking on >>>> its name to display the console window with the program or syntax >>>> errors shown without it closing in a split second. Putting read_raw >>>> in it doesn't work, since some error prevents it from ever being seen. >>>> >>> >>> you need to open a dos prompt before doing the steps above. Go to >>> start->run and hit "cmd" without the quotes. >> Something is amiss here. There's the MS Command Prompt, which I'm >> looking at right now. Yes, it has cd, and so on. I'm also looking at >> the Python command line window. It allow one to run interactively. >> >> If I write a simple python program with just raw_input, by clicking on >> the file name, I get a window with the the title "\Python25\pythonexe" >> that shows the prompt. If I deliberately put a syntax error in the >> program, and run it by clicking the file, then A window appears and >> disappears so quickly that I have no idea what it said. How do I keep >> that window up? >> >> Which, if any, of these is the real Python console? What is the window >> called in the example I gave with raw_input? >> > > Run the program from within the MS command line, not by double clicking it. Shirley, you jest? DOS? To do this? How ugly. I barely recall the DOS commands. I get to drill my way down 4 levels of folders. What DOS cmd allows one to list only folders? Still, why would one design a window that disappears, when it has useful data in it? I see that if I click on the window, it has properties, width, height, etc. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From gagsl-py2 at yahoo.com.ar Fri Feb 20 10:38:41 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 20 Feb 2009 13:38:41 -0200 Subject: FTP libs for Python? References: <031c6600-b8fb-49d6-bf24-aa12ff494376@p20g2000yqi.googlegroups.com> <19a392ba-1ecd-4e92-8636-c684281ed93f@x10g2000yqk.googlegroups.com> Message-ID: En Fri, 20 Feb 2009 13:24:37 -0200, Thomas Allen escribi?: > On Feb 20, 9:45 am, coldpizza wrote: >> Why don't you just use Curl? It does a dozen of protocols including >> SFTP. And if the command line version is not enough for you then there >> are Python bindings for Curl. > > I'm actually hoping to eventually package these tools using py2exe for > some co-workers, which is why I'm not looking to Unix utilities curl works on Windows too. -- Gabriel Genellina From wiggly at wiggly.org Fri Feb 20 10:39:22 2009 From: wiggly at wiggly.org (Nigel Rantor) Date: Fri, 20 Feb 2009 15:39:22 +0000 Subject: code challenge: generate minimal expressions using only digits 1,2,3 In-Reply-To: <941be713-2789-48c7-911b-422313f232d5@o36g2000yqh.googlegroups.com> References: <941be713-2789-48c7-911b-422313f232d5@o36g2000yqh.googlegroups.com> Message-ID: <499ECEAA.30103@wiggly.org> Trip Technician wrote: > anyone interested in looking at the following problem. if you can give me a good reason why this is not homework I'd love to hear it...I just don't see how this is a real problem. > we are trying to express numbers as minimal expressions using only the > digits one two and three, with conventional arithmetic. so for > instance > > 33 = 2^(3+2)+1 = 3^3+(3*2) > > are both minimal, using 4 digits but > > 33 = ((3+2)*2+1)*3 > > using 5 is not. > > I have tried coding a function to return the minimal representation > for any integer, but haven't cracked it so far. The naive first > attempt is to generate lots of random strings, eval() them and sort by > size and value. this is inelegant and slow. Wow. Okay, what other ways have you tried so far? Or are you beating your head against the "search the entire problem space" solution still? This problem smells a lot like factorisation, so I would think of it in terms of wanting to reduce the target number using as few operations as possible. If you allow exponentiation that's going to be your biggest hitter so you know that the best you can do using 2 digits is n^n where n is the largest digit you allow yourself. Are you going to allow things like n^n^n or not? n From notvalid2 at sbcglobal.net Fri Feb 20 10:39:30 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Fri, 20 Feb 2009 07:39:30 -0800 Subject: Keeping the Console Open with IDLE In-Reply-To: References: <54c56179-6f92-41e9-bad7-afa8b28d0671@l38g2000vba.googlegroups.com> <81znl.13277$D32.3772@flpi146.ffdc.sbc.com> Message-ID: <18Anl.14217$as4.4271@nlpi069.nbdc.sbc.com> Gabriel Genellina wrote: > En Fri, 20 Feb 2009 12:29:35 -0200, W. eWatson > escribi?: > >> Gabriel Genellina wrote: >>> En Fri, 20 Feb 2009 12:05:08 -0200, W. eWatson >>> escribi?: >>> >>>> Whoa! What's going on here? I just looked at About IDLE, and it >>>> shows 1.2.2, but yet the second edition of Learning Python talks >>>> about going to 2.3 as the book is about to go to press, 2004. I >>>> thought IDLE came bundled with Python. I have Py 2.5. 1.2.2??? Puzzled. >>> IDLE is a separate product; the version of IDLE that comes with >>> Python 2.5.4 is 1.2.4 >>> >> Where do I get 2.x.x, or the latest? > > You may update your Python version to 2.5.4 (the latest release in the > 2.5 series). Then IDLE will report 1.2.4. They are separate products, > their version numbers are uncorrelated. > Ah, I see, the book is referring to version 2.3 of Python and not IDLE. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From dns4 at cornell.edu Fri Feb 20 10:41:42 2009 From: dns4 at cornell.edu (David Smith) Date: Fri, 20 Feb 2009 10:41:42 -0500 Subject: Keeping the Console Open with IDLE In-Reply-To: References: <54c56179-6f92-41e9-bad7-afa8b28d0671@l38g2000vba.googlegroups.com> Message-ID: W. eWatson wrote: > >> >> I'm not sure whether I should feel old or write a smart alec comment -- >> I suppose there are people in the world who don't know what to do with a >> command prompt.... >> >> Assuming a Windows system: >> >> 2. Type 'cd ' (as in Change Directory) in the command prompt window (w/o >> the single quote characters) >> 3. Drag/drop the folder containing your python script to your command >> prompt window >> 4. Hit enter in your command prompt window. >> 5. Type python my_script_name.py to execute my_script_name.py. >> >> --David > If I enter just cd, then it tells me cd is not defined. If I enter > c:/python25, it tells me I have a syntax error at c in c:. The title of > the black background window I have up with a >>> prompt shown in it is > "Python(command line)". Maybe this isn't the real Python console window? > > What I want is that if I execute the program by double clicking on its > name to display the console window with the program or syntax errors > shown without it closing in a split second. Putting read_raw in it > doesn't work, since some error prevents it from ever being seen. > What I meant was open open the command prompt, type cd, space, DO NOT hit enter yet. Drag the folder with your script into the command prompt window. Then go to the command prompt window and hit enter. This should compose a command similar to the following: C:\Documents and Settings\user> cd "C:\Documents and Settings\user\My Documents\My Project" C:\Documents and Settings\user\My Documents\My Project> _ --David From catherine.heathcote at gmail.com Fri Feb 20 10:45:56 2009 From: catherine.heathcote at gmail.com (Catherine Heathcote) Date: Fri, 20 Feb 2009 15:45:56 GMT Subject: Keeping the Console Open with IDLE In-Reply-To: References: <54c56179-6f92-41e9-bad7-afa8b28d0671@l38g2000vba.googlegroups.com> Message-ID: W. eWatson wrote: > Catherine Heathcote wrote: >> W. eWatson wrote: >>> Catherine Heathcote wrote: >>>> W. eWatson wrote: >>>>> >>>>>> >>>>>> I'm not sure whether I should feel old or write a smart alec >>>>>> comment -- >>>>>> I suppose there are people in the world who don't know what to do >>>>>> with a >>>>>> command prompt.... >>>>>> >>>>>> Assuming a Windows system: >>>>>> >>>>>> 2. Type 'cd ' (as in Change Directory) in the command prompt >>>>>> window (w/o >>>>>> the single quote characters) >>>>>> 3. Drag/drop the folder containing your python script to your command >>>>>> prompt window >>>>>> 4. Hit enter in your command prompt window. >>>>>> 5. Type python my_script_name.py to execute my_script_name.py. >>>>>> >>>>>> --David >>>>> If I enter just cd, then it tells me cd is not defined. If I enter >>>>> c:/python25, it tells me I have a syntax error at c in c:. The >>>>> title of the black background window I have up with a >>> prompt >>>>> shown in it is "Python(command line)". Maybe this isn't the real >>>>> Python console window? >>>>> >>>>> What I want is that if I execute the program by double clicking on >>>>> its name to display the console window with the program or syntax >>>>> errors shown without it closing in a split second. Putting read_raw >>>>> in it doesn't work, since some error prevents it from ever being seen. >>>>> >>>> >>>> you need to open a dos prompt before doing the steps above. Go to >>>> start->run and hit "cmd" without the quotes. >>> Something is amiss here. There's the MS Command Prompt, which I'm >>> looking at right now. Yes, it has cd, and so on. I'm also looking at >>> the Python command line window. It allow one to run interactively. >>> >>> If I write a simple python program with just raw_input, by clicking >>> on the file name, I get a window with the the title >>> "\Python25\pythonexe" that shows the prompt. If I deliberately put a >>> syntax error in the program, and run it by clicking the file, then A >>> window appears and disappears so quickly that I have no idea what it >>> said. How do I keep that window up? >>> >>> Which, if any, of these is the real Python console? What is the >>> window called in the example I gave with raw_input? >>> >> >> Run the program from within the MS command line, not by double >> clicking it. > Shirley, you jest? DOS? To do this? How ugly. I barely recall the DOS > commands. I get to drill my way down 4 levels of folders. What DOS cmd > allows one to list only folders? > > Still, why would one design a window that disappears, when it has useful > data in it? I see that if I click on the window, it has properties, > width, height, etc. > Thats programming. Whaterver the language, you will need to be comfortable with the CLI of your operating system. From luke.dunn at gmail.com Fri Feb 20 10:52:10 2009 From: luke.dunn at gmail.com (Luke Dunn) Date: Fri, 20 Feb 2009 15:52:10 +0000 Subject: code challenge: generate minimal expressions using only digits 1,2,3 In-Reply-To: <499ECEAA.30103@wiggly.org> References: <941be713-2789-48c7-911b-422313f232d5@o36g2000yqh.googlegroups.com> <499ECEAA.30103@wiggly.org> Message-ID: I am teaching myself coding. No university or school, so i guess its homework if you like. i am interested in algorithms generally, after doing some of Project Euler. Of course my own learning process is best served by just getting on with it but sometimes you will do that while other times you might just choose to ask for help. if no one suggests then i will probably shelve it and come back to it myself when I'm fresh. no it's not a real world problem but my grounding is in math so i like pure stuff anyway. don't see how that is a problem, as a math person i accept the validity of pure research conducted just for curiosity and aesthetic satisfaction. it often finds an application later anyway Thanks for your helpful suggestion of trying other methods and i will do that in time. my motive was to share an interesting problem because a human of moderate math education can sit down with this and find minimal solutions easily but the intuition they use is quite subtle, hence the idea of converting the human heuristic into an algorithm became of interest, and particularly a recursive one. i find that the development of a piece of recursion usually comes as an 'aha', and since i hadn't had such a moment, i thought i'd turn the problem loose on the public. also i found no online reference to this problem so it seemed ripe for sharing. On Fri, Feb 20, 2009 at 3:39 PM, Nigel Rantor wrote: > Trip Technician wrote: > >> anyone interested in looking at the following problem. >> > > if you can give me a good reason why this is not homework I'd love to hear > it...I just don't see how this is a real problem. > > we are trying to express numbers as minimal expressions using only the >> digits one two and three, with conventional arithmetic. so for >> instance >> >> 33 = 2^(3+2)+1 = 3^3+(3*2) >> >> are both minimal, using 4 digits but >> >> 33 = ((3+2)*2+1)*3 >> >> using 5 is not. >> >> I have tried coding a function to return the minimal representation >> for any integer, but haven't cracked it so far. The naive first >> attempt is to generate lots of random strings, eval() them and sort by >> size and value. this is inelegant and slow. >> > > Wow. Okay, what other ways have you tried so far? Or are you beating your > head against the "search the entire problem space" solution still? > > This problem smells a lot like factorisation, so I would think of it in > terms of wanting to reduce the target number using as few operations as > possible. > > If you allow exponentiation that's going to be your biggest hitter so you > know that the best you can do using 2 digits is n^n where n is the largest > digit you allow yourself. > > Are you going to allow things like n^n^n or not? > > n > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From notvalid2 at sbcglobal.net Fri Feb 20 10:55:46 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Fri, 20 Feb 2009 07:55:46 -0800 Subject: Keeping the Console Open with IDLE In-Reply-To: References: <54c56179-6f92-41e9-bad7-afa8b28d0671@l38g2000vba.googlegroups.com> Message-ID: David Smith wrote: > W. eWatson wrote: >>> I'm not sure whether I should feel old or write a smart alec comment -- >>> I suppose there are people in the world who don't know what to do with a >>> command prompt.... >>> >>> Assuming a Windows system: >>> >>> 2. Type 'cd ' (as in Change Directory) in the command prompt window (w/o >>> the single quote characters) >>> 3. Drag/drop the folder containing your python script to your command >>> prompt window >>> 4. Hit enter in your command prompt window. >>> 5. Type python my_script_name.py to execute my_script_name.py. >>> >>> --David >> If I enter just cd, then it tells me cd is not defined. If I enter >> c:/python25, it tells me I have a syntax error at c in c:. The title of >> the black background window I have up with a >>> prompt shown in it is >> "Python(command line)". Maybe this isn't the real Python console window? >> >> What I want is that if I execute the program by double clicking on its >> name to display the console window with the program or syntax errors >> shown without it closing in a split second. Putting read_raw in it >> doesn't work, since some error prevents it from ever being seen. >> > > What I meant was open open the command prompt, type cd, space, DO NOT > hit enter yet. Drag the folder with your script into the command prompt > window. Then go to the command prompt window and hit enter. This > should compose a command similar to the following: > > C:\Documents and Settings\user> cd "C:\Documents and Settings\user\My > Documents\My Project" > > C:\Documents and Settings\user\My Documents\My Project> _ > > --David Ah, I thought I'd be clever and do a copy on the path name in the address area at the top of the folder. That doesn't work. I'm quite surprised though that one can do the drag as you say. But, hey, it works. Thanks. I wonder what else non-DOS things can be done in it? -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From robert.kern at gmail.com Fri Feb 20 10:59:16 2009 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 20 Feb 2009 09:59:16 -0600 Subject: Matplotlib change xticks and retain xticks changing during zoom In-Reply-To: References: Message-ID: You will probably get better help on the matplotlib mailing list: https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From robert.kern at gmail.com Fri Feb 20 10:59:52 2009 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 20 Feb 2009 09:59:52 -0600 Subject: matplotlib issue: cannot auto-scale X axis of plop properly In-Reply-To: References: Message-ID: On 2009-02-19 19:22, Nash, Brent R wrote: > Hey everyone, > > I'm fairly new to matplotlib, but have read through tons of the > documentation today and have a decent understanding of it. All the > auto-scaling, xlim, and x_bound stuff works fine for me with the > examples, but as soon as I try to use it on my data, it's not working > for me. I've attached a demo script, 2 input files of data, and a PNG > showing the resulting chart I get. The numbers on my Y-axis range from > 7656 to 59928 (a difference of 52272) and the numbers on my X-axis range > from 1.22896144017e+12 to 1.22896155012e+12 (a difference of 109950). You will probably get better help on the matplotlib mailing list: https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From luke.dunn at gmail.com Fri Feb 20 11:01:25 2009 From: luke.dunn at gmail.com (Luke Dunn) Date: Fri, 20 Feb 2009 16:01:25 +0000 Subject: code challenge: generate minimal expressions using only digits 1,2,3 In-Reply-To: References: <941be713-2789-48c7-911b-422313f232d5@o36g2000yqh.googlegroups.com> <499ECEAA.30103@wiggly.org> Message-ID: yes power towers are allowed exponentiation, multiplication, division, addition and subtraction. Brackets when necessary but length is sorted on number of digits not number of operators plus digits. I always try my homework myself first. in 38 years of life I've learned only to do what i want, if I wanted everyone else to do my work for me I'd be a management consultant ! On Fri, Feb 20, 2009 at 3:52 PM, Luke Dunn wrote: > I am teaching myself coding. No university or school, so i guess its > homework if you like. i am interested in algorithms generally, after doing > some of Project Euler. Of course my own learning process is best served by > just getting on with it but sometimes you will do that while other times you > might just choose to ask for help. if no one suggests then i will probably > shelve it and come back to it myself when I'm fresh. > > no it's not a real world problem but my grounding is in math so i like pure > stuff anyway. don't see how that is a problem, as a math person i accept the > validity of pure research conducted just for curiosity and aesthetic > satisfaction. it often finds an application later anyway > > Thanks for your helpful suggestion of trying other methods and i will do > that in time. my motive was to share an interesting problem because a human > of moderate math education can sit down with this and find minimal solutions > easily but the intuition they use is quite subtle, hence the idea of > converting the human heuristic into an algorithm became of interest, and > particularly a recursive one. i find that the development of a piece of > recursion usually comes as an 'aha', and since i hadn't had such a moment, i > thought i'd turn the problem loose on the public. also i found no online > reference to this problem so it seemed ripe for sharing. > > On Fri, Feb 20, 2009 at 3:39 PM, Nigel Rantor wrote: > >> Trip Technician wrote: >> >>> anyone interested in looking at the following problem. >>> >> >> if you can give me a good reason why this is not homework I'd love to hear >> it...I just don't see how this is a real problem. >> >> we are trying to express numbers as minimal expressions using only the >>> digits one two and three, with conventional arithmetic. so for >>> instance >>> >>> 33 = 2^(3+2)+1 = 3^3+(3*2) >>> >>> are both minimal, using 4 digits but >>> >>> 33 = ((3+2)*2+1)*3 >>> >>> using 5 is not. >>> >>> I have tried coding a function to return the minimal representation >>> for any integer, but haven't cracked it so far. The naive first >>> attempt is to generate lots of random strings, eval() them and sort by >>> size and value. this is inelegant and slow. >>> >> >> Wow. Okay, what other ways have you tried so far? Or are you beating your >> head against the "search the entire problem space" solution still? >> >> This problem smells a lot like factorisation, so I would think of it in >> terms of wanting to reduce the target number using as few operations as >> possible. >> >> If you allow exponentiation that's going to be your biggest hitter so you >> know that the best you can do using 2 digits is n^n where n is the largest >> digit you allow yourself. >> >> Are you going to allow things like n^n^n or not? >> >> n >> >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From http Fri Feb 20 11:02:45 2009 From: http (Paul Rubin) Date: 20 Feb 2009 08:02:45 -0800 Subject: code challenge: generate minimal expressions using only digits 1, 2, 3 References: <941be713-2789-48c7-911b-422313f232d5@o36g2000yqh.googlegroups.com> Message-ID: <7xljs1xfiy.fsf@ruckus.brouhaha.com> Trip Technician writes: > I have a dim intuition that it could be done with a very clever bit of > recursion, but the exact form so far eludes me. This sounds a little like a homework assignment, or maybe a challenge you are trying to solve for yourself, rather than be given a complete answer for. Anyway, the basic idea is to enumerate the expression trees with 1 digit, then 2 digits, then 3 digits, etc, and compute the value expressed by each tree. From bruno.42.desthuilliers at websiteburo.invalid Fri Feb 20 11:03:04 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 20 Feb 2009 17:03:04 +0100 Subject: How do I declare global vars or class vars in Python ? In-Reply-To: References: <499eaa34$0$21372$426a74cc@news.free.fr> Message-ID: <499ed41c$0$15309$426a74cc@news.free.fr> Paddy O'Loughlin a ?crit : > 2009/2/20 Bruno Desthuilliers : >> Note that while you *can* do direct access to the implementation attribute >> (here, '_A' for property 'A'), you don't *need* to so (and usually shouldn't >> - unless you have a very compelling reason). > > Interesting. Why shouldn't you? > I haven't used the property() function s/function/object/ > before and probably have no > call to, but when you say "usually shouldn't", what is there against > it? The case is that the whole point of using a computed attribute is to perform some computation on the value. IOW, except for a couple corner cases, only the accessors should directly access the implementation(s) attributes(s). And of course, like for any other GoldenRule(tm), it's not meant to be blindly followed. It's just that most of the times, going thru the accessors is really what you want - even from within the class code. From cdsd at d.com Fri Feb 20 11:12:00 2009 From: cdsd at d.com (ssd) Date: Fri, 20 Feb 2009 17:12:00 +0100 Subject: Problem with lists. Message-ID: Hi, In the following code, (in Python 2.5) I was expecting to get in "b" variable the values b: [[0, 0], [0, 1],[0, 2], [0, 3],[0, 4], [1, 0],[1, 1], [1, 2], .....] But I get only the last value [4,4], b: b: [[4, 4], [4, 4], [4, 4], ... ] My code: a = ["",""] b = [] for i in range (0,5): for j in range (0,5): a[0] = i a[1] = j print "a: " + str(a) b.append(a) print "b: " + str(b) what is worng in the code? Thanks, Bye, From gagsl-py2 at yahoo.com.ar Fri Feb 20 11:14:16 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 20 Feb 2009 14:14:16 -0200 Subject: Keeping the Console Open with IDLE References: <54c56179-6f92-41e9-bad7-afa8b28d0671@l38g2000vba.googlegroups.com> Message-ID: En Fri, 20 Feb 2009 13:37:06 -0200, W. eWatson escribi?: > Catherine Heathcote wrote: >> W. eWatson wrote: >> Run the program from within the MS command line, not by double >> clicking it. > Shirley, you jest? DOS? To do this? How ugly. I barely recall the DOS > commands. I get to drill my way down 4 levels of folders. What DOS cmd > allows one to list only folders? After executing these two commands, pressing TAB will auto-complete matching filenames/directories: reg add "HKLM\Software\Microsoft\Command Processor" /v CompletionChar /t REG_DWORD /d 9 reg add "HKLM\Software\Microsoft\Command Processor" /v PathCompletionChar /t REG_DWORD /d 9 (Overwrite the previous value, if exists). This is a global change and the logged on user must have administrative rights to modify the registry. Unprivileged users must use HKCU instead of HKLM. -- Gabriel Genellina From luke.dunn at gmail.com Fri Feb 20 11:30:10 2009 From: luke.dunn at gmail.com (Trip Technician) Date: Fri, 20 Feb 2009 08:30:10 -0800 (PST) Subject: code challenge: generate minimal expressions using only digits 1,2,3 References: <941be713-2789-48c7-911b-422313f232d5@o36g2000yqh.googlegroups.com> <7xljs1xfiy.fsf@ruckus.brouhaha.com> Message-ID: On 20 Feb, 16:02, Paul Rubin wrote: > Trip Technician writes: > > I have a dim intuition that it could be done with a very clever bit of > > recursion, but the exact form so far eludes me. > > This sounds a little like a homework assignment, or maybe a challenge > you are trying to solve for yourself, rather than be given a complete > answer for. ?Anyway, the basic idea is to enumerate the expression > trees with 1 digit, then 2 digits, then 3 digits, etc, and compute the > value expressed by each tree. Thanks will get onto it. It's just a challenge I set myself so hints only are cool. From luke.dunn at gmail.com Fri Feb 20 11:32:55 2009 From: luke.dunn at gmail.com (Trip Technician) Date: Fri, 20 Feb 2009 08:32:55 -0800 (PST) Subject: code challenge: generate minimal expressions using only digits 1,2,3 References: <941be713-2789-48c7-911b-422313f232d5@o36g2000yqh.googlegroups.com> Message-ID: <524396b0-cd08-4ac7-8789-fe52c6afa4f9@j1g2000yqi.googlegroups.com> On 20 Feb, 15:39, Nigel Rantor wrote: > Trip Technician wrote: > > anyone interested in looking at the following problem. > > if you can give me a good reason why this is not homework I'd love to > hear it...I just don't see how this is a real problem. > > > > > > > we are trying to express numbers as minimal expressions using only the > > digits one two and three, with conventional arithmetic. so for > > instance > > > 33 = 2^(3+2)+1 = 3^3+(3*2) > > > are both minimal, using 4 digits but > > > 33 = ((3+2)*2+1)*3 > > > using 5 is not. > > > I have tried coding a function to return the minimal representation > > for any integer, but haven't cracked it so far. The naive first > > attempt is to generate lots of random strings, eval() them and sort by > > size and value. this is inelegant and slow. > > Wow. Okay, what other ways have you tried so far? Or are you beating > your head against the "search the entire problem space" solution still? > > This problem smells a lot like factorisation, so I would think of it in > terms of wanting to reduce the target number using as few operations as > possible. > > If you allow exponentiation that's going to be your biggest hitter so > you know that the best you can do using 2 digits is n^n where n is the > largest digit you allow yourself. > > Are you going to allow things like n^n^n or not? > > ? ?n- Hide quoted text - > > - Show quoted text - yes n^n^n would be fine. agree it is connected to factorisation. building a tree of possible expressions is my next angle. From digitig at gmail.com Fri Feb 20 11:33:20 2009 From: digitig at gmail.com (Tim Rowe) Date: Fri, 20 Feb 2009 16:33:20 +0000 Subject: get most common number in a list with tolerance In-Reply-To: <499E6EC0.8090509@al.com.au> References: <499E6EC0.8090509@al.com.au> Message-ID: 2009/2/20 Astan Chee : > Hi, > I have a list that has a bunch of numbers in it and I want to get the most > common number that appears in the list. This is trivial because i can do a > max on each unique number. What I want to do is to have a tolerance to say > that each number is not quite unique and if the difference from other > numbers is small, than it can be counted together. This is what I have to > get the common number (taken from the internet somewhere): > > l = [10,30,20,20,11,12] > d = {} > tolerance = 5 > for elm in l: > d[elm] = d.get(elm, 0) + 1 > counts = [(j,i) for i,j in d.items()] > > > > This of course returns a list where each of them is unique > > [(1, 12), (1, 10), (1, 11), (2, 20), (1, 30)] > > but I am expecting a list that looks like this: > > [(3, 10), (2, 20), (1, 30)] Why only the points 10, 20 and 30? what has happened to (3,11), for example? (10, 11 and 12 are all within 11+/-5) It seems you are trying to do one of two things. Either you are trying to form a histogram with data bands +/-tolerance, or you are trying to do something like kernel smoothing with a rectangular kernel. What would you expect the output to be if the data set were [10,30,20,20,11,12,13] and the tolerance were 2? -- Tim Rowe From andrew at acooke.org Fri Feb 20 11:34:34 2009 From: andrew at acooke.org (andrew cooke) Date: Fri, 20 Feb 2009 13:34:34 -0300 (CLST) Subject: code challenge: generate minimal expressions using only digits 1,2,3 In-Reply-To: <941be713-2789-48c7-911b-422313f232d5@o36g2000yqh.googlegroups.com> References: <941be713-2789-48c7-911b-422313f232d5@o36g2000yqh.googlegroups.com> Message-ID: this is a neat problem. here is what i would do: use generators that extend an input. a stream approach. the initial input would be the numbers themselves. [('1', 1),('2', 2),('3', 3)] those are (expression, value) pairs then an initial attempt at the next function would be to extend that list with additions: def additions(pairs): for (expr1, value1) in pairs: # first, pass through unchanged yield (expr1, value1) # then generate all possible additions for (expr2, value2) in pairs: yield ('%s+%s'%(value1, value2), value1 + value2)) this would give you: [('1', 1),('2', 2),('3', 3), ('1+1', 2), ...] (you may need to add parentheses to expressions to preserve meaning correctly) you could extend that with an extra loop over different operations. (subtraction, multiplication, etc) then you could repeat that as often as you want (eating its own tail, in a sense, i think). an infinite list is ok because these are generators. then you could filter that to group expressions that give a certain value, and find the shortest. andrew Trip Technician wrote: > anyone interested in looking at the following problem. > > we are trying to express numbers as minimal expressions using only the > digits one two and three, with conventional arithmetic. so for > instance > > 33 = 2^(3+2)+1 = 3^3+(3*2) > > are both minimal, using 4 digits but > > 33 = ((3+2)*2+1)*3 > > using 5 is not. > > I have tried coding a function to return the minimal representation > for any integer, but haven't cracked it so far. The naive first > attempt is to generate lots of random strings, eval() them and sort by > size and value. this is inelegant and slow. > > I have a dim intuition that it could be done with a very clever bit of > recursion, but the exact form so far eludes me. > -- > http://mail.python.org/mailman/listinfo/python-list > > From wiggly at wiggly.org Fri Feb 20 11:38:18 2009 From: wiggly at wiggly.org (Nigel Rantor) Date: Fri, 20 Feb 2009 16:38:18 +0000 Subject: code challenge: generate minimal expressions using only digits 1,2,3 In-Reply-To: References: <941be713-2789-48c7-911b-422313f232d5@o36g2000yqh.googlegroups.com> <499ECEAA.30103@wiggly.org> Message-ID: <499EDC7A.80201@wiggly.org> Luke Dunn wrote: > yes power towers are allowed right, okay, without coding it here's my thought. factorise the numbers you have but only allowing primes that exist in your digit set. then take that factorisation and turn any repeated runs of digits multiplied by themselves into power-towers any remainder can then be created in other ways, starting with a way other than exponentiation that is able to create the largest number, i.e. multiplication, then addition... I've not got time to put it into code right now but it shouldn't be too hard... e.g. digits : 3, 2, 1 n : 10 10 = 2*5 - but we don't have 5... 10 = 3*3 + 1 10 = 3^2+1 3 digits n : 27 27 = 3*3*3 27 = 3^3 2 digits n : 33 33 = 3*3*3 + 6 33 = 3*3*3 + 3*2 33 = 3^3+3*2 4 digits > exponentiation, multiplication, division, addition and subtraction. > Brackets when necessary but length is sorted on number of digits not > number of operators plus digits. > > I always try my homework myself first. in 38 years of life I've > learned only to do what i want, if I wanted everyone else to do my work > for me I'd be a management consultant ! > On Fri, Feb 20, 2009 at 3:52 PM, Luke Dunn > wrote: > > I am teaching myself coding. No university or school, so i guess its > homework if you like. i am interested in algorithms generally, after > doing some of Project Euler. Of course my own learning process is > best served by just getting on with it but sometimes you will do > that while other times you might just choose to ask for help. if no > one suggests then i will probably shelve it and come back to it > myself when I'm fresh. > > no it's not a real world problem but my grounding is in math so i > like pure stuff anyway. don't see how that is a problem, as a math > person i accept the validity of pure research conducted just for > curiosity and aesthetic satisfaction. it often finds an application > later anyway > > Thanks for your helpful suggestion of trying other methods and i > will do that in time. my motive was to share an interesting problem > because a human of moderate math education can sit down with this > and find minimal solutions easily but the intuition they use is > quite subtle, hence the idea of converting the human heuristic into > an algorithm became of interest, and particularly a recursive one. i > find that the development of a piece of recursion usually comes as > an 'aha', and since i hadn't had such a moment, i thought i'd turn > the problem loose on the public. also i found no online reference to > this problem so it seemed ripe for sharing. > > On Fri, Feb 20, 2009 at 3:39 PM, Nigel Rantor > wrote: > > Trip Technician wrote: > > anyone interested in looking at the following problem. > > > if you can give me a good reason why this is not homework I'd > love to hear it...I just don't see how this is a real problem. > > > we are trying to express numbers as minimal expressions > using only the > digits one two and three, with conventional arithmetic. so for > instance > > 33 = 2^(3+2)+1 = 3^3+(3*2) > > are both minimal, using 4 digits but > > 33 = ((3+2)*2+1)*3 > > using 5 is not. > > I have tried coding a function to return the minimal > representation > for any integer, but haven't cracked it so far. The naive first > attempt is to generate lots of random strings, eval() them > and sort by > size and value. this is inelegant and slow. > > > Wow. Okay, what other ways have you tried so far? Or are you > beating your head against the "search the entire problem space" > solution still? > > This problem smells a lot like factorisation, so I would think > of it in terms of wanting to reduce the target number using as > few operations as possible. > > If you allow exponentiation that's going to be your biggest > hitter so you know that the best you can do using 2 digits is > n^n where n is the largest digit you allow yourself. > > Are you going to allow things like n^n^n or not? > > n > > > > From wiggly at wiggly.org Fri Feb 20 11:41:45 2009 From: wiggly at wiggly.org (Nigel Rantor) Date: Fri, 20 Feb 2009 16:41:45 +0000 Subject: code challenge: generate minimal expressions using only digits 1,2,3 In-Reply-To: <524396b0-cd08-4ac7-8789-fe52c6afa4f9@j1g2000yqi.googlegroups.com> References: <941be713-2789-48c7-911b-422313f232d5@o36g2000yqh.googlegroups.com> <524396b0-cd08-4ac7-8789-fe52c6afa4f9@j1g2000yqi.googlegroups.com> Message-ID: <499EDD49.80703@wiggly.org> Trip Technician wrote: > > yes n^n^n would be fine. agree it is connected to factorisation. > building a tree of possible expressions is my next angle. I think building trees of the possible expressions as a couple of other people have suggested is simply a more structured way of doing what you're currnetly doing. Right now you're throwing darts at the problem space, and hoping that the next one point you hit will be a more optimal solution. If you enumerate all the expression trees you are just ensuring you don't miss any solutions. I think the algorithm/hueristic I just posted should get you to the answer quicker though... n From yguan08 at gmail.com Fri Feb 20 11:46:38 2009 From: yguan08 at gmail.com (Allen) Date: Fri, 20 Feb 2009 08:46:38 -0800 (PST) Subject: cx_oracle -- how to insert "&" Message-ID: <1af94e53-7a85-46e9-bf33-7165c9f47c8b@q30g2000prq.googlegroups.com> I am using Python with cx_oracle to load an excel spreadsheet into an Oracle table. There are lots of text on the spreadsheet that have "&" in them which I want to keep in the table. But inserting those text will fail. Is there a work around for this? I can filter out the failed insert statements and in SQLPLUS set define off to run those statements, but it would be nice to insert "&" directly in PYTHON. Allen From jimzat at iname.com Fri Feb 20 11:47:27 2009 From: jimzat at iname.com (jimzat) Date: Fri, 20 Feb 2009 08:47:27 -0800 (PST) Subject: Killing subservient threads Message-ID: <4bdc5d28-9ad9-446f-bd37-9e431fd702c6@p36g2000prp.googlegroups.com> I am trying to create an app which will have a main window from which the user will launch other (children) windows. When I launch the child window I start a new thread which periodically polls another device and updates the child window accordingly. When I dismiss the child window the "polling" thread stays alive and then crashes with an exception when trying to write to the now defunct child window. How can I handle this? I want to either 1) have the destructor for the child window kill the spawned thread or 2) catch the exception within the "polling" thread and see that the child window is gone and then commit suicide. I am an experienced embedded C programmer but have VERY little experience with GUI programming and no experience in the Micro$oft programming world. From patrick.oloughlin at gmail.com Fri Feb 20 12:04:23 2009 From: patrick.oloughlin at gmail.com (Paddy O'Loughlin) Date: Fri, 20 Feb 2009 17:04:23 +0000 Subject: How do I declare global vars or class vars in Python ? In-Reply-To: <499ed41c$0$15309$426a74cc@news.free.fr> References: <499eaa34$0$21372$426a74cc@news.free.fr> <499ed41c$0$15309$426a74cc@news.free.fr> Message-ID: 2009/2/20 Bruno Desthuilliers : >> Interesting. Why shouldn't you? >> I haven't used the property() function > > s/function/object/ Nice try, but what I wrote was what I intended to say: http://docs.python.org/library/functions.html#property For all I know I could have used property objects several times in modules :) > The case is that the whole point of using a computed attribute is to perform > some computation on the value. IOW, except for a couple corner cases, only > the accessors should directly access the implementation(s) attributes(s). > > And of course, like for any other GoldenRule(tm), it's not meant to be > blindly followed. It's just that most of the times, going thru the accessors > is really what you want - even from within the class code. Hmm, it doesn't seem to me like it's much of a big deal, for it to described as anything like a "GoldenRule" or to advise against its overuse. You use it when its appropriate and don't use it when you it's not, like any other feature. Paddy -- "Ray, when someone asks you if you're a god, you say YES!" From google at mrabarnett.plus.com Fri Feb 20 12:13:44 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 20 Feb 2009 17:13:44 +0000 Subject: Keeping the Console Open with IDLE In-Reply-To: References: <54c56179-6f92-41e9-bad7-afa8b28d0671@l38g2000vba.googlegroups.com> Message-ID: <499EE4C8.4060104@mrabarnett.plus.com> Catherine Heathcote wrote: > W. eWatson wrote: >> Catherine Heathcote wrote: >>> W. eWatson wrote: >>>> >>>>> >>>>> I'm not sure whether I should feel old or write a smart alec >>>>> comment -- >>>>> I suppose there are people in the world who don't know what to do >>>>> with a >>>>> command prompt.... >>>>> >>>>> Assuming a Windows system: >>>>> >>>>> 2. Type 'cd ' (as in Change Directory) in the command prompt window >>>>> (w/o >>>>> the single quote characters) >>>>> 3. Drag/drop the folder containing your python script to your command >>>>> prompt window >>>>> 4. Hit enter in your command prompt window. >>>>> 5. Type python my_script_name.py to execute my_script_name.py. >>>>> >>>>> --David >>>> If I enter just cd, then it tells me cd is not defined. If I enter >>>> c:/python25, it tells me I have a syntax error at c in c:. The title >>>> of the black background window I have up with a >>> prompt shown in >>>> it is "Python(command line)". Maybe this isn't the real Python >>>> console window? >>>> >>>> What I want is that if I execute the program by double clicking on >>>> its name to display the console window with the program or syntax >>>> errors shown without it closing in a split second. Putting read_raw >>>> in it doesn't work, since some error prevents it from ever being seen. >>>> >>> >>> you need to open a dos prompt before doing the steps above. Go to >>> start->run and hit "cmd" without the quotes. >> Something is amiss here. There's the MS Command Prompt, which I'm >> looking at right now. Yes, it has cd, and so on. I'm also looking at >> the Python command line window. It allow one to run interactively. >> >> If I write a simple python program with just raw_input, by clicking on >> the file name, I get a window with the the title "\Python25\pythonexe" >> that shows the prompt. If I deliberately put a syntax error in the >> program, and run it by clicking the file, then A window appears and >> disappears so quickly that I have no idea what it said. How do I keep >> that window up? >> >> Which, if any, of these is the real Python console? What is the window >> called in the example I gave with raw_input? >> > > Run the program from within the MS command line, not by double clicking it. > Or create a .bat file containing the commands to run the Python program, ending with the command "pause", which will wait for you to press a key when the program has quit. From bing.liu at gmail.com Fri Feb 20 12:14:52 2009 From: bing.liu at gmail.com (bing) Date: Fri, 20 Feb 2009 09:14:52 -0800 (PST) Subject: How Can I run some Python Scripts in VS C++? Message-ID: Hi, I have some simple python scripts, anyone knows how to run the Python Scripts in C++? Any code example would be really helpful and appreciated. From gagsl-py2 at yahoo.com.ar Fri Feb 20 12:21:42 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 20 Feb 2009 15:21:42 -0200 Subject: Killing subservient threads References: <4bdc5d28-9ad9-446f-bd37-9e431fd702c6@p36g2000prp.googlegroups.com> Message-ID: En Fri, 20 Feb 2009 14:47:27 -0200, jimzat escribi?: > I am trying to create an app which will have a main window from which > the user will launch other (children) windows. > > When I launch the child window I start a new thread which periodically > polls another device and updates the child window accordingly. When I > dismiss the child window the "polling" thread stays alive and then > crashes with an exception when trying to write to the now defunct > child window. > > How can I handle this? I want to either 1) have the destructor for > the child window kill the spawned thread or 2) catch the exception > within the "polling" thread and see that the child window is gone and > then commit suicide. 1) make the child window set a flag in the thread (let's say, t.terminate = True). And make the polling thread check the flag periodically (you possibly already have a loop there - just break the loop when you detect that self.terminate became true) 2) catching an exception is as easy as enclosing the code in a try/except block. And "commit suicide" is just "exit from the run() method". -- Gabriel Genellina From koranthala at gmail.com Fri Feb 20 12:22:36 2009 From: koranthala at gmail.com (koranthala) Date: Fri, 20 Feb 2009 09:22:36 -0800 (PST) Subject: Killing subservient threads References: <4bdc5d28-9ad9-446f-bd37-9e431fd702c6@p36g2000prp.googlegroups.com> Message-ID: On Feb 20, 9:47?pm, jimzat wrote: > I am trying to create an app which will have a main window from which > the user will launch other (children) windows. > > When I launch the child window I start a new thread which periodically > polls another device and updates the child window accordingly. ?When I > dismiss the child window the "polling" thread stays alive and then > crashes with an exception when trying to write to the now defunct > child window. > > How can I handle this? ?I want to either 1) have the destructor for > the child window kill the spawned thread or 2) catch the exception > within the "polling" thread and see that the child window is gone and > then commit suicide. > > I am an experienced embedded C programmer but have VERY little > experience with GUI programming and no experience in the Micro$oft > programming world. thread.setDaemon(True) Makes it a daemon thread which means that interpreter will not stay alive if only that thread is alive. From notvalid2 at sbcglobal.net Fri Feb 20 12:26:37 2009 From: notvalid2 at sbcglobal.net (W. eWatson) Date: Fri, 20 Feb 2009 09:26:37 -0800 Subject: Keeping the Console Open with IDLE In-Reply-To: References: <54c56179-6f92-41e9-bad7-afa8b28d0671@l38g2000vba.googlegroups.com> Message-ID: W. eWatson wrote: > David Smith wrote: >> W. eWatson wrote: >>>> I'm not sure whether I should feel old or write a smart alec comment -- >>>> I suppose there are people in the world who don't know what to do >>>> with a >>>> command prompt.... >>>> >>>> Assuming a Windows system: >>>> >>>> 2. Type 'cd ' (as in Change Directory) in the command prompt window >>>> (w/o >>>> the single quote characters) >>>> 3. Drag/drop the folder containing your python script to your command >>>> prompt window >>>> 4. Hit enter in your command prompt window. >>>> 5. Type python my_script_name.py to execute my_script_name.py. >>>> >>>> --David >>> If I enter just cd, then it tells me cd is not defined. If I enter >>> c:/python25, it tells me I have a syntax error at c in c:. The title of >>> the black background window I have up with a >>> prompt shown in it is >>> "Python(command line)". Maybe this isn't the real Python console window? >>> >>> What I want is that if I execute the program by double clicking on its >>> name to display the console window with the program or syntax errors >>> shown without it closing in a split second. Putting read_raw in it >>> doesn't work, since some error prevents it from ever being seen. >>> >> >> What I meant was open open the command prompt, type cd, space, DO NOT >> hit enter yet. Drag the folder with your script into the command prompt >> window. Then go to the command prompt window and hit enter. This >> should compose a command similar to the following: >> >> C:\Documents and Settings\user> cd "C:\Documents and Settings\user\My >> Documents\My Project" >> >> C:\Documents and Settings\user\My Documents\My Project> _ >> >> --David > Ah, I thought I'd be clever and do a copy on the path name in the > address area at the top of the folder. That doesn't work. I'm quite > surprised though that one can do the drag as you say. But, hey, it > works. Thanks. I wonder what else non-DOS things can be done in it? > Well, there is a difficulty with this method. The path is very long, and one must change the property width of the window. However, putting the name of a long py file further complicates this. The negative surprise here is that I'm trying to avoid executing the program in IDLE, because I'm told elsewhere it produced erroneous error msgs. They are exactly the same here. I'll take this up on another thread. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet Web Page: From gagsl-py2 at yahoo.com.ar Fri Feb 20 12:28:02 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 20 Feb 2009 15:28:02 -0200 Subject: How Can I run some Python Scripts in VS C++? References: Message-ID: En Fri, 20 Feb 2009 15:14:52 -0200, bing escribi?: > Hi, I have some simple python scripts, anyone knows how to run the > Python Scripts in C++? > Any code example would be really helpful and appreciated. Do you want to write a C++ application, and allow your users to write scripts in Python, possibly exposing some objects from you application? Yes: read the "Extending and Embedding" document, specially the "Embedding part" (last) No: please explain in more detail what you want to do. -- Gabriel Genellina From lists at cheimes.de Fri Feb 20 12:30:43 2009 From: lists at cheimes.de (Christian Heimes) Date: Fri, 20 Feb 2009 18:30:43 +0100 Subject: Killing subservient threads In-Reply-To: References: <4bdc5d28-9ad9-446f-bd37-9e431fd702c6@p36g2000prp.googlegroups.com> Message-ID: Gabriel Genellina wrote: > 1) make the child window set a flag in the thread (let's say, > t.terminate = True). And make the polling thread check the flag > periodically (you possibly already have a loop there - just break the > loop when you detect that self.terminate became true) threading.Condition() and threading.Event() are especially designed for the job. Please use them appropriately. Christian From marc.wyburn at googlemail.com Fri Feb 20 12:33:13 2009 From: marc.wyburn at googlemail.com (marc wyburn) Date: Fri, 20 Feb 2009 09:33:13 -0800 (PST) Subject: pymssql text type Message-ID: <851ed9db-2561-48ad-b54c-95f96a7fa42d@q9g2000yqc.googlegroups.com> Hi, I'm trying to pass a text blob to MS SQL Express 2008 but get the follwoing error. (, OperationalError("SQL Server message 102, severity 15, state 1, line 1:\nIncorrect syntax near 'assigned'.\n",), ) the string it is having an issue with is (\r\n\r\n\tLogon ID:\t\t(0x0,0xE892A8)\r\n\r\n\tLogon Type:\t2\r\n\r \n') It looks like SQL is reading the blob, finding the newline codes and generating an error. Is there anyway I can get it to ignore the text and just enter the whole sentance as a string. I think that some automatic character encodign might be taking place hence the string is being read but I can work out whether I need to character encode in Python, change a table setting in SQL or do something to pymssql. Thanks, Marc. From bruno.42.desthuilliers at websiteburo.invalid Fri Feb 20 12:38:27 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 20 Feb 2009 18:38:27 +0100 Subject: How do I declare global vars or class vars in Python ? In-Reply-To: References: <499eaa34$0$21372$426a74cc@news.free.fr> <499ed41c$0$15309$426a74cc@news.free.fr> Message-ID: <499eea77$0$4840$426a74cc@news.free.fr> Paddy O'Loughlin a ?crit : > 2009/2/20 Bruno Desthuilliers : >>> Interesting. Why shouldn't you? >>> I haven't used the property() function >> s/function/object/ > > Nice try, but what I wrote was what I intended to say: > http://docs.python.org/library/functions.html#property Check by yourself: >>> import inspect >>> inspect.isfunction(property) False >>> property() >>> dir(property) ['__class__', '__delattr__', '__delete__', '__doc__', '__get__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__set__', '__setattr__', '__str__', 'fdel', 'fget', 'fset'] >>> >> The case is that the whole point of using a computed attribute is to perform >> some computation on the value. IOW, except for a couple corner cases, only >> the accessors should directly access the implementation(s) attributes(s). >> >> And of course, like for any other GoldenRule(tm), it's not meant to be >> blindly followed. It's just that most of the times, going thru the accessors >> is really what you want - even from within the class code. > > Hmm, it doesn't seem to me like it's much of a big deal, for it to > described as anything like a "GoldenRule" One could say the same for each and any of the usual GoldenRules(tm). From bing.liu at gmail.com Fri Feb 20 12:47:06 2009 From: bing.liu at gmail.com (david) Date: Fri, 20 Feb 2009 09:47:06 -0800 (PST) Subject: How Can I run some Python Scripts in VS C++? References: Message-ID: <3305aa6f-7f1d-4103-9bf0-42c1a0d81c4f@v15g2000yqn.googlegroups.com> > > No: please explain in more detail what you want to do. > > -- > Gabriel Genellina Thanks for the fast reply Gabriel, Basically I have some python scripts to do some document processing, all in command line tho. I want to have an C++ application so that my scripts can run in dialogs (API). I saw a post before using c# to run python scripts within the c# main. I am willing to run my python scripts within c++. Thanks. From thorsten at thorstenkampe.de Fri Feb 20 12:54:11 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Fri, 20 Feb 2009 18:54:11 +0100 Subject: To unicode or not to unicode References: Message-ID: * Ron Garret (Thu, 19 Feb 2009 18:57:13 -0800) > I'm writing a little wiki that I call ?Wiki. That's a lowercase Greek > mu at the beginning (it's pronounced micro-wiki). No, it's not. I suggest you start your Unicode adventure by configuring your newsreader. Thorsten From aahz at pythoncraft.com Fri Feb 20 13:07:15 2009 From: aahz at pythoncraft.com (Aahz) Date: 20 Feb 2009 10:07:15 -0800 Subject: can multi-core improve single funciton? References: <6a4f17690902092228i31fd1661n41c61c4037a289df@mail.gmail.com> Message-ID: In article , Steven D'Aprano wrote: > >As I understand it, there's very little benefit to multi-cores in Python >due to the GIL. As phrased, your statement is completely wrong. Here's a more correct phrasing: "For threaded compute-bound applications written in pure Python, there's very little benefit to multiple cores." But threaded I/O-bound applications do receive some benefit from multiple cores, and using multiple processes certainly leverages multiple cores. If boosting the performance of a threaded compute-bound application is important, one can always write the critical parts in C/C++. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From google at mrabarnett.plus.com Fri Feb 20 13:08:18 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 20 Feb 2009 18:08:18 +0000 Subject: To unicode or not to unicode In-Reply-To: References: Message-ID: <499EF192.5010300@mrabarnett.plus.com> Thorsten Kampe wrote: > * Ron Garret (Thu, 19 Feb 2009 18:57:13 -0800) >> I'm writing a little wiki that I call ?Wiki. That's a lowercase Greek >> mu at the beginning (it's pronounced micro-wiki). > > No, it's not. I suggest you start your Unicode adventure by configuring > your newsreader. > It looked like mu to me, but you're correct: it's "MICRO SIGN", not "GREEK SMALL LETTER MU". From jimzat at iname.com Fri Feb 20 13:11:39 2009 From: jimzat at iname.com (jimzat) Date: Fri, 20 Feb 2009 10:11:39 -0800 (PST) Subject: Killing subservient threads References: <4bdc5d28-9ad9-446f-bd37-9e431fd702c6@p36g2000prp.googlegroups.com> Message-ID: <5ca84e48-07a1-426f-b3c9-580c8dc7f151@k19g2000prh.googlegroups.com> On Feb 20, 11:22?am, koranthala wrote: > > thread.setDaemon(True) > Makes it a daemon thread which means that interpreter will not stay > alive if only that thread is alive. My main window is used to launch multiple children and therefore when one is dismissed the interpreter will remain active. From gagsl-py2 at yahoo.com.ar Fri Feb 20 13:12:17 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 20 Feb 2009 16:12:17 -0200 Subject: How Can I run some Python Scripts in VS C++? References: <3305aa6f-7f1d-4103-9bf0-42c1a0d81c4f@v15g2000yqn.googlegroups.com> Message-ID: En Fri, 20 Feb 2009 15:47:06 -0200, david escribi?: > Basically I have some python scripts to do some document processing, > all in command line tho. > I want to have an C++ application so that my scripts can run in dialogs > (API). > I saw a post before using c# to run python scripts within the c# main. > I am willing to run my python scripts within c++. > Thanks. So you want to execute a Python script, in a different process, as if you typed the command line? That's not different to executing any other external program in C# - in fact is a C# question, no Python involved. Try something like this: Process p = new Process(); p.StartInfo.FileName = "path\to\python.exe"; p.StartInfo.Arguments = "path\to\your\script.py other arguments"; p.Start(); p.WaitForExit(); p.Close() There are other properties you may want to use, like RedirectStandardOutput; see the C# documentation. -- Gabriel Genellina From jimzat at iname.com Fri Feb 20 13:15:10 2009 From: jimzat at iname.com (jimzat) Date: Fri, 20 Feb 2009 10:15:10 -0800 (PST) Subject: Killing subservient threads References: <4bdc5d28-9ad9-446f-bd37-9e431fd702c6@p36g2000prp.googlegroups.com> Message-ID: On Feb 20, 11:21?am, "Gabriel Genellina" wrote: > 1) make the child window set a flag in the thread (let's say, t.terminate ? > = True). And make the polling thread check the flag periodically (you ? > possibly already have a loop there - just break the loop when you detect ? > that self.terminate became true) > > 2) catching an exception is as easy as enclosing the code in a try/except ? > block. And "commit suicide" is just "exit from the run() method". Gabriel, I am using the thread module and calling thread.start_new_thread (...). If I use t=thread.start_new_thread(...) and later set t.terminate, I get "AttributeError: 'int' object has no attribute 'terminate'" What is the proper way to do this? I don't want to use globals as I will have multiple child windows of various classes. From bing.liu at gmail.com Fri Feb 20 13:16:08 2009 From: bing.liu at gmail.com (david) Date: Fri, 20 Feb 2009 10:16:08 -0800 (PST) Subject: How Can I run some Python Scripts in VS C++? References: <3305aa6f-7f1d-4103-9bf0-42c1a0d81c4f@v15g2000yqn.googlegroups.com> Message-ID: <074c3462-a7da-4426-bcdd-387f9eb19811@x9g2000yqk.googlegroups.com> On Feb 20, 11:12?am, "Gabriel Genellina" wrote: > En Fri, 20 Feb 2009 15:47:06 -0200, david escribi?: > > > Basically I have some python scripts to do some document processing, > > all in command line tho. > > I want to have an C++ application so that my scripts can run in dialogs > > (API). > > I saw a post before using c# to run python scripts within the c# main. > > I am willing to run my python scripts within c++. > > Thanks. > > So you want to execute a Python script, in a different process, as if you ? > typed the command line? > That's not different to executing any other external program in C# - in ? > fact is a C# question, no Python involved. Try something like this: > > ? ? ?Process p = new Process(); > ? ? ?p.StartInfo.FileName = "path\to\python.exe"; > ? ? ?p.StartInfo.Arguments = "path\to\your\script.py other arguments"; > ? ? ?p.Start(); > ? ? ?p.WaitForExit(); > ? ? ?p.Close() > > There are other properties you may want to use, like ? > RedirectStandardOutput; see the C# documentation. > > -- > Gabriel Genellina Thanks so much. I'll give it a try :) Best Regards. David From tim.wintle at teamrubber.com Fri Feb 20 13:22:27 2009 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Fri, 20 Feb 2009 18:22:27 +0000 Subject: code challenge: generate minimal expressions using only digits 1,2,3 In-Reply-To: <499EDC7A.80201@wiggly.org> References: <941be713-2789-48c7-911b-422313f232d5@o36g2000yqh.googlegroups.com> <499ECEAA.30103@wiggly.org> <499EDC7A.80201@wiggly.org> Message-ID: <1235154147.8441.31.camel@tim-laptop> On Fri, 2009-02-20 at 16:38 +0000, Nigel Rantor wrote: > Luke Dunn wrote: That was my initial thought when I read this too - but I'm not certain that is guaranteed to find a solution (i.e. a solution that's optimal). I'd welcome a proof that it will though, a few minutes thought hasn't found a counter-example. > > yes power towers are allowed > > right, okay, without coding it here's my thought. > > factorise the numbers you have but only allowing primes that exist in > your digit set. > > then take that factorisation and turn any repeated runs of digits > multiplied by themselves into power-towers > > any remainder can then be created in other ways, starting with a way > other than exponentiation that is able to create the largest number, > i.e. multiplication, then addition... > > I've not got time to put it into code right now but it shouldn't be too > hard... > > e.g. > > digits : 3, 2, 1 > > n : 10 > 10 = 2*5 - but we don't have 5... > 10 = 3*3 + 1 > 10 = 3^2+1 > 3 digits > > n : 27 > 27 = 3*3*3 > 27 = 3^3 > 2 digits > > n : 33 > 33 = 3*3*3 + 6 > 33 = 3*3*3 + 3*2 > 33 = 3^3+3*2 > 4 digits > > > exponentiation, multiplication, division, addition and subtraction. > > Brackets when necessary but length is sorted on number of digits not > > number of operators plus digits. > > > > I always try my homework myself first. in 38 years of life I've > > learned only to do what i want, if I wanted everyone else to do my work > > for me I'd be a management consultant ! > > On Fri, Feb 20, 2009 at 3:52 PM, Luke Dunn > > wrote: > > > > I am teaching myself coding. No university or school, so i guess its > > homework if you like. i am interested in algorithms generally, after > > doing some of Project Euler. Of course my own learning process is > > best served by just getting on with it but sometimes you will do > > that while other times you might just choose to ask for help. if no > > one suggests then i will probably shelve it and come back to it > > myself when I'm fresh. > > > > no it's not a real world problem but my grounding is in math so i > > like pure stuff anyway. don't see how that is a problem, as a math > > person i accept the validity of pure research conducted just for > > curiosity and aesthetic satisfaction. it often finds an application > > later anyway > > > > Thanks for your helpful suggestion of trying other methods and i > > will do that in time. my motive was to share an interesting problem > > because a human of moderate math education can sit down with this > > and find minimal solutions easily but the intuition they use is > > quite subtle, hence the idea of converting the human heuristic into > > an algorithm became of interest, and particularly a recursive one. i > > find that the development of a piece of recursion usually comes as > > an 'aha', and since i hadn't had such a moment, i thought i'd turn > > the problem loose on the public. also i found no online reference to > > this problem so it seemed ripe for sharing. > > > > On Fri, Feb 20, 2009 at 3:39 PM, Nigel Rantor > > wrote: > > > > Trip Technician wrote: > > > > anyone interested in looking at the following problem. > > > > > > if you can give me a good reason why this is not homework I'd > > love to hear it...I just don't see how this is a real problem. > > > > > > we are trying to express numbers as minimal expressions > > using only the > > digits one two and three, with conventional arithmetic. so for > > instance > > > > 33 = 2^(3+2)+1 = 3^3+(3*2) > > > > are both minimal, using 4 digits but > > > > 33 = ((3+2)*2+1)*3 > > > > using 5 is not. > > > > I have tried coding a function to return the minimal > > representation > > for any integer, but haven't cracked it so far. The naive first > > attempt is to generate lots of random strings, eval() them > > and sort by > > size and value. this is inelegant and slow. > > > > > > Wow. Okay, what other ways have you tried so far? Or are you > > beating your head against the "search the entire problem space" > > solution still? > > > > This problem smells a lot like factorisation, so I would think > > of it in terms of wanting to reduce the target number using as > > few operations as possible. > > > > If you allow exponentiation that's going to be your biggest > > hitter so you know that the best you can do using 2 digits is > > n^n where n is the largest digit you allow yourself. > > > > Are you going to allow things like n^n^n or not? > > > > n > > > > > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list From aisaac at american.edu Fri Feb 20 13:27:33 2009 From: aisaac at american.edu (Alan Isaac) Date: Fri, 20 Feb 2009 18:27:33 GMT Subject: is it possible to add a property to an instance? In-Reply-To: References: <2dda482a-d15c-4f8d-9fca-3bfffe9e4fa1@f63g2000hsf.googlegroups.com> Message-ID: Darren Dale wrote to GHUM: > Sorry, that's an attribute, not a property. This is a question about terminology. In contrast to Darren's recommended usage, I have run into the following. If hasattr(x,'a') is True, for instance object `x`, then `a` is an attribute of `x`. Attributes are data attributes or callable attributes. Data attributes are variables or properties. Callable attributes are usually method attributes. This seemed about right to me, but a better (or "official") taxonomy would be welcome. Thanks, Alan Isaac From aaron.hildebrandt at gmail.com Fri Feb 20 13:28:34 2009 From: aaron.hildebrandt at gmail.com (Aaron Scott) Date: Fri, 20 Feb 2009 10:28:34 -0800 (PST) Subject: Find the location of a loaded module Message-ID: <73f87180-7a68-4d50-952d-e966a3932690@s9g2000prg.googlegroups.com> I'm running into a problem that's rapidly reaching keyboard-smashing levels. I'm trying to import a module into Python, but it seems like Python is almost randomly loading the module from an entirely different directory, one that shouldn't be in the module search path. When I tell Python to load a module, is there a way to tell which directory the module was loaded from? From lists at cheimes.de Fri Feb 20 13:39:51 2009 From: lists at cheimes.de (Christian Heimes) Date: Fri, 20 Feb 2009 19:39:51 +0100 Subject: Find the location of a loaded module In-Reply-To: <73f87180-7a68-4d50-952d-e966a3932690@s9g2000prg.googlegroups.com> References: <73f87180-7a68-4d50-952d-e966a3932690@s9g2000prg.googlegroups.com> Message-ID: Aaron Scott schrieb: > I'm running into a problem that's rapidly reaching keyboard-smashing > levels. I'm trying to import a module into Python, but it seems like > Python is almost randomly loading the module from an entirely > different directory, one that shouldn't be in the module search path. > > When I tell Python to load a module, is there a way to tell which > directory the module was loaded from? All except builtin modules have an attribute __file__ that points to the file. Christian From patrick.oloughlin at gmail.com Fri Feb 20 13:45:16 2009 From: patrick.oloughlin at gmail.com (Paddy O'Loughlin) Date: Fri, 20 Feb 2009 18:45:16 +0000 Subject: How do I declare global vars or class vars in Python ? In-Reply-To: <499eea77$0$4840$426a74cc@news.free.fr> References: <499eaa34$0$21372$426a74cc@news.free.fr> <499ed41c$0$15309$426a74cc@news.free.fr> <499eea77$0$4840$426a74cc@news.free.fr> Message-ID: 2009/2/20 Bruno Desthuilliers : > Check by yourself: > >>>> import inspect >>>> inspect.isfunction(property) > False Using this, every single builtin function returns False. That's a pretty limited definition to be being pedantic over, especially when they are in the "Built-in Functions" section of the manual. >>>> property() > I never said that calling it didn't return a property object :) >>> property So it's a type. I think I didn't make such a bad error on my part. My intent in what I was saying was to indicate that I hadn't created a property type. It's fair enough to consider type constructors as functions given how they are listed as such by the python documentation. I don't think that your correction was much help, unless you just want to say that everything is an object. Maybe you'd be right, but it's not much use to use the term that way, imo >>>> dir(property) > ['__class__', '__delattr__', '__delete__', '__doc__', '__get__', > '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', > '__reduce_ex__', '__repr__', '__set__', '__setattr__', '__str__', 'fdel', > 'fget', 'fset'] Doesn't prove a whole lot. So types have attributes... So do functions: >>> def myfunc(): ... pass ... >>> dir(myfunc) ['__call__', '__class__', '__delattr__', '__dict__', '__doc__', '__get__', '__getattribute__', '__hash__', '__init__', '__module__', '__name__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', 'func_closure', 'func_code', 'func_defaults', 'func_dict', 'func_doc', 'func_globals', 'func_name'] >> Hmm, it doesn't seem to me like it's much of a big deal, for it to >> described as anything like a "GoldenRule" > > One could say the same for each and any of the usual GoldenRules(tm). Not really. To do so would be over-generalising and not useful to discussion I guess it's your pedantry that I'm questioning. Something like "don't use goto's" works as a GoldenRule because it's been observed that without it, people start using goto statements in places where it's not really appropriate. When you said that "[you] usually shouldn't [use properties] - unless you have a very compelling reason", your tone implied that properties are easy to misuse and tend to be. Not being familiar with properties and seeing them as being pretty harmless, I was intrigued by this, which is why I asked for an explanation. Your explanation seems to show that your tone was likely to be more personal bias than any real issue with properties. Paddy -- "Ray, when someone asks you if you're a god, you say YES!" From aisaac at american.edu Fri Feb 20 13:49:21 2009 From: aisaac at american.edu (Alan Isaac) Date: Fri, 20 Feb 2009 18:49:21 GMT Subject: function factory question: embed current values of object attributes Message-ID: I have a class `X` where many parameters are set at instance initialization. The parameter values of an instance `x` generally remain unchanged, but is there way to communicate to a method that it depends only on the initial values of these parameters (and does not need to worry about any changes)? The behavior of method `m` depends on these parameter values. It turns out `m` gets called a lot, which means that the pameter values are accessed over and over (self.p0, self.p1, etc). I would like to manufacture a function equivalent to the method that simply uses fixed values (the values at the time it is manufactured). I do not care if this function is attached to `x` or not. I have a feeling that I am turning something simple into something complex, perhaps for lack of an afternoon coffee or lack of CS training. Suggestions appreciated. Alan Isaac From aaron.hildebrandt at gmail.com Fri Feb 20 13:53:58 2009 From: aaron.hildebrandt at gmail.com (Aaron Scott) Date: Fri, 20 Feb 2009 10:53:58 -0800 (PST) Subject: Find the location of a loaded module References: <73f87180-7a68-4d50-952d-e966a3932690@s9g2000prg.googlegroups.com> Message-ID: Okay, I'm going out of my mind. I have three directories -- 'act1', 'act2', and 'act3'. Each of these has a module named 'story'. Through mod_python, I need to load 'story' in the directory 'act1'. I do it like this: req.content_type = "text/html" sys.path.append(os.path.dirname( __file__ )) req.write(str(sys.path)) import story req.write(story.game.Save()) sys.path.pop() According to sys.path, these are Python's paths: ['/usr/lib/python25.zip', '/usr/lib/python2.5', '/usr/lib/python2.5/ plat-linux2', '/usr/lib/python2.5/lib-tk', '/usr/lib/python2.5/lib- dynload', '/usr/lib/python2.5/site-packages', '/usr/local/python2.5.2/ lib/python2.5/', '/home/www/---/docs/act1'] story.game.Save() returns the location of the story.game module, which is reported as '/home/www/---/docs/act1/story/game.pyc'. So far so good. Now, I'll try the same thing from the 'act2' directory. These are the paths reported in sys.path: ['/usr/lib/python25.zip', '/usr/lib/python2.5', '/usr/lib/python2.5/ plat-linux2', '/usr/lib/python2.5/lib-tk', '/usr/lib/python2.5/lib- dynload', '/usr/lib/python2.5/site-packages', '/usr/local/python2.5.2/ lib/python2.5/', '/home/www/---/docs/act2'] All good, right? Not so fast. Here's what story.game.Save() returns as its location: '/home/www/---/docs/act1/story/game.pyc'. Which means it's loading the 'story' module from the old location, even though that location is no longer in the path. If I refresh a couple times, eventually it loads the module from the proper directory ('act2'). Then, I'll go back to the first directory, and find that it too will be loading the module from 'act2'. I'll refresh, and it'll load from 'act1' again. I'll refresh a couple times, and suddenly it's loading from 'act2' again. I'm seriously going insane. If anyone has any insight, please, please share it with me. Aaron From umarpy at googlemail.com Fri Feb 20 14:11:11 2009 From: umarpy at googlemail.com (umarpy at googlemail.com) Date: Fri, 20 Feb 2009 11:11:11 -0800 (PST) Subject: Regular expression bug? References: Message-ID: <18ff6125-1b25-48ff-b6c5-8accec79b69d@u38g2000yqe.googlegroups.com> More elegant way >>> [x for x in re.split('([A-Z]+[a-z]+)', a) if x ] ['foo', 'Bar', 'Baz'] R. On Feb 20, 2:03?pm, Lie Ryan wrote: > On Thu, 19 Feb 2009 13:03:59 -0800, Ron Garret wrote: > > In article , > > ?Peter Otten <__pete... at web.de> wrote: > > >> Ron Garret wrote: > > >> > I'm trying to split a CamelCase string into its constituent > >> > components. > > >> How about > > >> >>> re.compile("[A-Za-z][a-z]*").findall("fooBarBaz") > >> ['foo', 'Bar', 'Baz'] > > > That's very clever. ?Thanks! > > >> > (BTW, I tried looking at the source code for the re module, but I > >> > could not find the relevant code. ?re.split calls > >> > sre_compile.compile().split, but the string 'split' does not appear > >> > in sre_compile.py. ?So where does this method come from?) > > >> It's coded in C. The source is Modules/sremodule.c. > > > Ah. ?Thanks! > > > rg > > This re.split() doesn't consume character: > > >>> re.split('([A-Z][a-z]*)', 'fooBarBaz') > > ['foo', 'Bar', '', 'Baz', ''] > > it does what the OP wants, albeit with extra blank strings. From invalid at invalid Fri Feb 20 14:20:48 2009 From: invalid at invalid (Grant Edwards) Date: Fri, 20 Feb 2009 13:20:48 -0600 Subject: can multi-core improve single funciton? References: <6a4f17690902092228i31fd1661n41c61c4037a289df@mail.gmail.com> Message-ID: On 2009-02-20, Aahz wrote: > Steven D'Aprano wrote: > >> As I understand it, there's very little benefit to multi-cores >> in Python due to the GIL. > > As phrased, your statement is completely wrong. Here's a more > correct phrasing: "For threaded compute-bound applications > written in pure Python, there's very little benefit to > multiple cores." But threaded I/O-bound applications do > receive some benefit from multiple cores, and using multiple > processes certainly leverages multiple cores. If boosting the > performance of a threaded compute-bound application is > important, one can always write the critical parts in C/C++. Do the crunchy bits of scipy/numpy, scientific python, vtk and other compute-intensive libraries tend to release the GIL while they're busy "computing"? [Perhaps using them doesn't count as "pure Python", but...] -- Grant Edwards grante Yow! NEWARK has been at REZONED!! DES MOINES has visi.com been REZONED!! From rNOSPAMon at flownet.com Fri Feb 20 14:21:02 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Fri, 20 Feb 2009 11:21:02 -0800 Subject: To unicode or not to unicode References: Message-ID: In article , MRAB wrote: > Thorsten Kampe wrote: > > * Ron Garret (Thu, 19 Feb 2009 18:57:13 -0800) > >> I'm writing a little wiki that I call ??Wiki. That's a lowercase Greek > >> mu at the beginning (it's pronounced micro-wiki). > > > > No, it's not. I suggest you start your Unicode adventure by configuring > > your newsreader. > > > It looked like mu to me, but you're correct: it's "MICRO SIGN", not > "GREEK SMALL LETTER MU". Heh, I didn't know that those two things were distinct. Learn something new every day. rg From rNOSPAMon at flownet.com Fri Feb 20 14:48:45 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Fri, 20 Feb 2009 11:48:45 -0800 Subject: What encoding does u'...' syntax use? Message-ID: I would have thought that the answer would be: the default encoding (duh!) But empirically this appears not to be the case: >>> unicode('\xb5') Traceback (most recent call last): File "", line 1, in UnicodeDecodeError: 'ascii' codec can't decode byte 0xb5 in position 0: ordinal not in range(128) >>> u'\xb5' u'\xb5' >>> print u'\xb5' ? (That last character shows up as a micron sign despite the fact that my default encoding is ascii, so it seems to me that that unicode string must somehow have picked up a latin-1 encoding.) rg From martin at v.loewis.de Fri Feb 20 15:05:04 2009 From: martin at v.loewis.de (=?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=) Date: Fri, 20 Feb 2009 21:05:04 +0100 Subject: To unicode or not to unicode In-Reply-To: References: Message-ID: <499F0CF0.8070800@v.loewis.de> MRAB wrote: > Thorsten Kampe wrote: >> * Ron Garret (Thu, 19 Feb 2009 18:57:13 -0800) >>> I'm writing a little wiki that I call ?Wiki. That's a lowercase >>> Greek mu at the beginning (it's pronounced micro-wiki). >> >> No, it's not. I suggest you start your Unicode adventure by >> configuring your newsreader. >> > It looked like mu to me, but you're correct: it's "MICRO SIGN", not > "GREEK SMALL LETTER MU". I don't think that was the complaint. Instead, the complaint was that the OP's original message did not have a Content-type header, and that it was thus impossible to tell what the byte in front of "Wiki" meant. To properly post either MICRO SIGN or GREEK SMALL LETTER MU in a usenet or email message, you really must use MIME. (As both your article and Thorsten's did, by choosing UTF-8) Regards, Martin P.S. The difference between MICRO SIGN and GREEK SMALL LETTER MU is nit-picking, IMO: py> unicodedata.name(unicodedata.normalize("NFKC", u"\N{MICRO SIGN}")) 'GREEK SMALL LETTER MU' From rNOSPAMon at flownet.com Fri Feb 20 15:19:13 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Fri, 20 Feb 2009 12:19:13 -0800 Subject: To unicode or not to unicode References: <499F0CF0.8070800@v.loewis.de> Message-ID: In article <499F0CF0.8070800 at v.loewis.de>, "Martin v. L??wis" wrote: > MRAB wrote: > > Thorsten Kampe wrote: > >> * Ron Garret (Thu, 19 Feb 2009 18:57:13 -0800) > >>> I'm writing a little wiki that I call ??Wiki. That's a lowercase > >>> Greek mu at the beginning (it's pronounced micro-wiki). > >> > >> No, it's not. I suggest you start your Unicode adventure by > >> configuring your newsreader. > >> > > It looked like mu to me, but you're correct: it's "MICRO SIGN", not > > "GREEK SMALL LETTER MU". > > I don't think that was the complaint. Instead, the complaint was > that the OP's original message did not have a Content-type header, I'm the OP. I'm using MT-Newswatcher 3.5.1. I thought I had it configured properly, but I guess I didn't. Under Preferences->Languages->Send Messages with Encoding I had selected latin-1. I didn't know I also needed to have MIME turned on for that to work. I've turned it on now. Is this better? This should be a micro sign: ?? rg From aaron.hildebrandt at gmail.com Fri Feb 20 15:23:03 2009 From: aaron.hildebrandt at gmail.com (Aaron Scott) Date: Fri, 20 Feb 2009 12:23:03 -0800 (PST) Subject: Find the location of a loaded module References: <73f87180-7a68-4d50-952d-e966a3932690@s9g2000prg.googlegroups.com> Message-ID: <1d94d39d-1795-4111-b567-3263c1da569f@d32g2000yqe.googlegroups.com> Here's another clue: if I'm trying to run the script from the directory 'act1', but it's loading the module from 'act2', if I rename the module directory in 'act2' and refresh, the module still reports that it's running from '/home/www/---/docs/act2/story/game.pyc'... even though that files no longer exists. If I refresh a few more times, both 'act1' and 'act2' will load the module from 'act1's directory (even though the directory doesn't appear in sys.path when you try to load it from 'act2'). So, Python is trying to import a module from a directory that isn't in sys.path, and will generally default to running the module from the directory where it was last run. If I run it from 'act1', then 'act2', both times it will load the module from 'act1'. If I do it the other way around, it will load the module from 'act2' both times. The question now is... why is it loading from a directory that isn't in sys.path? How can I avoid this? From rushenaly at gmail.com Fri Feb 20 15:35:58 2009 From: rushenaly at gmail.com (rushenaly at gmail.com) Date: Fri, 20 Feb 2009 12:35:58 -0800 (PST) Subject: Will multithreading make python less popular? References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <28e3612d-2e91-4a91-82cb-5fb2deda95fd@q9g2000yqc.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> <7x8wo2kwoz.fsf@ruckus.brouhaha.com> <52a0375d-4fad-4caa-8328-47b8f30f2395@40g2000prx.googlegroups.com> Message-ID: I want to correct my last post where i said that there is not any intend to remove GIL from python. There is an intend actually i wish from a wizard :). On the pypy blog there is an explanation about gil and pypy "Note that multithreading in PyPy is based on a global interpreter lock, as in CPython. I imagine that we will get rid of the global interpreter lock at some point in the future -- I can certainly see how this might be done in PyPy, unlike in CPython -- but it will be a lot of work nevertheless. Given our current priorities, it will probably not occur soon unless someone steps in." Nothing new about GIL and Cpython and even PyPy Thank you... Rushen Thank you... From martin at v.loewis.de Fri Feb 20 15:41:18 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 20 Feb 2009 21:41:18 +0100 Subject: To unicode or not to unicode In-Reply-To: References: <499F0CF0.8070800@v.loewis.de> Message-ID: <499F156E.3030902@v.loewis.de> Ron Garret wrote: > In article <499F0CF0.8070800 at v.loewis.de>, > "Martin v. L??wis" wrote: > > > I'm the OP. I'm using MT-Newswatcher 3.5.1. I thought I had it > configured properly, but I guess I didn't. Probably you did. However, it then means that the newsreader is crap. > Under > Preferences->Languages->Send Messages with Encoding I had selected > latin-1. That sounds like early nineties, before the invention of MIME. > I didn't know I also needed to have MIME turned on for that to > work. I've turned it on now. Is this better? > > This should be a micro sign: ?? Not really (it's worse, from my point of view - but might be better for others). You are now sending in UTF-8, but there is still no MIME declaration in the news headers. As a consequence, my newsreader continues to interpret it as Latin-1 (which it assumes as the default encoding), and it comes out as moji-bake (in responding, my reader should declare the encoding properly, so you should see what I see, namely A-circumflex, micro sign) If you look at the message headers / message source as sent e.g. by MRAB, you'll notice lines like MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These lines are missing from your posting. Assuming the newsreader is not crap, it might help to set the default send encoding to ASCII. When sending micro sign, the newsreader might infer that ASCII is not good enough, and use MIME - although it then still needs to pick an encoding. Regards, Martin From nad at acm.org Fri Feb 20 15:48:46 2009 From: nad at acm.org (Ned Deily) Date: Fri, 20 Feb 2009 12:48:46 -0800 Subject: Framework installation of 2.6 on OS X, with specified prefix References: Message-ID: In article , Evert Rol wrote: > I'm trying to install Python 2.6 from source on Mac OS X.5, in its own > directory using a framework install. That goes fine, up to the point > where it wants to install the applications that come with it (eg, the > Wish shell): it tries to install things into /Applications, instead of > eg /Applications. > Here's my configure line (the flags are there just to let it find my > own installed readline): > > CPPFLAGS=-I/sw/include LDFLAGS=-L/sw/lib ./configure --prefix=/sw -- > enable-shared --enable-framework=/sw/Library/Frameworks --with- > readline=/sw --with-pth CC=gcc-4.2 MACOSX_DEPLOYMENT_TARGET=10.5 > > > And the last part of the output of 'make install': > > ../python.exe ./scripts/BuildApplet.py \ > --destroot "" \ > --python=/sw/Library/Frameworks/Python.framework/Versions/2.6/ > Resources/Python.app/Contents/MacOS/Python`test -f "/sw/Library/ > Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/ > MacOS/Python-32" && echo "-32"` \ > --output "/sw/Applications/Python 2.6/Build Applet.app" \ > ./scripts/BuildApplet.py > cd PythonLauncher && make install DESTDIR= > test -d "/Applications/Python 2.6" || mkdir -p "/Applications/Python > 2.6" > mkdir: /Applications/Python 2.6: Permission denied > make[2]: *** [install] Error 1 > make[1]: *** [install_PythonLauncher] Error 2 > make: *** [frameworkinstallapps] Error 2 > > Is there an option on the configure line that I need to set, or > something in setup.py? Or perhaps hack the Makefile? FWIW, the OS X build-installer.py script handles this by specifying a DESTDIR on the make install steps rather than including a --prefix on the configure. See Mac/BuildScript/build-installer.py. -- Ned Deily, nad at acm.org From stefan_ml at behnel.de Fri Feb 20 15:55:25 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 20 Feb 2009 21:55:25 +0100 Subject: What encoding does u'...' syntax use? In-Reply-To: References: Message-ID: <499f18bd$0$31879$9b4e6d93@newsspool3.arcor-online.net> Ron Garret wrote: > I would have thought that the answer would be: the default encoding > (duh!) But empirically this appears not to be the case: > >>>> unicode('\xb5') > Traceback (most recent call last): > File "", line 1, in > UnicodeDecodeError: 'ascii' codec can't decode byte 0xb5 in position 0: > ordinal not in range(128) >>>> u'\xb5' > u'\xb5' >>>> print u'\xb5' > ? > > (That last character shows up as a micron sign despite the fact that my > default encoding is ascii, so it seems to me that that unicode string > must somehow have picked up a latin-1 encoding.) You are mixing up console output and internal data representation. What you see in the last line is what the Python interpreter makes of your unicode string when passing it into stdout, which in your case seems to use a latin-1 encoding (check your environment settings for that). BTW, Unicode is not an encoding. Wikipedia will tell you more. Stefan From stefan_ml at behnel.de Fri Feb 20 15:58:59 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 20 Feb 2009 21:58:59 +0100 Subject: What encoding does u'...' syntax use? In-Reply-To: <499f18bd$0$31879$9b4e6d93@newsspool3.arcor-online.net> References: <499f18bd$0$31879$9b4e6d93@newsspool3.arcor-online.net> Message-ID: <499f1993$0$31879$9b4e6d93@newsspool3.arcor-online.net> Stefan Behnel wrote: >>>>> print u'\xb5' >> ? > > What you > see in the last line is what the Python interpreter makes of your unicode > string when passing it into stdout, which in your case seems to use a > latin-1 encoding (check your environment settings for that). The "seems to" is misleading. The example doesn't actually tell you anything about the encoding used by your console, except that it can display non-ASCII characters. Stefan From dotancohen at gmail.com Fri Feb 20 16:09:13 2009 From: dotancohen at gmail.com (Dotan Cohen) Date: Fri, 20 Feb 2009 23:09:13 +0200 Subject: Python 3D CAD -- need collaborators, or just brave souls :) In-Reply-To: <5764d607-e323-4996-aa6f-a7f04c779110@i38g2000yqd.googlegroups.com> References: <4993DE39.8030200@cosc.canterbury.ac.nz> <9ef65856-0f62-4434-a4b4-e15558e7c7b0@n2g2000vba.googlegroups.com> <5764d607-e323-4996-aa6f-a7f04c779110@i38g2000yqd.googlegroups.com> Message-ID: <880dece00902201309i1a12bd79qc79aa06b58f11176@mail.gmail.com> > Even 3DS or Maya is easier to learn that Blender. > Notepad is easier to learn that VI. Not a good program does simple make. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-??-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-? ?-?-?-?-?-?-? From rNOSPAMon at flownet.com Fri Feb 20 16:15:51 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Fri, 20 Feb 2009 13:15:51 -0800 Subject: What encoding does u'...' syntax use? References: <499f18bd$0$31879$9b4e6d93@newsspool3.arcor-online.net> Message-ID: In article <499f18bd$0$31879$9b4e6d93 at newsspool3.arcor-online.net>, Stefan Behnel wrote: > Ron Garret wrote: > > I would have thought that the answer would be: the default encoding > > (duh!) But empirically this appears not to be the case: > > > >>>> unicode('\xb5') > > Traceback (most recent call last): > > File "", line 1, in > > UnicodeDecodeError: 'ascii' codec can't decode byte 0xb5 in position 0: > > ordinal not in range(128) > >>>> u'\xb5' > > u'\xb5' > >>>> print u'\xb5' > > ? > > > > (That last character shows up as a micron sign despite the fact that my > > default encoding is ascii, so it seems to me that that unicode string > > must somehow have picked up a latin-1 encoding.) > > You are mixing up console output and internal data representation. What you > see in the last line is what the Python interpreter makes of your unicode > string when passing it into stdout, which in your case seems to use a > latin-1 encoding (check your environment settings for that). > > BTW, Unicode is not an encoding. Wikipedia will tell you more. Yes, I know that. But every concrete representation of a unicode string has to have an encoding associated with it, including unicode strings produced by the Python parser when it parses the ascii string "u'\xb5'" My question is: what is that encoding? It can't be ascii. So what is it? Put this another way: I would have thought that when the Python parser parses "u'\xb5'" it would produce the same result as calling unicode('\xb5'), but it doesn't. Instead it seems to produce the same result as calling unicode('\xb5', 'latin-1'). But my default encoding is not latin-1, it's ascii. So where is the Python parser getting its encoding from? Why does parsing "u'\xb5'" not produce the same error as calling unicode('\xb5')? rg From aaron.hildebrandt at gmail.com Fri Feb 20 16:16:26 2009 From: aaron.hildebrandt at gmail.com (Aaron Scott) Date: Fri, 20 Feb 2009 13:16:26 -0800 (PST) Subject: Find the location of a loaded module References: <73f87180-7a68-4d50-952d-e966a3932690@s9g2000prg.googlegroups.com> <1d94d39d-1795-4111-b567-3263c1da569f@d32g2000yqe.googlegroups.com> Message-ID: <28aba044-d927-499b-8bd2-525870ae0267@j1g2000yqi.googlegroups.com> And more madness... Executed from inside 'act1', which contains the directory / module 'story': directory = os.path.dirname(__file__) req.write(str(directory)) story = apache.import_module('story', path=[directory]) Results: File "/home/www/---/docs/act1/play.py", line 24, in Rebuild storylab = apache.import_module('story', path=[directory]) File "/usr/local/python2.5.2/lib/python2.5/site-packages/mod_python/ importer.py", line 304, in import_module return __import__(module_name, {}, {}, ['*']) ImportError: No module named story Awesome. I'm going to go stick my head through a wall. From aaron.hildebrandt at gmail.com Fri Feb 20 16:24:00 2009 From: aaron.hildebrandt at gmail.com (Aaron Scott) Date: Fri, 20 Feb 2009 13:24:00 -0800 (PST) Subject: Find the location of a loaded module References: <73f87180-7a68-4d50-952d-e966a3932690@s9g2000prg.googlegroups.com> <1d94d39d-1795-4111-b567-3263c1da569f@d32g2000yqe.googlegroups.com> <28aba044-d927-499b-8bd2-525870ae0267@j1g2000yqi.googlegroups.com> Message-ID: Son of a bitch. It gets worse. > Executed from inside 'act1', which contains the directory / module > 'story': > > ? ? ? ? directory = os.path.dirname(__file__) > ? ? ? ? req.write(str(directory)) > ? ? ? ? story = apache.import_module('story', path=[directory]) > > Results: > > /home/www/---/docs/act1 > > ? File "/home/www/---/docs/act1/play.py", line 24, in Rebuild > ? ? storylab = apache.import_module('story', path=[directory]) > > ? File "/usr/local/python2.5.2/lib/python2.5/site-packages/mod_python/ > importer.py", line 304, in import_module > ? ? return __import__(module_name, {}, {}, ['*']) > > ImportError: No module named story > If I execute the exact same code from the 'act1' directory after running it from the 'act2' directory, it successfully loads the 'story' module... from 'act2'. Even though I used the Apache importer to specify the EXACT LOCATION of the module to import. 'req.write(str(os.path.dirname(__file__)))' returns '/home/www/---/ docs/act1'. 'req.write(story.game.Save())' returns '/home/www/--/docs/act2/ storylab/game.pyc' as the file being accessed. BLOODY HELL. Okay, deep breath. Does anyone know what's going on? Am I just not understanding how module importing in mod_python works? I'd really appreciate help, since I'll be stuck at work today until I can get this sorted out, and I've long since run out of ideas. From aaron.hildebrandt at gmail.com Fri Feb 20 16:24:52 2009 From: aaron.hildebrandt at gmail.com (Aaron Scott) Date: Fri, 20 Feb 2009 13:24:52 -0800 (PST) Subject: Find the location of a loaded module References: e0b3b363-c14d-4708-99e7-60101a00bbfe@h5g2000yqh.googlegroups.com Message-ID: > > 'req.write(story.game.Save())' returns '/home/www/--/docs/act2/ > storylab/game.pyc' as the file being accessed. > Sorry, that should have read: > 'req.write(story.game.Save())' returns '/home/www/--/docs/act2/story/game.pyc' as the file being accessed. From tjreedy at udel.edu Fri Feb 20 16:26:55 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 20 Feb 2009 16:26:55 -0500 Subject: function factory question: embed current values of object attributes In-Reply-To: References: Message-ID: Alan Isaac wrote: > I have a class `X` where many parameters are set > at instance initialization. The parameter values > of an instance `x` generally remain unchanged, 'Parameters' are the function local names in the header that get bound to argument objects when the function is called. What you are describing are 'attributes'. > but is there way to communicate to a method that > it depends only on the initial values of these parameters > (and does not need to worry about any changes)? In the terms stated, no. > The behavior of method `m` depends on these parameter values. > It turns out `m` gets called a lot, which means > that the pameter values are accessed over and over > (self.p0, self.p1, etc). I would like to > manufacture a function equivalent to the method > that simply uses fixed values (the values at the > time it is manufactured). You are now describing a function closure. Here is an example that might help. def f_maker(a1, a2): def _(b): return a1*b + a2 return _ class C: def __init__(self, attr1, attr2): self.attr1 = attr1 self.attr2 = attr2 self.f = f_maker(attr1, attr2) c = C(2,3) print(*(c.f(i) for i in range(5))) # 3 5 7 9 11 Having f use both initial and 'current' attribute values would be a bit trickier ;-) Terry Jan Reedy From tjreedy at udel.edu Fri Feb 20 16:35:47 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 20 Feb 2009 16:35:47 -0500 Subject: What encoding does u'...' syntax use? In-Reply-To: References: Message-ID: Ron Garret wrote: > I would have thought that the answer would be: the default encoding > (duh!) But empirically this appears not to be the case: > >>>> unicode('\xb5') > Traceback (most recent call last): > File "", line 1, in > UnicodeDecodeError: 'ascii' codec can't decode byte 0xb5 in position 0: > ordinal not in range(128) The unicode function is usually used to decode bytes read from *external sources*, each of which can have its own encoding. So the function (actually, developer crew) refuses to guess and uses the ascii common subset. >>>> u'\xb5' > u'\xb5' >>>> print u'\xb5' > ? Unicode literals are *in the source file*, which can only have one encoding (for a given source file). > (That last character shows up as a micron sign despite the fact that my > default encoding is ascii, so it seems to me that that unicode string > must somehow have picked up a latin-1 encoding.) I think latin-1 was the default without a coding cookie line. (May be uft-8 in 3.0). From robert.kern at gmail.com Fri Feb 20 16:52:02 2009 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 20 Feb 2009 15:52:02 -0600 Subject: can multi-core improve single funciton? In-Reply-To: References: <6a4f17690902092228i31fd1661n41c61c4037a289df@mail.gmail.com> Message-ID: On 2009-02-20 13:20, Unknown wrote: > On 2009-02-20, Aahz wrote: >> Steven D'Aprano wrote: >> >>> As I understand it, there's very little benefit to multi-cores >>> in Python due to the GIL. >> As phrased, your statement is completely wrong. Here's a more >> correct phrasing: "For threaded compute-bound applications >> written in pure Python, there's very little benefit to >> multiple cores." But threaded I/O-bound applications do >> receive some benefit from multiple cores, and using multiple >> processes certainly leverages multiple cores. If boosting the >> performance of a threaded compute-bound application is >> important, one can always write the critical parts in C/C++. > > Do the crunchy bits of scipy/numpy, scientific python, vtk and > other compute-intensive libraries tend to release the GIL while > they're busy "computing"? Often. Not as often as they could, sometimes. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From steve at holdenweb.com Fri Feb 20 17:09:19 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 20 Feb 2009 17:09:19 -0500 Subject: cx_oracle -- how to insert "&" In-Reply-To: <1af94e53-7a85-46e9-bf33-7165c9f47c8b@q30g2000prq.googlegroups.com> References: <1af94e53-7a85-46e9-bf33-7165c9f47c8b@q30g2000prq.googlegroups.com> Message-ID: Allen wrote: > I am using Python with cx_oracle to load an excel spreadsheet into an > Oracle table. There are lots of text on the spreadsheet that have "&" > in them which I want to keep in the table. But inserting those text > will fail. Why do you say that? > Is there a work around for this? I can filter out the > failed insert statements and in SQLPLUS set define off to run those > statements, but it would be nice to insert "&" directly in PYTHON. > regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From andrew at acooke.org Fri Feb 20 17:18:13 2009 From: andrew at acooke.org (andrew cooke) Date: Fri, 20 Feb 2009 19:18:13 -0300 (CLST) Subject: code challenge: generate minimal expressions using only digits 1,2,3 Message-ID: from subsequent posts i think you were looking for something "smarter" than my streams, but i was interested in the idea, so i wrote an implementation. hope this is ok - if you don't want to see a worked solution, read no further... i have been using generators a lot recently; now that i understand them better i really like the "laziness" they give. this code is perhaps more like you would see in haskell than in python... some results from the code as below: -725 = (((1)+(1))+((1)+(1)))-(((1)+(2))^((2)*(3))) (length 8) ... -2 = (1)-(3) (length 2) -1 = (1)-(2) (length 2) 0 = (1)-(1) (length 2) 1 = 1 (length 1) 2 = 2 (length 1) 3 = 3 (length 1) 4 = (1)+(3) (length 2) ... 972 = (((1)+(1))+((1)+(1)))*(((1)+(2))^((2)+(3))) (length 8) note that because this is a brute-force search it is limited in the number of combinations it considers (for a given "take", below), and not at all "smart" (in preferring pow over other values for example), so the extreme values are nothing like optimal (the final invocation, commented out, uses sorting to improve things). also, complex and float values are generated; i discard those with a filter, but you can drop that if you are curious. #!/usr/bin/python3 ''' See http://groups.google.com/group/comp.lang.python/browse_thread/thread/b387f99deb376392 This is a brute force approach using streams, implemented with generators. ''' from operator import add, sub, mul, truediv as div, pow OPERATORS = [('+', add), ('-', sub), ('*', mul), ('/', div), ('^', pow)] START = [(str(i), 1, i) for i in [1,2,3]] def all_operators(stream): ''' Generate new values by combining the values in 'stream' in all the different ways possible. ''' for (exprn, length, value) in stream: for (symbol, op) in OPERATORS: for (exprn2, length2, value2) in stream: try: yield ('({0}){1}({2})'.format( exprn, symbol, exprn2), length + length2, op(value, value2)) except Exception as e: # print('Ignoring {}',format(e)) pass def repeat(generator, preproc=lambda x: x): ''' Make a generator 'eat its own tail', primed with 'start'. All output is kept and fed back into the generator as input. Note that memory use increases steadily. ''' def repeater(start): start = preproc(start) for value in start: yield value while True: finish = [] for value in generator(start): yield value finish.append(value) start = finish return repeater def value(elv): ''' Pick the value from an elv triplet. ''' (exprn, length, value) = elv return value def take(n): ''' Build a filter that takes the first n values from a stream. ''' def taker(stream, n=n): while n > 0: yield next(stream) n -= 1 return taker def mkfilter(predicate): ''' Curry Python's filter function. ''' def myfilter(stream): return filter(lambda elv: predicate(value(elv)), stream) return myfilter def compose(*filters): ''' Compose several filters to give a new filter. (Is there a better way to write this?) ''' def composer(iter1, iter2): def composed(stream): for value in iter1(iter2(stream)): yield value return composed if len(filters) == 1: return filters[0] else: return composer(filters[0], compose(*filters[1:])) def summarise(stream): ''' Group values by value, keeping the shortest expression, then print everything. ''' exprns = {} lengths = {} for (exprn, length, value) in stream: if value not in exprns or length < lengths[value]: exprns[value] = exprn lengths[value] = length values = [value for value in exprns if type(value) is int] for value in sorted(values): print('{0:>5} = {1:20} (length {2})'.format( value, exprns[value], lengths[value])) if __name__ == '__main__': ints = mkfilter(lambda x: type(x) is int) small = mkfilter(lambda x: abs(x) < 1000) # this gets very slow after 20000 values # summarise(compose(take(20000), # repeat(compose(ints, # all_operators)))(START)) # clipping values to below 1000 makes things much faster # note 200,000 below, 20,000 above! summarise(compose(take(200000), repeat(compose(ints, small, all_operators)))(START)) # get to larger values faster by sorting in the repeat # sort = lambda x: sorted(x, key=value, reverse=True) # summarise(compose(take(200000), # repeat(compose(ints, small, # all_operators), # preproc=sort))(START)) andrew cooke wrote: > > this is a neat problem. > > here is what i would do: use generators that extend an input. a stream approach. the initial input would be the numbers themselves. > > [('1', 1),('2', 2),('3', 3)] > > those are (expression, value) pairs > > then an initial attempt at the next function would be to extend that list > with additions: > > def additions(pairs): > for (expr1, value1) in pairs: > # first, pass through unchanged > yield (expr1, value1) > # then generate all possible additions > for (expr2, value2) in pairs: > yield ('%s+%s'%(value1, value2), value1 + value2)) > > this would give you: > > [('1', 1),('2', 2),('3', 3), ('1+1', 2), ...] > > (you may need to add parentheses to expressions to preserve meaning correctly) > > you could extend that with an extra loop over different operations. (subtraction, multiplication, etc) > > then you could repeat that as often as you want (eating its own tail, in a > sense, i think). an infinite list is ok because these are generators. > > then you could filter that to group expressions that give a certain value, > and find the shortest. > > andrew > > > > Trip Technician wrote: >> anyone interested in looking at the following problem. >> we are trying to express numbers as minimal expressions using only the digits one two and three, with conventional arithmetic. so for >> instance >> 33 = 2^(3+2)+1 = 3^3+(3*2) >> are both minimal, using 4 digits but >> 33 = ((3+2)*2+1)*3 >> using 5 is not. >> I have tried coding a function to return the minimal representation for any integer, but haven't cracked it so far. The naive first attempt is to generate lots of random strings, eval() them and sort by size and value. this is inelegant and slow. >> I have a dim intuition that it could be done with a very clever bit of recursion, but the exact form so far eludes me. >> -- >> http://mail.python.org/mailman/listinfo/python-list > > > -- > http://mail.python.org/mailman/listinfo/python-list > > From invalid at invalid Fri Feb 20 17:27:19 2009 From: invalid at invalid (Grant Edwards) Date: Fri, 20 Feb 2009 16:27:19 -0600 Subject: can multi-core improve single funciton? References: <6a4f17690902092228i31fd1661n41c61c4037a289df@mail.gmail.com> Message-ID: On 2009-02-20, Robert Kern wrote: > >> Do the crunchy bits of scipy/numpy, scientific python, vtk and >> other compute-intensive libraries tend to release the GIL >> while they're busy "computing"? > > Often. Not as often as they could, sometimes. On one hand, the upshot of that is that by finding an appropriate library module you might gain some of the same benefits as removing the GIL. On the other hand, that doesn't help if you're doing something original enough that nobody has written a library to handle large chunks of it. And on the grasping hand, I find that most of us vastly overestimate the originality of what we're doing. -- Grant Edwards grante Yow! This is a NO-FRILLS at flight -- hold th' CANADIAN visi.com BACON!! From callen314 at gmail.com Fri Feb 20 17:34:51 2009 From: callen314 at gmail.com (Craig Allen) Date: Fri, 20 Feb 2009 14:34:51 -0800 (PST) Subject: Threading and tkinter References: <492d5db9-3681-4ae8-827e-f2a4f66bee80@v39g2000yqm.googlegroups.com> <6ef2c1d5-d742-4d4c-b1b6-2e685b9ff758@c12g2000yqj.googlegroups.com> Message-ID: <3c42278a-9748-4f12-a876-da5802a55785@e18g2000yqo.googlegroups.com> > The statement > > ? ? x=x+1 > > (which, by the way, should stylistically be written > > ? ? x = x + 1 > yes I was wondering what "x=x+1" meant until you translated it... oh, "x = x + 1" of course! I thought to myself. Oh wait no I'm sarcastic. From dg.gmane at thesamovar.net Fri Feb 20 17:37:04 2009 From: dg.gmane at thesamovar.net (Dan Goodman) Date: Fri, 20 Feb 2009 23:37:04 +0100 Subject: code challenge: generate minimal expressions using only digits 1,2,3 In-Reply-To: <941be713-2789-48c7-911b-422313f232d5@o36g2000yqh.googlegroups.com> References: <941be713-2789-48c7-911b-422313f232d5@o36g2000yqh.googlegroups.com> Message-ID: This sounds kind of similar to a problem I posted to this list last year, you might find that thread gives you some ideas: http://mail.python.org/pipermail/python-list/2008-January/474071.html Dan From matthew at woodcraft.me.uk Fri Feb 20 17:43:13 2009 From: matthew at woodcraft.me.uk (Matthew Woodcraft) Date: Fri, 20 Feb 2009 22:43:13 GMT Subject: What encoding does u'...' syntax use? References: <499f18bd$0$31879$9b4e6d93@newsspool3.arcor-online.net> Message-ID: <87ab8gu3um.fsf@golux.woodcraft.me.uk> Ron Garret writes: > Put this another way: I would have thought that when the Python parser > parses "u'\xb5'" it would produce the same result as calling > unicode('\xb5'), but it doesn't. Instead it seems to produce the same > result as calling unicode('\xb5', 'latin-1'). But my default encoding > is not latin-1, it's ascii. So where is the Python parser getting its > encoding from? Why does parsing "u'\xb5'" not produce the same error > as calling unicode('\xb5')? There is no encoding involved other than ascii, only processing of a backslash escape. The backslash escape '\xb5' is converted to the unicode character whose ordinal number is B5h. This gives the same result as "\xb5".decode("latin-1") because the unicode numbering is the same as the 'latin-1' numbering in that range. -M- From aaron.hildebrandt at gmail.com Fri Feb 20 17:44:21 2009 From: aaron.hildebrandt at gmail.com (Aaron Scott) Date: Fri, 20 Feb 2009 14:44:21 -0800 (PST) Subject: Find the location of a loaded module References: e0b3b363-c14d-4708-99e7-60101a00bbfe@h5g2000yqh.googlegroups.com Message-ID: <5879412d-ffba-4fd9-82b7-7e798dc425e3@f3g2000yqf.googlegroups.com> And finally, an epilogue. So, the problem lies with how Python cached the modules in memory. Yes, the modules were in two different locations and yes, the one that I specified using its direct path should be the one loaded. The problem is, the module isn't always loaded -- if it's already in memory, it'll use that instead. And since the modules had the same name, Python wouldn't distinguish between them, even though they weren't exactly the same. So, loading the module act1/story would load act1/story. Then, loading the module act2/story would use the story module already in memory. Of course, this made the problem hard to pinpoint, since memory is a fickle thing, and the results weren't always reproducible. The final solution? Renaming the 'story' modules to 'story_1' and 'story_2'... and importing them via 'exec("from story_"+modulename+" import game")'. Will I go to hell for this 'solution'? Probably. But hey, it means I can go home tonight instead of spending all evening at the office hitting my head against the wall. I'll come back to it Monday and try to figure out a more reasonable solution. From martin at v.loewis.de Fri Feb 20 18:15:08 2009 From: martin at v.loewis.de (=?ISO-8859-15?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 21 Feb 2009 00:15:08 +0100 Subject: What encoding does u'...' syntax use? In-Reply-To: References: <499f18bd$0$31879$9b4e6d93@newsspool3.arcor-online.net> Message-ID: <499F397C.7030404@v.loewis.de> > Yes, I know that. But every concrete representation of a unicode string > has to have an encoding associated with it, including unicode strings > produced by the Python parser when it parses the ascii string "u'\xb5'" > > My question is: what is that encoding? The internal representation is either UTF-16, or UTF-32; which one is a compile-time choice (i.e. when the Python interpreter is built). > Put this another way: I would have thought that when the Python parser > parses "u'\xb5'" it would produce the same result as calling > unicode('\xb5'), but it doesn't. Right. In the former case, \xb5 denotes a Unicode character, namely U+00B5, MICRO SIGN. It is the same as u"\u00b5", and still the same as u"\N{MICRO SIGN}". By "the same", I mean "the very same". OTOH, unicode('\xb5') is something entirely different. '\xb5' is a byte string with length 1, with a single byte with the numeric value 0xb5, or 181. It does not, per se, denote any specific character. It only gets a character meaning when you try to decode it to unicode, which you do with unicode('\xb5'). This is short for unicode('\xb5', sys.getdefaultencoding()) and sys.getdefaultencoding() is (or should be) "ascii". Now, in ASCII, byte 0xb5 does not have a meaning (i.e. it does not denote a character at all), hence you get a UnicodeError. > Instead it seems to produce the same > result as calling unicode('\xb5', 'latin-1'). Sure. However, this is only by coincidence, because latin-1 has the same code points as Unicode (for 0..255). > But my default encoding > is not latin-1, it's ascii. So where is the Python parser getting its > encoding from? Why does parsing "u'\xb5'" not produce the same error as > calling unicode('\xb5')? Because \xb5 *directly* refers to character U+00b5, with no byte-oriented encoding in-between. Regards, Martin From brianlong at cox.net Fri Feb 20 18:15:31 2009 From: brianlong at cox.net (brianrpsgt1) Date: Fri, 20 Feb 2009 15:15:31 -0800 (PST) Subject: count secton of data in list Message-ID: I have a list of three columns of data. I run the following code: def step1(val): for d1r in data1_row: if d1r[1] >= val: switch = 0 data2_row = d1r[0],d1r[1],d1r[2],switch print d1r[0],d1r[1],d1r[2],switch else: switch = 1 print d1r[0],d1r[1],d1r[2],switch step1(95) After running that code I get four columns with either a '0' or '1' in the 4th column, as shown below 2009-01-09 13:17:30 96 123456 0 2009-01-09 13:17:31 95 123456 0 2009-01-09 13:17:32 95 123456 0 2009-01-09 13:17:33 95 123456 0 2009-01-09 13:17:34 94 123456 1 2009-01-09 13:17:35 94 123456 1 2009-01-09 13:17:36 94 123456 1 2009-01-09 13:17:37 94 123456 1 2009-01-09 13:17:38 94 123456 1 2009-01-09 13:17:39 94 123456 1 2009-01-09 13:17:40 94 123456 1 2009-01-09 13:17:41 94 123456 1 2009-01-09 13:17:42 95 123456 0 2009-01-09 13:17:43 95 123456 0 2009-01-09 13:17:44 95 123456 0 2009-01-09 13:17:45 95 123456 0 Where I am getting stuck is that I now need to get the individual counts for the various consecutive areas in the list where the values are '1'. I was trying to run a FOR Loop on the variable data2_row.... but that does not work. Any assistance would be great. Thanks: B From Scott.Daniels at Acm.Org Fri Feb 20 18:15:42 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 20 Feb 2009 15:15:42 -0800 Subject: Implementaion of random.shuffle In-Reply-To: References: <4e8b75a40707160510h25773f3ch749492cba2dc733@mail.gmail.com> <87d4ys9z46.fsf@mulj.homelinux.net> <1184787155.773575.303080@d30g2000prg.googlegroups.com> Message-ID: Steven D'Aprano wrote: > On Wed, 18 Jul 2007 19:32:35 +0000, George Sakkis wrote: >... >> Wow, can you make a coffee in.. 57ms ? > [snip demonstration of xrange raising an exception] > Of course! Can't you? > > And if I use a microwave oven, [*** deleted section outlining Guido's time machine structure ***] Steve, consider yourself warned!!! -- The PSU From martin at v.loewis.de Fri Feb 20 18:19:43 2009 From: martin at v.loewis.de (=?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=) Date: Sat, 21 Feb 2009 00:19:43 +0100 Subject: What encoding does u'...' syntax use? In-Reply-To: References: Message-ID: <499F3A8F.9010200@v.loewis.de> >>>>> u'\xb5' >> u'\xb5' >>>>> print u'\xb5' >> ? > > Unicode literals are *in the source file*, which can only have one > encoding (for a given source file). > >> (That last character shows up as a micron sign despite the fact that >> my default encoding is ascii, so it seems to me that that unicode >> string must somehow have picked up a latin-1 encoding.) > > I think latin-1 was the default without a coding cookie line. (May be > uft-8 in 3.0). It is, but that's irrelevant for the example. In the source u'\xb5' all characters are ASCII (i.e. all of "letter u", "single quote", "backslash", "letter x", "letter b", "digit 5"). As a consequence, this source text has the same meaning in all supported source encodings (as source encodings must be ASCII supersets). The Unicode literal shown here does not get its interpretation from Latin-1. Instead, it directly gets its interpretation from the Unicode coded character set. The string is a short-hand for u'\u00b5' and this denotes character U+00B5 (just as u'\u20ac" denotes U+20AC; the same holds for any other u'\uXXXX'). HTH, Martin From lionel.keene at gmail.com Fri Feb 20 18:33:14 2009 From: lionel.keene at gmail.com (Lionel) Date: Fri, 20 Feb 2009 15:33:14 -0800 (PST) Subject: "import" not working? Message-ID: Hello all: I've crafted several classes and exceptions which I've stored in a file called "DataFileType.py". I then invoke them from within other files like this: # Top of file import sys sys.path.append("c:\DataFileTypes") from DataFileTypes import * data = None try: # Note: "INTData" is a class defined in "DataFileTypes" data = INTData("C:\SomeRawDataFile.int") except DataFileError: print("Error opening data file") except ResourceFileError: print("Error opening resource file") The above works very well. No complaints. However, I'm experimenting with the wxPython gui library and found that this no longer seems to work when I add the crucial bits to one of their examples. I've copied and run an example that came with wxPython and verified that, with no modification on my part, it runs with no problem. I then add ONLY my import instructions and try to instantiate an object as follows (I'm only showing a portion of the file): #!/usr/bin/env python from numpy import arange, sin, pi import matplotlib matplotlib.use('WX') from matplotlib.backends.backend_wx import FigureCanvasWx as FigureCanvas from matplotlib.figure import Figure from wx import * # The following 4 lines are my additions to the example code: import sys sys.path.append("c:\DataFileTypes") from DataFileTypes import * data = INTData("C:\SomeRawDataFile.int") class CanvasFrame(Frame): . . etc . . Running the above program (which I've called "guiplottest.py") generates an immediate error with the following traceback: C:\Guiplottest.py Traceback : File "C:\GuiPlotTest.py", line 19, in data = INTData("C:\SomeRawDataFile.int") NameError: name 'INTData' is not defined But "INTData" is defined...it's defined in "DataFileTypes" from which I've imported everything. What's happening here? Thanks in advance! -L From emile at fenx.com Fri Feb 20 18:45:53 2009 From: emile at fenx.com (Emile van Sebille) Date: Fri, 20 Feb 2009 15:45:53 -0800 Subject: count secton of data in list In-Reply-To: References: Message-ID: brianrpsgt1 wrote: > > def step1(val): data2_row = [] > for d1r in data1_row: > if d1r[1] >= val: > switch = 0 > data2_row = d1r[0],d1r[1],d1r[2],switch data2_row.append([d1r[0],d1r[1],d1r[2],switch]) HTH, Emile From emile at fenx.com Fri Feb 20 18:48:54 2009 From: emile at fenx.com (Emile van Sebille) Date: Fri, 20 Feb 2009 15:48:54 -0800 Subject: "import" not working? In-Reply-To: References: Message-ID: Lionel wrote: > from DataFileTypes import * That's an import where you don't know what's getting import'd -- ie, namespace pollution [snip] > from wx import * > and more here. Try being explicit with your naming. HTH, Emile From clp2 at rebertia.com Fri Feb 20 18:52:10 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 20 Feb 2009 15:52:10 -0800 Subject: "import" not working? In-Reply-To: References: Message-ID: <50697b2c0902201552q20c9a682y55b5c40f801e96a2@mail.gmail.com> On Fri, Feb 20, 2009 at 3:33 PM, Lionel wrote: > Hello all: > > I've crafted several classes and exceptions which I've stored in a > file called "DataFileType.py". I then invoke them from within other > files like this: > > > # Top of file > > import sys > sys.path.append("c:\DataFileTypes") Recall that the backslash is the escape character in Python and that therefore you need to put \\ to get a backslash in the resulting path string. Thus, the path you think you're adding isn't the path that's getting added. Alternatively, you can just use forward slashes instead (yes, that works on Windows from Python). Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From lionel.keene at gmail.com Fri Feb 20 18:56:25 2009 From: lionel.keene at gmail.com (Lionel) Date: Fri, 20 Feb 2009 15:56:25 -0800 (PST) Subject: "import" not working? References: Message-ID: <7f0d1540-ae7e-4da1-936e-afbc8c6d2d49@k19g2000yqg.googlegroups.com> On Feb 20, 3:52?pm, Chris Rebert wrote: > On Fri, Feb 20, 2009 at 3:33 PM, Lionel wrote: > > Hello all: > > > I've crafted several classes and exceptions which I've stored in a > > file called "DataFileType.py". I then invoke them from within other > > files like this: > > > # Top of file > > > import sys > > sys.path.append("c:\DataFileTypes") > > Recall that the backslash is the escape character in Python and that > therefore you need to put \\ to get a backslash in the resulting path > string. Thus, the path you think you're adding isn't the path that's > getting added. > Alternatively, you can just use forward slashes instead (yes, that > works on Windows from Python). > > Cheers, > Chris > > -- > Follow the path of the Iguana...http://rebertia.com But I'm only using a single backslash in the first example I gave, and it works just fine there. How can this be? From rNOSPAMon at flownet.com Fri Feb 20 19:10:15 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Fri, 20 Feb 2009 16:10:15 -0800 Subject: What encoding does u'...' syntax use? References: <499F3A8F.9010200@v.loewis.de> Message-ID: In article <499F3A8F.9010200 at v.loewis.de>, "Martin v. L?wis" wrote: > >>>>> u'\xb5' > >> u'\xb5' > >>>>> print u'\xb5' > >> ? > > > > Unicode literals are *in the source file*, which can only have one > > encoding (for a given source file). > > > >> (That last character shows up as a micron sign despite the fact that > >> my default encoding is ascii, so it seems to me that that unicode > >> string must somehow have picked up a latin-1 encoding.) > > > > I think latin-1 was the default without a coding cookie line. (May be > > uft-8 in 3.0). > > It is, but that's irrelevant for the example. In the source > > u'\xb5' > > all characters are ASCII (i.e. all of "letter u", "single > quote", "backslash", "letter x", "letter b", "digit 5"). > As a consequence, this source text has the same meaning in all > supported source encodings (as source encodings must be ASCII > supersets). > > The Unicode literal shown here does not get its interpretation > from Latin-1. Instead, it directly gets its interpretation from > the Unicode coded character set. The string is a short-hand > for > > u'\u00b5' > > and this denotes character U+00B5 (just as u'\u20ac" denotes > U+20AC; the same holds for any other u'\uXXXX'). > > HTH, > Martin Ah, that makes sense. Thanks! rg From rNOSPAMon at flownet.com Fri Feb 20 19:10:51 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Fri, 20 Feb 2009 16:10:51 -0800 Subject: What encoding does u'...' syntax use? References: <499f18bd$0$31879$9b4e6d93@newsspool3.arcor-online.net> <499F397C.7030404@v.loewis.de> Message-ID: In article <499F397C.7030404 at v.loewis.de>, "Martin v. L?wis" wrote: > > Yes, I know that. But every concrete representation of a unicode string > > has to have an encoding associated with it, including unicode strings > > produced by the Python parser when it parses the ascii string "u'\xb5'" > > > > My question is: what is that encoding? > > The internal representation is either UTF-16, or UTF-32; which one is > a compile-time choice (i.e. when the Python interpreter is built). > > > Put this another way: I would have thought that when the Python parser > > parses "u'\xb5'" it would produce the same result as calling > > unicode('\xb5'), but it doesn't. > > Right. In the former case, \xb5 denotes a Unicode character, namely > U+00B5, MICRO SIGN. It is the same as u"\u00b5", and still the same > as u"\N{MICRO SIGN}". By "the same", I mean "the very same". > > OTOH, unicode('\xb5') is something entirely different. '\xb5' is a > byte string with length 1, with a single byte with the numeric > value 0xb5, or 181. It does not, per se, denote any specific character. > It only gets a character meaning when you try to decode it to unicode, > which you do with unicode('\xb5'). This is short for > > unicode('\xb5', sys.getdefaultencoding()) > > and sys.getdefaultencoding() is (or should be) "ascii". Now, in > ASCII, byte 0xb5 does not have a meaning (i.e. it does not denote > a character at all), hence you get a UnicodeError. > > > Instead it seems to produce the same > > result as calling unicode('\xb5', 'latin-1'). > > Sure. However, this is only by coincidence, because latin-1 has the same > code points as Unicode (for 0..255). > > > But my default encoding > > is not latin-1, it's ascii. So where is the Python parser getting its > > encoding from? Why does parsing "u'\xb5'" not produce the same error as > > calling unicode('\xb5')? > > Because \xb5 *directly* refers to character U+00b5, with no > byte-oriented encoding in-between. > > Regards, > Martin OK, I think I get it now. Thanks! rg From mkhitrov at gmail.com Fri Feb 20 19:14:57 2009 From: mkhitrov at gmail.com (Maxim Khitrov) Date: Fri, 20 Feb 2009 19:14:57 -0500 Subject: Using clock() in threading on Windows Message-ID: <26ddd1750902201614h2f692e0br7b1ae44f3566f8b4@mail.gmail.com> Greetings, The threading module uses time.time in _Condition and _Thread classes to implement timeouts. On Windows, time() typically has a resolution of 15.625ms. In addition, if the system clock is changed (though ntp, for example) it would reflect that change, causing the timeout to last longer or shorter depending on which way the update went. Would it not be better to use time.clock() instead? The resolution is much better, and the value is not linked to system clock. Right now, I replace the threading._time reference with clock in some of my programs and everything works perfectly. Condition and Event timeouts are precise down to the millisecond (resolution of the sleep function), and I see no side-effects. Is it possible to make that change part of the module itself (keeping time() for linux systems), or can someone think of a reason why using clock is a bad idea? I know that it's using QueryPerformanceCounter for implementation, which has some known issues, but I still think that the advantages outweigh potential faults. - Max From mccredie at gmail.com Fri Feb 20 19:15:59 2009 From: mccredie at gmail.com (Matimus) Date: Fri, 20 Feb 2009 16:15:59 -0800 (PST) Subject: "import" not working? References: <7f0d1540-ae7e-4da1-936e-afbc8c6d2d49@k19g2000yqg.googlegroups.com> Message-ID: <11062739-5a43-43d8-b4a2-9bd494230992@t13g2000yqc.googlegroups.com> On Feb 20, 3:56?pm, Lionel wrote: > On Feb 20, 3:52?pm, Chris Rebert wrote: > > > > > On Fri, Feb 20, 2009 at 3:33 PM, Lionel wrote: > > > Hello all: > > > > I've crafted several classes and exceptions which I've stored in a > > > file called "DataFileType.py". I then invoke them from within other > > > files like this: > > > > # Top of file > > > > import sys > > > sys.path.append("c:\DataFileTypes") > > > Recall that the backslash is the escape character in Python and that > > therefore you need to put \\ to get a backslash in the resulting path > > string. Thus, the path you think you're adding isn't the path that's > > getting added. > > Alternatively, you can just use forward slashes instead (yes, that > > works on Windows from Python). > > > Cheers, > > Chris > > > -- > > Follow the path of the Iguana...http://rebertia.com > > But I'm only using a single backslash in the first example I gave, and > it works just fine there. How can this be? You must be running the python script from a directory where the file you are trying to import is already in the path. It never tries to look in the (bad) path because it found a file with the same name locally. My guess is that you are running the wx example from another location, and that is when you run into problems. Matt From steve at holdenweb.com Fri Feb 20 19:32:36 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 20 Feb 2009 19:32:36 -0500 Subject: "import" not working? In-Reply-To: <50697b2c0902201552q20c9a682y55b5c40f801e96a2@mail.gmail.com> References: <50697b2c0902201552q20c9a682y55b5c40f801e96a2@mail.gmail.com> Message-ID: Chris Rebert wrote: > On Fri, Feb 20, 2009 at 3:33 PM, Lionel wrote: >> Hello all: >> >> I've crafted several classes and exceptions which I've stored in a >> file called "DataFileType.py". I then invoke them from within other >> files like this: >> >> >> # Top of file >> >> import sys >> sys.path.append("c:\DataFileTypes") > > Recall that the backslash is the escape character in Python and that > therefore you need to put \\ to get a backslash in the resulting path > string. Thus, the path you think you're adding isn't the path that's > getting added. > Alternatively, you can just use forward slashes instead (yes, that > works on Windows from Python). > In fact "\D" isn't a defined escape character, so this particular usage does give the right path, though your general point is good. >>> "\D" '\\D' >>> len("\D") 2 regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From lionel.keene at gmail.com Fri Feb 20 19:40:03 2009 From: lionel.keene at gmail.com (Lionel) Date: Fri, 20 Feb 2009 16:40:03 -0800 (PST) Subject: "import" not working? References: <7f0d1540-ae7e-4da1-936e-afbc8c6d2d49@k19g2000yqg.googlegroups.com> <11062739-5a43-43d8-b4a2-9bd494230992@t13g2000yqc.googlegroups.com> Message-ID: <65f8a016-a4c1-48c0-8128-47f62b865a6f@m40g2000yqh.googlegroups.com> On Feb 20, 4:15?pm, Matimus wrote: > On Feb 20, 3:56?pm, Lionel wrote: > > > > > > > On Feb 20, 3:52?pm, Chris Rebert wrote: > > > > On Fri, Feb 20, 2009 at 3:33 PM, Lionel wrote: > > > > Hello all: > > > > > I've crafted several classes and exceptions which I've stored in a > > > > file called "DataFileType.py". I then invoke them from within other > > > > files like this: > > > > > # Top of file > > > > > import sys > > > > sys.path.append("c:\DataFileTypes") > > > > Recall that the backslash is the escape character in Python and that > > > therefore you need to put \\ to get a backslash in the resulting path > > > string. Thus, the path you think you're adding isn't the path that's > > > getting added. > > > Alternatively, you can just use forward slashes instead (yes, that > > > works on Windows from Python). > > > > Cheers, > > > Chris > > > > -- > > > Follow the path of the Iguana...http://rebertia.com > > > But I'm only using a single backslash in the first example I gave, and > > it works just fine there. How can this be? > > You must be running the python script from a directory where the file > you are trying to import is already in the path. It never tries to > look in the (bad) path because it found a file with the same name > locally. My guess is that you are running the wx example from another > location, and that is when you run into problems. > > Matt- Hide quoted text - > > - Show quoted text - Okay, moving the wx example into the same directory containing the first example that was working fixed it. This directory only contains these two modules and nothing else. The old directory which contained the example that wasn't working did not contain a module with the same name as the one I was trying to import, so i don't know why this "fix" worked. From kevinosky at gmail.com Fri Feb 20 19:52:43 2009 From: kevinosky at gmail.com (kevin hayes) Date: Fri, 20 Feb 2009 16:52:43 -0800 Subject: Python won't run Message-ID: <37c2b0840902201652m118c1661s6eebe110f1b41fdf@mail.gmail.com> Hi, I had python 2.5 installed on my Mac osx 10.4.11 and idle stopped opening and running after I ran a few programs. I installed python 2.6 hoping this would allow me to open idle and start learning to program. How do I get Idle running again? -------------- next part -------------- An HTML attachment was scrubbed... URL: From sjmachin at lexicon.net Fri Feb 20 20:00:45 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 20 Feb 2009 17:00:45 -0800 (PST) Subject: cx_oracle -- how to insert "&" References: 1af94e53-7a85-46e9-bf33-7165c9f47c8b@q30g2000prq.googlegroups.com Message-ID: <04fcf9b4-d496-4585-a63e-d76086fd1cc3@t11g2000yqg.googlegroups.com> On Feb 21, 3:46?am, Allen wrote: > I am using Python with cx_oracle to load an excel spreadsheet into an > Oracle table. There are lots of text on the spreadsheet that have "&" > in them which I want to keep in the table. But inserting those text > will fail. "Will fail" (future tense) or have failed (past tense)?? > Is there a work around for this? I can filter out the > failed insert statements and in SQLPLUS set define off ?to run those > statements, but it would be nice to insert "&" directly in PYTHON. > We don't have crystal balls. More information please: 1. How are you digging the data out of the spreadsheet? 2. What does print repr(text_on_the_spreadsheet) show for the failing cases? 3. Show us your code for inserting. 4. What is the failure message? 5. What does "set define off" do for you in SQLPLUS? From clp2 at rebertia.com Fri Feb 20 20:03:07 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 20 Feb 2009 17:03:07 -0800 Subject: Python won't run In-Reply-To: <37c2b0840902201652m118c1661s6eebe110f1b41fdf@mail.gmail.com> References: <37c2b0840902201652m118c1661s6eebe110f1b41fdf@mail.gmail.com> Message-ID: <50697b2c0902201703x79b6635dw60e7956d8500731a@mail.gmail.com> On Fri, Feb 20, 2009 at 4:52 PM, kevin hayes wrote: > Hi, I had python 2.5 installed on my Mac osx 10.4.11 and idle stopped > opening and running after I ran a few programs. I installed python 2.6 > hoping this would allow me to open idle and start learning to program. How > do I get Idle running again? What error do you get when trying to run it from the command line? Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From dsdale24 at gmail.com Fri Feb 20 20:12:01 2009 From: dsdale24 at gmail.com (Darren Dale) Date: Fri, 20 Feb 2009 17:12:01 -0800 (PST) Subject: how to assert that method accepts specific types Message-ID: <3f26a2f1-94cf-4083-9bda-7076959ad784@k19g2000yqg.googlegroups.com> I would like to assert that a method accepts certain types. I have a short example that works: from functools import wraps def accepts(*types): def check_accepts(f): @wraps(f) def new_f(self, other): assert isinstance(other, types), \ "arg %r does not match %s" % (other, types) return f(self, other) return new_f return check_accepts class Test(object): @accepts(int) def check(self, obj): print obj t = Test() t.check(1) but now I want Test.check to accept an instance of Test as well. Does anyone know how this can be accomplished? The following class definition for Test raises a NameError: class Test(object): @accepts(int, Test) def check(self, obj): print obj Thanks, Darren From clp2 at rebertia.com Fri Feb 20 20:20:02 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 20 Feb 2009 17:20:02 -0800 Subject: how to assert that method accepts specific types In-Reply-To: <3f26a2f1-94cf-4083-9bda-7076959ad784@k19g2000yqg.googlegroups.com> References: <3f26a2f1-94cf-4083-9bda-7076959ad784@k19g2000yqg.googlegroups.com> Message-ID: <50697b2c0902201720v495e62fen590ca3b564866f40@mail.gmail.com> On Fri, Feb 20, 2009 at 5:12 PM, Darren Dale wrote: > I would like to assert that a method accepts certain types. I have a > short example that works: > > from functools import wraps > > def accepts(*types): > def check_accepts(f): > @wraps(f) > def new_f(self, other): > assert isinstance(other, types), \ > "arg %r does not match %s" % (other, types) > return f(self, other) > return new_f > return check_accepts > > class Test(object): > > @accepts(int) > def check(self, obj): > print obj > > t = Test() > t.check(1) > > but now I want Test.check to accept an instance of Test as well. Does > anyone know how this can be accomplished? The following class > definition for Test raises a NameError: > > class Test(object): > > @accepts(int, Test) > def check(self, obj): > print obj You're going to have to either inject it after the class definition somehow, or give the class name as a string and use eval() or similar. The class object doesn't exist until the entire class body has finished executing, so you can't refer to the class within its own body. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From clp2 at rebertia.com Fri Feb 20 20:28:19 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 20 Feb 2009 17:28:19 -0800 Subject: Python won't run In-Reply-To: <37c2b0840902201724h51e949fbpb49f99c3521ed32d@mail.gmail.com> References: <37c2b0840902201652m118c1661s6eebe110f1b41fdf@mail.gmail.com> <50697b2c0902201703x79b6635dw60e7956d8500731a@mail.gmail.com> <37c2b0840902201716y6d072720m18b64d7734e65b18@mail.gmail.com> <50697b2c0902201720j2025ee3pad92c2600c912fb8@mail.gmail.com> <37c2b0840902201724h51e949fbpb49f99c3521ed32d@mail.gmail.com> Message-ID: <50697b2c0902201728k50076bdard53da0f567f2c65e@mail.gmail.com> How were you running IDLE previously? - Chris On Fri, Feb 20, 2009 at 5:24 PM, kevin hayes wrote: > how do i do that? > > On Fri, Feb 20, 2009 at 5:20 PM, Chris Rebert wrote: >> >> I meant, what happens when you run *IDLE* from the command line? >> >> - Chris >> >> On Fri, Feb 20, 2009 at 5:16 PM, kevin hayes wrote: >> > When I type "python" into terminal I get >>> but I would like to be able >> > to >> > open it as I would any application. Thanks. >> > >> > On Fri, Feb 20, 2009 at 5:03 PM, Chris Rebert wrote: >> >> >> >> On Fri, Feb 20, 2009 at 4:52 PM, kevin hayes >> >> wrote: >> >> > Hi, I had python 2.5 installed on my Mac osx 10.4.11 and idle stopped >> >> > opening and running after I ran a few programs. I installed python >> >> > 2.6 >> >> > hoping this would allow me to open idle and start learning to >> >> > program. >> >> > How >> >> > do I get Idle running again? >> >> >> >> What error do you get when trying to run it from the command line? >> >> >> >> Cheers, >> >> Chris >> >> >> >> -- >> >> Follow the path of the Iguana... >> >> http://rebertia.com From tjreedy at udel.edu Fri Feb 20 20:38:39 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 20 Feb 2009 20:38:39 -0500 Subject: What encoding does u'...' syntax use? In-Reply-To: <499F3A8F.9010200@v.loewis.de> References: <499F3A8F.9010200@v.loewis.de> Message-ID: Martin v. L?wis wrote: mehow have picked up a latin-1 encoding.) >> I think latin-1 was the default without a coding cookie line. (May be >> uft-8 in 3.0). > > It is, but that's irrelevant for the example. In the source > > u'\xb5' > > all characters are ASCII (i.e. all of "letter u", "single > quote", "backslash", "letter x", "letter b", "digit 5"). > As a consequence, this source text has the same meaning in all > supported source encodings (as source encodings must be ASCII > supersets). I think I understand now that the coding cookie only matters if I use an editor that actually stores *non-ascii* bytes in the file for the Python parser to interpret. From clp2 at rebertia.com Fri Feb 20 20:41:57 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 20 Feb 2009 17:41:57 -0800 Subject: Python won't run In-Reply-To: <37c2b0840902201734n708e7d6ds349d7b4ad7af1b2d@mail.gmail.com> References: <37c2b0840902201652m118c1661s6eebe110f1b41fdf@mail.gmail.com> <50697b2c0902201703x79b6635dw60e7956d8500731a@mail.gmail.com> <37c2b0840902201716y6d072720m18b64d7734e65b18@mail.gmail.com> <50697b2c0902201720j2025ee3pad92c2600c912fb8@mail.gmail.com> <37c2b0840902201724h51e949fbpb49f99c3521ed32d@mail.gmail.com> <50697b2c0902201728k50076bdard53da0f567f2c65e@mail.gmail.com> <37c2b0840902201734n708e7d6ds349d7b4ad7af1b2d@mail.gmail.com> Message-ID: <50697b2c0902201741x46ebbe07ge4fbac1e3f7fee4b@mail.gmail.com> Hmm. How did you install Python/IDLE? Also, please use Reply-All as others on the list might have helpful ideas. - Chris On Fri, Feb 20, 2009 at 5:34 PM, kevin hayes wrote: > I was clicking on the application. then the idle/python icon would bounce > in my > dock and then disappear. > On Fri, Feb 20, 2009 at 5:28 PM, Chris Rebert wrote: >> >> How were you running IDLE previously? >> >> - Chris >> >> On Fri, Feb 20, 2009 at 5:24 PM, kevin hayes wrote: >> > how do i do that? >> > >> > On Fri, Feb 20, 2009 at 5:20 PM, Chris Rebert wrote: >> >> >> >> I meant, what happens when you run *IDLE* from the command line? >> >> >> >> - Chris >> >> >> >> On Fri, Feb 20, 2009 at 5:16 PM, kevin hayes >> >> wrote: >> >> > When I type "python" into terminal I get >>> but I would like to be >> >> > able >> >> > to >> >> > open it as I would any application. Thanks. >> >> > >> >> > On Fri, Feb 20, 2009 at 5:03 PM, Chris Rebert >> >> > wrote: >> >> >> >> >> >> On Fri, Feb 20, 2009 at 4:52 PM, kevin hayes >> >> >> wrote: >> >> >> > Hi, I had python 2.5 installed on my Mac osx 10.4.11 and idle >> >> >> > stopped >> >> >> > opening and running after I ran a few programs. I installed >> >> >> > python >> >> >> > 2.6 >> >> >> > hoping this would allow me to open idle and start learning to >> >> >> > program. >> >> >> > How >> >> >> > do I get Idle running again? >> >> >> >> >> >> What error do you get when trying to run it from the command line? >> >> >> >> >> >> Cheers, >> >> >> Chris >> >> >> >> >> >> -- >> >> >> Follow the path of the Iguana... >> >> >> http://rebertia.com From dsdale24 at gmail.com Fri Feb 20 20:43:46 2009 From: dsdale24 at gmail.com (Darren Dale) Date: Fri, 20 Feb 2009 17:43:46 -0800 (PST) Subject: how to assert that method accepts specific types References: <3f26a2f1-94cf-4083-9bda-7076959ad784@k19g2000yqg.googlegroups.com> Message-ID: <72d00e6a-cc14-4b59-9f41-a1adbe7e9ca8@x10g2000yqk.googlegroups.com> On Feb 20, 8:20?pm, Chris Rebert wrote: > On Fri, Feb 20, 2009 at 5:12 PM, Darren Dale wrote: > > I would like to assert that a method accepts certain types. I have a > > short example that works: > > > from functools import wraps > > > def accepts(*types): > > ? ?def check_accepts(f): > > ? ? ? ?@wraps(f) > > ? ? ? ?def new_f(self, other): > > ? ? ? ? ? ?assert isinstance(other, types), \ > > ? ? ? ? ? ? ? ?"arg %r does not match %s" % (other, types) > > ? ? ? ? ? ?return f(self, other) > > ? ? ? ?return new_f > > ? ?return check_accepts > > > class Test(object): > > > ? ?@accepts(int) > > ? ?def check(self, obj): > > ? ? ? ?print obj > > > t = Test() > > t.check(1) > > > but now I want Test.check to accept an instance of Test as well. Does > > anyone know how this can be accomplished? The following class > > definition for Test raises a NameError: > > > class Test(object): > > > ? ?@accepts(int, Test) > > ? ?def check(self, obj): > > ? ? ? ?print obj > > You're going to have to either inject it after the class definition > somehow, or give the class name as a string and use eval() or similar. > The class object doesn't exist until the entire class body has > finished executing, so you can't refer to the class within its own > body. Thats too bad, thanks for clarifying. From tjreedy at udel.edu Fri Feb 20 20:48:37 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 20 Feb 2009 20:48:37 -0500 Subject: how to assert that method accepts specific types In-Reply-To: <3f26a2f1-94cf-4083-9bda-7076959ad784@k19g2000yqg.googlegroups.com> References: <3f26a2f1-94cf-4083-9bda-7076959ad784@k19g2000yqg.googlegroups.com> Message-ID: Darren Dale wrote: > I would like to assert that a method accepts certain types. I have a > short example that works: > > from functools import wraps > > def accepts(*types): > def check_accepts(f): > @wraps(f) > def new_f(self, other): > assert isinstance(other, types), \ > "arg %r does not match %s" % (other, types) > return f(self, other) > return new_f > return check_accepts > > class Test(object): > > @accepts(int) > def check(self, obj): > print obj > > t = Test() > t.check(1) > > but now I want Test.check to accept an instance of Test as well. Does > anyone know how this can be accomplished? The following class > definition for Test raises a NameError: > > class Test(object): > > @accepts(int, Test) > def check(self, obj): > print obj Because Test does not exist at the time the function is compiled. Remove '@accepts...' and put Test.check = accepts(int, Test)(Test.check) after the class definition and it should work. tjr From andrew at acooke.org Fri Feb 20 20:50:27 2009 From: andrew at acooke.org (andrew cooke) Date: Fri, 20 Feb 2009 22:50:27 -0300 (CLST) Subject: how to assert that method accepts specific types In-Reply-To: <3f26a2f1-94cf-4083-9bda-7076959ad784@k19g2000yqg.googlegroups.com> References: <3f26a2f1-94cf-4083-9bda-7076959ad784@k19g2000yqg.googlegroups.com> Message-ID: <7c51ecbf8a5d5accbd4184216e51ba97.squirrel@acooke.dyndns.org> Darren Dale wrote: > I would like to assert that a method accepts certain types. I have a > short example that works: just in case it's useful - are you aware that pep3107 (which looks like it should be leet-speak for something) is implemented in python 3? http://www.python.org/dev/peps/pep-3107/ andrew From kevinosky at gmail.com Fri Feb 20 20:51:37 2009 From: kevinosky at gmail.com (kevin hayes) Date: Fri, 20 Feb 2009 17:51:37 -0800 Subject: Python won't run In-Reply-To: <50697b2c0902201741x46ebbe07ge4fbac1e3f7fee4b@mail.gmail.com> References: <37c2b0840902201652m118c1661s6eebe110f1b41fdf@mail.gmail.com> <50697b2c0902201703x79b6635dw60e7956d8500731a@mail.gmail.com> <37c2b0840902201716y6d072720m18b64d7734e65b18@mail.gmail.com> <50697b2c0902201720j2025ee3pad92c2600c912fb8@mail.gmail.com> <37c2b0840902201724h51e949fbpb49f99c3521ed32d@mail.gmail.com> <50697b2c0902201728k50076bdard53da0f567f2c65e@mail.gmail.com> <37c2b0840902201734n708e7d6ds349d7b4ad7af1b2d@mail.gmail.com> <50697b2c0902201741x46ebbe07ge4fbac1e3f7fee4b@mail.gmail.com> Message-ID: <37c2b0840902201751q5ac4b607n14c90ee0b51c1c00@mail.gmail.com> I installed it...with the package that came with python 2.6. When I had 2.5 I was using it(idle) successfully, until I ran a few programs that I got off the web. Then, Idle wouldn't open (it just bounced in the dock and then disappeared). So I tried installing 2.6 and the same thing happened. On Fri, Feb 20, 2009 at 5:41 PM, Chris Rebert wrote: > Hmm. How did you install Python/IDLE? > Also, please use Reply-All as others on the list might have helpful ideas. > > - Chris > > On Fri, Feb 20, 2009 at 5:34 PM, kevin hayes wrote: > > I was clicking on the application. then the idle/python icon would > bounce > > in my > > dock and then disappear. > > On Fri, Feb 20, 2009 at 5:28 PM, Chris Rebert wrote: > >> > >> How were you running IDLE previously? > >> > >> - Chris > >> > >> On Fri, Feb 20, 2009 at 5:24 PM, kevin hayes > wrote: > >> > how do i do that? > >> > > >> > On Fri, Feb 20, 2009 at 5:20 PM, Chris Rebert > wrote: > >> >> > >> >> I meant, what happens when you run *IDLE* from the command line? > >> >> > >> >> - Chris > >> >> > >> >> On Fri, Feb 20, 2009 at 5:16 PM, kevin hayes > >> >> wrote: > >> >> > When I type "python" into terminal I get >>> but I would like to be > >> >> > able > >> >> > to > >> >> > open it as I would any application. Thanks. > >> >> > > >> >> > On Fri, Feb 20, 2009 at 5:03 PM, Chris Rebert > >> >> > wrote: > >> >> >> > >> >> >> On Fri, Feb 20, 2009 at 4:52 PM, kevin hayes > > >> >> >> wrote: > >> >> >> > Hi, I had python 2.5 installed on my Mac osx 10.4.11 and idle > >> >> >> > stopped > >> >> >> > opening and running after I ran a few programs. I installed > >> >> >> > python > >> >> >> > 2.6 > >> >> >> > hoping this would allow me to open idle and start learning to > >> >> >> > program. > >> >> >> > How > >> >> >> > do I get Idle running again? > >> >> >> > >> >> >> What error do you get when trying to run it from the command line? > >> >> >> > >> >> >> Cheers, > >> >> >> Chris > >> >> >> > >> >> >> -- > >> >> >> Follow the path of the Iguana... > >> >> >> http://rebertia.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at cheimes.de Fri Feb 20 20:56:36 2009 From: lists at cheimes.de (Christian Heimes) Date: Sat, 21 Feb 2009 02:56:36 +0100 Subject: Using clock() in threading on Windows In-Reply-To: <26ddd1750902201614h2f692e0br7b1ae44f3566f8b4@mail.gmail.com> References: <26ddd1750902201614h2f692e0br7b1ae44f3566f8b4@mail.gmail.com> Message-ID: Maxim Khitrov wrote: > The threading module uses time.time in _Condition and _Thread classes > to implement timeouts. On Windows, time() typically has a resolution > of 15.625ms. In addition, if the system clock is changed (though ntp, > for example) it would reflect that change, causing the timeout to last > longer or shorter depending on which way the update went. > > Would it not be better to use time.clock() instead? The resolution is > much better, and the value is not linked to system clock. Right now, I > replace the threading._time reference with clock in some of my > programs and everything works perfectly. Condition and Event timeouts > are precise down to the millisecond (resolution of the sleep > function), and I see no side-effects. > > Is it possible to make that change part of the module itself (keeping > time() for linux systems), or can someone think of a reason why using > clock is a bad idea? I know that it's using QueryPerformanceCounter > for implementation, which has some known issues, but I still think > that the advantages outweigh potential faults. Can you make a feature request? Your proposal seems sensible. A trivial patch should solve the issue: from time import sleep as _sleep if _sys.name == "win32": from time import clock as _time else: from time import time as _time However I'm not sure about the implications. Christian From evert.rol at gmail.com Fri Feb 20 21:01:19 2009 From: evert.rol at gmail.com (Evert Rol) Date: Sat, 21 Feb 2009 03:01:19 +0100 Subject: Framework installation of 2.6 on OS X, with specified prefix In-Reply-To: References: Message-ID: <1D24E2A3-0456-49BE-ABD6-E0B706C5EC09@gmail.com> On 20 Feb 2009, at 21:48 , Ned Deily wrote: > In article , > Evert Rol wrote: >> I'm trying to install Python 2.6 from source on Mac OS X.5, in its >> own >> directory using a framework install. That goes fine, up to the point >> where it wants to install the applications that come with it (eg, the >> Wish shell): it tries to install things into /Applications, instead >> of >> eg /Applications. >> Here's my configure line (the flags are there just to let it find my >> own installed readline): >> >> CPPFLAGS=-I/sw/include LDFLAGS=-L/sw/lib ./configure --prefix=/sw -- >> enable-shared --enable-framework=/sw/Library/Frameworks --with- >> readline=/sw --with-pth CC=gcc-4.2 MACOSX_DEPLOYMENT_TARGET=10.5 >> >> >> And the last part of the output of 'make install': >> >> ../python.exe ./scripts/BuildApplet.py \ >> --destroot "" \ >> --python=/sw/Library/Frameworks/Python.framework/Versions/2.6/ >> Resources/Python.app/Contents/MacOS/Python`test -f "/sw/Library/ >> Frameworks/Python.framework/Versions/2.6/Resources/Python.app/ >> Contents/ >> MacOS/Python-32" && echo "-32"` \ >> --output "/sw/Applications/Python 2.6/Build Applet.app" \ >> ./scripts/BuildApplet.py >> cd PythonLauncher && make install DESTDIR= >> test -d "/Applications/Python 2.6" || mkdir -p "/Applications/Python >> 2.6" >> mkdir: /Applications/Python 2.6: Permission denied >> make[2]: *** [install] Error 1 >> make[1]: *** [install_PythonLauncher] Error 2 >> make: *** [frameworkinstallapps] Error 2 >> >> Is there an option on the configure line that I need to set, or >> something in setup.py? Or perhaps hack the Makefile? > > FWIW, the OS X build-installer.py script handles this by specifying a > DESTDIR on the make install steps rather than including a --prefix on > the configure. See Mac/BuildScript/build-installer.py. That worked: make install DESTDIR=/sw . Not sure if it's the proper way to do it, but it installed fine now. I did have to change the configure line: CPPFLAGS=-I/sw/include LDFLAGS=-L/sw/lib ./configure -- enable-shared --enable-framework=/Library/Frameworks --with- readline=/sw --with-pth CC=gcc-4.2 MACOSX_DEPLOYMENT_TARGET=10.5 So --prefix has gone, and --enable-framework lost the /sw. Then the DESTDIR setting on the make line prepends it as necessary. I would have hoped an option on the configure line would have taken care of this (--exec-prefix doesn't do it, at least), but well, maybe next time. (Actually, checking again, I now also have a /sw/sw/Applications directory, next to the /sw/Applications dir. The former contains Applet.app; no idea how it ended up there, while IDLE.app and Python Launcher.app ended up in /sw/Applications. So, it almost worked; maybe there's some double $DESTDIR/$DESTDIR in the Makefile. Good enough for my purposes though.) Thanks! Evert From nad at acm.org Fri Feb 20 21:28:18 2009 From: nad at acm.org (Ned Deily) Date: Fri, 20 Feb 2009 18:28:18 -0800 Subject: Python won't run References: <37c2b0840902201652m118c1661s6eebe110f1b41fdf@mail.gmail.com> <50697b2c0902201703x79b6635dw60e7956d8500731a@mail.gmail.com> <37c2b0840902201716y6d072720m18b64d7734e65b18@mail.gmail.com> <50697b2c0902201720j2025ee3pad92c2600c912fb8@mail.gmail.com> <37c2b0840902201724h51e949fbpb49f99c3521ed32d@mail.gmail.com> <50697b2c0902201728k50076bdard53da0f567f2c65e@mail.gmail.com> <37c2b0840902201734n708e7d6ds349d7b4ad7af1b2d@mail.gmail.com> <50697b2c0902201741x46ebbe07ge4fbac1e3f7fee4b@mail.gmail.com> <37c2b0840902201751q5ac4b607n14c90ee0b51c1c00@mail.gmail.com> Message-ID: In article <37c2b0840902201751q5ac4b607n14c90ee0b51c1c00 at mail.gmail.com>, kevin hayes wrote: > I installed it...with the package that came with python 2.6. When I had 2.5 > I was using it(idle) successfully, until I ran a few programs that I got off > the web. Then, Idle wouldn't open (it just bounced in the dock and then > disappeared). So I tried installing 2.6 and the same thing happened. There may be some clues in the system.log as to why IDLE is not launching. Launch /Applications/Utilities/Console.app and under its File menu select Open System Log. Now try to launch IDLE again by double-clicking on its icon and see if any suspicious messages show up in the log. You could also try moving any IDLE preferences files out of the way temporarily and see if that helps. From a Terminal window, type: cd $HOME mv .idlerc .idlerc-disabled then try launching IDLE again. -- Ned Deily, nad at acm.org From odeits at gmail.com Fri Feb 20 22:14:02 2009 From: odeits at gmail.com (odeits) Date: Fri, 20 Feb 2009 19:14:02 -0800 (PST) Subject: Pythonic way to determine if one char of many in a string References: <1234761457.20683.1300568627@webmail.messagingengine.com> <8666ef66-288d-426a-9622-9d68d1f7971c@b40g2000pri.googlegroups.com> Message-ID: <9f03fc9d-7136-4372-8116-a999fb67bf87@p23g2000prp.googlegroups.com> On Feb 15, 11:31?pm, odeits wrote: > On Feb 15, 9:56?pm, Chris Rebert wrote: > > > > > On Sun, Feb 15, 2009 at 9:17 PM, ? wrote: > > > I need to test strings to determine if one of a list of chars is in the > > > string. A simple example would be to test strings to determine if they have > > > a vowel (aeiouAEIOU) present. > > > > I was hopeful that there was a built-in method that operated similar to > > > startswith where I could pass a tuple of chars to be tested, but I could not > > > find such a method. > > > > Which of the following techniques is most Pythonic or are there better ways > > > to perform this type of match? > > > > # long and hard coded but short circuits as soon as match found > > > if 'a' in word or 'e' in word or 'i' in word or 'u' in word or ... : > > > > -OR- > > > > # flexible, but no short circuit on first match > > > if [ char for char in word if char in 'aeiouAEIOU' ]: > > > Just use the fairly new builtin function any() to make it short-circuit: > > > if any(char.lower() in 'aeiou' for char in word): > > ? ? do_whatever() > > > Cheers, > > Chris > > > -- > > Follow the path of the Iguana...http://rebertia.com > > If you want to generalize it you should look at setshttp://docs.python.org/library/sets.html > > It seems what you are actually testing for is if the intersection of > the two sets is not empty where the first set is the characters in > your word and the second set is the characters in your defined string. To expand on what I was saying I thought i should provide a code snippet: WORD = 'g' * 100 WORD2 = 'g' * 50 + 'U' VOWELS = 'aeiouAEIOU' BIGWORD = 'g' * 10000 + 'U' def set_test(vowels, word): vowels = set( iter(vowels)) letters = set( iter(word) ) if letters & vowels: return True else: return False with python 2.5 I got 1.30 usec/pass against the BIGWORD From odeits at gmail.com Fri Feb 20 22:20:30 2009 From: odeits at gmail.com (odeits) Date: Fri, 20 Feb 2009 19:20:30 -0800 (PST) Subject: Changing the Image on a button References: <59253b2f-c90d-4308-835d-e81a2e602127@p23g2000prp.googlegroups.com> Message-ID: <612b19f3-a577-4a92-8be4-cad02af5922a@a39g2000prl.googlegroups.com> On Feb 17, 7:14?am, John Posner wrote: > ?>> > Try this change: > ?>> > > ?>> > ? from: btn.configure(image = None) > ?>> > ? ? to: img1.blank() > ?>> > > ?>> > ?>> This does in fact clear the image out, however it isn't causing the > ?>> text to display... Do i have have to create a new button and swap it > ?>> out? > > I knew you were gonna ask that! :-) I haven't worked in this area before, > but I > found this athttp://effbot.org/tkinterbook/button.htm: > > ? ? In earlier versions of Tkinter, the image option overrides the text > option. > ? ? If you specify both, only the image is displayed. In later versions, you > can > ? ? use the compound option to change this behavior. To display text on top > of > ? ? an image, set compound to CENTER: > > ? ? ?b = Button(master, text="Click me", image=pattern, compound=CENTER) > > So here's a reworking, in which the text and image are both toggled by > pressing the button: > > ### button that toggles both text and image > from Tkinter import * > > def pushed(): > ? ? """callback: button push""" > > ? ? global toggle > > ? ? if toggle: > ? ? ? ? btn.config(text="", image=img_empty) > ? ? ? ? toggle = not toggle > ? ? else: > ? ? ? ? btn.config(text=msg, image=img_good) > ? ? ? ? toggle = not toggle > > ### main program > toggle = True > msg = "hello" > > root = Tk() > > ### store two versions of an image in global variables: > # 1. original image > img_good = PhotoImage(file="bacon.gif") > > # 2. blank image, created by copying and erasing > img_empty = img_good.copy() > img_empty.blank() > > ### create toggle button > btn = Button(root, compound=CENTER, > ? ? ? ? ? ? text="hello", font="helvetica 14 bold", > ? ? ? ? ? ? image=img_good, > ? ? ? ? ? ? command=pushed) > btn.pack() > > ### go > root.mainloop() > > E-mail message checked by Spyware Doctor (6.0.0.386) > Database version: 5.11780http://www.pctools.com/en/spyware-doctor-antivirus/ Thank you very much for your help! It is now behaving the way I wanted! From gagsl-py2 at yahoo.com.ar Fri Feb 20 23:17:41 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 21 Feb 2009 02:17:41 -0200 Subject: Killing subservient threads References: <4bdc5d28-9ad9-446f-bd37-9e431fd702c6@p36g2000prp.googlegroups.com> Message-ID: En Fri, 20 Feb 2009 16:15:10 -0200, jimzat escribi?: > I am using the thread module and calling thread.start_new_thread > (...). If I use t=thread.start_new_thread(...) and later set > t.terminate, I get "AttributeError: 'int' object has no attribute > 'terminate'" Use the threading module instead, that provides a higher level interface. If you originally had: thread.start_new_thread(function, args) then it becomes: polling_thread = threading.Thread(target=function, args=args) ... polling_thread.start() > What is the proper way to do this? I don't want to use globals as I > will have multiple child windows of various classes. Use an attribute of this Thread instance. Either a simple boolean or a Condition/Event object as Christian Heimes suggested. -- Gabriel Genellina From kwmsmith at gmail.com Fri Feb 20 23:50:03 2009 From: kwmsmith at gmail.com (Kurt Smith) Date: Fri, 20 Feb 2009 22:50:03 -0600 Subject: can multi-core improve single funciton? In-Reply-To: References: <6a4f17690902092228i31fd1661n41c61c4037a289df@mail.gmail.com> Message-ID: On Fri, Feb 20, 2009 at 4:27 PM, Grant Edwards wrote: > On one hand, the upshot of that is that by finding an > appropriate library module you might gain some of the same > benefits as removing the GIL. > > On the other hand, that doesn't help if you're doing something > original enough that nobody has written a library to handle > large chunks of it. > > And on the grasping hand, I find that most of us vastly > overestimate the originality of what we're doing. +1 The Mote in God's Eye / The Gripping Hand reference! Kurt From gagsl-py2 at yahoo.com.ar Fri Feb 20 23:52:05 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 21 Feb 2009 02:52:05 -0200 Subject: function factory question: embed current values of object attributes References: Message-ID: En Fri, 20 Feb 2009 16:49:21 -0200, Alan Isaac escribi?: > I have a class `X` where many parameters are set > at instance initialization. The parameter values > of an instance `x` generally remain unchanged, > but is there way to communicate to a method that > it depends only on the initial values of these parameters > (and does not need to worry about any changes)? > > The behavior of method `m` depends on these parameter values. > It turns out `m` gets called a lot, which means > that the pameter values are accessed over and over > (self.p0, self.p1, etc). I would like to > manufacture a function equivalent to the method > that simply uses fixed values (the values at the > time it is manufactured). I do not care if this > function is attached to `x` or not. Not automatically; but you could refactor the method to call an external function with arguments: class X(...): ... def foo(self): c = self.a + self.b return c Rewrite the method as: def foo(self): return _foo(self.a, self.b) and define _foo outside the class: def _foo(a, b): c = a + b return c If you want a "frozen" function (that is, a function already set-up with the parameters taken from the current values of x.a, x.b) use functools.partial: x = X() frozen_foo = functools.partial(_foo, a=x.a, b=x.b) frozen_foo() # equivalent to x.foo() at the time it was defined But if you call this in a loop, perhaps it's enough to assign x.a, x.b to local variables and call _foo with those arguments. -- Gabriel Genellina From rozzin at geekspace.com Sat Feb 21 00:20:20 2009 From: rozzin at geekspace.com (Joshua Judson Rosen) Date: Sat, 21 Feb 2009 00:20:20 -0500 Subject: multiprocessing module and os.close(sys.stdin.fileno()) References: <3098ffc2-6884-4a35-99a5-ee917442af25@r37g2000prr.googlegroups.com> Message-ID: <87bpswe57v.fsf@slice.rozzin.com> Jesse Noller writes: > > On Tue, Feb 17, 2009 at 10:34 PM, Graham Dumpleton > wrote: > > Why is the multiprocessing module, ie., multiprocessing/process.py, in > > _bootstrap() doing: > > > > os.close(sys.stdin.fileno()) > > > > rather than: > > > > sys.stdin.close() > > > > Technically it is feasible that stdin could have been replaced with > > something other than a file object, where the replacement doesn't have > > a fileno() method. > > > > In that sort of situation an AttributeError would be raised, which > > isn't going to be caught as either OSError or ValueError, which is all > > the code watches out for. > > I don't know why it was implemented that way. File an issue on the > tracker and assign it to me (jnoller) please. My guess would be: because it's also possible for sys.stdin to be a file that's open in read+*write* mode, and for that file to have pending output buffered (for example, in the case of a socketfile). There's a general guideline, inherited from C, that one should ensure that the higher-level close() routine is invoked on a given file-descriptor in at most *one* process after that descriptor has passed through a fork(); in the other (probably child) processes, the lower-level close() routine should be called to avoid a double-flush--whereby buffered data is flushed out of one process, and then the *same* buffered data is flushed out of the (other) child-/parent-process' copy of the file-object. So, if you call sys.stdin.close() in the child-process in _bootstrap(), then it could lead to a double-flush corrupting output somewhere in the application that uses the multiprocessing module. You can expect similar issues with just about /any/ `file-like objects' that might have `file-like semantics' of buffering data and flushing it on close, also--because you end up with multiple copies of the same object in `pre-flush' state, and each copy tries to flush at some point. As such, I'd recommend against just using .close(); you might use something like `if hasattr(sys.stdin, "fileno"): ...'; but, if your `else' clause unconditionally calls sys.stdin.close(), then you still have double-flush problems if someone's set sys.stdin to a file-like object with output-buffering. I guess you could try calling that an `edge-case' and seeing if anyone screams. It'd be sort-of nice if there was finer granularity in the file API--maybe if file.close() took a boolean `flush' argument.... -- Don't be afraid to ask (Lf.((Lx.xx) (Lr.f(rr)))). From nagle at animats.com Sat Feb 21 00:33:38 2009 From: nagle at animats.com (John Nagle) Date: Fri, 20 Feb 2009 21:33:38 -0800 Subject: "Byte" type? In-Reply-To: References: <4997aa38$0$1678$742ec2ed@news.sonic.net> <499841bf$0$1624$742ec2ed@news.sonic.net> <499859e2$0$1618$742ec2ed@news.sonic.net> Message-ID: <499f8a8e$0$1588$742ec2ed@news.sonic.net> Steve Holden wrote: > John Nagle wrote: >> Benjamin Kaplan wrote: >>> On Sun, Feb 15, 2009 at 11:57 AM, John Nagle wrote: >>> ...Re "bytes" not behaving as documented in 2.6: >> That's indeed how Python 2.6 works. But that's not how >> PEP 3137 says it's supposed to work. >> >> Guido: >> >> "I propose the following type names at the Python level: >> >> * bytes is an immutable array of bytes (PyString) >> * bytearray is a mutable array of bytes (PyBytes)" ... >> (Not true in Python 2.6 >> >> Is this a bug, a feature, a documentation error, or bad design? >> > It's a feature. In fact all that was done to accommodate easier > migration to 3.x is easily shown in one statement: > >>>> str is bytes > True > > So that's why bytes works the way it does in 2.6 ... hence my contested > description of it as an "ugly hack". I am happy to withdraw "ugly", but > I think "hack" could still be held to apply. Agreed. But is this a 2.6 thing, making 2.6 incompatible with 3.0, or what? How will 3.x do it? The PEP 3137 way, or the Python 2.6 way? The way it works in 2.6 makes it necessary to do "ord" conversions where they shouldn't be required. John Nagle From Scott.Daniels at Acm.Org Sat Feb 21 01:05:40 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 20 Feb 2009 22:05:40 -0800 Subject: Python won't run In-Reply-To: References: <37c2b0840902201652m118c1661s6eebe110f1b41fdf@mail.gmail.com> Message-ID: Chris Rebert wrote: > On Fri, Feb 20, 2009 at 4:52 PM, kevin hayes wrote: >> Hi, I had python 2.5 installed on my Mac osx 10.4.11 and idle stopped >> opening and running after I ran a few programs. I installed python 2.6 >> hoping this would allow me to open idle and start learning to program. How >> do I get Idle running again? > > What error do you get when trying to run it from the command line? > > Cheers, > Chris > Try from the command line: $ python -m idlelib.idle -n If it works, do a bit and see how that goes. Then try: $ python -m idlelib.idle In both cases, you _may_ get error messages to the command window that help diagnose. --Scott David Daniels Scott.Daniels at Acm.Org From rhodri at wildebst.demon.co.uk Sat Feb 21 01:25:08 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sat, 21 Feb 2009 06:25:08 -0000 Subject: how to assert that method accepts specific types In-Reply-To: <3f26a2f1-94cf-4083-9bda-7076959ad784@k19g2000yqg.googlegroups.com> References: <3f26a2f1-94cf-4083-9bda-7076959ad784@k19g2000yqg.googlegroups.com> Message-ID: On Sat, 21 Feb 2009 01:12:01 -0000, Darren Dale wrote: > I would like to assert that a method accepts certain types. I have a > short example that works: > > from functools import wraps > > def accepts(*types): > def check_accepts(f): > @wraps(f) > def new_f(self, other): > assert isinstance(other, types), \ > "arg %r does not match %s" % (other, types) > return f(self, other) > return new_f > return check_accepts > > class Test(object): > > @accepts(int) > def check(self, obj): > print obj > > t = Test() > t.check(1) > > but now I want Test.check to accept an instance of Test as well. Does > anyone know how this can be accomplished? The following class > definition for Test raises a NameError: > > class Test(object): > > @accepts(int, Test) > def check(self, obj): > print obj An icky but relatively clear way to get around this is to gratuitously subclass Test: class AcceptableTest(object): pass class Test(AcceptableTest): @accepts(int, AcceptableTest) def check(self, obj): print obj -- Rhodri James *-* Wildebeeste Herder to the Masses From sidell at gmail.com Sat Feb 21 01:55:23 2009 From: sidell at gmail.com (jsidell) Date: Fri, 20 Feb 2009 22:55:23 -0800 (PST) Subject: Wanted: Online Python Course for Credit Message-ID: <3d974c13-efcd-48ae-8015-7b4a8812280f@w1g2000prk.googlegroups.com> I'm a high school game development teacher and I have recently discovered Python to be a great way to introduce computer programming. I intend to study Python on my own but I can get professional development credit at my job for taking a Python course. So I'm looking for an online class that I can get a certificate, college credit, or something to that effect. Any suggestions would be greatly appreciated From gagsl-py2 at yahoo.com.ar Sat Feb 21 02:00:29 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 21 Feb 2009 05:00:29 -0200 Subject: Find the location of a loaded module References: <5879412d-ffba-4fd9-82b7-7e798dc425e3@f3g2000yqf.googlegroups.com> Message-ID: En Fri, 20 Feb 2009 20:44:21 -0200, Aaron Scott escribi?: > So, the problem lies with how Python cached the modules in memory. > Yes, the modules were in two different locations and yes, the one that > I specified using its direct path should be the one loaded. The > problem is, the module isn't always loaded -- if it's already in > memory, it'll use that instead. And since the modules had the same > name, Python wouldn't distinguish between them, even though they > weren't exactly the same. Yes, that's how import works. It's barely documented, and you finally learned it the hard way... > So, loading the module act1/story would load > act1/story. Then, loading the module act2/story would use the story > module already in memory. Of course, this made the problem hard to > pinpoint, since memory is a fickle thing, and the results weren't > always reproducible. > > The final solution? Renaming the 'story' modules to 'story_1' and > 'story_2'... and importing them via 'exec("from story_"+modulename+" > import game")'. > > Will I go to hell for this 'solution'? Probably. But hey, it means I > can go home tonight instead of spending all evening at the office > hitting my head against the wall. I'll come back to it Monday and try > to figure out a more reasonable solution. Use packages. Make act1 and act2 packages by creating __init__.py files. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Sat Feb 21 03:37:22 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 21 Feb 2009 06:37:22 -0200 Subject: "import" not working? References: <7f0d1540-ae7e-4da1-936e-afbc8c6d2d49@k19g2000yqg.googlegroups.com> <11062739-5a43-43d8-b4a2-9bd494230992@t13g2000yqc.googlegroups.com> <65f8a016-a4c1-48c0-8128-47f62b865a6f@m40g2000yqh.googlegroups.com> Message-ID: En Fri, 20 Feb 2009 22:40:03 -0200, Lionel escribi?: > Okay, moving the wx example into the same directory containing the > first example that was working fixed it. This directory only contains > these two modules and nothing else. The old directory which contained > the example that wasn't working did not contain a module with the same > name as the one I was trying to import, so i don't know why this "fix" > worked. Just play safe: - Don't use "from xxx import *", least from two places at the same time. The wx package has a short name on purpose - use "import wx" and then wx.Frame, etc. - Don't play with sys.path if you don't have to; you can put your own modules in a place already listed (like Lib\site-packages). Or, use a .pth file if you want to add a copmletely separate directory like c:\DataFileTypes -- Gabriel Genellina From alia_khouri at yahoo.com Sat Feb 21 03:46:08 2009 From: alia_khouri at yahoo.com (Alia Khouri) Date: Sat, 21 Feb 2009 00:46:08 -0800 (PST) Subject: python contextmanagers and ruby blocks Message-ID: <0ca5a9c3-03d3-4824-9c66-c1a3604aa98b@x9g2000yqk.googlegroups.com> As an exercise, I recently translated one of my python scripts (http:// code.activestate.com/recipes/576643/) to haskell (a penultimate version exists at http://groups.google.com/group/comp.lang.haskell/browse_thread/thread/fb1ebd986b44244e# in case anyone is interested) with the result that haskell has now become my second favourite language (after python of course :-) Just to change mental gears a bit, I'd now like to do the same and create a ruby version. As I've progressed on the latter, I've been struck by how pervasive the use of blocks is in ruby. For example: class Builder attr_accessor :name def machine &block @name = "m1" block.call end def build(x, &block) puts x block.call end end builder = Builder.new builder.machine do puts "hello #{builder.name}" end builder.build "hello" do puts "world" end which should print out: hello m1 hello world Now, python's relatively new contextmanagers seem to provide something similar such that one can write: from __future__ import with_statement from contextlib import contextmanager class Builder: @contextmanager def machine(self): self.name = "m1" yield @contextmanager def build(self, x): print x yield builder = Builder() with builder.machine(): print 'hello %s' % builder.name with builder.build("hello"): print 'world' Which brings me to my questions: 1. To what extent are python's contextmanagers similar or equivalent to ruby's blocks? 2. If there is a gap in power or expressiveness in python's context managers relative to ruby's blocks, what are possible (syntactic and non-syntactic) proposals to bridge this gap? Thank you for your responses. AK From gagsl-py2 at yahoo.com.ar Sat Feb 21 03:47:33 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 21 Feb 2009 06:47:33 -0200 Subject: Pythonic way to determine if one char of many in a string References: <1234761457.20683.1300568627@webmail.messagingengine.com> <8666ef66-288d-426a-9622-9d68d1f7971c@b40g2000pri.googlegroups.com> <9f03fc9d-7136-4372-8116-a999fb67bf87@p23g2000prp.googlegroups.com> Message-ID: En Sat, 21 Feb 2009 01:14:02 -0200, odeits escribi?: > On Feb 15, 11:31?pm, odeits wrote: >> It seems what you are actually testing for is if the intersection of >> the two sets is not empty where the first set is the characters in >> your word and the second set is the characters in your defined string. > > To expand on what I was saying I thought i should provide a code > snippet: > > WORD = 'g' * 100 > WORD2 = 'g' * 50 + 'U' > VOWELS = 'aeiouAEIOU' > BIGWORD = 'g' * 10000 + 'U' > > def set_test(vowels, word): > > vowels = set( iter(vowels)) > letters = set( iter(word) ) > > if letters & vowels: > return True > else: > return False > > with python 2.5 I got 1.30 usec/pass against the BIGWORD You could make it slightly faster by removing the iter() call: letters = set(word) And (if vowels are really constant) you could pre-build the vowels set. -- Gabriel Genellina From aisaac at american.edu Sat Feb 21 04:07:25 2009 From: aisaac at american.edu (Alan Isaac) Date: Sat, 21 Feb 2009 09:07:25 GMT Subject: function factory question: embed current values of object attributes In-Reply-To: References: Message-ID: Terry Reedy wrote: > You are now describing a function closure. Here is an example that > might help. It does. Thanks, Alan From aisaac at american.edu Sat Feb 21 04:15:25 2009 From: aisaac at american.edu (Alan Isaac) Date: Sat, 21 Feb 2009 09:15:25 GMT Subject: function factory question: embed current values of object attributes In-Reply-To: References: Message-ID: Gabriel Genellina wrote: > If you want a "frozen" function (that is, a function already set-up with > the parameters taken from the current values of x.a, x.b) use > functools.partial: OK, that's also a nice idea. Thanks! Alan From martin at v.loewis.de Sat Feb 21 04:15:39 2009 From: martin at v.loewis.de (=?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=) Date: Sat, 21 Feb 2009 10:15:39 +0100 Subject: Using clock() in threading on Windows In-Reply-To: References: Message-ID: <499fc63c$0$30913$9b622d9e@news.freenet.de> > Would it not be better to use time.clock() instead? If you really want to reconsider this implementation, I think it would be best to use relative timeouts all the way down to the system. In the specific case of Windows, WaitForSingleObject expects a relative number of milliseconds (i.e. a wait duration). As this is also what the Python script passes (in seconds), it is best to leave issues of timer resolution to the operating system (which we have to trust anyway). As a consequence, the half-busy loops could go away, at least on systems where lock timeouts can be given to the system. Regards, Martin From intelliminer at gmail.com Sat Feb 21 04:35:14 2009 From: intelliminer at gmail.com (intelliminer at gmail.com) Date: Sat, 21 Feb 2009 01:35:14 -0800 (PST) Subject: Python dictionary size/entry limit? Message-ID: I wrote a script to process textual data and extract phrases from them, storing these phrases in a dictionary. It encounters a MemoryError when there are about 11.18M keys in the dictionary, and the size is about 1.5GB. I tried multiple times, and the error occurs everytime at exactly the same place (with the same number of keys in the dict). I then split the dictionary into two using a simple algorithm: if str[0]<='m': dict=dict1 else: dict=dict2 #use dict... And it worked fine. The total size of the two dictionaries well exceeded 2GB yet no MemoryError occured. I have 1GB of pysical memory and 3GB in pagefile. Is there a limit to the size or number of entries that a single dictionary can possess? By searching on the web I can't find a clue why this problem occurs. From tino at wildenhain.de Sat Feb 21 05:25:28 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Sat, 21 Feb 2009 11:25:28 +0100 Subject: Python dictionary size/entry limit? In-Reply-To: References: Message-ID: <499FD698.9040606@wildenhain.de> intelliminer at gmail.com wrote: > I wrote a script to process textual data and extract phrases from > them, storing these phrases in a dictionary. It encounters a > MemoryError when there are about 11.18M keys in the dictionary, and > the size is about 1.5GB. I tried multiple times, and the error occurs > everytime at exactly the same place (with the same number of keys in > the dict). I then split the dictionary into two using a simple > algorithm: > > if str[0]<='m': > dict=dict1 > else: > dict=dict2 > > #use dict... > > And it worked fine. The total size of the two dictionaries well > exceeded 2GB yet no MemoryError occured. > > I have 1GB of pysical memory and 3GB in pagefile. Is there a limit to > the size or number of entries that a single dictionary can possess? By > searching on the web I can't find a clue why this problem occurs. From what can be deducted from the headers of your message: X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1;... you are using windows? It seems either python or windows memory management somehow prevent the use of continuous memory areas that large. We've got such an example somewhere down the list which was similar (iirc it was a large string in memory) which runned perfectly with linux. You can try yourself maybe by installing ubuntu on the same host. (If you feel fit you can even skip the install and run it off life CD but then you need to fiddle a little to get swap space on disk) Regards Tino > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3241 bytes Desc: S/MIME Cryptographic Signature URL: From intelliminer at gmail.com Sat Feb 21 05:45:39 2009 From: intelliminer at gmail.com (intelliminer at gmail.com) Date: Sat, 21 Feb 2009 02:45:39 -0800 (PST) Subject: Python dictionary size/entry limit? References: Message-ID: <0823e6c0-ed69-4dfe-85aa-286631b9bbee@i15g2000pro.googlegroups.com> On Feb 21, 6:25?pm, Tino Wildenhain wrote: > intellimi... at gmail.com wrote: > > I wrote a script to process textual data and extract phrases from > > them, storing these phrases in a dictionary. It encounters a > > MemoryError when there are about 11.18M keys in the dictionary, and > > the size is about 1.5GB. I tried multiple times, and the error occurs > > everytime at exactly the same place (with the same number of keys in > > the dict). I then split the dictionary into two using a simple > > algorithm: > > > if str[0]<='m': > > ? ? dict=dict1 > > else: > > ? ? dict=dict2 > > > #use dict... > > > And it worked fine. The total size of the two dictionaries well > > exceeded 2GB yet no MemoryError occured. > > > I have 1GB of pysical memory and 3GB in pagefile. Is there a limit to > > the size or number of entries that a single dictionary can possess? By > > searching on the web I can't find a clue why this problem occurs. > > ?From what can be deducted from the headers of your message: > X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1;... > you are using windows? > It seems either python or windows memory management somehow prevent > the use of continuous memory areas that large. > We've got such an example somewhere down the list which was similar > (iirc it was a large string in memory) which runned perfectly > with linux. You can try yourself maybe by installing ubuntu > on the same host. (If you feel fit you can even skip the install > and run it off life CD but then you need to fiddle a little to > get swap space on disk) > > Regards > Tino > > > -- > >http://mail.python.org/mailman/listinfo/python-list > > > > ?smime.p7s > 4KViewDownload Yes, it's winxp, I forgot to mention it. Thanks for the reply. From stefan_ml at behnel.de Sat Feb 21 05:47:10 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 21 Feb 2009 11:47:10 +0100 Subject: Python dictionary size/entry limit? In-Reply-To: References: Message-ID: <499fdbae$0$31865$9b4e6d93@newsspool3.arcor-online.net> intelliminer at gmail.com wrote: > I wrote a script to process textual data and extract phrases from > them, storing these phrases in a dictionary. It encounters a > MemoryError when there are about 11.18M keys in the dictionary, and > the size is about 1.5GB. > [...] > I have 1GB of pysical memory and 3GB in pagefile. Is there a limit to > the size or number of entries that a single dictionary can possess? By > searching on the web I can't find a clue why this problem occurs. Python dicts are only limited by what your OS returns as free memory. However, when a dict grows, it needs to resize, which means that it has to create a bigger copy of itself and redistribute the keys. For a dict that is already 1.5GB big, this can temporarily eat a lot more memory than you have, at least more than two times as much as the size of the dict itself. You may be better served with one of the dbm databases that come with Python. They live on-disk but do the usual in-memory caching. They'll likely perform a lot better than your OS level swap file. Stefan From bockman at virgilio.it Sat Feb 21 06:00:56 2009 From: bockman at virgilio.it (Francesco Bochicchio) Date: Sat, 21 Feb 2009 12:00:56 +0100 Subject: python contextmanagers and ruby blocks References: <0ca5a9c3-03d3-4824-9c66-c1a3604aa98b@x9g2000yqk.googlegroups.com> Message-ID: On Sat, 21 Feb 2009 00:46:08 -0800, Alia Khouri wrote: > As an exercise, I recently translated one of my python scripts (http:// > code.activestate.com/recipes/576643/) to haskell (a penultimate > version exists at http://groups.google.com/group/comp.lang.haskell/browse_thread/thread/fb1ebd986b44244e# > in case anyone is interested) with the result that haskell has now > become my second favourite language (after python of course :-) > > Just to change mental gears a bit, I'd now like to do the same and > create a ruby version. As I've progressed on the latter, I've been > struck by how pervasive the use of blocks is in ruby. For example: > ... ruby code that shows the most twisted 'Hellow world' example I have ever seen :-) ... > > Now, python's relatively new contextmanagers seem to provide something > similar such that one can write: > ... python code doing the same thing - apparently - of prevous ruby code, using context managers in a way that I believe the authors of contextlib module never thought of. > > Which brings me to my questions: > > 1. To what extent are python's contextmanagers similar or equivalent > to ruby's blocks? > ASAIK, context managers are nothing like ruby blocks. Context managers have a very specific purpose : to make people able to abstract the code that one writes to 'enter a context' (i.e. open a file, start a transaction, ... ) and 'leave a context' (i.e. close a file, commit or rollback the transaction ... ). So that you can separate context handling code from the code that performs actions insed that context, factoring out the first for reuse and better code maintenance. Ruby blocks are blocks of code which can be passed as objects for a number of different usage - for instance to make context management stuff. If I have to compare them to something in Python, I would say they are 'lambda on steroids' or 'nameless functions'. And - personally - I don't like them just as I don't like lambdas in python for anything but one-liners and I don't like anonymous functions in haskell (which I am painfully trying to learn ). They may be cool to write, but they look not very readable to me - but maybe this is just me. Ciao ---- FB Ruby blocks - for the little I know of ruby - are anonymous block of codes > 2. If there is a gap in power or expressiveness in python's context > managers relative to ruby's blocks, what are possible (syntactic and > non-syntactic) proposals to bridge this gap? > > Thank you for your responses. > > AK From alia_khouri at yahoo.com Sat Feb 21 08:20:51 2009 From: alia_khouri at yahoo.com (Alia K) Date: Sat, 21 Feb 2009 05:20:51 -0800 (PST) Subject: python contextmanagers and ruby blocks References: <0ca5a9c3-03d3-4824-9c66-c1a3604aa98b@x9g2000yqk.googlegroups.com> Message-ID: Francesco wrote: > ... ruby code that shows the most twisted 'Hellow world' example I have > ever seen :-) ... and I was gunning for the simplest possible example (-: > ... python code doing the same thing - apparently - > of prevous ruby code, using context managers in a way that I believe the > authors of contextlib module never thought of. Methinks they probably thought of such usage. > > 1. To what extent are python's contextmanagers similar or equivalent > > to ruby's blocks? > ASAIK, context managers are nothing like ruby blocks. > Context managers have a very specific purpose : to make people able to > abstract the code that one writes to 'enter a context' > (i.e. open a file, start a transaction, ... ) and 'leave a context' > (i.e. close a file, commit or rollback the transaction ... ). > So that you can separate context handling code from the code that performs > actions insed that context, factoring out the first for reuse and better > code maintenance. Thinking about it: I suppose one could say in python a contextmanager defines the functional context of a block of code and makes it a first class construct in the language, whereas in ruby the block itself is a first class citizen -- contextmanagers are like the inverse of blocks. > Ruby blocks are blocks of code which can be passed as > objects for a number of different usage - for instance to make context > management stuff. If I have to compare them to something in Python, I > would say they are 'lambda on steroids' or 'nameless functions'. Agreed, but also they are more tightly integrated e.g. the &block construct which can be passed into functions... > personally - I don't like them just as I don't like lambdas in python for > anything but one-liners and I don't like anonymous functions in haskell > (which I am painfully trying to learn ). They may be cool to write, but > they look not very readable to me - but maybe this is just me. In case you are learning haskell, here are some excellent guides (order is important) : * Learn you a haskell: http://learnyouahaskell.com/chapters * Real World Haskell: http://book.realworldhaskell.org/ * Typeclassopedia: http://byorgey.wordpress.com/2009/02/16/the-typeclassopedia-request-for-feedback/ (I'm personally still scratching the surface of it all...) back to the subject... I suppose because contextmanagers (indeed decorators) are so relatively new to python, it will probably take a little while for these constructs to comprehensively penetrate the stdlib. It's already happened with files, locks, and db transactions but I'm sure there are many instances where one could benefit from using the with statement. Nevertheless, I remain curious about whether once can use the contextmanager in python to achieve the full power of ruby's blocks... Best, AK From mailinglists at vanwingerde.net Sat Feb 21 08:35:05 2009 From: mailinglists at vanwingerde.net (Jaap van Wingerde) Date: Sat, 21 Feb 2009 14:35:05 +0100 Subject: TypeError: descriptor 'replace' requires a 'str' object but received a 'unicode' Message-ID: <49A00309.5030505@vanwingerde.net> # -*- coding: utf_8 -*- Omschrijving = u'priv? assuranti?n' # string from a bank.csv Omschrijving = str.replace(Omschrijving, "priv?", 'priv?') Omschrijving = str.replace(Omschrijving, "Assuranti?n", 'Assuranti?n') print Omschrijving When I run this script I get the following message. "Traceback (most recent call last): File "/home/jaap/Desktop/unicode.py", line 3, in Omschrijving = str.replace(Omschrijving, "priv?", 'priv?') TypeError: descriptor 'replace' requires a 'str' object but received a 'unicode'" How can I solve this? -- Jaap van Wingerde e-mail: 1234567890 at vanwingerde.net web: http://jaap.vanwingerde.net/ From stefan_ml at behnel.de Sat Feb 21 08:55:54 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 21 Feb 2009 14:55:54 +0100 Subject: TypeError: descriptor 'replace' requires a 'str' object but received a 'unicode' In-Reply-To: References: Message-ID: <49a007ea$0$30236$9b4e6d93@newsspool1.arcor-online.net> Jaap van Wingerde wrote: > # -*- coding: utf_8 -*- > Omschrijving = u'priv? assuranti?n' # string from a bank.csv > Omschrijving = str.replace(Omschrijving, "priv?", 'priv?') > Omschrijving = str.replace(Omschrijving, "Assuranti?n", 'Assuranti?n') > print Omschrijving > > When I run this script I get the following message. > > "Traceback (most recent call last): > File "/home/jaap/Desktop/unicode.py", line 3, in > Omschrijving = str.replace(Omschrijving, "priv?", 'priv?') > TypeError: descriptor 'replace' requires a 'str' object but received a > 'unicode'" > > How can I solve this? By using unicode.replace() instead of str.replace(), i.e. Omschrijving = Omschrijving.replace("priv?", 'priv?') Stefan From mailinglists at vanwingerde.net Sat Feb 21 09:43:37 2009 From: mailinglists at vanwingerde.net (Jaap van Wingerde) Date: Sat, 21 Feb 2009 15:43:37 +0100 Subject: ordinal not in range In-Reply-To: <49a007ea$0$30236$9b4e6d93@newsspool1.arcor-online.net> References: <49a007ea$0$30236$9b4e6d93@newsspool1.arcor-online.net> Message-ID: <49A01319.306@vanwingerde.net> Stefan Behnel wrote: > Omschrijving = Omschrijving.replace("priv?", 'priv?') I Thank you, this works now, but I get a new error message. .... import codecs file = "postbank.csv" output = "%s.eb" % file outfile = codecs.open(output, "w", "utf_8") Omschrijving = u'priv? assuranti?n' # string from postbank.csv Omschrijving = Omschrijving.replace("priv?", 'priv?') Omschrijving = Omschrijving.replace("Assuranti?n", 'Assuranti?n') outfile.write (Omschrijving) "Traceback (most recent call last): File "/home/jaap/Desktop/unicode.py", line 9, in outfile.write (Omschrijving) File "/usr/lib/python2.5/codecs.py", line 638, in write return self.writer.write(data) File "/usr/lib/python2.5/codecs.py", line 303, in write data, consumed = self.encode(object, self.errors) UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 4: ordinal not in range(128)" From aahz at pythoncraft.com Sat Feb 21 09:59:48 2009 From: aahz at pythoncraft.com (Aahz) Date: 21 Feb 2009 06:59:48 -0800 Subject: Uploading big files wit cherrypy References: <366595b2-226c-48e4-961d-85bd0ce4bd9a@h16g2000yqj.googlegroups.com> Message-ID: In article <366595b2-226c-48e4-961d-85bd0ce4bd9a at h16g2000yqj.googlegroups.com>, Farsheed Ashouri wrote: > >But I couldn't upload files bigger than 100Mb. Why and what is >workaround? What happens when you upload a file larger than 100MB? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From stefan_ml at behnel.de Sat Feb 21 10:00:41 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 21 Feb 2009 16:00:41 +0100 Subject: ordinal not in range In-Reply-To: References: <49a007ea$0$30236$9b4e6d93@newsspool1.arcor-online.net> Message-ID: <49a01719$0$30224$9b4e6d93@newsspool1.arcor-online.net> Jaap van Wingerde wrote: > Stefan Behnel wrote: >> Omschrijving = Omschrijving.replace("priv?", 'priv?') actually, make that Omschrijving = Omschrijving.replace(u"priv?", u'priv?') (mind the u"...") > .... > import codecs > file = "postbank.csv" > output = "%s.eb" % file > outfile = codecs.open(output, "w", "utf_8") > Omschrijving = u'priv? assuranti?n' # string from postbank.csv > Omschrijving = Omschrijving.replace("priv?", 'priv?') > Omschrijving = Omschrijving.replace("Assuranti?n", 'Assuranti?n') I guess you mixed up the case here. > outfile.write (Omschrijving) > > "Traceback (most recent call last): > File "/home/jaap/Desktop/unicode.py", line 9, in > outfile.write (Omschrijving) > File "/usr/lib/python2.5/codecs.py", line 638, in write > return self.writer.write(data) > File "/usr/lib/python2.5/codecs.py", line 303, in write > data, consumed = self.encode(object, self.errors) > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 4: > ordinal not in range(128)" Does this help? outfile = codecs.open(output, "wb", encoding="UTF-8") (mind the "wb" for 'write binary/bytes') Looks like you'd be happier with Python 3.0, BTW... Stefan From wnewbery at hotmail.co.uk Sat Feb 21 10:01:16 2009 From: wnewbery at hotmail.co.uk (William Newbery) Date: Sat, 21 Feb 2009 15:01:16 +0000 Subject: Python C-API Object Allocation Message-ID: Ive been learning the C-API lately so I can write python extensions for some of my c++ stuff. I want to use the new and delete operators for creating and destroying my objects. The problem is python seems to break it into several stages. tp_new, tp_init and tp_alloc for creation and tp_del, tp_free and tp_dealloc for destruction. However c++ just has new which allocates and fully constructs the object and delete which destructs and deallocates the object. Which of the python tp_* methods do I need to provide and what must they do to be compatible with python subclassing. Also I want to be able to create the object directly in c++ eg "PyObject *obj = new MyExtensionObject(args);" _________________________________________________________________ Love Hotmail?? Check out the new services from Windows Live! http://clk.atdmt.com/UKM/go/132630768/direct/01/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Sat Feb 21 10:01:30 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 21 Feb 2009 10:01:30 -0500 Subject: "Byte" type? In-Reply-To: <499f8a8e$0$1588$742ec2ed@news.sonic.net> References: <4997aa38$0$1678$742ec2ed@news.sonic.net> <499841bf$0$1624$742ec2ed@news.sonic.net> <499859e2$0$1618$742ec2ed@news.sonic.net> <499f8a8e$0$1588$742ec2ed@news.sonic.net> Message-ID: John Nagle wrote: > Steve Holden wrote: >> John Nagle wrote: >>> Benjamin Kaplan wrote: >>>> On Sun, Feb 15, 2009 at 11:57 AM, John Nagle wrote: >>>> > ...Re "bytes" not behaving as documented in 2.6: > >>> That's indeed how Python 2.6 works. But that's not how >>> PEP 3137 says it's supposed to work. >>> >>> Guido: >>> >>> "I propose the following type names at the Python level: >>> >>> * bytes is an immutable array of bytes (PyString) >>> * bytearray is a mutable array of bytes (PyBytes)" > ... >>> (Not true in Python 2.6 >>> Is this a bug, a feature, a documentation error, or bad design? >>> >> It's a feature. In fact all that was done to accommodate easier >> migration to 3.x is easily shown in one statement: >> >>>>> str is bytes >> True >> >> So that's why bytes works the way it does in 2.6 ... hence my contested >> description of it as an "ugly hack". I am happy to withdraw "ugly", but >> I think "hack" could still be held to apply. > > Agreed. But is this a 2.6 thing, making 2.6 incompatible with 3.0, or > what? How will 3.x do it? The PEP 3137 way, or the Python 2.6 way? > > The way it works in 2.6 makes it necessary to do "ord" conversions > where they shouldn't be required. > Yes, the hack was to achieve a modicum of compatibility with 3.0 without having to turn the world upside down. I haven't used 3.0 enough the say whether bytearray has been correctly implemented. But I believe the intention is that 3.0 should fully implement PEP 3137. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From aahz at pythoncraft.com Sat Feb 21 10:01:38 2009 From: aahz at pythoncraft.com (Aahz) Date: 21 Feb 2009 07:01:38 -0800 Subject: Change in cgi handling of POST requests References: Message-ID: [posted & e-mailed] In article , Mac wrote: > >We just upgraded Python to 2.6 on some of our servers and a number of >our CGI scripts broke because the cgi module has changed the way it >handles POST requests. When the 'action' attribute was not present in >the form element on an HTML page the module behaved as if the value of >the attribute was the URL which brought the user to the page with the >form, but without the query (?x=y...) part. Now FieldStorage.getvalue >() is giving the script a list of two copies of the value for some of >the parameters (folding in the parameters from the previous request) >instead of the single string it used to return for each. I searched >this newsgroup looking for a discussion of the proposal to impose this >change of behavior, and perhaps I wasn't using the right phrases in my >search, but I didn't find anything. Interesting. Nobody has responded, so I suggest first filing a report using bugs.python.org and then asking on python-dev (with reference to your report). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From steve at holdenweb.com Sat Feb 21 10:27:54 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 21 Feb 2009 10:27:54 -0500 Subject: TypeError: descriptor 'replace' requires a 'str' object but received a 'unicode' In-Reply-To: <49A00309.5030505@vanwingerde.net> References: <49A00309.5030505@vanwingerde.net> Message-ID: Jaap van Wingerde wrote: > # -*- coding: utf_8 -*- > Omschrijving = u'priv? assuranti?n' # string from a bank.csv > Omschrijving = str.replace(Omschrijving, "priv?", 'priv?') > Omschrijving = str.replace(Omschrijving, "Assuranti?n", 'Assuranti?n') > print Omschrijving > > When I run this script I get the following message. > > "Traceback (most recent call last): > File "/home/jaap/Desktop/unicode.py", line 3, in > Omschrijving = str.replace(Omschrijving, "priv?", 'priv?') > TypeError: descriptor 'replace' requires a 'str' object but received a > 'unicode'" > > How can I solve this? > First of all, use the methods of the unicode type, not the str type. Secondly, call the methods on an instance, not on the type (the instance is passed automatically). Thirdly, use Unicode arguments to replace. Omschrijving = u'priv? assuranti?n' # string from a bank.csv Omschrijving = Omschrijving.replace(u"priv?", u'priv?') Omschrijving = Omschrijving.replace(u"assuranti?n", u'assuranti?n') print Omschrijving regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From mailinglists at vanwingerde.net Sat Feb 21 11:16:58 2009 From: mailinglists at vanwingerde.net (Jaap van Wingerde) Date: Sat, 21 Feb 2009 17:16:58 +0100 Subject: ordinal not in range In-Reply-To: <49a01719$0$30224$9b4e6d93@newsspool1.arcor-online.net> References: <49a007ea$0$30236$9b4e6d93@newsspool1.arcor-online.net> <49a01719$0$30224$9b4e6d93@newsspool1.arcor-online.net> Message-ID: <49A028FA.90901@vanwingerde.net> Stefan Behnel wrote: > Omschrijving = Omschrijving.replace(u"priv?", u'priv?') > (mind the u"...") > outfile = codecs.open(output, "wb", encoding="UTF-8") > (mind the "wb" for 'write binary/bytes') It works now! > Looks like you'd be happier with Python 3.0, BTW... Python 3 is not in Debian Lenny. With your help I made my first Python-script. This script saves me from hours dumb work. Thanks a lot!! -- Jaap van Wingerde e-mail: 1234567890 at vanwingerde.net From Scott.Daniels at Acm.Org Sat Feb 21 11:49:09 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 21 Feb 2009 08:49:09 -0800 Subject: how to assert that method accepts specific types In-Reply-To: References: <3f26a2f1-94cf-4083-9bda-7076959ad784@k19g2000yqg.googlegroups.com> Message-ID: Rhodri James wrote: > On Sat, 21 Feb 2009 01:12:01 -0000, Darren Dale wrote: >> I would like to assert that a method accepts certain types.... >> from functools import wraps >> def accepts(*types): >> def check_accepts(f): ... >> class Test(object): >> @accepts(int) >> def check(self, obj): >> print obj >> but now I want Test.check to accept an instance of Test as well.... > > An icky but relatively clear way to get around this is to gratuitously > subclass Test: > class AcceptableTest(object): > pass > > class Test(AcceptableTest): > @accepts(int, AcceptableTest) > def check(self, obj): > print obj To Increase the ick, but lowering the name pollution (while making the _source_ read more clearly): class Test(): pass # Just a placeholder for type checking class Test(Test): @accepts(int, Test) def check(self, obj): print obj --Scott David Daniels Scott.Daniels at Acm.Org From rdmurray at bitdance.com Sat Feb 21 11:51:40 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Sat, 21 Feb 2009 16:51:40 +0000 (UTC) Subject: Find the location of a loaded module References: <5879412d-ffba-4fd9-82b7-7e798dc425e3@f3g2000yqf.googlegroups.com> Message-ID: "Gabriel Genellina" wrote: > En Fri, 20 Feb 2009 20:44:21 -0200, Aaron Scott > escribi=F3: > > > So, the problem lies with how Python cached the modules in memory. > > Yes, the modules were in two different locations and yes, the one that > > I specified using its direct path should be the one loaded. The > > problem is, the module isn't always loaded -- if it's already in > > memory, it'll use that instead. And since the modules had the same > > name, Python wouldn't distinguish between them, even though they > > weren't exactly the same. > > Yes, that's how import works. It's barely documented, and you finally > learned it the hard way... I'd argue a little bit with "barely documented". In the reference, the discussion of the import statement starts off saying: Import statements are executed in two steps: (1) find a module, and initialize it if necessary; (2) define a name or names in the local namespace (of the scope where the import statement occurs). The third paragraph then says: The system maintains a table of modules that have been or are being initialized, indexed by module name. This table is accessible as sys.modules. When a module name is found in this table, step (1) is finished. That is pretty up front and unambiguous documentation. However, the consequences of that statement won't be immediately clear on first reading. I think it would have cleared up Aaron's confusion if he'd happened to think to read it. But since he knew the syntax of the import statement already, I'm not surprised he did not read it. The Tutorial, in the section on modules and import, says: A module can contain executable statements as well as function definitions. These statements are intended to initialize the module. They are executed only the first time the module is imported somewhere. This is considerably less precise, if more superficially understandable. I wonder if it would be worth expanding on that statement to mention that the module is not even looked for on disk if a module by that name has already been imported. --RDM From Scott.Daniels at Acm.Org Sat Feb 21 12:07:42 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 21 Feb 2009 09:07:42 -0800 Subject: Wanted: Online Python Course for Credit In-Reply-To: <3d974c13-efcd-48ae-8015-7b4a8812280f@w1g2000prk.googlegroups.com> References: <3d974c13-efcd-48ae-8015-7b4a8812280f@w1g2000prk.googlegroups.com> Message-ID: jsidell wrote: > I'm a high school game development teacher and I have recently > discovered Python to be a great way to introduce computer > programming. I intend to study Python on my own but I can get > professional development credit at my job for taking a Python course. > So I'm looking for an online class that I can get a certificate, > college credit, or something to that effect. Any suggestions would be > greatly appreciated I'd strongly suggest going to PyCon, (sign up for tutorials as well): http://us.pycon.org/2009/about/ I know, you want on-line, but the chance to meet with a group of others, and this PyCon will likely have the best collection of teachers and Python. for example, There is a tutorial: Python for Teachers (Urner/Holden) Also two strongly relevant sections in the scheduled talks: 8. Learning and Teaching Python Programming: The Crunchy Way Dr. Andr? Roberge 88. Seven ways to use Python's new turtle module Mr. Gregor Lingl But make no mistake, you need to mingle when you are there to get the inspiration you'll want. --Scott David Daniels Scott.Daniels at Acm.Org From nagle at animats.com Sat Feb 21 12:21:41 2009 From: nagle at animats.com (John Nagle) Date: Sat, 21 Feb 2009 09:21:41 -0800 Subject: "Byte" type? In-Reply-To: References: <4997aa38$0$1678$742ec2ed@news.sonic.net> <499841bf$0$1624$742ec2ed@news.sonic.net> <499859e2$0$1618$742ec2ed@news.sonic.net> <499f8a8e$0$1588$742ec2ed@news.sonic.net> Message-ID: <49a03081$0$1599$742ec2ed@news.sonic.net> Steve Holden wrote: > John Nagle wrote: >> Steve Holden wrote: >>> John Nagle wrote: >>>> Benjamin Kaplan wrote: >>>>> On Sun, Feb 15, 2009 at 11:57 AM, John Nagle wrote: >>>>> >> ...Re "bytes" not behaving as documented in 2.6: >> >>>> That's indeed how Python 2.6 works. But that's not how >>>> PEP 3137 says it's supposed to work. >>>> >>>> Guido: >>>> >>>> "I propose the following type names at the Python level: >>>> >>>> * bytes is an immutable array of bytes (PyString) >>>> * bytearray is a mutable array of bytes (PyBytes)" >> ... >>>> (Not true in Python 2.6 >>>> Is this a bug, a feature, a documentation error, or bad design? >>>> >>> It's a feature. In fact all that was done to accommodate easier >>> migration to 3.x is easily shown in one statement: >>> >>>>>> str is bytes >>> True >>> >>> So that's why bytes works the way it does in 2.6 ... hence my contested >>> description of it as an "ugly hack". I am happy to withdraw "ugly", but >>> I think "hack" could still be held to apply. >> Agreed. But is this a 2.6 thing, making 2.6 incompatible with 3.0, or >> what? How will 3.x do it? The PEP 3137 way, or the Python 2.6 way? >> >> The way it works in 2.6 makes it necessary to do "ord" conversions >> where they shouldn't be required. >> > Yes, the hack was to achieve a modicum of compatibility with 3.0 without > having to turn the world upside down. > > I haven't used 3.0 enough the say whether bytearray has been correctly > implemented. But I believe the intention is that 3.0 should fully > implement PEP 3137. If "bytes", a new keyword, works differently in 2.6 and 3.0, that was really dumb. There's no old code using "bytes". So converting code to 2.6 means it has to be converted AGAIN for 3.0. That's a good reason to ignore 2.6 as defective. John Nagle From rridge at csclub.uwaterloo.ca Sat Feb 21 12:22:36 2009 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Sat, 21 Feb 2009 12:22:36 -0500 Subject: To unicode or not to unicode References: <499F0CF0.8070800@v.loewis.de> Message-ID: =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= wrote: >I don't think that was the complaint. Instead, the complaint was >that the OP's original message did not have a Content-type header, >and that it was thus impossible to tell what the byte in front of >"Wiki" meant. To properly post either MICRO SIGN or GREEK SMALL LETTER >MU in a usenet or email message, you really must use MIME. (As both >your article and Thorsten's did, by choosing UTF-8) MIME only applies Internet e-mail messages. RFC 1036 doesn't require nor give a meaning to a Content-Type header in a Usenet message, so there's nothing wrong with the original poster's newsreader. In any case what the original poster really should do is come up with a better name for his program Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From aahz at pythoncraft.com Sat Feb 21 12:42:02 2009 From: aahz at pythoncraft.com (Aahz) Date: 21 Feb 2009 09:42:02 -0800 Subject: python contextmanagers and ruby blocks References: <0ca5a9c3-03d3-4824-9c66-c1a3604aa98b@x9g2000yqk.googlegroups.com> Message-ID: In article , Alia K wrote: > >Nevertheless, I remain curious about whether once can use the >contextmanager in python to achieve the full power of ruby's blocks... Short answer: no Longer answer: the way in Python to achieve the full power of Ruby blocks is to write a function. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From lists at cheimes.de Sat Feb 21 12:42:27 2009 From: lists at cheimes.de (Christian Heimes) Date: Sat, 21 Feb 2009 18:42:27 +0100 Subject: "Byte" type? In-Reply-To: <49a03081$0$1599$742ec2ed@news.sonic.net> References: <4997aa38$0$1678$742ec2ed@news.sonic.net> <499841bf$0$1624$742ec2ed@news.sonic.net> <499859e2$0$1618$742ec2ed@news.sonic.net> <499f8a8e$0$1588$742ec2ed@news.sonic.net> <49a03081$0$1599$742ec2ed@news.sonic.net> Message-ID: John Nagle wrote > If "bytes", a new keyword, works differently in 2.6 and 3.0, that was > really > dumb. There's no old code using "bytes". So converting code to 2.6 means > it has to be converted AGAIN for 3.0. That's a good reason to ignore > 2.6 as > defective. Please don't call something dumb that you don't fully understand. It's offenses the people who have spent lots of time developing Python -- personal, unpaid and voluntary time! I can assure, the bytes alias and b'' alias have their right to exist. Christian From aahz at pythoncraft.com Sat Feb 21 12:45:25 2009 From: aahz at pythoncraft.com (Aahz) Date: 21 Feb 2009 09:45:25 -0800 Subject: can multi-core improve single funciton? References: <6a4f17690902092228i31fd1661n41c61c4037a289df@mail.gmail.com> Message-ID: In article , Grant Edwards wrote: >On 2009-02-20, Aahz wrote: >> Steven D'Aprano wrote: >>> >>> As I understand it, there's very little benefit to multi-cores in >>> Python due to the GIL. >> >> As phrased, your statement is completely wrong. Here's a more >> correct phrasing: "For threaded compute-bound applications written >> in pure Python, there's very little benefit to multiple cores." But >> threaded I/O-bound applications do receive some benefit from multiple >> cores, and using multiple processes certainly leverages multiple >> cores. If boosting the performance of a threaded compute-bound >> application is important, one can always write the critical parts in >> C/C++. > >Do the crunchy bits of scipy/numpy, scientific python, vtk and other >compute-intensive libraries tend to release the GIL while they're busy >"computing"? > >[Perhaps using them doesn't count as "pure Python", but...] They definitely do not count as pure Python -- but I probably should have mentioned that there are pre-existing libraries that can be used. It's just that I/O is about the only area where there is a concerted effort to ensure that GIL gets released. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From aahz at pythoncraft.com Sat Feb 21 12:48:21 2009 From: aahz at pythoncraft.com (Aahz) Date: 21 Feb 2009 09:48:21 -0800 Subject: What encoding does u'...' syntax use? References: <499f18bd$0$31879$9b4e6d93@newsspool3.arcor-online.net> <499F397C.7030404@v.loewis.de> Message-ID: In article <499F397C.7030404 at v.loewis.de>, =?ISO-8859-15?Q?=22Martin_v=2E_L=F6wis=22?= wrote: >> Yes, I know that. But every concrete representation of a unicode string >> has to have an encoding associated with it, including unicode strings >> produced by the Python parser when it parses the ascii string "u'\xb5'" >> >> My question is: what is that encoding? > >The internal representation is either UTF-16, or UTF-32; which one is >a compile-time choice (i.e. when the Python interpreter is built). Wait, I thought it was UCS-2 or UCS-4? Or am I misremembering the countless threads about the distinction between UTF and UCS? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From thorsten at thorstenkampe.de Sat Feb 21 13:20:12 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Sat, 21 Feb 2009 19:20:12 +0100 Subject: To unicode or not to unicode References: <499F0CF0.8070800@v.loewis.de> Message-ID: * Ross Ridge (Sat, 21 Feb 2009 12:22:36 -0500) > =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= wrote: > >I don't think that was the complaint. Instead, the complaint was > >that the OP's original message did not have a Content-type header, > >and that it was thus impossible to tell what the byte in front of > >"Wiki" meant. To properly post either MICRO SIGN or GREEK SMALL LETTER > >MU in a usenet or email message, you really must use MIME. (As both > >your article and Thorsten's did, by choosing UTF-8) > > MIME only applies Internet e-mail messages. No, it doesn't: "MIME's use, however, has grown beyond describing the content of e-mail to describing content type in general. [...] The content types defined by MIME standards are also of importance outside of e-mail, such as in communication protocols like HTTP [...]" http://en.wikipedia.org/wiki/MIME > RFC 1036 doesn't require nor give a meaning to a Content-Type header > in a Usenet message Well, /maybe/ the reason for that is that RFC 1036 was written in 1987 and the first MIME RFC in 1992...? The "Son of RFC 1036" mentions MIME more often than you can count. > so there's nothing wrong with the original poster's newsreader. If you follow RFC 1036 (who was written before anyone even thought of MIME) then all content has to ASCII. The OP used non ASCII letters. It's all about declaring your charset. In Python as well as in your newsreader. If you don't declare your charset it's ASCII for you - in Python as well as in your newsreader. Thorsten From thorsten at thorstenkampe.de Sat Feb 21 13:24:23 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Sat, 21 Feb 2009 19:24:23 +0100 Subject: What encoding does u'...' syntax use? References: <499f18bd$0$31879$9b4e6d93@newsspool3.arcor-online.net> <499F397C.7030404@v.loewis.de> Message-ID: * "Martin v. L?wis" (Sat, 21 Feb 2009 00:15:08 +0100) > > Yes, I know that. But every concrete representation of a unicode > > string has to have an encoding associated with it, including unicode > > strings produced by the Python parser when it parses the ascii > > string "u'\xb5'" > > > > My question is: what is that encoding? > > The internal representation is either UTF-16, or UTF-32; which one is > a compile-time choice (i.e. when the Python interpreter is built). I'm pretty much sure it is UCS-2 or UCS-4. (Yes, I know there is only a slight difference to UTF-16/UTF-32). Thorsten From massi_srb at msn.com Sat Feb 21 13:56:03 2009 From: massi_srb at msn.com (Massi) Date: Sat, 21 Feb 2009 10:56:03 -0800 (PST) Subject: Ctypes debug of dll function Message-ID: <1eef6de3-ebfc-45d5-845d-6345a4563c2e@f3g2000yqf.googlegroups.com> Hi everyone, I'm pretty new to the ctypes module and I'm encountering a problem. I'm working under windows xp with python 2.5 and in my script I use ctypes to call from a dll some functions I wrote in C. When I call one of these functions it happens that my script crashes raising the following error: WindowsError: exception: access violation writing 0x00000000 My question is...is there a way to debug my C function from the dll while it is run from the python script? Thanks in advance for the help. From benjamin.kaplan at case.edu Sat Feb 21 14:02:19 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sat, 21 Feb 2009 14:02:19 -0500 Subject: "Byte" type? In-Reply-To: <49a03081$0$1599$742ec2ed@news.sonic.net> References: <4997aa38$0$1678$742ec2ed@news.sonic.net> <499841bf$0$1624$742ec2ed@news.sonic.net> <499859e2$0$1618$742ec2ed@news.sonic.net> <499f8a8e$0$1588$742ec2ed@news.sonic.net> <49a03081$0$1599$742ec2ed@news.sonic.net> Message-ID: On Sat, Feb 21, 2009 at 12:21 PM, John Nagle wrote: > Steve Holden wrote: > >> John Nagle wrote: >> >>> Steve Holden wrote: >>> >>>> John Nagle wrote: >>>> >>>>> Benjamin Kaplan wrote: >>>>> >>>>>> On Sun, Feb 15, 2009 at 11:57 AM, John Nagle >>>>>> wrote: >>>>>> >>>>>> ...Re "bytes" not behaving as documented in 2.6: >>> >>> That's indeed how Python 2.6 works. But that's not how >>>>> PEP 3137 says it's supposed to work. >>>>> >>>>> Guido: >>>>> >>>>> "I propose the following type names at the Python level: >>>>> >>>>> * bytes is an immutable array of bytes (PyString) >>>>> * bytearray is a mutable array of bytes (PyBytes)" >>>>> >>>> ... >>> >>>> (Not true in Python 2.6 >>>>> Is this a bug, a feature, a documentation error, or bad design? >>>>> >>>>> It's a feature. In fact all that was done to accommodate easier >>>> migration to 3.x is easily shown in one statement: >>>> >>>> str is bytes >>>>>>> >>>>>> True >>>> >>>> So that's why bytes works the way it does in 2.6 ... hence my contested >>>> description of it as an "ugly hack". I am happy to withdraw "ugly", but >>>> I think "hack" could still be held to apply. >>>> >>> Agreed. But is this a 2.6 thing, making 2.6 incompatible with 3.0, or >>> what? How will 3.x do it? The PEP 3137 way, or the Python 2.6 way? >>> >>> The way it works in 2.6 makes it necessary to do "ord" conversions >>> where they shouldn't be required. >>> >>> Yes, the hack was to achieve a modicum of compatibility with 3.0 without >> having to turn the world upside down. >> >> I haven't used 3.0 enough the say whether bytearray has been correctly >> implemented. But I believe the intention is that 3.0 should fully >> implement PEP 3137. >> > > If "bytes", a new keyword, works differently in 2.6 and 3.0, that was > really > dumb. There's no old code using "bytes". So converting code to 2.6 means > it has to be converted AGAIN for 3.0. That's a good reason to ignore 2.6 > as > defective. > """ The primary use of bytes in 2.6 will be to write tests of object type such as isinstance(x, bytes). This will help the 2to3 converter, which can't tell whether 2.x code intends strings to contain either characters or 8-bit bytes; you can now use either bytes or strto represent your intention exactly, and the resulting code will also be correct in Python 3.0. """ The reason for putting bytes (a new type, not a keyword) into 2.6 was purely for use in the 2to3 tool. It is designed to break less code on the conversion from 2.x to 3.x, not to add extra features to 2.6+. > > John Nagle > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bkline at rksystems.com Sat Feb 21 14:16:12 2009 From: bkline at rksystems.com (Bob Kline) Date: Sat, 21 Feb 2009 14:16:12 -0500 Subject: Change in cgi handling of POST requests In-Reply-To: References: Message-ID: Aahz wrote: > Interesting. Nobody has responded, so I suggest first filing a report > using bugs.python.org and then asking on python-dev (with reference to > your report). http://bugs.python.org/issue5340 Cheers, Bob From denis.kasak at gmail.com Sat Feb 21 14:32:10 2009 From: denis.kasak at gmail.com (Denis Kasak) Date: Sat, 21 Feb 2009 20:32:10 +0100 Subject: What encoding does u'...' syntax use? In-Reply-To: References: <499f18bd$0$31879$9b4e6d93@newsspool3.arcor-online.net> <499F397C.7030404@v.loewis.de> Message-ID: <39e19a010902211132m39730333vd8d76f334115d206@mail.gmail.com> On Sat, Feb 21, 2009 at 7:24 PM, Thorsten Kampe wrote: > > I'm pretty much sure it is UCS-2 or UCS-4. (Yes, I know there is only a > slight difference to UTF-16/UTF-32). I wouldn't call the difference that slight, especially between UTF-16 and UCS-2, since the former can encode all Unicode code points, while the latter can only encode those in the BMP. -- Denis Kasak From rridge at csclub.uwaterloo.ca Sat Feb 21 14:52:09 2009 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Sat, 21 Feb 2009 14:52:09 -0500 Subject: To unicode or not to unicode References: <499F0CF0.8070800@v.loewis.de> Message-ID: Thorsten Kampe wrote: >> RFC 1036 doesn't require nor give a meaning to a Content-Type header >> in a Usenet message > >Well, /maybe/ the reason for that is that RFC 1036 was written in 1987 >and the first MIME RFC in 1992...? Obviously. >"Son of RFC 1036" mentions MIME more often than you can count. Since it was never sumbitted and accepted, RFC 1036 remains current. >> so there's nothing wrong with the original poster's newsreader. > >If you follow RFC 1036 (who was written before anyone even thought of >MIME) then all content has to ASCII. The OP used non ASCII letters. RFC 1036 doesn't place any restrictions on the content on the body of an article. On the other hand "Son of RFC 1036" does have restrictions on characters used in the body of message: Articles MUST not contain any octet with value exceeding 127, i.e. any octet that is not an ASCII character Which means that merely adding a Content-Encoding header wouldn't be enough to conform to "Son of RFC 1036", the original poster would also have had to either switch to a 7-bit character set or use a 7-bit compatible transfer encoding. If you trying to claim that "Son of RFC 1036" is the new defacto standard, then that would mean your newsreader is broken too. >It's all about declaring your charset. In Python as well as in your >newsreader. If you don't declare your charset it's ASCII for you - in >Python as well as in your newsreader. Except in practice unlike Python, many newsreaders don't assume ASCII. The original article displayed fine for me. Google Groups displays it correctly too: http://groups.google.com/group/comp.lang.python/msg/828fefd7040238bc I could just as easily argue that assuming ISO 8859-1 is the defacto standard, and that its your newsreader that's broken. The reality however is that RFC 1036 is the only standard for Usenet messages, defacto or otherwise, and so there's nothing wrong with anyone's newsreader. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From martin at v.loewis.de Sat Feb 21 15:06:27 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 21 Feb 2009 21:06:27 +0100 Subject: What encoding does u'...' syntax use? In-Reply-To: References: <499f18bd$0$31879$9b4e6d93@newsspool3.arcor-online.net> <499F397C.7030404@v.loewis.de> Message-ID: <49A05EC3.6080209@v.loewis.de> >>> My question is: what is that encoding? >> The internal representation is either UTF-16, or UTF-32; which one is >> a compile-time choice (i.e. when the Python interpreter is built). > > Wait, I thought it was UCS-2 or UCS-4? Or am I misremembering the > countless threads about the distinction between UTF and UCS? You are not misremembering. I personally never found them conclusive, and, with PEP 261, I think, calling the 2-byte version "UCS-2" is incorrect. Regards, Martin From martin at v.loewis.de Sat Feb 21 15:10:30 2009 From: martin at v.loewis.de (=?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=) Date: Sat, 21 Feb 2009 21:10:30 +0100 Subject: What encoding does u'...' syntax use? In-Reply-To: References: <499f18bd$0$31879$9b4e6d93@newsspool3.arcor-online.net> <499F397C.7030404@v.loewis.de> Message-ID: <49a05fb6$0$30900$9b622d9e@news.freenet.de> >> I'm pretty much sure it is UCS-2 or UCS-4. (Yes, I know there is only a >> slight difference to UTF-16/UTF-32). > > I wouldn't call the difference that slight, especially between UTF-16 > and UCS-2, since the former can encode all Unicode code points, while > the latter can only encode those in the BMP. Indeed. As Python *can* encode all characters even in 2-byte mode (since PEP 261), it seems clear that Python's Unicode representation is *not* strictly UCS-2 anymore. Regards, Martin From rozzin at geekspace.com Sat Feb 21 15:13:26 2009 From: rozzin at geekspace.com (Joshua Judson Rosen) Date: Sat, 21 Feb 2009 15:13:26 -0500 Subject: `high overhead of multiple Python processes' (was: Will multithreading make python less popular?) References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <28e3612d-2e91-4a91-82cb-5fb2deda95fd@q9g2000yqc.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> <7x8wo2kwoz.fsf@ruckus.brouhaha.com> <975d0b81-0810-43c2-9734-b7a5a890e431@k19g2000prh.googlegroups.com> <7x3aeadqlo.fsf@ruckus.brouhaha.com> Message-ID: <87mycfczvd.fsf_-_@slice.rozzin.com> Paul Rubin writes: > > Right, that's basically the issue here: the cost of using multiple > Python processes is unnecessarily high. If that cost were lower then > we could more easily use multiple cores to make oru apps faster. What cost is that? At least on unix systems, fork() tends have *trivial* overhead in terms of both time and space, because the processes use lazy copy-on-write memory underneath, so the real costs of resource-consumption for spawning a new process vs. spawning a new thread should be comparable. Are you referring to overhead associated with inter-process communication? If so, what overhead is that? -- Don't be afraid to ask (Lf.((Lx.xx) (Lr.f(rr)))). From john.weatherwax at gmail.com Sat Feb 21 15:22:38 2009 From: john.weatherwax at gmail.com (john.weatherwax at gmail.com) Date: Sat, 21 Feb 2009 12:22:38 -0800 (PST) Subject: urllib2 login help Message-ID: <4612e1c1-3e1e-48ee-9780-312fff074bad@i38g2000yqd.googlegroups.com> Hello, I'm having trouble using urllib2 (maybe) when trying to log into a web site that requires a user to enter a login name and a password (authentication). I've tried many things but none seem to work and have become stuck recently and was hoping to get a hint from those much more knowledgeable than myself. I want to automate logging on to the investopedia stock simulator web site. http://simulator.investopedia.com/authorization/login.aspx I can't seem to automate this successfully. My python script is below: import os,re import urllib, urllib2 theurl = "http://simulator.investopedia.com/authorization/login.aspx" post_dict = { "ct100$MainPlaceHolder$usernameText": "XXX", "ct100$MainPlaceHolder$passwordText": "XXX", "ct100$MainPlaceHolder $loginButton": "Sign In", "ct100$MainPlaceHolder$rememberMeCheckBox": "on" } post_data = urllib.urlencode( post_dict ) headers = { 'User-agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)', 'Host': 'simulator.investopedia.com', 'Referer': 'http://simulator.investopedia.com/ authorization/login.aspx', } req = urllib2.Request( theurl, post_data, headers ) response = urllib2.urlopen(req) the_page = response.read() The problem is that this page returned seems to be the same as the login page which I connected to initially. When I perform the login process manually things work as expected. What am I doing incorrectly? *ANY* hints/suggestions/directions would be very appreciated since I've run out of ideas of things to try at this point. Thanks very much From denis.kasak at gmail.com Sat Feb 21 15:24:30 2009 From: denis.kasak at gmail.com (Denis Kasak) Date: Sat, 21 Feb 2009 21:24:30 +0100 Subject: What encoding does u'...' syntax use? In-Reply-To: <49a05fb6$0$30900$9b622d9e@news.freenet.de> References: <499f18bd$0$31879$9b4e6d93@newsspool3.arcor-online.net> <499F397C.7030404@v.loewis.de> <49a05fb6$0$30900$9b622d9e@news.freenet.de> Message-ID: <39e19a010902211224v3f9a28dbt978fed7a5696a510@mail.gmail.com> On Sat, Feb 21, 2009 at 9:10 PM, "Martin v. L?wis" wrote: >>> I'm pretty much sure it is UCS-2 or UCS-4. (Yes, I know there is only a >>> slight difference to UTF-16/UTF-32). >> >> I wouldn't call the difference that slight, especially between UTF-16 >> and UCS-2, since the former can encode all Unicode code points, while >> the latter can only encode those in the BMP. > > Indeed. As Python *can* encode all characters even in 2-byte mode > (since PEP 261), it seems clear that Python's Unicode representation > is *not* strictly UCS-2 anymore. Since we're already discussing this, I'm curious - why was UCS-2 chosen over plain UTF-16 or UTF-8 in the first place for Python's internal storage? -- Denis Kasak From apt.shansen at gmail.com Sat Feb 21 15:36:56 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sat, 21 Feb 2009 12:36:56 -0800 Subject: urllib2 login help In-Reply-To: <4612e1c1-3e1e-48ee-9780-312fff074bad@i38g2000yqd.googlegroups.com> References: <4612e1c1-3e1e-48ee-9780-312fff074bad@i38g2000yqd.googlegroups.com> Message-ID: <7a9c25c20902211236y28e14833y1e475ea0cc0c9829@mail.gmail.com> > > *ANY* hints/suggestions/directions would be very appreciated since > I've run out of ideas of things to try at this point. > The last time I heard something like this, I suggested that the problem might be cookies -- and it ended up working for the person I believe. http://groups.google.com/group/comp.lang.python/browse_thread/thread/4d78de927ee1e549 --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From rhamph at gmail.com Sat Feb 21 15:39:22 2009 From: rhamph at gmail.com (Adam Olsen) Date: Sat, 21 Feb 2009 12:39:22 -0800 (PST) Subject: What encoding does u'...' syntax use? References: <499f18bd$0$31879$9b4e6d93@newsspool3.arcor-online.net> <499F397C.7030404@v.loewis.de> Message-ID: <06779757-e822-4cba-adba-69f669acf92c@k19g2000yqg.googlegroups.com> On Feb 21, 10:48?am, a... at pythoncraft.com (Aahz) wrote: > In article <499F397C.7030... at v.loewis.de>, > > =?ISO-8859-15?Q?=22Martin_v=2E_L=F6wis=22?= ? wrote: > >> Yes, I know that. ?But every concrete representation of a unicode string > >> has to have an encoding associated with it, including unicode strings > >> produced by the Python parser when it parses the ascii string "u'\xb5'" > > >> My question is: what is that encoding? > > >The internal representation is either UTF-16, or UTF-32; which one is > >a compile-time choice (i.e. when the Python interpreter is built). > > Wait, I thought it was UCS-2 or UCS-4? ?Or am I misremembering the > countless threads about the distinction between UTF and UCS? Nope, that's partly mislabeling and partly a bug. UCS-2/UCS-4 refer to Unicode 1.1 and earlier, with no surrogates. We target Unicode 5.1. If you naively encode UCS-2 as UTF-8 you really end up with CESU-8. You miss the step where you combine surrogate pairs (which only exist in UTF-16) into a single supplementary character. Lo and behold, that's actually what current python does in some places. It's not pretty. See bugs #3297 and #3672. From martin at v.loewis.de Sat Feb 21 15:45:09 2009 From: martin at v.loewis.de (=?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=) Date: Sat, 21 Feb 2009 21:45:09 +0100 Subject: What encoding does u'...' syntax use? In-Reply-To: <39e19a010902211224v3f9a28dbt978fed7a5696a510@mail.gmail.com> References: <499f18bd$0$31879$9b4e6d93@newsspool3.arcor-online.net> <499F397C.7030404@v.loewis.de> <49a05fb6$0$30900$9b622d9e@news.freenet.de> <39e19a010902211224v3f9a28dbt978fed7a5696a510@mail.gmail.com> Message-ID: <49A067D5.9000404@v.loewis.de> >> Indeed. As Python *can* encode all characters even in 2-byte mode >> (since PEP 261), it seems clear that Python's Unicode representation >> is *not* strictly UCS-2 anymore. > > Since we're already discussing this, I'm curious - why was UCS-2 > chosen over plain UTF-16 or UTF-8 in the first place for Python's > internal storage? You mean, originally? Originally, the choice was only between UCS-2 and UCS-4; choice was in favor of UCS-2 because of size concerns. UTF-8 was ruled out easily because it doesn't allow constant-size indexing; UTF-16 essentially for the same reason (plus there was no point to UTF-16, since there were no assigned characters outside the BMP). Regards, Martin From denis.kasak at gmail.com Sat Feb 21 15:48:05 2009 From: denis.kasak at gmail.com (Denis Kasak) Date: Sat, 21 Feb 2009 21:48:05 +0100 Subject: What encoding does u'...' syntax use? In-Reply-To: <49A067D5.9000404@v.loewis.de> References: <499f18bd$0$31879$9b4e6d93@newsspool3.arcor-online.net> <499F397C.7030404@v.loewis.de> <49a05fb6$0$30900$9b622d9e@news.freenet.de> <39e19a010902211224v3f9a28dbt978fed7a5696a510@mail.gmail.com> <49A067D5.9000404@v.loewis.de> Message-ID: <39e19a010902211248h280b4949q7279b88fafe93c62@mail.gmail.com> On Sat, Feb 21, 2009 at 9:45 PM, "Martin v. L?wis" wrote: >>> Indeed. As Python *can* encode all characters even in 2-byte mode >>> (since PEP 261), it seems clear that Python's Unicode representation >>> is *not* strictly UCS-2 anymore. >> >> Since we're already discussing this, I'm curious - why was UCS-2 >> chosen over plain UTF-16 or UTF-8 in the first place for Python's >> internal storage? > > You mean, originally? Originally, the choice was only between UCS-2 > and UCS-4; choice was in favor of UCS-2 because of size concerns. > UTF-8 was ruled out easily because it doesn't allow constant-size > indexing; UTF-16 essentially for the same reason (plus there was > no point to UTF-16, since there were no assigned characters outside > the BMP). Yes, I failed to realise how long ago the unicode data type was implemented originally. :-) Thanks for the explanation. -- Denis Kasak From thorsten at thorstenkampe.de Sat Feb 21 16:05:39 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Sat, 21 Feb 2009 22:05:39 +0100 Subject: To unicode or not to unicode References: <499F0CF0.8070800@v.loewis.de> Message-ID: * Ross Ridge (Sat, 21 Feb 2009 14:52:09 -0500) > Thorsten Kampe wrote: >> It's all about declaring your charset. In Python as well as in your >> newsreader. If you don't declare your charset it's ASCII for you - in >> Python as well as in your newsreader. > > Except in practice unlike Python, many newsreaders don't assume ASCII. They assume ASCII - unless you declare your charset (the exception being Outlook Express and a few Windows newsreaders). Everything else is "guessing". > The original article displayed fine for me. Google Groups displays it > correctly too: > > http://groups.google.com/group/comp.lang.python/msg/828fefd7040238bc Your understanding of the principles of Unicode is as least as non- existant as the OP's. > I could just as easily argue that assuming ISO 8859-1 is the defacto > standard, and that its your newsreader that's broken. There is no "standard" in regard to guessing (this is what you call "assuming"). The need for explicit declaration of an encoding is exactly the same in Python as in any Usenet article. > The reality however is that RFC 1036 is the only standard for Usenet > messages, defacto or otherwise, and so there's nothing wrong with > anyone's newsreader. The reality is that all non-broken newsreaders use MIME headers to declare and interpret the charset being used. I suggest you read at least http://www.joelonsoftware.com/articles/Unicode.html to get an idea of Unicode and associated topics. Thorsten From odeits at gmail.com Sat Feb 21 16:12:32 2009 From: odeits at gmail.com (odeits) Date: Sat, 21 Feb 2009 13:12:32 -0800 (PST) Subject: Pythonic way to determine if one char of many in a string References: <1234761457.20683.1300568627@webmail.messagingengine.com> <8666ef66-288d-426a-9622-9d68d1f7971c@b40g2000pri.googlegroups.com> <9f03fc9d-7136-4372-8116-a999fb67bf87@p23g2000prp.googlegroups.com> Message-ID: <9e7c7dc9-deb4-4cdb-99a3-411d89ce73b6@e18g2000yqo.googlegroups.com> On Feb 21, 12:47?am, "Gabriel Genellina" wrote: > En Sat, 21 Feb 2009 01:14:02 -0200, odeits escribi?: > > > > > On Feb 15, 11:31?pm, odeits wrote: > >> It seems what you are actually testing for is if the intersection of > >> the two sets is not empty where the first set is the characters in > >> your word and the second set is the characters in your defined string. > > > To expand on what I was saying I thought i should provide a code > > snippet: > > > WORD = 'g' * 100 > > WORD2 = 'g' * 50 + 'U' > > VOWELS = 'aeiouAEIOU' > > BIGWORD = 'g' * 10000 + 'U' > > > def set_test(vowels, word): > > > ? ? vowels = set( iter(vowels)) > > ? ? letters = set( iter(word) ) > > > ? ? if letters & vowels: > > ? ? ? ? return True > > ? ? else: > > ? ? ? ? return False > > > with python 2.5 I got 1.30 usec/pass against the BIGWORD > > You could make it slightly faster by removing the iter() call: letters = ? > set(word) > And (if vowels are really constant) you could pre-build the vowels set. > > -- > Gabriel Genellina set(word) = set{[word]} meaning a set with one element, the string the call to iter makes it set of the letters making up the word. From alia_khouri at yahoo.com Sat Feb 21 16:31:07 2009 From: alia_khouri at yahoo.com (Alia K) Date: Sat, 21 Feb 2009 13:31:07 -0800 (PST) Subject: python contextmanagers and ruby blocks References: <0ca5a9c3-03d3-4824-9c66-c1a3604aa98b@x9g2000yqk.googlegroups.com> Message-ID: Aahz wrote: > Longer answer: the way in Python to achieve the full power of Ruby > blocks is to write a function. You are most likely right... there is probably no need to introduce ruby-like blocks to python where iteration comes naturally with list comprehensions and generators. But for the simple case of entering a block of code as one does with @contextmanager I suppose it would be nice to make a generator with a single yield statement a contextmanager by default such that: >>> def g(): ... print "a" ... yield ... print "b" ... >>> with g(): ... print "c" ... a c b would be equivalent to >>> from __future__ import with_statement >>> from contextlib import contextmanager >>> @contextmanager ... def g(): ... print "a" ... yield ... print "b" ... >>> with g(): ... print "c" ... a c b but then again, I suppose "explicit is better than implicit"... AK From http Sat Feb 21 17:02:27 2009 From: http (Paul Rubin) Date: 21 Feb 2009 14:02:27 -0800 Subject: `high overhead of multiple Python processes' (was: Will multithreading make python less popular?) References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com> <28e3612d-2e91-4a91-82cb-5fb2deda95fd@q9g2000yqc.googlegroups.com> <04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com> <6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com> <4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com> <7x8wo2kwoz.fsf@ruckus.brouhaha.com> <975d0b81-0810-43c2-9734-b7a5a890e431@k19g2000prh.googlegroups.com> <7x3aeadqlo.fsf@ruckus.brouhaha.com> <87mycfczvd.fsf_-_@slice.rozzin.com> Message-ID: <7xfxi75tzg.fsf@ruckus.brouhaha.com> Joshua Judson Rosen writes: > > Right, that's basically the issue here: the cost of using multiple > > Python processes is unnecessarily high. > What cost is that? The cost of messing with the multiprocessing module instead of having threads work properly, and the overhead of serializing Python data structures to send to another process by IPC, instead of using the same object in two threads. Also, one way I often use threading is by sending function objects to another thread through a Queue, so the other thread can evaluate the function. I don't think multiprocessing gives a way to serialize functions, though maybe something like it can be done at higher nuisance using classes. From rridge at csclub.uwaterloo.ca Sat Feb 21 17:07:35 2009 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Sat, 21 Feb 2009 17:07:35 -0500 Subject: To unicode or not to unicode References: Message-ID: Ross Ridge (Sat, 21 Feb 2009 14:52:09 -0500) > Except in practice unlike Python, many newsreaders don't assume ASCII. Thorsten Kampe wrote: >They assume ASCII - unless you declare your charset (the exception being >Outlook Express and a few Windows newsreaders). Everything else is >"guessing". No, it's an assumption like the way Python by default assumes ASCII. >> The original article displayed fine for me. Google Groups displays it >> correctly too: >> >> http://groups.google.com/group/comp.lang.python/msg/828fefd7040238bc > >Your understanding of the principles of Unicode is as least as non- >existant as the OP's. The link demonstrates that Google Groups doesn't assume ASCII like Python does. Since popular newsreaders like Google Groups and Outlook Express can display the message correctly without the MIME headers, but your obscure one can't, there's a much stronger case to made that it's your newsreader that's broken. >> I could just as easily argue that assuming ISO 8859-1 is the defacto >> standard, and that its your newsreader that's broken. > >There is no "standard" in regard to guessing (this is what you call >"assuming"). The need for explicit declaration of an encoding is exactly >the same in Python as in any Usenet article. No, many newsreaders don't assume ASCII by default like Python. >> The reality however is that RFC 1036 is the only standard for Usenet >> messages, defacto or otherwise, and so there's nothing wrong with >> anyone's newsreader. > >The reality is that all non-broken newsreaders use MIME headers to >declare and interpret the charset being used. Since RFC 1036 doesn't require MIME headers a reader that doesn't generate them is by definition not broken. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From rdmurray at bitdance.com Sat Feb 21 17:24:51 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Sat, 21 Feb 2009 22:24:51 +0000 (UTC) Subject: Pythonic way to determine if one char of many in a string References: <1234761457.20683.1300568627@webmail.messagingengine.com> <8666ef66-288d-426a-9622-9d68d1f7971c@b40g2000pri.googlegroups.com> <9f03fc9d-7136-4372-8116-a999fb67bf87@p23g2000prp.googlegroups.com> <9e7c7dc9-deb4-4cdb-99a3-411d89ce73b6@e18g2000yqo.googlegroups.com> Message-ID: odeits wrote: > On Feb 21, 12:47=A0am, "Gabriel Genellina" > wrote: > > En Sat, 21 Feb 2009 01:14:02 -0200, odeits escribi=F3: > > > > > On Feb 15, 11:31=A0pm, odeits wrote: > > >> It seems what you are actually testing for is if the intersection of > > >> the two sets is not empty where the first set is the characters in > > >> your word and the second set is the characters in your defined string. > > > > > To expand on what I was saying I thought i should provide a code > > > snippet: > > > > > WORD = 'g' * 100 > > > WORD2 = 'g' * 50 + 'U' > > > VOWELS = 'aeiouAEIOU' > > > BIGWORD = 'g' * 10000 + 'U' > > > > > def set_test(vowels, word): > > > > > vowels = set( iter(vowels)) > > > letters = set( iter(word) ) > > > > > if letters & vowels: > > > return True > > > else: > > > return False > > > > > with python 2.5 I got 1.30 usec/pass against the BIGWORD > > > > You could make it slightly faster by removing the iter() call: > > letters = set(word) > > And (if vowels are really constant) you could pre-build the vowels set. > > set(word) = set{[word]} meaning a set with one element, the string > the call to iter makes it set of the letters making up the word. Did you try it? Python 2.6.1 (r261:67515, Jan 7 2009, 17:09:13) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> set('abcd') set(['a', 'c', 'b', 'd']) --RDM From pavlovevidence at gmail.com Sat Feb 21 17:24:55 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 21 Feb 2009 14:24:55 -0800 (PST) Subject: To unicode or not to unicode References: Message-ID: On Feb 19, 6:57?pm, Ron Garret wrote: > I'm writing a little wiki that I call ?Wiki. ?That's a lowercase Greek > mu at the beginning (it's pronounced micro-wiki). ?It's working, except > that I can't actually enter the name of the wiki into the wiki itself > because the default unicode encoding on my Python installation is > "ascii". ?So I'm trying to decide on a course of action. ?There seem to > be three possibilities: > > 1. ?Change the code to properly support unicode. ?Preliminary > investigations indicate that this is going to be a colossal pain in the > ass. > > 2. ?Change the default encoding on my Python installation to be latin-1 > or UTF8. ?The disadvantage to this is that no one else will be able to > run my code without making the same change to their installation, since > you can't change default encodings once Python has started. > > 3. ?Punt and spell it 'uwiki' instead. > > I'm feeling indecisive so I thought I'd ask other people's opinion. ? > What should I do? > > rg From ethan at stoneleaf.us Sat Feb 21 17:44:42 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 21 Feb 2009 14:44:42 -0800 Subject: datetime.time and midnight Message-ID: <49A083DA.7000107@stoneleaf.us> Greetings, List! I was curious if anyone knew the rationale behind making midnight False? --> import datetime --> midnight = datetime.time(0,0,0) --> bool(midnight) False To my way of thinking, midnight does actually exist so it should be true. If datetime.time was measuring an *amount* of time, rather than a certain point during the day, then a time of 0:0:0 should certainly be False as it would mean no time had passed. However, since midnight does indeed exist (as many programmers have observed when deadlines approach ;) I would think it should be true. -- ~Ethan~ From thorsten at thorstenkampe.de Sat Feb 21 17:52:03 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Sat, 21 Feb 2009 23:52:03 +0100 Subject: To unicode or not to unicode References: Message-ID: * Ross Ridge (Sat, 21 Feb 2009 17:07:35 -0500) > The link demonstrates that Google Groups doesn't assume ASCII like > Python does. Since popular newsreaders like Google Groups and Outlook > Express can display the message correctly without the MIME headers, > but your obscure one can't, there's a much stronger case to made that > it's your newsreader that's broken. *sigh* I give up on you. You didn't even read the "Joel on Software" article. The whole "why" and "what for" of Unicode and MIME will always be a complete mystery to you. T. From rridge at csclub.uwaterloo.ca Sat Feb 21 18:06:35 2009 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Sat, 21 Feb 2009 18:06:35 -0500 Subject: To unicode or not to unicode References: Message-ID: Ross Ridge (Sat, 21 Feb 2009 17:07:35 -0500) > The link demonstrates that Google Groups doesn't assume ASCII like > Python does. Since popular newsreaders like Google Groups and Outlook > Express can display the message correctly without the MIME headers, > but your obscure one can't, there's a much stronger case to made that > it's your newsreader that's broken. Thorsten Kampe wrote: >*sigh* I give up on you. You didn't even read the "Joel on Software" >article. The whole "why" and "what for" of Unicode and MIME will always >be a complete mystery to you. I understand what Unicode and MIME are for and why they exist. Neither their merits nor your insults change the fact that the only current standard governing the content of Usenet posts doesn't require their use. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From aahz at pythoncraft.com Sat Feb 21 18:29:32 2009 From: aahz at pythoncraft.com (Aahz) Date: 21 Feb 2009 15:29:32 -0800 Subject: zlib interface semi-broken References: <20090210205739.GT6522@subspacefield.org> Message-ID: In article , Travis wrote: > >So I've submitted a patch to bugs.python.org to add a new member >called is_finished to the zlib decompression object. > >Issue 5210, file 13056, msg 81780 You may also want to bring this up on the python-ideas mailing list for further discussion. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From thorsten at thorstenkampe.de Sat Feb 21 18:35:35 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Sun, 22 Feb 2009 00:35:35 +0100 Subject: To unicode or not to unicode References: Message-ID: * Ross Ridge (Sat, 21 Feb 2009 18:06:35 -0500) > > The link demonstrates that Google Groups doesn't assume ASCII like > > Python does. Since popular newsreaders like Google Groups and Outlook > > Express can display the message correctly without the MIME headers, > > but your obscure one can't, there's a much stronger case to made that > > it's your newsreader that's broken. > > Thorsten Kampe wrote: > >*sigh* I give up on you. You didn't even read the "Joel on Software" > >article. The whole "why" and "what for" of Unicode and MIME will always > >be a complete mystery to you. > > I understand what Unicode and MIME are for and why they exist. Neither > their merits nor your insults change the fact that the only current > standard governing the content of Usenet posts doesn't require their > use. That's right. As long as you use pure ASCII you can skip this nasty step of informing other people which charset you are using. If you do use non ASCII then you have to do that. That's the way virtually all newsreaders work. It has nothing to do with some 21+ year old RFC. Even your Google Groups "newsreader" does that ('content="text/html; charset=UTF-8"'). Being explicit about your encoding is 99% of the whole Unicode magic in Python and in any communication across the Internet (may it be NNTP, SMTP or HTTP). Your Google Groups simply uses heuristics to guess the encoding the OP probably used. Windows newsreaders simply use the locale of the local host. That's guessing. You can call it assuming but it's still guessing. There is no way you can be sure without any declaration. And it's unpythonic. Python "assumes" ASCII and if the decodes/encoded text doesn't fit that encoding it refuses to guess. T. From google at mrabarnett.plus.com Sat Feb 21 18:55:23 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sat, 21 Feb 2009 23:55:23 +0000 Subject: datetime.time and midnight In-Reply-To: <49A083DA.7000107@stoneleaf.us> References: <49A083DA.7000107@stoneleaf.us> Message-ID: <49A0946B.8040206@mrabarnett.plus.com> Ethan Furman wrote: > Greetings, List! > > I was curious if anyone knew the rationale behind making midnight False? > > --> import datetime > --> midnight = datetime.time(0,0,0) > --> bool(midnight) > False > > To my way of thinking, midnight does actually exist so it should be > true. If datetime.time was measuring an *amount* of time, rather than a > certain point during the day, then a time of 0:0:0 should certainly be > False as it would mean no time had passed. However, since midnight does > indeed exist (as many programmers have observed when deadlines approach > ;) I would think it should be true. > I think it's because midnight is to the time of day what zero is to integers, or an empty string is to strings, or an empty container ... From Graham.Dumpleton at gmail.com Sat Feb 21 18:58:45 2009 From: Graham.Dumpleton at gmail.com (Graham Dumpleton) Date: Sat, 21 Feb 2009 15:58:45 -0800 (PST) Subject: multiprocessing module and os.close(sys.stdin.fileno()) References: <3098ffc2-6884-4a35-99a5-ee917442af25@r37g2000prr.googlegroups.com> <87bpswe57v.fsf@slice.rozzin.com> Message-ID: <83c3925e-6456-4d84-8490-7e1ef66b3c4b@41g2000yqf.googlegroups.com> On Feb 21, 4:20?pm, Joshua Judson Rosen wrote: > Jesse Noller writes: > > > On Tue, Feb 17, 2009 at 10:34 PM, Graham Dumpleton > > wrote: > > > Why is the multiprocessing module, ie., multiprocessing/process.py, in > > > _bootstrap() doing: > > > > ?os.close(sys.stdin.fileno()) > > > > rather than: > > > > ?sys.stdin.close() > > > > Technically it is feasible that stdin could have been replaced with > > > something other than a file object, where the replacement doesn't have > > > a fileno() method. > > > > In that sort of situation an AttributeError would be raised, which > > > isn't going to be caught as either OSError or ValueError, which is all > > > the code watches out for. > > > I don't know why it was implemented that way. File an issue on the > > tracker and assign it to me (jnoller) please. > > My guess would be: because it's also possible for sys.stdin to be a > file that's open in read+*write* mode, and for that file to have > pending output buffered (for example, in the case of a socketfile). If you are going to have a file that is writable as well as readable, such as a socket, then likely that sys.stdout/sys.stderr are going to be bound to it at the same time. If that is the case then one should not be using close() at all as it will then also close the write side of the pipe and cause errors when code subsequently attempts to write to sys.stdout/sys.stderr. In the case of socket you would actually want to use shutdown() to close just the input side of the socket. What this all means is that what is the appropriate thing to do is going to depend on the environment in which the code is used. Thus, having the behaviour hard wired a certain way is really bad. There perhaps instead should be a way of a user providing a hook function to be called to perform any case specific cleanup of stdin, stdout and stderr, or otherwise reassign them. That this is currently in the _bootstrap() function, which does other important stuff, doesn't exactly make it look like it is easily overridden to work for a specific execution environment which is different to the norm. > There's a general guideline, inherited from C, that one should ensure > that the higher-level close() routine is invoked on a given > file-descriptor in at most *one* process after that descriptor has > passed through a fork(); in the other (probably child) processes, the > lower-level close() routine should be called to avoid a > double-flush--whereby buffered data is flushed out of one process, and > then the *same* buffered data is flushed out of the (other) > child-/parent-process' copy of the file-object. > > So, if you call sys.stdin.close() in the child-process in > _bootstrap(), then it could lead to a double-flush corrupting output > somewhere in the application that uses the multiprocessing module. > > You can expect similar issues with just about /any/ `file-like objects' > that might have `file-like semantics' of buffering data and flushing > it on close, also--because you end up with multiple copies of the same > object in `pre-flush' state, and each copy tries to flush at some point. > > As such, I'd recommend against just using .close(); you might use > something like `if hasattr(sys.stdin, "fileno"): ...'; but, if your > `else' clause unconditionally calls sys.stdin.close(), then you still > have double-flush problems if someone's set sys.stdin to a file-like > object with output-buffering. > > I guess you could try calling that an `edge-case' and seeing if anyone > screams. It'd be sort-of nice if there was finer granularity in the > file API--maybe if file.close() took a boolean `flush' argument.... Graham From rridge at csclub.uwaterloo.ca Sat Feb 21 19:39:42 2009 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Sat, 21 Feb 2009 19:39:42 -0500 Subject: To unicode or not to unicode References: Message-ID: Ross Ridge (Sat, 21 Feb 2009 18:06:35 -0500) > I understand what Unicode and MIME are for and why they exist. Neither > their merits nor your insults change the fact that the only current > standard governing the content of Usenet posts doesn't require their > use. Thorsten Kampe wrote: >That's right. As long as you use pure ASCII you can skip this nasty step >of informing other people which charset you are using. If you do use non >ASCII then you have to do that. That's the way virtually all newsreaders >work. It has nothing to do with some 21+ year old RFC. Even your Google >Groups "newsreader" does that ('content="text/html; charset=UTF-8"'). No, the original post demonstrates you don't have include MIME headers for ISO 8859-1 text to be properly displayed by many newsreaders. The fact that your obscure newsreader didn't display it properly doesn't mean that original poster's newsreader is broken. >Being explicit about your encoding is 99% of the whole Unicode magic in >Python and in any communication across the Internet (may it be NNTP, >SMTP or HTTP). HTTP requires the assumption of ISO 8859-1 in the absense of any specified encoding. >Your Google Groups simply uses heuristics to guess the >encoding the OP probably used. Windows newsreaders simply use the locale >of the local host. That's guessing. You can call it assuming but it's >still guessing. There is no way you can be sure without any declaration. Newsreaders assuming ISO 8859-1 instead of ASCII doesn't make it a guess. It's just a different assumption, nor does making an assumption, ASCII or ISO 8850-1, give you any certainty. >And it's unpythonic. Python "assumes" ASCII and if the decodes/encoded >text doesn't fit that encoding it refuses to guess. Which is reasonable given that Python is programming language where it's better to have more conservative assumption about encodings so errors can be more quickly diagnosed. A newsreader however is a different beast, where it's better to make a less conservative assumption that's more likely to display messages correctly to the user. Assuming ISO 8859-1 in the absense of any specified encoding allows the message to be correctly displayed if the character set is either ISO 8859-1 or ASCII. Doing things the "pythonic" way and assuming ASCII only allows such messages to be displayed if ASCII is used. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From odeits at gmail.com Sat Feb 21 19:53:25 2009 From: odeits at gmail.com (odeits) Date: Sat, 21 Feb 2009 16:53:25 -0800 (PST) Subject: Pythonic way to determine if one char of many in a string References: <1234761457.20683.1300568627@webmail.messagingengine.com> <8666ef66-288d-426a-9622-9d68d1f7971c@b40g2000pri.googlegroups.com> <9f03fc9d-7136-4372-8116-a999fb67bf87@p23g2000prp.googlegroups.com> <9e7c7dc9-deb4-4cdb-99a3-411d89ce73b6@e18g2000yqo.googlegroups.com> Message-ID: <2811f9f5-ca08-47f3-b70d-4106443d3b36@a12g2000yqm.googlegroups.com> On Feb 21, 2:24?pm, rdmur... at bitdance.com wrote: > odeits wrote: > > On Feb 21, 12:47=A0am, "Gabriel Genellina" > > wrote: > > > En Sat, 21 Feb 2009 01:14:02 -0200, odeits escribi=F3: > > > > > On Feb 15, 11:31=A0pm, odeits wrote: > > > >> It seems what you are actually testing for is if the intersection of > > > >> the two sets is not empty where the first set is the characters in > > > >> your word and the second set is the characters in your defined string. > > > > > To expand on what I was saying I thought i should provide a code > > > > snippet: > > > > > WORD = 'g' * 100 > > > > WORD2 = 'g' * 50 + 'U' > > > > VOWELS = 'aeiouAEIOU' > > > > BIGWORD = 'g' * 10000 + 'U' > > > > > def set_test(vowels, word): > > > > > ?vowels = set( iter(vowels)) > > > > ?letters = set( iter(word) ) > > > > > ?if letters & vowels: > > > > ? ? ?return True > > > > ?else: > > > > ? ? return False > > > > > with python 2.5 I got 1.30 usec/pass against the BIGWORD > > > > You could make it slightly faster by removing the iter() call: > > > letters = set(word) > > > And (if vowels are really constant) you could pre-build the vowels set. > > > set(word) = set{[word]} meaning a set with one element, the string > > the call to iter makes it set of the letters making up the word. > > Did you try it? > > Python 2.6.1 (r261:67515, Jan ?7 2009, 17:09:13) > [GCC 4.3.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information.>>> set('abcd') > > set(['a', 'c', 'b', 'd']) > > --RDM You are in fact correct. Thank you for pointing that out. From thorsten at thorstenkampe.de Sat Feb 21 20:25:54 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Sun, 22 Feb 2009 02:25:54 +0100 Subject: To unicode or not to unicode References: Message-ID: * Ross Ridge (Sat, 21 Feb 2009 19:39:42 -0500) > Thorsten Kampe wrote: > >That's right. As long as you use pure ASCII you can skip this nasty step > >of informing other people which charset you are using. If you do use non > >ASCII then you have to do that. That's the way virtually all newsreaders > >work. It has nothing to do with some 21+ year old RFC. Even your Google > >Groups "newsreader" does that ('content="text/html; charset=UTF-8"'). > > No, the original post demonstrates you don't have include MIME headers for > ISO 8859-1 text to be properly displayed by many newsreaders. *sigh* As you still refuse to read the article[1] I'm going to quote it now here: 'The Single Most Important Fact About Encodings If you completely forget everything I just explained, please remember one extremely important fact. It does not make sense to have a string without knowing what encoding it uses. [...] If you have a string [...] in an email message, you have to know what encoding it is in or you cannot interpret it or display it to users correctly. Almost every [...] "she can't read my emails when I use accents" problem comes down to one naive programmer who didn't understand the simple fact that if you don't tell me whether a particular string is encoded using UTF-8 or ASCII or ISO 8859-1 (Latin 1) or Windows 1252 (Western European), you simply cannot display it correctly [...]. There are over a hundred encodings and above code point 127, all bets are off.' Enough said. > The fact that your obscure newsreader didn't display it properly > doesn't mean that original poster's newsreader is broken. You don't even know if my "obscure newsreader" displayed it properly. Non ASCII text without a declared encoding is just a bunch of bytes. It's not even text. T. [1] http://www.joelonsoftware.com/articles/Unicode.html From db3l.net at gmail.com Sat Feb 21 20:37:09 2009 From: db3l.net at gmail.com (David Bolen) Date: Sat, 21 Feb 2009 20:37:09 -0500 Subject: Using clock() in threading on Windows References: <499fc63c$0$30913$9b622d9e@news.freenet.de> Message-ID: "Martin v. L?wis" writes: > As a consequence, the half-busy loops could go away, at least > on systems where lock timeouts can be given to the system. I know that in some cases in the past I've had to bypass a Queue's use of threading objects for waiting for a queue to unblock because of the increased overhead (and latency as the timer increases) of the busy loop. On windows, replacing it with an implementation using WaitForObject calls with the same timeouts I would have used with the Queue performed much better, not unexpectedly, but was non-portable. The current interface to the lowest level locks in Python are certainly generic enough to cross lots of platforms, but it would definitely be useful if they could implement timeouts without busy loops on those platforms where they were supported. -- David From rozzin at geekspace.com Sat Feb 21 20:52:19 2009 From: rozzin at geekspace.com (Joshua Judson Rosen) Date: Sat, 21 Feb 2009 20:52:19 -0500 Subject: multiprocessing module and os.close(sys.stdin.fileno()) References: <3098ffc2-6884-4a35-99a5-ee917442af25@r37g2000prr.googlegroups.com> <87bpswe57v.fsf@slice.rozzin.com> <83c3925e-6456-4d84-8490-7e1ef66b3c4b@41g2000yqf.googlegroups.com> Message-ID: <87tz6ns0fg.fsf@slice.rozzin.com> Graham Dumpleton writes: > > On Feb 21, 4:20?pm, Joshua Judson Rosen wrote: > > Jesse Noller writes: > > > > > On Tue, Feb 17, 2009 at 10:34 PM, Graham Dumpleton > > > wrote: > > > > Why is the multiprocessing module, ie., multiprocessing/process.py, in > > > > _bootstrap() doing: > > > > > > ?os.close(sys.stdin.fileno()) > > > > > > rather than: > > > > > > ?sys.stdin.close() > > > > > > Technically it is feasible that stdin could have been replaced with > > > > something other than a file object, where the replacement doesn't have > > > > a fileno() method. > > > > > > In that sort of situation an AttributeError would be raised, which > > > > isn't going to be caught as either OSError or ValueError, which is all > > > > the code watches out for. > > > > > I don't know why it was implemented that way. File an issue on the > > > tracker and assign it to me (jnoller) please. > > > > My guess would be: because it's also possible for sys.stdin to be a > > file that's open in read+*write* mode, and for that file to have > > pending output buffered (for example, in the case of a socketfile). > > If you are going to have a file that is writable as well as readable, > such as a socket, then likely that sys.stdout/sys.stderr are going to > be bound to it at the same time. Yes. > If that is the case then one should not be using close() at all If you mean stdin.close(), then that's what I said :) > as it will then also close the write side of the pipe and cause > errors when code subsequently attempts to write to > sys.stdout/sys.stderr. > > > In the case of socket you would actually want to use shutdown() to > close just the input side of the socket. Sure--but isn't this "you" the /calling/ code that set the whole thing up? What the /caller/ does with its stdio is up to /him/, and beyond the scope of the present discourse. I can appreciate a library forking and then using os.close() on stdio (it protects my files from any I/O the subprocess might think it wants to do with them), but I think I might be even more annoyed if it *shutdown my sockets* than if it caused double-flushes (there's at least a possibility that I could cope with the double-flushes by just ensuring that *I* flushed before the fork--not so with socket.shutdown()!) > What this all means is that what is the appropriate thing to do is > going to depend on the environment in which the code is used. Thus, > having the behaviour hard wired a certain way is really bad. There > perhaps instead should be a way of a user providing a hook function to > be called to perform any case specific cleanup of stdin, stdout and > stderr, or otherwise reassign them. Usually, I'd say that that's what the methods on the passed-in object are for. Though, as I said--the file-object API is lacking, here :( > > As such, I'd recommend against just using .close(); you might use > > something like `if hasattr(sys.stdin, "fileno"): ...'; but, if your > > `else' clause unconditionally calls sys.stdin.close(), then you still > > have double-flush problems if someone's set sys.stdin to a file-like > > object with output-buffering. > > > > I guess you could try calling that an `edge-case' and seeing if anyone > > screams. It'd be sort-of nice if there was finer granularity in the > > file API--maybe if file.close() took a boolean `flush' argument.... -- Don't be afraid to ask (Lf.((Lx.xx) (Lr.f(rr)))). From seandc at att.net Sat Feb 21 21:03:41 2009 From: seandc at att.net (Sean) Date: Sun, 22 Feb 2009 02:03:41 GMT Subject: Python dictionary size/entry limit? In-Reply-To: <499fdbae$0$31865$9b4e6d93@newsspool3.arcor-online.net> References: <499fdbae$0$31865$9b4e6d93@newsspool3.arcor-online.net> Message-ID: <1o2ol.392511$Mh5.120409@bgtnsc04-news.ops.worldnet.att.net> Stefan Behnel wrote: > intelliminer at gmail.com wrote: > You may be better served with one of the dbm databases that come with > Python. They live on-disk but do the usual in-memory caching. They'll > likely perform a lot better than your OS level swap file. > > Stefan the bsddb module has the feature that access to the database uses the same methods as python dictionaries. Sean From odeits at gmail.com Sat Feb 21 21:34:47 2009 From: odeits at gmail.com (odeits) Date: Sat, 21 Feb 2009 18:34:47 -0800 (PST) Subject: count secton of data in list References: Message-ID: <3ed253bb-d6ec-4f47-af08-ad193e9c46e3@h16g2000yqj.googlegroups.com> On Feb 20, 3:45?pm, Emile van Sebille wrote: > brianrpsgt1 wrote: > > > def step1(val): > > ? ? ? ?data2_row = [] > > > ? ? for d1r in data1_row: > > ? ? ? ? if d1r[1] >= val: > > ? ? ? ? ? ? switch = 0 > > ? ? ? ? ? ? data2_row = d1r[0],d1r[1],d1r[2],switch > > ? ? ? ? ? ? ? ?data2_row.append([d1r[0],d1r[1],d1r[2],switch]) > > HTH, > > Emile def count_consecutive(rows): switch = 0 count = 0 for r in rows: if r[-1] == switch: count += 1 else: switch = not switch if count != 0: yield count count = 0 if count != 0: yield count rows = [ ['2009-01-09','13:17:30,96',123456,0], ['2009-01-09','13:17:31,95',123456,0], ['2009-01-09','13:17:32,95',123456,0], ['2009-01-09','13:17:33,95',123456,0], ['2009-01-09','13:17:34,94',123456,1], ['2009-01-09','13:17:35,94',123456,1], ['2009-01-09','13:17:36,94',123456,1], ['2009-01-09','13:17:37,94',123456,1], ['2009-01-09','13:17:38,94',123456,1], ['2009-01-09','13:17:39,94',123456,1], ['2009-01-09','13:17:40,94',123456,1], ['2009-01-09','13:17:41,94',123456,1], ['2009-01-09','13:17:42,95',123456,0], ['2009-01-09','13:17:43,95',123456,0], ['2009-01-09','13:17:44,95',123456,0], ['2009-01-09','13:17:45,95',123456,0] ] for cnt in count_consecutive(rows): print cnt From steve at holdenweb.com Sat Feb 21 21:46:27 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 21 Feb 2009 21:46:27 -0500 Subject: Wanted: Online Python Course for Credit In-Reply-To: References: <3d974c13-efcd-48ae-8015-7b4a8812280f@w1g2000prk.googlegroups.com> Message-ID: Scott David Daniels wrote: > jsidell wrote: >> I'm a high school game development teacher and I have recently >> discovered Python to be a great way to introduce computer >> programming. I intend to study Python on my own but I can get >> professional development credit at my job for taking a Python course. >> So I'm looking for an online class that I can get a certificate, >> college credit, or something to that effect. Any suggestions would be >> greatly appreciated > O'Reilly have commissioned me to write four on-line classes. We anticipate that they will become available later this year through the O'Reilly School of Technology - see http://www.oreillyschool.com/ regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sat Feb 21 22:04:02 2009 From: steve at holdenweb.com (Steve Holden) Date: Sat, 21 Feb 2009 22:04:02 -0500 Subject: To unicode or not to unicode In-Reply-To: References: <499F0CF0.8070800@v.loewis.de> Message-ID: Thorsten Kampe wrote: > * Ross Ridge (Sat, 21 Feb 2009 14:52:09 -0500) >> Thorsten Kampe wrote: >>> It's all about declaring your charset. In Python as well as in your >>> newsreader. If you don't declare your charset it's ASCII for you - in >>> Python as well as in your newsreader. >> Except in practice unlike Python, many newsreaders don't assume ASCII. > > They assume ASCII - unless you declare your charset (the exception being > Outlook Express and a few Windows newsreaders). Everything else is > "guessing". > >> The original article displayed fine for me. Google Groups displays it >> correctly too: >> >> http://groups.google.com/group/comp.lang.python/msg/828fefd7040238bc > > Your understanding of the principles of Unicode is as least as non- > existant as the OP's. > >> I could just as easily argue that assuming ISO 8859-1 is the defacto >> standard, and that its your newsreader that's broken. > > There is no "standard" in regard to guessing (this is what you call > "assuming"). The need for explicit declaration of an encoding is exactly > the same in Python as in any Usenet article. > >> The reality however is that RFC 1036 is the only standard for Usenet >> messages, defacto or otherwise, and so there's nothing wrong with >> anyone's newsreader. > > The reality is that all non-broken newsreaders use MIME headers to > declare and interpret the charset being used. I suggest you read at > least http://www.joelonsoftware.com/articles/Unicode.html to get an idea > of Unicode and associated topics. > And I suggest you try to phrase your remarks in a way more respectful of those you are discussing these matters with. I understand that exasperation can lead to offensiveness, but if a lack of understanding does exist then it's better to simply try and remove it without commenting on its existence. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From martin at v.loewis.de Sat Feb 21 23:21:21 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 22 Feb 2009 05:21:21 +0100 Subject: To unicode or not to unicode In-Reply-To: References: Message-ID: <49A0D2C1.5080102@v.loewis.de> > Since when is "Google Groups" a newsreader? So far as I know, all > the display/formatting is handled by my web browser and GG merely stuffs > messages into an HTML wrapper... It also transmits this HTML wrapper via HTTP, where it claims that the charset of the HTML is UTF-8. To do that, it must have converted the original message from Latin-1 to UTF-8, which must have required interpreting it as Latin-1 in the first place. Regards, Martin From peter.anderson at internode.on.net Sat Feb 21 23:46:07 2009 From: peter.anderson at internode.on.net (Peter Anderson) Date: Sun, 22 Feb 2009 15:46:07 +1100 Subject: Python 3 and easygui problem Message-ID: <49A0D88F.4010806@internode.on.net> I have just installed Python 3. I have been using Tkinter and easygui (with Python 2.5.4) for any GUI needs. I have just started to port some of my existing scripts to Python 3 and discovered problems with easygui. I was using the following script for testing: from easygui import * import sys while 1: msgbox("Hello, world!") msg ="What is your favorite flavor?" title = "Ice Cream Survey" choices = ["Vanilla", "Chocolate", "Strawberry", "Rocky Road"] choice = choicebox(msg, title, choices) # note that we convert choice to string, in case # the user cancelled the choice, and we got None. msgbox("You chose: " + str(choice), "Survey Result") msg = "Do you want to continue?" title = "Please Confirm" if ccbox(msg, title): # show a Continue/Cancel dialog pass # user chose Continue else: sys.exit(0) # user chose Cancel I have changed the easygui source to Python 3 'import' and 'print' requirements and the initial message box in the above script displays fine fine. However the subsequent message boxes do not display and after the script completes I get the following error message: ---------- Python 3 ---------- Traceback (most recent call last): File "easyguidemo.py", line 10, in choice = choicebox(msg, title, choices) File "C:\Python30\lib\site-packages\easygui.py", line 703, in choicebox return __choicebox(msg,title,choices,buttons) File "C:\Python30\lib\site-packages\easygui.py", line 824, in __choicebox choices.sort( lambda x,y: cmp(x.lower(), y.lower())) # case-insensitive sort TypeError: must use keyword argument for key function Output completed (7 sec consumed) ------------------------------ Fixing this is a bit beyond my skills and I was wondering whether anyone has any thoughts. I am happy to post a copy of my revised easygui.py script. Regards, Peter -- *Peter Anderson* There is nothing more difficult to take in hand, more perilous to conduct, or more uncertain in its success, than to take the lead in the introduction of a new order of things?Niccolo Machiavelli, /The Prince/, ch. 6 From clp2 at rebertia.com Sun Feb 22 00:05:51 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 21 Feb 2009 21:05:51 -0800 Subject: Python 3 and easygui problem In-Reply-To: <49A0D88F.4010806@internode.on.net> References: <49A0D88F.4010806@internode.on.net> Message-ID: <50697b2c0902212105g5594e030h9f7cbb721780ef09@mail.gmail.com> On Sat, Feb 21, 2009 at 8:46 PM, Peter Anderson wrote: > I have just installed Python 3. I have been using Tkinter and easygui (with > Python 2.5.4) for any GUI needs. I have just started to port some of my > existing scripts to Python 3 and discovered problems with easygui. > > I was using the following script for testing: > File "C:\Python30\lib\site-packages\easygui.py", line 824, in __choicebox > choices.sort( lambda x,y: cmp(x.lower(), y.lower())) # case-insensitive sort > TypeError: must use keyword argument for key function Change the line to choices.sort(key=lambda x,y: cmp(x.lower(), y.lower())) Note the "key=". The calling sequence for .sort() changed in Python 3.0 to make 'key' a keyword-only argument (I think). Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From rozzin at geekspace.com Sun Feb 22 00:07:34 2009 From: rozzin at geekspace.com (Joshua Judson Rosen) Date: Sun, 22 Feb 2009 00:07:34 -0500 Subject: To unicode or not to unicode References: <499F0CF0.8070800@v.loewis.de> Message-ID: <87mycfqctl.fsf@slice.rozzin.com> Ross Ridge writes: > > > It's all about declaring your charset. In Python as well as in your > > newsreader. If you don't declare your charset it's ASCII for you - in > > Python as well as in your newsreader. > > Except in practice unlike Python, many newsreaders don't assume ASCII. > The original article displayed fine for me. Right. Exactly. Wasn't that exact issue a driving force behind unicode's creation in the first place? :) To avoid horrors like this: http://en.wikipedia.org/wiki/File:Letter_to_Russia_with_krokozyabry.jpg ... and people getting into arguments on usenet and having to use rebuttals like "Well, it looked fine to *me*--there's nothing wrong, we're just using incompatible encodings!"? But you're right--specifying in usenet-posts is like turn-signals.... Can we get back to Python programming, now? :) -- Don't be afraid to ask (Lf.((Lx.xx) (Lr.f(rr)))). From Graham.Dumpleton at gmail.com Sun Feb 22 00:41:00 2009 From: Graham.Dumpleton at gmail.com (Graham Dumpleton) Date: Sat, 21 Feb 2009 21:41:00 -0800 (PST) Subject: multiprocessing module and os.close(sys.stdin.fileno()) References: <3098ffc2-6884-4a35-99a5-ee917442af25@r37g2000prr.googlegroups.com> <87bpswe57v.fsf@slice.rozzin.com> <83c3925e-6456-4d84-8490-7e1ef66b3c4b@41g2000yqf.googlegroups.com> <87tz6ns0fg.fsf@slice.rozzin.com> Message-ID: <8477ae7b-0b0a-45c5-aba0-8df85b916fc0@l39g2000yqn.googlegroups.com> On Feb 22, 12:52?pm, Joshua Judson Rosen wrote: > Graham Dumpleton writes: > > > On Feb 21, 4:20?pm, Joshua Judson Rosen wrote: > > > Jesse Noller writes: > > > > > On Tue, Feb 17, 2009 at 10:34 PM, Graham Dumpleton > > > > wrote: > > > > > Why is the multiprocessing module, ie., multiprocessing/process.py, in > > > > > _bootstrap() doing: > > > > > > ?os.close(sys.stdin.fileno()) > > > > > > rather than: > > > > > > ?sys.stdin.close() > > > > > > Technically it is feasible that stdin could have been replaced with > > > > > something other than a file object, where the replacement doesn't have > > > > > a fileno() method. > > > > > > In that sort of situation an AttributeError would be raised, which > > > > > isn't going to be caught as either OSError or ValueError, which is all > > > > > the code watches out for. > > > > > I don't know why it was implemented that way. File an issue on the > > > > tracker and assign it to me (jnoller) please. > > > > My guess would be: because it's also possible for sys.stdin to be a > > > file that's open in read+*write* mode, and for that file to have > > > pending output buffered (for example, in the case of a socketfile). > > > If you are going to have a file that is writable as well as readable, > > such as a socket, then likely that sys.stdout/sys.stderr are going to > > be bound to it at the same time. > > Yes. > > > If that is the case then one should not be using close() at all > > If you mean stdin.close(), then that's what I said :) Either. The problem is that same, it close for both read and write and if was expecting to still be able to write because used for stdout or stderr, then will not work. > > as it will then also close the write side of the pipe and cause > > errors when code subsequently attempts to write to > > sys.stdout/sys.stderr. > > > In the case of socket you would actually want to use shutdown() to > > close just the input side of the socket. > > Sure--but isn't this "you" the /calling/ code that set the whole thing > up? What the /caller/ does with its stdio is up to /him/, and beyond > the scope of the present discourse. I can appreciate a library forking > and then using os.close() on stdio (it protects my files from any I/O > the subprocess might think it wants to do with them), but I think I > might be even more annoyed if it *shutdown my sockets* Ah, yeah, forgot that shutdown does end to end shutdown rather than just that file object reference. :-) Graham > than if it > caused double-flushes (there's at least a possibility that I could > cope with the double-flushes by just ensuring that *I* flushed before > the fork--not so with socket.shutdown()!) > > > What this all means is that what is the appropriate thing to do is > > going to depend on the environment in which the code is used. Thus, > > having the behaviour hard wired a certain way is really bad. There > > perhaps instead should be a way of a user providing a hook function to > > be called to perform any case specific cleanup of stdin, stdout and > > stderr, or otherwise reassign them. > > Usually, I'd say that that's what the methods on the passed-in object > are for. Though, as I said--the file-object API is lacking, here :( > > > > As such, I'd recommend against just using .close(); you might use > > > something like `if hasattr(sys.stdin, "fileno"): ...'; but, if your > > > `else' clause unconditionally calls sys.stdin.close(), then you still > > > have double-flush problems if someone's set sys.stdin to a file-like > > > object with output-buffering. > > > > I guess you could try calling that an `edge-case' and seeing if anyone > > > screams. It'd be sort-of nice if there was finer granularity in the > > > file API--maybe if file.close() took a boolean `flush' argument.... > > -- > Don't be afraid to ask (Lf.((Lx.xx) (Lr.f(rr)))). From paddy3118 at googlemail.com Sun Feb 22 00:51:10 2009 From: paddy3118 at googlemail.com (Paddy3118) Date: Sat, 21 Feb 2009 21:51:10 -0800 (PST) Subject: datetime.time and midnight References: Message-ID: <5a2e2b9c-12d6-4606-9dff-0d7f4f9642c1@q9g2000yqc.googlegroups.com> On Feb 21, 10:44?pm, Ethan Furman wrote: > Greetings, List! > > I was curious if anyone knew the rationale behind making midnight False? > > --> import datetime > --> midnight = datetime.time(0,0,0) > --> bool(midnight) > False > > To my way of thinking, midnight does actually exist so it should be > true. ?If datetime.time was measuring an *amount* of time, rather than a > certain point during the day, then a time of 0:0:0 should certainly be > False as it would mean no time had passed. ?However, since midnight does > indeed exist (as many programmers have observed when deadlines approach > ;) I would think it should be true. > -- > ~Ethan~ Ethan, Knights are true and seek the light. Evil trolls seek the night and so their hour is false. ;-) - Paddy. From sbassi at clubdelarazon.org Sun Feb 22 01:06:15 2009 From: sbassi at clubdelarazon.org (Sebastian Bassi) Date: Sun, 22 Feb 2009 04:06:15 -0200 Subject: Problem trying to install ReportLab with easy_install Message-ID: <9e2f512b0902212206q1054875ci3bbe5026f74f62a3@mail.gmail.com> I don't understand what is wrong when I try to install ReportLab. This is under Ubuntu and all build packages are installed. Here is what I get when trying to install it: (I could install it with apt-get, but I am testing virtualenv and easy_install). (testbio149)vicky at maricurie:~/Public/testbio149$ easy_install ReportLab Searching for ReportLab Reading http://pypi.python.org/simple/ReportLab/ Reading http://www.reportlab.com/ Best match: reportLab 2.3 Downloading http://pypi.python.org/packages/source/r/reportlab/reportLab-2.3.zip#md5=7d98b26fa287a9e4be4d35d682ce64ac Processing reportLab-2.3.zip Running ReportLab_2_3/setup.py -q bdist_egg --dist-dir /tmp/easy_install-ZZcgFG/ReportLab_2_3/egg-dist-tmp-FqKULE ################################################ #Attempting install of _rl_accel, sgmlop & pyHnj #extensions from '/tmp/easy_install-ZZcgFG/ReportLab_2_3/src/rl_addons/rl_accel' ################################################ ################################################ #Attempting install of _renderPM #extensions from '/tmp/easy_install-ZZcgFG/ReportLab_2_3/src/rl_addons/renderPM' # installing with freetype version 21 ################################################ /tmp/easy_install-ZZcgFG/ReportLab_2_3/src/rl_addons/rl_accel/_rl_accel.c: In function ?hex32?: /tmp/easy_install-ZZcgFG/ReportLab_2_3/src/rl_addons/rl_accel/_rl_accel.c:793: warning: format ?%8.8X? expects type ?unsigned int?, but argument 3 has type ?long unsigned int? /tmp/easy_install-ZZcgFG/ReportLab_2_3/src/rl_addons/rl_accel/_rl_accel.c: In function ?_instanceStringWidthU?: /tmp/easy_install-ZZcgFG/ReportLab_2_3/src/rl_addons/rl_accel/_rl_accel.c:1200:warning: pointer targets in assignment differ in signedness /tmp/easy_install-ZZcgFG/ReportLab_2_3/src/rl_addons/rl_accel/_rl_accel.c:1123:warning: ?f? may be used uninitialized in this function /tmp/easy_install-ZZcgFG/ReportLab_2_3/src/rl_addons/rl_accel/_rl_accel.c:1123:warning: ?t? may be used uninitialized in this function /tmp/easy_install-ZZcgFG/ReportLab_2_3/src/rl_addons/rl_accel/_rl_accel.c:1123:warning: ?L? may be used uninitialized in this function /usr/bin/ld: cannot find -l_renderPM_libart collect2: ld returned 1 exit status error: Setup script exited with error: command 'gcc' failed with exit status 1 (testbio149)vicky at maricurie:~/Public/testbio149$ From gagsl-py2 at yahoo.com.ar Sun Feb 22 01:52:46 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 22 Feb 2009 04:52:46 -0200 Subject: Find the location of a loaded module References: <5879412d-ffba-4fd9-82b7-7e798dc425e3@f3g2000yqf.googlegroups.com> Message-ID: En Sat, 21 Feb 2009 14:51:40 -0200, escribi?: > "Gabriel Genellina" wrote: >> En Fri, 20 Feb 2009 20:44:21 -0200, Aaron Scott >> escribi=F3: >> >> > So, the problem lies with how Python cached the modules in memory. >> > Yes, the modules were in two different locations and yes, the one that >> > I specified using its direct path should be the one loaded. The >> > problem is, the module isn't always loaded -- if it's already in >> > memory, it'll use that instead. And since the modules had the same >> > name, Python wouldn't distinguish between them, even though they >> > weren't exactly the same. >> >> Yes, that's how import works. It's barely documented, and you finally >> learned it the hard way... > > I'd argue a little bit with "barely documented". In the reference, the > discussion of the import statement starts off saying: > > Import statements are executed in two steps: (1) find a module, > and initialize it if necessary; (2) define a name or names in the > local namespace (of the scope where the import statement occurs). > > The third paragraph then says: > > The system maintains a table of modules that have been or are being > initialized, indexed by module name. This table is accessible as > sys.modules. When a module name is found in this table, step (1) > is finished. > > That is pretty up front and unambiguous documentation. Sure? At a minimum, it doesn't define what "module name" means (isnt't so easy). It does not describe correctly how packages are handled, nor dotted names that aren't packages. It does not describe sys.meta_path nor sys.path_hooks, than can *radically* alter things. It does not describe absolute vs. relative imports, nor the "mix" of them in 2.x. It doesn't menction the *caller* module as relevant. > However, the consequences of that statement won't be immediately clear > on first reading. I think it would have cleared up Aaron's confusion > if he'd happened to think to read it. But since he knew the syntax > of the import statement already, I'm not surprised he did not read it. > > The Tutorial, in the section on modules and import, says: > > A module can contain executable statements as well as function > definitions. These statements are intended to initialize the > module. They are executed only the first time the module is imported > somewhere. > > This is considerably less precise, if more superficially understandable. > I wonder if it would be worth expanding on that statement to mention > that the module is not even looked for on disk if a module by that > name has already been imported. If only that were true... Importers can do almost anything they want. The behaviour you describe is only what happens when a) there are no meta_path hooks installed, b) there are no path_hooks involved, c) __import__ has not been replaced, and d) you are importing a module from the filesystem. This is what I call "barely documented". -- Gabriel Genellina From steve at pearwood.info Sun Feb 22 01:54:41 2009 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 22 Feb 2009 17:54:41 +1100 Subject: datetime.time and midnight References: <5a2e2b9c-12d6-4606-9dff-0d7f4f9642c1@q9g2000yqc.googlegroups.com> Message-ID: <01b0ec24$0$20612$c3e8da3@news.astraweb.com> Paddy3118 wrote: > Ethan, > Knights are true and seek the light. Evil trolls seek the night and so > their hour is false. > > ;-) That's speciest *and* lightist. There's nothing wrong with avoiding the evil burning day star, that's practically de rigour for programmers. *wink* -- Steven From intelliminer at gmail.com Sun Feb 22 02:08:32 2009 From: intelliminer at gmail.com (intelliminer at gmail.com) Date: Sat, 21 Feb 2009 23:08:32 -0800 (PST) Subject: Python dictionary size/entry limit? References: <499fdbae$0$31865$9b4e6d93@newsspool3.arcor-online.net> Message-ID: <006db7aa-76c6-4bf4-bf2a-e180f1665e5e@g38g2000yqd.googlegroups.com> On Feb 21, 6:47?pm, Stefan Behnel wrote: > intellimi... at gmail.com wrote: > > I wrote a script to process textual data and extract phrases from > > them, storing these phrases in a dictionary. It encounters a > > MemoryError when there are about 11.18M keys in the dictionary, and > > the size is about 1.5GB. > > [...] > > I have 1GB of pysical memory and 3GB in pagefile. Is there a limit to > > the size or number of entries that a single dictionary can possess? By > > searching on the web I can't find a clue why this problem occurs. > > Python dicts are only limited by what your OS returns as free memory. > However, when a dict grows, it needs to resize, which means that it has to > create a bigger copy of itself and redistribute the keys. For a dict that > is already 1.5GB big, this can temporarily eat a lot more memory than you > have, at least more than two times as much as the size of the dict itself. > > You may be better served with one of the dbm databases that come with > Python. They live on-disk but do the usual in-memory caching. They'll > likely perform a lot better than your OS level swap file. > > Stefan Ummm, I didn't know about the dbm databases. It seems there are many different modules for this kind of tasks: gdbm, berkeley db, cdb, etc. I'm needing to implement a constant hashtable with a large number of keys, but only a small fraction of them will be accessed frequently, the read speed is crucial. It would be ideal if the implementation caches all the frequently used key/value pairs in memory. Which module should I use? And is there a way to specify the amount of memory it uses for caching? BTW, the target platform is Linux. Thank you. From gagsl-py2 at yahoo.com.ar Sun Feb 22 02:20:31 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 22 Feb 2009 05:20:31 -0200 Subject: datetime.time and midnight References: <49A083DA.7000107@stoneleaf.us> <49A0946B.8040206@mrabarnett.plus.com> Message-ID: En Sat, 21 Feb 2009 21:55:23 -0200, MRAB escribi?: > Ethan Furman wrote: >> Greetings, List! >> I was curious if anyone knew the rationale behind making midnight >> False? >> --> import datetime >> --> midnight = datetime.time(0,0,0) >> --> bool(midnight) >> False >> To my way of thinking, midnight does actually exist so it should be >> true. If datetime.time was measuring an *amount* of time, rather than >> a certain point during the day, then a time of 0:0:0 should certainly >> be False as it would mean no time had passed. However, since midnight >> does indeed exist (as many programmers have observed when deadlines >> approach ;) I would think it should be true. >> > I think it's because midnight is to the time of day what zero is to > integers, or an empty string is to strings, or an empty container ... So chr(0) should be False too... -- Gabriel Genellina From mail at microcorp.co.za Sun Feb 22 02:29:21 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sun, 22 Feb 2009 09:29:21 +0200 Subject: "Byte" type? References: <4997aa38$0$1678$742ec2ed@news.sonic.net> <499841bf$0$1624$742ec2ed@news.sonic.net> <499859e2$0$1618$742ec2ed@news.sonic.net> <499f8a8e$0$1588$742ec2ed@news.sonic.net> <49a03081$0$1599$742ec2ed@news.sonic.net> Message-ID: <00d501c994c8$d8eab400$0d00a8c0@hendrik> "Christian Heimes" wrote: > John Nagle wrote > > If "bytes", a new keyword, works differently in 2.6 and 3.0, that was > > really > > dumb. There's no old code using "bytes". So converting code to 2.6 means > > it has to be converted AGAIN for 3.0. That's a good reason to ignore > > 2.6 as > > defective. > > Please don't call something dumb that you don't fully understand. It's > offenses the people who have spent lots of time developing Python -- > personal, unpaid and voluntary time! Crying out; "Please do not criticise me, I am doing it for free!" does not justify delivering sub standard work - that is the nature of the open source process - if you lift your head and say or do something, there are bound to be some objections - some thoughtful and valid, and others merely carping. Being sensitive about it serves no purpose. > I can assure, the bytes alias and b'' alias have their right to exist. This is not a helpful response - on the surface JN has a point - If you have to go through two conversions, then 2.6 does not achieve what it appears to set out to do. So the issue is simple: - do you have to convert twice? - If yes - why? - as he says - there exists no prior code, so there seems to be no reason not to make it identical to 3.0 The response answers neither of these valid concerns. - Hendrik From gagsl-py2 at yahoo.com.ar Sun Feb 22 02:34:02 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 22 Feb 2009 05:34:02 -0200 Subject: Python 3 and easygui problem References: <49A0D88F.4010806@internode.on.net> <50697b2c0902212105g5594e030h9f7cbb721780ef09@mail.gmail.com> Message-ID: En Sun, 22 Feb 2009 03:05:51 -0200, Chris Rebert escribi?: > On Sat, Feb 21, 2009 at 8:46 PM, Peter Anderson > wrote: >> I have just installed Python 3. I have been using Tkinter and easygui >> (with >> Python 2.5.4) for any GUI needs. I have just started to port some of my >> existing scripts to Python 3 and discovered problems with easygui. >> >> I was using the following script for testing: > > >> File "C:\Python30\lib\site-packages\easygui.py", line 824, in >> __choicebox >> choices.sort( lambda x,y: cmp(x.lower(), y.lower())) # case-insensitive >> sort >> TypeError: must use keyword argument for key function > > Change the line to > > choices.sort(key=lambda x,y: cmp(x.lower(), y.lower())) > > Note the "key=". The calling sequence for .sort() changed in Python > 3.0 to make 'key' a keyword-only argument (I think). That's very short-lived; cmp is gone in 3.0.1 (should not have existed in 3.0 in the first place). Try with: choices.sort(key=str.lower) -- Gabriel Genellina From mail at microcorp.co.za Sun Feb 22 03:09:39 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sun, 22 Feb 2009 10:09:39 +0200 Subject: `high overhead of multiple Python processes' (was: Willmultithreading make python less popular?) References: <3a138978-4545-40ca-bcb6-1e3937ac2df8@j38g2000yqa.googlegroups.com><28e3612d-2e91-4a91-82cb-5fb2deda95fd@q9g2000yqc.googlegroups.com><04b5d5ed-0d0b-42da-9181-bdb61c34f185@g38g2000yqd.googlegroups.com><6b73fa70-04d9-456c-b4da-bb1e62877f24@j39g2000yqn.googlegroups.com><4d937932-b55a-4a66-b220-f915708bb0ce@h5g2000yqh.googlegroups.com><7x8wo2kwoz.fsf@ruckus.brouhaha.com><975d0b81-0810-43c2-9734-b7a5a890e431@k19g2000prh.googlegroups.com><7x3aeadqlo.fsf@ruckus.brouhaha.com><87mycfczvd.fsf_-_@slice.rozzin.com> <7xfxi75tzg.fsf@ruckus.brouhaha.com> Message-ID: <00d601c994c8$d9ee1a40$0d00a8c0@hendrik> "Paul Rubin" wrote: > The cost of messing with the multiprocessing module instead of having > threads work properly, and the overhead of serializing Python data > structures to send to another process by IPC, instead of using the > same object in two threads. Also, one way I often use threading is by > sending function objects to another thread through a Queue, so the > other thread can evaluate the function. I don't think multiprocessing > gives a way to serialize functions, though maybe something like it > can be done at higher nuisance using classes. There are also Pyro and xmlrpc and shm. - all of them more apparent hassle than threads, and all of them better able to exploit parallelism. That said, this has made me think the following: It is an error to pass anything but plain data between processes, as anything else does not scale easily. Passing plain data between processes means either serialising the data and using channels such as pipes or sockets, or passing a pointer to a shared memory block through a similar channel. Following this leads to a clean design, while attempting to pass higher order stuff quickly leads to convoluted code when you try to make things operate in parallel. The above can be crudely summed up as: You can share and pass data, but you should not pass or share code between processes. Now the above is congruent with my own experience, but I wonder if it is generally applicable. - Hendrik From w_a_x_man at yahoo.com Sun Feb 22 03:13:11 2009 From: w_a_x_man at yahoo.com (William James) Date: 22 Feb 2009 08:13:11 GMT Subject: reading file to list References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> Message-ID: Andr? Thieme wrote: > (map #(map (fn [s] (Integer/parseInt s)) (.split % "\\s")) (line-seq > (reader "blob.txt"))) An error results: java.lang.Exception: Unable to resolve symbol: reader in this context This works: (map #(map (fn [s] (Integer/parseInt s)) (.split % "\\s")) (.split (slurp "junk") "\r?\n")) From dickinsm at gmail.com Sun Feb 22 04:18:21 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Sun, 22 Feb 2009 01:18:21 -0800 (PST) Subject: datetime.time and midnight References: Message-ID: <0e8ef14d-ffa9-4513-abe2-404aeb91a079@i38g2000yqd.googlegroups.com> On Feb 21, 10:44?pm, Ethan Furman wrote: > --> midnight = datetime.time(0,0,0) > --> bool(midnight) > False I'd call this a bug. Mark From Ron.Barak at lsi.com Sun Feb 22 04:37:38 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Sun, 22 Feb 2009 09:37:38 +0000 Subject: "metaclass conflict" error: where is noconflict ? In-Reply-To: <50697b2c0902191258ye5aa478gecaf7b7b097e3eba@mail.gmail.com> References: <7F0503CD69378F49BE0DC30661C6CCF60E68800F@enbmail01.lsi.com> <50697b2c0902191258ye5aa478gecaf7b7b097e3eba@mail.gmail.com> Message-ID: <7F0503CD69378F49BE0DC30661C6CCF62783D662@enbmail01.lsi.com> Hi Chris, > -----Original Message----- > From: chris at rebertia.com [mailto:chris at rebertia.com] On > Behalf Of Chris Rebert > Sent: Thursday, February 19, 2009 22:58 > To: Barak, Ron > Cc: python-list at python.org; wxpython-users at lists.wxwidgets.org > Subject: Re: "metaclass conflict" error: where is noconflict ? > > On Thu, Feb 19, 2009 at 5:01 AM, Barak, Ron wrote: > > Hi, > > > > I have a class derived from two parents (in blue below), > which gives > > me the following error: > > > > $ python -u ./failover_pickle_demo09.py Traceback (most recent call > > last): > > File "./failover_pickle_demo09.py", line 291, in > > class ListControl(wx.Frame, CopyAndPaste): > > TypeError: Error when calling the metaclass bases > > metaclass conflict: the metaclass of a derived class must be a > > (non-strict) subclass of the metaclasses of all its bases Googling > > suggested I should add from noconflict import classmaker and > > > > __metaclass__=classmaker() > > to this class. > > > > However, I don't seem able to find where to get the > noconflict module from. > > > > Do any of you where noconflict could be downloaded/installed from ? > > From what I could google, you should in theory be able to fix > the problem (without using any 3rd party module) by doing: > > class ListControlMeta(type(wx.Frame), type(CopyAndPaste)): > pass > > class ListControl(wx.Frame, CopyAndPaste): > __metaclass__ = ListControlMeta > #rest of class... > > Cheers, > Chris Applying your suggestion: class ListControlMeta(type(wx.Frame), type(CopyAndPaste)): pass class ListControl(wx.Frame, CopyAndPaste): def __init__(self, parent, id, title, list, max_list_width, log_stream, style=wx.DEFAULT_FRAME_STYLE): __metaclass__= ListControlMeta wx.Frame.__init__(self,parent,id,title,size=(max_list_width,-1), style=style) self.list = list self.log_stream = log_stream self.list_ctrl = wx.ListCtrl(self, -1, style=wx.LC_REPORT | wx.LC_NO_HEADER) self.list_ctrl.InsertColumn(0, title) for i,line_ in enumerate(list): self.list_ctrl.InsertStringItem(i, line_) ... I get: $ python -u ./failover_pickle_demo09.py Traceback (most recent call last): File "./failover_pickle_demo09.py", line 319, in class ListControlMeta(type(wx.Frame), type(CopyAndPaste)): TypeError: Error when calling the metaclass bases multiple bases have instance lay-out conflict So, back to trying to understand... Thanks and bye, Ron. > > -- > Follow the path of the Iguana... > http://rebertia.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Sun Feb 22 04:47:38 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 22 Feb 2009 01:47:38 -0800 Subject: "metaclass conflict" error: where is noconflict ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF62783D662@enbmail01.lsi.com> References: <7F0503CD69378F49BE0DC30661C6CCF60E68800F@enbmail01.lsi.com> <50697b2c0902191258ye5aa478gecaf7b7b097e3eba@mail.gmail.com> <7F0503CD69378F49BE0DC30661C6CCF62783D662@enbmail01.lsi.com> Message-ID: <50697b2c0902220147y4c8dbf94j1415aae9ee7d640@mail.gmail.com> On Sun, Feb 22, 2009 at 1:37 AM, Barak, Ron wrote: > Hi Chris, > >> -----Original Message----- >> From: chris at rebertia.com [ > mailto:chris at rebertia.com] On >> Behalf Of Chris Rebert >> Sent: Thursday, February 19, 2009 22:58 >> To: Barak, Ron >> Cc: python-list at python.org; wxpython-users at lists.wxwidgets.org >> Subject: Re: "metaclass conflict" error: where is noconflict ? >> >> On Thu, Feb 19, 2009 at 5:01 AM, Barak, Ron wrote: >> > Hi, >> > >> > I have a class derived from two parents (in blue below), >> which gives >> > me the following error: >> > >> > $ python -u ./failover_pickle_demo09.py Traceback (most recent call >> > last): >> > File "./failover_pickle_demo09.py", line 291, in >> > class ListControl(wx.Frame, CopyAndPaste): >> > TypeError: Error when calling the metaclass bases >> > metaclass conflict: the metaclass of a derived class must be a >> > (non-strict) subclass of the metaclasses of all its bases Googling >> > suggested I should add from noconflict import classmaker and >> > >> > __metaclass__=classmaker() >> > to this class. >> > >> > However, I don't seem able to find where to get the >> noconflict module from. >> > >> > Do any of you where noconflict could be downloaded/installed from ? >> >> From what I could google, you should in theory be able to fix >> the problem (without using any 3rd party module) by doing: >> >> class ListControlMeta(type(wx.Frame), type(CopyAndPaste)): >> pass >> >> class ListControl(wx.Frame, CopyAndPaste): >> __metaclass__ = ListControlMeta >> #rest of class... >> >> Cheers, >> Chris > > Applying your suggestion: > > class ListControlMeta(type(wx.Frame), type(CopyAndPaste)): > pass > > class ListControl(wx.Frame, CopyAndPaste): > def __init__(self, parent, id, title, list, max_list_width, log_stream, > style=wx.DEFAULT_FRAME_STYLE): > > __metaclass__= ListControlMeta > > wx.Frame.__init__(self,parent,id,title,size=(max_list_width,-1), > style=style) > self.list = list > self.log_stream = log_stream > self.list_ctrl = wx.ListCtrl(self, -1, style=wx.LC_REPORT | > wx.LC_NO_HEADER) > self.list_ctrl.InsertColumn(0, title) > for i,line_ in enumerate(list): > self.list_ctrl.InsertStringItem(i, line_) > ... > > I get: > > $ python -u ./failover_pickle_demo09.py > Traceback (most recent call last): > File "./failover_pickle_demo09.py", line 319, in > class ListControlMeta(type(wx.Frame), type(CopyAndPaste)): > TypeError: Error when calling the metaclass bases > multiple bases have instance lay-out conflict >From what I recall, that basically means that type(wx.Frame) and type(CopyAndPaste) are both C classes that are are mutually incompatible. It's basically the same reason you can't subclass from both `list` and `dict` or two other built-in types (you get the exact same error). Sounds like the only way to workaround this would be to do some coding in C or to use composition rather than inheritance for one of ListControl's superclasses. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From dickinsm at gmail.com Sun Feb 22 04:47:54 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Sun, 22 Feb 2009 01:47:54 -0800 (PST) Subject: datetime.time and midnight References: <0e8ef14d-ffa9-4513-abe2-404aeb91a079@i38g2000yqd.googlegroups.com> Message-ID: On Feb 22, 9:18?am, Mark Dickinson wrote: > On Feb 21, 10:44?pm, Ethan Furman wrote: > > > --> midnight = datetime.time(0,0,0) > > --> bool(midnight) > > False > > I'd call this a bug. ...although looking at the source (see the function time_nonzero in Modules/datetimemodule.c), this behaviour is clearly intentional. So it's not a bug; merely a questionable design decision. :) Mark From jdigital2121 at yahoo.com Sun Feb 22 04:54:58 2009 From: jdigital2121 at yahoo.com (jeff) Date: Sun, 22 Feb 2009 01:54:58 -0800 (PST) Subject: ftpslib caveat solution? Message-ID: <605090.67543.qm@web32805.mail.mud.yahoo.com> The only python library that I am aware of that supports ftp + TLS is ftpslib, which is also included with M2Crypto. However, as stated in the README, there is one major caveat. Quote: """ The end-of-file marker for binary data transfers is sent by closing the connection. Many FTP servers close the TCP socket without shutting down the TLS connection. ftpslib attempts to avoid this by using the method in test_ftpslib.py attached to Python bug 978833, overriding retrbinary to read from the socket's makefile wrapper instead of the socket itself. Although this appears to work for the builtin socket.ssl and M2Crypto, it is conceivable for a particular SSL implementation to still throw an exception in this case, and, regardless, the issue is still exposed when using ntransfercmd outside of retrbinary. Note that if an exception is thrown in retrbinary, the response from the last RETR will not be read, causing any future commands to be one response behind. This is especially troublesome if using passive FTP, as the FTP class will be unable to parse the 227 response to future PASV commands. """ Has anyone happened to figure out a more elegant solution to this? More specifically, the part about responses being 1 response behind when an exception is thrown, thus making this module unstable when working with a pasv FTP. Any insight to solving this problem would be much appreciated. Cheers, Jeff -------------- next part -------------- An HTML attachment was scrubbed... URL: From marcel.luethi at mlsystems.ch Sun Feb 22 05:55:51 2009 From: marcel.luethi at mlsystems.ch (Marcel Luethi) Date: Sun, 22 Feb 2009 11:55:51 +0100 Subject: Python AppStore / Marketplace Message-ID: <46ed0da80902220255s2ce0182dl28af84dd335aa546@mail.gmail.com> Dear Community Now I'm standing here, having this great idea for a brand new rocking app... But where do I start? I want it to be multi-platform (Linux, Mac OS X, Windows). It should be easy to install and upgrade. It should be self-contained, independent of an already installed Python. And of course - the world should be able to find it! So what do I do? I'm studying all the possibilities to make it self-contained (virtualenv, InstantDjango, PortablePython...), searching for installers (PyInstaller, EasyInstall, ...), looking into making it executable on every platform (py2exe, py2app, cx_Freeze, ...), analyzing all GUI frameworks (wxPython, PyGTK, PyQt, ...), investigating all hosting providers (Google Code, SourceForge, ...) and so on and so forth. This is not easy at all! Using my iPhone I suddenly realize how easy it is to find applications in Apple's AppStore. How easy and fast it is to install or de-install an app. My iPhone even checks in the background if there is an upgrade which could be installed painlessly. Then I see VMware's Virtual Appliance Marketplace, where you can download already pre-configured "appliances" for all kind of stuff. You can even download a basic appliance, install and configure your servers and tools - and upload it again, so that others can profit of your work. Unfortunately there's nothing like this in the Python world... My idea: what about having a beefed up Cheeseshop for Python apps and an accompanying client app kind of iTunes for Python apps? The server side could be easily implemented with any of the current web frameworks. It's simply a management platform for the app packages (descriptions, versions, platforms, licenses, user's comments, number of downloads, ...) and the package files themselves. It should be definitely hosted by the PSF I think. The multi-platform client should be intuitively and elegantly allow app browsing, downloading and installing those Python apps. In that respect it is sort of a Linux package manager (Synaptic, YUM, ...). But this is only the end-user related stuff. Furthermore it should allow to create new apps (probably based on a previously downloaded base app), package and upload them again (kind of Google AppEngine Launcher). Those base packages should include some basic management framework (for installation and configuration) and hopefully soon after the release of this platform they will be created in a broad variety to allow app developers to choose among many Python-version/platform/GUI/...-combinations. IMHO an architecture like this would greatly enhance the productivity of the whole Python community by capitalizing the knowledge of many Python specialists. I don't have to find/install/configure all the basic stuff myself (see above) to build my app. But I can concentrate on my app because I'm standing on the shoulders of giants. I believe it also would make Python as a great platform more visible to the world - because there is only one place you have to go... What do you think??? Is this crazy??? Or simply stupid? Or is this the way to world domination...? ;-) Unfortunately I'm not expert enough to build such a system - but if there is enough interest in the community I gladly would like to help. Marcel PS: Naming is important! "Python AppStore" or "Python App Marketplace" is nice - but I would prefer something like "Python Bazaar" or "Python Souq" to emphasize the community aspect. -------------- next part -------------- An HTML attachment was scrubbed... URL: From matthew at woodcraft.me.uk Sun Feb 22 06:23:18 2009 From: matthew at woodcraft.me.uk (Matthew Woodcraft) Date: Sun, 22 Feb 2009 11:23:18 GMT Subject: "Byte" type? References: <4997aa38$0$1678$742ec2ed@news.sonic.net> <499841bf$0$1624$742ec2ed@news.sonic.net> <499859e2$0$1618$742ec2ed@news.sonic.net> <499f8a8e$0$1588$742ec2ed@news.sonic.net> <49a03081$0$1599$742ec2ed@news.sonic.net> Message-ID: <87eixq4swp.fsf@golux.woodcraft.me.uk> "Hendrik van Rooyen" writes: > "Christian Heimes" wrote: > on the surface JN has a point - If you have to go through two > conversions, then 2.6 does not achieve what it appears to set out to > do. So the issue is simple: > - do you have to convert twice? > - If yes - why? - as he says - there exists no prior code, > so there seems to be no reason not to make it identical > to 3.0 You don't have to convert twice. You don't have to use 'bytes' in 2.6 at all. It's there in 2.6 to make some strategies for transition to 3.x easier. Note that 'bytes' is not (as JN asserted) a keyword, so its inclusion won't break existing programs which were using it as an identifier. -M- From marcel.luethi at gmail.com Sun Feb 22 06:24:26 2009 From: marcel.luethi at gmail.com (Marcel Luethi) Date: Sun, 22 Feb 2009 03:24:26 -0800 (PST) Subject: Python AppStore / Marketplace Message-ID: Dear Community Now I'm standing here, having this great idea for a brand new rocking app... But where do I start? I want it to be multi-platform (Linux, Mac OS X, Windows). It should be easy to install and upgrade. It should be self- contained, independent of an already installed Python. And of course - the world should be able to find it! So what do I do? I'm studying all the possibilities to make it self- contained (virtualenv, InstantDjango, PortablePython...), searching for installers (PyInstaller, EasyInstall, ...), looking into making it executable on every platform (py2exe, py2app, cx_Freeze, ...), analyzing all GUI frameworks (wxPython, PyGTK, PyQt, ...), investigating all hosting providers (Google Code, SourceForge, ...) and so on and so forth. This is not easy at all! Using my iPhone I suddenly realize how easy it is to find applications in Apple's AppStore. How easy and fast it is to install or de-install an app. My iPhone even checks in the background if there is an upgrade which could be installed painlessly. Then I see VMware's Virtual Appliance Marketplace, where you can download already pre-configured "appliances" for all kind of stuff. You can even download a basic appliance, install and configure your servers and tools - and upload it again, so that others can profit of your work. Unfortunately there's nothing like this in the Python world... My idea: what about having a beefed up Cheeseshop for Python apps and an accompanying client app kind of iTunes for Python apps? The server side could be easily implemented with any of the current web frameworks. It's simply a management platform for the app packages (descriptions, versions, platforms, licenses, user's comments, number of downloads, ...) and the package files themselves. It should be definitely hosted by the PSF I think. The multi-platform client should be intuitively and elegantly allow app browsing, downloading and installing those Python apps. In that respect it is sort of a Linux package manager (Synaptic, YUM, ...). But this is only the end-user related stuff. Furthermore it should allow to create new apps (probably based on a previously downloaded base app), package and upload them again (kind of Google AppEngine Launcher). Those base packages should include some basic management framework (for installation and configuration) and hopefully soon after the release of this platform they will be created in a broad variety to allow app developers to choose among many Python-version/ platform/GUI/...-combinations. IMHO an architecture like this would greatly enhance the productivity of the whole Python community by capitalizing the knowledge of many Python specialists. I don't have to find/install/configure all the basic stuff myself (see above) to build my app. But I can concentrate on my app because I'm standing on the shoulders of giants. I believe it also would make Python as a great platform more visible to the world - because there is only one place you have to go... What do you think??? Is this crazy??? Or simply stupid? Or is this the way to world domination...? ;-) Unfortunately I'm not expert enough to build such a system - but if there is enough interest in the community I gladly would like to help. Marcel PS: Naming is important! "Python AppStore" or "Python App Marketplace" is nice - but I would prefer something like "Python Bazaar" or "Python Souq" to emphasize the community aspect. From Ron.Barak at lsi.com Sun Feb 22 06:31:01 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Sun, 22 Feb 2009 11:31:01 +0000 Subject: "metaclass conflict" error: where is noconflict ? In-Reply-To: <50697b2c0902220147y4c8dbf94j1415aae9ee7d640@mail.gmail.com> References: <7F0503CD69378F49BE0DC30661C6CCF60E68800F@enbmail01.lsi.com> <50697b2c0902191258ye5aa478gecaf7b7b097e3eba@mail.gmail.com> <7F0503CD69378F49BE0DC30661C6CCF62783D662@enbmail01.lsi.com> <50697b2c0902220147y4c8dbf94j1415aae9ee7d640@mail.gmail.com> Message-ID: <7F0503CD69378F49BE0DC30661C6CCF62783D673@enbmail01.lsi.com> Hi Chris, > -----Original Message----- > From: Chris Rebert [mailto:clp2 at rebertia.com] > Sent: Sunday, February 22, 2009 11:48 > To: Barak, Ron > Cc: python-list at python.org; wxpython-users at lists.wxwidgets.org > Subject: Re: "metaclass conflict" error: where is noconflict ? > > On Sun, Feb 22, 2009 at 1:37 AM, Barak, Ron wrote: > > Hi Chris, > > > >> -----Original Message----- > >> From: chris at rebertia.com [ > > mailto:chris at rebertia.com] On > >> Behalf Of Chris Rebert > >> Sent: Thursday, February 19, 2009 22:58 > >> To: Barak, Ron > >> Cc: python-list at python.org; wxpython-users at lists.wxwidgets.org > >> Subject: Re: "metaclass conflict" error: where is noconflict ? > >> > >> On Thu, Feb 19, 2009 at 5:01 AM, Barak, Ron > wrote: > >> > Hi, > >> > > >> > I have a class derived from two parents (in blue below), > >> which gives > >> > me the following error: > >> > > >> > $ python -u ./failover_pickle_demo09.py Traceback (most > recent call > >> > last): > >> > File "./failover_pickle_demo09.py", line 291, in > >> > class ListControl(wx.Frame, CopyAndPaste): > >> > TypeError: Error when calling the metaclass bases > >> > metaclass conflict: the metaclass of a derived class > must be a > >> > (non-strict) subclass of the metaclasses of all its > bases Googling > >> > suggested I should add from noconflict import classmaker and > >> > > >> > __metaclass__=classmaker() > >> > to this class. > >> > > >> > However, I don't seem able to find where to get the > >> noconflict module from. > >> > > >> > Do any of you where noconflict could be > downloaded/installed from ? > >> > >> From what I could google, you should in theory be able to fix the > >> problem (without using any 3rd party module) by doing: > >> > >> class ListControlMeta(type(wx.Frame), type(CopyAndPaste)): > >> pass > >> > >> class ListControl(wx.Frame, CopyAndPaste): > >> __metaclass__ = ListControlMeta > >> #rest of class... > >> > >> Cheers, > >> Chris > > > > Applying your suggestion: > > > > class ListControlMeta(type(wx.Frame), type(CopyAndPaste)): > > pass > > > > class ListControl(wx.Frame, CopyAndPaste): > > def __init__(self, parent, id, title, list, max_list_width, > > log_stream, > > style=wx.DEFAULT_FRAME_STYLE): > > > > __metaclass__= ListControlMeta > > > > > > wx.Frame.__init__(self,parent,id,title,size=(max_list_width,-1), > > style=style) > > self.list = list > > self.log_stream = log_stream > > self.list_ctrl = wx.ListCtrl(self, -1, style=wx.LC_REPORT | > > wx.LC_NO_HEADER) > > self.list_ctrl.InsertColumn(0, title) > > for i,line_ in enumerate(list): > > self.list_ctrl.InsertStringItem(i, line_) > > ... > > > > I get: > > > > $ python -u ./failover_pickle_demo09.py Traceback (most recent call > > last): > > File "./failover_pickle_demo09.py", line 319, in > > class ListControlMeta(type(wx.Frame), type(CopyAndPaste)): > > TypeError: Error when calling the metaclass bases > > multiple bases have instance lay-out conflict > > >From what I recall, that basically means that type(wx.Frame) and > type(CopyAndPaste) are both C classes that are are mutually > incompatible. It's basically the same reason you can't > subclass from both `list` and `dict` or two other built-in > types (you get the exact same error). > > Sounds like the only way to workaround this would be to do > some coding in C or to use composition rather than > inheritance for one of ListControl's superclasses. The wx.Frame may be coded in C, but the CopyAndPaste class, which I wrote, is not (see it's listing below). Could you have a look at the CopyAndPaste class, and see if something in its construction strikes you as susspicious ? Thanks, Ron. $ cat ./CopyAndPaste.py #!/usr/bin/env python import wx class CopyAndPaste(): def __init__(self): pass def set_copy_and_paste(self): """ Setting clipboard copy-and-pasting (only copying from the application to the clipboard is supported). The "menu" menu is hidded, and is only there to facilitate the acceleration table. Both CTRL-C and CTRL-Ins are supported. """ #print line()+". set_copy_and_paste started" #print line()+". self.__dict__:",self.__dict__ menu = wx.Menu() copy_ = menu.Append(-1, "&Copy\tCtrl-Ins") # Copy with accelerator minimize_ = menu.Append(-1, "Minimize") # close_ = menu.Append(-1, "Close window\tCtrl-W") # Close window exit_ = menu.Append(-1, "E&xit application\tCtrl-X") # Close window """ #copy2_ = menu.Append(-1, "&Copy\tCtrl-C") # Copy with accelerator paste_ = menu.Append(-1, "&Paste\tShift-Ins") # Paste with accelerator paste2_ = menu.Append(-1, "&Paste\tCtrl-V") # Paste with accelerator """ self.Bind(wx.EVT_MENU, self.on_copy, copy_) self.Bind(wx.EVT_MENU, self.on_minimize, minimize_) self.Bind(wx.EVT_MENU, self.on_close, close_) self.Bind(wx.EVT_MENU, self.on_exit, exit_) #self.Bind(wx.EVT_MENU, self.on_paste, paste_) menuBar = wx.MenuBar() self.SetMenuBar(menuBar) acceltbl = wx.AcceleratorTable( [ (wx.ACCEL_CTRL, ord('C'), copy_.GetId()), (wx.ACCEL_CTRL, ord('W'), close_.GetId()), (wx.ACCEL_CTRL, ord('X'), exit_.GetId()), (wx.ACCEL_CTRL, ord('Q'), exit_.GetId()), (wx.ACCEL_CTRL, wx.WXK_INSERT, copy_.GetId()), (wx.ACCEL_CTRL, wx.WXK_NUMPAD_INSERT, copy_.GetId()), #(wx.ACCEL_CTRL, ord('V'), paste_.GetId()), #(wx.ACCEL_SHIFT, wx.WXK_INSERT, paste_.GetId()), ]) self.SetAcceleratorTable(acceltbl) # Setting popup menu self.popupmenu = menu self.Bind(wx.EVT_CONTEXT_MENU, self.on_show_popup) """ def on_paste(self, evt): wx.MessageBox("You selected 'paste'") """ def on_show_popup(self, evt): pos = evt.GetPosition() pos = self.list_ctrl.ScreenToClient(pos) self.PopupMenu(self.popupmenu, pos) def get_data_for_clipboard(self,format="text"): """ Return data ready to be copied to the clipboard. This is an abstract method - concrete subclasses must override this. Sample implementation of get_data_for_clipboard() is: def get_data_for_clipboard(self,format="text"): first_selected = self.list_ctrl.GetFirstSelected() selected_item_count = self.list_ctrl.GetSelectedItemCount() text_for_clipboard = "" for i in range(first_selected,first_selected+selected_item_count): text_for_clipboard = "%s%s\n" % (text_for_clipboard, self.list_ctrl.GetItemText(i)) return(text_for_clipboard) """ raise NotImplementedError def on_copy(self, evt): """ """ text_for_clipboard = self.get_data_for_clipboard() data = wx.TextDataObject() data.SetText(text_for_clipboard) if wx.TheClipboard.Open(): wx.TheClipboard.SetData(data) wx.TheClipboard.Close() else: wx.MessageBox("Unable to copy to the clipboard", "Error") def on_minimize(self, evt): self.Iconize() #self.parent.Iconize() def on_close(self, evt): self.Close() #self.parent.Close() def on_exit(self, evt): try: self.Parent.Close() except AttributeError: self.Close() if __name__ == "__main__": app = wx.App(redirect=False) copy_and_paste = CopyAndPaste() app.MainLoop() > > Cheers, > Chris > > -- > Follow the path of the Iguana... > http://rebertia.com > > From clp2 at rebertia.com Sun Feb 22 06:57:22 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 22 Feb 2009 03:57:22 -0800 Subject: "metaclass conflict" error: where is noconflict ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF62783D673@enbmail01.lsi.com> References: <7F0503CD69378F49BE0DC30661C6CCF60E68800F@enbmail01.lsi.com> <50697b2c0902191258ye5aa478gecaf7b7b097e3eba@mail.gmail.com> <7F0503CD69378F49BE0DC30661C6CCF62783D662@enbmail01.lsi.com> <50697b2c0902220147y4c8dbf94j1415aae9ee7d640@mail.gmail.com> <7F0503CD69378F49BE0DC30661C6CCF62783D673@enbmail01.lsi.com> Message-ID: <50697b2c0902220357g762fe390q6535079d42f6afb0@mail.gmail.com> On Sun, Feb 22, 2009 at 3:31 AM, Barak, Ron wrote: >> > Applying your suggestion: >> > >> > class ListControlMeta(type(wx.Frame), type(CopyAndPaste)): >> > pass >> > >> > class ListControl(wx.Frame, CopyAndPaste): >> > def __init__(self, parent, id, title, list, max_list_width, >> > log_stream, >> > style=wx.DEFAULT_FRAME_STYLE): >> > >> > __metaclass__= ListControlMeta >> > >> > >> > wx.Frame.__init__(self,parent,id,title,size=(max_list_width,-1), >> > style=style) >> > self.list = list >> > self.log_stream = log_stream >> > self.list_ctrl = wx.ListCtrl(self, -1, style=wx.LC_REPORT | >> > wx.LC_NO_HEADER) >> > self.list_ctrl.InsertColumn(0, title) >> > for i,line_ in enumerate(list): >> > self.list_ctrl.InsertStringItem(i, line_) >> > ... >> > >> > I get: >> > >> > $ python -u ./failover_pickle_demo09.py Traceback (most recent call >> > last): >> > File "./failover_pickle_demo09.py", line 319, in >> > class ListControlMeta(type(wx.Frame), type(CopyAndPaste)): >> > TypeError: Error when calling the metaclass bases >> > multiple bases have instance lay-out conflict >> >> >From what I recall, that basically means that type(wx.Frame) and >> type(CopyAndPaste) are both C classes that are are mutually >> incompatible. It's basically the same reason you can't >> subclass from both `list` and `dict` or two other built-in >> types (you get the exact same error). >> >> Sounds like the only way to workaround this would be to do >> some coding in C or to use composition rather than >> inheritance for one of ListControl's superclasses. > > The wx.Frame may be coded in C, but the CopyAndPaste class, which I wrote, is not (see it's listing below). > Could you have a look at the CopyAndPaste class, and see if something in its construction strikes you as susspicious ? > > Thanks, > Ron. > > $ cat ./CopyAndPaste.py > #!/usr/bin/env python > > import wx > > class CopyAndPaste(): You need to subclass 'object' so as to make CopyAndPaste a new-style class. This may or may not resolve the error, but you should be doing it either way. class CopyAndPaste(object): Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From hniksic at xemacs.org Sun Feb 22 07:05:24 2009 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Sun, 22 Feb 2009 13:05:24 +0100 Subject: "metaclass conflict" error: where is noconflict ? References: <7F0503CD69378F49BE0DC30661C6CCF60E68800F@enbmail01.lsi.com> <50697b2c0902191258ye5aa478gecaf7b7b097e3eba@mail.gmail.com> <7F0503CD69378F49BE0DC30661C6CCF62783D662@enbmail01.lsi.com> <50697b2c0902220147y4c8dbf94j1415aae9ee7d640@mail.gmail.com> Message-ID: <87k57iu16j.fsf@mulj.homelinux.net> "Barak, Ron" writes: > class CopyAndPaste(): CopyAndPaste is an old-style class. Make it a new-style class, and you'll probably be able to inherit from it and wx.Frame without explicitly creating a new metaclass. From peter.anderson at internode.on.net Sun Feb 22 07:05:32 2009 From: peter.anderson at internode.on.net (Peter Anderson) Date: Sun, 22 Feb 2009 23:05:32 +1100 Subject: Python 3 and easygui problem In-Reply-To: References: Message-ID: <49A13F8C.1000506@internode.on.net> Gabriel Genellina said: That's very short-lived; cmp is gone in 3.0.1 (should not have existed in 3.0 in the first place). Try with: choices.sort(key=str.lower) Gabriel, That's worked fine - thank you. I think I now have a version of easygui.py that works with Python 3, probably needs a bit more testing. Regards, Peter -- *Peter Anderson* There is nothing more difficult to take in hand, more perilous to conduct, or more uncertain in its success, than to take the lead in the introduction of a new order of things?Niccolo Machiavelli, /The Prince/, ch. 6 From bockman at virgilio.it Sun Feb 22 07:53:23 2009 From: bockman at virgilio.it (Francesco Bochicchio) Date: Sun, 22 Feb 2009 13:53:23 +0100 Subject: python contextmanagers and ruby blocks References: <0ca5a9c3-03d3-4824-9c66-c1a3604aa98b@x9g2000yqk.googlegroups.com> Message-ID: On Sat, 21 Feb 2009 09:42:02 -0800, Aahz wrote: > In article , > Alia K wrote: >> >>Nevertheless, I remain curious about whether once can use the >>contextmanager in python to achieve the full power of ruby's blocks... > > Short answer: no > > Longer answer: the way in Python to achieve the full power of Ruby > blocks is to write a function. Which was where I was aiming to with my very long-winded post :-) Ciao ---- FB From yanegomi at gmail.com Sun Feb 22 08:07:57 2009 From: yanegomi at gmail.com (Garrett Cooper) Date: Sun, 22 Feb 2009 05:07:57 -0800 Subject: Problem trying to install ReportLab with easy_install In-Reply-To: <9e2f512b0902212206q1054875ci3bbe5026f74f62a3@mail.gmail.com> References: <9e2f512b0902212206q1054875ci3bbe5026f74f62a3@mail.gmail.com> Message-ID: <364299f40902220507i6c5520dcyb6547c6bf6a848e3@mail.gmail.com> On Sat, Feb 21, 2009 at 10:06 PM, Sebastian Bassi wrote: > I don't understand what is wrong when I try to install ReportLab. This > is under Ubuntu and all build packages are installed. > Here is what I get when trying to install it: (I could install it with > apt-get, but I am testing virtualenv and easy_install). > > (testbio149)vicky at maricurie:~/Public/testbio149$ easy_install ReportLab > Searching for ReportLab > Reading http://pypi.python.org/simple/ReportLab/ > Reading http://www.reportlab.com/ > Best match: reportLab 2.3 > Downloading http://pypi.python.org/packages/source/r/reportlab/reportLab-2.3.zip#md5=7d98b26fa287a9e4be4d35d682ce64ac > Processing reportLab-2.3.zip > Running ReportLab_2_3/setup.py -q bdist_egg --dist-dir > /tmp/easy_install-ZZcgFG/ReportLab_2_3/egg-dist-tmp-FqKULE > ################################################ > #Attempting install of _rl_accel, sgmlop & pyHnj > #extensions from '/tmp/easy_install-ZZcgFG/ReportLab_2_3/src/rl_addons/rl_accel' > ################################################ > ################################################ > #Attempting install of _renderPM > #extensions from '/tmp/easy_install-ZZcgFG/ReportLab_2_3/src/rl_addons/renderPM' > # installing with freetype version 21 > ################################################ > /tmp/easy_install-ZZcgFG/ReportLab_2_3/src/rl_addons/rl_accel/_rl_accel.c: > In function ?hex32?: > /tmp/easy_install-ZZcgFG/ReportLab_2_3/src/rl_addons/rl_accel/_rl_accel.c:793: > warning: format ?%8.8X? expects type ?unsigned int?, but argument 3 > has type ?long unsigned int? > /tmp/easy_install-ZZcgFG/ReportLab_2_3/src/rl_addons/rl_accel/_rl_accel.c: > In function ?_instanceStringWidthU?: > /tmp/easy_install-ZZcgFG/ReportLab_2_3/src/rl_addons/rl_accel/_rl_accel.c:1200:warning: > pointer targets in assignment differ in signedness > /tmp/easy_install-ZZcgFG/ReportLab_2_3/src/rl_addons/rl_accel/_rl_accel.c:1123:warning: > ?f? may be used uninitialized in this function > /tmp/easy_install-ZZcgFG/ReportLab_2_3/src/rl_addons/rl_accel/_rl_accel.c:1123:warning: > ?t? may be used uninitialized in this function > /tmp/easy_install-ZZcgFG/ReportLab_2_3/src/rl_addons/rl_accel/_rl_accel.c:1123:warning: > ?L? may be used uninitialized in this function > /usr/bin/ld: cannot find -l_renderPM_libart > collect2: ld returned 1 exit status > error: Setup script exited with error: command 'gcc' failed with exit status 1 > (testbio149)vicky at maricurie:~/Public/testbio149$ It's not building lib_renderPM_libart properly, or it's a typo that supposed to be librenderPM_libart, or bad LDFLAGS... More details need to be provided like an ls of your site-packages directory and a partial ls of your local library directory (ls /usr/?local/?lib/lib*render*libart*, etc). Thanks, -Garrett From Ron.Barak at lsi.com Sun Feb 22 08:14:28 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Sun, 22 Feb 2009 13:14:28 +0000 Subject: Is there a way to ask a class what its metaclasses are ? In-Reply-To: <50697b2c0902220357g762fe390q6535079d42f6afb0@mail.gmail.com> References: <7F0503CD69378F49BE0DC30661C6CCF60E68800F@enbmail01.lsi.com> <50697b2c0902191258ye5aa478gecaf7b7b097e3eba@mail.gmail.com> <7F0503CD69378F49BE0DC30661C6CCF62783D662@enbmail01.lsi.com> <50697b2c0902220147y4c8dbf94j1415aae9ee7d640@mail.gmail.com> <7F0503CD69378F49BE0DC30661C6CCF62783D673@enbmail01.lsi.com> <50697b2c0902220357g762fe390q6535079d42f6afb0@mail.gmail.com> Message-ID: <7F0503CD69378F49BE0DC30661C6CCF62783D685@enbmail01.lsi.com> Hi Chris, > -----Original Message----- > From: chris at rebertia.com [mailto:chris at rebertia.com] On > Behalf Of Chris Rebert > Sent: Sunday, February 22, 2009 13:57 > To: Barak, Ron > Cc: python-list at python.org > Subject: Re: "metaclass conflict" error: where is noconflict ? > > On Sun, Feb 22, 2009 at 3:31 AM, Barak, Ron wrote: > > >> > Applying your suggestion: > >> > > >> > class ListControlMeta(type(wx.Frame), type(CopyAndPaste)): > >> > pass > >> > > >> > class ListControl(wx.Frame, CopyAndPaste): > >> > def __init__(self, parent, id, title, list, max_list_width, > >> > log_stream, > >> > style=wx.DEFAULT_FRAME_STYLE): > >> > > >> > __metaclass__= ListControlMeta > >> > > >> > > >> > wx.Frame.__init__(self,parent,id,title,size=(max_list_width,-1), > >> > style=style) > >> > self.list = list > >> > self.log_stream = log_stream > >> > self.list_ctrl = wx.ListCtrl(self, -1, > style=wx.LC_REPORT | > >> > wx.LC_NO_HEADER) > >> > self.list_ctrl.InsertColumn(0, title) > >> > for i,line_ in enumerate(list): > >> > self.list_ctrl.InsertStringItem(i, line_) > >> > ... > >> > > >> > I get: > >> > > >> > $ python -u ./failover_pickle_demo09.py Traceback (most > recent call > >> > last): > >> > File "./failover_pickle_demo09.py", line 319, in > >> > class ListControlMeta(type(wx.Frame), type(CopyAndPaste)): > >> > TypeError: Error when calling the metaclass bases > >> > multiple bases have instance lay-out conflict > >> > >> >From what I recall, that basically means that type(wx.Frame) and > >> type(CopyAndPaste) are both C classes that are are mutually > >> incompatible. It's basically the same reason you can't > subclass from > >> both `list` and `dict` or two other built-in types (you > get the exact > >> same error). > >> > >> Sounds like the only way to workaround this would be to do some > >> coding in C or to use composition rather than inheritance > for one of > >> ListControl's superclasses. > > > > The wx.Frame may be coded in C, but the CopyAndPaste class, > which I wrote, is not (see it's listing below). > > Could you have a look at the CopyAndPaste class, and see if > something in its construction strikes you as susspicious ? > > > > Thanks, > > Ron. > > > > $ cat ./CopyAndPaste.py > > #!/usr/bin/env python > > > > import wx > > > > class CopyAndPaste(): > > You need to subclass 'object' so as to make CopyAndPaste a > new-style class. This may or may not resolve the error, but > you should be doing it either way. > > class CopyAndPaste(object): > > Cheers, > Chris > Thanks for the super-prompt replies. Is there a way to ask a class what its metaclasses are ? (e.g., how to ask wx.Frame what it's metaclass is) I'm asking, because, even subclassing from object, viz.: class CopyAndPaste(object): def __init__(self): pass ... Still gives me: $ python -u ./failover_pickle_demo09.py Traceback (most recent call last): File "./failover_pickle_demo09.py", line 321, in class ListControlMeta(wx.Frame, CopyAndPaste): TypeError: Error when calling the metaclass bases metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases Bye, Ron. > -- > Follow the path of the Iguana... > http://rebertia.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dineshbvadhia at hotmail.com Sun Feb 22 08:17:39 2009 From: dineshbvadhia at hotmail.com (dineshv) Date: Sun, 22 Feb 2009 05:17:39 -0800 (PST) Subject: To unicode or not to unicode References: Message-ID: <211f0ece-f29f-43c3-bd50-4c64bdee2087@j35g2000yqh.googlegroups.com> re: "You should never have to rely on the default encoding. You should explicitly decode and encode data." What is the best practice for 1) doing this in Python and 2) for unicode support ? I want to standardize on unicode and want to put into place best Python practice so that we don't have to worry. Thanks! Dinesh On Feb 19, 7:21?pm, Benjamin Peterson wrote: > Ron Garret flownet.com> writes: > > > > > I'm writing a little wiki that I call ?Wiki. ?That's a lowercase Greek > > mu at the beginning (it's pronounced micro-wiki). ?It's working, except > > that I can't actually enter the name of the wiki into the wiki itself > > because the default unicode encoding on my Python installation is > > "ascii". ?So I'm trying to decide on a course of action. ?There seem to > > be three possibilities: > > You should never have to rely on the default encoding. You should explicitly > decode and encode data. > > > > > 1. ?Change the code to properly support unicode. ?Preliminary > > investigations indicate that this is going to be a colossal pain in the > > ass. > > Properly handling unicode may be painful at first, but it will surely pay off in > the future. From Ron.Barak at lsi.com Sun Feb 22 08:29:10 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Sun, 22 Feb 2009 13:29:10 +0000 Subject: How to inherit from two classes without metaclass clashing ? In-Reply-To: References: <7F0503CD69378F49BE0DC30661C6CCF60E68800F@enbmail01.lsi.com> Message-ID: <7F0503CD69378F49BE0DC30661C6CCF62783D686@enbmail01.lsi.com> Hi Michele, I tried understanding how to avoid the metaclasses clashing, and I did read the link you referred to below, as well as the relevant O'Reilly cookbook chapter (Recipe 20.17. Solving Metaclass Conflicts), but seems I do not understand the correct syntax to use, as I either get $ python -u ./failover_pickle_demo09.py Traceback (most recent call last): File "./failover_pickle_demo09.py", line 323, in class ListControlMeta(wx.Frame, CopyAndPaste): TypeError: Error when calling the metaclass bases metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases or $ python -u ./failover_pickle_demo09.py Traceback (most recent call last): File "./failover_pickle_demo09.py", line 322, in class ListControlMeta(type(wx.Frame), type(CopyAndPaste)): TypeError: Error when calling the metaclass bases multiple bases have instance lay-out conflict And, mind you, all I wanted to do was inherit from two classes: wxPython's wx.Frame and my CopyAndPaste. Namely - I have a subclass of wxPython's wx.Frame called ListControl. I wanted to add copy (from copy-and-paste) capabilities to this ListControl class. I changed the header of this class to be: class ListControl(wx.Frame, CopyAndPaste): But, the addition of CopyAndPaste to the class parents got me into this quagmire of metaclasses. Bye, Ron. > -----Original Message----- > From: Michele Simionato [mailto:michele.simionato at gmail.com] > Sent: Friday, February 20, 2009 07:23 > To: python-list at python.org > Subject: Re: "metaclass conflict" error: where is noconflict ? > > On Feb 19, 9:58 pm, Chris Rebert wrote: > > On Thu, Feb 19, 2009 at 5:01 AM, Barak, Ron > wrote: > > > Hi, > > > > > I have a class derived from two parents (in blue below), > which gives > > > me the following error: > > > > > $ python -u ./failover_pickle_demo09.py Traceback (most > recent call > > > last): > > > File "./failover_pickle_demo09.py", line 291, in > > > class ListControl(wx.Frame, CopyAndPaste): > > > TypeError: Error when calling the metaclass bases > > > metaclass conflict: the metaclass of a derived class must be a > > > (non-strict) subclass of the metaclasses of all its bases > Googling > > > suggested I should add from noconflict import classmaker and > > > > > __metaclass__=classmaker() > > > to this class. > > > > > However, I don't seem able to find where to get the > noconflict module from. > > > > > Do any of you where noconflict could be > downloaded/installed from ? > > > It refers to this cookbook recipe: > http://code.activestate.com/recipes/204197/ > > See also the printed cookbook: > > http://books.google.it/books?id=1Shx_VXS6ioC&pg=PA786&lpg=PA78 6&dq=python+cookbook+noconflict&source=bl&ots=BB413AZ8R7&sig=cnAB-E9rNFolHBEZQTIm_d4Mj3o&hl=it&ei=GT2eSfCtBdWa_gadppHYCw&sa=X&oi=book_result&resnum=2&ct=result#PPA786,M1 However, there is no module to download, and this is on purpose: instead of blindly apply a "fix" one should understand what the conflict is: then it is quite easy to solve it by hand. The recipe discussion explains it all. -------------- next part -------------- An HTML attachment was scrubbed... URL: From Ron.Barak at lsi.com Sun Feb 22 08:41:20 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Sun, 22 Feb 2009 13:41:20 +0000 Subject: "metaclass conflict" error: where is noconflict ? In-Reply-To: <87k57iu16j.fsf@mulj.homelinux.net> References: <7F0503CD69378F49BE0DC30661C6CCF60E68800F@enbmail01.lsi.com> <50697b2c0902191258ye5aa478gecaf7b7b097e3eba@mail.gmail.com> <7F0503CD69378F49BE0DC30661C6CCF62783D662@enbmail01.lsi.com> <50697b2c0902220147y4c8dbf94j1415aae9ee7d640@mail.gmail.com> <87k57iu16j.fsf@mulj.homelinux.net> Message-ID: <7F0503CD69378F49BE0DC30661C6CCF62783D688@enbmail01.lsi.com> Hi Hrvoje, I tried also as follows: #!/usr/bin/env python import wx class CopyAndPaste(object): def __init__(self): pass def set_copy_and_paste(self): ... and CopyAndPaste is being called with: ... class ListControlMeta(wx.Frame, CopyAndPaste): pass class ListControl(wx.Frame, CopyAndPaste): def __init__(self, parent, id, title, list, max_list_width, log_stream, style=wx.DEFAULT_FRAME_STYLE): wx.Frame.__init__(self,parent,id,title,size=(max_list_width,-1), style=style) self.list = list ... But I'm still getting: $ python -u ./failover_pickle_demo09.py Traceback (most recent call last): File "./failover_pickle_demo09.py", line 324, in class ListControlMeta(wx.Frame, CopyAndPaste): TypeError: Error when calling the metaclass bases metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases So, obviously the line in blue is not to Python's liking. Bye, Ron. > -----Original Message----- > From: Hrvoje Niksic [mailto:hniksic at xemacs.org] > Sent: Sunday, February 22, 2009 14:05 > To: python-list at python.org > Subject: Re: "metaclass conflict" error: where is noconflict ? > > "Barak, Ron" writes: > > > class CopyAndPaste(): > > CopyAndPaste is an old-style class. Make it a new-style > class, and you'll probably be able to inherit from it and > wx.Frame without explicitly creating a new metaclass. > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From stef.mientki at gmail.com Sun Feb 22 08:43:23 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Sun, 22 Feb 2009 14:43:23 +0100 Subject: can error messages be improved or can they be overridden ? Message-ID: <49A1567B.5020407@gmail.com> hello, I often get an error message like this self.Brick.Par [ self.EP[2] ]['FileName'] = filename IndexError: list index out of range Now it would be very welcome, if the error message specified which index is out of range, in this case e.g., - specifying the length of self.EP - specifying the value of self.EP[2] - specifying the length of self.Brick.Par etc.. Is there a way to override the error message and provide this information, or is it impossible ? And if it's possible, am I the only one who often stumbles about this problem ? (I expect many people must have bounced in this problem before me ;-) thanks, Stef Mientki From steve at holdenweb.com Sun Feb 22 09:01:43 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 22 Feb 2009 09:01:43 -0500 Subject: Find the location of a loaded module In-Reply-To: References: <5879412d-ffba-4fd9-82b7-7e798dc425e3@f3g2000yqf.googlegroups.com> Message-ID: Gabriel Genellina wrote: > En Sat, 21 Feb 2009 14:51:40 -0200, escribi?: > >> "Gabriel Genellina" wrote: >>> En Fri, 20 Feb 2009 20:44:21 -0200, Aaron Scott >>> escribi=F3: >>> >>> > So, the problem lies with how Python cached the modules in memory. >>> > Yes, the modules were in two different locations and yes, the one that >>> > I specified using its direct path should be the one loaded. The >>> > problem is, the module isn't always loaded -- if it's already in >>> > memory, it'll use that instead. And since the modules had the same >>> > name, Python wouldn't distinguish between them, even though they >>> > weren't exactly the same. >>> >>> Yes, that's how import works. It's barely documented, and you finally >>> learned it the hard way... >> >> I'd argue a little bit with "barely documented". In the reference, the >> discussion of the import statement starts off saying: >> >> Import statements are executed in two steps: (1) find a module, >> and initialize it if necessary; (2) define a name or names in the >> local namespace (of the scope where the import statement occurs). >> >> The third paragraph then says: >> >> The system maintains a table of modules that have been or are being >> initialized, indexed by module name. This table is accessible as >> sys.modules. When a module name is found in this table, step (1) >> is finished. >> >> That is pretty up front and unambiguous documentation. > > Sure? At a minimum, it doesn't define what "module name" means (isnt't > so easy). It does not describe correctly how packages are handled, nor > dotted names that aren't packages. It does not describe sys.meta_path > nor sys.path_hooks, than can *radically* alter things. It does not > describe absolute vs. relative imports, nor the "mix" of them in 2.x. It > doesn't menction the *caller* module as relevant. > >> However, the consequences of that statement won't be immediately clear >> on first reading. I think it would have cleared up Aaron's confusion >> if he'd happened to think to read it. But since he knew the syntax >> of the import statement already, I'm not surprised he did not read it. >> >> The Tutorial, in the section on modules and import, says: >> >> A module can contain executable statements as well as function >> definitions. These statements are intended to initialize the >> module. They are executed only the first time the module is imported >> somewhere. >> >> This is considerably less precise, if more superficially understandable. >> I wonder if it would be worth expanding on that statement to mention >> that the module is not even looked for on disk if a module by that >> name has already been imported. > > If only that were true... Importers can do almost anything they want. > The behaviour you describe is only what happens when a) there are no > meta_path hooks installed, b) there are no path_hooks involved, c) > __import__ has not been replaced, and d) you are importing a module from > the filesystem. > > This is what I call "barely documented". > Fortunately Brett Cannon has been working hard in this area, and we are likely to see more straightforward import semantics in the near future. In my own meanderings through the import system it did seem to me like something that had grown organically into an arcane and impenetrable system that was exceedingly difficult to understand. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sun Feb 22 09:08:29 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 22 Feb 2009 09:08:29 -0500 Subject: datetime.time and midnight In-Reply-To: <49A083DA.7000107@stoneleaf.us> References: <49A083DA.7000107@stoneleaf.us> Message-ID: Ethan Furman wrote: > Greetings, List! > > I was curious if anyone knew the rationale behind making midnight False? > > --> import datetime > --> midnight = datetime.time(0,0,0) > --> bool(midnight) > False > > To my way of thinking, midnight does actually exist so it should be > true. If datetime.time was measuring an *amount* of time, rather than a > certain point during the day, then a time of 0:0:0 should certainly be > False as it would mean no time had passed. However, since midnight does > indeed exist (as many programmers have observed when deadlines approach > ;) I would think it should be true. One might ask the rationale behind treating a time as Boolean in the first place. Let me guess: you are retrieving the times from a database, and you are testing of the NULL value? If that's the case, a simple "is not None" will overcome the objection. Though I do agree it's a little weird for bool(midnight) to return False. Probably worth a bug report. I imagine it's just returning the bool of the underlying integer. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sun Feb 22 09:21:12 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 22 Feb 2009 09:21:12 -0500 Subject: Python AppStore / Marketplace In-Reply-To: References: Message-ID: Marcel Luethi wrote: > Dear Community > > Now I'm standing here, having this great idea for a brand new rocking > app... > But where do I start? I want it to be multi-platform (Linux, Mac OS X, > Windows). It should be easy to install and upgrade. It should be self- > contained, independent of an already installed Python. And of course - > the world should be able to find it! > > So what do I do? I'm studying all the possibilities to make it self- > contained (virtualenv, InstantDjango, PortablePython...), searching > for installers (PyInstaller, EasyInstall, ...), looking into making it > executable on every platform (py2exe, py2app, cx_Freeze, ...), > analyzing all GUI frameworks (wxPython, PyGTK, PyQt, ...), > investigating all hosting providers (Google Code, SourceForge, ...) > and so on and so forth. > > This is not easy at all! > > Using my iPhone I suddenly realize how easy it is to find applications > in Apple's AppStore. How easy and fast it is to install or de-install > an app. My iPhone even checks in the background if there is an upgrade > which could be installed painlessly. > > Then I see VMware's Virtual Appliance Marketplace, where you can > download already pre-configured "appliances" for all kind of stuff. > You can even download a basic appliance, install and configure your > servers and tools - and upload it again, so that others can profit of > your work. > > Unfortunately there's nothing like this in the Python world... > > My idea: what about having a beefed up Cheeseshop for Python apps and > an accompanying client app kind of iTunes for Python apps? > > The server side could be easily implemented with any of the current > web frameworks. It's simply a management platform for the app packages > (descriptions, versions, platforms, licenses, user's comments, number > of downloads, ...) and the package files themselves. > It should be definitely hosted by the PSF I think. > > The multi-platform client should be intuitively and elegantly allow > app browsing, downloading and installing those Python apps. In that > respect it is sort of a Linux package manager (Synaptic, YUM, ...). > But this is only the end-user related stuff. Furthermore it should > allow to create new apps (probably based on a previously downloaded > base app), package and upload them again (kind of Google AppEngine > Launcher). Those base packages should include some basic management > framework (for installation and configuration) and hopefully soon > after the release of this platform they will be created in a broad > variety to allow app developers to choose among many Python-version/ > platform/GUI/...-combinations. > > IMHO an architecture like this would greatly enhance the productivity > of the whole Python community by capitalizing the knowledge of many > Python specialists. I don't have to find/install/configure all the > basic stuff myself (see above) to build my app. But I can concentrate > on my app because I'm standing on the shoulders of giants. > > I believe it also would make Python as a great platform more visible > to the world - because there is only one place you have to go... > > > What do you think??? > Is this crazy??? Or simply stupid? > Or is this the way to world domination...? ;-) > > > Unfortunately I'm not expert enough to build such a system - but if > there is enough interest in the community I gladly would like to help. > Without wishing in any way to "rain on your parade", a "beefed up cheeseshop" isn't a new idea. When you say it should be "... simply an management platform for the app packages" this doesn't solve any problems at all. And the "multiplatform client" that should "easily and elegantly allow app browsing, downloading and installing those apps" would presumably have to account for the many differences in package formats and install requirements between the different platforms. So I don't think you will find too much disagreement that this is an excellent idea, but neither do I think you fully appreciate the difficulties this would involve. There have been many discussions on the python-dev list and the distutils list about how applications should and/or could be distributed, but so far little universal agreement on how to achieve this nirvana of which you conceive. > Marcel > > > PS: > Naming is important! "Python AppStore" or "Python App Marketplace" is > nice - but I would prefer something like "Python Bazaar" or "Python > Souq" to emphasize the community aspect. Unfortunately I have no idea what a "souq" is, so I suspect this may be linguistically biased against English speakers. Or perhaps I'm just ignorant. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From denis.kasak at gmail.com Sun Feb 22 09:49:25 2009 From: denis.kasak at gmail.com (Denis Kasak) Date: Sun, 22 Feb 2009 15:49:25 +0100 Subject: To unicode or not to unicode In-Reply-To: References: Message-ID: <39e19a010902220649u6d39eb51l9dc164e35ecc222@mail.gmail.com> On Sun, Feb 22, 2009 at 1:39 AM, Ross Ridge wrote: > Ross Ridge (Sat, 21 Feb 2009 18:06:35 -0500) >> I understand what Unicode and MIME are for and why they exist. Neither >> their merits nor your insults change the fact that the only current >> standard governing the content of Usenet posts doesn't require their >> use. > > Thorsten Kampe wrote: >>That's right. As long as you use pure ASCII you can skip this nasty step >>of informing other people which charset you are using. If you do use non >>ASCII then you have to do that. That's the way virtually all newsreaders >>work. It has nothing to do with some 21+ year old RFC. Even your Google >>Groups "newsreader" does that ('content="text/html; charset=UTF-8"'). > > No, the original post demonstrates you don't have include MIME headers for > ISO 8859-1 text to be properly displayed by many newsreaders. The fact > that your obscure newsreader didn't display it properly doesn't mean > that original poster's newsreader is broken. And how is this kind of assuming better than clearly stating the used encoding? Does the fact that the last official Usenet RFC doesn't mandate content-type headers mean that all bets are off and that we should rely on guesswork to determine the correct encoding of a message? No, it means the RFC is outdated and no longer suitable for current needs. >>Being explicit about your encoding is 99% of the whole Unicode magic in >>Python and in any communication across the Internet (may it be NNTP, >>SMTP or HTTP). > > HTTP requires the assumption of ISO 8859-1 in the absense of any > specified encoding. Which is, of course, completely irrelevant for this discussion. Or are you saying that this fact should somehow obliterate the need for specifying encodings? >>Your Google Groups simply uses heuristics to guess the >>encoding the OP probably used. Windows newsreaders simply use the locale >>of the local host. That's guessing. You can call it assuming but it's >>still guessing. There is no way you can be sure without any declaration. > > Newsreaders assuming ISO 8859-1 instead of ASCII doesn't make it a guess. > It's just a different assumption, nor does making an assumption, ASCII > or ISO 8850-1, give you any certainty. Assuming is another way of saying "I don't know, so I'm using this arbitrary default", which is not that different from a completely wild guess. :-) >>And it's unpythonic. Python "assumes" ASCII and if the decodes/encoded >>text doesn't fit that encoding it refuses to guess. > > Which is reasonable given that Python is programming language where it's > better to have more conservative assumption about encodings so errors > can be more quickly diagnosed. A newsreader however is a different > beast, where it's better to make a less conservative assumption that's > more likely to display messages correctly to the user. Assuming ISO > 8859-1 in the absense of any specified encoding allows the message to be > correctly displayed if the character set is either ISO 8859-1 or ASCII. > Doing things the "pythonic" way and assuming ASCII only allows such > messages to be displayed if ASCII is used. Reading this paragraph, I've began thinking that we've misunderstood each other. I agree that assuming ISO 8859-1 in the absence of specification is a better guess than most (since it's more likely to display the message correctly). However, not specifying the encoding of a message is just asking for trouble and assuming anything is just an attempt of cleaning someone's mess. Unfortunately, it is impossible to detect the encoding scheme just by heuristics and with hundreds of encodings in existence today, the only real solution to the problem is clearly stating your content-type. Since MIME is the most accepted way of doing this, it should be the preferred way, RFC'ed or not. -- Denis Kasak From Ron.Barak at lsi.com Sun Feb 22 09:51:44 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Sun, 22 Feb 2009 14:51:44 +0000 Subject: can error messages be improved or can they be overridden ? In-Reply-To: <49A1567B.5020407@gmail.com> References: <49A1567B.5020407@gmail.com> Message-ID: <7F0503CD69378F49BE0DC30661C6CCF62783D690@enbmail01.lsi.com> Hi Stef, You can do something like (not tested): try: self.Brick.Par [ self.EP[2] ]['FileName'] = filename except IndexError,e: msg = "%s: '%s %s %s %d" % (e.strerror,e.filename,self.EP,self.EP[2],len(self.Brick.Par)) print msg Bye, Ron. > -----Original Message----- > From: Stef Mientki [mailto:stef.mientki at gmail.com] > Sent: Sunday, February 22, 2009 15:43 > To: python-list at python.org > Subject: can error messages be improved or can they be overridden ? > > hello, > > I often get an error message like this > > self.Brick.Par [ self.EP[2] ]['FileName'] = filename > IndexError: list index out of range > > Now it would be very welcome, > if the error message specified which index is out of range, > in this case e.g., > - specifying the length of self.EP > - specifying the value of self.EP[2] > - specifying the length of self.Brick.Par etc.. > > Is there a way to override the error message and provide this > information, or is it impossible ? > > And if it's possible, am I the only one who often stumbles > about this problem ? > (I expect many people must have bounced in this problem before me ;-) > > thanks, > Stef Mientki > > > From darcy at druid.net Sun Feb 22 10:10:19 2009 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sun, 22 Feb 2009 10:10:19 -0500 Subject: datetime.time and midnight In-Reply-To: References: <49A083DA.7000107@stoneleaf.us> <49A0946B.8040206@mrabarnett.plus.com> Message-ID: <20090222101019.e53478c8.darcy@druid.net> On Sun, 22 Feb 2009 05:20:31 -0200 "Gabriel Genellina" wrote: > En Sat, 21 Feb 2009 21:55:23 -0200, MRAB > escribi?: > > I think it's because midnight is to the time of day what zero is to > > integers, or an empty string is to strings, or an empty container ... > > So chr(0) should be False too... >>> chr(0) '\x00' That's not an empty string. This is like... >>> bool([0]) True Now if Python had a char type one might expect the zero char to be False but a collection of anything, even if the elements are False, is not empty and hence is True. As someone else said, there's not much point in casting time to boolean but if you do, it is a base type, not a sequence so I wouldn't expect to apply sequence logic to the outcome. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From tmohr at s.netic.de Sun Feb 22 10:13:02 2009 From: tmohr at s.netic.de (Torsten Mohr) Date: Sun, 22 Feb 2009 16:13:02 +0100 Subject: Reference or Value? Message-ID: Hi, how is the rule in Python, if i pass objects to a function, when is this done by reference and when is it by value? def f1(a): a = 7 b = 3 f1(b) print b => 3 Integers are obviously passed by value, lists and dicts by reference. Is there a general rule? Some common formulation? Thanks for any hints, Torsten. From steve at holdenweb.com Sun Feb 22 10:14:24 2009 From: steve at holdenweb.com (Steve Holden) Date: Sun, 22 Feb 2009 10:14:24 -0500 Subject: can error messages be improved or can they be overridden ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF62783D690@enbmail01.lsi.com> References: <49A1567B.5020407@gmail.com> <7F0503CD69378F49BE0DC30661C6CCF62783D690@enbmail01.lsi.com> Message-ID: Barak, Ron wrote: > Hi Stef, > > You can do something like (not tested): > > try: > self.Brick.Par [ self.EP[2] ]['FileName'] = filename > except IndexError,e: > msg = "%s: '%s %s %s %d" % (e.strerror,e.filename,self.EP,self.EP[2],len(self.Brick.Par)) > print msg > Unfortunately this too can raise an IndexError if self.EP has less than three elements ... regards Steve > Bye, > Ron. > >> -----Original Message----- >> From: Stef Mientki [mailto:stef.mientki at gmail.com] >> Sent: Sunday, February 22, 2009 15:43 >> To: python-list at python.org >> Subject: can error messages be improved or can they be overridden ? >> >> hello, >> >> I often get an error message like this >> >> self.Brick.Par [ self.EP[2] ]['FileName'] = filename >> IndexError: list index out of range >> >> Now it would be very welcome, >> if the error message specified which index is out of range, >> in this case e.g., >> - specifying the length of self.EP >> - specifying the value of self.EP[2] >> - specifying the length of self.Brick.Par etc.. >> >> Is there a way to override the error message and provide this >> information, or is it impossible ? >> >> And if it's possible, am I the only one who often stumbles >> about this problem ? >> (I expect many people must have bounced in this problem before me ;-) >> >> thanks, >> Stef Mientki >> >> >> > -- > http://mail.python.org/mailman/listinfo/python-list > -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From lists at cheimes.de Sun Feb 22 10:15:14 2009 From: lists at cheimes.de (Christian Heimes) Date: Sun, 22 Feb 2009 16:15:14 +0100 Subject: "Byte" type? In-Reply-To: <00d501c994c8$d8eab400$0d00a8c0@hendrik> References: <4997aa38$0$1678$742ec2ed@news.sonic.net> <499841bf$0$1624$742ec2ed@news.sonic.net> <499859e2$0$1618$742ec2ed@news.sonic.net> <499f8a8e$0$1588$742ec2ed@news.sonic.net> <49a03081$0$1599$742ec2ed@news.sonic.net> <00d501c994c8$d8eab400$0d00a8c0@hendrik> Message-ID: Hendrik van Rooyen wrote: > "Christian Heimes" wrote: > >> John Nagle wrote >>> If "bytes", a new keyword, works differently in 2.6 and 3.0, that was >>> really >>> dumb. There's no old code using "bytes". So converting code to 2.6 means >>> it has to be converted AGAIN for 3.0. That's a good reason to ignore >>> 2.6 as >>> defective. >> Please don't call something dumb that you don't fully understand. It's >> offenses the people who have spent lots of time developing Python -- >> personal, unpaid and voluntary time! > > Crying out; "Please do not criticise me, I am doing it for free!" does > not justify delivering sub standard work - that is the nature of the > open source process - if you lift your head and say or do something, > there are bound to be some objections - some thoughtful and valid, > and others merely carping. Being sensitive about it serves no purpose. There are proper and polites way to criticize somebody or something -- it's called constructive criticism -- and there are offensive ways. I hope we can all agree that calling something dumb without good reason is impolite. The bytes alias does exactly what it was designed for -- and documented, too. It just doesn't do what somebody expects it to do. Is this really sub standard? I don't think so! Christian From rzantow at gmail.com Sun Feb 22 10:21:19 2009 From: rzantow at gmail.com (rzed) Date: Sun, 22 Feb 2009 15:21:19 +0000 Subject: Scanning a file character by character References: <557daab0-504f-47f4-84a7-e98000e7c3b1@y1g2000pra.googlegroups.com> <203f699b-de30-422a-aa7d-97eb62d6ebba@a12g2000pro.googlegroups.com> Message-ID: Spacebar265 wrote in news:c86cd530-cee5-4de6-8e19-304c664c9ca0 at c12g2000yqj.googlegroups.c om: > On Feb 11, 1:06?am, Duncan Booth > wrote: [...] >> >>> re.split("(\w+)", "The quick brown fox jumps, and falls >> >>> over.")[1::2] >> >> ['The', 'quick', 'brown', 'fox', 'jumps', 'and', 'falls', >> 'over'] > > Using this code how would it load each word into a temporary > variable. >>> import re >>> list_name = re.split("(\w+)", "The quick brown fox jumps, and falls over.")[1::2] >>> list_name[2] 'brown' You see, temporary variables are set. Their names are spelled 'list_name[x]', where x is an index into the list. If your plan was instead to have predefined names of variables, what would they be called? How many would you have? With list variables, you will have enough, and you will know their names. -- rzed From lists at cheimes.de Sun Feb 22 10:23:58 2009 From: lists at cheimes.de (Christian Heimes) Date: Sun, 22 Feb 2009 16:23:58 +0100 Subject: Reference or Value? In-Reply-To: References: Message-ID: Torsten Mohr schrieb: > Hi, > > how is the rule in Python, if i pass objects to a function, when is this > done by reference and when is it by value? > > def f1(a): > a = 7 > > b = 3 > f1(b) > print b > => 3 > > Integers are obviously passed by value, lists and dicts by reference. > > Is there a general rule? Some common formulation? Python uses neither call by reference nor call by value. It's called call by sharing or call by object. http://effbot.org/zone/call-by-object.htm Christian From Samnsparky at gmail.com Sun Feb 22 10:46:30 2009 From: Samnsparky at gmail.com (Sparky) Date: Sun, 22 Feb 2009 07:46:30 -0800 (PST) Subject: Windows Install Command Line Message-ID: <79f5a45d-e603-41f1-8858-1206fb95f1fd@b16g2000yqb.googlegroups.com> For internal distribution purposes, I was wondering if there was an already established process/program for installing Python on Windows machines without using an msi file or compiling from source. Basically I need the standard distribution installed by either a batch file or python script through py2exe. Thank you in advance, Sam From duncan.booth at invalid.invalid Sun Feb 22 10:47:16 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 22 Feb 2009 15:47:16 GMT Subject: Reference or Value? References: Message-ID: Torsten Mohr wrote: > how is the rule in Python, if i pass objects to a function, when is this > done by reference and when is it by value? > > def f1(a): > a = 7 > > b = 3 > f1(b) > print b >=> 3 > > Integers are obviously passed by value, lists and dicts by reference. > > Is there a general rule? Some common formulation? Yes, integers are 'obviously' passed by value, except that if they were you couldn't do this: >>> x = 26*1000 >>> y = 26000 >>> id(x)==id(y) False >>> def whichint(arg): if id(arg)==id(x): print "You passed x" elif id(arg)==id(y): print "You passed y" >>> whichint(x) You passed x >>> whichint(y) You passed y The general rule is that everything is passed in exactly the same way. From google at mrabarnett.plus.com Sun Feb 22 10:53:59 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sun, 22 Feb 2009 15:53:59 +0000 Subject: datetime.time and midnight In-Reply-To: References: <49A083DA.7000107@stoneleaf.us> <49A0946B.8040206@mrabarnett.plus.com> Message-ID: <49A17517.5010307@mrabarnett.plus.com> Gabriel Genellina wrote: > En Sat, 21 Feb 2009 21:55:23 -0200, MRAB > escribi?: > >> Ethan Furman wrote: >>> Greetings, List! >>> I was curious if anyone knew the rationale behind making midnight >>> False? >>> --> import datetime >>> --> midnight = datetime.time(0,0,0) >>> --> bool(midnight) >>> False >>> To my way of thinking, midnight does actually exist so it should be >>> true. If datetime.time was measuring an *amount* of time, rather >>> than a certain point during the day, then a time of 0:0:0 should >>> certainly be False as it would mean no time had passed. However, >>> since midnight does indeed exist (as many programmers have observed >>> when deadlines approach ;) I would think it should be true. >>> >> I think it's because midnight is to the time of day what zero is to >> integers, or an empty string is to strings, or an empty container ... > > So chr(0) should be False too... > If that returned a character, then yes, but it returns a non-empty string, so no. :-) From google at mrabarnett.plus.com Sun Feb 22 11:09:26 2009 From: google at mrabarnett.plus.com (MRAB) Date: Sun, 22 Feb 2009 16:09:26 +0000 Subject: Reference or Value? In-Reply-To: References: Message-ID: <49A178B6.1040701@mrabarnett.plus.com> Torsten Mohr wrote: > Hi, > > how is the rule in Python, if i pass objects to a function, when is this > done by reference and when is it by value? > > def f1(a): > a = 7 > > b = 3 > f1(b) > print b > => 3 > > Integers are obviously passed by value, lists and dicts by reference. > > Is there a general rule? Some common formulation? > They are all passed the same way: def f2(a): a = [7] b = [3] f2(b) print b => [3] It's just that lists and dicts are containers whose contents you can change (they are mutable), but integers aren't containers (they are immutable). Tuples are also containers, but you can't change their contents (they are immutable). From andrew at acooke.org Sun Feb 22 11:37:27 2009 From: andrew at acooke.org (andrew cooke) Date: Sun, 22 Feb 2009 13:37:27 -0300 (CLST) Subject: Reference or Value? In-Reply-To: References: Message-ID: <5b1b0ac71a7fe5a4e89092b0e8ec7c78.squirrel@acooke.dyndns.org> as far as i understand things, the best model is: 1 - everything is an object 2 - everything is passed by reference 3 - some objects are immutable 4 - some (immutable?) objects are cached/reused by the system andrew Torsten Mohr wrote: > Hi, > > how is the rule in Python, if i pass objects to a function, when is this > done by reference and when is it by value? > > def f1(a): > a = 7 > > b = 3 > f1(b) > print b > => 3 > > Integers are obviously passed by value, lists and dicts by reference. > > Is there a general rule? Some common formulation? > > > Thanks for any hints, > Torsten. > > -- > http://mail.python.org/mailman/listinfo/python-list > > From deets at nospam.web.de Sun Feb 22 11:52:16 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 22 Feb 2009 17:52:16 +0100 Subject: Musings: Using decorators to reduce duplicate exception handling In-Reply-To: <878wo4verq.fsf@agentultra.com> References: <878wo4verq.fsf@agentultra.com> Message-ID: <70de61Fp2e8U1@mid.uni-berlin.de> J Kenneth King schrieb: > I recently started a project called TracShell > (http://code.google.com/p/tracshell) where I make heavy use of the > xmlrpclib core module. > > When the number of RPC calls was small, wrapping each call in try/except > was acceptable. However, this obviously will duplicate code all over the > place. There are only ever two exceptions that the module itself will > throw: xmlrpclib.ProtocolError and xmlrpclib.Fault -- both very useful, > but not show stoppers. I think the answer depends a lot on the actual error handling performed. If you want retries, either immediately, or with some larger prologue, it might make sense to abstract that away (I would have suggested the context-manager thing myself, but Cameron did that already). But if you essentially want to abort in all cases, I'd just push the handling upwards, and rather improve the error reporting itself, e.g. by storing away the trace in a temporary file the user can send you. Diez From grante at visi.com Sun Feb 22 11:57:17 2009 From: grante at visi.com (Grant Edwards) Date: Sun, 22 Feb 2009 10:57:17 -0600 Subject: Unexpected long pyserial read delay on Windows References: <49a17e2d$0$1678$742ec2ed@news.sonic.net> Message-ID: <5LidnW-lq61wHjzUnZ2dnUVZ_jqWnZ2d@posted.usinternet> On 2009-02-22, John Nagle wrote: > I've been using PySerial on Windows (Win2000, amusingly) to > drive a Baudot teletype at 45.45 baud. Input and output work, > but there's a delay of about 1 second (!) on the input side > between receiving a character and reporting it to the program. The UART you're using almost certainly has a receive FIFO. Normally, the UART doesn't interrupt the CPU to tell it there's receeve data ready until the FIFO is almost full (eg 12 bytes present in a 16 byte FIFO). If the UART has an empty receive FIFO, and it receives a single character that character goes into the receive FIFO. If data stops coming in before the rx FIFO threshold is reached, the UART will wait 40 bit-times and then interrupt the CPU to tell it there is receive data ready. The thought is that maybe there's more data coming -- we don't want to waste the CPU's time handling a single byte if there's more data coming in. At 45.45 baud, 40 bit-times is pretty close to 1 second. If you don't want to wait 40-bit times for the rx data timeout, then you need to disable the rx FIFO. I'm not sure how you do that in Windows. I don't remember seeing anything in pyserial to do it, but I avoid Windows as much as possible. You might want to go looking around in the device manager to see if there's a checkbox "disalbe FIFO" in the serial port driver config. If not, then Google can probably help. -- Grant From nagle at animats.com Sun Feb 22 12:05:20 2009 From: nagle at animats.com (John Nagle) Date: Sun, 22 Feb 2009 09:05:20 -0800 Subject: Unexpected long pyserial read delay on Windows Message-ID: <49a17e2d$0$1678$742ec2ed@news.sonic.net> I've been using PySerial on Windows (Win2000, amusingly) to drive a Baudot teletype at 45.45 baud. Input and output work, but there's a delay of about 1 second (!) on the input side between receiving a character and reporting it to the program. I'm using the latest "supports 1.5 stop bits" version of PySerial (as noted previously, this is necessary for the old mechanical Teletypes), and opening as follows: ser = serial.Serial(port, baudrate=baud, bytesize=serial.FIVEBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE5, timeout=None) I've tried omitting the timeout parameter, "timeout=0", and "timeout=0.1", none of which seem to change the behavior. The code doing the reading is simply while True : s = ser.read() # get some input for ch in s: ser.write(ch) # write to tty This correctly types back what's typed in, but with a delay of about 10 character times, over 1 second. (Remember, this is a VERY slow serial device.) There's nothing else running; CPU load is under 1%. I've tried "ser.read(1)"; makes no difference. The delay is on the read side; if I put in a "print", the delay occurs before the computer prints the received character. Is this some Windows thing? I've looked at serialwin32.py around line 88, and don't see any nonzero timeout parameters being fed to Windows when "timeout=None". Checking the Microsoft documentation, at http://msdn.microsoft.com/en-us/library/aa363190(VS.85).aspx feeding all zeroes into the COMMTIMEOUT structure should result in no additional delays. John Nagle From digitig at gmail.com Sun Feb 22 12:09:29 2009 From: digitig at gmail.com (Tim Rowe) Date: Sun, 22 Feb 2009 17:09:29 +0000 Subject: datetime.time and midnight In-Reply-To: <0e8ef14d-ffa9-4513-abe2-404aeb91a079@i38g2000yqd.googlegroups.com> References: <0e8ef14d-ffa9-4513-abe2-404aeb91a079@i38g2000yqd.googlegroups.com> Message-ID: 2009/2/22 Mark Dickinson : > On Feb 21, 10:44 pm, Ethan Furman wrote: > >> --> midnight = datetime.time(0,0,0) >> --> bool(midnight) >> False > > I'd call this a bug. No more so than zero being false. Zero exists too (check my bank balance). Once you've accepted non-Boolean types having Boolean values, the logic of what value they have is always going to be a bit hairy. If you're unsure of the logic, just test against a value or a range. After all, what value do you *expect* a time of day to have when interpreted as a Boolean? If you don't have an expectation, why are you interpreting it as a Boolean? -- Tim Rowe From marcel.luethi at mlsystems.ch Sun Feb 22 12:17:23 2009 From: marcel.luethi at mlsystems.ch (Marcel Luethi) Date: Sun, 22 Feb 2009 18:17:23 +0100 Subject: Python AppStore / Marketplace In-Reply-To: References: Message-ID: <46ed0da80902220917r6bb696a6u68d67f9f8674aa28@mail.gmail.com> Hi Steve I really appreciate your feedback! Certainly I'm no expert "for the many differences in package formats and install requirements between the different platforms". But let me explain a bit more: I don't have the idea that the multi-platform client should handle all the different package formats - instead it should define a new one: a simple zip-file. For me "self-contained, independent of an already installed Python" means that there is a complete, isolated Python environment for each app (see virtualenv). So Python would go into APP/lib/..., APP/bin/... and the app itself into APP/app/... Certainly there would be also some more files like the app icons and a description file APP/app.xml The packaged app is a zip/gzip of the whole APP directory. Installing is simply unpacking to a defined directory (into something like PythonApps/APP) and setting it up as an os app. Because there is a complete Python environment for each app (disk space and bandwidth are cheap nowadays!) and all 3rd party libs are "integrated" there shouldn't be any other local dependencies. So there could be APP1 with a Python 2.5.2 + a wxPython/wxWidgets and another APP2 with Python 2.6.1 + PyQt4. (This is something I'm not really sure about: is it possible to setup all binary 3rd party libs ?*.so/*.pyo/*.dll/*.pyd/...? into an isolated Python environment?) Of course there can't be a single APP1 for all possible platforms. But there could be one setup for each: APP1_Linux, APP1_MacOsX10.5, APP1_WinXP The developer has to setup/test every supported platform anyway. The "bootstrap" (standing on the shoulders of giants) could work like this: - first there is a base app "Python 2.5.1 for Mac OS X 10.5" built by developer A - next developer B creates "Django 1.0.2 for Mac OS X 10.5" based on the one above - then developer C integrates Pinax into B's app and creates "Pinax 0.5.1 for Mac OS X 10.5" All those "apps" could be found in Python AppStore and a developer could search for the one which matches his requirements best. His implementation cost is therefore minimized. A iTunes-like client would allow the end-user to find apps - assumed that all (or most) developers upload their apps into the one and only Python AppStore. The client (there should be one for every supported platform) is a front-end application for the (PSF-) hosted "super-cheeseshop", which end-users are not expected to access directly. Is my nirvana really that far away? ;-) Best regards, Marcel PS A "Souq" is an Arab market (similar to a bazaar): http://en.wikipedia.org/wiki/Souq I got to know one visiting one last year in Oman - and I really liked it. But now I can see that soundex('souq') == soundex('suck'). You're right, this would be a very bad choice... ;-) On Sun, Feb 22, 2009 at 3:21 PM, Steve Holden wrote: > Marcel Luethi wrote: > > Dear Community > > > > Now I'm standing here, having this great idea for a brand new rocking > > app... > > But where do I start? I want it to be multi-platform (Linux, Mac OS X, > > Windows). It should be easy to install and upgrade. It should be self- > > contained, independent of an already installed Python. And of course - > > the world should be able to find it! > > > > So what do I do? I'm studying all the possibilities to make it self- > > contained (virtualenv, InstantDjango, PortablePython...), searching > > for installers (PyInstaller, EasyInstall, ...), looking into making it > > executable on every platform (py2exe, py2app, cx_Freeze, ...), > > analyzing all GUI frameworks (wxPython, PyGTK, PyQt, ...), > > investigating all hosting providers (Google Code, SourceForge, ...) > > and so on and so forth. > > > > This is not easy at all! > > > > Using my iPhone I suddenly realize how easy it is to find applications > > in Apple's AppStore. How easy and fast it is to install or de-install > > an app. My iPhone even checks in the background if there is an upgrade > > which could be installed painlessly. > > > > Then I see VMware's Virtual Appliance Marketplace, where you can > > download already pre-configured "appliances" for all kind of stuff. > > You can even download a basic appliance, install and configure your > > servers and tools - and upload it again, so that others can profit of > > your work. > > > > Unfortunately there's nothing like this in the Python world... > > > > My idea: what about having a beefed up Cheeseshop for Python apps and > > an accompanying client app kind of iTunes for Python apps? > > > > The server side could be easily implemented with any of the current > > web frameworks. It's simply a management platform for the app packages > > (descriptions, versions, platforms, licenses, user's comments, number > > of downloads, ...) and the package files themselves. > > It should be definitely hosted by the PSF I think. > > > > The multi-platform client should be intuitively and elegantly allow > > app browsing, downloading and installing those Python apps. In that > > respect it is sort of a Linux package manager (Synaptic, YUM, ...). > > But this is only the end-user related stuff. Furthermore it should > > allow to create new apps (probably based on a previously downloaded > > base app), package and upload them again (kind of Google AppEngine > > Launcher). Those base packages should include some basic management > > framework (for installation and configuration) and hopefully soon > > after the release of this platform they will be created in a broad > > variety to allow app developers to choose among many Python-version/ > > platform/GUI/...-combinations. > > > > IMHO an architecture like this would greatly enhance the productivity > > of the whole Python community by capitalizing the knowledge of many > > Python specialists. I don't have to find/install/configure all the > > basic stuff myself (see above) to build my app. But I can concentrate > > on my app because I'm standing on the shoulders of giants. > > > > I believe it also would make Python as a great platform more visible > > to the world - because there is only one place you have to go... > > > > > > What do you think??? > > Is this crazy??? Or simply stupid? > > Or is this the way to world domination...? ;-) > > > > > > Unfortunately I'm not expert enough to build such a system - but if > > there is enough interest in the community I gladly would like to help. > > > Without wishing in any way to "rain on your parade", a "beefed up > cheeseshop" isn't a new idea. When you say it should be "... simply an > management platform for the app packages" this doesn't solve any > problems at all. > > And the "multiplatform client" that should "easily and elegantly allow > app browsing, downloading and installing those apps" would presumably > have to account for the many differences in package formats and install > requirements between the different platforms. > > So I don't think you will find too much disagreement that this is an > excellent idea, but neither do I think you fully appreciate the > difficulties this would involve. > > There have been many discussions on the python-dev list and the > distutils list about how applications should and/or could be > distributed, but so far little universal agreement on how to achieve > this nirvana of which you conceive. > > > Marcel > > > > > > PS: > > Naming is important! "Python AppStore" or "Python App Marketplace" is > > nice - but I would prefer something like "Python Bazaar" or "Python > > Souq" to emphasize the community aspect. > > Unfortunately I have no idea what a "souq" is, so I suspect this may be > linguistically biased against English speakers. Or perhaps I'm just > ignorant. > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > Holden Web LLC http://www.holdenweb.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -- ******************************************** MLSystems GmbH Marcel L?thi El.-Ing. HTL, Inf.-Ing. HTL/NDS, CNE, CNS Betriebswirtschafts-Ing. HTL/NDS Schwarzbachstrasse 22a CH-3113 Rubigen / Switzerland Tel. +41 (31) 721 83 25 Mob. +41 (79) 709 66 58 marcel.luethi at mlsystems.ch ******************************************** -------------- next part -------------- An HTML attachment was scrubbed... URL: From hniksic at xemacs.org Sun Feb 22 12:44:04 2009 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Sun, 22 Feb 2009 18:44:04 +0100 Subject: "metaclass conflict" error: where is noconflict ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF62783D688@enbmail01.lsi.com> (Ron Barak's message of "Sun\, 22 Feb 2009 13\:41\:20 +0000") References: <7F0503CD69378F49BE0DC30661C6CCF60E68800F@enbmail01.lsi.com> <50697b2c0902191258ye5aa478gecaf7b7b097e3eba@mail.gmail.com> <7F0503CD69378F49BE0DC30661C6CCF62783D662@enbmail01.lsi.com> <50697b2c0902220147y4c8dbf94j1415aae9ee7d640@mail.gmail.com> <87k57iu16j.fsf@mulj.homelinux.net> <7F0503CD69378F49BE0DC30661C6CCF62783D688@enbmail01.lsi.com> Message-ID: <8763j2tli3.fsf@mulj.homelinux.net> "Barak, Ron" writes: > import wx > > class CopyAndPaste(object): > def __init__(self): > pass > > def set_copy_and_paste(self): > ... > > and CopyAndPaste is being called with: > > ... > class ListControlMeta(wx.Frame, CopyAndPaste): > pass You don't need ListControlMeta at all; just inherit from wx.Frame and (new-style) CopyAndPaste directly. > $ python -u ./failover_pickle_demo09.py > Traceback (most recent call last): > File "./failover_pickle_demo09.py", line 324, in > class ListControlMeta(wx.Frame, CopyAndPaste): > TypeError: Error when calling the metaclass bases > metaclass conflict: the metaclass of a derived class must be a > (non-strict) subclass of the metaclasses of all its bases Are you sure you're executing the latest version where CopyAndPaste is a new-style class? The equivalent code works for me: >>> import wx >>> class CopyAndPaste(object): ... pass ... >>> class ListControl(wx.Frame, CopyAndPaste): ... pass ... >>> # no error Could it be that you're using an older version of wx, where wx.Frame itself is an old-style class? From martin at v.loewis.de Sun Feb 22 13:15:32 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 22 Feb 2009 19:15:32 +0100 Subject: Windows Install Command Line In-Reply-To: <79f5a45d-e603-41f1-8858-1206fb95f1fd@b16g2000yqb.googlegroups.com> References: <79f5a45d-e603-41f1-8858-1206fb95f1fd@b16g2000yqb.googlegroups.com> Message-ID: <49a19644$0$27378$9b622d9e@news.freenet.de> Sparky wrote: > For internal distribution purposes, I was wondering if there was an > already established process/program for installing Python on Windows > machines without using an msi file or compiling from source. Basically > I need the standard distribution installed by either a batch file or > python script through py2exe. What's wrong with running the MSI from a batch file? msiexec /i pythonxy.msi If you want installation to be silent, add more command line options to msiexec. HTH, Martin From martin at v.loewis.de Sun Feb 22 13:38:10 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 22 Feb 2009 19:38:10 +0100 Subject: "Byte" type? In-Reply-To: References: <4997aa38$0$1678$742ec2ed@news.sonic.net> <499841bf$0$1624$742ec2ed@news.sonic.net> <499859e2$0$1618$742ec2ed@news.sonic.net> <499f8a8e$0$1588$742ec2ed@news.sonic.net> <49a03081$0$1599$742ec2ed@news.sonic.net> Message-ID: <49A19B92.2080102@v.loewis.de> >> Please don't call something dumb that you don't fully understand. It's >> offenses the people who have spent lots of time developing Python -- >> personal, unpaid and voluntary time! > > Crying out; "Please do not criticise me, I am doing it for free!" does > not justify delivering sub standard work - that is the nature of the > open source process - if you lift your head and say or do something, > there are bound to be some objections - some thoughtful and valid, > and others merely carping. Being sensitive about it serves no purpose. Still, John *clearly* doesn't understand what he observes, so asking him not to draw conclusions until he does understand is not defending against criticism. > This is not a helpful response - on the surface JN has a point - If > you have to go through two conversions, then 2.6 does not achieve > what it appears to set out to do. So the issue is simple: > > - do you have to convert twice? Depends on how you write your code. If you use the bytearray type (which John didn't, despite his apparent believe that he did), then no conversion additional conversion is needed. Likewise, if you only use byte (not bytearray) literals, without accessing individual bytes (e.g. if you only ever read and write them, or pass them to the struct module), 2to3 will do the right thing. > - If yes - why? - as he says - there exists no prior code, > so there seems to be no reason not to make it identical > to 3.0 Sure there is. Making the bytes type and the str type identical in 2.x gives the easiest way of porting. Adding bytes as a separate type would have complicated a lot of things. Regards, Martin From nagle at animats.com Sun Feb 22 13:38:11 2009 From: nagle at animats.com (John Nagle) Date: Sun, 22 Feb 2009 10:38:11 -0800 Subject: Unexpected long pyserial read delay on Windows In-Reply-To: <5LidnW-lq61wHjzUnZ2dnUVZ_jqWnZ2d@posted.usinternet> References: <49a17e2d$0$1678$742ec2ed@news.sonic.net> <5LidnW-lq61wHjzUnZ2dnUVZ_jqWnZ2d@posted.usinternet> Message-ID: <49a193c7$0$1581$742ec2ed@news.sonic.net> Grant Edwards wrote: > On 2009-02-22, John Nagle wrote: > >> I've been using PySerial on Windows (Win2000, amusingly) to >> drive a Baudot teletype at 45.45 baud. Input and output work, >> but there's a delay of about 1 second (!) on the input side >> between receiving a character and reporting it to the program. > > The UART you're using almost certainly has a receive FIFO. > Normally, the UART doesn't interrupt the CPU to tell it there's > receeve data ready until the FIFO is almost full (eg 12 bytes > present in a 16 byte FIFO). > > If the UART has an empty receive FIFO, and it receives a single > character that character goes into the receive FIFO. If data > stops coming in before the rx FIFO threshold is reached, the > UART will wait 40 bit-times... Ah, 40 bit times. That's the default. And that's the problem. I thought the accumulation timer was a fixed timer of a few milliseconds. There is a "disable FIFO" checkbox in Windows 2000. It's hard to find. - Log off as user. - Log on as "administrator" - Open Control Panel -> System - Go to "Devices" tab and select "Device manager". - Open "Ports" in the tree and click on desired COM1 port. - Click "Advanced" button. - Set "Receive buffer size" slider to 1. - Click "Disable FIFO" checkbox. - Close all the dialogs. - Reboot. (Yes, it doesn't take effect until the next reboot.) That fixed the problem. Thanks. John Nagle From ark at acm.org Sun Feb 22 13:39:01 2009 From: ark at acm.org (Andrew Koenig) Date: Sun, 22 Feb 2009 18:39:01 GMT Subject: Reference or Value? References: Message-ID: <9Zgol.34884$4m1.18711@bgtnsc05-news.ops.worldnet.att.net> "andrew cooke" wrote in message news:mailman.464.1235320654.11746.python-list at python.org... > as far as i understand things, the best model is: > > 1 - everything is an object > 2 - everything is passed by reference > 3 - some objects are immutable > 4 - some (immutable?) objects are cached/reused by the system 0 - Assignment rebinds the reference on its left-hand side; it does not change the object to which that reference refers. Example: x = 42 y = x Now x and y are bound to the same object x = x + 1 This statement computes the value of x + 1, which is a new object with value 43. It then rebinds x to refer to this object, so x and y now refer to different objects. Therefore: def f(a): a = a + 1 x = 42 f(x) This example behaves analogously to the previous one: The assignment a = a + 1 binds a to a new object, so it does not affect the object to which x is bound. z = [3] y = z z[0] = z[0] + 1 The assignment rebinds z[0] to refer to a new object that has the value 4. This rebinding does not affect the object formerly bound to z[0]. It does, however, affect the value of the object to which z is bound, because it changes the value of its list element. By analogy: def g(b): b[0] = b[0] + 1 w = [42] g(w) Now w[0] will be 43. From stefan_ml at behnel.de Sun Feb 22 14:21:51 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 22 Feb 2009 20:21:51 +0100 Subject: Python dictionary size/entry limit? In-Reply-To: <006db7aa-76c6-4bf4-bf2a-e180f1665e5e@g38g2000yqd.googlegroups.com> References: <499fdbae$0$31865$9b4e6d93@newsspool3.arcor-online.net> <006db7aa-76c6-4bf4-bf2a-e180f1665e5e@g38g2000yqd.googlegroups.com> Message-ID: <49a1a5d0$0$31340$9b4e6d93@newsspool4.arcor-online.net> intelliminer at gmail.com wrote: > Ummm, I didn't know about the dbm databases. It seems there are many > different > modules for this kind of tasks: gdbm, berkeley db, cdb, etc. I'm > needing to implement > a constant hashtable with a large number of keys, but only a small > fraction of them > will be accessed frequently, the read speed is crucial. It would be > ideal if > the implementation caches all the frequently used key/value pairs in > memory. Which > module should I use? And is there a way to specify the amount of > memory it uses for caching? > BTW, the target platform is Linux. Their interfaces are mostly compatible to Python dicts. Just keep your code independent at the beginning and benchmark it against all of them. Stefan From ra.ravi.rav at gmail.com Sun Feb 22 14:44:50 2009 From: ra.ravi.rav at gmail.com (Ravi) Date: Sun, 22 Feb 2009 11:44:50 -0800 (PST) Subject: Forwarding keyword arguments from one function to another Message-ID: The following code didn't work: class X(object): def f(self, **kwds): print kwds try: print kwds['i'] * 2 except KeyError: print "unknown keyword argument" self.g("string", **kwds) def g(self, s, kwds): print s print kwds if __name__ == "__main__": x = X() x.f(k = 2, j = 10) However the following did: class X(object): def f(self, **kwds): print kwds try: print kwds['i'] * 2 except KeyError: print "unknown keyword argument" self.g("string", **kwds) def g(self, s, **kwds): print s print kwds if __name__ == "__main__": x = X() x.f(k = 2, j = 10) Please explain From tim.wintle at teamrubber.com Sun Feb 22 14:52:13 2009 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Sun, 22 Feb 2009 19:52:13 +0000 Subject: Forwarding keyword arguments from one function to another In-Reply-To: References: Message-ID: <1235332334.32144.4.camel@tim-laptop> On Sun, 2009-02-22 at 11:44 -0800, Ravi wrote: > The following code didn't work: > > def g(self, s, kwds): > print s > print kwds This expects the function g to be called with the parameters "s" and "kwds" > def g(self, s, **kwds): > print s > print kwds This expects to be passed the parameter "s", and various keyword arguments, which will be put into the dict "kwds". when you call o.g("string",**kwds) you are passing the parameter "string" as the first parameter, and then a sequence of keyword arguments taken from kwds, which will be passed separately. This is what the second form expects, but not what the first one expects. Tim Wintle From ra.ravi.rav at gmail.com Sun Feb 22 15:09:26 2009 From: ra.ravi.rav at gmail.com (Ravi) Date: Sun, 22 Feb 2009 12:09:26 -0800 (PST) Subject: Forwarding keyword arguments from one function to another References: Message-ID: <2d5cbec9-49ac-4180-bb49-6f518ac3fcad@n21g2000vba.googlegroups.com> I am sorry about the typo mistake, well the code snippets are as: # Non Working: class X(object): def f(self, **kwds): print kwds try: print kwds['i'] * 2 except KeyError: print "unknown keyword argument" self.g("string", kwds) def g(self, s, **kwds): print s print kwds if __name__ == "__main__": x = X() x.f(k = 2, j = 10) # Working One class X(object): def f(self, **kwds): print kwds try: print kwds['i'] * 2 except KeyError: print "unknown keyword argument" self.g("string", **kwds) def g(self, s, **kwds): print s print kwds if __name__ == "__main__": x = X() x.f(k = 2, j = 10) From marduk at letterboxes.org Sun Feb 22 15:09:38 2009 From: marduk at letterboxes.org (Albert Hopkins) Date: Sun, 22 Feb 2009 15:09:38 -0500 Subject: Forwarding keyword arguments from one function to another In-Reply-To: References: Message-ID: <1235333378.17589.6.camel@centar.nbk> On Sun, 2009-02-22 at 11:44 -0800, Ravi wrote: > The following code didn't work: > > class X(object): > def f(self, **kwds): > print kwds > try: > print kwds['i'] * 2 > except KeyError: > print "unknown keyword argument" > self.g("string", **kwds) ^^^^^^ This means call g() with kwds passed as keyword arguments. > def g(self, s, kwds): The method signature is not expecting keyword arguments. > print s > print kwds > > if __name__ == "__main__": > x = X() > x.f(k = 2, j = 10) > > > However the following did: > > class X(object): > def f(self, **kwds): > print kwds > try: > print kwds['i'] * 2 > except KeyError: > print "unknown keyword argument" > self.g("string", **kwds) > > def g(self, s, **kwds): ^^^^^^ The method signature expects (optionally) keyword arguments. > print s > print kwds > > if __name__ == "__main__": > x = X() > x.f(k = 2, j = 10) > > From Samnsparky at gmail.com Sun Feb 22 15:10:59 2009 From: Samnsparky at gmail.com (Sparky) Date: Sun, 22 Feb 2009 12:10:59 -0800 (PST) Subject: Windows Install Command Line References: <79f5a45d-e603-41f1-8858-1206fb95f1fd@b16g2000yqb.googlegroups.com> <49a19644$0$27378$9b622d9e@news.freenet.de> Message-ID: <5e645c6d-8707-4f6b-abd1-798e3802df32@u38g2000yqe.googlegroups.com> On Feb 22, 11:15?am, "Martin v. L?wis" wrote: > Sparky wrote: > > For internal distribution purposes, I was wondering if there was an > > already established process/program for installing Python on Windows > > machines without using an msi file or compiling from source. Basically > > I need the standard distribution installed by either a batch file or > > python script through py2exe. > > What's wrong with running the MSI from a batch file? > > msiexec /i pythonxy.msi > > If you want installation to be silent, add more command line options > to msiexec. > > HTH, > Martin Ah! Wonderful that was exactly what I was looking for. Thanks, Sam From martin at v.loewis.de Sun Feb 22 15:11:41 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 22 Feb 2009 21:11:41 +0100 Subject: Python dictionary size/entry limit? In-Reply-To: References: Message-ID: <49a1b17d$0$28748$9b622d9e@news.freenet.de> intelliminer at gmail.com wrote: > Is there a limit to the size or number of entries that a single > dictionary can possess? On a 32-bit system, the dictionary can have up to 2**31 slots, meaning that the maximum number of keys is slightly smaller (about 2**30). As others have pointed out, Python's or Windows' memory management might have led to fragmentation, so that no contiguous piece of memory to hold the resized dictionary can be found. One solution to that problem would be to use a 64-bit system. Regards, Martin From clp2 at rebertia.com Sun Feb 22 15:11:59 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 22 Feb 2009 12:11:59 -0800 Subject: Is there a way to ask a class what its metaclasses are ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF62783D685@enbmail01.lsi.com> References: <7F0503CD69378F49BE0DC30661C6CCF60E68800F@enbmail01.lsi.com> <50697b2c0902191258ye5aa478gecaf7b7b097e3eba@mail.gmail.com> <7F0503CD69378F49BE0DC30661C6CCF62783D662@enbmail01.lsi.com> <50697b2c0902220147y4c8dbf94j1415aae9ee7d640@mail.gmail.com> <7F0503CD69378F49BE0DC30661C6CCF62783D673@enbmail01.lsi.com> <50697b2c0902220357g762fe390q6535079d42f6afb0@mail.gmail.com> <7F0503CD69378F49BE0DC30661C6CCF62783D685@enbmail01.lsi.com> Message-ID: <50697b2c0902221211k3be5f797k5f0419179864ae4f@mail.gmail.com> On Sun, Feb 22, 2009 at 5:14 AM, Barak, Ron wrote: > Hi Chris, Is there a way to ask a class what its metaclasses are ? > (e.g., how to ask wx.Frame what it's metaclass is) Of course. A metaclass is the type of a class, so it's just type(wx.Frame). Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com > > I'm asking, because, even subclassing from object, viz.: > > class CopyAndPaste(object): > def __init__(self): > pass > ... > > Still gives me: > > $ python -u ./failover_pickle_demo09.py > Traceback (most recent call last): > File "./failover_pickle_demo09.py", line 321, in > class ListControlMeta(wx.Frame, CopyAndPaste): > TypeError: Error when calling the metaclass bases > metaclass conflict: the metaclass of a derived class must be a > (non-strict) subclass of the metaclasses of all its bases > > Bye, > Ron. From marduk at letterboxes.org Sun Feb 22 15:32:23 2009 From: marduk at letterboxes.org (Albert Hopkins) Date: Sun, 22 Feb 2009 15:32:23 -0500 Subject: Forwarding keyword arguments from one function to another In-Reply-To: <2d5cbec9-49ac-4180-bb49-6f518ac3fcad@n21g2000vba.googlegroups.com> References: <2d5cbec9-49ac-4180-bb49-6f518ac3fcad@n21g2000vba.googlegroups.com> Message-ID: <1235334743.17589.15.camel@centar.nbk> On Sun, 2009-02-22 at 12:09 -0800, Ravi wrote: > I am sorry about the typo mistake, well the code snippets are as: > > # Non Working: > > class X(object): > def f(self, **kwds): > print kwds > try: > print kwds['i'] * 2 > except KeyError: > print "unknown keyword argument" > self.g("string", kwds) > > def g(self, s, **kwds): > print s > print kwds > > if __name__ == "__main__": > x = X() > x.f(k = 2, j = 10) > > > # Working One > > class X(object): > def f(self, **kwds): > print kwds > try: > print kwds['i'] * 2 > except KeyError: > print "unknown keyword argument" > self.g("string", **kwds) > > def g(self, s, **kwds): > print s > print kwds > > if __name__ == "__main__": > x = X() > x.f(k = 2, j = 10) Same reasoning, though admittedly the error text is misleading. This example can be simplified as: def foo(x, **kwargs): pass >>> foo(1, {'boys': 5, 'girls': 10}) ==> TypeError: foo() takes exactly 1 argument (2 given) Again misleading, but the argument is the same (no pun intended). However the following would have worked: >>> foo(1, **{'boys': 5, 'girls': 10}) or >>> foo(1, boys=5, girls=10) From desas2 at gmail.com Sun Feb 22 16:03:03 2009 From: desas2 at gmail.com (desas2 at gmail.com) Date: Sun, 22 Feb 2009 13:03:03 -0800 (PST) Subject: Problem with lists. References: Message-ID: <172d73c1-58e3-443b-81e7-15052092308e@f3g2000yqf.googlegroups.com> On Feb 20, 10:12?am, "ssd" wrote: > Hi, > > In the following code, (in Python 2.5) > I was expecting to get in "b" variable the values ?b: [[0, 0], [0, 1],[0, > 2], [0, 3],[0, 4], [1, 0],[1, 1], [1, 2], .....] > But I get only the last value [4,4], b: b: [[4, 4], [4, 4], [4, 4], ... ] > > My code: > > a = ["",""] > b = [] > > for i in range (0,5): > ? ? for j in range (0,5): > ? ? ? ? a[0] = i > ? ? ? ? a[1] = j > ? ? ? ? print "a: " + str(a) > ? ? ? ? b.append(a) > > print "b: " + str(b) > > what is worng in the code? > > Thanks, > Bye, This is what I did and gives your expected results. I am sure, there may be better way of doing it. a = [] b =[] for i in range(0,5): for j in range(0,5): a.append(i) a.append(j) b.append(a) a =[] print b output: [[0, 0], [0, 1], [0, 2], [0, 3], [0, 4], [1, 0], [1, 1], [1, 2], [1, 3], [1, 4], [2, 0], [2, 1], [2, 2], [2, 3], [2, 4], [3, 0], [3, 1], [3, 2], [3, 3], [3, 4], [4, 0], [4, 1], [4, 2], [4, 3], [4, 4]] HTH Dinakar From rozzin at geekspace.com Sun Feb 22 16:06:35 2009 From: rozzin at geekspace.com (Joshua Judson Rosen) Date: Sun, 22 Feb 2009 16:06:35 -0500 Subject: datetime.time and midnight References: <49A083DA.7000107@stoneleaf.us> <49A0946B.8040206@mrabarnett.plus.com> Message-ID: <8763j2qizo.fsf@slice.rozzin.com> "D'Arcy J.M. Cain" writes: > > On Sun, 22 Feb 2009 05:20:31 -0200 > "Gabriel Genellina" wrote: > > En Sat, 21 Feb 2009 21:55:23 -0200, MRAB > > escribi?: > > > I think it's because midnight is to the time of day what zero is to > > > integers, or an empty string is to strings, or an empty container ... > > > > So chr(0) should be False too... > > >>> chr(0) > '\x00' > > That's not an empty string. This is like... > > >>> bool([0]) > True > > Now if Python had a char type one might expect the zero char to be > False but a collection of anything, even if the elements are False, is > not empty and hence is True. And, as Halmos said: A box that contains a hat and nothing else is not the same thing as a hat.... :) -- Don't be afraid to ask (Lf.((Lx.xx) (Lr.f(rr)))). From clp2 at rebertia.com Sun Feb 22 16:11:55 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 22 Feb 2009 13:11:55 -0800 Subject: Problem with lists. In-Reply-To: References: Message-ID: <50697b2c0902221311s3eca7d6y396c6abb3f959879@mail.gmail.com> On Fri, Feb 20, 2009 at 8:12 AM, ssd wrote: > > Hi, > > In the following code, (in Python 2.5) > I was expecting to get in "b" variable the values b: [[0, 0], [0, 1],[0, > 2], [0, 3],[0, 4], [1, 0],[1, 1], [1, 2], .....] > But I get only the last value [4,4], b: b: [[4, 4], [4, 4], [4, 4], ... ] > > My code: > > a = ["",""] > b = [] > > for i in range (0,5): > for j in range (0,5): > a[0] = i > a[1] = j > print "a: " + str(a) > b.append(a) .append() does NOT copy the list `a`, it appends a /reference/ to `a` (so to speak); thus, when you change `a` on the next iteration, you change the same list *all* the entries in `b` point to. Here's a corrected version: b =[] for i in range(0,5): for j in range(0,5): a = [i, j] b.append(a) print b Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From tjreedy at udel.edu Sun Feb 22 16:18:39 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 22 Feb 2009 16:18:39 -0500 Subject: Python 3 and easygui problem In-Reply-To: <49A13F8C.1000506@internode.on.net> References: <49A13F8C.1000506@internode.on.net> Message-ID: Peter Anderson wrote: > Gabriel Genellina said: > > That's very short-lived; cmp is gone in 3.0.1 (should not have existed > in 3.0 in the first place). > Try with: > choices.sort(key=str.lower) > > > Gabriel, > > That's worked fine - thank you. I think I now have a version of > easygui.py that works with Python 3, probably needs a bit more testing. Can you please make it available thru PyPI? From tjreedy at udel.edu Sun Feb 22 16:20:13 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 22 Feb 2009 16:20:13 -0500 Subject: Python 3 and easygui problem In-Reply-To: <50697b2c0902212105g5594e030h9f7cbb721780ef09@mail.gmail.com> References: <49A0D88F.4010806@internode.on.net> <50697b2c0902212105g5594e030h9f7cbb721780ef09@mail.gmail.com> Message-ID: Chris Rebert wrote: > On Sat, Feb 21, 2009 at 8:46 PM, Peter Anderson > wrote: >> I have just installed Python 3. I have been using Tkinter and easygui (with >> Python 2.5.4) for any GUI needs. I have just started to port some of my >> existing scripts to Python 3 and discovered problems with easygui. >> >> I was using the following script for testing: > > >> File "C:\Python30\lib\site-packages\easygui.py", line 824, in __choicebox >> choices.sort( lambda x,y: cmp(x.lower(), y.lower())) # case-insensitive sort >> TypeError: must use keyword argument for key function > > Change the line to > > choices.sort(key=lambda x,y: cmp(x.lower(), y.lower())) The key function must take one arg, not two, as with Gabriel's solution: str.lower. From ethan at stoneleaf.us Sun Feb 22 16:20:59 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 22 Feb 2009 13:20:59 -0800 Subject: datetime.time and midnight In-Reply-To: References: <0e8ef14d-ffa9-4513-abe2-404aeb91a079@i38g2000yqd.googlegroups.com> Message-ID: <49A1C1BB.5070506@stoneleaf.us> Tim Rowe wrote: > 2009/2/22 Mark Dickinson : > >> On Feb 21, 10:44 pm, Ethan Furman wrote: >> >> >>> --> midnight = datetime.time(0,0,0) >>> --> bool(midnight) >>> False >>> >> I'd call this a bug. >> > > No more so than zero being false. Zero exists too (check my bank > balance). Once you've accepted non-Boolean types having Boolean > values, the logic of what value they have is always going to be a bit > hairy. If you're unsure of the logic, just test against a value or a > range. After all, what value do you *expect* a time of day to have > when interpreted as a Boolean? If you don't have an expectation, why > are you interpreting it as a Boolean? > > As Steve Holden correctly guessed, my use case is with databases (more accurately, with dBase and VFP dbf files). As I was creating a dbf date/datetime/time wrapper for the existing datetime data types I noticed that it is *not* possible to have a false date, nor a false date/time, so I was surprised with the false time. So partly because of dates and datetimes, partly because objects are true unless special effort is made to have them be false, and partly because midnight is in fact a time of day, and not a lack of a time of day, I do indeed expect it to be True. -- ~Ethan~ From mccredie at gmail.com Sun Feb 22 16:23:47 2009 From: mccredie at gmail.com (Matimus) Date: Sun, 22 Feb 2009 13:23:47 -0800 (PST) Subject: Problem with lists. References: Message-ID: On Feb 20, 8:12?am, "ssd" wrote: > Hi, > > In the following code, (in Python 2.5) > I was expecting to get in "b" variable the values ?b: [[0, 0], [0, 1],[0, > 2], [0, 3],[0, 4], [1, 0],[1, 1], [1, 2], .....] > But I get only the last value [4,4], b: b: [[4, 4], [4, 4], [4, 4], ... ] > > My code: > > a = ["",""] > b = [] > > for i in range (0,5): > ? ? for j in range (0,5): > ? ? ? ? a[0] = i > ? ? ? ? a[1] = j > ? ? ? ? print "a: " + str(a) > ? ? ? ? b.append(a) > > print "b: " + str(b) > > what is worng in the code? > > Thanks, > Bye, The problem is that `a' is the name of a list object. When you change the contents of that list object you are simply mutating that object. You then append that list object to list `b'. But, you aren't creating a new list, you are simply mutating the same list object over and over and appending it to list `b'. So list `b' contains 5 references to the same object. A couple of things I would do differently. There is no reason to declare `a' outside of the loop. This isn't C you don't have to declare your variables before they are needed. `range(0, 5)' is usually just written `range(5)'. Also, check out `xrange'. Here are a couple of examples of alternatives: construct new lists and append them in the inner loop: b = [] for i in range(5): for j in range(5): b.append([i, j]) print b check out list comprehension: b = [[i, j] for i in range(5) for j in range(5)] print b Matt From tjreedy at udel.edu Sun Feb 22 16:28:48 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 22 Feb 2009 16:28:48 -0500 Subject: Forwarding keyword arguments from one function to another In-Reply-To: References: Message-ID: Ravi wrote: > The following code didn't work: In the future, explain "didn't work". Wrong output? give actual (copy and paste) and expected. Error message? give traceback (copy and paste). From clp2 at rebertia.com Sun Feb 22 16:41:39 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 22 Feb 2009 13:41:39 -0800 Subject: Python 3 and easygui problem In-Reply-To: References: <49A0D88F.4010806@internode.on.net> <50697b2c0902212105g5594e030h9f7cbb721780ef09@mail.gmail.com> Message-ID: <50697b2c0902221341n18ff4926y739017c912e31412@mail.gmail.com> On Sun, Feb 22, 2009 at 1:20 PM, Terry Reedy wrote: > Chris Rebert wrote: >> >> On Sat, Feb 21, 2009 at 8:46 PM, Peter Anderson >> wrote: >>> >>> I have just installed Python 3. I have been using Tkinter and easygui >>> (with >>> Python 2.5.4) for any GUI needs. I have just started to port some of my >>> existing scripts to Python 3 and discovered problems with easygui. >>> >>> I was using the following script for testing: >> >> >> >>> File "C:\Python30\lib\site-packages\easygui.py", line 824, in __choicebox >>> choices.sort( lambda x,y: cmp(x.lower(), y.lower())) # case-insensitive >>> sort >>> TypeError: must use keyword argument for key function >> >> Change the line to >> >> choices.sort(key=lambda x,y: cmp(x.lower(), y.lower())) > > The key function must take one arg, not two, as with Gabriel's solution: > str.lower. Yeah, I was too quick on the trigger and mixed up key and cmp. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From dineshbvadhia at hotmail.com Sun Feb 22 16:47:22 2009 From: dineshbvadhia at hotmail.com (dineshv) Date: Sun, 22 Feb 2009 13:47:22 -0800 (PST) Subject: Python on 64-bit Windows Vista Message-ID: <7bb9f5c5-400c-4ae0-86f4-ecc589d083ed@a12g2000yqm.googlegroups.com> Does anyone have experience of working with Python and very large text files (> 10Gb) on 64-bit Windows Vista? The problem is that my Python program - to perform simple data processing on the 10Gb file - never completes and ends with an error. When I reduce the size of the file (< 5Gb) the program works perfectly. So, it is not my code! This is not the first time that this has happened and I'm wondering what is it about Python and/or 64-bit Vista that causes these inexplicable errors when processing very large text files? Dinesh From sjmachin at lexicon.net Sun Feb 22 16:58:21 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 22 Feb 2009 13:58:21 -0800 (PST) Subject: Python 3 and easygui problem References: <49A13F8C.1000506@internode.on.net> Message-ID: <7e8a2b8e-4892-4d0d-bf6f-64c8b2a9910d@p13g2000yqc.googlegroups.com> On Feb 23, 8:18?am, Terry Reedy wrote: > Peter Anderson wrote: > > Gabriel Genellina said: > > > That's very short-lived; cmp is gone in 3.0.1 (should not have existed > > in 3.0 in the first place). > > Try with: > > choices.sort(key=str.lower) > > > Gabriel, > > > That's worked fine - thank you. I think I now have a version of > > easygui.py that works with Python 3, probably needs a bit more testing. > > Can you please make it available thru PyPI? Are you 100% certain that easygui is not being maintained any more? If so, it's rather sudden; the latest released version is "version 0.85 (2009-01-16)" ... see http://easygui.sourceforge.net/download/easygui_v0.85.html Did you mistake the OP for the author/maintainer?? Has the OP tried to contact the author/maintainer of easygui [the usually-recommended approach to problems with not-widely-used third- party modules]? Don't you think the author/maintainer might like to be consulted before you incite an OP to claim-jump his package name on PyPI? From peke at iki.fi Sun Feb 22 17:10:58 2009 From: peke at iki.fi (=?ISO-8859-1?Q?Pekka_Kl=E4rck?=) Date: Mon, 23 Feb 2009 00:10:58 +0200 Subject: Find the location of a loaded module In-Reply-To: References: <5879412d-ffba-4fd9-82b7-7e798dc425e3@f3g2000yqf.googlegroups.com> Message-ID: <7dedbb6d0902221410l68c9e174h5cdd9beebc1fb42@mail.gmail.com> 2009/2/21 Gabriel Genellina : > > Use packages. Make act1 and act2 packages by creating __init__.py files. That's how I'd do it too. The code would be also more easy to understand and maintain: import act1 import act2 act1.story() act2.story() Alternative solution would be using reload function after changing sys.path. Cheers, .peke From peter.anderson at internode.on.net Sun Feb 22 17:17:03 2009 From: peter.anderson at internode.on.net (Peter Anderson) Date: Mon, 23 Feb 2009 09:17:03 +1100 Subject: Python 3 and easygui problem In-Reply-To: <7e8a2b8e-4892-4d0d-bf6f-64c8b2a9910d@p13g2000yqc.googlegroups.com> References: <7e8a2b8e-4892-4d0d-bf6f-64c8b2a9910d@p13g2000yqc.googlegroups.com> Message-ID: <49A1CEDF.7020609@internode.on.net> John Machin said: Has the OP tried to contact the author/maintainer of easygui [the usually-recommended approach to problems with not-widely-used third- party modules]? Don't you think the author/maintainer might like to be consulted before you incite an OP to claim-jump his package name on PyPI? The OP (I presume you mean me) has tried to contact Steve Ferg (the original developer) but I have not had a reply yet. See my e-mail above; it is NOT my intention to place my modified script on PyPI as I AM NOT the original developer. My claim to fame is changing a few "import" and "print" statements and getting some useful advice from other members of this list. I am happy to make my modified script available unofficially and if Steve does contact me I would prefer to pass it on to him for his consideration. This little project started out to solve a personal need not to plagiarise or usurp the rights and skills of another developer. I was happy to make my simple effort available, unofficially, in return for help from other list members. I hope that resolves the issue. Regards, Peter -- *Peter Anderson* There is nothing more difficult to take in hand, more perilous to conduct, or more uncertain in its success, than to take the lead in the introduction of a new order of things?Niccolo Machiavelli, /The Prince/, ch. 6 From peter.anderson at internode.on.net Sun Feb 22 17:58:06 2009 From: peter.anderson at internode.on.net (Peter Anderson) Date: Mon, 23 Feb 2009 09:58:06 +1100 Subject: Python 3 and easygui problem Message-ID: <49A1D87E.4050805@internode.on.net> Terry, I have not used PyPI before and feel a little uneasy about putting this modified script into such a public place. I have previously contacted Steve Ferg (the original developer of EasyGui) but have not had a reply. Clearly the bulk of the work is his still where as the modifications are mine (and several helpers from the Python List). Until I work out what I ought to do I have attached a copy of my script (and the test script I have been using) as is. I would really appreciate any comments. If Steve does not reply and further testing proves my modified script is sound then I will certainly look at a 'public' release. Regards, Peter -- *Peter Anderson* There is nothing more difficult to take in hand, more perilous to conduct, or more uncertain in its success, than to take the lead in the introduction of a new order of things?Niccolo Machiavelli, /The Prince/, ch. 6 From sjmachin at lexicon.net Sun Feb 22 18:24:10 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 22 Feb 2009 15:24:10 -0800 (PST) Subject: Python 3 and easygui problem References: <7e8a2b8e-4892-4d0d-bf6f-64c8b2a9910d@p13g2000yqc.googlegroups.com> Message-ID: <8e5a80a0-670f-43b2-86c5-be3239c91c93@v38g2000yqb.googlegroups.com> On Feb 23, 9:17?am, Peter Anderson wrote: > John Machin said: > > Has the OP tried to contact the author/maintainer of easygui [the > usually-recommended approach to problems with not-widely-used third- > party modules]? > > Don't you think the author/maintainer might like to be consulted > before you incite an OP to claim-jump his package name on PyPI? > > The OP (I presume you mean me) has tried to contact Steve Ferg (the > original developer) but I have not had a reply yet. See my e-mail above; > it is NOT my intention to place my modified script on PyPI as I AM NOT > the original developer. My claim to fame is changing a few "import" and > "print" statements and getting some useful advice from other members of > this list. > > I am happy to make my modified script available unofficially and if > Steve does contact me I would prefer to pass it on to him for his > consideration. > > This little project started out to solve a personal need not to > plagiarise or usurp the rights and skills of another developer. I was > happy to make my simple effort available, unofficially, in return for > help from other list members. > > I hope that resolves the issue. Thank you, but your intentions stated above are just fine and what I presumed. The issue is not with you but with Terry suggesting that you should "make it available thru PyPI" with no qualification or caveat at all -- the knowledge that you had attempted to contact Steve Ferg and have not yet had a response was not available on c.l.py and in any case is not a justification for incitement to hijack. From james.m.pearson at gmail.com Sun Feb 22 19:15:40 2009 From: james.m.pearson at gmail.com (James Pearson) Date: Sun, 22 Feb 2009 16:15:40 -0800 Subject: pickle.load() on an dictionary of dictionaries doesn't load full data structure on first call Message-ID: <7dbb3da80902221615sd6ecb28g327a5a56e2b9c4fc@mail.gmail.com> I've been using irclib to write a simple irc bot, and I was running into some difficulties with pickle. Upon some experimentation with pdb, I found that pickle.load() doesn't load *all* of the data the _first_ time it's called. For instance, I have this dictionary pickled: {'xiong_chiamiov': {'name': 'James Pearson', 'distro': 'Arch'}} The first time I pickle.load() it, I get this: {'xiong_chiamiov': {'name': 'James Pearson'}} The 2nd time, I get the full thing. Is this a bug in pickle, something wrong with the way I'm approaching this, or what? Full code is available at: http://github.com/xiongchiamiov/mpu/ -- James Pearson -- The best way to predict the future is to invent it. - Alan Kay -- GCS/MU d- s+:- a--- C++(++++)>$ ULC+(++)>$ P(+) L+++>++++$ !E W++(+++)$>$ N+(++) o? K-- w--- O? M--(+) V? PS+(--) PE++() Y+(++) PGP- !t !5 !X R- tv-(--) b+>+++ DI+(++) D G e>++ h- r y- [http://tinyurl.com/23uv8t] -------------- next part -------------- An HTML attachment was scrubbed... URL: From rozzin at geekspace.com Sun Feb 22 19:46:35 2009 From: rozzin at geekspace.com (Joshua Judson Rosen) Date: Sun, 22 Feb 2009 19:46:35 -0500 Subject: choosing a default text-encoding in Python programs (was: To unicode or not to unicode) References: Message-ID: <87hc2mnfo4.fsf_-_@slice.rozzin.com> Denis Kasak writes: > > > > Python "assumes" ASCII and if the decodes/encoded text doesn't > > > fit that encoding it refuses to guess. > > > > Which is reasonable given that Python is programming language where it's > > better to have more conservative assumption about encodings so errors > > can be more quickly diagnosed. A newsreader however is a different > > beast, where it's better to make a less conservative assumption that's > > more likely to display messages correctly to the user. Assuming ISO > > 8859-1 in the absense of any specified encoding allows the message to be > > correctly displayed if the character set is either ISO 8859-1 or ASCII. > > Doing things the "pythonic" way and assuming ASCII only allows such > > messages to be displayed if ASCII is used. > > Reading this paragraph, I've began thinking that we've misunderstood > each other. I agree that assuming ISO 8859-1 in the absence of > specification is a better guess than most (since it's more likely to > display the message correctly). So, yeah--back on the subject of programming in Python and supporting charactersets beyond ASCII: If you have to make an assumption, I'd really think that it'd be better to use whatever the host OS's default is, if the host OS has such a thing--using an assumption of ISO 8859-1 works only in select regions on unix systems, and may fail even in those select regions on Windows, Mac OS, and other systems; without the OS considerations, just the regional constraints are likely to make an ISO-8859-1 assumption result in /incorrect/ results anywhere eastward of central Europe. Is a user in Russia (or China, or Japan) *really* most likely to be using ISO 8859-1? As a point of reference, here's what's in the man-pages that I have installed (note the /complete/ and conspicuous lack of references to even some notable eastern languages or character-sets, such as Chinese and Japanese, in the /entire/ ISO-8859 spectrum): "ISO 8859 Alphabets The full set of ISO 8859 alphabets includes: ISO 8859-1 West European languages (Latin-1) ISO 8859-2 Central and East European languages (Latin-2) ISO 8859-3 Southeast European and miscellaneous languages (Latin-3) ISO 8859-4 Scandinavian/Baltic languages (Latin-4) ISO 8859-5 Latin/Cyrillic ISO 8859-6 Latin/Arabic ISO 8859-7 Latin/Greek ISO 8859-8 Latin/Hebrew ISO 8859-9 Latin-1 modification for Turkish (Latin-5) ISO 8859-10 Lappish/Nordic/Eskimo languages (Latin-6) ISO 8859-11 Latin/Thai ISO 8859-13 Baltic Rim languages (Latin-7) ISO 8859-14 Celtic (Latin-8) ISO 8859-15 West European languages (Latin-9) ISO 8859-16 Romanian (Latin-10)" "ISO 8859-1 supports the following languages: Afrikaans, Basque, Catalan, Danish, Dutch, English, Faeroese, Finnish, French, Galician, German, Icelandic, Irish, Italian, Norwegian, Portuguese, Scottish, Spanish, and Swedish." "ISO 8859-2 supports the following languages: Albanian, Bosnian, Croatian, Czech, English, Finnish, German, Hungarian, Irish, Polish, Slovak, Slovenian and Sorbian." "ISO 8859-7 encodes the characters used in modern monotonic Greek." "ISO 8859-9, also known as the "Latin Alphabet No. 5", encodes the characters used in Turkish." "ISO 8859-15 supports the following languages: Albanian, Basque, Breton, Catalan, Danish, Dutch, English, Estonian, Faroese, Finnish, French, Frisian, Galician, German, Greenlandic, Icelandic, Irish Gaelic, Italian, Latin, Luxemburgish, Norwegian, Portuguese, Rhaeto-Romanic, Scottish Gaelic, Spanish, and Swedish." "ISO 8859-16 supports the following languages: Albanian, Bosnian, Croatian, English, Finnish, German, Hungarian, Irish, Polish, Romanian, Slovenian and Serbian." -- Don't be afraid to ask (Lf.((Lx.xx) (Lr.f(rr)))). From rozzin at geekspace.com Sun Feb 22 19:52:25 2009 From: rozzin at geekspace.com (Joshua Judson Rosen) Date: Sun, 22 Feb 2009 19:52:25 -0500 Subject: datetime.time and midnight References: <0e8ef14d-ffa9-4513-abe2-404aeb91a079@i38g2000yqd.googlegroups.com> Message-ID: <873ae6nfee.fsf@slice.rozzin.com> Ethan Furman writes: > > [...]partly because midnight is in fact a time of day, and not a lack of > a time of day, I do indeed expect it to be True. While it's not a lack of `time of day', it /is/ a lack of /elapsed/ time in the day ;) Just as if you were using a plain integer or float to count the time :) -- Don't be afraid to ask (Lf.((Lx.xx) (Lr.f(rr)))). From sbassi at clubdelarazon.org Sun Feb 22 19:53:25 2009 From: sbassi at clubdelarazon.org (Sebastian Bassi) Date: Sun, 22 Feb 2009 21:53:25 -0300 Subject: Problem trying to install ReportLab with easy_install In-Reply-To: <364299f40902220507i6c5520dcyb6547c6bf6a848e3@mail.gmail.com> References: <9e2f512b0902212206q1054875ci3bbe5026f74f62a3@mail.gmail.com> <364299f40902220507i6c5520dcyb6547c6bf6a848e3@mail.gmail.com> Message-ID: <9e2f512b0902221653m7f82018clb839f0f7f1f7d587@mail.gmail.com> On Sun, Feb 22, 2009 at 10:07 AM, Garrett Cooper wrote: > It's not building lib_renderPM_libart properly, or it's a typo > that supposed to be librenderPM_libart, or bad LDFLAGS... > More details need to be provided like an ls of your site-packages > directory and a partial ls of your local library directory (ls > /usr/?local/?lib/lib*render*libart*, etc). > sbassi at hp:~$ ls /usr/lib/lib*ren* /usr/lib/libktorrent.la /usr/lib/libXrender.la /usr/lib/libktorrent.so /usr/lib/libXrender.so /usr/lib/libktorrent.so.0 /usr/lib/libXrender.so.1 /usr/lib/libktorrent.so.0.0.0 /usr/lib/libXrender.so.1.3.0 /usr/lib/libXrender.a sbassi at hp:~$ ls /usr/lib/libart* /usr/lib/libart_lgpl_2.so.2 /usr/lib/libartsflow_idl.so.1 /usr/lib/libart_lgpl_2.so.2.3.16 /usr/lib/libartsflow_idl.so.1.0.0 /usr/lib/libart_lgpl.so.2 /usr/lib/libartsflow.so.1 /usr/lib/libart_lgpl.so.2.2.0 /usr/lib/libartsflow.so.1.0.0 /usr/lib/libartscbackend.la /usr/lib/libartsgslplayobject.la /usr/lib/libartscbackend.so.0 /usr/lib/libartsgslplayobject.so.0 /usr/lib/libartscbackend.so.0.0.0 /usr/lib/libartsgslplayobject.so.0.0.0 /usr/lib/libartsc.so.0 /usr/lib/libartskde.so.1 /usr/lib/libartsc.so.0.0.0 /usr/lib/libartskde.so.1.2.0 /usr/lib/libartsdsp.so.0 /usr/lib/libartswavplayobject.la /usr/lib/libartsdsp.so.0.0.0 /usr/lib/libartswavplayobject.so.0 /usr/lib/libartsdsp_st.so.0 /usr/lib/libartswavplayobject.so.0.0.0 /usr/lib/libartsdsp_st.so.0.0.0 (t6)sbassi at hp:~/test/virtualenv-1.3.2/t6$ ls lib/python2.5/site-packages/ easy-install.pth setuptools.pth setuptools-0.6c9-py2.5.egg xlwt-0.7.0-py2.5.egg This is a virtualenv created with --no-site-packages (to have a clean start). Other easy_install works, but this one, doesn't :( From peter.anderson at internode.on.net Sun Feb 22 19:55:35 2009 From: peter.anderson at internode.on.net (Peter Anderson) Date: Mon, 23 Feb 2009 11:55:35 +1100 Subject: Python 3 and easygui problem In-Reply-To: <8e5a80a0-670f-43b2-86c5-be3239c91c93@v38g2000yqb.googlegroups.com> References: <8e5a80a0-670f-43b2-86c5-be3239c91c93@v38g2000yqb.googlegroups.com> Message-ID: <49A1F407.7080400@internode.on.net> John Machin said:* *"... the knowledge that you had attempted to contact Steve Ferg and have not yet had a response was not available on c.l.py and in any case is not a justification for incitement to hijack." John, I resent the implication that I am trying to hijack Steve's project. This was never my intention. I am uneasy about posting this rebuttal on the list as this is not what I think lists like this are for; but given your response I will post this one reply in my defence. I think that if you want to follow up this matter do it off line. For your information I have since been in contact with Steve and sent him a copy of my code. Its been my experience that there are some users of these lists who ought to hesitate before they jump in because they often are not in full possession of all the facts. Once again (and for the last time) this was a personal project, I offered to share my additions to Steve's work in an informal way to anyone who helped me with fixing error responses I was getting - its a very long bow to draw to say this constitutes hijacking. It was NEVER my intention to hijack anyone's work and I resent the accusation. To end, I have included below a statement that I added to the script that I sent to Terry: ------------------------------------------------- This is an experimental version of EasyGui that has converted the latest 'official' version so that it will run under Python 3.0.1 The script is still being tested and any comments would be appreciated. NOTE: This version of the script is not from Steve Ferg although his contribution of the original script is acknowledged. This script is released under the same Creative Commons Attribution 2.0 License as the original script. Modified by: Peter Anderson Date: Monday, 23 February 2009 Contact: peterjohnanderson at gmail.com ------------------------------------------------- As far as I am concerned that is the end of the matter on this list. Feel free to contact me off line if you want to follow up this post. Regards, Peter -- *Peter Anderson* There is nothing more difficult to take in hand, more perilous to conduct, or more uncertain in its success, than to take the lead in the introduction of a new order of things?Niccolo Machiavelli, /The Prince/, ch. 6 From bignose+hates-spam at benfinney.id.au Sun Feb 22 20:05:13 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Mon, 23 Feb 2009 12:05:13 +1100 Subject: choosing a default text-encoding in Python programs References: <87hc2mnfo4.fsf_-_@slice.rozzin.com> Message-ID: <87y6vyhsja.fsf@benfinney.id.au> Joshua Judson Rosen writes: > If you have to make an assumption, I'd really think that it'd be > better to use whatever the host OS's default is, if the host OS has > such a thing--using an assumption of ISO 8859-1 works only in select > regions on unix systems, and may fail even in those select regions > on Windows, Mac OS, and other systems; without the OS > considerations, just the regional constraints are likely to make an > ISO-8859-1 assumption result in /incorrect/ results anywhere > eastward of central Europe. Is a user in Russia (or China, or Japan) > *really* most likely to be using ISO 8859-1? The fallacy in the above is to assume that a given programmer will only be opening files created in their current locale. I say that is a fallacy, because programmers in fact open program files created all over the world in different locales; and those files should, where possible, be interpreted by Python the same everwhere. Assuming a *single*, defined, encoding in the absence of an explicit declaration at least makes all Python installations (of a given version) read any program file the same in any locale. -- \ ?If [a technology company] has confidence in their future | `\ ability to innovate, the importance they place on protecting | _o__) their past innovations really should decline.? ?Gary Barnett | Ben Finney From marduk at letterboxes.org Sun Feb 22 20:10:56 2009 From: marduk at letterboxes.org (Albert Hopkins) Date: Sun, 22 Feb 2009 20:10:56 -0500 Subject: pickle.load() on an dictionary of dictionaries doesn't load full data structure on first call In-Reply-To: <7dbb3da80902221615sd6ecb28g327a5a56e2b9c4fc@mail.gmail.com> References: <7dbb3da80902221615sd6ecb28g327a5a56e2b9c4fc@mail.gmail.com> Message-ID: <1235351456.28498.19.camel@centar.nbk> On Sun, 2009-02-22 at 16:15 -0800, James Pearson wrote: > I've been using irclib to write a simple irc bot, and I was running > into some difficulties with pickle. Upon some experimentation with > pdb, I found that pickle.load() doesn't load *all* of the data the > _first_ time it's called. > > For instance, I have this dictionary pickled: > {'xiong_chiamiov': {'name': 'James Pearson', 'distro': 'Arch'}} > The first time I pickle.load() it, I get this: > {'xiong_chiamiov': {'name': 'James Pearson'}} > The 2nd time, I get the full thing. > > Is this a bug in pickle, something wrong with the way I'm approaching > this, or what? Full code is available at: > http://github.com/xiongchiamiov/mpu/ > In general it's a bad idea to point the list to a full. It's usually wiser to deduce the issue to a relatively small, easily runnable, snippet of code and then paste that snippet in your post. Readers usually don't want to have to read through your entire program to understand what you are asking them. Having said that, pickle is for serializing data. You shouldn't be opening a file in read/write/append mode and dumping and loading to the same file object. It's not a multi-access database like a DBMS is. The basic idea is: 1. open (empty) file write-only. 2. dump object(s) to file. 3. close file or 1. open file read-only 2. load object(s) from file 3. close file Anything other than the two may lead to undesired/undefined behavior. But the likely answer to your question is that your pickle file has (at least) 2 objects stored in it. And so on each load you get subsequent objects. That's probably the "undesired" affect of opening the file in append mode. From sjmachin at lexicon.net Sun Feb 22 20:16:47 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 22 Feb 2009 17:16:47 -0800 (PST) Subject: choosing a default text-encoding in Python programs (was: To unicode or not to unicode) References: <87hc2mnfo4.fsf_-_@slice.rozzin.com> Message-ID: On Feb 23, 11:46?am, Joshua Judson Rosen wrote: > Denis Kasak writes: > > > > > Python "assumes" ASCII and if the decodes/encoded text doesn't > > > > fit that encoding it refuses to guess. > > > > Which is reasonable given that Python is programming language where it's > > > better to have more conservative assumption about encodings so errors > > > can be more quickly diagnosed. ?A newsreader however is a different > > > beast, where it's better to make a less conservative assumption that's > > > more likely to display messages correctly to the user. ?Assuming ISO > > > 8859-1 in the absense of any specified encoding allows the message to be > > > correctly displayed if the character set is either ISO 8859-1 or ASCII. > > > Doing things the "pythonic" way and assuming ASCII only allows such > > > messages to be displayed if ASCII is used. > > > Reading this paragraph, I've began thinking that we've misunderstood > > each other. I agree that assuming ISO 8859-1 in the absence of > > specification is a better guess than most (since it's more likely to > > display the message correctly). > > So, yeah--back on the subject of programming in Python and supporting > charactersets beyond ASCII: > > If you have to make an assumption, I'd really think that it'd be > better to use whatever the host OS's default is, if the host OS has > such a thing--using an assumption of ISO 8859-1 works only in select > regions on unix systems, and may fail even in those select regions on > Windows, Mac OS, and other systems; without the OS considerations, > just the regional constraints are likely to make an ISO-8859-1 > assumption result in /incorrect/ results anywhere eastward of central > Europe. Is a user in Russia (or China, or Japan) *really* most likely > to be using ISO 8859-1? > > As a point of reference, here's what's in the man-pages that I have > installed (note the /complete/ and conspicuous lack of references to > even some notable eastern languages or character-sets, such as Chinese > and Japanese, in the /entire/ ISO-8859 spectrum): 1. As a point of reference for what? 2. The ISO 8859 character sets were deliberately restricted to scripts that would fit in 8 bits. So Chinese, Japanese, Korean and Vietnamese aren't included. Note that Chinese and Japanese already each had *multiple* legacy (i.e. non-Unicode) character sets ... they (and the rest the world) don't want/need yet another character set for each language and never did want/need one. From sjmachin at lexicon.net Sun Feb 22 20:26:05 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 22 Feb 2009 17:26:05 -0800 (PST) Subject: Python 3 and easygui problem References: <8e5a80a0-670f-43b2-86c5-be3239c91c93@v38g2000yqb.googlegroups.com> Message-ID: On Feb 23, 11:55?am, Peter Anderson wrote: > John Machin said:* > > *"... the knowledge that you had attempted to contact Steve Ferg and > have not yet had a response was not available on c.l.py and in any case > is not a justification for incitement to hijack." > > John, I resent the implication that I am trying to hijack Steve's > project. This was never my intention. I am uneasy about posting this > rebuttal on the list as this is not what I think lists like this are > for; but given your response I will post this one reply in my defence. I > think that if you want to follow up this matter do it off line. I'll keep it online for the same reason that you did. Please re-read what I wrote: """ Thank you, but your intentions stated above are just fine and what I presumed. The issue is not with you but with Terry ... """ How you managed to construe that as an implication that you were trying to hijack Steve's project, I can't imagine. You wrote: "It was NEVER my intention to hijack anyone's work and I resent the accusation." There was no such accusation. From steven at REMOVE.THIS.cybersource.com.au Sun Feb 22 21:43:59 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 23 Feb 2009 02:43:59 GMT Subject: Reference or Value? References: Message-ID: On Sun, 22 Feb 2009 16:13:02 +0100, Torsten Mohr wrote: > Hi, > > how is the rule in Python, if i pass objects to a function, when is this > done by reference and when is it by value? Never, and never. > Integers are obviously passed by value, lists and dicts by reference. Your error is assuming that pass-by-value and pass-by-reference are the only two possibilities, consequently you are misinterpreting what you see. Python uses the same evaluation strategy regardless of the type of object being passed. Sometimes that strategy looks something like pass-by-value, and sometimes it looks something like pass-by-reference, but in fact it always behaves consistently no matter what object you use. > Is there a general rule? Some common formulation? http://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_sharing http://effbot.org/zone/call-by-object.htm -- Steven From ccormie at aussiemail.com.au Sun Feb 22 22:56:09 2009 From: ccormie at aussiemail.com.au (Chris Cormie) Date: Mon, 23 Feb 2009 14:56:09 +1100 Subject: How does one get from "ImportError: DLL load failed:..." to a culprit .dll and symbol? Message-ID: <01b213c7$0$20626$c3e8da3@news.astraweb.com> Hi, I've been Googling around on a moderately common Windows Python problem: a mismatch between the symbols a python extension thinks are available and the contents of the associated DLL. Python users running into this problem are greeted with: import "ImportError: DLL load failed: The specified procedure could not be found." That's it: no mention of which dll nor which symbol is causing the problem. Both these pieces of information are helpful/important in resolving this class of problem: how does one get Python to dump this debugging data? (>python -v -d doesn't help, BTW) Regards, Chris From xiong.chiamiov at gmail.com Sun Feb 22 22:58:27 2009 From: xiong.chiamiov at gmail.com (James Pearson) Date: Sun, 22 Feb 2009 19:58:27 -0800 Subject: pickle.load() on an dictionary of dictionaries doesn't load full data structure on first call In-Reply-To: <1235351456.28498.19.camel@centar.nbk> References: <7dbb3da80902221615sd6ecb28g327a5a56e2b9c4fc@mail.gmail.com> <1235351456.28498.19.camel@centar.nbk> Message-ID: <7dbb3da80902221958g4dc579f3k21e31e9468f2a619@mail.gmail.com> Ah, thank you, you explained that quite well and opened my eyes to some things I very much need to improve in my code. I'll keep those list-etiquette things in mind next time. On Sun, Feb 22, 2009 at 5:10 PM, Albert Hopkins wrote: > On Sun, 2009-02-22 at 16:15 -0800, James Pearson wrote: > > I've been using irclib to write a simple irc bot, and I was running > > into some difficulties with pickle. Upon some experimentation with > > pdb, I found that pickle.load() doesn't load *all* of the data the > > _first_ time it's called. > > > > For instance, I have this dictionary pickled: > > {'xiong_chiamiov': {'name': 'James Pearson', 'distro': 'Arch'}} > > The first time I pickle.load() it, I get this: > > {'xiong_chiamiov': {'name': 'James Pearson'}} > > The 2nd time, I get the full thing. > > > > Is this a bug in pickle, something wrong with the way I'm approaching > > this, or what? Full code is available at: > > http://github.com/xiongchiamiov/mpu/ > > > > In general it's a bad idea to point the list to a full. It's usually > wiser to deduce the issue to a relatively small, easily runnable, > snippet of code and then paste that snippet in your post. Readers > usually don't want to have to read through your entire program to > understand what you are asking them. > > Having said that, pickle is for serializing data. You shouldn't be > opening a file in read/write/append mode and dumping and loading to the > same file object. It's not a multi-access database like a DBMS is. The > basic idea is: > > 1. open (empty) file write-only. > 2. dump object(s) to file. > 3. close file > > or > > 1. open file read-only > 2. load object(s) from file > 3. close file > > Anything other than the two may lead to undesired/undefined behavior. > > But the likely answer to your question is that your pickle file has (at > least) 2 objects stored in it. And so on each load you get subsequent > objects. That's probably the "undesired" affect of opening the file in > append mode. > > -- > http://mail.python.org/mailman/listinfo/python-list > -- James Pearson -------------- next part -------------- An HTML attachment was scrubbed... URL: From steven at REMOVE.THIS.cybersource.com.au Sun Feb 22 23:09:17 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 23 Feb 2009 04:09:17 GMT Subject: Reference or Value? References: Message-ID: On Sun, 22 Feb 2009 13:37:27 -0300, andrew cooke wrote: > as far as i understand things, the best model is: > > 1 - everything is an object > 2 - everything is passed by reference Except that is wrong. If it were true, you could do this: def swap(x, y): y, x = x, y a = 1 b = 2 swap(a, b) assert a == 2 and b == 1 but you can't, it does not work. Ergo, parameter passing in Python does not have the same semantics as languages that use pass-by-reference, such as Pascal and Basic. That means that even if you can justify the claim "Python is pass-by-reference" by some technical argument (and I don't believe you can), it is misleading to make that claim without further qualifications. > 3 - some objects are immutable All objects are passed the same way, regardless of whether they are mutable or immutable. > 4 - some (immutable?) objects are cached/reused by the system That's irrelevant. Caching affects the creation of new objects, but has no effect on argument passing. -- Steven From venutaurus539 at gmail.com Sun Feb 22 23:13:23 2009 From: venutaurus539 at gmail.com (venutaurus539 at gmail.com) Date: Sun, 22 Feb 2009 20:13:23 -0800 (PST) Subject: How to open a remote file using python. Message-ID: Hello all, I am writing an application where I need to open a shared file on a remote machine using python script. I tried using the following function: f = urllib.open("\\remote_machine\\folder1\\file1.doc") I also tried using class urllib.FancyURLopener(...) but didn't work. Can some one help me in this regard. Thank you in advance, Venu From clp2 at rebertia.com Sun Feb 22 23:21:43 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 22 Feb 2009 20:21:43 -0800 Subject: How to open a remote file using python. In-Reply-To: References: Message-ID: <50697b2c0902222021h4d545688y57cedf768eae1aab@mail.gmail.com> On Sun, Feb 22, 2009 at 8:13 PM, venutaurus539 at gmail.com wrote: > Hello all, > I am writing an application where I need to open a shared > file on a remote machine using python script. I tried using the > following function: > > f = urllib.open("\\remote_machine\\folder1\\file1.doc") > > I also tried using > > class urllib.FancyURLopener(...) > > but didn't work. Can some one help me in this regard. That function and class are be for retrieving materials over the web (typically HTTP/FTP); however, your path suggests you're trying to access a file over a local Windows network, so those aren't appropriate. The regular open() function would have a better chance of working for this. Have you tried it? Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From google at mrabarnett.plus.com Sun Feb 22 23:25:13 2009 From: google at mrabarnett.plus.com (MRAB) Date: Mon, 23 Feb 2009 04:25:13 +0000 Subject: How to open a remote file using python. In-Reply-To: References: Message-ID: <49A22529.8000300@mrabarnett.plus.com> venutaurus539 at gmail.com wrote: > Hello all, > I am writing an application where I need to open a shared > file on a remote machine using python script. I tried using the > following function: > > f = urllib.open("\\remote_machine\\folder1\\file1.doc") > > I also tried using > > class urllib.FancyURLopener(...) > > but didn't work. Can some one help me in this regard. > What do you mean by "remote machine"? Do you mean you want to open a file that's in a shared folder on a machine that's on the same local network? If it's meant to be a Windows filepath then it should be: f = open(r"\\remote_machine\folder1\file1.doc") (If the file is a Microsoft Word document file, then you won't probably be able to make much sense of its contents using open().) From michele.simionato at gmail.com Sun Feb 22 23:38:40 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Mon, 23 Feb 2009 05:38:40 +0100 Subject: How to inherit from two classes without metaclass clashing ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF62783D686@enbmail01.lsi.com> References: <7F0503CD69378F49BE0DC30661C6CCF60E68800F@enbmail01.lsi.com> <7F0503CD69378F49BE0DC30661C6CCF62783D686@enbmail01.lsi.com> Message-ID: <4edc17eb0902222038gbdf39feyb806537c990fca08@mail.gmail.com> On Sun, Feb 22, 2009 at 2:29 PM, Barak, Ron wrote: > Hi Michele, > > I tried understanding how to avoid the metaclasses clashing, and I did read > the link you referred to below, > as well as the relevant O'Reilly cookbook chapter (Recipe 20.17. Solving > Metaclass Conflicts), but seems I do not understand the correct syntax to > use, as I either get > > $ python -u ./failover_pickle_demo09.py > Traceback (most recent call last): > File "./failover_pickle_demo09.py", line 323, in > class ListControlMeta(wx.Frame, CopyAndPaste): > TypeError: Error when calling the metaclass bases > metaclass conflict: the metaclass of a derived class must be a > (non-strict) subclass of the metaclasses of all its bases > > or > > $ python -u ./failover_pickle_demo09.py > Traceback (most recent call last): > File "./failover_pickle_demo09.py", line 322, in > class ListControlMeta(type(wx.Frame), type(CopyAndPaste)): > TypeError: Error when calling the metaclass bases > multiple bases have instance lay-out conflict This is not a matter of syntax. wx.Frame is a C++-coded class with a non standard layout and there is nothing than the recipe can do to solve the metaclass conflict. I guess you are using an old version of wx since I cannot reproduce the problem. Let us see what the wx guys say. From venutaurus539 at gmail.com Mon Feb 23 00:02:13 2009 From: venutaurus539 at gmail.com (venutaurus539 at gmail.com) Date: Sun, 22 Feb 2009 21:02:13 -0800 (PST) Subject: How to open a remote file using python. References: Message-ID: <00296096-1b2f-41fa-927a-53b2c33c58ac@n20g2000vba.googlegroups.com> On Feb 23, 9:25?am, MRAB wrote: > venutaurus... at gmail.com wrote: > > Hello all, > > ? ? ? ? ? ?I am writing an application where I need to open a shared > > file on a remote machine using python script. I tried using the > > following function: > > > f = urllib.open("\\remote_machine\\folder1\\file1.doc") > > > ? ? ? ? ?I also tried using > > > class urllib.FancyURLopener(...) > > > ? ? ? ? ?but didn't work. Can some one help me in this regard. > > What do you mean by "remote machine"? Do you mean you want to open a > file that's in a shared folder on a machine that's on the same local > network? > > If it's meant to be a Windows filepath then it should be: > > ? ? ?f = open(r"\\remote_machine\folder1\file1.doc") > > (If the file is a Microsoft Word document file, then you won't probably > be able to make much sense of its contents using open().) Thanks to all for your brisk replies: Yes, my aim is to open a file from another machine in the same LAN. It also worked using >>f = urllib.urlopen("\\\remote_machine\\folder\\file.doc") But now I also have to copy the same file to the local machine in Python. Do I need to follow any protocols for this? Thank you, Venu. From odeits at gmail.com Mon Feb 23 00:06:10 2009 From: odeits at gmail.com (odeits) Date: Sun, 22 Feb 2009 21:06:10 -0800 (PST) Subject: How to open a remote file using python. References: <00296096-1b2f-41fa-927a-53b2c33c58ac@n20g2000vba.googlegroups.com> Message-ID: <69d01028-2a8e-4717-b7e4-ba17fa2ca174@r41g2000yqm.googlegroups.com> On Feb 22, 9:02?pm, "venutaurus... at gmail.com" wrote: > On Feb 23, 9:25?am, MRAB wrote: > > > > > venutaurus... at gmail.com wrote: > > > Hello all, > > > ? ? ? ? ? ?I am writing an application where I need to open a shared > > > file on a remote machine using python script. I tried using the > > > following function: > > > > f = urllib.open("\\remote_machine\\folder1\\file1.doc") > > > > ? ? ? ? ?I also tried using > > > > class urllib.FancyURLopener(...) > > > > ? ? ? ? ?but didn't work. Can some one help me in this regard. > > > What do you mean by "remote machine"? Do you mean you want to open a > > file that's in a shared folder on a machine that's on the same local > > network? > > > If it's meant to be a Windows filepath then it should be: > > > ? ? ?f = open(r"\\remote_machine\folder1\file1.doc") > > > (If the file is a Microsoft Word document file, then you won't probably > > be able to make much sense of its contents using open().) > > Thanks to all for your brisk replies: > > ? ? ? ? Yes, my aim is to open a file from another machine in the same > LAN. It also worked using > > >>f = urllib.urlopen("\\\remote_machine\\folder\\file.doc") > > ? ? ? ? But now I also have to copy the same file to the local machine > in Python. Do I need to follow any protocols for this? > > Thank you, > Venu. the copy in shutil will work just fine. import shutil shutil.copy(remotepath,localpath) From clp2 at rebertia.com Mon Feb 23 00:10:38 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 22 Feb 2009 21:10:38 -0800 Subject: How to open a remote file using python. In-Reply-To: <00296096-1b2f-41fa-927a-53b2c33c58ac@n20g2000vba.googlegroups.com> References: <00296096-1b2f-41fa-927a-53b2c33c58ac@n20g2000vba.googlegroups.com> Message-ID: <50697b2c0902222110n783f9d11xb1c4245ba532e170@mail.gmail.com> On Sun, Feb 22, 2009 at 9:02 PM, venutaurus539 at gmail.com wrote: > On Feb 23, 9:25 am, MRAB wrote: >> venutaurus... at gmail.com wrote: >> > Hello all, >> > I am writing an application where I need to open a shared >> > file on a remote machine using python script. I tried using the >> > following function: >> >> > f = urllib.open("\\remote_machine\\folder1\\file1.doc") >> >> > I also tried using >> >> > class urllib.FancyURLopener(...) >> >> > but didn't work. Can some one help me in this regard. >> >> What do you mean by "remote machine"? Do you mean you want to open a >> file that's in a shared folder on a machine that's on the same local >> network? >> >> If it's meant to be a Windows filepath then it should be: >> >> f = open(r"\\remote_machine\folder1\file1.doc") >> >> (If the file is a Microsoft Word document file, then you won't probably >> be able to make much sense of its contents using open().) > > Thanks to all for your brisk replies: > > Yes, my aim is to open a file from another machine in the same > LAN. It also worked using > >>>f = urllib.urlopen("\\\remote_machine\\folder\\file.doc") > > But now I also have to copy the same file to the local machine > in Python. Do I need to follow any protocols for this? You may find urllib.urlretrieve() useful for accomplishing that. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From denis.kasak at gmail.com Mon Feb 23 00:54:16 2009 From: denis.kasak at gmail.com (Denis Kasak) Date: Mon, 23 Feb 2009 06:54:16 +0100 Subject: Reference or Value? In-Reply-To: References: Message-ID: <39e19a010902222154m1d2af37vea53e17578331939@mail.gmail.com> On Mon, Feb 23, 2009 at 5:09 AM, Steven D'Aprano wrote: > On Sun, 22 Feb 2009 13:37:27 -0300, andrew cooke wrote: > >> as far as i understand things, the best model is: >> >> 1 - everything is an object >> 2 - everything is passed by reference > > Except that is wrong. If it were true, you could do this: > > def swap(x, y): > y, x = x, y > > a = 1 > b = 2 > swap(a, b) > assert a == 2 and b == 1 > > > but you can't, it does not work. Ergo, parameter passing in Python does > not have the same semantics as languages that use pass-by-reference, such > as Pascal and Basic. That means that even if you can justify the claim > "Python is pass-by-reference" by some technical argument (and I don't > believe you can), it is misleading to make that claim without further > qualifications. You could, however, argue that the swap function doesn't work as expected (e.g. from a Pascal or a C++ POV) simply because the underlying objects aren't mutable. The objects *do* get passed by reference; the function doesn't receive a new copy of the object and it can examine the original object's ID. The actual culprit is not the way objects are passed but the assignment operator, since it works by rebinding names (as Andrew Koenig explained) and not by changing the object itself. If the swap() function could somehow access the underlying integer object and modify it, swapping of values would indeed occur because the function *did* get references to the objects passed to it. That said, it's a rather convoluted way of explaining what happens and calling it pass-by-object feels much better. :-) -- Denis Kasak From sjmachin at lexicon.net Mon Feb 23 01:38:47 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 22 Feb 2009 22:38:47 -0800 (PST) Subject: How does one get from "ImportError: DLL load failed:..." to a culprit .dll and symbol? References: <01b213c7$0$20626$c3e8da3@news.astraweb.com> Message-ID: <5850dc46-638f-4a3c-8d9a-f84bf7523979@o11g2000yql.googlegroups.com> On Feb 23, 2:56?pm, Chris Cormie wrote: > Hi, > > I've been Googling around on a moderately common Windows Python problem: > a mismatch between the symbols a python extension thinks are available > and the contents of the associated DLL. Python users running into this > problem are greeted with: > > import > "ImportError: DLL load failed: The specified procedure could not be found." > > That's it: no mention of which dll nor which symbol is causing the > problem. Both these pieces of information are helpful/important in > resolving this class of problem: how does one get Python to dump this > debugging data? > > (>python -v -d > doesn't help, BTW) Use -vv ... you need to know exactly which of possibly many incarnations of somemodule.pyd Python is trying to import from. Then get a copy of the Dependency Walker from http://www.dependencywalker.com/ Open c:\the\failing\somemodule.pyd with the DW. Look at grumble messages in the bottom pane. Note: you often get 1 or 2 warning messages with a pyd that's not having problems. Scroll through all the modules in the middle pane, looking for grumbles. If that not-very-technical description [all I've ever needed] doesn't help, you'll need to read the DW help file (HTFF1K) or wait till someone who knows what they are doing comes along :-) By the way, I presume that you are aware that extensions on Windows are tied to a particular version of Python ... you would have got a different error message if you had a version mismatch (I think). If your problem is not obvious, come back here with: -- what version of Python you are running -- what DLLs you find in the middle pane whose names match (1) MSVC*.DLL (2) PYTHON??.DLL You may need to answer questions about the extension (e.g. compiler/ linker options used) -- is it your extension or a 3rd party's? HTH, John From sternbrightblade at gmail.com Mon Feb 23 01:51:39 2009 From: sternbrightblade at gmail.com (Tony) Date: Sun, 22 Feb 2009 22:51:39 -0800 Subject: different errors, return outside function and others Message-ID: Hi, I am trying to write a small program for my final for school, everytime i run my program it gives me a return outside function error (after i fixed all the indentation errors it throws at me), i am not very good at programing with python atm, so any help would be appreiciated. and if im missing somethign please feel free to throw any suggestions out there. #This is a Text based RPG # HP = Character hit points, ZHP = Zombie Hit points, ZBHP = Zombie Boss Hit Points def fakemain(): #This is a place holder for me untill im ready to run the program start() startselection = start() if startselection == 1: character_creation() else: #end game (need the code to exit program) charselection = character_creation() if charselection == 1: name = raw_input ('Please Enter Your Name') HP = dice_roll2() print 'Your HP is ',HP elif charselection == 2: name = raw_input ('Please Enter Your Name') HP = dice_roll() print 'Your HP is ',HP else: intro_area() introselection = intro_area() if introselection == 1: print 'A Zombie Attacks you' fight(HP, ZHP, weapon) death(HP, ZHP, ZBHP) intro_area() else: back_yard() backyardselection = back_yard() if backyardselection == 1: fight(HP, ZHP, weapon) death(HP, ZHP, ZBHP) else: print 'The Zombie leaps and reaches you before you shut the door.' print 'YOU HAVE DIED!!!' #reset the game (need the code to reset program) Alley() alleyselection = Alley() if alleyselection == 1: police_station() else: #The object here is for the person to die if they select option 2 print 'As you try to get something to munch on 5 zombies attack you' fight(HP, ZHP, weapon) death(HP, ZHP, ZBHP) fight(HP, ZHP, weapon) death(HP, ZHP, ZBHP) fight(HP, ZHP, weapon) death(HP, ZHP, ZBHP) fight(HP, ZHP, weapon) death(HP, ZHP, ZBHP) fight(HP, ZHP, weapon) death(HP, ZHP, ZBHP) policeselection = police_station() if policeselection == 1: fight(HP, ZHP, weapon) death(HP, ZHP, ZBHP) fight(HP, ZHP, weapon) death(HP, ZHP, ZBHP) else: print 'The door mysteriously locked itself' police_station() police_backdoor() policebackselection = police_backdoor() if policebackselection == 1: forest() else: print 'The Front Door is locked only way out is the backdoor' police_backdoor() forestselection = forest() if forestselection == 1: fight(HP, ZBHP, weapon, True) death(HP, ZHP, ZBHP) end() else: print 'Jonas reaches you before you get back and eats your brains' #End game endselection = end() if endselection == 1: #End program or play rick roll'd haha else: #reset program #This mod is the first area you are in def intro_area(): introselection = 0 print ' Welcome to Zombie Survival' print ' It is a quite night in Egad, Wisconsin when..You suddenly awake' print ' to the sounds from outside. You see sparks outside from your window.' print ' The phone line has been cut. You have nothing to help you fend' print ' of attackers. What will you do!!!' print print '1. Open the Front door?' print '2. Go out the back door and towards the alley?' while introselection < 1 or introselection > 2 print 'That area is unavaible please buy the expansion haha' return introselection #This is the second area of the RPG def back_yard(): backyardselection = 0 print ' As you make your way out the back door, a Zombie appears from the' print ' side of the yard. He is slowly making his way to you, and you have' print ' to kill him to get to the alley. What course of action will you take.' print print '1.Fight the Zombie?' print '2.Run Away?' while backyardselection < 1 or backyardselection > 2: print 'That is a unavailible course of action.' #fight zombie return backyardselection #The Alley No Zombie fight here def Alley(): alleyselection = 0 print 'After you killed the Zombie you begin to cautiously walk down the alley' print 'looking for something to help you fend off anymore Zombies. When you' print 'get near the end of the alley you find a baseball bat and a first aid' print 'kit laying on the ground, You instinctifly pick up the bat and first' print 'aid kit, You reach the end of the alley, and you look around for a' print 'place to hide. Then you remeber about the forest beyond the police' print 'station. What will you do?' print print '1.Run to the police station?' print '2.Run to the grocery store?' while alleyselection < 1 or alleyselection > 2: print 'Theres a group of zombies over there!!' return alleyselection #fight 2 Zombies here def police_station(): policeselection = 0 print 'You make your way down the street and avoid all the zombies. when you' print 'reach the police station, The lights are flickering on and off. You see' print 'couple people moving around on the inside. As you open the front door' print 'the two zombies look at you and start heading torwards you. You raise' print 'your bat and prepare to kill them. What will you do first?' print print '1.Stand your ground?' print '2.Run back outside the door?' while policeselection < 1 or policeselection > 2: print 'Impossible please try again' return policeselection #fight 2 zombies #No Zombies here def police_backdoor(): policebackselection = 0 print 'You look down at the two zombies you just killed and see a gun.' print 'You lean over and grab the gun and the ammo. Then you start to' print 'look around and you notice another first aid kit, You walk over' print 'there and patch yourself up. After your done you head towards the' print 'back door. what will you do?' print print '1.Open the door?' print '2.Go Home?' while policebackselection < 1 or policebackselection > 2: print 'Not possible' return policebackselection #last area, boss is here def forest(): forestselection = 0 print 'You open the back door and you begin to walk out into the forest.' print 'As your steping through the trees, you look ahead of you and you' print 'see someone moving slowly towards you. As you focus you see that' print 'its your old army buddy Jonas, You yell at him but he just keeps' print 'moving towards you. You begin to notice that he is also a zombie' print 'What will you do now?' print print '1.Draw your gun and kill Jonas?' print '2.Go back into the police station?' while forestselection < 1 or forestselection > 2: print 'That option will be in the expansion lol' return forestselection #Fight Boss here #this is for the Ending def End(): endselection = 0 print 'You have completed the Zombie survival game.' print print '1. End Game' print '2. Start Over' while endselection < 1 or endselection > 2: print 'Dont Taze me!!' return endselection #this is for the start of the game def start(): startselection = 0 print ' Zombie Survial 1.0.1' print print '1. Start Game print '2. End Game' #if End game put rick roll'd there #Survial Mode (only if i can get this finished) while startselection < 1 or startselection > 2: print 'Please enter a selection 1 or 2 startselection = input('Press 1 to start the game') return startselection #This module is for the character creation at the beginning game and determines #how much health you have def character_creation(): charselection = 0 print ' Create your character' print '1. Male' print '2. Female' print '3. Be a coward and Quit' while charselection < 1 or charselection > 3: print 'Please enter a selection 1-3' charselection = input ('please inter gender') return charselection #This module is for the monster named Zombie def Zombie(): ZHP = dice_roll2() while ZHP > 0: return ZHP #This is for the Boss named Jonas def Zombie_Boss(): ZBHP = dice_roll4() while ZBHP > 0: return ZBHP #specific for Zombie Boss HP def dice_roll4(): seed() dice4 = random.randrange(4, 24, 1) return dice4 #This Module is for 2d6 sided dice def dice_roll2(): seed() dice2 = random.randrange(2, 12, 1) return dice2 #This Module is for 1d6 sided dice def dice_roll(): seed() dice = random.randrange(1, 6, 1) return dice #weapons = fist, gun, baseball bat # for regular zombie #call fight(HP, ZHP, weapon) # for boss zombie #call fight(HP, ZBHP, weapon, True) def fight(HP, ZHP, weapon, boss=False): if weapon == 'fist': while HP > 0 and ZHP > 0: damage = 2 ZHP = ZHP - damage if boss: HP = HP - dice_roll2() else: HP = HP - 2 elif weapon == 'baseball bat': while HP > 0 and ZHP > 0: damage = dice_roll() ZHP = ZHP - damage if boss: HP = HP - dice_roll2() else: HP = HP - 2 else weapon == 'gun': while HP > 0 and ZHP >0: damge = dice_roll2() ZHP = ZHP - damage if boss: HP = HP - dice_roll2() else: HP = HP - 2 #This module is used when you die def death(HP, ZHP, ZBHP): if HP == 0: print 'You have Died.' elif ZHP == 0: print 'You have killed the Zombie.' elif ZBHP == 0: print 'Right before you kill the Zombie, he runs off.' -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Mon Feb 23 01:58:22 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 22 Feb 2009 22:58:22 -0800 Subject: different errors, return outside function and others In-Reply-To: References: Message-ID: <50697b2c0902222258h75b1fdeeif736260818dfd6b3@mail.gmail.com> On Sun, Feb 22, 2009 at 10:51 PM, Tony wrote: > Hi, > I am trying to write a small program for my final for school, everytime i > run my program it gives me a return outside function error (after i fixed > all the indentation errors it throws at me), i am not very good at > programing with python atm, so any help would be appreiciated. and if im > missing somethign please feel free to throw > any suggestions out there. Please provide the full error message you're getting. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From kom2 at centrum.cz Mon Feb 23 02:51:27 2009 From: kom2 at centrum.cz (Kom2) Date: Sun, 22 Feb 2009 23:51:27 -0800 (PST) Subject: Running script in module initialization References: <56d0c8e4-c7cd-4b3b-aef0-7dc92996efb3@m15g2000vbp.googlegroups.com> Message-ID: <73cffb49-642a-4d6f-8c28-cc0ee5bb738b@z1g2000yqn.googlegroups.com> On 20 ?n, 16:27, Steve Holden wrote: > Kom2 wrote: > > Hello, > > I'm trying to convert my project from python 2.5 to python 3.0 and I > > have the following problem. My project is PYD library written in C++. > > So I have this PyInit_ModuleName function containing PyModule_Create > > call and this function also call some script with declarations: > > > ? ?PyObject* m; > > > ? ?m = PyModule_Create(&PyVRDAModule); > > ? ?if (m == NULL) { > > ? ? ? return NULL; > > ? ?} > > ? ?PyObject *d, *v; > > ? ?d = PyModule_GetDict(m); > > ? ?v = PyRun_StringFlags(txtPyPredefinedConstants), Py_file_input, d, > > d, NULL); > > ? ?...... > > > txtPyPredefinedConstants is string with this content: > > > class CursorMoveType: > > ? ?First = 0 > > ? ?Last = 1 > > ? ?Next = 2 > > ? ?Previous = 3 > > ? ?Bookmark = 4 > > ? ?NewRecord = 5 > > > In Python 2.5 everything works fine, now in python3.0 > > PyRun_StringFlags returns NULL and I get error "__build_class__ not > > found". > > > Can anybody tell mi please, what is wrong? > > Presumably you haven't upgraded your extension module to use the new API? > > ?http://wiki.python.org/moin/PortingExtensionModulesToPy3k > > regards > ?Steve > -- > Steve Holden ? ? ? ?+1 571 484 6266 ? +1 800 494 3119 > Holden Web LLC ? ? ? ? ? ? ?http://www.holdenweb.com/ Sorry, but I didn't get your point. I read the article, but I can't see anything about running script in module Init function... From afriere at yahoo.co.uk Mon Feb 23 02:52:10 2009 From: afriere at yahoo.co.uk (afriere at yahoo.co.uk) Date: Sun, 22 Feb 2009 23:52:10 -0800 (PST) Subject: Reference or Value? References: Message-ID: <87d8049c-a400-42f8-b2ac-8ab0bf0b4663@m24g2000vbp.googlegroups.com> On Feb 23, 2:13?am, Torsten Mohr wrote: > Hi, > > how is the rule in Python, if i pass objects to a function, when is this > done by reference and when is it by value? > > def f1(a): > ? ? a = 7 > > b = 3 > f1(b) > print b > => 3 > > Integers are obviously passed by value, lists and dicts by reference. > > Is there a general rule? ?Some common formulation? > > Thanks for any hints, > Torsten. Let's add some comments and a little code >>>def f1 (a) : print a, id(a) #print the object passed and it's id a = 7 #reassign 'a' to point to a different object print a, id(a) #print the new object and it's id >>> b = 1 >>> #make 'b' refer to object '1' residing at a particular memory location >>> id(b) 161120104 >>> #which we might refer to as 161120104 >>> f1(b) #pass the object '1' refered to by 'b' to our function 1 161120104 7 161120032 >>> #no surprises there, the new object has a different id. >>> id(b) 161120104 >>> #no surprises ther, b (unlike the name internal to the function >>> #hasn't been reassigned, so it still points where it always has >>> #which is of course .. >>> b 1 >>> z = [] >>> #name 'z' refers to an empty list >>> id(z) 162432780 >>> f1(z) [] 162432780 7 161120032 >>> #no surprise that the empty list object has the same id outside >>> #and inside the function >>> #stranger is that the '7' object has the same id as the 7 object >>> #created on the previous run on the function, but that is another >>> #story From gagsl-py2 at yahoo.com.ar Mon Feb 23 03:03:54 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 23 Feb 2009 06:03:54 -0200 Subject: Reference or Value? References: <39e19a010902222154m1d2af37vea53e17578331939@mail.gmail.com> Message-ID: En Mon, 23 Feb 2009 03:54:16 -0200, Denis Kasak escribi?: > On Mon, Feb 23, 2009 at 5:09 AM, Steven D'Aprano > wrote: >> On Sun, 22 Feb 2009 13:37:27 -0300, andrew cooke wrote: >> >>> as far as i understand things, the best model is: >>> >>> 1 - everything is an object >>> 2 - everything is passed by reference >> >> Except that is wrong. If it were true, you could do this: >> >> def swap(x, y): >> y, x = x, y >> >> a = 1 >> b = 2 >> swap(a, b) >> assert a == 2 and b == 1 >> >> >> but you can't, it does not work. Ergo, parameter passing in Python does >> not have the same semantics as languages that use pass-by-reference, >> such >> as Pascal and Basic. That means that even if you can justify the claim >> "Python is pass-by-reference" by some technical argument (and I don't >> believe you can), it is misleading to make that claim without further >> qualifications. > > You could, however, argue that the swap function doesn't work as > expected (e.g. from a Pascal or a C++ POV) simply because the > underlying objects aren't mutable. That's irrelevant - mutable and immutable objects are passed exactly the same way. > The objects *do* get passed by > reference; the function doesn't receive a new copy of the object and > it can examine the original object's ID. The actual culprit is not the > way objects are passed but the assignment operator, since it works by > rebinding names (as Andrew Koenig explained) and not by changing the > object itself. There is *no* difference between "the way objects are passed" and "the assignment opera[tion]": both work exactly the same way. Python execution model is based on namespaces (a collection of name->object pairs, usually implemented as dictionaries). An assignment x = y means: - evaluate the right hand side and obtain a value (an object, always). In this case, it is the object referenced by the name "y" - make the name "x" refer to such object. That's all. In short, assignment rebinds a name in a namespace. When a function call is made, a new namespace is created. The names come from the function parameters (the names that were used to define the function in the def ... line) and the objects come from the actual arguments (the objects you pass inside the (...) when doing the call). The function code is then executed using this namespace as its locals(). def foo(a, b): print a, b foo(4, ['hello', 'world!']) The call is equivalent to: ns = {} ns['a'], ns['b'] = 4, ['hello', 'world!'] execute foo code using ns as locals except the right hand side is evaluated on the *calling* namespace, and the left hand assignments are done on the new namespace. So a call binds many names in a new namespace: the same as assignment. No copies, no pointers, nothing: only names and objects are manipulated. > If the swap() function could somehow access the > underlying integer object and modify it, swapping of values would > indeed occur because the function *did* get references to the objects > passed to it. There is a difference between modify the value of an object, and modify the caller's namespace. Usually "pass by reference" means that the *caller* may see a different thing after the call - this is not true in Python, there is no way the called code could alter the caller namespace (well, not just due to the call operation alone...) > That said, it's a rather convoluted way of explaining what happens and > calling it pass-by-object feels much better. :-) And is more correct... -- Gabriel Genellina From neoedmund at gmail.com Mon Feb 23 03:06:58 2009 From: neoedmund at gmail.com (neoedmund) Date: Mon, 23 Feb 2009 00:06:58 -0800 (PST) Subject: confusing UnboundLocalError behaive Message-ID: <7eb57b3d-de83-4e1b-a7c1-048064c511bb@o11g2000yql.googlegroups.com> see the 3 small piece of code, i cannot understand why it result as this. 1. def test(): abc="111" def m1(): print(abc) m1() test() Output: 111 2. def test(): abc="111" def m1(): print(abc) abc+="222" m1() test() Output: print(abc) UnboundLocalError: local variable 'abc' referenced before assignment 3. def test2(): abc=[111] def m1(): print(abc) abc.append(222) m1() print(abc) test2() Output: [111] [111,222] it seems "you cannot change the outter scope values but can use it readonly." From sternbrightblade at gmail.com Mon Feb 23 03:08:45 2009 From: sternbrightblade at gmail.com (Tony) Date: Mon, 23 Feb 2009 00:08:45 -0800 Subject: different errors, return outside function and others In-Reply-To: References: Message-ID: The full error message says "There's an error in your program: *** 'return' outside function (final(2).py, line 114) which is were this return statement is.. while introselection < 1 or introselection > 2: print 'That area is unavaible please buy the expansion haha' return introselection On Sun, Feb 22, 2009 at 10:51 PM, Tony wrote: > Hi, > I am trying to write a small program for my final for school, everytime i > run my program it gives me a return outside function error (after i fixed > all the indentation errors it throws at me), i am not very good at > programing with python atm, so any help would be appreiciated. and if im > missing somethign please feel free to throw > any suggestions out there. > > #This is a Text based RPG > # HP = Character hit points, ZHP = Zombie Hit points, ZBHP = Zombie Boss > Hit Points > def fakemain(): #This is a place holder for me untill im ready to run the > program > start() > startselection = start() > if startselection == 1: > character_creation() > else: > #end game (need the code to exit program) > > charselection = character_creation() > if charselection == 1: > name = raw_input ('Please Enter Your Name') > HP = dice_roll2() > print 'Your HP is ',HP > elif charselection == 2: > name = raw_input ('Please Enter Your Name') > HP = dice_roll() > print 'Your HP is ',HP > else: > > intro_area() > introselection = intro_area() > if introselection == 1: > print 'A Zombie Attacks you' > fight(HP, ZHP, weapon) > death(HP, ZHP, ZBHP) > intro_area() > else: > back_yard() > backyardselection = back_yard() > if backyardselection == 1: > fight(HP, ZHP, weapon) > death(HP, ZHP, ZBHP) > else: > print 'The Zombie leaps and reaches you before you shut the door.' > print 'YOU HAVE DIED!!!' > #reset the game (need the code to reset program) > > Alley() > alleyselection = Alley() > if alleyselection == 1: > police_station() > else: #The object here is for the person to die if they select option > 2 > print 'As you try to get something to munch on 5 zombies attack > you' > fight(HP, ZHP, weapon) > death(HP, ZHP, ZBHP) > fight(HP, ZHP, weapon) > death(HP, ZHP, ZBHP) > fight(HP, ZHP, weapon) > death(HP, ZHP, ZBHP) > fight(HP, ZHP, weapon) > death(HP, ZHP, ZBHP) > fight(HP, ZHP, weapon) > death(HP, ZHP, ZBHP) > policeselection = police_station() > if policeselection == 1: > fight(HP, ZHP, weapon) > death(HP, ZHP, ZBHP) > fight(HP, ZHP, weapon) > death(HP, ZHP, ZBHP) > else: > print 'The door mysteriously locked itself' > police_station() > police_backdoor() > policebackselection = police_backdoor() > if policebackselection == 1: > forest() > else: > print 'The Front Door is locked only way out is the backdoor' > police_backdoor() > > forestselection = forest() > if forestselection == 1: > fight(HP, ZBHP, weapon, True) > death(HP, ZHP, ZBHP) > end() > else: > print 'Jonas reaches you before you get back and eats your brains' > #End game > endselection = end() > if endselection == 1: > #End program or play rick roll'd haha > else: > #reset program > > > #This mod is the first area you are in > def intro_area(): > introselection = 0 > print ' Welcome to Zombie Survival' > print ' It is a quite night in Egad, Wisconsin when..You suddenly > awake' > print ' to the sounds from outside. You see sparks outside from your > window.' > print ' The phone line has been cut. You have nothing to help you fend' > print ' of attackers. What will you do!!!' > print > print '1. Open the Front door?' > print '2. Go out the back door and towards the alley?' > while introselection < 1 or introselection > 2 > print 'That area is unavaible please buy the expansion haha' > return introselection > > #This is the second area of the RPG > def back_yard(): > backyardselection = 0 > print ' As you make your way out the back door, a Zombie appears from > the' > print ' side of the yard. He is slowly making his way to you, and you > have' > print ' to kill him to get to the alley. What course of action will you > take.' > print > print '1.Fight the Zombie?' > print '2.Run Away?' > while backyardselection < 1 or backyardselection > 2: > print 'That is a unavailible course of action.' > #fight zombie > return backyardselection > > #The Alley No Zombie fight here > def Alley(): > alleyselection = 0 > print 'After you killed the Zombie you begin to cautiously walk down > the alley' > print 'looking for something to help you fend off anymore Zombies. When > you' > print 'get near the end of the alley you find a baseball bat and a > first aid' > print 'kit laying on the ground, You instinctifly pick up the bat and > first' > print 'aid kit, You reach the end of the alley, and you look around for > a' > print 'place to hide. Then you remeber about the forest beyond the > police' > print 'station. What will you do?' > print > print '1.Run to the police station?' > print '2.Run to the grocery store?' > while alleyselection < 1 or alleyselection > 2: > print 'Theres a group of zombies over there!!' > return alleyselection > > #fight 2 Zombies here > def police_station(): > policeselection = 0 > print 'You make your way down the street and avoid all the zombies. > when you' > print 'reach the police station, The lights are flickering on and off. > You see' > print 'couple people moving around on the inside. As you open the front > door' > print 'the two zombies look at you and start heading torwards you. You > raise' > print 'your bat and prepare to kill them. What will you do first?' > print > print '1.Stand your ground?' > print '2.Run back outside the door?' > while policeselection < 1 or policeselection > 2: > print 'Impossible please try again' > return policeselection > #fight 2 zombies > > #No Zombies here > def police_backdoor(): > policebackselection = 0 > print 'You look down at the two zombies you just killed and see a gun.' > print 'You lean over and grab the gun and the ammo. Then you start to' > print 'look around and you notice another first aid kit, You walk over' > print 'there and patch yourself up. After your done you head towards > the' > print 'back door. what will you do?' > print > print '1.Open the door?' > print '2.Go Home?' > while policebackselection < 1 or policebackselection > 2: > print 'Not possible' > return policebackselection > > #last area, boss is here > def forest(): > forestselection = 0 > print 'You open the back door and you begin to walk out into the > forest.' > print 'As your steping through the trees, you look ahead of you and > you' > print 'see someone moving slowly towards you. As you focus you see > that' > print 'its your old army buddy Jonas, You yell at him but he just > keeps' > print 'moving towards you. You begin to notice that he is also a > zombie' > print 'What will you do now?' > print > print '1.Draw your gun and kill Jonas?' > print '2.Go back into the police station?' > while forestselection < 1 or forestselection > 2: > print 'That option will be in the expansion lol' > return forestselection > #Fight Boss here > > #this is for the Ending > def End(): > endselection = 0 > print 'You have completed the Zombie survival game.' > print > print '1. End Game' > print '2. Start Over' > while endselection < 1 or endselection > 2: > print 'Dont Taze me!!' > return endselection > > #this is for the start of the game > def start(): > startselection = 0 > print ' Zombie Survial 1.0.1' > print > print '1. Start Game > print '2. End Game' > #if End game put rick roll'd there > #Survial Mode (only if i can get this finished) > while startselection < 1 or startselection > 2: > print 'Please enter a selection 1 or 2 > startselection = input('Press 1 to start the game') > return startselection > > #This module is for the character creation at the beginning game and > determines > #how much health you have > def character_creation(): > charselection = 0 > print ' Create your character' > print '1. Male' > print '2. Female' > print '3. Be a coward and Quit' > while charselection < 1 or charselection > 3: > print 'Please enter a selection 1-3' > charselection = input ('please inter gender') > return charselection > > #This module is for the monster named Zombie > def Zombie(): > ZHP = dice_roll2() > while ZHP > 0: > return ZHP > > #This is for the Boss named Jonas > def Zombie_Boss(): > ZBHP = dice_roll4() > while ZBHP > 0: > return ZBHP > > #specific for Zombie Boss HP > def dice_roll4(): > seed() > dice4 = random.randrange(4, 24, 1) > return dice4 > > #This Module is for 2d6 sided dice > def dice_roll2(): > seed() > dice2 = random.randrange(2, 12, 1) > return dice2 > > #This Module is for 1d6 sided dice > def dice_roll(): > seed() > dice = random.randrange(1, 6, 1) > return dice > > #weapons = fist, gun, baseball bat > # for regular zombie > #call fight(HP, ZHP, weapon) > # for boss zombie > #call fight(HP, ZBHP, weapon, True) > def fight(HP, ZHP, weapon, boss=False): > if weapon == 'fist': > while HP > 0 and ZHP > 0: > damage = 2 > ZHP = ZHP - damage > if boss: > HP = HP - dice_roll2() > else: > HP = HP - 2 > elif weapon == 'baseball bat': > while HP > 0 and ZHP > 0: > damage = dice_roll() > ZHP = ZHP - damage > if boss: > HP = HP - dice_roll2() > else: > HP = HP - 2 > else weapon == 'gun': > while HP > 0 and ZHP >0: > damge = dice_roll2() > ZHP = ZHP - damage > if boss: > HP = HP - dice_roll2() > else: > HP = HP - 2 > > #This module is used when you die > def death(HP, ZHP, ZBHP): > if HP == 0: > print 'You have Died.' > elif ZHP == 0: > print 'You have killed the Zombie.' > elif ZBHP == 0: > print 'Right before you kill the Zombie, he runs off.' > -------------- next part -------------- An HTML attachment was scrubbed... URL: From Ron.Barak at lsi.com Mon Feb 23 03:09:44 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Mon, 23 Feb 2009 08:09:44 +0000 Subject: Is there a way to ask a class what its metaclasses are ? In-Reply-To: <50697b2c0902221211k3be5f797k5f0419179864ae4f@mail.gmail.com> References: <7F0503CD69378F49BE0DC30661C6CCF60E68800F@enbmail01.lsi.com> <50697b2c0902191258ye5aa478gecaf7b7b097e3eba@mail.gmail.com> <7F0503CD69378F49BE0DC30661C6CCF62783D662@enbmail01.lsi.com> <50697b2c0902220147y4c8dbf94j1415aae9ee7d640@mail.gmail.com> <7F0503CD69378F49BE0DC30661C6CCF62783D673@enbmail01.lsi.com> <50697b2c0902220357g762fe390q6535079d42f6afb0@mail.gmail.com> <7F0503CD69378F49BE0DC30661C6CCF62783D685@enbmail01.lsi.com> <50697b2c0902221211k3be5f797k5f0419179864ae4f@mail.gmail.com> Message-ID: <7F0503CD69378F49BE0DC30661C6CCF659FDEDBD@enbmail01.lsi.com> > -----Original Message----- > From: chris at rebertia.com [mailto:chris at rebertia.com] On > Behalf Of Chris Rebert > Sent: Sunday, February 22, 2009 22:12 > To: Barak, Ron > Cc: python-list at python.org > Subject: Re: Is there a way to ask a class what its metaclasses are ? > > On Sun, Feb 22, 2009 at 5:14 AM, Barak, Ron wrote: > > Hi Chris, > > Is there a way to ask a class what its metaclasses are ? > > (e.g., how to ask wx.Frame what it's metaclass is) > > Of course. A metaclass is the type of a class, so it's just > type(wx.Frame). > > Cheers, > Chris Thanks Chris. When I try the following (to see the types of the classes involved): #!/usr/bin/env python import wx from Debug import _line as line class CopyAndPaste(object): def __init__(self, *args, **kwargs): super(CopyAndPaste, self).__init__(*args, **kwargs) print line()+". type(wx.Frame):",type(wx.Frame) print line()+". type(object):",type(object) I get: $ python -u CopyAndPaste.py 9. type(wx.Frame): 10. type(object): And I don't understand what it means... In any case, it does not seem to help me resolve the metaclasses exception. Bye, Ron. > > -- > Follow the path of the Iguana... > http://rebertia.com > > > > > I'm asking, because, even subclassing from object, viz.: > > > > class CopyAndPaste(object): > > def __init__(self): > > pass > > ... > > > > Still gives me: > > > > $ python -u ./failover_pickle_demo09.py Traceback (most recent call > > last): > > File "./failover_pickle_demo09.py", line 321, in > > class ListControlMeta(wx.Frame, CopyAndPaste): > > TypeError: Error when calling the metaclass bases > > metaclass conflict: the metaclass of a derived class must be a > > (non-strict) subclass of the metaclasses of all its bases > > > > Bye, > > Ron. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From alwaseem307ster at yahoo.com Mon Feb 23 03:17:41 2009 From: alwaseem307ster at yahoo.com (klia) Date: Mon, 23 Feb 2009 00:17:41 -0800 (PST) Subject: pysqlite smart search Message-ID: <22157116.post@talk.nabble.com> Hey guys; I am trying to develop a tiny program using python to search inside sqlite database with file extension is .db in which the program will ask users to enter their search query and base on that it will retrieve the results But I need the program to have some smartness in search mechanism in which the program will guess that the user is looking for these key words in the database. so far i came up with this but the search ain't smart, i have to write the full key word in order to retrieve specific information. from pysqlite2 import dbapi2 as sqlite3 connection = sqlite3.connect('Photos.db') memoryConnection = sqlite3.connect(':memory:') cursor = connection.cursor() prompt = 'Enter your search query?\n' keyword = raw_input(prompt) if cursor.execute('SELECT * FROM photos WHERE Tag LIKE ?',[keyword]): print cursor.fetchall() else: cursor.execute('SELECT * FROM photos WHERE Date LIKE ?', [keyword]) print cursor.fetchall() Any ideas and thanks in advance Reply -- View this message in context: http://www.nabble.com/pysqlite-smart-search-tp22157116p22157116.html Sent from the Python - python-list mailing list archive at Nabble.com. From clp2 at rebertia.com Mon Feb 23 03:21:35 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 23 Feb 2009 00:21:35 -0800 Subject: different errors, return outside function and others In-Reply-To: References: Message-ID: <50697b2c0902230021v6a52db2eoc2218cf7bf835995@mail.gmail.com> Ok, that's not a standard Python error report (I'm guessing you're using an IDE of some sort). Also, something's not right because your excerpt doesn't match the source you posted. In your previous post, the 'while' line in question was given as: while introselection < 1 or introselection > 2 Note the missing semicolon. Whereas in your last message, you show it with the semicolon. Try running your program from the command line with Python and check what error message it gives. And ensure you give the /exact/ source if you have further questions. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com On Mon, Feb 23, 2009 at 12:08 AM, Tony wrote: > The full error message says "There's an error in your program: *** 'return' > outside function (final(2).py, line 114) > which is were this return statement is.. > while introselection < 1 or introselection > 2: > print 'That area is unavaible please buy the expansion haha' > return introselection > On Sun, Feb 22, 2009 at 10:51 PM, Tony wrote: >> >> Hi, >> I am trying to write a small program for my final for school, everytime i >> run my program it gives me a return outside function error (after i fixed >> all the indentation errors it throws at me), i am not very good at >> programing with python atm, so any help would be appreiciated. and if im >> missing somethign please feel free to throw >> any suggestions out there. >> >> #This is a Text based RPG >> # HP = Character hit points, ZHP = Zombie Hit points, ZBHP = Zombie Boss >> Hit Points >> def fakemain(): #This is a place holder for me untill im ready to run the >> program >> start() >> startselection = start() >> if startselection == 1: >> character_creation() >> else: >> #end game (need the code to exit program) >> >> charselection = character_creation() >> if charselection == 1: >> name = raw_input ('Please Enter Your Name') >> HP = dice_roll2() >> print 'Your HP is ',HP >> elif charselection == 2: >> name = raw_input ('Please Enter Your Name') >> HP = dice_roll() >> print 'Your HP is ',HP >> else: >> >> intro_area() >> introselection = intro_area() >> if introselection == 1: >> print 'A Zombie Attacks you' >> fight(HP, ZHP, weapon) >> death(HP, ZHP, ZBHP) >> intro_area() >> else: >> back_yard() >> backyardselection = back_yard() >> if backyardselection == 1: >> fight(HP, ZHP, weapon) >> death(HP, ZHP, ZBHP) >> else: >> print 'The Zombie leaps and reaches you before you shut the door.' >> print 'YOU HAVE DIED!!!' >> #reset the game (need the code to reset program) >> >> Alley() >> alleyselection = Alley() >> if alleyselection == 1: >> police_station() >> else: #The object here is for the person to die if they select >> option 2 >> print 'As you try to get something to munch on 5 zombies attack >> you' >> fight(HP, ZHP, weapon) >> death(HP, ZHP, ZBHP) >> fight(HP, ZHP, weapon) >> death(HP, ZHP, ZBHP) >> fight(HP, ZHP, weapon) >> death(HP, ZHP, ZBHP) >> fight(HP, ZHP, weapon) >> death(HP, ZHP, ZBHP) >> fight(HP, ZHP, weapon) >> death(HP, ZHP, ZBHP) >> policeselection = police_station() >> if policeselection == 1: >> fight(HP, ZHP, weapon) >> death(HP, ZHP, ZBHP) >> fight(HP, ZHP, weapon) >> death(HP, ZHP, ZBHP) >> else: >> print 'The door mysteriously locked itself' >> police_station() >> police_backdoor() >> policebackselection = police_backdoor() >> if policebackselection == 1: >> forest() >> else: >> print 'The Front Door is locked only way out is the backdoor' >> police_backdoor() >> forestselection = forest() >> if forestselection == 1: >> fight(HP, ZBHP, weapon, True) >> death(HP, ZHP, ZBHP) >> end() >> else: >> print 'Jonas reaches you before you get back and eats your brains' >> #End game >> endselection = end() >> if endselection == 1: >> #End program or play rick roll'd haha >> else: >> #reset program >> >> #This mod is the first area you are in >> def intro_area(): >> introselection = 0 >> print ' Welcome to Zombie Survival' >> print ' It is a quite night in Egad, Wisconsin when..You suddenly >> awake' >> print ' to the sounds from outside. You see sparks outside from your >> window.' >> print ' The phone line has been cut. You have nothing to help you >> fend' >> print ' of attackers. What will you do!!!' >> print >> print '1. Open the Front door?' >> print '2. Go out the back door and towards the alley?' >> while introselection < 1 or introselection > 2 >> print 'That area is unavaible please buy the expansion haha' >> return introselection >> >> #This is the second area of the RPG >> def back_yard(): >> backyardselection = 0 >> print ' As you make your way out the back door, a Zombie appears from >> the' >> print ' side of the yard. He is slowly making his way to you, and you >> have' >> print ' to kill him to get to the alley. What course of action will >> you take.' >> print >> print '1.Fight the Zombie?' >> print '2.Run Away?' >> while backyardselection < 1 or backyardselection > 2: >> print 'That is a unavailible course of action.' >> #fight zombie >> return backyardselection >> >> #The Alley No Zombie fight here >> def Alley(): >> alleyselection = 0 >> print 'After you killed the Zombie you begin to cautiously walk down >> the alley' >> print 'looking for something to help you fend off anymore Zombies. >> When you' >> print 'get near the end of the alley you find a baseball bat and a >> first aid' >> print 'kit laying on the ground, You instinctifly pick up the bat and >> first' >> print 'aid kit, You reach the end of the alley, and you look around >> for a' >> print 'place to hide. Then you remeber about the forest beyond the >> police' >> print 'station. What will you do?' >> print >> print '1.Run to the police station?' >> print '2.Run to the grocery store?' >> while alleyselection < 1 or alleyselection > 2: >> print 'Theres a group of zombies over there!!' >> return alleyselection >> >> #fight 2 Zombies here >> def police_station(): >> policeselection = 0 >> print 'You make your way down the street and avoid all the zombies. >> when you' >> print 'reach the police station, The lights are flickering on and off. >> You see' >> print 'couple people moving around on the inside. As you open the >> front door' >> print 'the two zombies look at you and start heading torwards you. You >> raise' >> print 'your bat and prepare to kill them. What will you do first?' >> print >> print '1.Stand your ground?' >> print '2.Run back outside the door?' >> while policeselection < 1 or policeselection > 2: >> print 'Impossible please try again' >> return policeselection >> #fight 2 zombies >> >> #No Zombies here >> def police_backdoor(): >> policebackselection = 0 >> print 'You look down at the two zombies you just killed and see a >> gun.' >> print 'You lean over and grab the gun and the ammo. Then you start to' >> print 'look around and you notice another first aid kit, You walk >> over' >> print 'there and patch yourself up. After your done you head towards >> the' >> print 'back door. what will you do?' >> print >> print '1.Open the door?' >> print '2.Go Home?' >> while policebackselection < 1 or policebackselection > 2: >> print 'Not possible' >> return policebackselection >> >> #last area, boss is here >> def forest(): >> forestselection = 0 >> print 'You open the back door and you begin to walk out into the >> forest.' >> print 'As your steping through the trees, you look ahead of you and >> you' >> print 'see someone moving slowly towards you. As you focus you see >> that' >> print 'its your old army buddy Jonas, You yell at him but he just >> keeps' >> print 'moving towards you. You begin to notice that he is also a >> zombie' >> print 'What will you do now?' >> print >> print '1.Draw your gun and kill Jonas?' >> print '2.Go back into the police station?' >> while forestselection < 1 or forestselection > 2: >> print 'That option will be in the expansion lol' >> return forestselection >> #Fight Boss here >> #this is for the Ending >> def End(): >> endselection = 0 >> print 'You have completed the Zombie survival game.' >> print >> print '1. End Game' >> print '2. Start Over' >> while endselection < 1 or endselection > 2: >> print 'Dont Taze me!!' >> return endselection >> >> #this is for the start of the game >> def start(): >> startselection = 0 >> print ' Zombie Survial 1.0.1' >> print >> print '1. Start Game >> print '2. End Game' >> #if End game put rick roll'd there >> #Survial Mode (only if i can get this finished) >> while startselection < 1 or startselection > 2: >> print 'Please enter a selection 1 or 2 >> startselection = input('Press 1 to start the game') >> return startselection >> >> #This module is for the character creation at the beginning game and >> determines >> #how much health you have >> def character_creation(): >> charselection = 0 >> print ' Create your character' >> print '1. Male' >> print '2. Female' >> print '3. Be a coward and Quit' >> while charselection < 1 or charselection > 3: >> print 'Please enter a selection 1-3' >> charselection = input ('please inter gender') >> return charselection >> >> #This module is for the monster named Zombie >> def Zombie(): >> ZHP = dice_roll2() >> while ZHP > 0: >> return ZHP >> >> #This is for the Boss named Jonas >> def Zombie_Boss(): >> ZBHP = dice_roll4() >> while ZBHP > 0: >> return ZBHP >> >> #specific for Zombie Boss HP >> def dice_roll4(): >> seed() >> dice4 = random.randrange(4, 24, 1) >> return dice4 >> >> #This Module is for 2d6 sided dice >> def dice_roll2(): >> seed() >> dice2 = random.randrange(2, 12, 1) >> return dice2 >> >> #This Module is for 1d6 sided dice >> def dice_roll(): >> seed() >> dice = random.randrange(1, 6, 1) >> return dice >> >> #weapons = fist, gun, baseball bat >> # for regular zombie >> #call fight(HP, ZHP, weapon) >> # for boss zombie >> #call fight(HP, ZBHP, weapon, True) >> def fight(HP, ZHP, weapon, boss=False): >> if weapon == 'fist': >> while HP > 0 and ZHP > 0: >> damage = 2 >> ZHP = ZHP - damage >> if boss: >> HP = HP - dice_roll2() >> else: >> HP = HP - 2 >> elif weapon == 'baseball bat': >> while HP > 0 and ZHP > 0: >> damage = dice_roll() >> ZHP = ZHP - damage >> if boss: >> HP = HP - dice_roll2() >> else: >> HP = HP - 2 >> else weapon == 'gun': >> while HP > 0 and ZHP >0: >> damge = dice_roll2() >> ZHP = ZHP - damage >> if boss: >> HP = HP - dice_roll2() >> else: >> HP = HP - 2 >> >> #This module is used when you die >> def death(HP, ZHP, ZBHP): >> if HP == 0: >> print 'You have Died.' >> elif ZHP == 0: >> print 'You have killed the Zombie.' >> elif ZBHP == 0: >> print 'Right before you kill the Zombie, he runs off.' > > -- > http://mail.python.org/mailman/listinfo/python-list From gagsl-py2 at yahoo.com.ar Mon Feb 23 03:23:25 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 23 Feb 2009 06:23:25 -0200 Subject: different errors, return outside function and others References: Message-ID: En Mon, 23 Feb 2009 04:51:39 -0200, Tony escribi?: > Hi, > I am trying to write a small program for my final for school, everytime i > run my program it gives me a return outside function error (after i fixed > all the indentation errors it throws at me), i am not very good at > programing with python atm, so any help would be appreiciated. and if im > missing somethign please feel free to throw > any suggestions out there. Is this your *actual* code? It does not even compile... Things like 'def foo(...):' are *functions*, not *modules*. Variables inside functions (including its arguments) are locals, private to the function. Even if you modify them, the "outside world" doesn't notice. So a function like this: > def fight(HP, ZHP, weapon, boss=False): > if weapon == 'fist': > while HP > 0 and ZHP > 0: > damage = 2 > ZHP = ZHP - damage > if boss: > HP = HP - dice_roll2() > else: > HP = HP - 2 > elif weapon == 'baseball bat': [... more code ...] won't alter the "global" values HP, ZHP; in fact, it won't do nothing. Either return the new values: return HP, ZHP and also adjust everywhere you call: HP, ZHP = fight(HP, ZHP, ...) Or mark HP, ZHP as globals (using the global statement). -- Gabriel Genellina From clp2 at rebertia.com Mon Feb 23 03:26:17 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 23 Feb 2009 00:26:17 -0800 Subject: confusing UnboundLocalError behaive In-Reply-To: <7eb57b3d-de83-4e1b-a7c1-048064c511bb@o11g2000yql.googlegroups.com> References: <7eb57b3d-de83-4e1b-a7c1-048064c511bb@o11g2000yql.googlegroups.com> Message-ID: <50697b2c0902230026v7f3826adq6472412dc892ba03@mail.gmail.com> On Mon, Feb 23, 2009 at 12:06 AM, neoedmund wrote: > see the 3 small piece of code, i cannot understand why it result as > this. > > 1. > def test(): > abc="111" > def m1(): > print(abc) > m1() > test() > > Output: 111 > > 2. > def test(): > abc="111" > def m1(): You need a 'nonlocal' declaration here (requires Python 3.0 I think). See PEP 3104 for more info -- http://www.python.org/dev/peps/pep-3104/ > print(abc) > abc+="222" > m1() > test() > > Output: > print(abc) > UnboundLocalError: local variable 'abc' referenced before assignment > > 3. > def test2(): > abc=[111] > def m1(): > print(abc) > abc.append(222) > m1() > print(abc) > test2() > > Output: > [111] > [111,222] > > it seems "you cannot change the outter scope values but can use it > readonly." Yeah, that's basically how nested scopes (sans 'nonlocal') work in Python, since assignment typically constitutes an implicit scope declaration. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From gagsl-py2 at yahoo.com.ar Mon Feb 23 03:47:13 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 23 Feb 2009 06:47:13 -0200 Subject: confusing UnboundLocalError behaive References: <7eb57b3d-de83-4e1b-a7c1-048064c511bb@o11g2000yql.googlegroups.com> Message-ID: En Mon, 23 Feb 2009 06:06:58 -0200, neoedmund escribi?: > it seems "you cannot change the outter scope values but can use it > readonly." Exactly. Python doesn't have variable "declarations" - so the compiler uses this rule: "if the variable is assigned to, anywhere in the function body, it's local". This is done by static analysis when the code is compiled. > 2. > def test(): > abc="111" > def m1(): > print(abc) > abc+="222" > m1() > test() > > Output: > print(abc) > UnboundLocalError: local variable 'abc' referenced before assignment abc is assigned to, so it is local (and different from the abc in its enclosing scope). You can't print abc until it is assigned "something". > 3. > def test2(): > abc=[111] > def m1(): > print(abc) > abc.append(222) > m1() > print(abc) No assignment to abc, so it's not local; print(abc) starts looking for it in all the enclosing scopes (up to the module global scope, and last, the builtin module). -- Gabriel Genellina From steven at REMOVE.THIS.cybersource.com.au Mon Feb 23 04:02:46 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 23 Feb 2009 09:02:46 GMT Subject: confusing UnboundLocalError behaive References: <7eb57b3d-de83-4e1b-a7c1-048064c511bb@o11g2000yql.googlegroups.com> Message-ID: On Mon, 23 Feb 2009 00:06:58 -0800, neoedmund wrote: > see the 3 small piece of code, i cannot understand why it result as > this. > > 1. > def test(): > abc="111" > def m1(): > print(abc) > m1() > test() > > Output: 111 abc is local to test(). print(abc) looks for a local abc, can't find one, and so searches the higher scope, and finds it there. > 2. > def test(): > abc="111" > def m1(): > print(abc) > abc+="222" > m1() > test() > > Output: > print(abc) > UnboundLocalError: local variable 'abc' referenced before assignment Because you make an assignment to abc inside the m1() function, but didn't declare it as global, Python assumes that it must be a local variable. So when you try to print it, it doesn't have a value yet. Solution: don't do that, or use the statement nonlocal (like global, except I think it is only introduced in Python 3.0). > 3. > def test2(): > abc=[111] > def m1(): > print(abc) > abc.append(222) > m1() > print(abc) > test2() > > Output: > [111] > [111,222] > > it seems "you cannot change the outter scope values but can use it > readonly." But you're not using it read-only, because the append worked. What you can't do is assign to the name. Have a look at the disassembled code: >>> import dis >>> def spam(): ... print x ... y = x+1 ... >>> dis.dis(spam) 2 0 LOAD_GLOBAL 0 (x) 3 PRINT_ITEM 4 PRINT_NEWLINE 3 5 LOAD_GLOBAL 0 (x) 8 LOAD_CONST 1 (1) 11 BINARY_ADD 12 STORE_FAST 0 (y) 15 LOAD_CONST 0 (None) 18 RETURN_VALUE >>> >>> def ham(): ... print x ... x = x+1 ... >>> dis.dis(ham) 2 0 LOAD_FAST 0 (x) 3 PRINT_ITEM 4 PRINT_NEWLINE 3 5 LOAD_FAST 0 (x) 8 LOAD_CONST 1 (1) 11 BINARY_ADD 12 STORE_FAST 0 (x) 15 LOAD_CONST 0 (None) 18 RETURN_VALUE -- Steven From gagsl-py2 at yahoo.com.ar Mon Feb 23 04:07:38 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 23 Feb 2009 07:07:38 -0200 Subject: pysqlite smart search References: <22157116.post@talk.nabble.com> Message-ID: En Mon, 23 Feb 2009 06:17:41 -0200, klia escribi?: > I need the program to have some smartness in search mechanism in which > the > program will guess that the user is looking for these key words in the > database. > > so far i came up with this but the search ain't smart, i have to write > the > full key word in order to retrieve specific information. > > from pysqlite2 import dbapi2 as sqlite3 > > connection = sqlite3.connect('Photos.db') > memoryConnection = sqlite3.connect(':memory:') > cursor = connection.cursor() > prompt = 'Enter your search query?\n' > keyword = raw_input(prompt) > if cursor.execute('SELECT * FROM photos WHERE Tag LIKE ?',[keyword]): > print cursor.fetchall() > else: > cursor.execute('SELECT * FROM photos WHERE Date LIKE ?', [keyword]) > print cursor.fetchall() That's pretty good. SQL wildcard is '%' so try using '... where Tag like ?', ('%'+keyword+'%',) Also, the return value of cursor.execute is undefined in PEP249, and fetchall is a connection method, not cursor's. (Although this may work with SQLite, if you later decide to switch to another database it would be inconvenient). cursor.execute('SELECT * FROM photos WHERE Tag LIKE ?', ('%'+keyword+'%',)) rows = cursor.fetchall() if not rows: cursor.execute('SELECT * FROM photos WHERE Date LIKE ?', (keyword,)) rows = cursor.fetchall() print rows -- Gabriel Genellina From sternbrightblade at gmail.com Mon Feb 23 04:07:57 2009 From: sternbrightblade at gmail.com (Tony) Date: Mon, 23 Feb 2009 01:07:57 -0800 Subject: different errors, return outside function and others In-Reply-To: References: Message-ID: ok thank you for that input, this is my first class in programming and its the only one the school offers. im pretty sure those are supposed to be modules that im writting. would it make a difference if those were modules and not functions? kinda stupid question there but im trying to learn as much as possible. Also anything with def infront of it example def start(): would be a function correct? also im Using 2.5 and the IDLE to do this On Mon, Feb 23, 2009 at 12:23 AM, Gabriel Genellina wrote: > En Mon, 23 Feb 2009 04:51:39 -0200, Tony > escribi?: > > Hi, >> I am trying to write a small program for my final for school, everytime i >> run my program it gives me a return outside function error (after i fixed >> all the indentation errors it throws at me), i am not very good at >> programing with python atm, so any help would be appreiciated. and if im >> missing somethign please feel free to throw >> any suggestions out there. >> > > Is this your *actual* code? It does not even compile... > Things like 'def foo(...):' are *functions*, not *modules*. > > Variables inside functions (including its arguments) are locals, private to > the function. Even if you modify them, the "outside world" doesn't notice. > So a function like this: > > def fight(HP, ZHP, weapon, boss=False): >> if weapon == 'fist': >> while HP > 0 and ZHP > 0: >> damage = 2 >> ZHP = ZHP - damage >> if boss: >> HP = HP - dice_roll2() >> else: >> HP = HP - 2 >> elif weapon == 'baseball bat': >> > [... more code ...] > > won't alter the "global" values HP, ZHP; in fact, it won't do nothing. > > Either return the new values: > return HP, ZHP > and also adjust everywhere you call: > HP, ZHP = fight(HP, ZHP, ...) > > Or mark HP, ZHP as globals (using the global statement). > > -- > Gabriel Genellina > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Mon Feb 23 04:21:53 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 23 Feb 2009 07:21:53 -0200 Subject: Is there a way to ask a class what its metaclasses are ? References: <7F0503CD69378F49BE0DC30661C6CCF60E68800F@enbmail01.lsi.com> <50697b2c0902191258ye5aa478gecaf7b7b097e3eba@mail.gmail.com> <7F0503CD69378F49BE0DC30661C6CCF62783D662@enbmail01.lsi.com> <50697b2c0902220147y4c8dbf94j1415aae9ee7d640@mail.gmail.com> <7F0503CD69378F49BE0DC30661C6CCF62783D673@enbmail01.lsi.com> <50697b2c0902220357g762fe390q6535079d42f6afb0@mail.gmail.com> <7F0503CD69378F49BE0DC30661C6CCF62783D685@enbmail01.lsi.com> <50697b2c0902221211k3be5f797k5f0419179864ae4f@mail.gmail.com> <7F0503CD69378F49BE0DC30661C6CCF659FDEDBD@enbmail01.lsi.com> Message-ID: En Mon, 23 Feb 2009 06:09:44 -0200, Barak, Ron escribi?: >> > I'm asking, because, even subclassing from object, viz.: >> > >> > class CopyAndPaste(object): >> > def __init__(self): >> > pass >> > ... >> > >> > Still gives me: >> > >> > $ python -u ./failover_pickle_demo09.py Traceback (most recent call >> > last): >> > File "./failover_pickle_demo09.py", line 321, in >> > class ListControlMeta(wx.Frame, CopyAndPaste): >> > TypeError: Error when calling the metaclass bases >> > metaclass conflict: the metaclass of a derived class must be a >> > (non-strict) subclass of the metaclasses of all its bases This works fine for me with Python 2.5 and wx 2.8.7.1; Python 2.4 and wx 2.6.1.0; even if CopyAndPaste is an old-style class. import wx class CopyAndPaste(object): pass class ListControl(wx.Frame, CopyAndPaste): pass app = wx.App() frame = ListControl(None) frame.Show(True) app.MainLoop() You'll have to provide more info on your setup... -- Gabriel Genellina From nick at craig-wood.com Mon Feb 23 04:32:00 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Mon, 23 Feb 2009 03:32:00 -0600 Subject: can multi-core improve single funciton? References: <6a4f17690902092228i31fd1661n41c61c4037a289df@mail.gmail.com> <64c334d7-434f-4ec3-8ccb-35e8088a0cb2@u13g2000yqg.googlegroups.com> Message-ID: sturlamolden wrote: > On Feb 10, 8:38?am, Paul McGuire wrote: > > > Even worse than linear, the function is recursive, which as I > > understand it, is inherently a no-no when looking for code that is > > parallel-friendly. > > There is no way to parallelize Fibonacci numbers computed with linear > time complexity, as we must know fib(n-1) to compute fib(n). But if we > were to use Oyster's recursive version, which has geometric > complexity, one could parallelize with a 'forkjoin' scheme. > > Anyhow, this runs in amortized linear time and would be a lot faster: > > def fib(n): > while True: > try: > return fib.seq[n] > except AttributeError: > fib.seq = [0, 1, 1] > except IndexError: > fib.seq.append( fib.seq[-2] + > fib.seq[-1] ) Or something which runs in O(1)... from gmpy import mpf, mpz, digits from math import log, sqrt root5_float = sqrt(5) phi_float = (1 + root5_float) / 2 log_phi_float = log(phi_float) log_root5_float = log(root5_float) log2 = log(2) def fibonacci_noniterative(n): """ Work out n'th Fibonacci number in an noniterative fashion using Binet's formula """ # Work out magnitude of answer bits = int(((n * log_phi_float - log_root5_float) / log2)*1.1) if bits < 0: bits = 0 root5 = mpf(5, bits).sqrt() phi = (mpf(1, bits) + root5) / mpf(2, bits) f_n = phi**n / root5 f_n = mpz(f_n + mpf(1, bits) / mpf(2, bits)) return long(f_n) It runs in O(1) if the O we are talking about is large integer arithmetic. It actually runs in more like O(log(n)**1.5) time. It is a lot faster than the iterative approach too which runs in O(log(n)**2) for any n > ~40. Times to calculate F(n) n, iterative, noniterative 1, 0.000003, 0.000016 2, 0.000003, 0.000014 4, 0.000003, 0.000012 8, 0.000003, 0.000016 16, 0.000004, 0.000009 32, 0.000007, 0.000010 64, 0.000014, 0.000010 128, 0.000032, 0.000011 256, 0.000072, 0.000014 512, 0.000157, 0.000019 1024, 0.000361, 0.000031 2048, 0.000881, 0.000066 4096, 0.002504, 0.000178 8192, 0.007640, 0.000521 16384, 0.025362, 0.001572 32768, 0.090633, 0.004701 65536, 0.342724, 0.014132 131072, 1.335723, 0.045194 262144, 5.273360, 0.111201 524288, 20.791205, 0.301488 1048576, 82.617938, 0.833644 Here is the rest of the program just in case anyone wants to play def fibonacci_iterative(n): """ Work out n'th Fibonacci number in an iterative fashion """ a, b = 0, 1 while n > 0: a, b = a + b, a n -= 1 return a if __name__ == "__main__": # warmup fibonacci_noniterative(100) print " n, iterative, noniterative" for e in range(30): i = 2 ** e t0 = time() f_iterative = fibonacci_iterative(i) t_iterative = time() - t0 t0 = time() f_noniterative = fibonacci_noniterative(i) t_noniterative = time() - t0 print "%10d, %10.6f, %10.6f" % (i, t_iterative, t_noniterative) if f_iterative != f_noniterative: print "Calculation error" print "iterative", f_iterative print "non iterative", f_noniterative print "difference", f_iterative-f_noniterative -- Nick Craig-Wood -- http://www.craig-wood.com/nick From Ron.Barak at lsi.com Mon Feb 23 04:32:52 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Mon, 23 Feb 2009 09:32:52 +0000 Subject: Metaclass conflict TypeError exception: problem demonstration script In-Reply-To: <20090222145717.787F04A136E@riobu.com> References: <20090222145717.787F04A136E@riobu.com> Message-ID: <7F0503CD69378F49BE0DC30661C6CCF659FDEDD5@enbmail01.lsi.com> Hi Guys, Thanks to Michele, Chris, Hrvoje et. al. who helped me trying to resolve the metaclass exception when a class has two parents problem. This post tries to unify all the metaclasses exception threads, in an attempt to reach a solution. I've created a short demo script (metaclass_test01.py) that demonstrate the problem. Listings of metaclass_test01.py and CopyAndPaste are below and attached. Note: When line 8 in metaclass_test01.py is in effect (with line 7 commented out), the script runs normally. However, when line 7 is in effect (with line 8 commented out), viz.: $ cat -n metaclass_test01.py | head 1 #!/usr/bin/env python 2 3 import sys 4 import wx 5 import CopyAndPaste 6 7 class ListControl(wx.Frame, CopyAndPaste): 8 #class ListControl(wx.Frame): 9 def __init__(self, parent, id, title, list, max_list_width): 10 wx.Frame.__init__(self,parent,id,title,size=(-1,-1), style=wx.DEFAULT_FRAME_STYLE) I get the metaclass conflict exception: $ python metaclass_test01.py Traceback (most recent call last): File "metaclass_test01.py", line 7, in class ListControl(wx.Frame, CopyAndPaste): TypeError: Error when calling the metaclass bases metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases I hope that now the problem is demonstrated more clearly, and the gurus out there could point me in the right direction towards a solution. Bye, Ron. ________________________________ $ cat -n metaclass_test01.py 1 #!/usr/bin/env python 2 3 import sys 4 import wx 5 import CopyAndPaste 6 7 #class ListControl(wx.Frame, CopyAndPaste): 8 class ListControl(wx.Frame): 9 def __init__(self, parent, id, title, list, max_list_width): 10 wx.Frame.__init__(self,parent,id,title,size=(-1,-1), style=wx.DEFAULT_FRAME_STYLE) 11 self.list = list 12 self.list_ctrl = wx.ListCtrl(self, -1, style=wx.LC_REPORT| wx.LC_NO_HEADER) 13 self.list_ctrl.InsertColumn(0, title) 14 for i,line_ in enumerate(list): 15 self.list_ctrl.InsertStringItem(i, line_) 16 self.list_ctrl.SetColumnWidth(0, max_list_width) 17 18 self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self.list_ctrl) 19 20 self.Raise() 21 self.Show(True) 22 23 def OnItemSelected(self, evt): 24 item = evt.GetText() 25 max_list_width = 10 * len(item) 26 ListControl(self, -1, item, item, max_list_width) 27 28 if __name__ == "__main__": 29 list = [ "First Line", "Second Line", "Third Line"] 30 app = wx.App(redirect=False) 31 max_list_width = 6 * max([len(x) for x in list]) 32 ListControl(None, -1, "Parent Window", list, max_list_width) 33 app.MainLoop() ________________________________ $ cat -n CopyAndPaste.py 1 #!/usr/bin/env python 2 3 import wx 4 5 class CopyAndPaste(object): 6 7 def __init__(self): 8 pass 9 10 def set_copy_and_paste(self): 11 """ 12 Setting clipboard copy-and-pasting (only copying from the application to the 13 clipboard is supported). 14 The "menu" menu is hidden, and is only there to facilitate the acceleration table. 15 Both CTRL-C and CTRL-Ins are supported. 16 """ 17 menu = wx.Menu() 18 copy_ = menu.Append(-1, "&Copy\tCtrl-Ins") # Copy with accelerator 19 minimize_ = menu.Append(-1, "Minimize") # 20 close_ = menu.Append(-1, "Close window\tCtrl-W") # Close window 21 exit_ = menu.Append(-1, "E&xit application\tCtrl-X") # Close window 22 23 self.Bind(wx.EVT_MENU, self.on_copy, copy_) 24 self.Bind(wx.EVT_MENU, self.on_minimize, minimize_) 25 self.Bind(wx.EVT_MENU, self.on_close, close_) 26 self.Bind(wx.EVT_MENU, self.on_exit, exit_) 27 28 menuBar = wx.MenuBar() 29 self.SetMenuBar(menuBar) 30 31 acceltbl = wx.AcceleratorTable( [ 32 (wx.ACCEL_CTRL, ord('C'), copy_.GetId()), 33 (wx.ACCEL_CTRL, ord('W'), close_.GetId()), 34 (wx.ACCEL_CTRL, ord('X'), exit_.GetId()), 35 (wx.ACCEL_CTRL, ord('Q'), exit_.GetId()), 36 (wx.ACCEL_CTRL, wx.WXK_INSERT, copy_.GetId()), 37 (wx.ACCEL_CTRL, wx.WXK_NUMPAD_INSERT, copy_.GetId()), 38 ]) 39 self.SetAcceleratorTable(acceltbl) 40 41 # Setting popup menu 42 43 self.popupmenu = menu 44 self.Bind(wx.EVT_CONTEXT_MENU, self.on_show_popup) 45 46 def on_show_popup(self, evt): 47 pos = evt.GetPosition() 48 pos = self.list_ctrl.ScreenToClient(pos) 49 self.PopupMenu(self.popupmenu, pos) 50 51 def get_data_for_clipboard(self,format="text"): 52 """ 53 Return data ready to be copied to the clipboard. 54 55 This is an abstract method - concrete subclasses must override this. 56 57 Sample implementation of get_data_for_clipboard() is: 58 59 def get_data_for_clipboard(self,format="text"): 60 first_selected = self.list_ctrl.GetFirstSelected() 61 selected_item_count = self.list_ctrl.GetSelectedItemCount() 62 text_for_clipboard = "" 63 for i in range(first_selected,first_selected+selected_item_count): 64 text_for_clipboard = "%s%s\n" % (text_for_clipboard, self.list_ctrl.GetItemText(i)) 65 return(text_for_clipboard) 66 """ 67 raise NotImplementedError 68 69 def on_copy(self, evt): 70 """ 71 """ 72 text_for_clipboard = self.get_data_for_clipboard() 73 74 data = wx.TextDataObject() 75 data.SetText(text_for_clipboard) 76 if wx.TheClipboard.Open(): 77 wx.TheClipboard.SetData(data) 78 wx.TheClipboard.Close() 79 else: 80 wx.MessageBox("Unable to copy to the clipboard", "Error") 81 82 def on_minimize(self, evt): 83 self.Iconize() 84 85 def on_close(self, evt): 86 self.Close() 87 88 def on_exit(self, evt): 89 try: 90 self.Parent.Close() 91 except AttributeError: 92 self.Close() 93 94 95 if __name__ == "__main__": 96 97 app = wx.App(redirect=False) 98 copy_and_paste = CopyAndPaste() 99 app.MainLoop() 100 ________________________________ -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: metaclass_test01.py Type: application/octet-stream Size: 1148 bytes Desc: metaclass_test01.py URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: CopyAndPaste.py Type: application/octet-stream Size: 3288 bytes Desc: CopyAndPaste.py URL: From mail at timgolden.me.uk Mon Feb 23 04:36:36 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 23 Feb 2009 09:36:36 +0000 Subject: Metaclass conflict TypeError exception: problem demonstration script In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF659FDEDD5@enbmail01.lsi.com> References: <20090222145717.787F04A136E@riobu.com> <7F0503CD69378F49BE0DC30661C6CCF659FDEDD5@enbmail01.lsi.com> Message-ID: <49A26E24.5060602@timgolden.me.uk> > $ cat -n metaclass_test01.py | head > 1 #!/usr/bin/env python > 2 > 3 import sys > 4 import wx > 5 import CopyAndPaste > 6 > 7 class ListControl(wx.Frame, CopyAndPaste): > 8 #class ListControl(wx.Frame): > 9 def __init__(self, parent, id, title, list, max_list_width): > 10 wx.Frame.__init__(self,parent,id,title,size=(-1,-1), style=wx.DEFAULT_FRAME_STYLE) > > I get the metaclass conflict exception: You're trying to use a module as a base class. Don't do that; it doesn't work. TJG From gagsl-py2 at yahoo.com.ar Mon Feb 23 04:38:43 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 23 Feb 2009 07:38:43 -0200 Subject: Metaclass conflict TypeError exception: problem demonstration script References: <20090222145717.787F04A136E@riobu.com> <7F0503CD69378F49BE0DC30661C6CCF659FDEDD5@enbmail01.lsi.com> Message-ID: En Mon, 23 Feb 2009 07:32:52 -0200, Barak, Ron escribi?: > $ cat -n metaclass_test01.py | head > 1 #!/usr/bin/env python > 2 > 3 import sys > 4 import wx > 5 import CopyAndPaste > 6 > 7 class ListControl(wx.Frame, CopyAndPaste): > 8 #class ListControl(wx.Frame): > 9 def __init__(self, parent, id, title, list, max_list_width): > 10 wx.Frame.__init__(self,parent,id,title,size=(-1,-1), > style=wx.DEFAULT_FRAME_STYLE) > > I get the metaclass conflict exception: > > $ python metaclass_test01.py > Traceback (most recent call last): > File "metaclass_test01.py", line 7, in > class ListControl(wx.Frame, CopyAndPaste): > TypeError: Error when calling the metaclass bases > metaclass conflict: the metaclass of a derived class must be a > (non-strict) subclass of the metaclasses of all its bases > > I hope that now the problem is demonstrated more clearly, and the gurus > out there could point me in the right direction towards a solution. You want the CopyAndPaste *class*, not the *module*! -- Gabriel Genellina From jonas.esp at googlemail.com Mon Feb 23 04:40:47 2009 From: jonas.esp at googlemail.com (Kless) Date: Mon, 23 Feb 2009 01:40:47 -0800 (PST) Subject: Access from class variable to one on constructor Message-ID: <1c006a1c-83e1-47fa-bf54-f458e98b484c@h5g2000yqh.googlegroups.com> How to access from a class variable to one that is initialized on the constructor? -------------- class Foo(): foo = bar # I want to access *from here* to variables created on the constructor. def __init__(self, bar_init): self.bar = bar_init -------------- Note: I've to create a subclass where the parent class to get variables using *for i in dir(self): * so it doesn't get variables initialized on the constructor. From stef.mientki at gmail.com Mon Feb 23 04:57:05 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Mon, 23 Feb 2009 10:57:05 +0100 Subject: can error messages be improved or can they be overridden ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF62783D690@enbmail01.lsi.com> References: <49A1567B.5020407@gmail.com> <7F0503CD69378F49BE0DC30661C6CCF62783D690@enbmail01.lsi.com> Message-ID: <49A272F1.7090004@gmail.com> thanks Ron, but I was looking for a more general solution, in which I don't change the program itself, and where the error messages (in general) become more informative than it is by default. cheers, Stef Barak, Ron wrote: > Hi Stef, > > You can do something like (not tested): > > try: > self.Brick.Par [ self.EP[2] ]['FileName'] = filename > except IndexError,e: > msg = "%s: '%s %s %s %d" % (e.strerror,e.filename,self.EP,self.EP[2],len(self.Brick.Par)) > print msg > > Bye, > Ron. > > >> -----Original Message----- >> From: Stef Mientki [mailto:stef.mientki at gmail.com] >> Sent: Sunday, February 22, 2009 15:43 >> To: python-list at python.org >> Subject: can error messages be improved or can they be overridden ? >> >> hello, >> >> I often get an error message like this >> >> self.Brick.Par [ self.EP[2] ]['FileName'] = filename >> IndexError: list index out of range >> >> Now it would be very welcome, >> if the error message specified which index is out of range, >> in this case e.g., >> - specifying the length of self.EP >> - specifying the value of self.EP[2] >> - specifying the length of self.Brick.Par etc.. >> >> Is there a way to override the error message and provide this >> information, or is it impossible ? >> >> And if it's possible, am I the only one who often stumbles >> about this problem ? >> (I expect many people must have bounced in this problem before me ;-) >> >> thanks, >> Stef Mientki >> >> >> From gagsl-py2 at yahoo.com.ar Mon Feb 23 04:57:18 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 23 Feb 2009 07:57:18 -0200 Subject: different errors, return outside function and others References: Message-ID: En Mon, 23 Feb 2009 07:07:57 -0200, Tony escribi?: > ok thank you for that input, this is my first class in programming and > its > the only one the school offers. im pretty sure those are supposed to be > modules > that im writting. would it make a difference if those were modules and > not > functions? kinda stupid question there but im trying to learn as much as > possible. Each module is a separate file, with extension .py If you put all your code in a single file, you write a single module. That's fine in this case, unless it grows to something unmanageable. Functions are blocks of code that have a name and "do" something specific, and usually return some result. They start with the keyword "def". You have defined several functions already, but called them "modules" in the comments, that's wrong and may be confusing. > Also anything with def infront of it example def start(): would be a > function correct? also im Using 2.5 and the IDLE to do this Exactly! I think you have written so much code without testing it. It's time to test every piece now. Start with... the start function, obviously! But before, you have to clean your code. There are a few strange lines that should not be there (all those lines on the left margin that aren't "def" statements, like intro_area(), alley()...). Just remove or comment them. Then you can start testing each function, one at a time. Simply call the function with the desired parameters (if any), right at the bottom of the file. To test the first one (start), use something like this: print "about to call start()" result = start() print "start() finished, result=", result and do the same for each individual function. Once you know each piece works fine, you can start combining them until you build the complete program. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Mon Feb 23 05:02:17 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 23 Feb 2009 08:02:17 -0200 Subject: Access from class variable to one on constructor References: <1c006a1c-83e1-47fa-bf54-f458e98b484c@h5g2000yqh.googlegroups.com> Message-ID: En Mon, 23 Feb 2009 07:40:47 -0200, Kless escribi?: > How to access from a class variable to one that is initialized on the > constructor? > -------------- > class Foo(): > foo = bar # I want to access *from here* to variables created on > the constructor. > > def __init__(self, bar_init): > self.bar = bar_init > -------------- Unless I misunderstand you, you can't do that. Class variables are shared by all instances and don't depend on a particular instance - they exist even *before* any instance is created. > Note: I've to create a subclass where the parent class to get > variables using *for i in dir(self): * so it doesn't get variables > initialized on the constructor. This part I don't understand at all. Perhaps a concrete example, showing what you actually want at the end? -- Gabriel Genellina From gabriel.rossetti at arimaz.com Mon Feb 23 05:10:16 2009 From: gabriel.rossetti at arimaz.com (Gabriel Rossetti) Date: Mon, 23 Feb 2009 11:10:16 +0100 Subject: shared lib from python code? Message-ID: <49A27608.3050403@arimaz.com> Hello everyone, I would like to know if it is possible to turn python code into a shared lib? I have several processes that use the same base code, and it seems like every process loads the "shared" code into memory. I would like it to be loaded once and shared, like a .so in linux or a .dll in windows and have the interpreters use the dared copy. Is there a way to do this? Thank you, Gabriel From jonas.esp at googlemail.com Mon Feb 23 05:17:52 2009 From: jonas.esp at googlemail.com (Kless) Date: Mon, 23 Feb 2009 02:17:52 -0800 (PST) Subject: Get variables on constructor Message-ID: <0185d001-203d-4aa3-abe7-5674997f8428@t13g2000yqc.googlegroups.com> To get class variables can be used *for i in dir(self): * but how to get variables initialized on the constructor? From http Mon Feb 23 05:37:49 2009 From: http (Paul Rubin) Date: 23 Feb 2009 02:37:49 -0800 Subject: shared lib from python code? References: Message-ID: <7x63j1v3pe.fsf@ruckus.brouhaha.com> Gabriel Rossetti writes: > I would like to know if it is possible to turn python code into a > shared lib? I have several processes that use the same base code, and > it seems like every process loads the "shared" code into memory. I > would like it to be loaded once and shared, like a .so in linux or a > .dll in windows and have the interpreters use the dared copy. Is there > a way to do this? I guess it's not completely inconceivable--Emacs used something called unexec back in the day, that transmogrified part of its data segment into the text segment and dumped it out as a runnable binary--but it doesn't seem worth it nowadays, given how small your .pyc's are likely to be relative to the size of memory. If you're concerned about the import overhead, maybe you can structure your program as a persistent process instead of re-running it all the time. From jonas.esp at googlemail.com Mon Feb 23 05:38:30 2009 From: jonas.esp at googlemail.com (Kless) Date: Mon, 23 Feb 2009 02:38:30 -0800 (PST) Subject: Get variables on constructor [Solved] References: <0185d001-203d-4aa3-abe7-5674997f8428@t13g2000yqc.googlegroups.com> Message-ID: On 23 feb, 10:17, Kless wrote: > To get class variables can be used *for i in dir(self): * but how to > get variables initialized on the constructor? Sorry. It's so simple as insert *self*. From jonas.esp at googlemail.com Mon Feb 23 05:48:19 2009 From: jonas.esp at googlemail.com (Kless) Date: Mon, 23 Feb 2009 02:48:19 -0800 (PST) Subject: Access from class variable to one on constructor [Solved] References: <1c006a1c-83e1-47fa-bf54-f458e98b484c@h5g2000yqh.googlegroups.com> Message-ID: <96d9815a-61c8-4745-94b8-532fd0489b7e@v42g2000yqj.googlegroups.com> Thanks Gabriel. You have reason, and I was having a design error. On 23 feb, 10:02, "Gabriel Genellina" wrote: > En Mon, 23 Feb 2009 07:40:47 -0200, Kless ? > escribi?: > > > How to access from a class variable to one that is initialized on the > > constructor? > > -------------- > > class Foo(): > > ? foo = bar ?# I want to access *from here* to variables created on > > the constructor. > > > ? def __init__(self, bar_init): > > ? ? self.bar = bar_init > > -------------- > > Unless I misunderstand you, you can't do that. Class variables are shared ? > by all instances and don't depend on a particular instance - they exist ? > even *before* any instance is created. > > > Note: I've to create a subclass where the parent class to get > > variables using *for i in dir(self): * so it doesn't get variables > > initialized on the constructor. > > This part I don't understand at all. Perhaps a concrete example, showing ? > what you actually want at the end? > > -- > Gabriel Genellina From gagsl-py2 at yahoo.com.ar Mon Feb 23 05:48:49 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 23 Feb 2009 08:48:49 -0200 Subject: shared lib from python code? References: <49A27608.3050403@arimaz.com> Message-ID: En Mon, 23 Feb 2009 08:10:16 -0200, Gabriel Rossetti escribi?: > I would like to know if it is possible to turn python code into a shared > lib? I have several processes that use the same base code, and it seems > like every process loads the "shared" code into memory. I would like it > to be loaded once and shared, like a .so in linux or a .dll in windows > and have the interpreters use the dared copy. Is there a way to do this? I don't think so. What you consider "code" isn't usually just code: there are functions, classes, instances, constants, modules, docstrings... a myriad of objects. You can't share objects between processes. Although true code objects are immutable and *could* be shared (with a lot of work), I don't think code objects actually could take so much memory as to be a problem. -- Gabriel Genellina From andrew at acooke.org Mon Feb 23 06:14:34 2009 From: andrew at acooke.org (andrew cooke) Date: Mon, 23 Feb 2009 08:14:34 -0300 (CLST) Subject: Reference or Value? In-Reply-To: References: Message-ID: <21425a030186ab9c40012a19048b4f92.squirrel@localhost> Steven D'Aprano wrote: > On Sun, 22 Feb 2009 13:37:27 -0300, andrew cooke wrote: > >> as far as i understand things, the best model is: >> >> 1 - everything is an object >> 2 - everything is passed by reference > > Except that is wrong. If it were true, you could do this: [pointer swapping] i was thinking of how the stack is used; i would have called what you are talking about "pointer semantics". however, on reading around a little, it seems that i'm in a very small minority (which is a pity, because if you restrict the meaning to how values are handled on the stack then you get a lot closer to having just values and references, rather than the whole pile of different terms that are apparently in use). sorry for the confusion, andrew From greg.ewing at canterbury.ac.nz Mon Feb 23 06:31:29 2009 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Tue, 24 Feb 2009 00:31:29 +1300 Subject: ANN: SuPy 1.5 Message-ID: SuPy 1.5 Available ------------------ http://www.cosc.canterbury.ac.nz/greg.ewing/SuPy/ New in this version: - Tool and Observer classes can be implemented in Python - Contextual menu facilities - Modifier key and status bar constants - to_length() function - dir() works on Ruby classes What is SuPy? ------------- SuPy is a plugin for the Sketchup 3D modelling application that lets you script it in Python. -- Greg Ewing greg.ewing at canterbury.ac.nz From gabriel.rossetti at arimaz.com Mon Feb 23 06:43:18 2009 From: gabriel.rossetti at arimaz.com (Gabriel Rossetti) Date: Mon, 23 Feb 2009 12:43:18 +0100 Subject: shared lib from python code? In-Reply-To: <49A27608.3050403@arimaz.com> References: <49A27608.3050403@arimaz.com> Message-ID: <49A28BD6.9040701@arimaz.com> Gabriel Rossetti wrote: > Hello everyone, > > I would like to know if it is possible to turn python code into a > shared lib? I have several processes that use the same base code, and > it seems like every process loads the "shared" code into memory. I > would like it to be loaded once and shared, like a .so in linux or a > .dll in windows and have the interpreters use the dared copy. Is there > a way to do this? > > Thank you, > Gabriel > Ok, maybe I mis-stated my problem (or mis-understood your answers).. I don' t want to share code as in have multiple processes access a variable and have the same value, like it is done in threads, what I want is to not have n copies of the code (classes, functions, etc) loaded by n python interpreters. When you load Apache for instance, it runs n processes but loads only one copy of parts of it's code (so/dll), that's what I want to do. In C/C++ I would write a shared-lib (so/dll), so once the system has loaded it, it doesn' t re-load it when another process needs it. Thank you, Gabriel From mark.dufour at gmail.com Mon Feb 23 06:54:17 2009 From: mark.dufour at gmail.com (Mark Dufour) Date: Mon, 23 Feb 2009 12:54:17 +0100 Subject: ANN: Shed Skin 0.1, an experimental (restricted-)Python-to-C++ Compiler Message-ID: <8180ef690902230354x39ec002cn8d6f229a8f45603a@mail.gmail.com> Hi all, I have recently released version 0.1 of Shed Skin, an experimental (restricted-)Python-to-C++ compiler. Please see my blog for more info about the release: http://shed-skin.blogspot.com Thanks, Mark Dufour. -- "One of my most productive days was throwing away 1000 lines of code" - Ken Thompson From nytrokiss at gmail.com Mon Feb 23 07:25:52 2009 From: nytrokiss at gmail.com (James Matthews) Date: Mon, 23 Feb 2009 14:25:52 +0200 Subject: ANN: Shed Skin 0.1, an experimental (restricted-)Python-to-C++ Compiler In-Reply-To: <8180ef690902230354x39ec002cn8d6f229a8f45603a@mail.gmail.com> References: <8180ef690902230354x39ec002cn8d6f229a8f45603a@mail.gmail.com> Message-ID: <8a6b8e350902230425x1176afa3ge7001e21013ce001@mail.gmail.com> Nice! I was looking for one of these for a while On Mon, Feb 23, 2009 at 1:54 PM, Mark Dufour wrote: > Hi all, > > I have recently released version 0.1 of Shed Skin, an experimental > (restricted-)Python-to-C++ compiler. > > Please see my blog for more info about the release: > > http://shed-skin.blogspot.com > > > Thanks, > Mark Dufour. > -- > "One of my most productive days was throwing away 1000 lines of code" > - Ken Thompson > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://www.astorandblack.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From ccormie at aussiemail.com.au Mon Feb 23 07:41:20 2009 From: ccormie at aussiemail.com.au (Chris Cormie) Date: Mon, 23 Feb 2009 23:41:20 +1100 Subject: How does one get from "ImportError: DLL load failed:..." to a culprit .dll and symbol? In-Reply-To: <5850dc46-638f-4a3c-8d9a-f84bf7523979@o11g2000yql.googlegroups.com> References: <01b213c7$0$20626$c3e8da3@news.astraweb.com> <5850dc46-638f-4a3c-8d9a-f84bf7523979@o11g2000yql.googlegroups.com> Message-ID: <01b28edb$0$20619$c3e8da3@news.astraweb.com> > If that not-very-technical description [all I've ever needed] doesn't > help, you'll need to read the DW help file (HTFF1K) or wait till > someone who knows what they are doing comes along :-) LOL, I am that person :p Your technique works well and it does provide the information and it is a (roundabout) solution to this class of problems: thank you very much. It doesn't answer the original question so I'll restate it: How do you get *Python* to tell you the dll and the problem symbol? Not external tools, Python. Python at a low level is calling LoadLibrary and GetProcAddress to resolve symbols and the call fails. At that point it has the name of the dll and the problem symbol to hand and yet strangely only gives an opaque error message. How does one get Python to print out the faulty DLL and symbol? (Even if it means a debug build of Python and adding the printf yourself, I just want to know where we stand on this issue! :) ) Best Regards, Chris From koranthala at gmail.com Mon Feb 23 07:42:23 2009 From: koranthala at gmail.com (koranthala) Date: Mon, 23 Feb 2009 04:42:23 -0800 (PST) Subject: Server programming Message-ID: Hi, Is server programming in Python procedure oriented or object oriented? I have this question because lately I am asked to make a medium complex web program (extremely database oriented) using Django. When I used to do application programs earlier (in Python itself), the whole thing being object oriented came out easily in programming. So, I was able to use different patterns etc for programming and the whole thing was - quite fun to design and create. But when I program in Django, since I just have to work on user responses - everything else being taken care of by Django - only, the complete coding has become procedure oriented. It is not kludgy or anything, but it doesnt have the nice feeling that we get when we code a proper object oriented program. Is my coding in error here? This is infact my first web program, so it might be the reason. What does other people find? Does web server programming using web frameworks (Django, TurboGears etc) make it procedure oriented? If I am in the wrong, it might be due to a wrong design or mindset, and I would like to change it. From see_website at mindprod.com.invalid Mon Feb 23 07:56:54 2009 From: see_website at mindprod.com.invalid (Roedy Green) Date: Mon, 23 Feb 2009 04:56:54 -0800 Subject: programming by evolution? References: <42a2e3fc-ec2e-4c09-b456-95a5fc4ce5a2@g39g2000pri.googlegroups.com> <6uuc4eFhc1u1U1@mid.individual.net> <11809792-676f-4d95-87c1-26666cc46b3b@w24g2000prd.googlegroups.com> <03db1c69-828a-4961-914d-62fe10ed88fb@w39g2000prb.googlegroups.com> Message-ID: On 19 Feb 2009 18:56:42 GMT, Albert van der Horst wrote, quoted or indirectly quoted someone who said : >Note here, that eXtreme >>Programing is one of the snake oil, Extreme programming is a variant on Deming's idea of constant incremental improvement that revolutionised quality in manufacturing. It is also based on the obvious idea that you will be smarter after you have used some version of a program than you are today. There are so many computer programs perfectly compliant with specs that looked good on paper but nobody ever tested with actual use to refine them until the project was "complete" and it was too expensive to fix them. -- Roedy Green Canadian Mind Products http://mindprod.com One path leads to despair and utter hopelessness. The other, to total extinction. Let us pray we have the wisdom to choose correctly. ~ Woody Allen . From alwaseem307ster at yahoo.com Mon Feb 23 08:03:13 2009 From: alwaseem307ster at yahoo.com (klia) Date: Mon, 23 Feb 2009 05:03:13 -0800 (PST) Subject: pysqlite smart search In-Reply-To: <22157116.post@talk.nabble.com> References: <22157116.post@talk.nabble.com> Message-ID: <22161119.post@talk.nabble.com> klia wrote: > > Hey guys; > > I am trying to develop a tiny program using python to search inside sqlite > database with file extension is .db in which the program will ask users to > enter their search query and base on that it will retrieve the results But > > I need the program to have some smartness in search mechanism in which the > program will guess that the user is looking for these key words in the > database. > > so far i came up with this but the search ain't smart, i have to write the > full key word in order to retrieve specific information. > > from pysqlite2 import dbapi2 as sqlite3 > > connection = sqlite3.connect('Photos.db') > memoryConnection = sqlite3.connect(':memory:') > cursor = connection.cursor() > prompt = 'Enter your search query?\n' > keyword = raw_input(prompt) > if cursor.execute('SELECT * FROM photos WHERE Tag LIKE ?',[keyword]): > print cursor.fetchall() > else: > cursor.execute('SELECT * FROM photos WHERE Date LIKE ?', [keyword]) > print cursor.fetchall() > > Any ideas and > thanks in advance > Reply > thank you man, it worked perfectly but one more thing; when i print rows it retrieves the whole rows of info which i don't need, i need just to retrieve the name of the photo. so how am i gonna do that? -- View this message in context: http://www.nabble.com/pysqlite-smart-search-tp22157116p22161119.html Sent from the Python - python-list mailing list archive at Nabble.com. From sjmachin at lexicon.net Mon Feb 23 08:05:49 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 23 Feb 2009 05:05:49 -0800 (PST) Subject: How does one get from "ImportError: DLL load failed:..." to a culprit .dll and symbol? References: <01b213c7$0$20626$c3e8da3@news.astraweb.com> <5850dc46-638f-4a3c-8d9a-f84bf7523979@o11g2000yql.googlegroups.com> <01b28edb$0$20619$c3e8da3@news.astraweb.com> Message-ID: <5daf9b18-eb79-450b-803e-c6bd4f73e145@r41g2000yqm.googlegroups.com> On Feb 23, 11:41?pm, Chris Cormie wrote: > > If that not-very-technical description [all I've ever needed] doesn't > > help, you'll need to read the DW help file (HTFF1K) or wait till > > someone who knows what they are doing comes along :-) > > LOL, I am that person :p It wasn't apparent, and still isn't. > Your technique works well and it does provide the information and it is > a (roundabout) solution to this class of problems: ?thank you very much. > It doesn't answer the original question so I'll restate it: > > How do you get *Python* to tell you the dll and the problem symbol? Not > external tools, Python. Python at a low level is calling LoadLibrary and > GetProcAddress to resolve symbols and the call fails. At that point it > has the name of the dll and the problem symbol to hand and yet strangely > only gives an opaque error message. How does one get Python to print out > the faulty DLL and symbol? If you know all that, then the answer is to submit a patch, isn't it?? > (Even if it means a debug build of Python and adding the printf > yourself, printf? Maybe you shouldn't submit a patch after all. From duncan.booth at invalid.invalid Mon Feb 23 08:09:15 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 23 Feb 2009 13:09:15 GMT Subject: shared lib from python code? References: <49A27608.3050403@arimaz.com> Message-ID: Gabriel Rossetti wrote: > Ok, maybe I mis-stated my problem (or mis-understood your answers).. I > don' t want to share code as in have multiple processes access a > variable and have the same value, like it is done in threads, what I > want is to not have n copies of the code (classes, functions, etc) > loaded by n python interpreters. When you load Apache for instance, it > runs n processes but loads only one copy of parts of it's code (so/dll), > that's what I want to do. In C/C++ I would write a shared-lib (so/dll), > so once the system has loaded it, it doesn' t re-load it when another > process needs it. > It doesn't matter how you restate it, the answer is still the one Gabriel Genellina gave you: Python code objects are not shared between processes. Code objects are immutable, but they are still objects like everything else in Python. That means they are reference counted and discarded when no longer referenced. To share code objects between different processes you would have to change the reference counting mechanism so it was either safe across multiple processes or didn't reference count shared code objects (but still ref counted non-shared objects). The actual code is just stored in a string, so perhaps you could share those strings between processes: just executing the code doesn't change the string's refcount (whereas it does change the function and the code objects' counts). You could probably make something work simply by editing the code constructor to move the code into shared memory and using some other mechanism to control the shared memory storage. C extension libraries on the other hand may be shared. -- Duncan Booth http://kupuguy.blogspot.com From deets at nospam.web.de Mon Feb 23 08:10:49 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 23 Feb 2009 14:10:49 +0100 Subject: shared lib from python code? In-Reply-To: References: <49A27608.3050403@arimaz.com> Message-ID: <70flipF47gafU1@mid.uni-berlin.de> Gabriel Rossetti schrieb: > Gabriel Rossetti wrote: >> Hello everyone, >> >> I would like to know if it is possible to turn python code into a >> shared lib? I have several processes that use the same base code, and >> it seems like every process loads the "shared" code into memory. I >> would like it to be loaded once and shared, like a .so in linux or a >> .dll in windows and have the interpreters use the dared copy. Is there >> a way to do this? >> >> Thank you, >> Gabriel >> > Ok, maybe I mis-stated my problem (or mis-understood your answers).. I > don' t want to share code as in have multiple processes access a > variable and have the same value, like it is done in threads, what I > want is to not have n copies of the code (classes, functions, etc) > loaded by n python interpreters. When you load Apache for instance, it > runs n processes but loads only one copy of parts of it's code (so/dll), > that's what I want to do. In C/C++ I would write a shared-lib (so/dll), > so once the system has loaded it, it doesn' t re-load it when another > process needs it. This is not done, and most probably won't ever happen. What would you do with this? import random import foo if random.random() > .5: foo.some_function = lambda x: x ** 2 else: foo.some_function = lambda x: x + 2 If the module foo would be shared amongst processes, these would affect the code of each other. Not so nice. Of course one could try & cough up some read-only, copy-on-modify scheme, but that would be hard, if not impossible - and for rather minimal gains. Take a look at the compiled *.pyc-files (which should pretty much represent the memory they consume) - they are in the kbytes. So optimizing here would be a waste I'd say. Diez From gagsl-py2 at yahoo.com.ar Mon Feb 23 08:49:59 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 23 Feb 2009 11:49:59 -0200 Subject: How does one get from "ImportError: DLL load failed:..." to a culprit .dll and symbol? References: <01b213c7$0$20626$c3e8da3@news.astraweb.com> <5850dc46-638f-4a3c-8d9a-f84bf7523979@o11g2000yql.googlegroups.com> <01b28edb$0$20619$c3e8da3@news.astraweb.com> Message-ID: En Mon, 23 Feb 2009 10:41:20 -0200, Chris Cormie escribi?: >> If that not-very-technical description [all I've ever needed] doesn't >> help, you'll need to read the DW help file (HTFF1K) or wait till >> someone who knows what they are doing comes along :-) > > LOL, I am that person :p > Your technique works well and it does provide the information and it is > a (roundabout) solution to this class of problems: thank you very much. > It doesn't answer the original question so I'll restate it: > > How do you get *Python* to tell you the dll and the problem symbol? Not > external tools, Python. Python at a low level is calling LoadLibrary and > GetProcAddress to resolve symbols and the call fails. At that point it > has the name of the dll and the problem symbol to hand and yet strangely > only gives an opaque error message. How does one get Python to print out > the faulty DLL and symbol? You can't, because it isn't Python who's trying to load the symbol - the *only* symbol that Python attempts to import itself is "initFOO" from FOO.pyd, and when that fails you get an explicit message. The error you see must come from the extension itself, and propagates into Python as an ImportError. -- Gabriel Genellina From venutaurus539 at gmail.com Mon Feb 23 08:51:36 2009 From: venutaurus539 at gmail.com (venutaurus539 at gmail.com) Date: Mon, 23 Feb 2009 05:51:36 -0800 (PST) Subject: opening files with names in non-english characters. Message-ID: <5b6a03dc-0393-46e6-bff0-c36669a67340@w34g2000yqm.googlegroups.com> Hi all, I am trying to find the attributes of afile whose name has non english characters one like given below. When I try to run my python scirpt, it fails giving out an error filename must be in string or UNICODE. When i try to copy the name of the file as a strinig, it (KOMODO IDE) is not allowing me to save the script saying that it cannot convert some of the characters in the current encoding which is Western European(CP-1252). 0010testUnicode_???????????????????? !#$%&'()+,-. 0123456789;=@ABCD.txt.txt Hope some one could help me in this regard. Thank you in advance, Venu Madhav From cwitts at gmail.com Mon Feb 23 08:51:44 2009 From: cwitts at gmail.com (Chris) Date: Mon, 23 Feb 2009 05:51:44 -0800 (PST) Subject: can error messages be improved or can they be overridden ? References: <49A1567B.5020407@gmail.com> <7F0503CD69378F49BE0DC30661C6CCF62783D690@enbmail01.lsi.com> Message-ID: On Feb 23, 11:57?am, Stef Mientki wrote: > thanks Ron, > > but I was looking for a more general solution, > in which I don't change the program itself, > and where the error messages (in general) become more informative than > it is by default. > > cheers, > Stef > > Barak, Ron wrote: > > Hi Stef, > > > You can do something like (not tested): > > > try: > > ? ?self.Brick.Par [ self.EP[2] ]['FileName'] = filename > > except IndexError,e: > > ? ? ? ? ? ? ? ? msg = "%s: '%s %s %s %d" % (e.strerror,e.filename,self.EP,self.EP[2],len(self.Brick.Par)) > > ? ? ? ? ? ? ? ? print msg > > > Bye, > > Ron. > > >> -----Original Message----- > >> From: Stef Mientki [mailto:stef.mien... at gmail.com] > >> Sent: Sunday, February 22, 2009 15:43 > >> To: python-l... at python.org > >> Subject: can error messages be improved or can they be overridden ? > > >> hello, > > >> I often get an error message like this > > >> ? ? self.Brick.Par [ self.EP[2] ]['FileName'] = filename > >> IndexError: list index out of range > > >> Now it would be very welcome, > >> if the error message specified which index is out of range, > >> in this case e.g., > >> - specifying the length of self.EP > >> - specifying the value of self.EP[2] > >> - specifying the length of self.Brick.Par etc.. > > >> Is there a way to override the error message and provide this > >> information, or is it impossible ? > > >> And if it's possible, am I the only one who often stumbles > >> about this problem ? > >> (I expect many people must have bounced in this problem before me ;-) > > >> thanks, > >> Stef Mientki > > Why not something like this ? I know it requires changing your application but tbh I don't see any other way. try: self.Brick.Par [ self.EP[2] ]['FileName'] = filename except IndexError, msg: try: v = self.EP[2] try: v = self.Brick.Par[v] except IndexError: v = 'self.Brick.Par[%s] is out of range'%v except IndexError: v = 'self.EP[2] is out of range' raise IndexError(msg.message, v) From hniksic at xemacs.org Mon Feb 23 08:53:01 2009 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Mon, 23 Feb 2009 14:53:01 +0100 Subject: Metaclass conflict TypeError exception: problem demonstration script In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF659FDEDD5@enbmail01.lsi.com> (Ron Barak's message of "Mon\, 23 Feb 2009 09\:32\:52 +0000") References: <20090222145717.787F04A136E@riobu.com> <7F0503CD69378F49BE0DC30661C6CCF659FDEDD5@enbmail01.lsi.com> Message-ID: <87k57h8dky.fsf@mulj.homelinux.net> "Barak, Ron" writes: > However, when line 7 is in effect (with line 8 commented out), viz.: > > $ cat -n metaclass_test01.py | head > 1 #!/usr/bin/env python > 2 > 3 import sys > 4 import wx > 5 import CopyAndPaste > 6 > 7 class ListControl(wx.Frame, CopyAndPaste): If this is the actual source you're running, then CopyAndPaste is a module, not a type, and that causes the conflict. Use CopyAndPaste.CopyAndPaste, or change the import line to read "from CopyAndPaste import CopyAndPaste". Or, even better, adhere to recommendations laid down in PEP 8 and you'll avoid confusion between module and class names. From andrew at acooke.org Mon Feb 23 09:00:32 2009 From: andrew at acooke.org (andrew cooke) Date: Mon, 23 Feb 2009 11:00:32 -0300 (CLST) Subject: shared lib from python code? In-Reply-To: <49A28BD6.9040701@arimaz.com> References: <49A27608.3050403@arimaz.com> <49A28BD6.9040701@arimaz.com> Message-ID: <89a1045472ca4ec4c07f26543032058e.squirrel@acooke.dyndns.org> Gabriel Rossetti wrote: > Ok, maybe I mis-stated my problem (or mis-understood your answers).. I > don' t want to share code as in have multiple processes access a > variable and have the same value, like it is done in threads, what I > want is to not have n copies of the code (classes, functions, etc) > loaded by n python interpreters. When you load Apache for instance, it > runs n processes but loads only one copy of parts of it's code (so/dll), > that's what I want to do. In C/C++ I would write a shared-lib (so/dll), > so once the system has loaded it, it doesn' t re-load it when another > process needs it. i think i understand what you want. the problem is that the kind of language that python is really doesn't work well with that kind of approach. this is (and i may be wrong - i've not really thought much about this before) largely because python places a very strong emphasis on late binding. that means that everything is very flexible - all kinds of things can be changed "under the hood". and that means that it is very difficult to share things safely because almost any solution would end up doing what you don't want (sharing variables, like with threads (even though they are very deeply buried variables)) rather than what you do want (just sharing the static part of the code to save space). another way to see this is to see the connection with security. this is the flip side of your case - because things are so flexible it is very hard to run some python code in a "sandbox" in a larger python program. there's some discussion on the dev group at the moment and it looks like the solution is to only use function closures. but even that doesn't work without some patches that remove certain ways to dynamically alter the code base. andrew From goodz158 at yahoo.com Mon Feb 23 09:02:54 2009 From: goodz158 at yahoo.com (Good Z) Date: Mon, 23 Feb 2009 06:02:54 -0800 (PST) Subject: Getting Certification Chain from Digital Signature Message-ID: <352443.74170.qm@web35901.mail.mud.yahoo.com> All, I need to extract certification chain/private key from digital signature certificate (DSC). The Digital Signature (DSC) is in PFX file format. I got the Java code but do not know the python equivalent in python. Any help will be appreciated. Best Regards, Mike -------------- next part -------------- An HTML attachment was scrubbed... URL: From sion at paintbox.UUCP Mon Feb 23 09:11:58 2009 From: sion at paintbox.UUCP (S Arrowsmith) Date: 23 Feb 2009 14:11:58 GMT Subject: count secton of data in list References: <3ed253bb-d6ec-4f47-af08-ad193e9c46e3@h16g2000yqj.googlegroups.com> Message-ID: In article <3ed253bb-d6ec-4f47-af08-ad193e9c46e3 at h16g2000yqj.googlegroups.com>, odeits wrote: >def count_consecutive(rows): > switch =3D 0 > count =3D 0 > for r in rows: > if r[-1] =3D=3D switch: > count +=3D 1 > else: > switch =3D not switch > if count !=3D 0: > yield count > count =3D 0 > if count !=3D 0: > yield count > >rows = [ ... ] > >for cnt in count_consecutive(rows): > print cnt import itertools, operator for k, g in itertools.groupby(rows, operator.itemgetter(3): print len(list(g)) -- \S under construction From freelancer317 at gmail.com Mon Feb 23 10:02:51 2009 From: freelancer317 at gmail.com (Bret Fledderjohn) Date: Mon, 23 Feb 2009 10:02:51 -0500 Subject: pysqlite smart search In-Reply-To: <22161119.post@talk.nabble.com> References: <22157116.post@talk.nabble.com> <22161119.post@talk.nabble.com> Message-ID: 2009/2/23 klia > > > > klia wrote: > > > > Hey guys; > > > > I am trying to develop a tiny program using python to search inside > sqlite > > database with file extension is .db in which the program will ask users > to > > enter their search query and base on that it will retrieve the results > But > > > > I need the program to have some smartness in search mechanism in which > the > > program will guess that the user is looking for these key words in the > > database. > > > > so far i came up with this but the search ain't smart, i have to write > the > > full key word in order to retrieve specific information. > > > > from pysqlite2 import dbapi2 as sqlite3 > > > > connection = sqlite3.connect('Photos.db') > > memoryConnection = sqlite3.connect(':memory:') > > cursor = connection.cursor() > > prompt = 'Enter your search query?\n' > > keyword = raw_input(prompt) > > if cursor.execute('SELECT * FROM photos WHERE Tag LIKE ?',[keyword]): > > print cursor.fetchall() > > else: > > cursor.execute('SELECT * FROM photos WHERE Date LIKE ?', [keyword]) > > print cursor.fetchall() > > > > Any ideas and > > thanks in advance > > Reply > > > > thank you man, it worked perfectly but one more thing; > > when i print rows it retrieves the whole rows of info which i don't need, i > need just to retrieve the name of the photo. > so how am i gonna do that? It depends on the structure of your table, but you're going to have to change the following lines: >if cursor.execute('SELECT * FROM photos WHERE Tag LIKE ?',[keyword]): >cursor.execute('SELECT * FROM photos WHERE Date LIKE ?', [keyword]) * indicates all fields in the selected records, so you need to change the * to the field that contains the name of the photo. For example: if cursor.execute('SELECT name FROM photos WHERE Tag LIKE ?',[keyword]): -- > View this message in context: > http://www.nabble.com/pysqlite-smart-search-tp22157116p22161119.html > Sent from the Python - python-list mailing list archive at Nabble.com. > > -- > http://mail.python.org/mailman/listinfo/python-list > -- - Bret -------------- next part -------------- An HTML attachment was scrubbed... URL: From Ron.Barak at lsi.com Mon Feb 23 10:23:23 2009 From: Ron.Barak at lsi.com (Barak, Ron) Date: Mon, 23 Feb 2009 15:23:23 +0000 Subject: Solved: Metaclass conflict TypeError exception: problem demonstration script In-Reply-To: <49A26E24.5060602@timgolden.me.uk> References: <20090222145717.787F04A136E@riobu.com> <7F0503CD69378F49BE0DC30661C6CCF659FDEDD5@enbmail01.lsi.com> <49A26E24.5060602@timgolden.me.uk> Message-ID: <7F0503CD69378F49BE0DC30661C6CCF659FDEE5E@enbmail01.lsi.com> Hi, > -----Original Message----- > From: Tim Golden [mailto:mail at timgolden.me.uk] > Sent: Monday, February 23, 2009 11:37 > Cc: python-list at python.org; wxpython-users at lists.wxwidgets.org > Subject: Re: Metaclass conflict TypeError exception: problem > demonstration script > > > $ cat -n metaclass_test01.py | head > > 1 #!/usr/bin/env python > > 2 > > 3 import sys > > 4 import wx > > 5 import CopyAndPaste > > 6 > > 7 class ListControl(wx.Frame, CopyAndPaste): > > 8 #class ListControl(wx.Frame): > > 9 def __init__(self, parent, id, title, list, > max_list_width): > > 10 > wx.Frame.__init__(self,parent,id,title,size=(-1,-1), > style=wx.DEFAULT_FRAME_STYLE) > > > > I get the metaclass conflict exception: > > > You're trying to use a module as a base class. > Don't do that; it doesn't work. > > TJG > > That's it. Once I changed my class header to: $ cat -n metaclass_test01.py 1 #!/usr/bin/env python 2 3 import sys 4 import wx 5 import CopyAndPaste 6 7 class ListControl(wx.Frame, CopyAndPaste.CopyAndPaste): I'm getting no more Metaclass conflict TypeError exceptions :-) (a clear case of "The Devil Is In The ...") Thanks so much, Ron. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Mon Feb 23 10:28:02 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 23 Feb 2009 15:28:02 +0000 Subject: Solved: Metaclass conflict TypeError exception: problem demonstration script In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF659FDEE5E@enbmail01.lsi.com> References: <20090222145717.787F04A136E@riobu.com> <7F0503CD69378F49BE0DC30661C6CCF659FDEDD5@enbmail01.lsi.com> <49A26E24.5060602@timgolden.me.uk> <7F0503CD69378F49BE0DC30661C6CCF659FDEE5E@enbmail01.lsi.com> Message-ID: <49A2C082.4050608@timgolden.me.uk> Barak, Ron wrote: > That's it. > > Once I changed my class header to: > > $ cat -n metaclass_test01.py > 1 #!/usr/bin/env python > 2 > 3 import sys > 4 import wx > 5 import CopyAndPaste > 6 > 7 class ListControl(wx.Frame, CopyAndPaste.CopyAndPaste): > > I'm getting no more Metaclass conflict TypeError exceptions :-) > (a clear case of "The Devil Is In The ...") Glad we could help. Also a good indication of how important it is to produce real code which really fails in the real way! Sometimes you can look at it yourself even before you post and see the problem. :) TJG From deets at nospam.web.de Mon Feb 23 10:49:01 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 23 Feb 2009 16:49:01 +0100 Subject: pysqlite smart search In-Reply-To: References: <22157116.post@talk.nabble.com> Message-ID: <70furdF4guqjU1@mid.uni-berlin.de> klia schrieb: > > > klia wrote: >> Hey guys; >> >> I am trying to develop a tiny program using python to search inside sqlite >> database with file extension is .db in which the program will ask users to >> enter their search query and base on that it will retrieve the results But >> >> I need the program to have some smartness in search mechanism in which the >> program will guess that the user is looking for these key words in the >> database. >> >> so far i came up with this but the search ain't smart, i have to write the >> full key word in order to retrieve specific information. >> >> from pysqlite2 import dbapi2 as sqlite3 >> >> connection = sqlite3.connect('Photos.db') >> memoryConnection = sqlite3.connect(':memory:') >> cursor = connection.cursor() >> prompt = 'Enter your search query?\n' >> keyword = raw_input(prompt) >> if cursor.execute('SELECT * FROM photos WHERE Tag LIKE ?',[keyword]): >> print cursor.fetchall() >> else: >> cursor.execute('SELECT * FROM photos WHERE Date LIKE ?', [keyword]) >> print cursor.fetchall() >> >> Any ideas and >> thanks in advance >> Reply >> > > thank you man, it worked perfectly but one more thing; > > when i print rows it retrieves the whole rows of info which i don't need, i > need just to retrieve the name of the photo. > so how am i gonna do that? select ... instead of select * Diez From xahlee at gmail.com Mon Feb 23 10:54:48 2009 From: xahlee at gmail.com (Xah Lee) Date: Mon, 23 Feb 2009 07:54:48 -0800 (PST) Subject: programming by evolution? References: <42a2e3fc-ec2e-4c09-b456-95a5fc4ce5a2@g39g2000pri.googlegroups.com> <6uuc4eFhc1u1U1@mid.individual.net> <11809792-676f-4d95-87c1-26666cc46b3b@w24g2000prd.googlegroups.com> <03db1c69-828a-4961-914d-62fe10ed88fb@w39g2000prb.googlegroups.com> Message-ID: <67b81919-4e73-4943-a6bc-5863e9a93a3a@j39g2000yqn.googlegroups.com> On Feb 23, 4:56 am, Roedy Green wrote: > On 19 Feb 2009 18:56:42 GMT, Albert van der Horst > wrote, quoted or indirectly quoted someone > who said : > > >Note here, that eXtreme > >>Programing is one of the snake oil, > > Extreme programming is a variant on Deming's idea of constant > incremental improvement that revolutionised quality in manufacturing. > > It is also based on the obvious idea that you will be smarter after > you have used some version of a program than you are today. There are > so many computer programs perfectly compliant with specs that looked > good on paper but nobody ever tested with actual use to refine them > until the project was "complete" and it was too expensive to fix them. 2009-02-09 Today, i happened to run across a blog on the eXtreme Programing FUCK. http://www.yosefk.com/blog/extreme-programming-explained.html Great article! Xah $B-t(B http://xahlee.org/ From john.ionides at gmail.com Mon Feb 23 11:09:23 2009 From: john.ionides at gmail.com (John Ionides) Date: Mon, 23 Feb 2009 08:09:23 -0800 (PST) Subject: ZSI / MTOM Message-ID: <1fd305a1-d087-4902-83ba-780e97bd042f@m24g2000vbp.googlegroups.com> I have project for which I would like to have a python web service including MTOM. It seems that ZSI is the most complete python web service library but that it doesn't currently support MTOM - and having worked through the code it looks as though it isn't going to be exactly simple. Is there anyone working on a patch (or interested in collaborating if it comes down to writing one)? John From schlaber at gmail.com Mon Feb 23 11:13:53 2009 From: schlaber at gmail.com (Brot) Date: Mon, 23 Feb 2009 08:13:53 -0800 (PST) Subject: charset problems with urllib/urllib2 Message-ID: Hello, I am using the mailman-installation (http://www.gnu.org/software/ mailman/) from my hosting company. I doesn't have access to the add_members script and so I am writing a python script which uses http requests to subscribe new members. But if I am posting a new member with an name, which includes "German Umlaute" I see only weird characters in the admin-interface. The mailman webinterface doesn't use utf-8. It always uses the corresponding charset for the actual language setting. If I post "B?rbel R?ssel" the admin-interface shows me the following name: "B??rbel R??ssel" I am using the German language setting, so mailman uses the ISO-8559-1 charset in the webinterface. If I switch my browser to UTF-8 the name is correct in the admin-interface, but all other special characters are wrong. The strange thing for me is, that the name is correct if I subscribe the member in the admin-interface manually. I don't know what the different is between my python script and the manuell subscription. To Post to my mailman-server I use this recipe (http:// code.activestate.com/recipes/146306/) to generate the multipart/form-data POST I looked into the Mailman source code and found the Util.canonstr method. At the end it changes the string to an unicode string. So the name is stored as unicode, isn't it? But why is there a difference if I display the manuell inserted name and the automatic inserted name?? I used Tamper Data (https://addons.mozilla.org/en-US/firefox/addon/ 966) to catch the request when I inserted the data manually through the webinterface. The request generated with my script looks the same, but the output isn't? Does anyone have experience with this problem or with mailman and urllib/urllib2? ~ Bernd From tjreedy at udel.edu Mon Feb 23 11:51:17 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 23 Feb 2009 11:51:17 -0500 Subject: different errors, return outside function and others In-Reply-To: References: Message-ID: Tony wrote: > The full error message says "There's an error in your program: *** > 'return' outside function (final(2).py, line 114) Ah, you left the quotes off before, and you still omitted the error class (SyntaxError, see below). When you are puzzled by an error, try to reduce the executed code to the MINIMUN needed to get the error. (You can use your editor's block comment feature -- for IDLE see Format/Comment out [marked] region.) For your error, the minimum is >>> return SyntaxError: 'return' outside function (, line 1) Return statements are only value inside functions and not in module level code. Perhaps you think you 'return' is in a function but it is not because it is not indented. Terry Jan Reedy From aquil.abdullah at gmail.com Mon Feb 23 11:53:20 2009 From: aquil.abdullah at gmail.com (aha) Date: Mon, 23 Feb 2009 08:53:20 -0800 (PST) Subject: A tale of two execs Message-ID: Hello All, I am working on a project where I need to support versions of Python as old as 2.3. Previously, we distributed Python with our product, but this seemed a bit silly so we are no longer doing this. The problem that I am faced with is that we have Python scripts that use the subprocess module, and subprocess is not available in Python 2.3. Below is the strategy I am thinking about using, however if, you have better ideas please let me know. def runner(cmd, stdin, stdout, ...): try: import subprocess sbm = 1 except: sbm = 0 # Now do something if sbm: process = subporcess(...) else: import popen2 process = popen2.Popen4(...) Has anyone else run into a situation similar to this one? From zelegolas at gmail.com Mon Feb 23 11:55:38 2009 From: zelegolas at gmail.com (zelegolas) Date: Mon, 23 Feb 2009 08:55:38 -0800 (PST) Subject: Python Imaging Library (PIL): create PDF from scratch Message-ID: Hi, I have some scan generated by SANE and i would like to do some transformation (like crop, brightness and resize) and finaly put all those images in PDF file. With PIL i can do all the transformations that i want. But i don't know how i can create from scratch a PDF. I'm not even sure that PIL is the right library for that. Any help/informations will be appreciate From bieffe62 at gmail.com Mon Feb 23 12:06:25 2009 From: bieffe62 at gmail.com (bieffe62 at gmail.com) Date: Mon, 23 Feb 2009 09:06:25 -0800 (PST) Subject: A tale of two execs References: Message-ID: <4e5f94f2-2707-4a4d-b48b-b97759225bef@j35g2000yqh.googlegroups.com> On Feb 23, 5:53?pm, aha wrote: > Hello All, > ? I am working on a project where I need to support versions of Python > as old as 2.3. Previously, we distributed Python with our product, but > this seemed a bit silly so we are no longer doing this. ?The problem > that I am faced with is that we have Python scripts that use the > subprocess module, and subprocess is not available in Python 2.3. > Below is the strategy I am thinking about using, however if, you have > better ideas please let me know. > > def runner(cmd, stdin, stdout, ...): > ? try: > ? ? import subprocess > ? ? sbm = 1 > ? except: > ? ? sbm = 0 > > ? # Now do something > ? if sbm: > ? ? process = subporcess(...) > ? else: > ? ? import popen2 > ? ? process = popen2.Popen4(...) > > Has anyone else run into a situation similar to this one? IIRC, subprocess is a pure python module. If so, tou could try if subprocess compiles under 2.3. If so, or if it has easily fixable problems, you could rename it as someting like 'backported_subprocess.py' and include it in your app, which then should do: try: import subprocess except ImportError: import backported_subprocess as subprocess This should minimize the change at your code. Of course if the usage of subprocess is restricted to few functions, your approach to provide two alternative implementations of those function is also workable. However, check if/when the module popen2, which is deprecated, is planned for remioval, otherwise you will have the same problem later. HTH Ciao ------ FB From mnordhoff at mattnordhoff.com Mon Feb 23 12:07:04 2009 From: mnordhoff at mattnordhoff.com (Matt Nordhoff) Date: Mon, 23 Feb 2009 17:07:04 +0000 Subject: A tale of two execs In-Reply-To: References: Message-ID: <49A2D7B8.2000106@mattnordhoff.com> aha wrote: > Hello All, > I am working on a project where I need to support versions of Python > as old as 2.3. Previously, we distributed Python with our product, but > this seemed a bit silly so we are no longer doing this. The problem > that I am faced with is that we have Python scripts that use the > subprocess module, and subprocess is not available in Python 2.3. > Below is the strategy I am thinking about using, however if, you have > better ideas please let me know. > > def runner(cmd, stdin, stdout, ...): > try: > import subprocess > sbm = 1 > except: > sbm = 0 > > # Now do something > if sbm: > process = subporcess(...) > else: > import popen2 > process = popen2.Popen4(...) > > Has anyone else run into a situation similar to this one? FWIW, the Mercurial project went the other way: They wrote "popen2", "popen3" and "Popen3" functions that were wrappers around subprocess: -- From phillip.oldham at gmail.com Mon Feb 23 12:12:20 2009 From: phillip.oldham at gmail.com (Phillip B Oldham) Date: Mon, 23 Feb 2009 09:12:20 -0800 (PST) Subject: Python shell scripting and errors Message-ID: <0b33c75d-807b-4a64-acec-4c6486893552@l22g2000vba.googlegroups.com> I've got a python script running as a daemon (using someone else's daemon module). It runs fine for a while, but will occasionally balk and die. Since its running in the background, I'm getting no error from it. What's the best way to capture the output into a file for later review? From ethan at stoneleaf.us Mon Feb 23 12:16:38 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 23 Feb 2009 09:16:38 -0800 Subject: ANN: Python dBase 0.84.18 released! Message-ID: <49A2D9F6.2060906@stoneleaf.us> This module is designed to work with dBase III and Visual FoxPro 6.0 dbf files, along with their memo files. Index files are not supported. The table header is read into memory, table data is read into memory on first record access; field updates are immediately written to disk. Documentation will be improved as time permits. Current web location is http://groups.google.com/group/python-dbase. My apologies for the extremely bare-bones web site. -- ~Ethan~ From tim.wintle at teamrubber.com Mon Feb 23 12:21:51 2009 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Mon, 23 Feb 2009 17:21:51 +0000 Subject: Python shell scripting and errors In-Reply-To: <0b33c75d-807b-4a64-acec-4c6486893552@l22g2000vba.googlegroups.com> References: <0b33c75d-807b-4a64-acec-4c6486893552@l22g2000vba.googlegroups.com> Message-ID: <1235409711.12946.31.camel@tim-laptop> On Mon, 2009-02-23 at 09:12 -0800, Phillip B Oldham wrote: > I've got a python script running as a daemon (using someone else's > daemon module). It runs fine for a while, but will occasionally balk > and die. Since its running in the background, I'm getting no error > from it. > > What's the best way to capture the output into a file for later review? Point standard out to an open file handle? From bieffe62 at gmail.com Mon Feb 23 12:28:44 2009 From: bieffe62 at gmail.com (bieffe62 at gmail.com) Date: Mon, 23 Feb 2009 09:28:44 -0800 (PST) Subject: A tale of two execs References: <4e5f94f2-2707-4a4d-b48b-b97759225bef@j35g2000yqh.googlegroups.com> Message-ID: <652cdc53-584d-49ca-891c-350465fe9ebf@u38g2000yqe.googlegroups.com> On Feb 23, 6:06?pm, bieff... at gmail.com wrote: > On Feb 23, 5:53?pm, aha wrote: > > > > > > > Hello All, > > ? I am working on a project where I need to support versions of Python > > as old as 2.3. Previously, we distributed Python with our product, but > > this seemed a bit silly so we are no longer doing this. ?The problem > > that I am faced with is that we have Python scripts that use the > > subprocess module, and subprocess is not available in Python 2.3. > > Below is the strategy I am thinking about using, however if, you have > > better ideas please let me know. > > > def runner(cmd, stdin, stdout, ...): > > ? try: > > ? ? import subprocess > > ? ? sbm = 1 > > ? except: > > ? ? sbm = 0 > > > ? # Now do something > > ? if sbm: > > ? ? process = subporcess(...) > > ? else: > > ? ? import popen2 > > ? ? process = popen2.Popen4(...) > > > Has anyone else run into a situation similar to this one? > > IIRC, ?subprocess is a pure python module. If so, tou could try if > subprocess compiles under 2.3. ... I checked, and, for windows platform subprocess.py uses the modules mvscrt and _subprocess, which I ham unable to locate on my windows XP python 2.6 installation. This make the whole thing harder, even impossible if _subprocess has been created especially for subprocess.py. For non-windows platform, subprocess.py seem to use only fairly well- established module, so there is a chance to backport it. Ciao again ---------- FB From tjreedy at udel.edu Mon Feb 23 12:29:16 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 23 Feb 2009 12:29:16 -0500 Subject: Is there a way to ask a class what its metaclasses are ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF659FDEDBD@enbmail01.lsi.com> References: <7F0503CD69378F49BE0DC30661C6CCF60E68800F@enbmail01.lsi.com> <50697b2c0902191258ye5aa478gecaf7b7b097e3eba@mail.gmail.com> <7F0503CD69378F49BE0DC30661C6CCF62783D662@enbmail01.lsi.com> <50697b2c0902220147y4c8dbf94j1415aae9ee7d640@mail.gmail.com> <7F0503CD69378F49BE0DC30661C6CCF62783D673@enbmail01.lsi.com> <50697b2c0902220357g762fe390q6535079d42f6afb0@mail.gmail.com> <7F0503CD69378F49BE0DC30661C6CCF62783D685@enbmail01.lsi.com> <50697b2c0902221211k3be5f797k5f0419179864ae4f@mail.gmail.com> <7F0503CD69378F49BE0DC30661C6CCF659FDEDBD@enbmail01.lsi.com> Message-ID: Barak, Ron wrote: > > When I try the following (to see the types of the classes involved): > > #!/usr/bin/env python > > import wx > from Debug import _line as line > > class CopyAndPaste(object): > def __init__(self, *args, **kwargs): > super(CopyAndPaste, self).__init__(*args, **kwargs) > print line()+". type(wx.Frame):",type(wx.Frame) > print line()+". type(object):",type(object) > > I get: > > $ python -u CopyAndPaste.py > 9. type(wx.Frame): > 10. type(object): > > And I don't understand what it means... The default metaclass is named 'type'. It it the class of all builtin classes and all user classes (3.0) that do not specify otherwise. Behind the scenes, new user classes are created as instances of 'type' by the equivalent of 'type(name, bases, class_dict)'. What is possibly confusing is that the __call__ method of 'type' also allows calls to type with only one arg, in which case it returns the class of the arg instead of trying to create a new class. And so one might mistakenly think that 'type' is a built-in function rather than a class. Terry Jan Reedy From philip at semanchuk.com Mon Feb 23 12:34:53 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 23 Feb 2009 12:34:53 -0500 Subject: Python shell scripting and errors In-Reply-To: <1235409711.12946.31.camel@tim-laptop> References: <0b33c75d-807b-4a64-acec-4c6486893552@l22g2000vba.googlegroups.com> <1235409711.12946.31.camel@tim-laptop> Message-ID: <90DA12C5-AC31-4747-AEBA-4952BAFFC02B@semanchuk.com> On Feb 23, 2009, at 12:21 PM, Tim Wintle wrote: > On Mon, 2009-02-23 at 09:12 -0800, Phillip B Oldham wrote: >> I've got a python script running as a daemon (using someone else's >> daemon module). It runs fine for a while, but will occasionally balk >> and die. Since its running in the background, I'm getting no error >> from it. >> >> What's the best way to capture the output into a file for later >> review? > > Point standard out to an open file handle? And stderr. I don't know how the OP's daemon is being launched, but the crontab command below worked for me for redirecting errors to a log file without the need to modify the script. python /usr/local/foo/bar.py >> /var/log/foo/bar.txt 2>&1 HTH Philip From steve at holdenweb.com Mon Feb 23 12:45:57 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 23 Feb 2009 12:45:57 -0500 Subject: Reference or Value? In-Reply-To: <39e19a010902222154m1d2af37vea53e17578331939@mail.gmail.com> References: <39e19a010902222154m1d2af37vea53e17578331939@mail.gmail.com> Message-ID: Denis Kasak wrote: > On Mon, Feb 23, 2009 at 5:09 AM, Steven D'Aprano > wrote: >> On Sun, 22 Feb 2009 13:37:27 -0300, andrew cooke wrote: >> >>> as far as i understand things, the best model is: >>> >>> 1 - everything is an object >>> 2 - everything is passed by reference >> Except that is wrong. If it were true, you could do this: >> >> def swap(x, y): >> y, x = x, y >> >> a = 1 >> b = 2 >> swap(a, b) >> assert a == 2 and b == 1 >> >> >> but you can't, it does not work. Ergo, parameter passing in Python does >> not have the same semantics as languages that use pass-by-reference, such >> as Pascal and Basic. That means that even if you can justify the claim >> "Python is pass-by-reference" by some technical argument (and I don't >> believe you can), it is misleading to make that claim without further >> qualifications. > > You could, however, argue that the swap function doesn't work as > expected (e.g. from a Pascal or a C++ POV) simply because the > underlying objects aren't mutable. The objects *do* get passed by > reference; the function doesn't receive a new copy of the object and > it can examine the original object's ID. The actual culprit is not the > way objects are passed but the assignment operator, since it works by > rebinding names (as Andrew Koenig explained) and not by changing the > object itself. If the swap() function could somehow access the > underlying integer object and modify it, swapping of values would > indeed occur because the function *did* get references to the objects > passed to it. > > That said, it's a rather convoluted way of explaining what happens and > calling it pass-by-object feels much better. :-) > The underlying point is that there is no way to rebind names in the caller's namespace by manipulations of parameters passed as arguments to a function. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From rdmurray at bitdance.com Mon Feb 23 12:54:03 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Mon, 23 Feb 2009 17:54:03 +0000 (UTC) Subject: can error messages be improved or can they be overridden ? References: <49A1567B.5020407@gmail.com> <7F0503CD69378F49BE0DC30661C6CCF62783D690@enbmail01.lsi.com> <49A272F1.7090004@gmail.com> Message-ID: Stef Mientki wrote: > thanks Ron, > > but I was looking for a more general solution, > in which I don't change the program itself, > and where the error messages (in general) become more informative than > it is by default. [snip] > >> -----Original Message----- > >> From: Stef Mientki [mailto:stef.mientki at gmail.com] [snip] > >> I often get an error message like this > >> > >> self.Brick.Par [ self.EP[2] ]['FileName'] = filename > >> IndexError: list index out of range > >> > >> Now it would be very welcome, > >> if the error message specified which index is out of range, > >> in this case e.g., > >> - specifying the length of self.EP > >> - specifying the value of self.EP[2] > >> - specifying the length of self.Brick.Par etc.. > >> > >> Is there a way to override the error message and provide this > >> information, or is it impossible ? > >> > >> And if it's possible, am I the only one who often stumbles > >> about this problem ? > >> (I expect many people must have bounced in this problem before me ;-) FYI, top posts are much harder to read and to reply to than if you edit the message to which you are replying and add your new content interleaved or at the bottom (as I have done). No you are not the only one who wishes the error messages were more informative. In one complex application I had, I made my life easier with a hack I copied from Zope. Briefly, at the top level of the program I trap all exceptions, get the traceback object from sys.exc_info, format it with format_tb, and then process it to add info. I applied several enhancements, but the one relevant to you was to grab the locals dictionary from the last frame of the traceback, and use a regex to split the last source line in the formatted traceback up into candidate variable names. Then I printed the name and the repr of the value of any of those names I found in the locals dict. That wouldn't tell you directly which variable it was threw the index error, but having the current values of the variables involved saves a lot of time (no need to go back and stick in prints in many cases). (You know, I really ought to revisit that routine and make it part of my standard development toolbox.) --RDM From steve at holdenweb.com Mon Feb 23 12:57:05 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 23 Feb 2009 12:57:05 -0500 Subject: Server programming In-Reply-To: References: Message-ID: koranthala wrote: > Hi, > Is server programming in Python procedure oriented or object > oriented? > I have this question because lately I am asked to make a medium > complex web program (extremely database oriented) using Django. When I > used to do application programs earlier (in Python itself), the whole > thing being object oriented came out easily in programming. So, I was > able to use different patterns etc for programming and the whole thing > was - quite fun to design and create. > But when I program in Django, since I just have to work on user > responses - everything else being taken care of by Django - only, the > complete coding has become procedure oriented. It is not kludgy or > anything, but it doesnt have the nice feeling that we get when we code > a proper object oriented program. > Is my coding in error here? This is infact my first web program, > so it might be the reason. What does other people find? Does web > server programming using web frameworks (Django, TurboGears etc) make > it procedure oriented? If I am in the wrong, it might be due to a > wrong design or mindset, and I would like to change it. > It's just that Django *seems* procedure-oriented because your views are written as functions. But they take request objects as arguments and return response objects as results, so the framework is object-oriented. Also each model is a class, and querysets eventually yield lists of instances. I wouldn't worry too much until Django forces you to do somethign you really don't want to do ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Mon Feb 23 13:00:08 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 23 Feb 2009 13:00:08 -0500 Subject: Python Imaging Library (PIL): create PDF from scratch In-Reply-To: References: Message-ID: zelegolas wrote: > Hi, > > I have some scan generated by SANE and i would like to do some > transformation (like crop, brightness and resize) and finaly put all > those images in PDF file. > > With PIL i can do all the transformations that i want. But i don't > know how i can create from scratch a PDF. I'm not even sure that PIL > is the right library for that. > PIL is great for graphics, but I use ReportLab's open source stuff (see www.reportlab.org) for creating PDFs - that's what it was designed for, and you can easily incorporate your graphics. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From andrew at acooke.org Mon Feb 23 13:00:37 2009 From: andrew at acooke.org (andrew cooke) Date: Mon, 23 Feb 2009 15:00:37 -0300 (CLST) Subject: can error messages be improved or can they be overridden ? In-Reply-To: References: <49A1567B.5020407@gmail.com> <7F0503CD69378F49BE0DC30661C6CCF62783D690@enbmail01.lsi.com> <49A272F1.7090004@gmail.com> Message-ID: <9afda87e04d99d252c989c08ade7699f.squirrel@acooke.dyndns.org> rdmurray at bitdance.com wrote: [...] > (You know, I really ought to revisit that routine and make it part > of my standard development toolbox.) please post it.... andrew From clp2 at rebertia.com Mon Feb 23 13:02:50 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 23 Feb 2009 10:02:50 -0800 Subject: opening files with names in non-english characters. In-Reply-To: <5b6a03dc-0393-46e6-bff0-c36669a67340@w34g2000yqm.googlegroups.com> References: <5b6a03dc-0393-46e6-bff0-c36669a67340@w34g2000yqm.googlegroups.com> Message-ID: <50697b2c0902231002k28b4f2dfs4b4bbf38e569511f@mail.gmail.com> On Mon, Feb 23, 2009 at 5:51 AM, venutaurus539 at gmail.com wrote: > Hi all, > I am trying to find the attributes of afile whose name has > non english characters one like given below. When I try to run my > python scirpt, it fails giving out an error filename must be in string > or UNICODE. When i try to copy the name of the file as a strinig, it > (KOMODO IDE) is not allowing me to save the script saying that it > cannot convert some of the characters in the current encoding which is > Western European(CP-1252). > > 0010testUnicode_???????????????????? !#$%&'()+,-. > 0123456789;=@ABCD.txt.txt (1) How are you entering or retrieving that filename? (2) Please provide the exact error and Traceback you're getting. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From bob at mellowood.ca Mon Feb 23 13:05:55 2009 From: bob at mellowood.ca (bvdp) Date: Mon, 23 Feb 2009 11:05:55 -0700 Subject: unescape escapes in strings Message-ID: When reading lines of data from a file in the from (no quotes!) foo\x20bar and I assign to a variable in a line line like: f = file('infile', 'r') for a in f: print a the string is read in as string with the literal characters 'f', 'o' ... 'x' , '2' ... as compared to an assignment like: a="foo\x20bar" which is identical to a="foo bar" Okay, so far ... I think this is what I want since my program is using space characters as delimiters and I'm trying to use the \x20 notation to avoid splitting. But, now the problem. When I finally assign the string with the \x20 to a variable the literals are still there. And here I really want them all nicely converted to the desired values. So, the question is: is there an "unescape()" for strings so that "foo\x20bar" is converted to "foo bar"???? From google at mrabarnett.plus.com Mon Feb 23 13:22:51 2009 From: google at mrabarnett.plus.com (MRAB) Date: Mon, 23 Feb 2009 18:22:51 +0000 Subject: unescape escapes in strings In-Reply-To: References: Message-ID: <49A2E97B.4010209@mrabarnett.plus.com> bvdp wrote: > > When reading lines of data from a file in the from (no quotes!) > > foo\x20bar > > and I assign to a variable in a line line like: > > f = file('infile', 'r') > for a in f: > print a > > the string is read in as string with the literal characters 'f', 'o' ... > 'x' , '2' ... > > as compared to an assignment like: > > a="foo\x20bar" > > which is identical to > > a="foo bar" > > Okay, so far ... I think this is what I want since my program is using > space characters as delimiters and I'm trying to use the \x20 notation > to avoid splitting. > > But, now the problem. When I finally assign the string with the \x20 to > a variable the literals are still there. And here I really want them all > nicely converted to the desired values. > > So, the question is: is there an "unescape()" for strings so that > "foo\x20bar" is converted to "foo bar"???? > >>> a = r"foo\x20bar" >>> print a foo\x20bar >>> a = a.decode("string-escape") >>> print a foo bar From bnsilinux at gmail.com Mon Feb 23 13:29:46 2009 From: bnsilinux at gmail.com (Ben) Date: Mon, 23 Feb 2009 10:29:46 -0800 (PST) Subject: Which GROUP to join ? Message-ID: hello, I have written a parameter driven menuing and screen system for S-Lang called SLAG. It is very intuitive and easy to use and was designed to rapidly build Accounting Applications with. I am currently working on porting it to Python. Which DEV group in Python should I join to get help and ask questions ? Thanks Ben Duncan From robert.kern at gmail.com Mon Feb 23 13:33:41 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 23 Feb 2009 12:33:41 -0600 Subject: Which GROUP to join ? In-Reply-To: References: Message-ID: On 2009-02-23 12:29, Ben wrote: > hello, I have written a parameter driven menuing and screen system for > S-Lang called SLAG. It is very intuitive and easy to use and was > designed to rapidly build Accounting Applications with. > > I am currently working on porting it to Python. > > Which DEV group in Python should I join to get help and ask > questions ? This one. Welcome! -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From kyosohma at gmail.com Mon Feb 23 13:34:16 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Mon, 23 Feb 2009 10:34:16 -0800 (PST) Subject: Which GROUP to join ? References: Message-ID: On Feb 23, 12:29?pm, Ben wrote: > hello, I have written a parameter driven menuing and screen system for > S-Lang called SLAG. ?It is very intuitive and easy to use and was > designed to rapidly build Accounting Applications with. > > I am currently working on porting it to Python. > > Which DEV group in Python should I join to get help and ask > questions ? > > Thanks > > Ben Duncan You don't need to join the dev groups unless you plan to contribute to their respective projects. For general questions, this is probably the best place. Most other projects (such as Sqlalchemy, wxPython, django) have their own specific lists. Join them as needed. Mike From bob at mellowood.ca Mon Feb 23 13:35:35 2009 From: bob at mellowood.ca (bvdp) Date: Mon, 23 Feb 2009 11:35:35 -0700 Subject: unescape escapes in strings In-Reply-To: References: Message-ID: MRAB wrote: > bvdp wrote: >> >> When reading lines of data from a file in the from (no quotes!) >> >> foo\x20bar >> >> and I assign to a variable in a line line like: >> >> f = file('infile', 'r') >> for a in f: >> print a >> >> the string is read in as string with the literal characters 'f', 'o' >> ... 'x' , '2' ... >> >> as compared to an assignment like: >> >> a="foo\x20bar" >> >> which is identical to >> >> a="foo bar" >> >> Okay, so far ... I think this is what I want since my program is using >> space characters as delimiters and I'm trying to use the \x20 notation >> to avoid splitting. >> >> But, now the problem. When I finally assign the string with the \x20 >> to a variable the literals are still there. And here I really want >> them all nicely converted to the desired values. >> >> So, the question is: is there an "unescape()" for strings so that >> "foo\x20bar" is converted to "foo bar"???? >> > >>> a = r"foo\x20bar" > >>> print a > foo\x20bar > >>> a = a.decode("string-escape") > >>> print a > foo bar > Thanks ... I think in my original testing I tried decode() but it didn't work. Testing more ... the file has 2 lines: foo bar foo\x20bar and the program to read is: f=file('in', 'r') for a in f: a = a.strip() a=a.decode() print list(a) I get: python read.py [] [u'f', u'o', u'o', u' ', u'b', u'a', u'r'] [u'f', u'o', u'o', u'\\', u'x', u'2', u'0', u'b', u'a', u'r'] So, the \x20 is still literal. Any other ideas??? I suppose I could write a re expression ... but surely that is not needed??? From stef.mientki at gmail.com Mon Feb 23 13:37:17 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Mon, 23 Feb 2009 19:37:17 +0100 Subject: can error messages be improved or can they be overridden ? In-Reply-To: References: <49A1567B.5020407@gmail.com> <7F0503CD69378F49BE0DC30661C6CCF62783D690@enbmail01.lsi.com> <49A272F1.7090004@gmail.com> Message-ID: <49A2ECDD.8040600@gmail.com> rdmurray at bitdance.com wrote: > Stef Mientki wrote: > >> thanks Ron, >> >> but I was looking for a more general solution, >> in which I don't change the program itself, >> and where the error messages (in general) become more informative than >> it is by default. >> > [snip] > >>>> -----Original Message----- >>>> From: Stef Mientki [mailto:stef.mientki at gmail.com] >>>> > [snip] > >>>> I often get an error message like this >>>> >>>> self.Brick.Par [ self.EP[2] ]['FileName'] = filename >>>> IndexError: list index out of range >>>> >>>> Now it would be very welcome, >>>> if the error message specified which index is out of range, >>>> in this case e.g., >>>> - specifying the length of self.EP >>>> - specifying the value of self.EP[2] >>>> - specifying the length of self.Brick.Par etc.. >>>> >>>> Is there a way to override the error message and provide this >>>> information, or is it impossible ? >>>> >>>> And if it's possible, am I the only one who often stumbles >>>> about this problem ? >>>> (I expect many people must have bounced in this problem before me ;-) >>>> > > FYI, top posts are much harder to read and to reply to than if you edit > the message to which you are replying and add your new content interleaved > or at the bottom (as I have done). > ??? I read that before, but I can't understand it. I think that depends totally on the mail reader you use (although I don't know any mail reader that scrolls to the bottom). I use Thunderbird, which opens every message at the top, so top posting is the best readable for me, I don't have to scroll (assuming that I know from previous readings the content of the previous message). Replying can be preset in any reader I know just as you like, bottom or top. So I guess there must be another reason, why some (or maybe even everyone except me) don't prefer top posting. > No you are not the only one who wishes the error messages were > more informative. In one complex application I had, I made my life > easier with a hack I copied from Zope. Briefly, at the top level > of the program I trap all exceptions, get the traceback object from > sys.exc_info, format it with format_tb, and then process it to add info. > I applied several enhancements, but the one relevant to you was to grab > the locals dictionary from the last frame of the traceback, and use a > regex to split the last source line in the formatted traceback up into > candidate variable names. Then I printed the name and the repr of the > value of any of those names I found in the locals dict. > > That wouldn't tell you directly which variable it was threw the index > error, but having the current values of the variables involved saves a > lot of time (no need to go back and stick in prints in many cases). > > (You know, I really ought to revisit that routine and make it part > of my standard development toolbox.) > > well that sound good, but contains a lot of suggestions with which I'm not familiar. Could please post some code snippets ? thanks, Stef Mientki > --RDM > > -- > http://mail.python.org/mailman/listinfo/python-list > From tjreedy at udel.edu Mon Feb 23 13:40:39 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 23 Feb 2009 13:40:39 -0500 Subject: can error messages be improved or can they be overridden ? In-Reply-To: <49A272F1.7090004@gmail.com> References: <49A1567B.5020407@gmail.com> <7F0503CD69378F49BE0DC30661C6CCF62783D690@enbmail01.lsi.com> <49A272F1.7090004@gmail.com> Message-ID: Stef Mientki wrote: > thanks Ron, > > but I was looking for a more general solution, > in which I don't change the program itself, > and where the error messages (in general) become more informative than > it is by default. Improving error messages is an ongoing project. I submitted feature request http://bugs.python.org/issue5353 Improve IndexError messages with actual values We can only hope someone will get 'bugged' to write a patch. Terry From python.list at tim.thechases.com Mon Feb 23 13:43:44 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 23 Feb 2009 12:43:44 -0600 Subject: Peculiar swap behavior Message-ID: <49A2EE60.1060300@tim.thechases.com> I stumbled across this oddity and was hoping folks on the list might be able to provide a little understanding: # swap scalars >>> x,y = 1,2 >>> x,y = y,x >>> x,y (2, 1) # swap lists >>> a,b = [1,2,3],[4,5,6] >>> a,b = b,a >>> a,b ([4, 5, 6], [1, 2, 3]) # swap list contents...not so much... >>> m,n = [1,2,3],[4,5,6] >>> m[:],n[:] = n,m >>> m,n ([4, 5, 6], [4, 5, 6]) The first two work as expected but the 3rd seems to leak some internal abstraction. It seems to work if I force content-copying: >>> m[:],n[:] = n[:],m[:] or even just >>> m[:],n[:] = n,m[:] but not >>> m[:],n[:] = n[:],m Is this a bug, something Python should smack the programmer for trying, or just me pushing the wrong edges? :) Thanks, -tkc From benjamin.kaplan at case.edu Mon Feb 23 13:49:02 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 23 Feb 2009 13:49:02 -0500 Subject: can error messages be improved or can they be overridden ? In-Reply-To: <49A2ECDD.8040600@gmail.com> References: <49A1567B.5020407@gmail.com> <7F0503CD69378F49BE0DC30661C6CCF62783D690@enbmail01.lsi.com> <49A272F1.7090004@gmail.com> <49A2ECDD.8040600@gmail.com> Message-ID: On Mon, Feb 23, 2009 at 1:37 PM, Stef Mientki wrote: > rdmurray at bitdance.com wrote: > >> >> FYI, top posts are much harder to read and to reply to than if you edit >> the message to which you are replying and add your new content interleaved >> or at the bottom (as I have done). >> >> > ??? I read that before, but I can't understand it. > I think that depends totally on the mail reader you use (although I don't > know any mail reader that scrolls to the bottom). > I use Thunderbird, which opens every message at the top, > so top posting is the best readable for me, > I don't have to scroll (assuming that I know from previous readings the > content of the previous message). > Replying can be preset in any reader I know just as you like, bottom or > top. > So I guess there must be another reason, why some (or maybe even everyone > except me) don't prefer top posting. It's because of your caveat. Many of us don't remember the exact content of the threads, especially the complicated ones that result in several branches. When you post underneath, we can see how the thread progressed as we scroll down. It makes it easier to follow without digging through all the other messages. -------------- next part -------------- An HTML attachment was scrubbed... URL: From google at mrabarnett.plus.com Mon Feb 23 13:49:55 2009 From: google at mrabarnett.plus.com (MRAB) Date: Mon, 23 Feb 2009 18:49:55 +0000 Subject: unescape escapes in strings In-Reply-To: References: Message-ID: <49A2EFD3.70809@mrabarnett.plus.com> bvdp wrote: > MRAB wrote: >> bvdp wrote: >>> >>> When reading lines of data from a file in the from (no quotes!) >>> >>> foo\x20bar >>> >>> and I assign to a variable in a line line like: >>> >>> f = file('infile', 'r') >>> for a in f: >>> print a >>> >>> the string is read in as string with the literal characters 'f', 'o' >>> ... 'x' , '2' ... >>> >>> as compared to an assignment like: >>> >>> a="foo\x20bar" >>> >>> which is identical to >>> >>> a="foo bar" >>> >>> Okay, so far ... I think this is what I want since my program is >>> using space characters as delimiters and I'm trying to use the \x20 >>> notation to avoid splitting. >>> >>> But, now the problem. When I finally assign the string with the \x20 >>> to a variable the literals are still there. And here I really want >>> them all nicely converted to the desired values. >>> >>> So, the question is: is there an "unescape()" for strings so that >>> "foo\x20bar" is converted to "foo bar"???? >>> >> >>> a = r"foo\x20bar" >> >>> print a >> foo\x20bar >> >>> a = a.decode("string-escape") >> >>> print a >> foo bar >> > > Thanks ... I think in my original testing I tried decode() but it didn't > work. Testing more ... > > the file has 2 lines: > foo bar > foo\x20bar > > and the program to read is: > f=file('in', 'r') > for a in f: > a = a.strip() > a=a.decode() You didn't specify what kind of decoding you want! > print list(a) > > I get: > > python read.py > [] > [u'f', u'o', u'o', u' ', u'b', u'a', u'r'] > [u'f', u'o', u'o', u'\\', u'x', u'2', u'0', u'b', u'a', u'r'] > > So, the \x20 is still literal. > > Any other ideas??? I suppose I could write a re expression ... but > surely that is not needed??? > From darcy at druid.net Mon Feb 23 13:54:47 2009 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Mon, 23 Feb 2009 13:54:47 -0500 Subject: Top posting In-Reply-To: <49A2ECDD.8040600@gmail.com> References: <49A1567B.5020407@gmail.com> <7F0503CD69378F49BE0DC30661C6CCF62783D690@enbmail01.lsi.com> <49A272F1.7090004@gmail.com> <49A2ECDD.8040600@gmail.com> Message-ID: <20090223135447.184e31bb.darcy@druid.net> On Mon, 23 Feb 2009 19:37:17 +0100 Stef Mientki wrote: > > FYI, top posts are much harder to read and to reply to than if you edit > > the message to which you are replying and add your new content interleaved > > > ??? I read that before, but I can't understand it. It is very simple. The critical part above is "...edit the message..." If you leave a 200 line message in your reply to discuss three lines then it won't matter whether you top post or bottom post. You still make it difficult for others to read your posting. > I use Thunderbird, which opens every message at the top, > so top posting is the best readable for me, Only if the previous poster didn't trim their text. Notice how I have removed everything here that I am not replying to. I doubt very much if you have to scroll down to start reading my response. You can also tell at a glance that this is not a "me too" response. > I don't have to scroll (assuming that I know from previous readings the > content of the previous message). But how do you know what part of the message is being replied to? > Replying can be preset in any reader I know just as you like, bottom or top. > So I guess there must be another reason, why some (or maybe even > everyone except me) don't prefer top posting. Ah, that makes sense. Because it is not the usual way we read the flow of a conversation. What is so bad about top posting? How long did you waste on the above exchange before reversing the lines in your head? The bottom line is that thousands of people are reading your reply but only one (you) is writing it. It just makes sense for you to take an extra ten seconds to save thousands of people two seconds reading it. It is polite and considerate to others. If everyone did the same you would also save because you read many more posts than you write. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From bob at mellowood.ca Mon Feb 23 13:55:04 2009 From: bob at mellowood.ca (bvdp) Date: Mon, 23 Feb 2009 11:55:04 -0700 Subject: unescape escapes in strings In-Reply-To: References: Message-ID: Perfect ... thanks. >>> >>> a = a.decode("string-escape") Using "string-escape" does the trick! Wonderful, this python. And the quick answers on this group. From bnsilinux at gmail.com Mon Feb 23 13:55:52 2009 From: bnsilinux at gmail.com (Ben) Date: Mon, 23 Feb 2009 10:55:52 -0800 (PST) Subject: Which group ... Message-ID: <17470b68-f175-4ab8-99de-e51560a8e86e@s14g2000vbp.googlegroups.com> Ok, thanks ... I am going to be asking a lot of questions now ;-> From lists at cheimes.de Mon Feb 23 14:08:44 2009 From: lists at cheimes.de (Christian Heimes) Date: Mon, 23 Feb 2009 20:08:44 +0100 Subject: A tale of two execs In-Reply-To: <652cdc53-584d-49ca-891c-350465fe9ebf@u38g2000yqe.googlegroups.com> References: <4e5f94f2-2707-4a4d-b48b-b97759225bef@j35g2000yqh.googlegroups.com> <652cdc53-584d-49ca-891c-350465fe9ebf@u38g2000yqe.googlegroups.com> Message-ID: bieffe62 at gmail.com wrote > I checked, and, for windows platform subprocess.py uses the modules > mvscrt and _subprocess, which I ham unable to > locate on my windows XP python 2.6 installation. This make the whole > thing harder, even impossible if _subprocess has > been created especially for subprocess.py. Some modules are built into pythonXX.dll. You won't find them in the file system. The subprocess module either requires _subprocess or it can be switched to pywin32. Check out the head of the file! Christian From lists at cheimes.de Mon Feb 23 14:10:12 2009 From: lists at cheimes.de (Christian Heimes) Date: Mon, 23 Feb 2009 20:10:12 +0100 Subject: A tale of two execs In-Reply-To: References: Message-ID: aha wrote > def runner(cmd, stdin, stdout, ...): > try: > import subprocess > sbm = 1 > except: > sbm = 0 > > # Now do something > if sbm: > process = subporcess(...) > else: > import popen2 > process = popen2.Popen4(...) > > Has anyone else run into a situation similar to this one? The canonical way for your try/except clause is: try: import subprocess except ImportError: subprocess = None ... if subprocess is not None: ... else: ... Christian From Scott.Daniels at Acm.Org Mon Feb 23 14:11:33 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 23 Feb 2009 11:11:33 -0800 Subject: Python Imaging Library (PIL): create PDF from scratch In-Reply-To: References: Message-ID: zelegolas wrote: > Hi, > > I have some scan generated by SANE and i would like to do some > transformation (like crop, brightness and resize) and finaly put all > those images in PDF file. > > With PIL i can do all the transformations that i want. But i don't > know how i can create from scratch a PDF. I'm not even sure that PIL > is the right library for that. > > Any help/informations will be appreciate Use PIL to fiddle the individual images, and reportlab to build a pdf from the (now tweaked) images. --Scott David Daniels Scott.Daniels at Acm.Org From yatsek at gmail.com Mon Feb 23 14:11:57 2009 From: yatsek at gmail.com (yatsek at gmail.com) Date: Mon, 23 Feb 2009 11:11:57 -0800 (PST) Subject: Python, HTTPS (SSL), tlslite and metoda POST (and lots of pain) Message-ID: <7f2676dd-a87c-4d0f-9f21-bcf2ce6d47fa@n10g2000vbl.googlegroups.com> Hi there. Since quite long time I'm trying to achieve following things: - for some sort of testing I need webserver with https access - with POST method implemented I found something which fits it in nicely written in Python, connected my toys and... server hangs in some weird "inter-state" while serving POST method Below server code: ------------------------- #!/usr/bin/python from SocketServer import * from BaseHTTPServer import * from SimpleHTTPServer import * from tlslite.api import * import string,cgi,time from os import curdir, sep s = open("./server.pem").read() x509 = X509() x509.parse(s) certChain = X509CertChain([x509]) s = open("./server.pem").read() privateKey = parsePEMKey(s, private=True) sessionCache = SessionCache() #class MyHandler(BaseHTTPRequestHandler): class MyHandler(SimpleHTTPRequestHandler): def do_POST(self): global rootnode try: ctype, pdict = cgi.parse_header(self.headers.getheader ('content-type')) form = cgi.FieldStorage(fp = self.rfile, headers=self.headers, environ={'REQUEST_METHOD':'POST', 'CONTENT_TYPE':self.headers ['content-type']} ) if ctype == 'multipart/form-data': if form.has_key('postdata'): temp_file = open(form['postdata'].filename,'wb') buffer = form['postdata'].file.read() temp_file.write(buffer) temp_file.close() self.send_response(200) #set apriopriate header if you want send something #self.send_header('Content-type', 'text/plain') self.send_header('Content-type', 'text/html') self.end_headers() #... and send it #self.wfile.write('OK') self.wfile.write('Post OK.') except : pass class MyHTTPServer(ThreadingMixIn, TLSSocketServerMixIn, HTTPServer): def handshake(self, tlsConnection): try: tlsConnection.handshakeServer(certChain=certChain, privateKey=privateKey, sessionCache=sessionCache) tlsConnection.ignoreAbruptClose = True return True except TLSError, error: print "Handshake failure:", str(error) return False httpd = MyHTTPServer(('127.0.0.1', 443), MyHandler) #httpd = HTTPServer(('127.0.0.1', 80), MyHandler) httpd.serve_forever() -------------------- And page which is used to serve POST request:
File to post:

File is being nicely send to server but as I've mentioned above server is halted in some interstate. Only after Ctrl+C terminates it confirmation of successful transmition is showed in web browser Choosing to use server without SSL (HTTPServer instead of MyHTTPServer) makes everything work without glitch. I would be happy to hear any suggestions If somebody knows any alternative to achieve similar thing (https + POST method on server side) it would be enough to get my tests working. Thx in advance Greetz Yatsek From bnsilinux at gmail.com Mon Feb 23 14:13:41 2009 From: bnsilinux at gmail.com (Ben) Date: Mon, 23 Feb 2009 11:13:41 -0800 (PST) Subject: Extending Python Questions ..... Message-ID: Ok... Now I can start asking. In My S-Lag Project called, SLAG, I have some function keys that get mapped back to S-lang internal functions. My SLAG project works pretty much like Python (as does the S-Lang). You write a S-lang script that "imports" your extension. module - and all this gets run by the shell/interpreter. I allow function keys to be mapped back internal function(s) inside of the controlling program. My question is which Python C api Do I need to this with ? Do I need to worry about my reference counting since the Python Program is in essence calling a function in itself? Thanks Ben ... From yatsek at gmail.com Mon Feb 23 14:13:46 2009 From: yatsek at gmail.com (yatsek at gmail.com) Date: Mon, 23 Feb 2009 11:13:46 -0800 (PST) Subject: Python, HTTPS (SSL), tlslite and POST method (and lots of pain) Message-ID: <3abda581-de7b-49cc-8f13-bfb85c483ee4@q18g2000vbn.googlegroups.com> Hi there. Since quite long time I'm trying to achieve following things: - for some sort of testing I need webserver with https access - with POST method implemented I found something which fits it in nicely written in Python, connected my toys and... server hangs in some weird "inter-state" while serving POST method Below server code: ------------------------- #!/usr/bin/python from SocketServer import * from BaseHTTPServer import * from SimpleHTTPServer import * from tlslite.api import * import string,cgi,time from os import curdir, sep s = open("./server.pem").read() x509 = X509() x509.parse(s) certChain = X509CertChain([x509]) s = open("./server.pem").read() privateKey = parsePEMKey(s, private=True) sessionCache = SessionCache() #class MyHandler(BaseHTTPRequestHandler): class MyHandler(SimpleHTTPRequestHandler): def do_POST(self): global rootnode try: ctype, pdict = cgi.parse_header(self.headers.getheader ('content-type')) form = cgi.FieldStorage(fp = self.rfile, headers=self.headers, environ={'REQUEST_METHOD':'POST', 'CONTENT_TYPE':self.headers ['content-type']} ) if ctype == 'multipart/form-data': if form.has_key('postdata'): temp_file = open(form['postdata'].filename,'wb') buffer = form['postdata'].file.read() temp_file.write(buffer) temp_file.close() self.send_response(200) #set apriopriate header if you want send something #self.send_header('Content-type', 'text/plain') self.send_header('Content-type', 'text/html') self.end_headers() #... and send it #self.wfile.write('OK') self.wfile.write('Post OK.') except : pass class MyHTTPServer(ThreadingMixIn, TLSSocketServerMixIn, HTTPServer): def handshake(self, tlsConnection): try: tlsConnection.handshakeServer(certChain=certChain, privateKey=privateKey, sessionCache=sessionCache) tlsConnection.ignoreAbruptClose = True return True except TLSError, error: print "Handshake failure:", str(error) return False httpd = MyHTTPServer(('127.0.0.1', 443), MyHandler) #httpd = HTTPServer(('127.0.0.1', 80), MyHandler) httpd.serve_forever() -------------------- And page which is used to serve POST request:
File to post:

File is being nicely send to server but as I've mentioned above server is halted in some interstate. Only after Ctrl+C terminates it confirmation of successful transmition is showed in web browser Choosing to use server without SSL (HTTPServer instead of MyHTTPServer) makes everything work without glitch. I would be happy to hear any suggestions If somebody knows any alternative to achieve similar thing (https + POST method on server side) it would be enough to get my tests working. Thx in advance Greetz Yatsek From sternbrightblade at gmail.com Mon Feb 23 14:15:39 2009 From: sternbrightblade at gmail.com (Tony) Date: Mon, 23 Feb 2009 11:15:39 -0800 Subject: different errors, return outside function and others In-Reply-To: References: Message-ID: Thank You, I now understand what i need to do now, and again Thanks On Mon, Feb 23, 2009 at 1:57 AM, Gabriel Genellina wrote: > En Mon, 23 Feb 2009 07:07:57 -0200, Tony > escribi?: > > ok thank you for that input, this is my first class in programming and its >> the only one the school offers. im pretty sure those are supposed to be >> modules >> that im writting. would it make a difference if those were modules and not >> functions? kinda stupid question there but im trying to learn as much as >> possible. >> > > Each module is a separate file, with extension .py > If you put all your code in a single file, you write a single module. > That's fine in this case, unless it grows to something unmanageable. > > Functions are blocks of code that have a name and "do" something specific, > and usually return some result. They start with the keyword "def". You have > defined several functions already, but called them "modules" in the > comments, that's wrong and may be confusing. > > Also anything with def infront of it example def start(): would be a >> function correct? also im Using 2.5 and the IDLE to do this >> > > Exactly! > > I think you have written so much code without testing it. It's time to test > every piece now. Start with... the start function, obviously! > > But before, you have to clean your code. There are a few strange lines that > should not be there (all those lines on the left margin that aren't "def" > statements, like intro_area(), alley()...). Just remove or comment them. > > Then you can start testing each function, one at a time. Simply call the > function with the desired parameters (if any), right at the bottom of the > file. To test the first one (start), use something like this: > > print "about to call start()" > result = start() > print "start() finished, result=", result > > and do the same for each individual function. Once you know each piece > works fine, you can start combining them until you build the complete > program. > > > -- > Gabriel Genellina > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bblais at bryant.edu Mon Feb 23 14:17:04 2009 From: bblais at bryant.edu (Brian Blais) Date: Mon, 23 Feb 2009 14:17:04 -0500 Subject: Reference or Value? In-Reply-To: References: <39e19a010902222154m1d2af37vea53e17578331939@mail.gmail.com> Message-ID: <6D420E20-FFC0-407B-ADCD-10D541E8C3CA@bryant.edu> On Feb 23, 2009, at 3:03 , Gabriel Genellina wrote: > En Mon, 23 Feb 2009 03:54:16 -0200, Denis Kasak > escribi?: > >> On Mon, Feb 23, 2009 at 5:09 AM, Steven D'Aprano >> wrote: >>> On Sun, 22 Feb 2009 13:37:27 -0300, andrew cooke wrote: >>> >>>> as far as i understand things, the best model is: >>>> >>>> 1 - everything is an object >>>> 2 - everything is passed by reference >>> >>> Except that is wrong. If it were true, you could do this: >>> >>> def swap(x, y): >>> y, x = x, y >>> >>> a = 1 >>> b = 2 >>> swap(a, b) >>> assert a == 2 and b == 1 >>> >>> >>> but you can't, it does not work. Ergo, parameter passing in >>> Python does >>> not have the same semantics as languages that use pass-by- >>> reference, such >>> as Pascal and Basic. That means that even if you can justify the >>> claim >>> "Python is pass-by-reference" by some technical argument (and I >>> don't >>> believe you can), it is misleading to make that claim without >>> further >>> qualifications. >> >> You could, however, argue that the swap function doesn't work as >> expected (e.g. from a Pascal or a C++ POV) simply because the >> underlying objects aren't mutable. > > That's irrelevant - mutable and immutable objects are passed > exactly the same way. > I don't think they were saying that mutable and immutable objects were handled differently. They are different in terms of what a function can do to them (mutate them or no). Thus, if you can't mutate them, then the caller can't see any changes in the objects by actions in the function so the swap won't work: it doesn't mutate the objects at all. In the case of a list or a dict, then one can mutate them, and the changes are seen in the caller. In both cases, the object itself is passed the same way. bb -- Brian Blais bblais at bryant.edu http://web.bryant.edu/~bblais -------------- next part -------------- An HTML attachment was scrubbed... URL: From adleslie at gmail.com Mon Feb 23 14:17:42 2009 From: adleslie at gmail.com (May) Date: Mon, 23 Feb 2009 11:17:42 -0800 (PST) Subject: python sql query in django Message-ID: <9c401cce-88c3-48b1-a6a5-288d2b897ba3@v19g2000yqn.googlegroups.com> I have three tables: class Technology(models.Model): technology = models.CharField(max_length=100, null=True, blank=True ) def __unicode__(self): return self.technology class Meta: ordering = ["technology"] class Publication(models.Model): pubtitle = models.TextField(null=True, blank=True) def __unicode__(self): return self.pubtitle class Meta: ordering = ["pubtitle"] class Techpubcombo(models.Model): technology = models.ForeignKey(Technology) publication = models.ForeignKey(Publication) The user selects a technology from the drop down menu on the web page. The technology is retrieved from the database table and then it must be used to retrieve the publication attributes, by first going through the Techpubcombo table. I wrote the select to retrieve the data for the html drop down box: technology_list = Technology.objects.all().order_by('technology') After the user makes a selection, the technology_id is retrieved: technology_id = request.POST['technology_id'] t = get_object_or_404(Technology, pk=technology_id) Now I need to use the technology_id to get to the publication attributes This is where I'm stuck. I get error messages when I try to do something like: pub=t.techpubcombo.publications_set() Ana From woodygar at sky.com Mon Feb 23 14:22:16 2009 From: woodygar at sky.com (Gary Wood) Date: Mon, 23 Feb 2009 19:22:16 -0000 Subject: Can someone tell me why i get None at the end please this has me stuck for ages Message-ID: '''exercise to complete and test this function''' import string def joinStrings(items): '''Join all the strings in stringList into one string, and return the result. For example: >>> print joinStrings(['very', 'hot', 'day']) 'veryhotday' ''' word = [items] for item in items: print (item, end='') def main(): print(joinStrings(['very', 'hot','day'])) print(joinStrings(['this', 'is','it'])) print(joinStrings(['1', '2', '3', '4', '5'])) main() -------------- next part -------------- An HTML attachment was scrubbed... URL: From lionel.keene at gmail.com Mon Feb 23 14:24:46 2009 From: lionel.keene at gmail.com (Lionel) Date: Mon, 23 Feb 2009 11:24:46 -0800 (PST) Subject: "import" not working? References: <7f0d1540-ae7e-4da1-936e-afbc8c6d2d49@k19g2000yqg.googlegroups.com> <11062739-5a43-43d8-b4a2-9bd494230992@t13g2000yqc.googlegroups.com> <65f8a016-a4c1-48c0-8128-47f62b865a6f@m40g2000yqh.googlegroups.com> Message-ID: On Feb 21, 12:37?am, "Gabriel Genellina" wrote: > En Fri, 20 Feb 2009 22:40:03 -0200, Lionel ? > escribi?: > > > Okay, moving the wx example into the same directory containing the > > first example that was working fixed it. This directory only contains > > these two modules and nothing else. The old directory which contained > > the example that wasn't working did not contain a module with the same > > name as the one I was trying to import, so i don't know why this "fix" > > worked. > > Just play safe: > > - Don't use "from xxx import *", least from two places at the same time. ? > The wx package has a short name on purpose - use "import wx" and then ? > wx.Frame, etc. > > - Don't play with sys.path if you don't have to; you can put your own ? > modules in a place already listed (like Lib\site-packages). Or, use a .pth ? > file if you want to add a copmletely separate directory like ? > c:\DataFileTypes > > -- > Gabriel Genellina Okay, I've moved the module directory. Originally I had a Python module named "DataFileTypes.py" in the "C:\DataFileTypes" folder. (the complete path is therefore "C:\DataFileTypes\DataFileTypes.py"). To access object types in this module from other Pyhton modules I specified the following: import sys sys.path.append("C:\DataFileTypes") from DataFileTypes import * The above 3 lines of code are contained at the begining of a module whose complete path is "C:\Python path test\Test.py". This folder only contains this module and two other unrelated python files I've written. At the moment this works fine i.e. Python is able to find the DataFileTypes.py module at its location using the "sys.path.append / import" statements above. However, now I've moved the "DataFileTypes" folder containing the module so that the new complete path is: "C:\Python25\Lib\site-packages\DataFileTypes\DataFileTypes.py" At this point I print the sys.path from the Python shell: IDLE 1.2.4 >>> import sys >>> print sys.path ['C:\\Python25\\Lib\\idlelib', 'C:\\WINDOWS\\system32\\python25.zip', 'C:\\Python25\\DLLs', 'C:\\Python25\\lib', 'C:\\Python25\\lib\\plat- win', 'C:\\Python25\\lib\\lib-tk', 'C:\\Python25', 'C:\\Python25\\lib\ \site-packages', 'C:\\Python25\\lib\\site-packages\\wx-2.8-msw- unicode'] >>> "...\site-packages" is indeed listed on the path. I now remove: import sys sys.path.append("c:\DataFileTypes") from DataFileTypes import * from the invoking module and replace it with: from DataFileTypes import * When I attempt to run the Test.py program after these changes I get error messages claiming: "except DataFileError: NameError: name 'DataFileError' is not defined" I get an error again claiming that my custom exception "DataFileError" declared in "DataFileTypes" is not defined. Why does this work fine when I have my module in the root directory and append the sys.path, but stops working when I put the module in another directory already resident in the sys.path? From rob.clewley at gmail.com Mon Feb 23 14:26:18 2009 From: rob.clewley at gmail.com (Rob Clewley) Date: Mon, 23 Feb 2009 14:26:18 -0500 Subject: Can someone tell me why i get None at the end please this has me stuck for ages In-Reply-To: References: Message-ID: You get None b/c that's what's being returned from your join strings function. Your function already prints out the result and doesn't return the joined strings a your usage case expects. So either return the joined strings from your function and don't print them inside the function, or vice versa. Besides, can't you just use print "".join(list_of_strings) ? On Mon, Feb 23, 2009 at 2:22 PM, Gary Wood wrote: > '''exercise to complete and test this function''' > import string > def joinStrings(items): > '''Join all the strings in stringList into one string, > and return the result. For example: > >>> print joinStrings(['very', 'hot', 'day']) > 'veryhotday' > ''' > word = [items] > for item in items: > print (item, end='') > > > def main(): > print(joinStrings(['very', 'hot','day'])) > print(joinStrings(['this', 'is','it'])) > print(joinStrings(['1', '2', '3', '4', '5'])) > > main() > From marduk at letterboxes.org Mon Feb 23 14:27:25 2009 From: marduk at letterboxes.org (Albert Hopkins) Date: Mon, 23 Feb 2009 14:27:25 -0500 Subject: Can someone tell me why i get None at the end please this has me stuck for ages In-Reply-To: References: Message-ID: <1235417245.27041.2.camel@localhost.localdomain> On Mon, 2009-02-23 at 19:22 +0000, Gary Wood wrote: > '''exercise to complete and test this function''' > import string > def joinStrings(items): > '''Join all the strings in stringList into one string, > and return the result. For example: > >>> print joinStrings(['very', 'hot', 'day']) > 'veryhotday' > ''' > word = [items] > for item in items: > print (item, end='') > > > def main(): > print(joinStrings(['very', 'hot','day'])) > print(joinStrings(['this', 'is','it'])) > print(joinStrings(['1', '2', '3', '4', '5'])) > > main() Your function, joinStrings() doesn't return a value. In Python a function that doesn't return a value explicitly returns None by default. So your print statements in main() will all print None. From stef.mientki at gmail.com Mon Feb 23 14:29:42 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Mon, 23 Feb 2009 20:29:42 +0100 Subject: Top posting In-Reply-To: <20090223135447.184e31bb.darcy@druid.net> References: <49A1567B.5020407@gmail.com> <7F0503CD69378F49BE0DC30661C6CCF62783D690@enbmail01.lsi.com> <49A272F1.7090004@gmail.com> <49A2ECDD.8040600@gmail.com> <20090223135447.184e31bb.darcy@druid.net> Message-ID: <49A2F926.5010207@gmail.com> I agree that top posting on a message like this is not very convenient, but for simple messages ... D'Arcy J.M. Cain wrote: > On Mon, 23 Feb 2009 19:37:17 +0100 > Stef Mientki wrote: > >>> FYI, top posts are much harder to read and to reply to than if you edit >>> the message to which you are replying and add your new content interleaved >>> >>> >> ??? I read that before, but I can't understand it. >> > > It is very simple. The critical part above is "...edit the > message..." If you leave a 200 line message in your reply to discuss > three lines then it won't matter whether you top post or bottom post. > You still make it difficult for others to read your posting. > > I think not the way in which the result is reached, but the result itself is important, and i like to get to the result as fast as possible. That's why in simple messages, I find top posting is more convenient. Version history is often (always?) written in reversed chronological order, you're only interested in the few last ones. >> I use Thunderbird, which opens every message at the top, >> so top posting is the best readable for me, >> > > Only if the previous poster didn't trim their text. Notice how I have > removed everything here that I am not replying to. I doubt very much > if you have to scroll down to start reading my response. You can also > tell at a glance that this is not a "me too" response. > Trimming is very useful and it's done too little. If you read mail by gmail (which I also do), you would love that everyone top posts (as you very fast open/close messages and see the top of the messages without scrolling) > >> I don't have to scroll (assuming that I know from previous readings the >> content of the previous message). >> > > But how do you know what part of the message is being replied to? > simple messages, 1 issue ? > >> Replying can be preset in any reader I know just as you like, bottom or top. >> So I guess there must be another reason, why some (or maybe even >> everyone except me) don't prefer top posting. >> > > Ah, that makes sense. > Because it is not the usual way we read the flow of a conversation. > What is so bad about top posting? > > How long did you waste on the above exchange before reversing the lines > in your head? > I do it already more than 10 years, and I mean that !! When I write a report, almost nobody is interested in all investigations, arguments, most are only interested in the conclusion and is therefor always on top. By not top-posting on simple messages, we stick to the middle ages and prevent development of new ideas. > The bottom line is that thousands of people are reading your reply but > only one (you) is writing it. It just makes sense for you to take an > extra ten seconds to save thousands of people two seconds reading it. > It is polite and considerate to others. If everyone did the same you > would also save because you read many more posts than you write. > > If it's considered polite, I will try to best next time I post to this group. But I'm not convinced that it saves time for anyone. btw, it's also polite (in some cultures) to sign your messages ;-) ( I don't want to start a flame war, so this is my last response to this thread) cheers, Stef Mientki From bdesth.quelquechose at free.quelquepart.fr Mon Feb 23 14:31:15 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Mon, 23 Feb 2009 20:31:15 +0100 Subject: python sql query in django In-Reply-To: <9c401cce-88c3-48b1-a6a5-288d2b897ba3@v19g2000yqn.googlegroups.com> References: <9c401cce-88c3-48b1-a6a5-288d2b897ba3@v19g2000yqn.googlegroups.com> Message-ID: <49a3071a$0$18735$426a34cc@news.free.fr> May a ?crit : > I have three tables: Actually - from Python's code POV - three Model classes. And actually, since there's a very active, friendly and helpful django group on googlegroups, you'd be better reposting your question there. (snip Django's ORM related question) From joshua at joshuakugler.com Mon Feb 23 14:33:45 2009 From: joshua at joshuakugler.com (Joshua Kugler) Date: Mon, 23 Feb 2009 10:33:45 -0900 Subject: urllib2 login help References: <4612e1c1-3e1e-48ee-9780-312fff074bad@i38g2000yqd.googlegroups.com> Message-ID: You also might want to look at http://wwwsearch.sourceforge.net/mechanize/ It will do most of the hard stuff for you (sending form elements, keeping track of cookies, etc.). j john.weatherwax at gmail.com wrote: > Hello, > > I'm having trouble using urllib2 (maybe) when trying to log into a web > site that requires a user to enter a login name and a password > (authentication). I've tried many things but none seem to work and > have become stuck recently and was hoping to get a hint from those > much more knowledgeable than myself. > > I want to automate logging on to the investopedia stock simulator web > site. > > http://simulator.investopedia.com/authorization/login.aspx > > I can't seem to automate this successfully. > > My python script is below: > > import os,re > import urllib, urllib2 > > theurl = "http://simulator.investopedia.com/authorization/login.aspx" > > post_dict = { "ct100$MainPlaceHolder$usernameText": "XXX", > "ct100$MainPlaceHolder$passwordText": "XXX", "ct100$MainPlaceHolder > $loginButton": "Sign In", "ct100$MainPlaceHolder$rememberMeCheckBox": > "on" } > > post_data = urllib.urlencode( post_dict ) > > headers = { 'User-agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows > NT)', > 'Host': 'simulator.investopedia.com', > 'Referer': 'http://simulator.investopedia.com/ > authorization/login.aspx', > } > > req = urllib2.Request( theurl, post_data, headers ) > response = urllib2.urlopen(req) > the_page = response.read() > > The problem is that this page returned seems to be the same as the > login page which I connected to initially. When I perform the login > process manually things work as expected. What am I doing > incorrectly? > > *ANY* hints/suggestions/directions would be very appreciated since > I've run out of ideas of things to try at this point. > > Thanks very much > > > -- > http://mail.python.org/mailman/listinfo/python-list From lists at cheimes.de Mon Feb 23 14:41:42 2009 From: lists at cheimes.de (Christian Heimes) Date: Mon, 23 Feb 2009 20:41:42 +0100 Subject: Reference or Value? In-Reply-To: <39e19a010902222154m1d2af37vea53e17578331939@mail.gmail.com> References: <39e19a010902222154m1d2af37vea53e17578331939@mail.gmail.com> Message-ID: Denis Kasak wrote > You could, however, argue that the swap function doesn't work as > expected (e.g. from a Pascal or a C++ POV) simply because the > underlying objects aren't mutable. The objects *do* get passed by > reference; We are getting down the same road every couple of months. Please don't explain Python's calling system with terms like "call by reference". It's plain simple wrong. The correct term is "call by sharing" or "call by object reference" although I myself don't use the latter term because it sounds too much like "call by reference". Every time somebody tries to explain Python with "call by reference", the person is confusing himself and others. Christian From david.birdsong at gmail.com Mon Feb 23 14:49:03 2009 From: david.birdsong at gmail.com (birdsong) Date: Mon, 23 Feb 2009 11:49:03 -0800 (PST) Subject: Python shell scripting and errors References: <0b33c75d-807b-4a64-acec-4c6486893552@l22g2000vba.googlegroups.com> <1235409711.12946.31.camel@tim-laptop> Message-ID: <96c8cd5f-7b26-4c81-9b80-b80e9c70aaef@j8g2000yql.googlegroups.com> On Feb 23, 9:34?am, Philip Semanchuk wrote: > On Feb 23, 2009, at 12:21 PM, Tim Wintle wrote: > > > On Mon, 2009-02-23 at 09:12 -0800, Phillip B Oldham wrote: > >> I've got a python script running as a daemon (using someone else's > >> daemon module). It runs fine for a while, but will occasionally balk > >> and die. Since its running in the background, I'm getting no error > >> from it. > > >> What's the best way to capture the output into a file for later ? > >> review? > > > Point standard out to an open file handle? > > And stderr. > > I don't know how the OP's daemon is being launched, but the crontab ? > command below worked for me for redirecting errors to a log file ? > without the need to modify the script. > > python /usr/local/foo/bar.py >> /var/log/foo/bar.txt 2>&1 If the daemon module is worth it's salt, it will have probably closed all open filehandles including STDOUT and STDERR. So this might not work. If all you want is some temporary debugging, add some redirection for stdout and stderr after you daemonize. import sys sys.stderr = open('/path/to/suitable_stderr_file', 'w') sys.stdout = open('/path/to/suitable_stdout_file', 'w') I'm pretty sure this should catch any tracebacks. > > HTH > Philip From denis.kasak at gmail.com Mon Feb 23 14:58:42 2009 From: denis.kasak at gmail.com (Denis Kasak) Date: Mon, 23 Feb 2009 20:58:42 +0100 Subject: Reference or Value? In-Reply-To: References: <39e19a010902222154m1d2af37vea53e17578331939@mail.gmail.com> Message-ID: <39e19a010902231158r27605a7bq72adbd99f29e6032@mail.gmail.com> On Mon, Feb 23, 2009 at 8:41 PM, Christian Heimes wrote: > Denis Kasak wrote >> You could, however, argue that the swap function doesn't work as >> expected (e.g. from a Pascal or a C++ POV) simply because the >> underlying objects aren't mutable. The objects *do* get passed by >> reference; > > We are getting down the same road every couple of months. Please don't > explain Python's calling system with terms like "call by reference". > It's plain simple wrong. The correct term is "call by sharing" or "call > by object reference" although I myself don't use the latter term because > it sounds too much like "call by reference". Every time somebody tries > to explain Python with "call by reference", the person is confusing > himself and others. I assure you I am not confused about Python's object model / calling system. I was arguing, from a purely theoretical standpoint, that the same system Python uses could be described in terms of call-by-reference with some additional constraints. I am by no means arguing that this is a good way of explaining it or trying to explain it to someone in terms of call-by-reference. I just don't think it's "plain simple wrong", just confusing and suboptimal. -- Denis Kasak From bdesth.quelquechose at free.quelquepart.fr Mon Feb 23 15:02:22 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Mon, 23 Feb 2009 21:02:22 +0100 Subject: Server programming In-Reply-To: References: Message-ID: <49a30e64$0$20701$426a74cc@news.free.fr> koranthala a ?crit : > Hi, > Is server programming in Python procedure oriented or object > oriented? It's how you want it to be. > I have this question because lately I am asked to make a medium > complex web program (extremely database oriented) using Django. When I > used to do application programs earlier (in Python itself), the whole > thing being object oriented came out easily in programming. So, I was > able to use different patterns etc for programming and the whole thing > was - quite fun to design and create. > But when I program in Django, since I just have to work on user > responses - everything else being taken care of by Django - only, the > complete coding has become procedure oriented. It is not kludgy or > anything, but it doesnt have the nice feeling that we get when we code > a proper object oriented program. So you may want to learn to enjoy the nice feeling we get when we code a proper procedural program - or a proper functional one FWIW !-) There's nothing inherently wrong with procedural programming. Nor with a mix of procedural, OO and functional code - which is usually the case in Python. It's just a matter of using the right tool for the problem to solve. > Is my coding in error here? Don't know - I don't have access to your code. But my experience with Django is that I tend to have quite a lot of code in models and templatetags, and much less in the views themselves. So I wouldn't say that "Django takes care of everything else". If you really ends up writing pages upon pages of repeting procedural code in your views and nothing in the other parts of the app, then yes, there might be something wrong - probably a case of AnemicDomainModel, and possibly a lack of knowledge of the whole framework. One of the reasons views are usually implemented as functions is that in most cases, you shouldn't have a need for more. FWIW, you sometimes don't even need to write a specific view - Django's GenericViews can handle quite a lot of cases Note also that Django doesn't _require_ that you use functions as view handlers - any callable object will do. But given how the HTTP protocol works and how Django is designed, there's more often than not just no *need* for a custom callable object. And finally, as Steve already mentioned, OO is first about objects, and that's what you're dealing with in your views - request objects, session objects, model objects etc... > This is infact my first web program, > so it might be the reason. What does other people find? Does web > server programming using web frameworks (Django, TurboGears etc) make > it procedure oriented? Not necessarily, no. Some frameworks requires your request handlers to be methods of classes FWIW, and nothing in Django prevents you from doing so if you want. > If I am in the wrong, it might be due to a > wrong design or mindset, and I would like to change it. From steve at holdenweb.com Mon Feb 23 15:03:58 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 23 Feb 2009 15:03:58 -0500 Subject: Python, HTTPS (SSL), tlslite and metoda POST (and lots of pain) In-Reply-To: <7f2676dd-a87c-4d0f-9f21-bcf2ce6d47fa@n10g2000vbl.googlegroups.com> References: <7f2676dd-a87c-4d0f-9f21-bcf2ce6d47fa@n10g2000vbl.googlegroups.com> Message-ID: yatsek at gmail.com wrote: > Hi there. [...] Yatsek: You just "hijacked a thread" by writing your question as a reply to somebody else's post. Be aware that a lot of newsreaders will show it as a part of this other thread rather than giving if a thread of its own, and so many people (who may have skimmed over the other thread) won't see your post! regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From lionel.keene at gmail.com Mon Feb 23 15:10:07 2009 From: lionel.keene at gmail.com (Lionel) Date: Mon, 23 Feb 2009 12:10:07 -0800 (PST) Subject: "import" not working? References: <7f0d1540-ae7e-4da1-936e-afbc8c6d2d49@k19g2000yqg.googlegroups.com> <11062739-5a43-43d8-b4a2-9bd494230992@t13g2000yqc.googlegroups.com> <65f8a016-a4c1-48c0-8128-47f62b865a6f@m40g2000yqh.googlegroups.com> Message-ID: <02ed27ed-4b4f-41b2-b4b8-7914d3f13674@v39g2000yqm.googlegroups.com> On Feb 23, 11:24?am, Lionel wrote: > On Feb 21, 12:37?am, "Gabriel Genellina" > wrote: > > > > > > > En Fri, 20 Feb 2009 22:40:03 -0200, Lionel ? > > escribi?: > > > > Okay, moving the wx example into the same directory containing the > > > first example that was working fixed it. This directory only contains > > > these two modules and nothing else. The old directory which contained > > > the example that wasn't working did not contain a module with the same > > > name as the one I was trying to import, so i don't know why this "fix" > > > worked. > > > Just play safe: > > > - Don't use "from xxx import *", least from two places at the same time. ? > > The wx package has a short name on purpose - use "import wx" and then ? > > wx.Frame, etc. > > > - Don't play with sys.path if you don't have to; you can put your own ? > > modules in a place already listed (like Lib\site-packages). Or, use a .pth ? > > file if you want to add a copmletely separate directory like ? > > c:\DataFileTypes > > > -- > > Gabriel Genellina > > Okay, I've moved the module directory. Originally I had a Python > module named "DataFileTypes.py" in the "C:\DataFileTypes" folder. (the > complete path is therefore "C:\DataFileTypes\DataFileTypes.py"). To > access object types in this module from other Pyhton modules I > specified the following: > > import sys > sys.path.append("C:\DataFileTypes") > from DataFileTypes import * > > The above 3 lines of code are contained at the begining of a module > whose complete path is "C:\Python path test\Test.py". ?This folder > only contains this module and two other unrelated python files I've > written. At the moment this works fine i.e. Python is able to find the > DataFileTypes.py module at its location using the "sys.path.append / > import" statements above. However, now I've moved the "DataFileTypes" > folder containing the module so that the new complete path is: > > "C:\Python25\Lib\site-packages\DataFileTypes\DataFileTypes.py" > > At this point I print the sys.path from the Python shell: > > IDLE 1.2.4>>> import sys > >>> print sys.path > > ['C:\\Python25\\Lib\\idlelib', 'C:\\WINDOWS\\system32\\python25.zip', > 'C:\\Python25\\DLLs', 'C:\\Python25\\lib', 'C:\\Python25\\lib\\plat- > win', 'C:\\Python25\\lib\\lib-tk', 'C:\\Python25', 'C:\\Python25\\lib\ > \site-packages', 'C:\\Python25\\lib\\site-packages\\wx-2.8-msw- > unicode'] > > > > "...\site-packages" is indeed listed on the path. I now remove: > > import sys > sys.path.append("c:\DataFileTypes") > from DataFileTypes import * > > from the invoking module and replace it with: > > from DataFileTypes import * > > When I attempt to run the Test.py program after these changes I get > error messages claiming: > > "except DataFileError: > NameError: name 'DataFileError' is not defined" > > I get an error again claiming that my custom exception "DataFileError" > declared in "DataFileTypes" is not defined. Why does this work fine > when I have my module in the root directory and append the sys.path, > but stops working when I put the module in another directory already > resident in the sys.path?- Hide quoted text - > > - Show quoted text - Taking "DataFileTypes.py" module out of the "...\site-packages \DataFileTypes" folder and placing it directly into the "site- packages" folder seems to have cleared it up. Some problem between package and module usage I suppose. From steve at holdenweb.com Mon Feb 23 15:12:05 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 23 Feb 2009 15:12:05 -0500 Subject: Reference or Value? In-Reply-To: <39e19a010902231158r27605a7bq72adbd99f29e6032@mail.gmail.com> References: <39e19a010902222154m1d2af37vea53e17578331939@mail.gmail.com> <39e19a010902231158r27605a7bq72adbd99f29e6032@mail.gmail.com> Message-ID: Denis Kasak wrote: > On Mon, Feb 23, 2009 at 8:41 PM, Christian Heimes wrote: >> Denis Kasak wrote >>> You could, however, argue that the swap function doesn't work as >>> expected (e.g. from a Pascal or a C++ POV) simply because the >>> underlying objects aren't mutable. The objects *do* get passed by >>> reference; >> We are getting down the same road every couple of months. Please don't >> explain Python's calling system with terms like "call by reference". >> It's plain simple wrong. The correct term is "call by sharing" or "call >> by object reference" although I myself don't use the latter term because >> it sounds too much like "call by reference". Every time somebody tries >> to explain Python with "call by reference", the person is confusing >> himself and others. > > I assure you I am not confused about Python's object model / calling > system. I was arguing, from a purely theoretical standpoint, that the > same system Python uses could be described in terms of > call-by-reference with some additional constraints. I am by no means > arguing that this is a good way of explaining it or trying to explain > it to someone in terms of call-by-reference. I just don't think it's > "plain simple wrong", just confusing and suboptimal. > Well, what's the benefit of discussing such a description, then? Regulars on c.l.py see this subject arising so regularly it's a bit like "there's nothing new under the sun". Honestly, it's been discussed /ad nauseam/ lately. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From deets at nospam.web.de Mon Feb 23 15:18:16 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 23 Feb 2009 21:18:16 +0100 Subject: Extending Python Questions ..... In-Reply-To: References: Message-ID: <70gek8F5ep0jU1@mid.uni-berlin.de> Ben schrieb: > Ok... Now I can start asking. > > In My S-Lag Project called, SLAG, I have some function keys that get > mapped back to S-lang internal functions. > > My SLAG project works pretty much like Python (as does the S-Lang). > You write a S-lang script > that "imports" your extension. module - and all this gets run by the > shell/interpreter. > > I allow function keys to be mapped back internal function(s) inside of > the controlling program. > > My question is which Python C api Do I need to this with ? Do I need > to worry about my reference counting since the Python Program is in > essence calling a function in itself? What's S-Lag? What is S-Lang? I'm sure I can google that, however I think you might want to provide a bit more context yourself to receive better answers. Diez From wolfgang at rohdewald.de Mon Feb 23 15:26:54 2009 From: wolfgang at rohdewald.de (Wolfgang Rohdewald) Date: Mon, 23 Feb 2009 21:26:54 +0100 Subject: Python, HTTPS (SSL), tlslite and metoda POST (and lots of pain) In-Reply-To: References: <7f2676dd-a87c-4d0f-9f21-bcf2ce6d47fa@n10g2000vbl.googlegroups.com> Message-ID: <200902232126.54519.wolfgang@rohdewald.de> On Montag, 23. Februar 2009, Steve Holden wrote: > yatsek at gmail.com wrote: > > Hi there. > [...] > > Yatsek: > > You just "hijacked a thread" by writing your question as a reply to > somebody else's post did he? His mail headers show no reference to any other mail AFAICS -- Wolfgang From nick at craig-wood.com Mon Feb 23 15:31:54 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Mon, 23 Feb 2009 14:31:54 -0600 Subject: Extending Python Questions ..... References: Message-ID: Ben wrote: > In My S-Lag Project called, SLAG, I have some function keys that get > mapped back to S-lang internal functions. > > My SLAG project works pretty much like Python (as does the S-Lang). > You write a S-lang script > that "imports" your extension. module - and all this gets run by the > shell/interpreter. > > I allow function keys to be mapped back internal function(s) inside of > the controlling program. > > My question is which Python C api Do I need to this with ? Do you mean like this? http://code.google.com/p/python-slang Not sure how well maintained it is though. > Do I need to worry about my reference counting since the Python > Program is in essence calling a function in itself? I'm not sure I understand you here, but in general you don't need to worry about reference counting in Python - it all happens behind the scenes. If you are writing a python extension in C then you do need to worry about reference counting - a lot! -- Nick Craig-Wood -- http://www.craig-wood.com/nick From tdelaney at avaya.com Mon Feb 23 15:34:57 2009 From: tdelaney at avaya.com (Delaney, Timothy (Tim)) Date: Tue, 24 Feb 2009 04:34:57 +0800 Subject: Peculiar swap behavior In-Reply-To: <49A2EE60.1060300@tim.thechases.com> Message-ID: Tim Chase wrote: > # swap list contents...not so much... > >>> m,n = [1,2,3],[4,5,6] > >>> m[:],n[:] = n,m > >>> m,n > ([4, 5, 6], [4, 5, 6]) > > > The first two work as expected but the 3rd seems to leak some > internal abstraction. It seems to work if I force content-copying: > > >>> m[:],n[:] = n[:],m[:] > > or even just > > >>> m[:],n[:] = n,m[:] > > but not > > >>> m[:],n[:] = n[:],m > > Is this a bug, something Python should smack the programmer for > trying, or just me pushing the wrong edges? :) For these types of things, it's best to expand the code out. The appropriate expansion of: m,n = [1,2,3],[4,5,6] m[:],n[:] = n,m is: m = [1,2,3] n = [4,5,6] m[:] = n n[:] = m After the third line, m == n, giving the behaviour you see. OTOH, for: m,n = [1,2,3],[4,5,6] m[:],n[:] = n[:],m[:] the expansion is more like: m = [1,2,3] n = [4,5,6] rhs1 = n[:] rhs2 = m[:] m[:] = rhs1 n[:] = rhs2 Tim Delaney From s.selvamsiva at gmail.com Mon Feb 23 15:38:56 2009 From: s.selvamsiva at gmail.com (S.Selvam Siva) Date: Tue, 24 Feb 2009 02:08:56 +0530 Subject: Need to store dictionary in file Message-ID: Hi all, I have a dictionary in which each key is associated with a list as value. eg: *dic={'a':['aa','ant','all']}* The dictionary contains *1.5 lakh keys*. Now i want to store it to a file,and need to be loaded to python program during execution. I expect your ideas/suggestions. Note:I think cPickle,bsddb can be used for this purpose,but i want to know the best solution which runs *faster*. -- Yours, S.Selvam -------------- next part -------------- An HTML attachment was scrubbed... URL: From denis.kasak at gmail.com Mon Feb 23 15:39:53 2009 From: denis.kasak at gmail.com (Denis Kasak) Date: Mon, 23 Feb 2009 21:39:53 +0100 Subject: Reference or Value? In-Reply-To: References: <39e19a010902222154m1d2af37vea53e17578331939@mail.gmail.com> <39e19a010902231158r27605a7bq72adbd99f29e6032@mail.gmail.com> Message-ID: <39e19a010902231239j16903627u19d330821baa0608@mail.gmail.com> On Mon, Feb 23, 2009 at 9:12 PM, Steve Holden wrote: > Denis Kasak wrote: >> I assure you I am not confused about Python's object model / calling >> system. I was arguing, from a purely theoretical standpoint, that the >> same system Python uses could be described in terms of >> call-by-reference with some additional constraints. I am by no means >> arguing that this is a good way of explaining it or trying to explain >> it to someone in terms of call-by-reference. I just don't think it's >> "plain simple wrong", just confusing and suboptimal. >> > Well, what's the benefit of discussing such a description, then? > Regulars on c.l.py see this subject arising so regularly it's a bit like > "there's nothing new under the sun". Honestly, it's been discussed /ad > nauseam/ lately. Someone said upthread that Andrew Cooke was completely wrong and I contested that. :-) I apologise for not being current with the latest discussions. -- Denis Kasak From philip at semanchuk.com Mon Feb 23 15:41:08 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 23 Feb 2009 15:41:08 -0500 Subject: Python C-API Object Allocation In-Reply-To: References: Message-ID: On Feb 21, 2009, at 10:01 AM, William Newbery wrote: > Ive been learning the C-API lately so I can write python extensions > for some of my c++ stuff. > > I want to use the new and delete operators for creating and > destroying my objects. > > The problem is python seems to break it into several stages. tp_new, > tp_init and tp_alloc for creation and tp_del, tp_free and tp_dealloc > for destruction. However c++ just has new which allocates and fully > constructs the object and delete which destructs and deallocates the > object. > > Which of the python tp_* methods do I need to provide and what must > they do to be compatible with python subclassing. > > Also I want to be able to create the object directly in c++ eg > "PyObject *obj = new MyExtensionObject(args);" Hi William, You can't use C++ new and delete to create Python objects. Not if you intend to use them in Python, anyway. Python has its own memory management, reference counting, etc. and C++ knows nothing about that. You could probably cook up an ugly hack that might work, but you'd be swimming against the tide. If you want to create Python objects, you need ask Python to do it. The function PyObject_New() is probably what you want: http://docs.python.org/c-api/allocation.html FYI, there are lists specifically for the Python C API and C++ issues. I don't mean to chase you away from here; plenty of people ask C API questions here. But the other groups are helpful to know about and, having just learned about them myself I'm trying to spread the word. The lists are here: http://mail.python.org/mailman/listinfo Cheers Philip From adleslie at gmail.com Mon Feb 23 15:44:51 2009 From: adleslie at gmail.com (May) Date: Mon, 23 Feb 2009 12:44:51 -0800 (PST) Subject: python sql query in django References: <9c401cce-88c3-48b1-a6a5-288d2b897ba3@v19g2000yqn.googlegroups.com> <49a3071a$0$18735$426a34cc@news.free.fr> Message-ID: On Feb 23, 11:31?am, Bruno Desthuilliers wrote: > May a ?crit : > > > I have three tables: > > Actually - from Python's code POV - three Model classes. And actually, > since there's a very active, friendly and helpful django group on > googlegroups, you'd be better reposting your question there. > > (snip Django's ORM related question) The django users groups suggests using a manytomany field. That works well in the html template, but in the admin tables, the logic for the manytomany field applies to the wrong model and doesn't create a choice for the data entry people. I'm trying to write this without using the manytomany option. Just using the standard relational database model. I need to understand if python can do what I need to do. So far, I've not been successful with an answer in users groups. Ana From bdesth.quelquechose at free.quelquepart.fr Mon Feb 23 15:48:32 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Mon, 23 Feb 2009 21:48:32 +0100 Subject: python sql query in django In-Reply-To: References: <9c401cce-88c3-48b1-a6a5-288d2b897ba3@v19g2000yqn.googlegroups.com> <49a3071a$0$18735$426a34cc@news.free.fr> Message-ID: <49a31936$0$24803$426a74cc@news.free.fr> May a ?crit : (snip) > I may not stay with Django. Nope, but your question was about Django. > I am seriously looking for whether python > can read data from a relational database Of course - as long as there's a Python adapter for your DB. > and send to an html template Of course - as long as it's either a Python templating system or there's a Python binding for this system. > or do I always need some kind of wrapper/interface such as Rails Uh ? Rails is a Ruby framework. > or > Django? No, you don't. If you prefer to reinvent the wheel on each and any part of each an any web app you write, please feel free to do so. > If this is the wrong group to ask that question Which "that" question ?-) For question related to Django's ORM, the django group is indeed a better place (as usual: always use the most specific group / maling list / whatever first). If you have questions (like the above) that are about Python itself, you're at the right place. From tav at espians.com Mon Feb 23 15:50:57 2009 From: tav at espians.com (tav) Date: Mon, 23 Feb 2009 20:50:57 +0000 Subject: Challenge: Please break this! [Python Security] Message-ID: Hey all, As an attempt to convince Python-Dev of the merits of a functions-based approach to security in Python, I've come up with a simple challenge. If enough smart hackers look at this and it holds up, Guido promises to accept a patch which would enable this on both App Engine and future Python versions. So, please try the challenge and let me know how you find it. Thanks! The challenge is simple: * Open a fresh Python interpreter and do: >>> from safelite import FileReader * You can use FileReader to read files on your filesystem * Now find a way to *write* to the filesystem from your interpreter [safelite.py is attached to this mail] Please note that the aim of this isn't to protect Python against crashes/segfaults or exhaustion of resources attacks, so those don't count. I'm keen to know your experiences even if you don't manage to write to the filesystem -- and especially if you do! Dinner and drinks on me for an evening -- when you are next in London or I am in your town -- to the first person who manages to break safelite.py and write to the filesystem. Good luck and thanks! =) -- love, tav plex:espians/tav | tav at espians.com | +44 (0) 7809 569 369 http://tav.espians.com | http://twitter.com/tav | skype:tavespian -------------- next part -------------- A non-text attachment was scrubbed... Name: safelite.py Type: text/x-python-script Size: 5994 bytes Desc: not available URL: From steve at holdenweb.com Mon Feb 23 15:53:21 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 23 Feb 2009 15:53:21 -0500 Subject: Reference or Value? In-Reply-To: <39e19a010902231239j16903627u19d330821baa0608@mail.gmail.com> References: <39e19a010902222154m1d2af37vea53e17578331939@mail.gmail.com> <39e19a010902231158r27605a7bq72adbd99f29e6032@mail.gmail.com> <39e19a010902231239j16903627u19d330821baa0608@mail.gmail.com> Message-ID: <49A30CC1.4040207@holdenweb.com> Denis Kasak wrote: > On Mon, Feb 23, 2009 at 9:12 PM, Steve Holden wrote: >> Denis Kasak wrote: >>> I assure you I am not confused about Python's object model / calling >>> system. I was arguing, from a purely theoretical standpoint, that the >>> same system Python uses could be described in terms of >>> call-by-reference with some additional constraints. I am by no means >>> arguing that this is a good way of explaining it or trying to explain >>> it to someone in terms of call-by-reference. I just don't think it's >>> "plain simple wrong", just confusing and suboptimal. >>> >> Well, what's the benefit of discussing such a description, then? >> Regulars on c.l.py see this subject arising so regularly it's a bit like >> "there's nothing new under the sun". Honestly, it's been discussed /ad >> nauseam/ lately. > > Someone said upthread that Andrew Cooke was completely wrong and I > contested that. :-) > I apologise for not being current with the latest discussions. > That's OK. If you haven't seen this stuff before it's new to you, I guess. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From darcy at druid.net Mon Feb 23 15:55:57 2009 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Mon, 23 Feb 2009 15:55:57 -0500 Subject: Top posting In-Reply-To: <49A2F926.5010207@gmail.com> References: <49A1567B.5020407@gmail.com> <7F0503CD69378F49BE0DC30661C6CCF62783D690@enbmail01.lsi.com> <49A272F1.7090004@gmail.com> <49A2ECDD.8040600@gmail.com> <20090223135447.184e31bb.darcy@druid.net> <49A2F926.5010207@gmail.com> Message-ID: <20090223155557.c810d017.darcy@druid.net> On Mon, 23 Feb 2009 20:29:42 +0100 Stef Mientki wrote: > I agree that top posting on a message like this is not very convenient, Not convenient for thousands, slightly convenient for you. > but for simple messages ... It is still better to follow the suggestions I posted. Also see http://en.wikipedia.org/wiki/Posting_style. > >> I don't have to scroll (assuming that I know from previous readings the > >> content of the previous message). > > > > But how do you know what part of the message is being replied to? > > > simple messages, 1 issue ? So, "simple" messages one rule and others a different rule? Who decides what is simple and what isn't. If two people put the line in different places that would really mess up the flow of an exchange between them. > When I write a report, almost nobody is interested in all > investigations, arguments, > most are only interested in the conclusion and is therefor always on top. You are talking about an abstract in a paper. That is not the same as a dialogue. It's not even close. > btw, it's also polite (in some cultures) to sign your messages ;-) Hmm. I appreciate that you took the time to remove my signature from your reply but I don't think that you should then claim that I never included one. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From steve at holdenweb.com Mon Feb 23 15:57:44 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 23 Feb 2009 15:57:44 -0500 Subject: Python, HTTPS (SSL), tlslite and metoda POST (and lots of pain) In-Reply-To: <200902232126.54519.wolfgang@rohdewald.de> References: <7f2676dd-a87c-4d0f-9f21-bcf2ce6d47fa@n10g2000vbl.googlegroups.com> <200902232126.54519.wolfgang@rohdewald.de> Message-ID: Wolfgang Rohdewald wrote: > On Montag, 23. Februar 2009, Steve Holden wrote: >> yatsek at gmail.com wrote: >>> Hi there. >> [...] >> >> Yatsek: >> >> You just "hijacked a thread" by writing your question as a reply to >> somebody else's post > > did he? His mail headers show no reference to any other mail AFAICS > No, apparently my newsreader just decided to mingle several threads for no apparent reason. Bizarrely the thread now appears on its own even though I haven't restarted Thunderbird. Yatsek, please accept my apologies. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Mon Feb 23 16:00:20 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 23 Feb 2009 16:00:20 -0500 Subject: python sql query in django In-Reply-To: References: <9c401cce-88c3-48b1-a6a5-288d2b897ba3@v19g2000yqn.googlegroups.com> <49a3071a$0$18735$426a34cc@news.free.fr> Message-ID: May wrote: > On Feb 23, 11:31 am, Bruno Desthuilliers > wrote: >> May a ?crit : >> >>> I have three tables: >> Actually - from Python's code POV - three Model classes. And actually, >> since there's a very active, friendly and helpful django group on >> googlegroups, you'd be better reposting your question there. >> >> (snip Django's ORM related question) > > The django users groups suggests using a manytomany field. That works > well in the html template, but in the admin tables, the logic for the > manytomany field applies to the wrong model and doesn't create a > choice for the data entry people. I'm trying to write this without > using the manytomany option. Just using the standard relational > database model. I need to understand if python can do what I need to > do. So far, I've not been successful with an answer in users groups. > I am sure if you explain in detail exactly what you want the admin to present to your data entry people there are those on django-users who can help you make it happen. That list *would* be the best place to get an answer: this one mostly discusses the Python language in a more generic manner. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From torriem at gmail.com Mon Feb 23 16:14:43 2009 From: torriem at gmail.com (Michael Torrie) Date: Mon, 23 Feb 2009 14:14:43 -0700 Subject: Python AppStore / Marketplace In-Reply-To: References: Message-ID: <49A311C3.80707@gmail.com> Steve Holden wrote: > Unfortunately I have no idea what a "souq" is, so I suspect this may be > linguistically biased against English speakers. Or perhaps I'm just > ignorant. Nah. Not biased against English speakers. Just biased against the un-traveled. :) From yatsek at gmail.com Mon Feb 23 16:17:31 2009 From: yatsek at gmail.com (yatsek at gmail.com) Date: Mon, 23 Feb 2009 13:17:31 -0800 (PST) Subject: Python, HTTPS (SSL), tlslite and POST method (and lots of pain) Message-ID: <00e56c9a-85a7-440c-a48d-2a0ea9e00992@j35g2000yqh.googlegroups.com> Hi there. Since quite long time I'm trying to achieve following things: - for some sort of testing I need webserver with https access - with POST method implemented I found something which fits it in nicely written in Python, connected my toys and... server hangs in some weird "inter-state" while serving POST method Below server code: ------------------------- #!/usr/bin/python from SocketServer import * from BaseHTTPServer import * from SimpleHTTPServer import * from tlslite.api import * import string,cgi,time from os import curdir, sep s = open("./server.pem").read() x509 = X509() x509.parse(s) certChain = X509CertChain([x509]) s = open("./server.pem").read() privateKey = parsePEMKey(s, private=True) sessionCache = SessionCache() #class MyHandler(BaseHTTPRequestHandler): class MyHandler(SimpleHTTPRequestHandler): def do_POST(self): global rootnode try: ctype, pdict = cgi.parse_header(self.headers.getheader ('content-type')) form = cgi.FieldStorage(fp = self.rfile, headers=self.headers, environ={'REQUEST_METHOD':'POST', 'CONTENT_TYPE':self.headers ['content-type']} ) if ctype == 'multipart/form-data': if form.has_key('postdata'): temp_file = open(form['postdata'].filename,'wb') buffer = form['postdata'].file.read() temp_file.write(buffer) temp_file.close() self.send_response(200) #set apriopriate header if you want send something #self.send_header('Content-type', 'text/plain') self.send_header('Content-type', 'text/html') self.end_headers() #... and send it #self.wfile.write('OK') self.wfile.write('Post OK.') except : pass class MyHTTPServer(ThreadingMixIn, TLSSocketServerMixIn, HTTPServer): def handshake(self, tlsConnection): try: tlsConnection.handshakeServer(certChain=certChain, privateKey=privateKey, sessionCache=sessionCache) tlsConnection.ignoreAbruptClose = True return True except TLSError, error: print "Handshake failure:", str(error) return False httpd = MyHTTPServer(('127.0.0.1', 443), MyHandler) #httpd = HTTPServer(('127.0.0.1', 80), MyHandler) httpd.serve_forever() -------------------- And page which is used to serve POST request:
File to post:

File is being nicely send to server but as I've mentioned above server is halted in some interstate. Only after Ctrl+C terminates it confirmation of successful transmition is showed in web browser Choosing to use server without SSL (HTTPServer instead of MyHTTPServer) makes everything work without glitch. I would be happy to hear any suggestions If somebody knows any alternative to achieve similar thing (https + POST method on server side) it would be enough to get my tests working. Thx in advance Greetz Yatsek --- sorry for repost - I've made mistake and tried correct it just after posting by deleting it. If it confuses somebody then again - sorry for that From stef.mientki at gmail.com Mon Feb 23 16:20:39 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Mon, 23 Feb 2009 22:20:39 +0100 Subject: Top posting In-Reply-To: <20090223155557.c810d017.darcy@druid.net> References: <49A1567B.5020407@gmail.com> <7F0503CD69378F49BE0DC30661C6CCF62783D690@enbmail01.lsi.com> <49A272F1.7090004@gmail.com> <49A2ECDD.8040600@gmail.com> <20090223135447.184e31bb.darcy@druid.net> <49A2F926.5010207@gmail.com> <20090223155557.c810d017.darcy@druid.net> Message-ID: <49A31327.60807@gmail.com> >> btw, it's also polite (in some cultures) to sign your messages ;-) >> > > Hmm. I appreciate that you took the time to remove my signature from > your reply but I don't think that you should then claim that I never > included one. > > Sorry for that. (now you get an idea how difficult it is for me to use the right posting guide lines) cheers, Stef From p at ulmcnett.com Mon Feb 23 16:20:57 2009 From: p at ulmcnett.com (Paul McNett) Date: Mon, 23 Feb 2009 13:20:57 -0800 Subject: Challenge: Please break this! [Python Security] In-Reply-To: References: Message-ID: <49A31339.6080207@ulmcnett.com> tav wrote: > I'm keen to know your experiences even if you don't manage to write to > the filesystem -- and especially if you do! Does it count when it breaks some standard libs that aren't even trying to write to the filesystem? mac:ss pmcnett$ python sbs_studio.py pkm Traceback (most recent call last): File "sbs_studio.py", line 159, in main() File "sbs_studio.py", line 15, in main parser = OptionParser() File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/optparse.py", line 1191, in __init__ self.set_usage(usage) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/optparse.py", line 1266, in set_usage self.usage = _("%prog [options]") File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/gettext.py", line 566, in gettext return dgettext(_current_domain, message) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/gettext.py", line 530, in dgettext codeset=_localecodesets.get(domain)) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/gettext.py", line 465, in translation mofiles = find(domain, localedir, languages, all=1) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/gettext.py", line 437, in find for nelang in _expand_lang(lang): File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/gettext.py", line 131, in _expand_lang from locale import normalize ImportError: cannot import name normalize Paul From yatsek at gmail.com Mon Feb 23 16:23:32 2009 From: yatsek at gmail.com (yatsek at gmail.com) Date: Mon, 23 Feb 2009 13:23:32 -0800 (PST) Subject: Python, HTTPS (SSL), tlslite and metoda POST (and lots of pain) References: <7f2676dd-a87c-4d0f-9f21-bcf2ce6d47fa@n10g2000vbl.googlegroups.com> <200902232126.54519.wolfgang@rohdewald.de> Message-ID: <9329924e-fd29-4637-aaa7-e70a81092b52@l1g2000yqj.googlegroups.com> On Feb 23, 9:57?pm, Steve Holden wrote: > Wolfgang Rohdewald wrote: > > On Montag, 23. Februar 2009, Steve Holden wrote: > >> yat... at gmail.com wrote: > >>> Hi there. > >> [...] > > >> Yatsek: > > >> You just "hijacked a thread" by writing your question as a reply to > >> somebody else's post > > > did he? His mail headers show no reference to any other mail AFAICS > > No, apparently my newsreader just decided to mingle several threads for > no apparent reason. Bizarrely the thread now appears on its own even > though I haven't restarted Thunderbird. > > Yatsek, please accept my apologies. > > regards > ?Steve Thx, my bad. I was trying to correct spelling mistake by deleting older post just after it was posted and re-posting. Sorry about that. By the way - don't you think that Google could ad this feature (re- editing post for some time after posting) and re-invent newsgroups making it a lot of better tool for communication? BR Yatsek From adleslie at gmail.com Mon Feb 23 16:27:26 2009 From: adleslie at gmail.com (May) Date: Mon, 23 Feb 2009 13:27:26 -0800 (PST) Subject: python sql query in django References: <9c401cce-88c3-48b1-a6a5-288d2b897ba3@v19g2000yqn.googlegroups.com> <49a3071a$0$18735$426a34cc@news.free.fr> Message-ID: On Feb 23, 1:00?pm, Steve Holden wrote: > May wrote: > > On Feb 23, 11:31 am, Bruno Desthuilliers > > wrote: > >> May a ?crit : > > >>> I have three tables: > >> Actually - from Python's code POV - three Model classes. And actually, > >> since there's a very active, friendly and helpful django group on > >> googlegroups, you'd be better reposting your question there. > > >> (snip Django's ORM related question) > > > The django users groups suggests using a manytomany field. ?That works > > well in the html template, but in the admin tables, the logic for the > > manytomany field applies to the wrong model and doesn't create a > > choice for the data entry people. ?I'm trying to write this without > > using the manytomany option. ?Just using the standard relational > > database model. ?I need to understand if python can do what I need to > > do. ?So far, I've not been successful with an answer in users groups. > > I am sure if you explain in detail exactly what you want the admin to > present to your data entry people there are those on django-users who > can help you make it happen. That list *would* be the best place to get > an answer: this one mostly discusses the Python language in a more > generic manner. > > regards > ?Steve > -- > Steve Holden ? ? ? ?+1 571 484 6266 ? +1 800 494 3119 > Holden Web LLC ? ? ? ? ? ? ?http://www.holdenweb.com/ I may not stay with Django. I am seriously looking for whether python can read data from a relational database and send to an html template or do I always need some kind of wrapper/interface such as Rails or Django? If this is the wrong group to ask that question could you recommend another python group that could? Thanks. From labmice at gmail.com Mon Feb 23 16:33:29 2009 From: labmice at gmail.com (Learning Python) Date: Mon, 23 Feb 2009 13:33:29 -0800 (PST) Subject: intermediate python csv reader/writer question from a beginner Message-ID: anything related to csv, I usually use VB within excel to manipulate the data, nonetheless, i finally got the courage to take a dive into python. i have viewed a lot of googled csv tutorials, but none of them address everything i need. Nonetheless, I was wondering if someone can help me manipulate the sample csv (sample.csv) I have generated: ,, someinfo,,,,,,, somotherinfo,,,,,,, SEQ,Names,Test1,Test2,Date,Time,, 1,Adam,1,2,Monday,1:00 PM,, 2,Bob,3,4,Monday,1:00 PM,, 3,Charlie,5,6,Monday,1:00 PM,, 4,Adam,7,8,Monday,2:00 PM,, 5,Bob,9,10,Monday,2:00 PM,, 6,Charlie,11,12,Monday,2:00 PM,, 7,Adam,13,14,Tuesday,1:00 PM,, 8,Bob,15,16,Tuesday,1:00 PM,, 9,Charlie,17,18,Tuesday,1:00 PM,, into (newfile.csv): Adam-Test1,Adam-Test2,Bob-Test1,Bob-Test2,Charlie-Test1,Charlie- Test2,Date,Time 1,2,3,4,5,6,Monday,1:00 PM 7,8,9,10,11,12,Monday,2:00 PM 13,14,15,16,17,18,Tuesday,1:00 PM note: 1. the true header doesn't start line 4 (if this is the case would i have to use "split"?) 2. if there were SEQ#10-12, or 13-15, it would still be Adam, Bob, Charlie, but with different Test1/Test2/Date/Time From deets at nospam.web.de Mon Feb 23 16:34:12 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 23 Feb 2009 22:34:12 +0100 Subject: python sql query in django In-Reply-To: References: <9c401cce-88c3-48b1-a6a5-288d2b897ba3@v19g2000yqn.googlegroups.com> <49a3071a$0$18735$426a34cc@news.free.fr> Message-ID: <70gj2oF5i4l2U1@mid.uni-berlin.de> > I may not stay with Django. I am seriously looking for whether python > can read data from a relational database and send to an html template > or do I always need some kind of wrapper/interface such as Rails or > Django? If this is the wrong group to ask that question could you > recommend another python group that could? Python itself comes neither with an ORM, nor with a HTML generating/mapping framework. So yes, if you want something like that, need something like rails or django. Or TurboGears. For example, you can use SQLAlchemy as ORM, and RUM as frontend for it. I'm not sure if it fullfills your requirements though. http://python-rum.org/ Diez From tav at espians.com Mon Feb 23 16:35:46 2009 From: tav at espians.com (tav) Date: Mon, 23 Feb 2009 21:35:46 +0000 Subject: Challenge: Please break this! [Python Security] In-Reply-To: References: Message-ID: Please use this attached updated safelite.py Victor Stinner got the dinner by using the reload builtin =) Good luck! -- love, tav plex:espians/tav | tav at espians.com | +44 (0) 7809 569 369 http://tav.espians.com | http://twitter.com/tav | skype:tavespian -------------- next part -------------- A non-text attachment was scrubbed... Name: safelite.py Type: text/x-python-script Size: 6034 bytes Desc: not available URL: From tim.wintle at teamrubber.com Mon Feb 23 16:35:49 2009 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Mon, 23 Feb 2009 21:35:49 +0000 Subject: Challenge: Please break this! [Python Security] In-Reply-To: References: Message-ID: <1235424949.27699.44.camel@tim-laptop> On Mon, 2009-02-23 at 20:50 +0000, tav wrote: > I'm keen to know your experiences even if you don't manage to write to > the filesystem -- and especially if you do! > er sorry, but: from safelite import FileReader reload(__builtins__) f = open("/home/tim/nano.save","w") f.write("oops") f.close() > Dinner and drinks on me for an evening -- when you are next in London > or I am in your town -- to the first person who manages to break > safelite.py and write to the filesystem. I'm in London on Wednesday ;-) Unfortunately I'm going to be too busy to take up your offer, lol Tim Wintle From philip at semanchuk.com Mon Feb 23 16:45:26 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 23 Feb 2009 16:45:26 -0500 Subject: python sql query in django In-Reply-To: <70gj2oF5i4l2U1@mid.uni-berlin.de> References: <9c401cce-88c3-48b1-a6a5-288d2b897ba3@v19g2000yqn.googlegroups.com> <49a3071a$0$18735$426a34cc@news.free.fr> <70gj2oF5i4l2U1@mid.uni-berlin.de> Message-ID: On Feb 23, 2009, at 4:34 PM, Diez B. Roggisch wrote: >> I may not stay with Django. I am seriously looking for whether >> python >> can read data from a relational database and send to an html template >> or do I always need some kind of wrapper/interface such as Rails or >> Django? If this is the wrong group to ask that question could you >> recommend another python group that could? > > Python itself comes neither with an ORM, nor with a HTML generating/ > mapping framework. > > So yes, if you want something like that, need something like rails > or django. Or TurboGears. > > For example, you can use SQLAlchemy as ORM, and RUM as frontend for > it. I'm not sure if it fullfills your requirements though. And if you don't like ORMs, most databases have at least one adapter out there that allows one to send straight SQL to the DB engine and get results back in some useful form. For instance, there's the psycopg2 adapter for talking to Postgres. Python has a built-in wrapper for SQLite. From sedelblut at gmail.com Mon Feb 23 16:45:31 2009 From: sedelblut at gmail.com (Stephen) Date: Mon, 23 Feb 2009 13:45:31 -0800 (PST) Subject: Reading a tab delimited text file. Message-ID: <2f324124-1373-458f-8d5f-8664f0128660@n21g2000vba.googlegroups.com> Hi, I would like to read a text file of numbers produced by a data acquisition system into three vectors of doubles. The contents of the file are: +0.0000000e+0 +2.7645134e+1 +2.7745625e+1 +0.4100041e-1 +2.7637787e+1 +2.7731047e+1 +0.0820008e+0 +2.7645134e+1 +2.7750483e+1 ... or +0.0000000e+0\t+2.7645134e+1\t+2.7745625e+1\r\n ... I would like to read the first column into time_vec, second into ch1_vec and so on. (I have never programmed in python and am having trouble finding a way to do this). Thanks From skippy.hammond at gmail.com Mon Feb 23 16:49:22 2009 From: skippy.hammond at gmail.com (Mark Hammond) Date: Tue, 24 Feb 2009 08:49:22 +1100 Subject: How does one get from "ImportError: DLL load failed:..." to a culprit .dll and symbol? In-Reply-To: <01b28edb$0$20619$c3e8da3@news.astraweb.com> References: <01b213c7$0$20626$c3e8da3@news.astraweb.com> <5850dc46-638f-4a3c-8d9a-f84bf7523979@o11g2000yql.googlegroups.com> <01b28edb$0$20619$c3e8da3@news.astraweb.com> Message-ID: <49A319E2.1000306@gmail.com> On 23/02/2009 11:41 PM, Chris Cormie wrote: > >> If that not-very-technical description [all I've ever needed] doesn't >> help, you'll need to read the DW help file (HTFF1K) or wait till >> someone who knows what they are doing comes along :-) > > LOL, I am that person :p LOL sounds right! > How do you get *Python* to tell you the dll and the problem symbol? Not > external tools, Python. Python at a low level is calling LoadLibrary and > GetProcAddress to resolve symbols and the call fails. It is the LoadLibrary that is failing; it should be obvious that if it was a simple GetProcAddress that was failing, Python would simply throw an exception rather than displaying the ugly dialog box you see. The problem is that some *other* DLL in the chain of dependencies is failing to load; please re-adjust your perceptions of your own knowledge and re-read John's initial response - if you follow his instructions that should all become quite obvious. Mark From aquil.abdullah at gmail.com Mon Feb 23 16:54:06 2009 From: aquil.abdullah at gmail.com (aha) Date: Mon, 23 Feb 2009 13:54:06 -0800 (PST) Subject: A tale of two execs References: Message-ID: <7d85586a-d746-4e0f-b01b-86bf2e388971@f18g2000vbf.googlegroups.com> Hello All, So below is my naive attempt at the wrapper, it is only half baked since I am no master at Interprocess communication... I know that it is lacking a lot of things comment greatly appreciated: #!/usr/bin/env python import os, sys, re, exceptions try: import subprocess except ImportError: import popen2 subprocess = None PIPE = 10 SOUT = 11 class Runner: def __init__(self): self.stdout = None self.stdin = None self.stderr = None self.pid = None self.process = None def runCmdLine(self, args, executable=None, stdin=None, stdout=None, stderr=None, preexec_fn=None, close_fds=False, shell=False,cwd=None, env=None): """ args -- a string, or a sequence of program arguments. The argument to execute is normally the first item in the args sequence or the string if a string is given, but can be explicitly set by using the executable argument. executable -- string to be executed stdin, stdout, stderr -- value of standard input, standard output, and standard error file handles. None implies no redirection. Valid values are PIPE, an existing file descriptor (a positive integer), an existing file object, and None. shell -- specifies whether command should be executed through shell cwd -- specifies whether, childs current directory will be changed to cwd env -- A map that specifies the environment variables in child process that will be overwritten NOTE: Depending on the modules available, some arguments may not be used. """ if subprocess: # Use subprocess to exec functions if stdin == PIPE: sin = subprocess.PIPE else: # NOTE: User may input invalid values that will cause exceptions sin = stdin if stdout == PIPE: sout = subprocess.PIPE else: sout = stdout if stderr == SOUT: serr = subprocess.STDOUT else: serr = stderr self.process = subprocess.Popen(args, stdin=sin, stdout=sout, stderr=serr, preexec_fn=preexec_fn,close_fds=close_fds, shell=shell, env=env, cwd=cwd) self.pid = self.process.pid # Add attributes stdin, stdout, and stderr self.stdin = self.process.stdin self.stdout = self.process.stdout self.stderr = self.process.stderr else: # Use popen2 to exec functions # Determine which form of popen2 to use if stderr == SOUT or stderr == None: self.process = popen2.Popen4(args) self.stdin = self.process.tochild self.stdout = self.process.fromchild self.stderr = None else: self.process = popen2.Popen3(args) self.stdin = self.process.tochild self.stdout = self.process.fromchild self.stderr = self.process.childerr self.pid = self.process.pid def wait(self,): """ Waits for and returns the status code of the child process. """ return self.process.wait() def poll(self,): """ Returns -1 if the child process hasn't completed yet, or it's return code otherwise """ return self.process.poll() Aquil On Feb 23, 2:10?pm, Christian Heimes wrote: > aha wrote > > > def runner(cmd, stdin, stdout, ...): > > ? try: > > ? ? import subprocess > > ? ? sbm = 1 > > ? except: > > ? ? sbm = 0 > > > ? # Now do something > > ? if sbm: > > ? ? process = subporcess(...) > > ? else: > > ? ? import popen2 > > ? ? process = popen2.Popen4(...) > > > Has anyone else run into a situation similar to this one? > > The canonical way for your try/except clause is: > > try: > ? ? import subprocess > except ImportError: > ? ? subprocess = None > > ... > > if subprocess is not None: > ? ? ... > else: > ? ? ... > > Christian From bob at mellowood.ca Mon Feb 23 17:05:42 2009 From: bob at mellowood.ca (bvdp) Date: Mon, 23 Feb 2009 15:05:42 -0700 Subject: more on unescaping escapes Message-ID: So, we think something is working and send of a bug fix to our client :) I'm not sure I understand this at all and wonder if there is bug? >>> a="c:\\Program\x20Files\\test" >>> a 'c:\\Program Files\\test' so far, so good. >>> a.decode("string-escape") 'c:\\Program Files\test' Umm, not so good? The \\ before the P is okay, but the \\t is change to \t and >>> print a.decode("string-escape") c:\Program Files est Now, decode() converted the \\t to a \t and print expanded the \t to a tab. I would have thought that the \\t would have the same result as the \\P ??? Obviously my brain is missing something (hopefully obvious). From python.list at tim.thechases.com Mon Feb 23 17:06:58 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 23 Feb 2009 16:06:58 -0600 Subject: Reading a tab delimited text file. In-Reply-To: <2f324124-1373-458f-8d5f-8664f0128660@n21g2000vba.googlegroups.com> References: <2f324124-1373-458f-8d5f-8664f0128660@n21g2000vba.googlegroups.com> Message-ID: <49A31E02.3020108@tim.thechases.com> > I would like to read a text file of numbers produced by a data > acquisition system into three vectors of doubles. The contents of the > file are: > > +0.0000000e+0 +2.7645134e+1 +2.7745625e+1 > +0.4100041e-1 +2.7637787e+1 +2.7731047e+1 > +0.0820008e+0 +2.7645134e+1 +2.7750483e+1 > ... > > or > > +0.0000000e+0\t+2.7645134e+1\t+2.7745625e+1\r\n > ... > > I would like to read the first column into time_vec, second into > ch1_vec and so on. > > (I have never programmed in python and am having trouble finding a way > to do this). Well, a very terse way of doing it would be something like: time_vec, ch1_vec, and_so_on = zip(*( map(float, line.split()) for line in file('in.txt'))) If my junior developer authored that, I'm not sure whether I'd laud her or fire her. :) If this isn't homework, there are some less terse versions which are a bit easier on the eyes and less like some love-child between Perl and Python. -tkc From steve at holdenweb.com Mon Feb 23 17:12:09 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 23 Feb 2009 17:12:09 -0500 Subject: Python AppStore / Marketplace In-Reply-To: <49A311C3.80707@gmail.com> References: <49A311C3.80707@gmail.com> Message-ID: Michael Torrie wrote: > Steve Holden wrote: >> Unfortunately I have no idea what a "souq" is, so I suspect this may be >> linguistically biased against English speakers. Or perhaps I'm just >> ignorant. > > Nah. Not biased against English speakers. Just biased against the > un-traveled. :) Don't think so. I've visited roughly twenty-five difference countries and traveled I-don't-know-how-many miles, but certainly over a million. Unless you'd like to redefine "un-traveled" ... ? But I do (still) speak English (of a kind). regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Mon Feb 23 17:12:56 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 23 Feb 2009 17:12:56 -0500 Subject: Top posting In-Reply-To: <49A31327.60807@gmail.com> References: <49A1567B.5020407@gmail.com> <7F0503CD69378F49BE0DC30661C6CCF62783D690@enbmail01.lsi.com> <49A272F1.7090004@gmail.com> <49A2ECDD.8040600@gmail.com> <20090223135447.184e31bb.darcy@druid.net> <49A2F926.5010207@gmail.com> <20090223155557.c810d017.darcy@druid.net> <49A31327.60807@gmail.com> Message-ID: Stef Mientki wrote: > >>> btw, it's also polite (in some cultures) to sign your messages ;-) >>> >> >> Hmm. I appreciate that you took the time to remove my signature from >> your reply but I don't think that you should then claim that I never >> included one. >> >> > Sorry for that. > > (now you get an idea how difficult it is for me to use the right posting > guide lines) > It gets easier the more you do it. Practice make perfect, y'know ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Mon Feb 23 17:14:15 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 23 Feb 2009 17:14:15 -0500 Subject: Python, HTTPS (SSL), tlslite and metoda POST (and lots of pain) In-Reply-To: <9329924e-fd29-4637-aaa7-e70a81092b52@l1g2000yqj.googlegroups.com> References: <7f2676dd-a87c-4d0f-9f21-bcf2ce6d47fa@n10g2000vbl.googlegroups.com> <200902232126.54519.wolfgang@rohdewald.de> <9329924e-fd29-4637-aaa7-e70a81092b52@l1g2000yqj.googlegroups.com> Message-ID: yatsek at gmail.com wrote: > On Feb 23, 9:57 pm, Steve Holden wrote: >> Wolfgang Rohdewald wrote: >>> On Montag, 23. Februar 2009, Steve Holden wrote: >>>> yat... at gmail.com wrote: >>>>> Hi there. >>>> [...] >>>> Yatsek: >>>> You just "hijacked a thread" by writing your question as a reply to >>>> somebody else's post >>> did he? His mail headers show no reference to any other mail AFAICS >> No, apparently my newsreader just decided to mingle several threads for >> no apparent reason. Bizarrely the thread now appears on its own even >> though I haven't restarted Thunderbird. >> >> Yatsek, please accept my apologies. >> >> regards >> Steve > > Thx, my bad. > I was trying to correct spelling mistake by deleting older post just > after it was posted and re-posting. Sorry about that. > > By the way - don't you think that Google could ad this feature (re- > editing post for some time after posting) and re-invent newsgroups > making it a lot of better tool for communication? > They probably could, but so far they don't even seem inclined to do much about rampant spamming. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From andrew at acooke.org Mon Feb 23 17:17:42 2009 From: andrew at acooke.org (andrew cooke) Date: Mon, 23 Feb 2009 19:17:42 -0300 (CLST) Subject: Peculiar swap behavior In-Reply-To: References: Message-ID: <474ac666ac46826d2be21d107a395dbc.squirrel@acooke.dyndns.org> Delaney, Timothy (Tim) wrote: > Tim Chase wrote: >> # swap list contents...not so much... >> >>> m,n = [1,2,3],[4,5,6] >> >>> m[:],n[:] = n,m >> >>> m,n >> ([4, 5, 6], [4, 5, 6]) [...] > For these types of things, it's best to expand the code out. The > appropriate expansion of: > m,n = [1,2,3],[4,5,6] > m[:],n[:] = n,m > is: > m = [1,2,3] > n = [4,5,6] > m[:] = n > n[:] = m > [...] OTOH, for: > m,n = [1,2,3],[4,5,6] > m[:],n[:] = n[:],m[:] > the expansion is more like: > m = [1,2,3] > n = [4,5,6] > rhs1 = n[:] > rhs2 = m[:] > m[:] = rhs1 > n[:] = rhs2 Maybe I'm just being stupid, but you don't seem to have explained anything. Isn't the question: Why is the expansion different for the two cases? Why don't both expand to have the intermediate rhs variables? Andrew From sedelblut at gmail.com Mon Feb 23 17:17:44 2009 From: sedelblut at gmail.com (Stephen) Date: Mon, 23 Feb 2009 14:17:44 -0800 (PST) Subject: Reading a tab delimited text file. References: <2f324124-1373-458f-8d5f-8664f0128660@n21g2000vba.googlegroups.com> Message-ID: <60e42b67-88b5-4790-af56-5070e697e8eb@t11g2000yqg.googlegroups.com> On Feb 23, 4:06?pm, Tim Chase wrote: > > I would like to read a text file of numbers produced by a data > > acquisition system into three vectors of doubles. The contents of the > > file are: > > > +0.0000000e+0 ? ? ?+2.7645134e+1 ? +2.7745625e+1 > > +0.4100041e-1 ? ? ?+2.7637787e+1 ? +2.7731047e+1 > > +0.0820008e+0 ? ? ?+2.7645134e+1 ? +2.7750483e+1 > > ... > > > or > > > +0.0000000e+0\t+2.7645134e+1\t+2.7745625e+1\r\n > > ... > > > I would like to read the first column into time_vec, second into > > ch1_vec and so on. > > > (I have never programmed in python and am having trouble finding a way > > to do this). > > Well, a very terse way of doing it would be something like: > > ? ?time_vec, ch1_vec, and_so_on = zip(*( > ? ? ?map(float, line.split()) > ? ? ?for line in file('in.txt'))) > > If my junior developer authored that, I'm not sure whether I'd > laud her or fire her. :) > > If this isn't homework, there are some less terse versions which > are a bit easier on the eyes and less like some love-child > between Perl and Python. > > -tkc haha, no this isn't homework. I'm a mechanical engineering student working on a research project and this program is for my personal use to analyze the data. From aquil.abdullah at gmail.com Mon Feb 23 17:20:04 2009 From: aquil.abdullah at gmail.com (aha) Date: Mon, 23 Feb 2009 14:20:04 -0800 (PST) Subject: A tale of two execs References: <7d85586a-d746-4e0f-b01b-86bf2e388971@f18g2000vbf.googlegroups.com> Message-ID: I've decided to change the runCmdLine method to Popen. On Feb 23, 4:54?pm, aha wrote: > Hello All, > ? So below is my naive attempt at the wrapper, it is only half baked > since I am no master at Interprocess communication... I know that it > is lacking a lot of things comment greatly appreciated: > > #!/usr/bin/env python > > import os, sys, re, exceptions > try: > ? ? import subprocess > except ImportError: > ? ? import popen2 > ? ? subprocess = None > > PIPE = 10 > SOUT = 11 > > class Runner: > ? ? def __init__(self): > ? ? ? ? self.stdout = None > ? ? ? ? self.stdin = None > ? ? ? ? self.stderr = None > ? ? ? ? self.pid = None > ? ? ? ? self.process = None > > ? ? def runCmdLine(self, args, executable=None, stdin=None, > stdout=None, stderr=None, preexec_fn=None, > ? ? ? ? ? ? ? ? ? ?close_fds=False, shell=False,cwd=None, env=None): > ? ? ? ? """ > ? ? ? ? args -- a string, or a sequence of program arguments. The > argument to execute is > ? ? ? ? normally the first item in the args sequence or the string if > a string is given, > ? ? ? ? but can be explicitly set by using the executable argument. > > ? ? ? ? executable -- string to be executed > > ? ? ? ? stdin, stdout, stderr -- value of standard input, standard > output, and standard > ? ? ? ? error file handles. ?None implies no redirection. Valid values > are PIPE, an existing > ? ? ? ? file descriptor (a positive integer), an existing file object, > and None. > > ? ? ? ? shell -- specifies whether command should be executed through > shell > > ? ? ? ? cwd -- specifies whether, childs current directory will be > changed to cwd > > ? ? ? ? env -- A map that specifies the environment variables in child > process > ? ? ? ? that will be overwritten > > ? ? ? ? NOTE: Depending on the modules available, some arguments may > not be used. > ? ? ? ? """ > ? ? ? ? if subprocess: > ? ? ? ? ? ? # Use subprocess to exec functions > ? ? ? ? ? ? if stdin == PIPE: > ? ? ? ? ? ? ? ? sin = subprocess.PIPE > ? ? ? ? ? ? else: > ? ? ? ? ? ? ? ? # NOTE: User may input invalid values that will cause > exceptions > ? ? ? ? ? ? ? ? sin = stdin > ? ? ? ? ? ? if stdout == PIPE: > ? ? ? ? ? ? ? ? sout = subprocess.PIPE > ? ? ? ? ? ? else: > ? ? ? ? ? ? ? ? sout = stdout > ? ? ? ? ? ? if stderr == SOUT: > ? ? ? ? ? ? ? ? serr = subprocess.STDOUT > ? ? ? ? ? ? else: > ? ? ? ? ? ? ? ? serr = stderr > > ? ? ? ? ? ? self.process = subprocess.Popen(args, stdin=sin, > stdout=sout, stderr=serr, > > preexec_fn=preexec_fn,close_fds=close_fds, shell=shell, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? env=env, cwd=cwd) > ? ? ? ? ? ? self.pid = self.process.pid > ? ? ? ? ? ?# Add attributes stdin, stdout, and stderr > ? ? ? ? ? ? self.stdin = self.process.stdin > ? ? ? ? ? ? self.stdout = self.process.stdout > ? ? ? ? ? ? self.stderr = self.process.stderr > ? ? ? ? else: > ? ? ? ? ? ? # Use popen2 to exec functions > ? ? ? ? ? ? # Determine which form of popen2 to use > ? ? ? ? ? ? if stderr == SOUT or stderr == None: > ? ? ? ? ? ? ? ? self.process = ?popen2.Popen4(args) > ? ? ? ? ? ? ? ? self.stdin = self.process.tochild > ? ? ? ? ? ? ? ? self.stdout = self.process.fromchild > ? ? ? ? ? ? ? ? self.stderr = None > ? ? ? ? ? ? else: > ? ? ? ? ? ? ? ? self.process = ?popen2.Popen3(args) > ? ? ? ? ? ? ? ? self.stdin = self.process.tochild > ? ? ? ? ? ? ? ? self.stdout = self.process.fromchild > ? ? ? ? ? ? ? ? self.stderr = self.process.childerr > > ? ? ? ? ? ? self.pid = self.process.pid > > ? ? def wait(self,): > ? ? ? ? """ > ? ? ? ? Waits for and returns the status code of the child process. > ? ? ? ? """ > ? ? ? ? return self.process.wait() > > ? ? def poll(self,): > ? ? ? ? """ > ? ? ? ? Returns -1 if the child process hasn't completed yet, or it's > return code > ? ? ? ? otherwise > ? ? ? ? """ > ? ? ? ? return self.process.poll() > > Aquil > > On Feb 23, 2:10?pm, Christian Heimes wrote: > > > aha wrote > > > > def runner(cmd, stdin, stdout, ...): > > > ? try: > > > ? ? import subprocess > > > ? ? sbm = 1 > > > ? except: > > > ? ? sbm = 0 > > > > ? # Now do something > > > ? if sbm: > > > ? ? process = subporcess(...) > > > ? else: > > > ? ? import popen2 > > > ? ? process = popen2.Popen4(...) > > > > Has anyone else run into a situation similar to this one? > > > The canonical way for your try/except clause is: > > > try: > > ? ? import subprocess > > except ImportError: > > ? ? subprocess = None > > > ... > > > if subprocess is not None: > > ? ? ... > > else: > > ? ? ... > > > Christian > > From mwilson at the-wire.com Mon Feb 23 17:22:29 2009 From: mwilson at the-wire.com (Mel) Date: Mon, 23 Feb 2009 17:22:29 -0500 Subject: Reading a tab delimited text file. References: <2f324124-1373-458f-8d5f-8664f0128660@n21g2000vba.googlegroups.com> Message-ID: Stephen wrote: > Hi, > > I would like to read a text file of numbers produced by a data > acquisition system into three vectors of doubles. The contents of the > file are: > > +0.0000000e+0 +2.7645134e+1 +2.7745625e+1 > > +0.4100041e-1 +2.7637787e+1 +2.7731047e+1 > > +0.0820008e+0 +2.7645134e+1 +2.7750483e+1 > ... > > or > > +0.0000000e+0\t+2.7645134e+1\t+2.7745625e+1\r\n > ... > > I would like to read the first column into time_vec, second into > ch1_vec and so on. > > (I have never programmed in python and am having trouble finding a way > to do this). A simple starting point, without error handling, etc., could be: a_list = [] b_list = [] c_list = [] for line in open ('my_numbers.txt', 'rt'): a, b, c = [float (x) for x in line.split()] a_list.append (a) b_list.append (b) c_list.append (c) Assuming every line has three tab-separated numbers, the text versions of the numbers are all convertable to float, the text file that's opened will eventually be closed (whether by garbage collection or program termination.) This code does illustrate the string's split method, list comprehension, sequence unpacking, and the fact that each of a_list, b_list, c_list *MUST* be initialized with a distinct empty list object. Mel. From google at mrabarnett.plus.com Mon Feb 23 17:36:41 2009 From: google at mrabarnett.plus.com (MRAB) Date: Mon, 23 Feb 2009 22:36:41 +0000 Subject: more on unescaping escapes In-Reply-To: References: Message-ID: <49A324F9.4040201@mrabarnett.plus.com> bvdp wrote: > > So, we think something is working and send of a bug fix to our client :) > > I'm not sure I understand this at all and wonder if there is bug? > > >>> a="c:\\Program\x20Files\\test" > >>> a > 'c:\\Program Files\\test' > > so far, so good. > > >>> a.decode("string-escape") > 'c:\\Program Files\test' > > Umm, not so good? The \\ before the P is okay, but the \\t is change to \t > Decoding changes "\\x20" to "\x20", which is the same as " ", a space. Decoding changes "\\t" to "\t", which is a tab. Decoding _doesn't_ change "\\P" to "\P" because that's not a valid escape sequence. > and > > >>> print a.decode("string-escape") > c:\Program Files est > > Now, decode() converted the \\t to a \t and print expanded the \t to a tab. > \t is already a tab. > I would have thought that the \\t would have the same result as the \\P ??? > > Obviously my brain is missing something (hopefully obvious). > Before storing the string (writing it to the file), encode it and then replace " " with "\\x20": C:\Program Files\test becomes: C:\Program Files\test and then: C:\\Program\x20Files\\test After fetching the string (reading it from the file), decode it: C:\\Program\x20Files\\test becomes: C:\Program Files\test From python.list at tim.thechases.com Mon Feb 23 17:45:12 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 23 Feb 2009 16:45:12 -0600 Subject: Reading a tab delimited text file. In-Reply-To: <60e42b67-88b5-4790-af56-5070e697e8eb@t11g2000yqg.googlegroups.com> References: <2f324124-1373-458f-8d5f-8664f0128660@n21g2000vba.googlegroups.com> <60e42b67-88b5-4790-af56-5070e697e8eb@t11g2000yqg.googlegroups.com> Message-ID: <49A326F8.5080202@tim.thechases.com> >> time_vec, ch1_vec, and_so_on = zip(*( >> map(float, line.split()) >> for line in file('in.txt'))) >> >> If this isn't homework, there are some less terse versions which >> are a bit easier on the eyes and less like some love-child >> between Perl and Python. > > haha, no this isn't homework. I'm a mechanical engineering student > working on a research project and this program is for my personal use > to analyze the data. The "zip-star map-float" variant is a pretty unreadable way to go. The more readable versions look something like data = [map(float, line.split()) for line in file('in.txt')] time_vec = [bit[0] for bit in data] ch1_vec = [bit[1] for bit in data] and_so_on = [bit[2] for bit in data] or even time_vec = [] ch1_vec = [] and_so_on = [] for line in file('in.txt'): a,b,c = map(float, line.split()) time_vec.append(a) ch1_vec.append(b) and_so_on.append(c) which could also be written as for line in file('in.txt'): line = line.split() time_vec.append(float(line[0])) ch1_vec.append(float(line[1])) and_so_on.append(float(line[2])) -tkc From steve at holdenweb.com Mon Feb 23 18:00:24 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 23 Feb 2009 18:00:24 -0500 Subject: A tale of two execs In-Reply-To: References: <7d85586a-d746-4e0f-b01b-86bf2e388971@f18g2000vbf.googlegroups.com> Message-ID: aha wrote: > I've decided to change the runCmdLine method to Popen. > [...] So just exactly why was it necessary to follow this remark with about three hundred lines of quoted text? And can't you put your replies at the bottom rather than the top, please? And trim the stuff that isn't required. It's simple courtesy to your readers. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From robert.kern at gmail.com Mon Feb 23 18:00:50 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 23 Feb 2009 17:00:50 -0600 Subject: Peculiar swap behavior In-Reply-To: <474ac666ac46826d2be21d107a395dbc.squirrel@acooke.dyndns.org> References: <474ac666ac46826d2be21d107a395dbc.squirrel@acooke.dyndns.org> Message-ID: On 2009-02-23 16:17, andrew cooke wrote: > Delaney, Timothy (Tim) wrote: >> Tim Chase wrote: >>> # swap list contents...not so much... >>> >>> m,n = [1,2,3],[4,5,6] >>> >>> m[:],n[:] = n,m >>> >>> m,n >>> ([4, 5, 6], [4, 5, 6]) > [...] >> For these types of things, it's best to expand the code out. The >> appropriate expansion of: >> m,n = [1,2,3],[4,5,6] >> m[:],n[:] = n,m >> is: >> m = [1,2,3] >> n = [4,5,6] >> m[:] = n >> n[:] = m >> [...] OTOH, for: >> m,n = [1,2,3],[4,5,6] >> m[:],n[:] = n[:],m[:] >> the expansion is more like: >> m = [1,2,3] >> n = [4,5,6] >> rhs1 = n[:] >> rhs2 = m[:] >> m[:] = rhs1 >> n[:] = rhs2 > > Maybe I'm just being stupid, but you don't seem to have explained > anything. Isn't the question: Why is the expansion different for the two > cases? Why don't both expand to have the intermediate rhs variables? n[:] on the RHS makes a copy of the list. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From nad at acm.org Mon Feb 23 18:01:00 2009 From: nad at acm.org (Ned Deily) Date: Mon, 23 Feb 2009 15:01:00 -0800 Subject: Python won't run References: <37c2b0840902201652m118c1661s6eebe110f1b41fdf@mail.gmail.com> <50697b2c0902201703x79b6635dw60e7956d8500731a@mail.gmail.com> <37c2b0840902201716y6d072720m18b64d7734e65b18@mail.gmail.com> <50697b2c0902201720j2025ee3pad92c2600c912fb8@mail.gmail.com> <37c2b0840902201724h51e949fbpb49f99c3521ed32d@mail.gmail.com> <50697b2c0902201728k50076bdard53da0f567f2c65e@mail.gmail.com> <37c2b0840902201734n708e7d6ds349d7b4ad7af1b2d@mail.gmail.com> <50697b2c0902201741x46ebbe07ge4fbac1e3f7fee4b@mail.gmail.com> <37c2b0840902201751q5ac4b607n14c90ee0b51c1c00@mail.gmail.com> Message-ID: [Again, please reply-all to the list, don't send private email!] On Feb 23, 2009, at 14:03 , kevin hayes wrote: > Ned, system log didn't do anything when I tried to open IDLE. However, this > is what's in the console.log. does this tell you anything? > > Unhandled server exception! > Thread: SockThread > Client Address: ('127.0.0.1', 8833) > Request: > Traceback (most recent call last): > File > "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/SocketServer. > py", line 281, in _handle_request_noblock > self.process_request(request, client_address) > File > "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/SocketServer. > py", line 307, in process_request > self.finish_request(request, client_address) > File > "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/SocketServer. > py", line 320, in finish_request > self.RequestHandlerClass(request, client_address, self) > File > "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/idlelib/rpc.p > y", line 503, in __init__ > SocketServer.BaseRequestHandler.__init__(self, sock, addr, svr) > File > "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/SocketServer. > py", line 615, in __init__ > self.handle() > File > "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/idlelib/run.p > y", line 256, in handle > import IOBinding > File > "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/idlelib/IOBin > ding.py", line 12, in > import tempfile > File > "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/tempfile.py", > line 34, in > from random import Random as _Random > File "random.py", line 3, in > import rand # handy random-number functions > ImportError: No module named rand > > *** Unrecoverable, server exiting! [...] It looks like you have a file named random.py in your Documents directory. IDLE.app adds ~/Documents to the front of sys.path, python's search path for modules. Your random.py is being found before the standard library module, random, causing the idle server process to abort. Rename your random.py* and all should be well for both 2.5 and 2.6. One could argue that IDLE.app should be smarter about situations like this. It would be good to open an issue about this on the python tracker: http://bugs.python.org/ -- Ned Deily nad at acm.org -- [] -- Ned Deily, nad at acm.org From tim.wintle at teamrubber.com Mon Feb 23 18:13:14 2009 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Mon, 23 Feb 2009 23:13:14 +0000 Subject: Challenge: Please break this! [Python Security] In-Reply-To: <49A31339.6080207@ulmcnett.com> References: <49A31339.6080207@ulmcnett.com> Message-ID: <1235430794.27699.131.camel@tim-laptop> On Mon, 2009-02-23 at 13:20 -0800, Paul McNett wrote: > tav wrote: > > I'm keen to know your experiences even if you don't manage to write to > > the filesystem -- and especially if you do! > > Does it count when it breaks some standard libs that aren't even trying to write to > the filesystem? It appears to prevent any imports from being allowed at all. > > mac:ss pmcnett$ python sbs_studio.py pkm > Traceback (most recent call last): > File "sbs_studio.py", line 159, in > main() > File "sbs_studio.py", line 15, in main > parser = OptionParser() > File > "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/optparse.py", line > 1191, in __init__ > self.set_usage(usage) > File > "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/optparse.py", line > 1266, in set_usage > self.usage = _("%prog [options]") > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/gettext.py", > line 566, in gettext > return dgettext(_current_domain, message) > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/gettext.py", > line 530, in dgettext > codeset=_localecodesets.get(domain)) > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/gettext.py", > line 465, in translation > mofiles = find(domain, localedir, languages, all=1) > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/gettext.py", > line 437, in find > for nelang in _expand_lang(lang): > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/gettext.py", > line 131, in _expand_lang > from locale import normalize > ImportError: cannot import name normalize > > Paul > -- > http://mail.python.org/mailman/listinfo/python-list From vincent at vincentdavis.net Mon Feb 23 18:18:00 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Mon, 23 Feb 2009 16:18:00 -0700 Subject: read csv error question Message-ID: <77e831100902231518q7a29e251s956be0b77d2613d@mail.gmail.com> I am trying to read a csv file from excel on a mac. I get the following error.SystemExit: file some.csv, line 1: new-line character seen in unquoted field - do you need to open the file in universal-newline mode? I was using the example code import csv, sys reader = csv.reader(open('/Volumes/vincentdavis 2/match/data/matchdata2008.csv', "rb")) try: for row in reader: print row except csv.Error, e: sys.exit('file %s, line %d: %s' % (filename, reader.line_num, e)) I think this has to do with the end of line character but I am unsure how to fix it. I don't what to change the actual csv file I would like to fix the code. Thanks Vincent Davis -------------- next part -------------- An HTML attachment was scrubbed... URL: From kyrie at uh.cu Mon Feb 23 18:18:10 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Mon, 23 Feb 2009 18:18:10 -0500 Subject: Challenge: Please break this! [Python Security] In-Reply-To: References: Message-ID: <200902231818.10603.kyrie@uh.cu> On Monday 23 February 2009 03:50:57 pm tav wrote: > Hey all, > > As an attempt to convince Python-Dev of the merits of a > functions-based approach to security in Python, I've come up with a > simple challenge. > While I'm almost excited that you are tackling the problem of python's security, I find that your approach seems to break too many things: --- >>> from safelite import FileReader >>> import numeric >>> print numeric None >>> import i_hope_this_doesnt_exists >>> print i_hope_this_doesnt_exists None --- Versus: --- >>> import django >>> print django >>> import i_hope_this_doesnt_exists Traceback (most recent call last): File "", line 1, in ImportError: No module named i_hope_this_doesnt_exists --- ipython also gets broken after the import (nothing works after the import). Still, it seems interesting... -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From clp2 at rebertia.com Mon Feb 23 18:20:45 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 23 Feb 2009 15:20:45 -0800 Subject: Peculiar swap behavior In-Reply-To: <49A2EE60.1060300@tim.thechases.com> References: <49A2EE60.1060300@tim.thechases.com> Message-ID: <50697b2c0902231520jcf7d85dhf5add59889db3868@mail.gmail.com> On Mon, Feb 23, 2009 at 10:43 AM, Tim Chase wrote: > # swap list contents...not so much... >>>> m,n = [1,2,3],[4,5,6] >>>> m[:],n[:] = n,m >>>> m,n > ([4, 5, 6], [4, 5, 6]) Pseudo-C-Python expansion: #evaluate RHS. simply *take pointers* since the RHS is just plain variables ptr_n = &n ptr_m = &m #perform "assignments" to LHS #remember that x[y] = z is really a method call to __setitem__ in disguise #let's pseudo-expand the method calls #also remember that the assignments must be serialized (Python isn't magically parallel) m._items = (*ptr_n)._items #uh-oh! this just clobbered n._items! since we only kept a pointer to n, n._items is now gone forever! n._items = (*ptr_m)._items #uh-oh! this now has no real effect since we clobbered m._items #badness! > The first two work as expected but the 3rd seems to leak some internal > abstraction. It seems to work if I force content-copying: > >>>> m[:],n[:] = n[:],m[:] Pseudo-C-Python expansion: #evaluate RHS. it's more complicated this time. this matters significantly! #remember that x[y] is really a *method call* in disguise to __getitem__ #let's pseudo-expend the method-calls too #note that we *make copies* instead of just taking pointers this time! n_cpy = copy_list(n) m_cpy = copy_list(m) #same principles as before m._items = n_cpy._items #but we have a copy of m._items in m_cpy, so m._items isn't lost forever! n._items = m_cpy._items #yay, it works! #huzzah > Is this a bug, something Python should smack the programmer for trying, or > just me pushing the wrong edges? :) Little from column A, little from column B. Using the swapping assignment works slightly unintuitively with list slices because copying doesn't magically take place; you need to do this copying explicitly whereas it's sorta done for you with plain variable swapping. Just keep in mind that container contents work "by-reference" rather than "by-value", so to speak. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From woodygar at sky.com Mon Feb 23 18:33:31 2009 From: woodygar at sky.com (Gary Wood) Date: Mon, 23 Feb 2009 23:33:31 -0000 Subject: thanks very much indeed for your help is there a better way to do this (python3) newby Message-ID: '''exercise to complete and test this function''' import string def joinStrings(items): '''Join all the strings in stringList into one string, and return the result. For example: >>> print joinStrings(['very', 'hot', 'day']) 'veryhotday' ''' for i in items: return (''.join(items)) def main(): print(joinStrings(['very', 'hot','day'])) print(joinStrings(['this', 'is','it'])) print(joinStrings(['1', '2', '3', '4', '5'])) main() -------------- next part -------------- An HTML attachment was scrubbed... URL: From harijay at gmail.com Mon Feb 23 18:37:36 2009 From: harijay at gmail.com (harijay) Date: Mon, 23 Feb 2009 15:37:36 -0800 (PST) Subject: Reading a tab delimited text file. References: <2f324124-1373-458f-8d5f-8664f0128660@n21g2000vba.googlegroups.com> <60e42b67-88b5-4790-af56-5070e697e8eb@t11g2000yqg.googlegroups.com> Message-ID: You could also use the csv module import csv myfileobj = open("myfiletab.txt","read") csv_read = csv.reader(myfileobj,dialect=csv.excel_tab) myval1 = [] myval2 = [] myval3 = [] for line in csv_read: # filter header and stuff using some criterion if len(line) = 3: myval1.append(line[0]) myval2.append(line[1]) myval3.append(line[2]) etc etc . The csv module defines a dialect excel_tab. Each line is then parsed into an array . You can insert that array into another array and have an array line mydata = [ [line1],[line2] ...] Hopw this helps harijay On Feb 23, 5:45?pm, Tim Chase wrote: > >> ? ?time_vec, ch1_vec, and_so_on = zip(*( > >> ? ? ?map(float, line.split()) > >> ? ? ?for line in file('in.txt'))) > > >> If this isn't homework, there are some less terse versions which > >> are a bit easier on the eyes and less like some love-child > >> between Perl and Python. > > > haha, no this isn't homework. I'm a mechanical engineering student > > working on a research project and this program is for my personal use > > to analyze the data. > > The "zip-star map-float" variant is a pretty unreadable way to go. > > The more readable versions look something like > > ? ?data = [map(float, line.split()) for line in file('in.txt')] > ? ?time_vec = [bit[0] for bit in data] > ? ?ch1_vec = [bit[1] for bit in data] > ? ?and_so_on = [bit[2] for bit in data] > > or even > > ? ?time_vec = [] > ? ?ch1_vec = [] > ? ?and_so_on = [] > ? ?for line in file('in.txt'): > ? ? ?a,b,c = map(float, line.split()) > ? ? ?time_vec.append(a) > ? ? ?ch1_vec.append(b) > ? ? ?and_so_on.append(c) > > which could also be written as > > ? ?for line in file('in.txt'): > ? ? ?line = line.split() > ? ? ?time_vec.append(float(line[0])) > ? ? ?ch1_vec.append(float(line[1])) > ? ? ?and_so_on.append(float(line[2])) > > -tkc Another way would be to use the csv module . import csv f = file.open("mytabfile.txt" From gagsl-py2 at yahoo.com.ar Mon Feb 23 18:38:37 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 23 Feb 2009 21:38:37 -0200 Subject: "import" not working? References: <7f0d1540-ae7e-4da1-936e-afbc8c6d2d49@k19g2000yqg.googlegroups.com> <11062739-5a43-43d8-b4a2-9bd494230992@t13g2000yqc.googlegroups.com> <65f8a016-a4c1-48c0-8128-47f62b865a6f@m40g2000yqh.googlegroups.com> <02ed27ed-4b4f-41b2-b4b8-7914d3f13674@v39g2000yqm.googlegroups.com> Message-ID: En Mon, 23 Feb 2009 18:10:07 -0200, Lionel escribi?: > Taking "DataFileTypes.py" module out of the "...\site-packages > \DataFileTypes" folder and placing it directly into the "site- > packages" folder seems to have cleared it up. Some problem between > package and module usage I suppose. You're right. To import module "foo", the directory containing the "foo.py" file must be listed in sys.path. To import package "foo", the directory containing the "foo" directory must be listed in sys.path; the foo directory itself must contain an "__init__.py" file. -- Gabriel Genellina From andrew at acooke.org Mon Feb 23 18:41:55 2009 From: andrew at acooke.org (andrew cooke) Date: Mon, 23 Feb 2009 20:41:55 -0300 (CLST) Subject: Peculiar swap behavior In-Reply-To: <474ac666ac46826d2be21d107a395dbc.squirrel@acooke.dyndns.org> References: <474ac666ac46826d2be21d107a395dbc.squirrel@acooke.dyndns.org> Message-ID: andrew cooke wrote: > Delaney, Timothy (Tim) wrote: >> Tim Chase wrote: >>> # swap list contents...not so much... >>> >>> m,n = [1,2,3],[4,5,6] >>> >>> m[:],n[:] = n,m >>> >>> m,n >>> ([4, 5, 6], [4, 5, 6]) > [...] >> For these types of things, it's best to expand the code out. The >> appropriate expansion of: >> m,n = [1,2,3],[4,5,6] >> m[:],n[:] = n,m >> is: >> m = [1,2,3] >> n = [4,5,6] >> m[:] = n >> n[:] = m >> [...] OTOH, for: >> m,n = [1,2,3],[4,5,6] >> m[:],n[:] = n[:],m[:] >> the expansion is more like: >> m = [1,2,3] >> n = [4,5,6] >> rhs1 = n[:] >> rhs2 = m[:] >> m[:] = rhs1 >> n[:] = rhs2 > > Maybe I'm just being stupid, but you don't seem to have explained > anything. Isn't the question: Why is the expansion different for the two > cases? Why don't both expand to have the intermediate rhs variables? To answer my own question - you can rewrite all cases to use rhs1, rhs2. The point is that when you do that: one case (m, n = n, m) reassigns variables; one case (m[:], n[:] = n, m) mutates one list to be equal to the other; one case (m[:], n[:] = n[:], m[:]) avoids seeing the effects of the mutation because a copy is generated. Which is what other people said, I guess. Andrew From rdmurray at bitdance.com Mon Feb 23 18:42:39 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Mon, 23 Feb 2009 23:42:39 +0000 (UTC) Subject: read csv error question References: <77e831100902231518q7a29e251s956be0b77d2613d@mail.gmail.com> Message-ID: Vincent Davis wrote: > I am trying to read a csv file from excel on a mac. I get the following > error.SystemExit: file some.csv, line 1: new-line character seen in unquoted > field - do you need to open the file in universal-newline mode? > I was using the example code > import csv, sys > > reader = csv.reader(open('/Volumes/vincentdavis > 2/match/data/matchdata2008.csv', "rb")) > try: > for row in reader: > print row > except csv.Error, e: > sys.exit('file %s, line %d: %s' % (filename, reader.line_num, e)) > > I think this has to do with the end of line character but I am unsure how to > fix it. I don't what to change the actual csv file I would like to fix the > code. You could try reading the error message and looking at the documentation of the 'open' function. Pay particular attention to the keywords 'universal-newline mode'. Hint: 'rb' is almost the opposite of universal newline mode, and it is very rare that you'd want to use 'b' to read a text file. --RDM From google at mrabarnett.plus.com Mon Feb 23 18:43:05 2009 From: google at mrabarnett.plus.com (MRAB) Date: Mon, 23 Feb 2009 23:43:05 +0000 Subject: read csv error question In-Reply-To: <77e831100902231518q7a29e251s956be0b77d2613d@mail.gmail.com> References: <77e831100902231518q7a29e251s956be0b77d2613d@mail.gmail.com> Message-ID: <49A33489.7060501@mrabarnett.plus.com> Vincent Davis wrote: > I am trying to read a csv file from excel on a mac. I get the following > error. > SystemExit: file some.csv, line 1: new-line character seen in unquoted > field - do you need to open the file in universal-newline mode? > I was using the example code > import csv, sys > > reader = csv.reader(open('/Volumes/vincentdavis > 2/match/data/matchdata2008.csv', "rb")) > try: > for row in reader: > print row > except csv.Error, e: > sys.exit('file %s, line %d: %s' % (filename, reader.line_num, e)) > > I think this has to do with the end of line character but I am unsure > how to fix it. I don't what to change the actual csv file I would like > to fix the code. > FYI, Mac line endings are carriage-return '\r', Linux line endings are linefeed '\n', and Windows endings are _both_ '\r\n'. Try: reader = csv.reader(open('/Volumes/vincentdavis 2/match/data/matchdata2008.csv', "U")) # or "rU" This will open the file for reading with "universal" line ending support, which will accept any kind of these line endings. (Opening it in text mode "r" should also work, assuming that the .csv file does indeed have the correct line endings for that platform.) From gagsl-py2 at yahoo.com.ar Mon Feb 23 18:47:46 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 23 Feb 2009 21:47:46 -0200 Subject: Reference or Value? References: <39e19a010902222154m1d2af37vea53e17578331939@mail.gmail.com> <6D420E20-FFC0-407B-ADCD-10D541E8C3CA@bryant.edu> Message-ID: En Mon, 23 Feb 2009 17:17:04 -0200, Brian Blais escribi?: > On Feb 23, 2009, at 3:03 , Gabriel Genellina wrote: >> En Mon, 23 Feb 2009 03:54:16 -0200, Denis Kasak >> escribi?: >>> On Mon, Feb 23, 2009 at 5:09 AM, Steven D'Aprano >>> wrote: >>>> On Sun, 22 Feb 2009 13:37:27 -0300, andrew cooke wrote: >>>> >>>>> as far as i understand things, the best model is: >>>>> >>>>> 1 - everything is an object >>>>> 2 - everything is passed by reference >>>> >>>> Except that is wrong. If it were true, you could do this: >>>> >>>> def swap(x, y): >>>> y, x = x, y >>>> >>>> a = 1 >>>> b = 2 >>>> swap(a, b) >>>> assert a == 2 and b == 1 >>>> >>>> >>>> but you can't, it does not work. Ergo, parameter passing in >>>> Python does >>>> not have the same semantics as languages that use pass-by- >>>> reference, such >>>> as Pascal and Basic. >>> >>> You could, however, argue that the swap function doesn't work as >>> expected (e.g. from a Pascal or a C++ POV) simply because the >>> underlying objects aren't mutable. >> >> That's irrelevant - mutable and immutable objects are passed >> exactly the same way. > > I don't think they were saying that mutable and immutable objects > were handled differently. They are different in terms of what a > function can do to them (mutate them or no). Thus, if you can't > mutate them, then the caller can't see any changes in the objects by > actions in the function so the swap won't work: it doesn't mutate the > objects at all. In the case of a list or a dict, then one can mutate > them, and the changes are seen in the caller. In both cases, the > object itself is passed the same way. Ok, in any case, making such claims without explanation or restricting the sense, only confuses the matter (which is innecesarily confusing already...) -- Gabriel Genellina From benjamin.kaplan at case.edu Mon Feb 23 18:52:43 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 23 Feb 2009 18:52:43 -0500 Subject: read csv error question In-Reply-To: <49A33489.7060501@mrabarnett.plus.com> References: <77e831100902231518q7a29e251s956be0b77d2613d@mail.gmail.com> <49A33489.7060501@mrabarnett.plus.com> Message-ID: On Mon, Feb 23, 2009 at 6:43 PM, MRAB wrote: > Vincent Davis wrote: > >> I am trying to read a csv file from excel on a mac. I get the following >> error. >> SystemExit: file some.csv, line 1: new-line character seen in unquoted >> field - do you need to open the file in universal-newline mode? >> I was using the example code >> import csv, sys >> >> reader = csv.reader(open('/Volumes/vincentdavis >> 2/match/data/matchdata2008.csv', "rb")) >> try: >> for row in reader: >> print row >> except csv.Error, e: >> sys.exit('file %s, line %d: %s' % (filename, reader.line_num, e)) >> >> I think this has to do with the end of line character but I am unsure how >> to fix it. I don't what to change the actual csv file I would like to fix >> the code. >> >> FYI, Mac line endings are carriage-return '\r', Linux line endings are > linefeed '\n', and Windows endings are _both_ '\r\n'. > Just to clarify, only the old Mac OSes (1-9) use carriage returns. OS X is Unix-based so it uses line feeds. > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bob at mellowood.ca Mon Feb 23 19:00:36 2009 From: bob at mellowood.ca (bvdp) Date: Mon, 23 Feb 2009 17:00:36 -0700 Subject: more on unescaping escapes In-Reply-To: References: Message-ID: I'm getting hopelessly lost in a series of \\\\\\\ s :) Let's see if this makes sense: >>> a='c:\\Program Files\\test' >>> a.decode('string-escape') 'c:\\Program Files\test' In this case there are still 2 '\'s before the P; but only 1 before the 't'. Now, when it comes time to open the file windows accepts double '\'s in the filename. So, life is fine. But, the essential part here is that we're lucky we can use '\\' or '\' in a path. What if this wasn't true? The following shows a bit of difference: >>> a='c:\Program Files\test' >>> a 'c:\\Program Files\test' In this case the interpreter has changed the '\P' to '\\P'. And if one lists the string the '\t' really is a tab. No decode() at all in any of this. I guess the general rule would be to double up '\'s in filenames and (in my program's case) to use the \x20 for spaces. Thanks. From vincent at vincentdavis.net Mon Feb 23 19:02:31 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Mon, 23 Feb 2009 17:02:31 -0700 Subject: read csv error question In-Reply-To: References: <77e831100902231518q7a29e251s956be0b77d2613d@mail.gmail.com> <49A33489.7060501@mrabarnett.plus.com> Message-ID: <77e831100902231602v754d7ccbu4a36cb91aee08e1a@mail.gmail.com> Thanks for the help the "U" was what I needed. I was reading the documentation here.http://docs.python.org/library/csv.html but I could not find the term universal-newline mode, In fact where do you find "U" I have not read it word for word but it is not obvious to me. I do even see anything about "rb" but I might just be really blind. Thanks again Vincent Davis On Mon, Feb 23, 2009 at 4:52 PM, Benjamin Kaplan wrote: > > > On Mon, Feb 23, 2009 at 6:43 PM, MRAB wrote: > >> Vincent Davis wrote: >> >>> I am trying to read a csv file from excel on a mac. I get the following >>> error. >>> SystemExit: file some.csv, line 1: new-line character seen in unquoted >>> field - do you need to open the file in universal-newline mode? >>> I was using the example code >>> import csv, sys >>> >>> reader = csv.reader(open('/Volumes/vincentdavis >>> 2/match/data/matchdata2008.csv', "rb")) >>> try: >>> for row in reader: >>> print row >>> except csv.Error, e: >>> sys.exit('file %s, line %d: %s' % (filename, reader.line_num, e)) >>> >>> I think this has to do with the end of line character but I am unsure how >>> to fix it. I don't what to change the actual csv file I would like to fix >>> the code. >>> >>> FYI, Mac line endings are carriage-return '\r', Linux line endings are >> linefeed '\n', and Windows endings are _both_ '\r\n'. >> > > Just to clarify, only the old Mac OSes (1-9) use carriage returns. OS X is > Unix-based so it uses line feeds. > > > >> >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From vincent at vincentdavis.net Mon Feb 23 19:05:55 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Mon, 23 Feb 2009 17:05:55 -0700 Subject: read csv error question In-Reply-To: References: <77e831100902231518q7a29e251s956be0b77d2613d@mail.gmail.com> <49A33489.7060501@mrabarnett.plus.com> Message-ID: <77e831100902231605x50919aq472171c709136228@mail.gmail.com> I just thought to look in the documentation for open() It seems this may contain the answers to my questions. I am just to new to python to know where my problem is, Thanks Vincent Davis 720-301-3003 On Mon, Feb 23, 2009 at 4:52 PM, Benjamin Kaplan wrote: > > > On Mon, Feb 23, 2009 at 6:43 PM, MRAB wrote: > >> Vincent Davis wrote: >> >>> I am trying to read a csv file from excel on a mac. I get the following >>> error. >>> SystemExit: file some.csv, line 1: new-line character seen in unquoted >>> field - do you need to open the file in universal-newline mode? >>> I was using the example code >>> import csv, sys >>> >>> reader = csv.reader(open('/Volumes/vincentdavis >>> 2/match/data/matchdata2008.csv', "rb")) >>> try: >>> for row in reader: >>> print row >>> except csv.Error, e: >>> sys.exit('file %s, line %d: %s' % (filename, reader.line_num, e)) >>> >>> I think this has to do with the end of line character but I am unsure how >>> to fix it. I don't what to change the actual csv file I would like to fix >>> the code. >>> >>> FYI, Mac line endings are carriage-return '\r', Linux line endings are >> linefeed '\n', and Windows endings are _both_ '\r\n'. >> > > Just to clarify, only the old Mac OSes (1-9) use carriage returns. OS X is > Unix-based so it uses line feeds. > > > >> >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From google at mrabarnett.plus.com Mon Feb 23 19:08:51 2009 From: google at mrabarnett.plus.com (MRAB) Date: Tue, 24 Feb 2009 00:08:51 +0000 Subject: read csv error question In-Reply-To: References: <77e831100902231518q7a29e251s956be0b77d2613d@mail.gmail.com> <49A33489.7060501@mrabarnett.plus.com> Message-ID: <49A33A93.7080403@mrabarnett.plus.com> Benjamin Kaplan wrote: > > > On Mon, Feb 23, 2009 at 6:43 PM, MRAB > wrote: > > Vincent Davis wrote: > > I am trying to read a csv file from excel on a mac. I get the > following error. > SystemExit: file some.csv, line 1: new-line character seen in > unquoted field - do you need to open the file in > universal-newline mode? > I was using the example code > import csv, sys > > reader = csv.reader(open('/Volumes/vincentdavis > 2/match/data/matchdata2008.csv', "rb")) > try: > for row in reader: > print row > except csv.Error, e: > sys.exit('file %s, line %d: %s' % (filename, reader.line_num, e)) > > I think this has to do with the end of line character but I am > unsure how to fix it. I don't what to change the actual csv file > I would like to fix the code. > > FYI, Mac line endings are carriage-return '\r', Linux line endings > are linefeed '\n', and Windows endings are _both_ '\r\n'. > > > Just to clarify, only the old Mac OSes (1-9) use carriage returns. OS X > is Unix-based so it uses line feeds. > Slightly OT, but PPD files on Macs used to work whatever the line endings (as they should, according to the spec), but at some point on MacOS X they broke that and PPD files would work only with CR line endings. I don't know if they've fixed that. Anyway, although it's Unix underneath I'm not so sure that they don't use CR line endings elsewhere for backwards compatibility. From andrew at acooke.org Mon Feb 23 19:10:31 2009 From: andrew at acooke.org (andrew cooke) Date: Mon, 23 Feb 2009 21:10:31 -0300 (CLST) Subject: more on unescaping escapes In-Reply-To: References: Message-ID: <1e4355c5c39776c0e4364f9becf45acc.squirrel@localhost> do you know that a string with the letter "r" in front doesn't escape slashes? it's intended for regular expressions, but would simplify things for you here too. just do a=r'c:\\Program Files\test' andrew bvdp wrote: > > I'm getting hopelessly lost in a series of \\\\\\\ s :) > > Let's see if this makes sense: > > >>> a='c:\\Program Files\\test' > >>> a.decode('string-escape') > 'c:\\Program Files\test' > > In this case there are still 2 '\'s before the P; but only 1 before the > 't'. Now, when it comes time to open the file windows accepts double > '\'s in the filename. So, life is fine. But, the essential part here is > that we're lucky we can use '\\' or '\' in a path. What if this wasn't > true? > > The following shows a bit of difference: > > >>> a='c:\Program Files\test' > >>> a > 'c:\\Program Files\test' > > In this case the interpreter has changed the '\P' to '\\P'. And if one > lists the string the '\t' really is a tab. No decode() at all in any of > this. > > I guess the general rule would be to double up '\'s in filenames and (in > my program's case) to use the \x20 for spaces. > > Thanks. > -- > http://mail.python.org/mailman/listinfo/python-list > > From gagsl-py2 at yahoo.com.ar Mon Feb 23 19:11:54 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 23 Feb 2009 22:11:54 -0200 Subject: can error messages be improved or can they be overridden ? References: <49A1567B.5020407@gmail.com> <7F0503CD69378F49BE0DC30661C6CCF62783D690@enbmail01.lsi.com> <49A272F1.7090004@gmail.com> Message-ID: En Mon, 23 Feb 2009 15:54:03 -0200, escribi?: > Stef Mientki wrote: >> but I was looking for a more general solution, >> in which I don't change the program itself, >> and where the error messages (in general) become more informative than >> it is by default. > No you are not the only one who wishes the error messages were > more informative. In one complex application I had, I made my life > easier with a hack I copied from Zope. Briefly, at the top level > of the program I trap all exceptions, get the traceback object from > sys.exc_info, format it with format_tb, and then process it to add info. > I applied several enhancements, but the one relevant to you was to grab > the locals dictionary from the last frame of the traceback, and use a > regex to split the last source line in the formatted traceback up into > candidate variable names. Then I printed the name and the repr of the > value of any of those names I found in the locals dict. Have you seen the cgitb module? Despite its name, it's a general purpose module. import cgitb cgitb.enable(format="txt") def f(some_list, x, y): return some_list[x + y] def g(a): return f(a, 1, 2) - f(a, 3, 4) g([1,2,3,4]) Output: Python 2.6: c:\apps\python26\python.exe Mon Feb 23 22:06:22 2009 A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred. C:\TEMP\test_cgitb.py in () 8 return f(a, 1, 2) - f(a, 3, 4) 9 10 g([1,2,3,4]) 11 12 g = C:\TEMP\test_cgitb.py in g(a=[1, 2, 3, 4]) 6 7 def g(a): 8 return f(a, 1, 2) - f(a, 3, 4) 9 10 g([1,2,3,4]) global f = a = [1, 2, 3, 4] C:\TEMP\test_cgitb.py in f(some_list=[1, 2, 3, 4], x=3, y=4 ) 3 4 def f(some_list, x, y): 5 return some_list[x + y] 6 7 def g(a): some_list = [1, 2, 3, 4] x = 3 y = 4 : list index out of range __class__ = [..] args = ('list index out of range',) message = 'list index out of range' The above is a description of an error in a Python program. Here is the original traceback: Traceback (most recent call last): File "test_cgitb.py", line 10, in g([1,2,3,4]) File "test_cgitb.py", line 8, in g return f(a, 1, 2) - f(a, 3, 4) File "test_cgitb.py", line 5, in f return some_list[x + y] IndexError: list index out of range -- Gabriel Genellina From tim.wintle at teamrubber.com Mon Feb 23 19:13:06 2009 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Tue, 24 Feb 2009 00:13:06 +0000 Subject: more on unescaping escapes In-Reply-To: References: Message-ID: <1235434386.6125.4.camel@tim-laptop> On Mon, 2009-02-23 at 17:00 -0700, bvdp wrote: > Let's see if this makes sense: > > >>> a='c:\\Program Files\\test' > >>> a.decode('string-escape') > 'c:\\Program Files\test' Hint: try running >>> print a and see what's written - I think that the interpreter adds extra "\" characters to escape things and make things more easy to read. i.e. >>> a = "c:\\test\\t" >>> a 'c:\\test\\t' >>> print a c:\test\t >>> so when it displays strings in the interpreter it includes escape characters, when it is printed though the output is straight to stdout and isn't escaped. Hope that helps, Tim Wintle From bob at mellowood.ca Mon Feb 23 19:18:24 2009 From: bob at mellowood.ca (bvdp) Date: Mon, 23 Feb 2009 17:18:24 -0700 Subject: more on unescaping escapes In-Reply-To: References: Message-ID: andrew cooke wrote: > do you know that a string with the letter "r" in front doesn't escape > slashes? it's intended for regular expressions, but would simplify things > for you here too. > > just do > > a=r'c:\\Program Files\test' > Yes, I knew that. Unfortunately in my program loop I really don't have the opportuity to use a raw string. But, good reminder. Thanks. From harijay at gmail.com Mon Feb 23 19:18:31 2009 From: harijay at gmail.com (harijay) Date: Mon, 23 Feb 2009 16:18:31 -0800 (PST) Subject: getting at individual bits inside byte field: struct module : bitwise operator Message-ID: <4c7d58a1-830f-4f02-ba07-aa4910f5f4e9@b16g2000yqb.googlegroups.com> In my last post I had asked about reading data from a binary file using the struct module. Thanks to some excellent help , I have managed to read in successfully most of the header of this binary format that I want to parse. These are some time-voltage traces from a digital to analog converter for my experiments. The output is according to a format mentioned here : ( http://www.dataq.com/support/techinfo/ff.htm) I have a question about how to bitmask a bunch of bytes read in from such a binary formatted file . For eg the spec says the first two bytes have different parameters in different bits . Byte 1 Byte 0 SN16 SD9 SD8 SD7 SD6 SD5 SD4 SD3 SD2 SD1 SD0 T4 T3 T2 T1 T0 I am reading in the two bytes using the following code import struct f.seek(0) element1_format = struct.Struct(" References: <7f0d1540-ae7e-4da1-936e-afbc8c6d2d49@k19g2000yqg.googlegroups.com> <11062739-5a43-43d8-b4a2-9bd494230992@t13g2000yqc.googlegroups.com> <65f8a016-a4c1-48c0-8128-47f62b865a6f@m40g2000yqh.googlegroups.com> Message-ID: On Mon, 23 Feb 2009 19:24:46 -0000, Lionel wrote: > sys.path.append("C:\DataFileTypes") Just so that we're clear, this is a *really* *bad* habit to get into. Not appending to sys.path, though that isn't often a good idea, but failing to escape your backslashes. This works because '\D' happens not to be a valid escape sequence: if your directory had instead been called "newtypes" then "C:\newtypes" would not have had the result you were expecting at all. If you really mean a backslash to be in any literal string, you should always double it: sys.path.append("C:\\DataFileTypes") IMHO, Python is somewhat inconsistent in not producing a compile-type error (or at least an annoying compile-time warning) when presented with invalid escape sequences. What it does, even though it's well-documented and usually the right guess, is to encourage bad habits. -- Rhodri James *-* Wildebeeste Herder to the Masses From clp2 at rebertia.com Mon Feb 23 19:19:19 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 23 Feb 2009 16:19:19 -0800 Subject: Need to store dictionary in file In-Reply-To: References: Message-ID: <50697b2c0902231619ub603332w1890bdbd68f7f455@mail.gmail.com> On Mon, Feb 23, 2009 at 12:38 PM, S.Selvam Siva wrote: > Hi all, > > I have a dictionary in which each key is associated with a list as value. > > eg: dic={'a':['aa','ant','all']} > > The dictionary contains 1.5 lakh keys. Tip: You might not want to use the "lakh" in international media such as internet mailinglists since it's rather Indian-subcontinent-specific and most people will be unfamiliar with it. I only know of it from coincidentally editing the Wikipedia article on it a while ago. To everyone else, that's 150,000 keys (150K if you wanna be metric about it). Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From clp2 at rebertia.com Mon Feb 23 19:23:54 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 23 Feb 2009 16:23:54 -0800 Subject: Can someone tell me why i get None at the end please this has me stuck for ages In-Reply-To: References: Message-ID: <50697b2c0902231623v6cb1c137u1d52897f1c4ec576@mail.gmail.com> On Mon, Feb 23, 2009 at 11:22 AM, Gary Wood wrote: > '''exercise to complete and test this function''' > import string > def joinStrings(items): > '''Join all the strings in stringList into one string, > and return the result. For example: > >>> print joinStrings(['very', 'hot', 'day']) > 'veryhotday' > ''' > word = [items] > for item in items: > print (item, end='') > > > def main(): > print(joinStrings(['very', 'hot','day'])) > print(joinStrings(['this', 'is','it'])) > print(joinStrings(['1', '2', '3', '4', '5'])) > > main() Reiterating myself from your previous thread which this is a duplicate of: You're not supposed to *output* the strings in joinStrings() [i.e. don't use print()!], you've supposed to *combine* them and *return* the single combined string (it's nearly identical to how you summed the numbers in the earlier exercise). The actual outputting of the combined string is done by the calls to print() *outside* of joinStrings(), in main(). Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From bob at mellowood.ca Mon Feb 23 19:26:29 2009 From: bob at mellowood.ca (bvdp) Date: Mon, 23 Feb 2009 17:26:29 -0700 Subject: more on unescaping escapes In-Reply-To: References: Message-ID: Tim Wintle wrote: > On Mon, 2009-02-23 at 17:00 -0700, bvdp wrote: >> Let's see if this makes sense: >> >> >>> a='c:\\Program Files\\test' >> >>> a.decode('string-escape') >> 'c:\\Program Files\test' > > Hint: try running > >>>> print a > > and see what's written - I think that the interpreter adds extra "\" > characters to escape things and make things more easy to read. > > i.e. > >>>> a = "c:\\test\\t" >>>> a > 'c:\\test\\t' >>>> print a > c:\test\t > > so when it displays strings in the interpreter it includes escape > characters, when it is printed though the output is straight to stdout > and isn't escaped. > > Hope that helps, > > Tim Wintle Not sure if it's more clear or not :) >>> a="c:\\Program\x20Files\\test" >>> a 'c:\\Program Files\\test' >>> print a c:\Program Files\test Which is all fine. And I didn't need to use decode(). So, in this case I'm assuming that the interpreter is converting the escapes on assignment. And, in this case the string has single \s in it. So far this is making sense. So, when I do a decode() the \t is converted to a tab, etc. I think my "problem" may be in viewing an assignment like that above as opposed to reading a line from a file with '\'s and '\x20's in it. In this case the assignment doesn't do the conversion (and that is a good thing!). Now, when I go to save the variable with the escapes I use decode() and it works. Just a matter of consistantly using a method I suppose. Still, confusing between my program reading data from a file and doing testing of strings at the interpreter. Best to do one or the other, not both. From rhodri at wildebst.demon.co.uk Mon Feb 23 19:32:18 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 24 Feb 2009 00:32:18 -0000 Subject: more on unescaping escapes In-Reply-To: References: Message-ID: On Mon, 23 Feb 2009 22:05:42 -0000, bvdp wrote: > > So, we think something is working and send of a bug fix to our client :) > > I'm not sure I understand this at all and wonder if there is bug? > > >>> a="c:\\Program\x20Files\\test" > >>> a > 'c:\\Program Files\\test' > > so far, so good. > > >>> a.decode("string-escape") > 'c:\\Program Files\test' > > Umm, not so good? The \\ before the P is okay, but the \\t is change to > \t Well yes, that's what you asked it to do. The "string-escape" decoder reads the string and replaces escape sequences with the corresponding characters. Bear in mind that it's the string as it really is that is being operated on, not the representation of it that you displayed above. In other words: b = a.decode("string-escape") is equivalent to: b = "C:\Program Files\test" "\P" isn't a valid escape sequence, so it doesn't get replaced. "\t" represents a tab, so it does. -- Rhodri James *-* Wildebeeste Herder to the Masses From clp2 at rebertia.com Mon Feb 23 19:32:48 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 23 Feb 2009 16:32:48 -0800 Subject: intermediate python csv reader/writer question from a beginner In-Reply-To: References: Message-ID: <50697b2c0902231632s76bfb28gff055b92bf725411@mail.gmail.com> On Mon, Feb 23, 2009 at 1:33 PM, Learning Python wrote: > anything related to csv, I usually use VB within excel to manipulate > the data, nonetheless, i finally got the courage to take a dive into > python. i have viewed a lot of googled csv tutorials, but none of > them address everything i need. Nonetheless, I was wondering if > someone can help me manipulate the sample csv (sample.csv) I have > generated: For reading and writing CSV files, see the `csv` module in the standard library (http://docs.python.org/library/csv.html). Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From gagsl-py2 at yahoo.com.ar Mon Feb 23 19:35:14 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 23 Feb 2009 22:35:14 -0200 Subject: Can someone tell me why i get None at the end please this has me stuck for ages References: Message-ID: En Mon, 23 Feb 2009 17:22:16 -0200, Gary Wood escribi?: > '''exercise to complete and test this function''' > import string > def joinStrings(items): > '''Join all the strings in stringList into one string, > and return the result. For example: > >>> print joinStrings(['very', 'hot', 'day']) > 'veryhotday' > ''' > word = [items] > for item in items: > print (item, end='') > def main(): > print(joinStrings(['very', 'hot','day'])) > print(joinStrings(['this', 'is','it'])) > print(joinStrings(['1', '2', '3', '4', '5'])) > > main() See this: py> def sum(a, b): ... "Returns the sum of two numbers" ... print a+b ... py> print sum(2,3) 5 None The function above does *not* do what is expected. It should compute a+b AND RETURN THE RESULT (instead, it PRINTS the result and returns nothing, None in Python parlance). It's up to the caller to decide what to do with the resultant value; if he wants to print it, fine; but maybe he wants to carry on other operations: py> print sum(2,3) * 4 5 Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for *: 'NoneType' and 'int' If the function claims to *return* something, it should return that thing: py> def sum(a, b): ... "Returns the sum of two numbers" ... return a+b ... py> print sum(2,3) 5 py> print sum(2,3) * 4 20 Back to your exercise, you have to join the strings together WITHOUT USING PRINT. You have to build a NEW string, joining the pieces one by one, and return the new, concatenated string. If I'm not mistaken, there were some clues in the exercise statement that you're ignoring and should help a lot. -- Gabriel Genellina From rhodri at wildebst.demon.co.uk Mon Feb 23 19:37:11 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 24 Feb 2009 00:37:11 -0000 Subject: more on unescaping escapes In-Reply-To: References: Message-ID: On Tue, 24 Feb 2009 00:26:29 -0000, bvdp wrote: > So, in this case I'm assuming that the interpreter is converting the > escapes on assignment. The compiler converts the escapes on creating its internal representation of the string, before assignment ever gets involved. -- Rhodri James *-* Wildebeeste Herder to the Masses From python at bdurham.com Mon Feb 23 19:37:15 2009 From: python at bdurham.com (python at bdurham.com) Date: Mon, 23 Feb 2009 19:37:15 -0500 Subject: can error messages be improved or can they be overridden ? In-Reply-To: References: <49A1567B.5020407@gmail.com> <7F0503CD69378F49BE0DC30661C6CCF62783D690@enbmail01.lsi.com> <49A272F1.7090004@gmail.com> Message-ID: <1235435835.25504.1302013015@webmail.messagingengine.com> Gabriel, > Have you seen the cgitb module? Despite its name, it's a general purpose module. > > > import cgitb > cgitb.enable(format="txt") > > My vote for tip of the week, perhaps even month. I'm not part of this thread, but your post is a great help on another project. Thank you! Regards, Malcolm From google at mrabarnett.plus.com Mon Feb 23 19:40:09 2009 From: google at mrabarnett.plus.com (MRAB) Date: Tue, 24 Feb 2009 00:40:09 +0000 Subject: getting at individual bits inside byte field: struct module : bitwise operator In-Reply-To: <4c7d58a1-830f-4f02-ba07-aa4910f5f4e9@b16g2000yqb.googlegroups.com> References: <4c7d58a1-830f-4f02-ba07-aa4910f5f4e9@b16g2000yqb.googlegroups.com> Message-ID: <49A341E9.8080107@mrabarnett.plus.com> harijay wrote: > In my last post I had asked about reading data from a binary file > using the struct module. > Thanks to some excellent help , I have managed to read in > successfully > most of the header of this binary format that I want to parse. These > are some time-voltage traces from a digital > to analog converter for my experiments. The output is according to a > format > mentioned here : ( http://www.dataq.com/support/techinfo/ff.htm) > > I have a question about how to bitmask a bunch of bytes read in from > such a binary formatted file . > > For eg the spec says the first two bytes have different parameters in > different bits . > Byte 1 Byte 0 > SN16 SD9 SD8 SD7 SD6 SD5 SD4 SD3 > SD2 SD1 SD0 T4 T3 T2 T1 T0 > > I am reading in the two bytes using the following code > > import struct > f.seek(0) > element1_format = struct.Struct(" (element1,) = element1_format.unpack(f.read(2)) > > Now element1 has type "str" . That's not what I get. For me it's an int. > How do I apply a bitmask to this to get > at information in the component bits . > Since the entire file format has many such bitmasked fields and since > this is my first venture into binary formats and c-type structs , I > wanted to know how to read values inside a byte using python. > My few tries at using bitwise operators ( element1 & 0x001f) are > frustrated by messages that say " unsupported operand type(s) for &: > 'str' and 'int' " . > How can I keep my string objects as bits and apply bitmasks to them > Any help in this will be greatly appreciated. > The T bits are (element1 & 0x1F), the SD bits are ((element1 >> 5) & 0x2FF) and the SN16 bit is (element1 >> 15). From clp2 at rebertia.com Mon Feb 23 19:41:50 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 23 Feb 2009 16:41:50 -0800 Subject: more on unescaping escapes In-Reply-To: References: Message-ID: <50697b2c0902231641l5f0938c5j59441cc8400ed560@mail.gmail.com> On Mon, Feb 23, 2009 at 4:26 PM, bvdp wrote: [problem with Python and Windows paths using backslashes] Is there any particular reason you can't just internally use regular forward-slashes for the paths? They work in Windows from Python in nearly all cases and you can easily interconvert using os.pathsep if you want the path to be pretty when you show it to (or get it from) the user or whatever. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From bob at mellowood.ca Mon Feb 23 19:46:34 2009 From: bob at mellowood.ca (bvdp) Date: Mon, 23 Feb 2009 17:46:34 -0700 Subject: more on unescaping escapes In-Reply-To: References: Message-ID: Chris Rebert wrote: > On Mon, Feb 23, 2009 at 4:26 PM, bvdp wrote: > [problem with Python and Windows paths using backslashes] > > Is there any particular reason you can't just internally use regular > forward-slashes for the paths? They work in Windows from Python in > nearly all cases and you can easily interconvert using os.pathsep if > you want the path to be pretty when you show it to (or get it from) > the user or whatever. > > Cheers, > Chris > Just because I never really thought too much about it :) I'm doing my work on a linux box and my user is on windows ... and he's used to using '\' ... but, you are absolutely right! Just use '/' on both systems and be done with it. Of course I still need to use \x20 for spaces, but that is easy. Thanks for the suggestion! From bob at mellowood.ca Mon Feb 23 19:48:32 2009 From: bob at mellowood.ca (bvdp) Date: Mon, 23 Feb 2009 17:48:32 -0700 Subject: more on unescaping escapes In-Reply-To: References: Message-ID: > Bear in mind that it's the string as it really is that is > being operated on, not the representation of it that you displayed Yes, that is the confusion ... what is displayed and what's actually in the string. I think I understand it all now :) Thanks. From rhodri at wildebst.demon.co.uk Mon Feb 23 19:54:45 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 24 Feb 2009 00:54:45 -0000 Subject: Python AppStore / Marketplace In-Reply-To: References: <49A311C3.80707@gmail.com> Message-ID: On Mon, 23 Feb 2009 22:12:09 -0000, Steve Holden wrote: > Michael Torrie wrote: >> Steve Holden wrote: >>> Unfortunately I have no idea what a "souq" is, so I suspect this may be >>> linguistically biased against English speakers. Or perhaps I'm just >>> ignorant. >> >> Nah. Not biased against English speakers. Just biased against the >> un-traveled. :) > > Don't think so. I've visited roughly twenty-five difference countries > and traveled I-don't-know-how-many miles, but certainly over a million. > Unless you'd like to redefine "un-traveled" ... ? > > But I do (still) speak English (of a kind). A souq is a bazaar :-) Well, close enough anyway. It's another arabic word that translates as "market" in both the mercantile and financial senses, I believe. Maybe I've just read too much arabic-themed fiction, but I was surprised not to find the word in my trusty Chambers. -- Rhodri James *-* Wildebeeste Herder to the Masses From gagsl-py2 at yahoo.com.ar Mon Feb 23 19:55:16 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 23 Feb 2009 22:55:16 -0200 Subject: getting at individual bits inside byte field: struct module : bitwise operator References: <4c7d58a1-830f-4f02-ba07-aa4910f5f4e9@b16g2000yqb.googlegroups.com> Message-ID: En Mon, 23 Feb 2009 22:18:31 -0200, harijay escribi?: > mentioned here : ( http://www.dataq.com/support/techinfo/ff.htm) > > I have a question about how to bitmask a bunch of bytes read in from > such a binary formatted file . > > For eg the spec says the first two bytes have different parameters in > different bits . > Byte 1 Byte 0 > SN16 SD9 SD8 SD7 SD6 SD5 SD4 SD3 > SD2 SD1 SD0 T4 T3 T2 T1 T0 > > I am reading in the two bytes using the following code > > import struct > f.seek(0) > element1_format = struct.Struct(" (element1,) = element1_format.unpack(f.read(2)) > > Now element1 has type "str" . No, should be type 'int', that's what the H format means. > How do I apply a bitmask to this to get > at information in the component bits . > Since the entire file format has many such bitmasked fields and since > this is my first venture into binary formats and c-type structs , I > wanted to know how to read values inside a byte using python. > My few tries at using bitwise operators ( element1 & 0x001f) are > frustrated by messages that say " unsupported operand type(s) for &: > 'str' and 'int' " . Try again - it should work. Perhaps you used the wrong variable name? instead of the resultant from struct.unpack py> import struct py> element1_format = struct.Struct(" (element1,) = element1_format.unpack('AB') py> element1 16961 py> element1 & 0x007F 65 py> chr(65) 'A' -- Gabriel Genellina From rhodri at wildebst.demon.co.uk Mon Feb 23 19:56:36 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 24 Feb 2009 00:56:36 -0000 Subject: more on unescaping escapes In-Reply-To: References: Message-ID: On Tue, 24 Feb 2009 00:46:34 -0000, bvdp wrote: > Just because I never really thought too much about it :) I'm doing my > work on a linux box and my user is on windows ... and he's used to using > '\' ... but, you are absolutely right! Just use '/' on both systems and > be done with it. Of course I still need to use \x20 for spaces, but that > is easy. Erm, no. "\x20" is exactly the same as " " in a string literal. -- Rhodri James *-* Wildebeeste Herder to the Masses From jjposner at snet.net Mon Feb 23 19:58:44 2009 From: jjposner at snet.net (John Posner) Date: Mon, 23 Feb 2009 16:58:44 -0800 (PST) Subject: Peculiar swap behavior Message-ID: <480179.92204.qm@web83107.mail.mud.yahoo.com> >> m,n = [1,2,3],[4,5,6] >> m[:],n[:] = n,m I believe this is an RTFM situation. In the Python 2.6.1 help topic "Simple Statements" > "Assignment Statements", see this para: If the target is a slicing: The primary expression in the reference is evaluated. It should yield a mutable sequence object (such as a list). The assigned object should be a sequence object of the same type. Next, the lower and upper bound expressions are evaluated, insofar they are present; defaults are zero and the sequence?s length. The bounds should evaluate to (small) integers. If either bound is negative, the sequence?s length is added to it. The resulting bounds are clipped to lie between zero and the sequence?s length, inclusive. Finally, the sequence object is asked to replace the slice with the items of the assigned sequence. The length of the slice may be different from the length of the assigned sequence, thus changing the length of the target sequence, if the object allows it. The crucial sentence is: Finally, the sequence object is asked to replace the slice with the items of the assigned sequence. In our example, this means that the assignment of the 3-item slicing m[:] = n ... has this result: * the identifier m[0] now refers to the same object as the identifier n[0] * the identifier m[1] now refers to the same object as the identifier n[1] * the identifier m[2] now refers to the same object as the identifier n[2] Although m and n are still different list objects, all of the "slots" in both lists now contain the same (sub)objects. I've verified the above analysis to my own satisfaction using IDLE 2.6.1: --------- def list_ids(mylist): return id(mylist), map(id, mylist) m,n = [1,2,3],[4,5,6] print m,n print "m:", list_ids(m) print "n:", list_ids(n) m[:], n[:] = n, m print m,n print "m:", list_ids(m) print "n:", list_ids(n) --------- output: [1, 2, 3] [4, 5, 6] m: (4589728, [10970688, 10970676, 10970664]) n: (11311344, [10970652, 10970640, 10970628]) [4, 5, 6] [4, 5, 6] m: (4589728, [10970652, 10970640, 10970628]) n: (11311344, [10970652, 10970640, 10970628]) -John -------------- next part -------------- An HTML attachment was scrubbed... URL: From mwilson at the-wire.com Mon Feb 23 20:03:28 2009 From: mwilson at the-wire.com (Mel) Date: Mon, 23 Feb 2009 20:03:28 -0500 Subject: more on unescaping escapes References: Message-ID: bvdp wrote: > Not sure if it's more clear or not :) > > >>> a="c:\\Program\x20Files\\test" > >>> a > 'c:\\Program Files\\test' > >>> print a > c:\Program Files\test > > Which is all fine. And I didn't need to use decode(). > > So, in this case I'm assuming that the interpreter is converting the > escapes on assignment. And, in this case the string has single \s in it. Strictly speaking, the compiler is converting the escapes when it uses the literal to create a string value. Mel. From gagsl-py2 at yahoo.com.ar Mon Feb 23 20:14:42 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 23 Feb 2009 23:14:42 -0200 Subject: more on unescaping escapes References: Message-ID: En Mon, 23 Feb 2009 22:46:34 -0200, bvdp escribi?: > Chris Rebert wrote: >> On Mon, Feb 23, 2009 at 4:26 PM, bvdp wrote: >> [problem with Python and Windows paths using backslashes] >> Is there any particular reason you can't just internally use regular >> forward-slashes for the paths? They work in Windows from Python in >> nearly all cases and you can easily interconvert using os.pathsep if >> you want the path to be pretty when you show it to (or get it from) >> the user or whatever. > > Just because I never really thought too much about it :) I'm doing my > work on a linux box and my user is on windows ... and he's used to using > '\' ... but, you are absolutely right! Just use '/' on both systems and > be done with it. Of course I still need to use \x20 for spaces, but that > is easy. Why is that? "\x20" is exactly the same as " ". It's not like %20 in URLs, that becomes a space only after decoding. py> '\x20' == ' ' True py> '\x20' is ' ' True (ok, the last line might show False, but being True means that both are the very same object) -- Gabriel Genellina From rhodri at wildebst.demon.co.uk Mon Feb 23 20:29:17 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 24 Feb 2009 01:29:17 -0000 Subject: thanks very much indeed for your help is there a better way to do this (python3) newby In-Reply-To: References: Message-ID: On Mon, 23 Feb 2009 23:33:31 -0000, Gary Wood wrote: > '''exercise to complete and test this function''' > import string > def joinStrings(items): > '''Join all the strings in stringList into one string, > and return the result. For example: > >>> print joinStrings(['very', 'hot', 'day']) > 'veryhotday' > ''' > for i in items: > return (''.join(items)) As I'm sure your teacher will point out, this is sub-optimal :-) That for-loop isn't doing anything, because you always return out of it at the first iteration. I suspect that you're expected to concatenate the strings together by hand and return the resulting string once you've done them all. Trying writing it that way. PS: it helps a lot if what you say in the doc string matches what you write in the rest of the code. In this case you call your input string "items", but then say "Join all the strings in *stringList*..." -- Rhodri James *-* Wildebeeste Herder to the Masses From bob at mellowood.ca Mon Feb 23 20:31:20 2009 From: bob at mellowood.ca (bvdp) Date: Mon, 23 Feb 2009 18:31:20 -0700 Subject: more on unescaping escapes In-Reply-To: References: Message-ID: Gabriel Genellina wrote: > En Mon, 23 Feb 2009 22:46:34 -0200, bvdp escribi?: > >> Chris Rebert wrote: >>> On Mon, Feb 23, 2009 at 4:26 PM, bvdp wrote: >>> [problem with Python and Windows paths using backslashes] >>> Is there any particular reason you can't just internally use regular >>> forward-slashes for the paths? They work in Windows from Python in >>> nearly all cases and you can easily interconvert using os.pathsep if >>> you want the path to be pretty when you show it to (or get it from) >>> the user or whatever. >> >> Just because I never really thought too much about it :) I'm doing my >> work on a linux box and my user is on windows ... and he's used to >> using '\' ... but, you are absolutely right! Just use '/' on both >> systems and be done with it. Of course I still need to use \x20 for >> spaces, but that is easy. > > Why is that? "\x20" is exactly the same as " ". It's not like %20 in > URLs, that becomes a space only after decoding. > > py> '\x20' == ' ' > True > py> '\x20' is ' ' > True > > (ok, the last line might show False, but being True means that both are > the very same object) > I need to use the \x20 because of my parser. I'm reading unquoted lines from a file. The file creater needs to use the form "foo\x20bar" without the quotes in the file so my parser can read it as a single token. Later, the string/token needs to be decoded with the \x20 converted to a space. So, in my file "foo bar" (no quotes) is read as 2 tokens; "foo\x20bar" is one. So, it's not really a problem of what happens when you assign a string in the form "foo bar", rather how to convert the \x20 in a string to a space. I think the \\ just complicates the entire issue. From rdmurray at bitdance.com Mon Feb 23 20:40:59 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Tue, 24 Feb 2009 01:40:59 +0000 (UTC) Subject: can error messages be improved or can they be overridden ? References: <49A1567B.5020407@gmail.com> <7F0503CD69378F49BE0DC30661C6CCF62783D690@enbmail01.lsi.com> <49A272F1.7090004@gmail.com> <9afda87e04d99d252c989c08ade7699f.squirrel@acooke.dyndns.org> Message-ID: "andrew cooke" wrote: > rdmurray at bitdance.com wrote: > [...] > > (You know, I really ought to revisit that routine and make it part > > of my standard development toolbox.) > > please post it.... OK. I dug it up, cut out the stuff that was specific to the application, freshened it up a little, and added a little demo. I don't claim this is the best possible way to do this (it certainly could be made smarter, possibly by using python facilities to actually parse the line; right now it takes a very brute force approach to trying to find variables), but it served my purposes and perhaps it will help others. Oh, yeah, and I just added the globals bit without thoroughly testing it...I think it probably doesn't help much and may be misleading when the traceback is thrown in an imported module. Enjoy. --RDM ------------------------------------------------------------------ from traceback import format_tb, format_exception_only from sys import exc_info from re import compile varsplitter = compile("[^0-9a-zA-Z_]") def format_exception(): """ Add a dump of any variables we can identify from the failing program line to the end of the traceback. The deep mojo for doing this came from an example in the Zope core plus documentation in the Python Quick Reference. """ etype, value, tb = exc_info() plaintb = format_tb(tb) result=['Traceback (innermost last):'] for line in plaintb: result.append(line) f = tb.tb_frame tb = tb.tb_next locals=f.f_locals vars = varsplitter.split(line.split('\n')[-2]) dvars = set() self = None if 'self' in locals: self = locals['self'] for v in vars: if v in dvars: continue dvars.add(v) if v in locals: result.append(' %s: %r\n' % (v,locals[v])) if self and hasattr(self, v): result.append(' self.%s: %r\n' % (v,getattr(self, v))) if v in globals(): result.append(' (global) %s: %r\n' % (v,globals()[v])) result.extend(format_exception_only(etype, value)) return ''.join(result) class Demo: y = 200 def __init__(self, x): self.x = x def bad(self): x = [1, 2] y = (5, 9, 9) y[1] = x[2] + foo foo = 'a value' def main(): bar = Demo('some value') bar.bad() if __name__=='__main__': try: main() except Exception: print format_exception() ------------------------------------------------------------------ rdmurray at maestro:~>python tb.py Traceback (innermost last): File "tb.py", line 56, in try: main() File "tb.py", line 52, in main bar.bad() File "tb.py", line 46, in bad y[1] = x[2] + foo y: (5, 9, 9) self.y: 200 x: [1, 2] self.x: 'some value' (global) foo: 'a value' IndexError: list index out of range ------------------------------------------------------------------ From mcrute at gmail.com Mon Feb 23 20:41:59 2009 From: mcrute at gmail.com (Michael Crute) Date: Mon, 23 Feb 2009 20:41:59 -0500 Subject: Code in __init__.py, is it bad form? Message-ID: <558b73fb0902231741g437fc3bfid81844d6cb403daf@mail.gmail.com> Is it bad form (i.e. non-pythonic) to have code in your __init__.py files? I know this is subjective so I'm just looking for the general consensus. I've heard both sides of the story and I personally feel its okay if the code pertains to the whole module but have an open mind about the matter. If you object to code in __init__.py why, and what alternatives do you propose? -- ________________________________ Michael E. Crute http://mike.crute.org God put me on this earth to accomplish a certain number of things. Right now I am so far behind that I will never die. --Bill Watterson From gagsl-py2 at yahoo.com.ar Mon Feb 23 20:47:43 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 23 Feb 2009 23:47:43 -0200 Subject: Need to store dictionary in file References: Message-ID: En Mon, 23 Feb 2009 18:38:56 -0200, S.Selvam Siva escribi?: > I have a dictionary in which each key is associated with a list as value. > > eg: *dic={'a':['aa','ant','all']}* > > The dictionary contains *1.5 lakh keys*. > Now i want to store it to a file,and need to be loaded to python program > during execution. > I expect your ideas/suggestions. > > Note:I think cPickle,bsddb can be used for this purpose,but i want to > know > the best solution which runs *faster*. Just try and see. You have to measure performance in your own specific use case. What is best for others may not be the best for you; for example, your dictionary appears to contain only strings, and this may affect performance. I would try: cPickle with protocol=-1 a cPickle.Pickler object with protocol=-1 , also setting fast=1 in the instance the csv module a SQL database, like sqlite bsddb a custom format, perhaps one word per line + blank line as separator. But I would reconsider if having the whole dictionary in memory all the time is a good idea. Databases are good for storing and retrieving key->values. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Mon Feb 23 20:54:18 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 23 Feb 2009 23:54:18 -0200 Subject: more on unescaping escapes References: Message-ID: En Mon, 23 Feb 2009 23:31:20 -0200, bvdp escribi?: > Gabriel Genellina wrote: >> En Mon, 23 Feb 2009 22:46:34 -0200, bvdp escribi?: >>> Chris Rebert wrote: >>>> On Mon, Feb 23, 2009 at 4:26 PM, bvdp wrote: >>>> [problem with Python and Windows paths using backslashes] >>>> Is there any particular reason you can't just internally use regular >>>> forward-slashes for the paths? [...] >>> >>> you are absolutely right! Just use '/' on both systems and be done >>> with it. Of course I still need to use \x20 for spaces, but that is >>> easy. >> Why is that? "\x20" is exactly the same as " ". It's not like %20 in >> URLs, that becomes a space only after decoding. > > I need to use the \x20 because of my parser. I'm reading unquoted lines > from a file. The file creater needs to use the form "foo\x20bar" without > the quotes in the file so my parser can read it as a single token. > Later, the string/token needs to be decoded with the \x20 converted to a > space. > > So, in my file "foo bar" (no quotes) is read as 2 tokens; "foo\x20bar" > is one. > > So, it's not really a problem of what happens when you assign a string > in the form "foo bar", rather how to convert the \x20 in a string to a > space. I think the \\ just complicates the entire issue. Just thinking, if you was reading the string from a file, why were you worried about \\ and \ in the first place? (Ok, you moved to use / so this is moot now). -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Mon Feb 23 21:02:04 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 24 Feb 2009 00:02:04 -0200 Subject: Peculiar swap behavior References: <480179.92204.qm@web83107.mail.mud.yahoo.com> Message-ID: En Mon, 23 Feb 2009 22:58:44 -0200, John Posner escribi?: >>> m,n = [1,2,3],[4,5,6] >>> m[:],n[:] = n,m > > I believe this is an RTFM situation. In the Python 2.6.1 help topic > "Simple Statements" > "Assignment Statements", see this para: Yes, the other relevant paragraph is: """An assignment statement evaluates the expression list (remember that this can be a single expression or a comma-separated list, the latter yielding a tuple) and assigns the single resulting object to each of the target lists, from left to right.""" Note that the RHS is evaluated COMPLETELY before assignment to the LHS begins. The assignment: a, b = c, d is NOT equivalent to: a = c b = d except in simple cases. -- Gabriel Genellina From steve at holdenweb.com Mon Feb 23 21:03:18 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 23 Feb 2009 21:03:18 -0500 Subject: Code in __init__.py, is it bad form? In-Reply-To: <558b73fb0902231741g437fc3bfid81844d6cb403daf@mail.gmail.com> References: <558b73fb0902231741g437fc3bfid81844d6cb403daf@mail.gmail.com> Message-ID: Michael Crute wrote: > Is it bad form (i.e. non-pythonic) to have code in your __init__.py > files? I know this is subjective so I'm just looking for the general > consensus. I've heard both sides of the story and I personally feel > its okay if the code pertains to the whole module but have an open > mind about the matter. If you object to code in __init__.py why, and > what alternatives do you propose? > No, it's absolutely fine. One common usage is to import symbols from sub-modules so that they are available from a simple import of the package. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From greg.ewing at canterbury.ac.nz Mon Feb 23 21:06:18 2009 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Tue, 24 Feb 2009 15:06:18 +1300 Subject: ANN: SuPy 1.6 Message-ID: SuPy 1.6 Available ------------------ http://www.cosc.canterbury.ac.nz/greg.ewing/SuPy/ Fixed some bugs in the Tool and Observer classes, and in the linetool example. What is SuPy? ------------- SuPy is a plugin for the Sketchup 3D modelling application that lets you script it in Python. -- Greg Ewing greg.ewing at canterbury.ac.nz From bob at mellowood.ca Mon Feb 23 21:18:28 2009 From: bob at mellowood.ca (bvdp) Date: Mon, 23 Feb 2009 19:18:28 -0700 Subject: more on unescaping escapes In-Reply-To: References: Message-ID: Gabriel Genellina wrote: > En Mon, 23 Feb 2009 23:31:20 -0200, bvdp escribi?: >> Gabriel Genellina wrote: >>> En Mon, 23 Feb 2009 22:46:34 -0200, bvdp escribi?: >>>> Chris Rebert wrote: >>>>> On Mon, Feb 23, 2009 at 4:26 PM, bvdp wrote: > >>>>> [problem with Python and Windows paths using backslashes] >>>>> Is there any particular reason you can't just internally use regular >>>>> forward-slashes for the paths? [...] >>>> >>>> you are absolutely right! Just use '/' on both systems and be done >>>> with it. Of course I still need to use \x20 for spaces, but that is >>>> easy. >>> Why is that? "\x20" is exactly the same as " ". It's not like %20 in >>> URLs, that becomes a space only after decoding. >> >> I need to use the \x20 because of my parser. I'm reading unquoted >> lines from a file. The file creater needs to use the form "foo\x20bar" >> without the quotes in the file so my parser can read it as a single >> token. Later, the string/token needs to be decoded with the \x20 >> converted to a space. >> >> So, in my file "foo bar" (no quotes) is read as 2 tokens; "foo\x20bar" >> is one. >> >> So, it's not really a problem of what happens when you assign a string >> in the form "foo bar", rather how to convert the \x20 in a string to a >> space. I think the \\ just complicates the entire issue. > > Just thinking, if you was reading the string from a file, why were you > worried about \\ and \ in the first place? (Ok, you moved to use / so > this is moot now). > Just cruft introduced while I was trying to figure it all out. Having to figure the \\ and \x20 at same time with file and keyboard input just confused the entire issue :) Having the user set a line like c:\\Program\x20File ... works just fine. I'll suggest he use c:/program\x20files to make it bit simple for HIM, not my parser. Unfortunately, due to some bad design decisions on my part about 5 years ago I'm afraid I'm stuck with the \x20. Thanks. From mcrute at gmail.com Mon Feb 23 21:21:57 2009 From: mcrute at gmail.com (Michael Crute) Date: Mon, 23 Feb 2009 21:21:57 -0500 Subject: Code in __init__.py, is it bad form? In-Reply-To: References: <558b73fb0902231741g437fc3bfid81844d6cb403daf@mail.gmail.com> Message-ID: <558b73fb0902231821o48c87d51m49e66981106c0ae7@mail.gmail.com> On Mon, Feb 23, 2009 at 9:03 PM, Steve Holden wrote: > Michael Crute wrote: >> Is it bad form (i.e. non-pythonic) to have code in your __init__.py >> files? I know this is subjective so I'm just looking for the general >> consensus. I've heard both sides of the story and I personally feel >> its okay if the code pertains to the whole module but have an open >> mind about the matter. If you object to code in __init__.py why, and >> what alternatives do you propose? >> > No, it's absolutely fine. One common usage is to import symbols from > sub-modules so that they are available from a simple import of the package. Yeah, I use it often for that I'm talking more about stuff like utility functions, main methods, etc... -mike -- ________________________________ Michael E. Crute http://mike.crute.org God put me on this earth to accomplish a certain number of things. Right now I am so far behind that I will never die. --Bill Watterson From cs at zip.com.au Mon Feb 23 21:30:11 2009 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 24 Feb 2009 13:30:11 +1100 Subject: ZSI / MTOM In-Reply-To: <1fd305a1-d087-4902-83ba-780e97bd042f@m24g2000vbp.googlegroups.com> Message-ID: <20090224023011.GA31951@cskk.homeip.net> On 23Feb2009 08:09, John Ionides wrote: | I have project for which I would like to have a python web service | including MTOM. It seems that ZSI is the most complete python web | service library but that it doesn't currently support MTOM - and | having worked through the code it looks as though it isn't going to be | exactly simple. Is there anyone working on a patch (or interested in | collaborating if it comes down to writing one)? Maybe you should ask on the pywebsvcs mailing list, where ZSI discussion takes place? http://pywebsvcs.sourceforge.net/ Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Software engineering? That's like military intelligence, isn't it? - Doug Mohney From benjamin at python.org Mon Feb 23 21:41:33 2009 From: benjamin at python.org (Benjamin Peterson) Date: Tue, 24 Feb 2009 02:41:33 +0000 (UTC) Subject: Code in =?utf-8?b?X19pbml0X18ucHks?= is it bad form? References: <558b73fb0902231741g437fc3bfid81844d6cb403daf@mail.gmail.com> <558b73fb0902231821o48c87d51m49e66981106c0ae7@mail.gmail.com> Message-ID: Michael Crute gmail.com> writes: > On Mon, Feb 23, 2009 at 9:03 PM, Steve Holden holdenweb.com> wrote: > > No, it's absolutely fine. One common usage is to import symbols from > > sub-modules so that they are available from a simple import of the package. > > Yeah, I use it often for that I'm talking more about stuff like > utility functions, main methods, etc... There's no overarching Python doctrine forbidding you to do it. It has simply become a matter of taste. Personally, I tend to put utility functions in their own module (eg. util), but I do use __init__ for main methods and such. From bignose+hates-spam at benfinney.id.au Mon Feb 23 21:43:06 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Tue, 24 Feb 2009 13:43:06 +1100 Subject: Code in __init__.py, is it bad form? References: Message-ID: <873ae4imh1.fsf@benfinney.id.au> Michael Crute writes: > Is it bad form (i.e. non-pythonic) to have code in your __init__.py > files? No, it's good form, but *only* for code that truly pertains to the entire package. Anything that can reasonably be in a module other than ?__init__?, should be. That leaves the following things suitable for code in ?__init__?, OTTOMH: * Metadata attributes for the package (e.g. version string). * Docstring for the package * ?from foo import bar? to present attributes of the package that are actually implemented in a module, which should be just about everything in the package. > If you object to code in __init__.py why I object only to code that isn't clearly ?relates to the entire package and can't reasonably be implemented in a separate module?. If you're going to the effort of making a package (rather than just coding the namespace as a single module), then the implementation should be in modules other than ?__init__? to allow easier re-use, re-factoring, and testing. -- \ ?When I wake up in the morning, I just can't get started until | `\ I've had that first, piping hot pot of coffee. Oh, I've tried | _o__) other enemas...? ?Emo Philips | Ben Finney From wuwei23 at gmail.com Mon Feb 23 21:43:15 2009 From: wuwei23 at gmail.com (alex23) Date: Mon, 23 Feb 2009 18:43:15 -0800 (PST) Subject: Code in __init__.py, is it bad form? References: <558b73fb0902231741g437fc3bfid81844d6cb403daf@mail.gmail.com> Message-ID: <8988a1ae-4741-4484-aa96-b00386ca58b7@v38g2000yqb.googlegroups.com> On Feb 24, 12:21?pm, Michael Crute wrote: > Yeah, I use it often for that I'm talking more about stuff like > utility functions, main methods, etc... Personally, I use it only for those tasks related to 'initialising' the package, a la the importing of various modules for convenience sake (as mentioned by Steve). I don't expect a class to define its method within its __init__, so I'd find it unusual for a package to be defining any kind of functionality within its __init__.py. I wouldn't _not_ use your code, but I might eye it warily... :) From mcrute at gmail.com Mon Feb 23 21:48:36 2009 From: mcrute at gmail.com (Michael Crute) Date: Mon, 23 Feb 2009 21:48:36 -0500 Subject: Code in __init__.py, is it bad form? In-Reply-To: References: <558b73fb0902231741g437fc3bfid81844d6cb403daf@mail.gmail.com> <558b73fb0902231821o48c87d51m49e66981106c0ae7@mail.gmail.com> Message-ID: <558b73fb0902231848w21810aaau45b950c99efd265b@mail.gmail.com> On Mon, Feb 23, 2009 at 9:41 PM, Benjamin Peterson wrote: > Michael Crute gmail.com> writes: >> On Mon, Feb 23, 2009 at 9:03 PM, Steve Holden holdenweb.com> wrote: >> > No, it's absolutely fine. One common usage is to import symbols from >> > sub-modules so that they are available from a simple import of the package. >> >> Yeah, I use it often for that I'm talking more about stuff like >> utility functions, main methods, etc... > > There's no overarching Python doctrine forbidding you to do it. It has simply > become a matter of taste. Personally, I tend to put utility functions in their > own module (eg. util), but I do use __init__ for main methods and such. Okay, so assuming I have decent judgment it sounds like I'm not doing anything patently wrong. Thanks for the input. -mike -- ________________________________ Michael E. Crute http://mike.crute.org God put me on this earth to accomplish a certain number of things. Right now I am so far behind that I will never die. --Bill Watterson From ccormie at aussiemail.com.au Mon Feb 23 21:49:41 2009 From: ccormie at aussiemail.com.au (Chris Cormie) Date: Tue, 24 Feb 2009 13:49:41 +1100 Subject: How does one get from "ImportError: DLL load failed:..." to a culprit .dll and symbol? In-Reply-To: References: <01b213c7$0$20626$c3e8da3@news.astraweb.com> <5850dc46-638f-4a3c-8d9a-f84bf7523979@o11g2000yql.googlegroups.com> <01b28edb$0$20619$c3e8da3@news.astraweb.com> Message-ID: <01b355ab$0$20654$c3e8da3@news.astraweb.com> Mark Hammond wrote: > On 23/02/2009 11:41 PM, Chris Cormie wrote: >> >>> If that not-very-technical description [all I've ever needed] doesn't >>> help, you'll need to read the DW help file (HTFF1K) or wait till >>> someone who knows what they are doing comes along :-) >> >> LOL, I am that person :p > > LOL sounds right! > >> How do you get *Python* to tell you the dll and the problem symbol? Not >> external tools, Python. Python at a low level is calling LoadLibrary and >> GetProcAddress to resolve symbols and the call fails. > > It is the LoadLibrary that is failing; it should be obvious that if it > was a simple GetProcAddress that was failing, Python would simply throw > an exception rather than displaying the ugly dialog box you see. I'm talking about the whole class of errors when loading an extension, the LoadLibary succeeds but the GetProcAddress fails. Not one specific error, a class of errors and *by definition* from the original question LoadLibrary succeeds. That's the point: at some point in this common scenario we have the path to the dll and a symbol we are resolving, and the symbol name, yet for whatever reason the GetProcAddress lookup fails, resulting in a surprisingly uninformative errors message. Regards, Chris. From pavlovevidence at gmail.com Mon Feb 23 22:16:54 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 23 Feb 2009 19:16:54 -0800 (PST) Subject: Code in __init__.py, is it bad form? References: Message-ID: <4a716d3b-91f2-48cc-a42d-b923ffb50835@j1g2000yqi.googlegroups.com> On Feb 23, 5:41?pm, Michael Crute wrote: > Is it bad form (i.e. non-pythonic) to have code in your __init__.py > files? I know this is subjective so I'm just looking for the general > consensus. I've heard both sides of the story and I personally feel > its okay if the code pertains to the whole module but have an open > mind about the matter. If you object to code in __init__.py why, and > what alternatives do you propose? Well, I don't like when __init__ "helpfully" imports stuff I don't need. However, most single modules have lots of code I don't need, too, and I never concern myself with them, so it's probably a misplaced irk. Go ahead and use it. Carl Banks From ccormie at aussiemail.com.au Mon Feb 23 22:23:03 2009 From: ccormie at aussiemail.com.au (Chris Cormie) Date: Tue, 24 Feb 2009 14:23:03 +1100 Subject: How does one get from "ImportError: DLL load failed:..." to a culprit .dll and symbol? In-Reply-To: References: <01b213c7$0$20626$c3e8da3@news.astraweb.com> <5850dc46-638f-4a3c-8d9a-f84bf7523979@o11g2000yql.googlegroups.com> <01b28edb$0$20619$c3e8da3@news.astraweb.com> Message-ID: <01b35d7d$0$20654$c3e8da3@news.astraweb.com> Gabriel Genellina wrote: > En Mon, 23 Feb 2009 10:41:20 -0200, Chris Cormie > escribi?: > >>> If that not-very-technical description [all I've ever needed] doesn't >>> help, you'll need to read the DW help file (HTFF1K) or wait till >>> someone who knows what they are doing comes along :-) >> >> LOL, I am that person :p >> Your technique works well and it does provide the information and it >> is a (roundabout) solution to this class of problems: thank you very >> much. It doesn't answer the original question so I'll restate it: >> >> How do you get *Python* to tell you the dll and the problem symbol? >> Not external tools, Python. Python at a low level is calling >> LoadLibrary and GetProcAddress to resolve symbols and the call fails. >> At that point it has the name of the dll and the problem symbol to >> hand and yet strangely only gives an opaque error message. How does >> one get Python to print out the faulty DLL and symbol? > > You can't, because it isn't Python who's trying to load the symbol - the > *only* symbol that Python attempts to import itself is "initFOO" from > FOO.pyd, and when that fails you get an explicit message. > The error you see must come from the extension itself, and propagates > into Python as an ImportError. Right -- now we are getting somewhere! That makes a lot of sense. What I was expecting to see next was an explicit GetProcAddress() call in the extension code that was failing in initFOO() or elsewhere in the extension code. But there are no such calls. I think what might have been making this confusing is that the root of my example problem is link time. Let me explain by giving the specific example case I have to hand. I orginally got on to this class of opaque runtime errors caused by missing symbols through building the pycURL extension on MinGW. As of Python 2.6, Python links against the new msvcr90.dll C Runtime. MinGW maintains a set of .a files for system DLLs including the C Runtime. When building pycURL naturally I want to link against libmsvcr90.a so Python 2.6 and pycURL are using the same C Rutime. Problem was, MinGW's .a was wrong: it exports symbols that msvcr90.dll does not in fact possess. Building pycURL with the faulty libmsvcr90.a causes the opaque error message: "ImportError: DLL load failed" Now I expected this meant an explict LoadLibrary() GetProcAddress() sequence was failing in the extension but perhaps that's not what happens at all? Chris From ccormie at aussiemail.com.au Mon Feb 23 22:25:40 2009 From: ccormie at aussiemail.com.au (Chris Cormie) Date: Tue, 24 Feb 2009 14:25:40 +1100 Subject: How does one get from "ImportError: DLL load failed:..." to a culprit .dll and symbol? In-Reply-To: <5daf9b18-eb79-450b-803e-c6bd4f73e145@r41g2000yqm.googlegroups.com> References: <01b213c7$0$20626$c3e8da3@news.astraweb.com> <5850dc46-638f-4a3c-8d9a-f84bf7523979@o11g2000yql.googlegroups.com> <01b28edb$0$20619$c3e8da3@news.astraweb.com> <5daf9b18-eb79-450b-803e-c6bd4f73e145@r41g2000yqm.googlegroups.com> Message-ID: <01b35e19$0$20654$c3e8da3@news.astraweb.com> John Machin wrote: > On Feb 23, 11:41 pm, Chris Cormie wrote: >>> If that not-very-technical description [all I've ever needed] doesn't >>> help, you'll need to read the DW help file (HTFF1K) or wait till >>> someone who knows what they are doing comes along :-) >> LOL, I am that person :p > > It wasn't apparent, and still isn't. Yikes, enough with the rudeness people. I'm asking a reasonable question in a good faith. From venutaurus539 at gmail.com Mon Feb 23 22:29:07 2009 From: venutaurus539 at gmail.com (venutaurus539 at gmail.com) Date: Mon, 23 Feb 2009 19:29:07 -0800 (PST) Subject: opening files with names in non-english characters. References: <5b6a03dc-0393-46e6-bff0-c36669a67340@w34g2000yqm.googlegroups.com> Message-ID: <1378a511-fe4e-4fe2-a8b0-46022e472d24@x10g2000yqk.googlegroups.com> On Feb 23, 11:02?pm, Chris Rebert wrote: > On Mon, Feb 23, 2009 at 5:51 AM, venutaurus... at gmail.com > > wrote: > > Hi all, > > ? ? ? ? ?I am trying to find the attributes of afile whose name has > > non english characters one like given below. When I try to run my > > python scirpt, it fails giving out an error filename must be in string > > or UNICODE. When i try to copy the name of the file as a strinig, it > > (KOMODO IDE) is not allowing me to save the script saying that it > > cannot convert some of the characters in the current encoding which is > > Western European(CP-1252). > > > 0010testUnicode_???????????????????? !#$%&'()+,-. > > 0123456789;=... at ABCD.txt.txt > > (1) How are you entering or retrieving that filename? > (2) Please provide the exact error and Traceback you're getting. > > Cheers, > Chris > > -- > Follow the path of the Iguana...http://rebertia.com Hello, First of all thanks for your response. I've written a function as shown below to recurse a directory and return a file based on the value of n. I am calling this fucntion from my main code to catch that filename. The folder which it recurses through contains a folder having files with unicode names (as an example i've given earlier. ----------------------------------------------------------------------------- def findFile(dir_path): for name in os.listdir(dir_path): full_path = os.path.join(dir_path, name) print full_path if os.path.isdir(full_path): findFile(full_path) else: n = n - 1 if(n ==0): return full_path -------------------------------------------------------------------------------------------------- The problem is in the return statement. In the function when I tried to print the file name, it is printing properly but the receiving variable is not getting populated with the file name. The below code (1st statement) shows the value of the full_path variable while the control is at the return statement. The second statement is in the main code from where the function call has been made. Once the control has reached the main procedure after executing the findFile procedure, the third statement gives the status of file variable which has type as NoneType and value as None. Now when I try to check if the path exists, it fails giving the below trace back. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- E:\DataSet\Unicode\UnicodeFiles_8859\001_0006_test_folder \0003testUnicode_??I?NOK?????U???UU?a??????ic?e?e??idnok?????u???uu.txt.txt ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ file = findFile(fpath) ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- file NoneType None ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- This is the final trace back: Traceback (most recent call last): File "C:\RecallStubFopen.py", line 268, in if os.path.exists(file): File "C:\Python26\lib\genericpath.py", line 18, in exists st = os.stat(path) TypeError: coercing to Unicode: need string or buffer, NoneType found --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Please ask if you need any further information. Thank you, Venu From johnforse at talktalk.net Mon Feb 23 22:31:56 2009 From: johnforse at talktalk.net (John Forse) Date: Tue, 24 Feb 2009 03:31:56 +0000 Subject: getting tut. example to work Message-ID: <45818CC4-B629-4995-9C52-150297BBE7E5@talktalk.net> I'm trying some examples from the language ref sections on the site in the process of learning some python in 3.0.1. I've tried to run both of the samples below ,but the only printout is "generator object chain at 0x11f4dc8" whether I use print() or not . How do I use the sample to produce the expected printout a b c d e f. Thanks John F A def chain(*iterables): for it in iterables: for element in it: print(element) yield element def main(): chain('abc','def') main() B alternative import itertools itertools.chain('abc','def') From ccormie at aussiemail.com.au Mon Feb 23 22:54:15 2009 From: ccormie at aussiemail.com.au (Chris Cormie) Date: Tue, 24 Feb 2009 14:54:15 +1100 Subject: How does one get from "ImportError: DLL load failed:..." to a culprit .dll and symbol? In-Reply-To: References: <01b213c7$0$20626$c3e8da3@news.astraweb.com> <5850dc46-638f-4a3c-8d9a-f84bf7523979@o11g2000yql.googlegroups.com> <01b28edb$0$20619$c3e8da3@news.astraweb.com> Message-ID: <01b364cd$0$5185$c3e8da3@news.astraweb.com> Mark Hammond wrote: > On 23/02/2009 11:41 PM, Chris Cormie wrote: >> >>> If that not-very-technical description [all I've ever needed] doesn't >>> help, you'll need to read the DW help file (HTFF1K) or wait till >>> someone who knows what they are doing comes along :-) >> >> LOL, I am that person :p > > LOL sounds right! > >> How do you get *Python* to tell you the dll and the problem symbol? Not >> external tools, Python. Python at a low level is calling LoadLibrary and >> GetProcAddress to resolve symbols and the call fails. > > It is the LoadLibrary that is failing; it should be obvious that if it > was a simple GetProcAddress that was failing, Python would simply throw > an exception rather than displaying the ugly dialog box you see. > > The problem is that some *other* DLL in the chain of dependencies is > failing to load; please re-adjust your perceptions of your own knowledge > and re-read John's initial response - if you follow his instructions > that should all become quite obvious. > > Mark I think an example would help rather than me jabbering on about LoadLibary/GetProcAddress . It really is a case of Python loads module x depending on DLL y that is missing symbol z, yet the error message is just "load x failed" when in theory it could be "load x failed: y doesn't have z". However I think I am confusing people (and myself!) by assuming it's always as explicit as a LoadLibary/GetProcAddress sequence that is failing when people see this error. Let me explain by giving the specific example case I have to hand. I originally got on to this class of opaque runtime errors caused by missing symbols through building the pycURL extension on MinGW. As of Python 2.6, Python links against the new msvcr90.dll C Runtime. MinGW maintains a set of .a files for system DLLs including the C Runtime. When building pycURL naturally I want to link against libmsvcr90.a so Python 2.6 and pycURL are using the same C Runtime. Problem was, MinGW's .a was wrong: it exports symbols that msvcr90.dll does not in fact possess. Building pycURL with the faulty libmsvcr90.a causes the opaque error message: "ImportError: DLL load failed" I think Gabriel's got the part of the answer: she said "it isn't Python who's trying to load the symbol - the *only* symbol that Python attempts to import itself is "initFOO" from FOO.pyd" So my next question is: given the above missing-symbol problem, is the system able/willing to report the bad symbol reference in the .pyd when Python attempts to import initFOO? Regards, Chris. From wuwei23 at gmail.com Mon Feb 23 23:07:53 2009 From: wuwei23 at gmail.com (alex23) Date: Mon, 23 Feb 2009 20:07:53 -0800 (PST) Subject: getting tut. example to work References: Message-ID: On Feb 24, 1:31?pm, John Forse wrote: > I'm trying some examples from the language ref sections on the site in ? > the process of learning some python in 3.0.1. I've tried to run both ? > of the samples below ,but the only printout is "generator object chain ? > at 0x11f4dc8" whether I use print() or not . Yes, because you're creating a generator object but you're not actually doing anything with it. > How do I use the sample ? > to produce the expected printout a b c d e f. Since you have a print inside 'chain', you should be able to get that output by doing the following: list(chain('abc','def')) Although I'd recommend removing the print from 'chain' and doing this instead: for elem in chain('abc','def'): print elem From venutaurus539 at gmail.com Mon Feb 23 23:20:30 2009 From: venutaurus539 at gmail.com (venutaurus539 at gmail.com) Date: Mon, 23 Feb 2009 20:20:30 -0800 (PST) Subject: opening files with names in non-english characters. References: <5b6a03dc-0393-46e6-bff0-c36669a67340@w34g2000yqm.googlegroups.com> <1378a511-fe4e-4fe2-a8b0-46022e472d24@x10g2000yqk.googlegroups.com> Message-ID: <0a4fa610-ac99-41e1-9fab-06b461c71a4a@r34g2000vbp.googlegroups.com> On Feb 24, 8:29?am, "venutaurus... at gmail.com" wrote: > On Feb 23, 11:02?pm, Chris Rebert wrote: > > > > > On Mon, Feb 23, 2009 at 5:51 AM, venutaurus... at gmail.com > > > wrote: > > > Hi all, > > > ? ? ? ? ?I am trying to find the attributes of afile whose name has > > > non english characters one like given below. When I try to run my > > > python scirpt, it fails giving out an error filename must be in string > > > or UNICODE. When i try to copy the name of the file as a strinig, it > > > (KOMODO IDE) is not allowing me to save the script saying that it > > > cannot convert some of the characters in the current encoding which is > > > Western European(CP-1252). > > > > 0010testUnicode_???????????????????? !#$%&'()+,-. > > > 0123456789;=... at ABCD.txt.txt > > > (1) How are you entering or retrieving that filename? > > (2) Please provide the exact error and Traceback you're getting. > > > Cheers, > > Chris > > > -- > > Follow the path of the Iguana...http://rebertia.com > > Hello, > ? ? ? ? First of all thanks for your response. I've written a function > as shown below to recurse a directory and return a file based on the > value of n. I am calling this fucntion from my main code to catch that > filename. The folder which it recurses through contains a folder > having files with unicode names (as an example i've given earlier. > --------------------------------------------------------------------------- -- > def findFile(dir_path): > ? ? for name in os.listdir(dir_path): > ? ? ? ? full_path = os.path.join(dir_path, name) > ? ? ? ? print full_path > ? ? ? ? if os.path.isdir(full_path): > ? ? ? ? ? ? findFile(full_path) > ? ? ? ? else: > ? ? ? ? ? ? n = n - 1 > ? ? ? ? ? ? if(n ==0): > ? ? ? ? ? ? ? ? return full_path > --------------------------------------------------------------------------- ----------------------- > ? ? ? ? ? ? ? ? ? ? The problem is in the return statement. In the > function when I tried to print the file name, it is printing properly > but the receiving variable is not getting populated with the file > name. The below code (1st statement) shows the value of the full_path > variable while the control is at the return statement. The second > statement is in the main code from where the function call has been > made. > Once the control has reached the main procedure after executing the > findFile procedure, the third statement gives the status of file > variable which has type as NoneType and value as None. Now when I try > to check if the path exists, it fails giving the below trace back. > > --------------------------------------------------------------------------- --------------------------------------------------------------------------- ---------------------------- > E:\DataSet\Unicode\UnicodeFiles_8859\001_0006_test_folder > \0003testUnicode_??I?NOK?????U???UU?a??????ic?e?e??idnok?????u???uu.txt.txt > --------------------------------------------------------------------------- --------------------------------------------------------------------------- ------------------ > file = findFile(fpath) > --------------------------------------------------------------------------- --------------------------------------------------------------------------- ----------------------------------------- > file > NoneType > None > > --------------------------------------------------------------------------- --------------------------------------------------------------------------- ----------------------------------------- > This is the final trace back: > > Traceback (most recent call last): > ? File "C:\RecallStubFopen.py", line 268, in > ? ? if os.path.exists(file): > ? File "C:\Python26\lib\genericpath.py", line 18, in exists > ? ? st = os.stat(path) > TypeError: coercing to Unicode: need string or buffer, NoneType found > > --------------------------------------------------------------------------- --------------------------------------------------------------------------- --------------------------------------------- > > Please ask if you need any further information. > > Thank you, > Venu To add to what I've said above...I tried manual conversion of the file using unicode() function which is throwing this error: Traceback (most recent call last): File "C:\RecallStubFopen.py", line 278, in file = unicode(file) UnicodeDecodeError: 'ascii' codec can't decode byte 0xeb in position 74: ordinal not in range(128) From nagle at animats.com Mon Feb 23 23:21:59 2009 From: nagle at animats.com (John Nagle) Date: Mon, 23 Feb 2009 20:21:59 -0800 Subject: "Byte" type? In-Reply-To: <49A19B92.2080102@v.loewis.de> References: <4997aa38$0$1678$742ec2ed@news.sonic.net> <499841bf$0$1624$742ec2ed@news.sonic.net> <499859e2$0$1618$742ec2ed@news.sonic.net> <499f8a8e$0$1588$742ec2ed@news.sonic.net> <49a03081$0$1599$742ec2ed@news.sonic.net> <49A19B92.2080102@v.loewis.de> Message-ID: <49a36e1c$0$1586$742ec2ed@news.sonic.net> Martin v. L?wis wrote: >>> Please don't call something dumb that you don't fully understand. It's >>> offenses the people who have spent lots of time developing Python -- >>> personal, unpaid and voluntary time! Some of the people involved are on Google's payroll. >> Crying out; "Please do not criticise me, I am doing it for free!" does >> not justify delivering sub standard work - that is the nature of the >> open source process - if you lift your head and say or do something, >> there are bound to be some objections - some thoughtful and valid, >> and others merely carping. Being sensitive about it serves no purpose. > > Still, John *clearly* doesn't understand what he observes, so asking him > not to draw conclusions until he does understand is not defending > against criticism. > >> This is not a helpful response - on the surface JN has a point - If >> you have to go through two conversions, then 2.6 does not achieve >> what it appears to set out to do. So the issue is simple: >> >> - do you have to convert twice? > > Depends on how you write your code. If you use the bytearray type > (which John didn't, despite his apparent believe that he did), > then no conversion additional conversion is needed. According to PEP 3137, there should be no distinction between the two for read purposes. In 2.6, there is. That's a bug. > Likewise, if you only use byte (not bytearray) literals, without > accessing individual bytes (e.g. if you only ever read and write > them, or pass them to the struct module), 2to3 will do the right > thing. > >> - If yes - why? - as he says - there exists no prior code, >> so there seems to be no reason not to make it identical >> to 3.0 > > Sure there is. Making the bytes type and the str type identical > in 2.x gives the easiest way of porting. Adding bytes as a separate > type would have complicated a lot of things. > > Regards, > Martin No, it's broken. PEP 3137 says one thing, and the 2.6 implementation does something else. So code written for 2.6 won't be ready for 3.0. This defeats the supposed point of 2.6. John Nagle From M8R-yfto6h at mailinator.com Mon Feb 23 23:27:33 2009 From: M8R-yfto6h at mailinator.com (Mark Tolonen) Date: Mon, 23 Feb 2009 20:27:33 -0800 Subject: getting at individual bits inside byte field: struct module : bitwise operator References: <4c7d58a1-830f-4f02-ba07-aa4910f5f4e9@b16g2000yqb.googlegroups.com> Message-ID: "harijay" wrote in message news:4c7d58a1-830f-4f02-ba07-aa4910f5f4e9 at b16g2000yqb.googlegroups.com... > In my last post I had asked about reading data from a binary file > using the struct module. > Thanks to some excellent help , I have managed to read in > successfully > most of the header of this binary format that I want to parse. These > are some time-voltage traces from a digital > to analog converter for my experiments. The output is according to a > format > mentioned here : ( http://www.dataq.com/support/techinfo/ff.htm) > > I have a question about how to bitmask a bunch of bytes read in from > such a binary formatted file . > > For eg the spec says the first two bytes have different parameters in > different bits . > Byte 1 Byte 0 > SN16 SD9 SD8 SD7 SD6 SD5 SD4 SD3 > SD2 SD1 SD0 T4 T3 T2 T1 T0 > > I am reading in the two bytes using the following code > > import struct > f.seek(0) > element1_format = struct.Struct(" (element1,) = element1_format.unpack(f.read(2)) > > Now element1 has type "str" . How do I apply a bitmask to this to get > at information in the component bits . > Since the entire file format has many such bitmasked fields and since > this is my first venture into binary formats and c-type structs , I > wanted to know how to read values inside a byte using python. > My few tries at using bitwise operators ( element1 & 0x001f) are > frustrated by messages that say " unsupported operand type(s) for &: > 'str' and 'int' " . > How can I keep my string objects as bits and apply bitmasks to them > Any help in this will be greatly appreciated. > Thanks > hari Please post a small example that fails as you describe. From your example, element1 should be an int (unpacked from two bytes), and there is no f defined. Without the actual code we can't figure out what you are doing wrong. This works as expected: >>> import struct >>> format = struct.Struct(">> (element1,) = format.unpack('aa') # a two-byte string to unpack >>> print hex(element1) 0x6161 >>> print element1 & 0x1f 1 -Mark From comptekki at gmail.com Mon Feb 23 23:35:38 2009 From: comptekki at gmail.com (Wes James) Date: Mon, 23 Feb 2009 21:35:38 -0700 Subject: how to conditionally add a dict in-line Message-ID: <533df7fa0902232035v261fdb2ck43992404b5a5a2c@mail.gmail.com> I have this line: navs.append(A(' '+str(i+1)+' ',_href=self.action(args=request.args,vars={'_page':i,'_query':request.vars._query or ''}))) How do I do something like this: vars={'_page':i, if request.vars._query not None then insert this key/value pair ('_query':request.vars._query) else insert nothing } thx, -wj From comptekki at gmail.com Mon Feb 23 23:44:37 2009 From: comptekki at gmail.com (Wes James) Date: Mon, 23 Feb 2009 21:44:37 -0700 Subject: how to conditionally add a dict in-line In-Reply-To: <533df7fa0902232035v261fdb2ck43992404b5a5a2c@mail.gmail.com> References: <533df7fa0902232035v261fdb2ck43992404b5a5a2c@mail.gmail.com> Message-ID: <533df7fa0902232044o6babfc8fh415f0815f531351a@mail.gmail.com> On Mon, Feb 23, 2009 at 9:35 PM, Wes James wrote: > I have this line: > > navs.append(A(' '+str(i+1)+' > ',_href=self.action(args=request.args,vars={'_page':i,'_query':request.vars._query > or ''}))) > > How do I do something like this: > > vars={'_page':i, if request.vars._query not None then insert this > key/value pair ('_query':request.vars._query) else insert nothing } Nevermind, this seems to work: navs.append(A(' '+str(i+1)+' ',_href=self.action(args=request.args,vars={'_page':i,'_query':request.vars._query} if request.vars._query else {'_page':i}))) -wj From steven at REMOVE.THIS.cybersource.com.au Mon Feb 23 23:47:23 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 24 Feb 2009 04:47:23 GMT Subject: how to conditionally add a dict in-line References: Message-ID: On Mon, 23 Feb 2009 21:35:38 -0700, Wes James wrote: > I have this line: > > navs.append(A(' '+str(i+1)+' > ',_href=self.action(args=request.args,vars= {'_page':i,'_query':request.vars._query > or ''}))) What a mess. How can you read it? > How do I do something like this: > > vars={'_page':i, if request.vars._query not None then insert this > key/value pair ('_query':request.vars._query) else insert nothing } vars = {'_page': i} if request.vars._query is not None: vars['_query'] = request.vars._query See how simple and clear things are when you give up the insistence on making everything a one-liner? But if you *insist* on a one-liner (perhaps because your keyboard has a broken Enter key): vars = {'_page': i} if request.vars._query is None else {'_page': i, '_query': request.vars._query} -- Steven From steven at REMOVE.THIS.cybersource.com.au Mon Feb 23 23:47:59 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 24 Feb 2009 04:47:59 GMT Subject: Reference or Value? References: Message-ID: On Mon, 23 Feb 2009 08:14:34 -0300, andrew cooke wrote: > Steven D'Aprano wrote: >> On Sun, 22 Feb 2009 13:37:27 -0300, andrew cooke wrote: >> >>> as far as i understand things, the best model is: >>> >>> 1 - everything is an object >>> 2 - everything is passed by reference >> >> Except that is wrong. If it were true, you could do this: > [pointer swapping] > > i was thinking of how the stack is used; i would have called what you > are talking about "pointer semantics". however, on reading around a > little, it seems that i'm in a very small minority (which is a pity, > because if you restrict the meaning to how values are handled on the > stack then you get a lot closer to having just values and references, > rather than the whole pile of different terms that are apparently in > use). > > sorry for the confusion, Why is it a pity to have a whole pile of different terms to describe a whole lot of different behaviours? I would suggest the real confusion would be if we had two terms to describe a dozen different parameter- passing conventions. -- Steven From steven at REMOVE.THIS.cybersource.com.au Mon Feb 23 23:50:18 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 24 Feb 2009 04:50:18 GMT Subject: Access from class variable to one on constructor References: <1c006a1c-83e1-47fa-bf54-f458e98b484c@h5g2000yqh.googlegroups.com> Message-ID: On Mon, 23 Feb 2009 08:02:17 -0200, Gabriel Genellina wrote: > En Mon, 23 Feb 2009 07:40:47 -0200, Kless > escribi?: > >> How to access from a class variable to one that is initialized on the >> constructor? >> -------------- >> class Foo(): >> foo = bar # I want to access *from here* to variables created on >> the constructor. >> >> def __init__(self, bar_init): >> self.bar = bar_init >> -------------- > > Unless I misunderstand you, you can't do that. Class variables are > shared by all instances and don't depend on a particular instance - they > exist even *before* any instance is created. Please don't use the term "class variables" to mean class *attributes*, it makes my brain hurt. If a string variable is a string, and an int variable is an int, and a bool variable is a bool, a class variable should be a class. What you can do is shift the creation of the class attribute to the constructor, instead of when the class is created: class Spam(): def __init__(self, bar_init): self.__class__.foo = bar_init But I'm not sure why you would want to. -- Steven From peter at www.pjb.com.au Mon Feb 23 23:56:12 2009 From: peter at www.pjb.com.au (Peter Billam) Date: 24 Feb 2009 04:56:12 GMT Subject: tkinter icons as bytestrings, not files? Message-ID: Greetings, As a newbie, starting with Python3, I'm working my way through Mark Summerfield's tkinter examples. In the toolbar, there's lines like: for image, command in ( ('images/filenew.gif', self.fileNew), ('images/fileopen.gif', self.fileOpen), ('images/filesave.gif', self.fileSave), ('images/editadd.gif', self.editAdd), ('images/editedit.gif', self.editEdit), ('images/editdelete.gif', self.editDelete),): image = os.path.join(os.path.dirname(__file__), image) image = tkinter.PhotoImage(file=image) self.toolbar_images.append(image) button = tkinter.Button(toolbar, image=image, command=command) button.grid(row=0, column=len(self.toolbar_images) -1) which are always failing because the icons are in the wrong place and I can't help but wonder if I can put all these little images in the application itself, either as b'whatever' or uuencoded or in svg etc, and then invoke some suitable variation of the image = tkinter.PhotoImage(file=image) or of the button = tkinter.Button(toolbar, image=image, command=command) command ? (I did try help('tkinter.PhotoImage') but didn't spot a magic key (unless it's "data=something, format=something")) ... Regards, Peter -- Peter Billam www.pjb.com.au www.pjb.com.au/comp/contact.html From comptekki at gmail.com Mon Feb 23 23:56:46 2009 From: comptekki at gmail.com (Wes James) Date: Mon, 23 Feb 2009 21:56:46 -0700 Subject: how to conditionally add a dict in-line In-Reply-To: References: Message-ID: <533df7fa0902232056q6d65eeacg1536c586c66e1732@mail.gmail.com> Steven. Thx (see my question below...) On Mon, Feb 23, 2009 at 9:47 PM, Steven D'Aprano wrote: > On Mon, 23 Feb 2009 21:35:38 -0700, Wes James wrote: > >> I have this line: >> >> navs.append(A(' '+str(i+1)+' >> ',_href=self.action(args=request.args,vars= > {'_page':i,'_query':request.vars._query >> or ''}))) > > What a mess. How can you read it? > > >> How do I do something like this: >> >> vars={'_page':i, if request.vars._query not None then insert this >> key/value pair ('_query':request.vars._query) else insert nothing } > > vars = {'_page': i} > if request.vars._query is not None: > ? ?vars['_query'] = request.vars._query Could this be: vars = {'_page': i} if request.vars._query: vars['_query'] = request.vars._query > > See how simple and clear things are when you give up the insistence on > making everything a one-liner? -wj From sjmachin at lexicon.net Tue Feb 24 00:01:28 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 23 Feb 2009 21:01:28 -0800 (PST) Subject: How does one get from "ImportError: DLL load failed:..." to a culprit .dll and symbol? References: <01b213c7$0$20626$c3e8da3@news.astraweb.com> <5850dc46-638f-4a3c-8d9a-f84bf7523979@o11g2000yql.googlegroups.com> <01b28edb$0$20619$c3e8da3@news.astraweb.com> <01b364cd$0$5185$c3e8da3@news.astraweb.com> Message-ID: <68447ae6-0b51-47ca-9a10-35d806f9b7e1@v15g2000yqn.googlegroups.com> On Feb 24, 2:54?pm, Chris Cormie wrote: > Mark Hammond wrote: > > On 23/02/2009 11:41 PM, Chris Cormie wrote: > > >>> If that not-very-technical description [all I've ever needed] doesn't > >>> help, you'll need to read the DW help file (HTFF1K) or wait till > >>> someone who knows what they are doing comes along :-) > > >> LOL, I am that person :p > > > LOL sounds right! > > >> How do you get *Python* to tell you the dll and the problem symbol? Not > >> external tools, Python. Python at a low level is calling LoadLibrary and > >> GetProcAddress to resolve symbols and the call fails. > > > It is the LoadLibrary that is failing; it should be obvious that if it > > was a simple GetProcAddress that was failing, Python would simply throw > > an exception rather than displaying the ugly dialog box you see. > > > The problem is that some *other* DLL in the chain of dependencies is > > failing to load; please re-adjust your perceptions of your own knowledge > > and re-read John's initial response - if you follow his instructions > > that should all become quite obvious. > > > Mark > > I think an example would help rather than me jabbering on about > LoadLibary/GetProcAddress . > > It really is a case of Python loads module x depending on DLL y that is > missing symbol z, yet the error message is just "load x failed" when in > theory it could be "load x failed: y doesn't have z". > > However I think I am confusing people (and myself!) by assuming it's Don't assume; read the [open] source code; see below. > always as explicit as a LoadLibary/GetProcAddress sequence that is > failing when people see this error. > > Let me explain by giving the specific example case I have to hand. > I originally got on to this class of opaque runtime errors caused by > missing symbols through building the pycURL extension on MinGW. As of > Python 2.6, Python links against the new msvcr90.dll C Runtime. MinGW > maintains a set of .a files for system DLLs including the C Runtime. > When building pycURL naturally I want to link against libmsvcr90.a so > Python 2.6 and pycURL are using the same C Runtime. Problem was, MinGW's > ? .a was wrong: it exports symbols that msvcr90.dll does not in fact > possess. Building pycURL with the faulty libmsvcr90.a causes the opaque > error message: "ImportError: DLL load failed" > > I think Gabriel's got the part of the answer: she said ?"it isn't Python > who's trying to load the symbol - the *only* symbol that Python attempts > to import itself is "initFOO" from FOO.pyd" > > So my next question is: given the above missing-symbol problem, is the > system able/willing to report the bad symbol reference in the .pyd when > Python attempts to import initFOO? My reading of the Python 2.6.1 version of dynload_win.c tells me that: 1. It uses LoadLibraryEx() to attempt to load the pyd given its full pathname 2. If that fails, it gets the Windows error code using GetLastError() 3. It gets the Windows message text using FormatMessage() 4. It assembles the message as "DLL load failed: " plus the Windows message text (less any trailing "\r\n"). Note that if the pyd load succeeds, it rummages in memory to find the pythonxx.dll used by the pyd so that it can be checked for consistency. Then and only then it uses GetProcAddress() to get the address of the initFOO function. Do you know a way of getting more info out of Windows than GetLastError ()? From alwaseem307ster at yahoo.com Tue Feb 24 00:04:21 2009 From: alwaseem307ster at yahoo.com (klia) Date: Mon, 23 Feb 2009 21:04:21 -0800 (PST) Subject: pysqlite smart search In-Reply-To: <22157116.post@talk.nabble.com> References: <22157116.post@talk.nabble.com> Message-ID: <22175924.post@talk.nabble.com> klia wrote: > > Hey guys; > > I am trying to develop a tiny program using python to search inside sqlite > database with file extension is .db in which the program will ask users to > enter their search query and base on that it will retrieve the results But > > I need the program to have some smartness in search mechanism in which the > program will guess that the user is looking for these key words in the > database. > > so far i came up with this but the search ain't smart, i have to write the > full key word in order to retrieve specific information. > > from pysqlite2 import dbapi2 as sqlite3 > > connection = sqlite3.connect('Photos.db') > memoryConnection = sqlite3.connect(':memory:') > cursor = connection.cursor() > prompt = 'Enter your search query?\n' > keyword = raw_input(prompt) > if cursor.execute('SELECT * FROM photos WHERE Tag LIKE ?',[keyword]): > print cursor.fetchall() > else: > cursor.execute('SELECT * FROM photos WHERE Date LIKE ?', [keyword]) > print cursor.fetchall() > > Any ideas and > thanks in advance > Reply > Thank you guys, it worked perfectly Solved -- View this message in context: http://www.nabble.com/pysqlite-smart-search-tp22157116p22175924.html Sent from the Python - python-list mailing list archive at Nabble.com. From aquil.abdullah at gmail.com Tue Feb 24 00:13:12 2009 From: aquil.abdullah at gmail.com (aha) Date: Mon, 23 Feb 2009 21:13:12 -0800 (PST) Subject: A tale of two execs References: <7d85586a-d746-4e0f-b01b-86bf2e388971@f18g2000vbf.googlegroups.com> Message-ID: <794a35cc-f530-43e7-97c5-87694f27b573@x9g2000yqk.googlegroups.com> Hello All, It occurred to me that I might just want to try copying the subprocess.py installed in a /usr/lib/python24 installation to the directory where I place the scripts that I need to launch my application...I know this was mentioned earlier. Anyway, my application worked under python 2.3 and later python versions as well. Here is what I did: I renamed subprocess.py to subprocess23.py and then used the following code: try: import subprocess except ImportError: import subprocess23 as subprocess I chose this route because I took a deeper look at the code in the subprocess module and I also realized that I would not be able to use the popen2, because I would not be able to do things like os.setpgrp for preexec_fn, with popen2. In the end, if I wanted that type of functionality I would have to use os.dup, fork, exec, which meant reinventing the wheel. I overcame the issue of dealing with msvcrt and _subprocess under windows by requiring python24 or greater under windows. Regards, Aquil From steven at REMOVE.THIS.cybersource.com.au Tue Feb 24 00:33:37 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 24 Feb 2009 05:33:37 GMT Subject: how to conditionally add a dict in-line References: Message-ID: On Mon, 23 Feb 2009 21:56:46 -0700, Wes James wrote: >> vars = {'_page': i} >> if request.vars._query is not None: >> ? ?vars['_query'] = request.vars._query > > Could this be: > > vars = {'_page': i} > if request.vars._query: > vars['_query'] = request.vars._query Instead of typing "request.vars._query" in all the examples, I'm going to abbreviate it as "x" instead. "if x is not None" and "if x" are very different things. Consider the following examples: >>> x = None >>> >>> if x is not None: ... print "action performed when x is not None" ... else: ... print "do nothing" ... do nothing >>> >>> if x: ... print "action performed when x is not None" ... else: ... print "do nothing" ... do nothing So far so good. Both pieces of code do the right thing when x actually is None. But what happens if x is *not* None? >>> x = "" # The empty string is *not* None. >>> >>> if x is not None: ... print "action performed when x is not None" ... else: ... print "do nothing" ... action performed when x is not None >>> >>> if x: ... print "action performed when x is not None" ... else: ... print "do nothing" ... do nothing That's clearly wrong, because we know that x isn't None, it is the empty string. The test "if x" does not test for the same thing as "if x is not None". "if x" tests the general truth value of any object, and many objects have a false truth value: None, empty string, 0, [], {} and many more. -- Steven From chaosmage at gmail.com Tue Feb 24 00:35:21 2009 From: chaosmage at gmail.com (collin) Date: Mon, 23 Feb 2009 21:35:21 -0800 (PST) Subject: How do I count the distance between strings in a list? Message-ID: <05e9fe5f-f0ea-475f-b8f6-b9e6c99f3c21@t11g2000yqg.googlegroups.com> For example, if I were to have the code randomlist = ["1", "2", "3", "4"] And I want to count the distance between strings "1" and "4" which is 3, what command can I use to do this? From harijay at gmail.com Tue Feb 24 00:42:26 2009 From: harijay at gmail.com (harijay) Date: Mon, 23 Feb 2009 21:42:26 -0800 (PST) Subject: getting at individual bits inside byte field: struct module : bitwise operator References: <4c7d58a1-830f-4f02-ba07-aa4910f5f4e9@b16g2000yqb.googlegroups.com> Message-ID: Thanks Gabriel , MRAB and Mark Instead of using the bitwise operator on the unpacked data I was trying to do a bitwise operator directly after read. This was giving the unsupported operand error i.e # version in my code - wrong file.read(2) & 0x001f Instead of # version in my example and now in my working code (element1,) = struct.unpack(" wrote: > "harijay" wrote in message > > news:4c7d58a1-830f-4f02-ba07-aa4910f5f4e9 at b16g2000yqb.googlegroups.com... > > > > > In my last post I had asked about reading data from a binary file > > using the struct module. > > Thanks to some excellent help , I have managed to read in > > successfully > > most of the header of this binary format that I want to parse. ?These > > are some time-voltage traces from a digital > > to analog converter for my experiments. The output is according to a > > format > > mentioned here : (http://www.dataq.com/support/techinfo/ff.htm) > > > I have a question about how to bitmask a bunch of bytes read in from > > such a binary formatted file . > > > For eg the spec says the first two bytes have different parameters in > > different bits . > > Byte 1 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Byte 0 > > SN16 SD9 ? ? ? ?SD8 ? ? SD7 ? ? SD6 ? ? SD5 ? ? SD4 ? ? SD3 > > SD2 ? ? SD1 ? ? SD0 ? ? T4 ? ? ?T3 ? ? ?T2 ? ? ?T1 ? ? ?T0 > > > I am reading in the two bytes using the following code > > > import struct > > f.seek(0) > > element1_format = struct.Struct(" > (element1,) = element1_format.unpack(f.read(2)) > > > Now element1 has type "str" . How do I apply a bitmask to this to get > > at information in the component bits . > > Since the entire file format has many such bitmasked fields and since > > this is my first venture into binary formats and c-type structs , I > > wanted to know how to read values inside a byte using python. > > My few tries at using bitwise operators ( element1 & 0x001f) are > > frustrated by messages that say " unsupported operand type(s) for &: > > 'str' and 'int' " . > > How can I keep my string objects as bits and apply bitmasks to them > > Any help in this will be greatly appreciated. > > Thanks > > hari > > Please post a small example that fails as you describe. ?From your example, > element1 should be an int (unpacked from two bytes), and there is no f > defined. ?Without the actual code we can't figure out what you are doing > wrong. > > This works as expected: > > >>> import struct > >>> format = struct.Struct(" >>> (element1,) = format.unpack('aa') # a two-byte string to unpack > >>> print hex(element1) > 0x6161 > >>> print element1 & 0x1f > > 1 > > -Mark From sambit2005 at gmail.com Tue Feb 24 00:45:54 2009 From: sambit2005 at gmail.com (Sambit Samal) Date: Tue, 24 Feb 2009 18:45:54 +1300 Subject: code challenge: generate minimal expressions using only digits 1,2,3 In-Reply-To: <941be713-2789-48c7-911b-422313f232d5@o36g2000yqh.googlegroups.com> References: <941be713-2789-48c7-911b-422313f232d5@o36g2000yqh.googlegroups.com> Message-ID: <9e680b420902232145k35b3af51tcc085484377bc88f@mail.gmail.com> test On Sat, Feb 21, 2009 at 3:31 AM, Trip Technician wrote: > anyone interested in looking at the following problem. > > we are trying to express numbers as minimal expressions using only the > digits one two and three, with conventional arithmetic. so for > instance > > 33 = 2^(3+2)+1 = 3^3+(3*2) > > are both minimal, using 4 digits but > > 33 = ((3+2)*2+1)*3 > > using 5 is not. > > I have tried coding a function to return the minimal representation > for any integer, but haven't cracked it so far. The naive first > attempt is to generate lots of random strings, eval() them and sort by > size and value. this is inelegant and slow. > > I have a dim intuition that it could be done with a very clever bit of > recursion, but the exact form so far eludes me. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jgardner at jonathangardner.net Tue Feb 24 01:08:28 2009 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Mon, 23 Feb 2009 22:08:28 -0800 (PST) Subject: How do I count the distance between strings in a list? References: <05e9fe5f-f0ea-475f-b8f6-b9e6c99f3c21@t11g2000yqg.googlegroups.com> Message-ID: <86df098b-1274-4702-b353-b00418dc51a6@e18g2000yqo.googlegroups.com> On Feb 23, 9:35?pm, collin wrote: > For example, if I were to have the code > > randomlist = ["1", "2", "3", "4"] > > And I want to count the distance between strings "1" and "4" which is > 3, what command can I use to do this? You'd have to get the indexes of the two items and subtract them. There is an 'index' method on the List object for that. From steven at REMOVE.THIS.cybersource.com.au Tue Feb 24 01:11:29 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 24 Feb 2009 06:11:29 GMT Subject: How do I count the distance between strings in a list? References: <05e9fe5f-f0ea-475f-b8f6-b9e6c99f3c21@t11g2000yqg.googlegroups.com> Message-ID: On Mon, 23 Feb 2009 21:35:21 -0800, collin wrote: > For example, if I were to have the code > > randomlist = ["1", "2", "3", "4"] > > And I want to count the distance between strings "1" and "4" which is 3, > what command can I use to do this? This question is ambiguous. It could mean: int("4") - int("1") => 3 ord("4") - ord("1") => 3 randomlist.index("4") - randomlist.index("1") => 3 and possible more as well. Perhaps you should explain what you want to do. What do you mean by "distance between strings", and is it important that they are in a list? -- Steven From martin at v.loewis.de Tue Feb 24 01:11:38 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 24 Feb 2009 07:11:38 +0100 Subject: "Byte" type? In-Reply-To: <49a36e1c$0$1586$742ec2ed@news.sonic.net> References: <4997aa38$0$1678$742ec2ed@news.sonic.net> <499841bf$0$1624$742ec2ed@news.sonic.net> <499859e2$0$1618$742ec2ed@news.sonic.net> <499f8a8e$0$1588$742ec2ed@news.sonic.net> <49a03081$0$1599$742ec2ed@news.sonic.net> <49A19B92.2080102@v.loewis.de> <49a36e1c$0$1586$742ec2ed@news.sonic.net> Message-ID: <49a38f9b$0$1880$9b622d9e@news.freenet.de> >> Depends on how you write your code. If you use the bytearray type >> (which John didn't, despite his apparent believe that he did), >> then no conversion additional conversion is needed. > > According to PEP 3137, there should be no distinction between > the two for read purposes. In 2.6, there is. That's a bug. No. Python 2.6 doesn't implement PEP 3137, and the PEP doesn't claim that it would, nor do the 2.6 release notes. So that it deviates from PEP 3137 is not a bug. > No, it's broken. PEP 3137 says one thing, and the 2.6 implementation > does something else. So code written for 2.6 won't be ready for 3.0. > This defeats the supposed point of 2.6. That's not true: if I write if isinstance(x, bytes): one_thing() elif isinstance(x, unicode): another_thing() then 2to3 will convert it perfectly. 2to3 couldn't have done the conversion correctly had I written if isinstance(x, str): one_thing() elif isinstance(x, unicode): another_thing() So the introduction of the bytes builtin *does* help the supposed point of 2.6, even though it doesn't help implementing PEP 3137. Regards, Martin From dhananjay.c.joshi at gmail.com Tue Feb 24 01:41:09 2009 From: dhananjay.c.joshi at gmail.com (Dhananjay) Date: Tue, 24 Feb 2009 12:11:09 +0530 Subject: How to read columns in python Message-ID: I am bit new to python and programming and this might be a basic question: I have a file containing 3 columns. first two columns are x and y axes and third column is their corresponding values in the graph. I want to read this in a matrix as well as plot in 2D. Could anyone tell me how to do so the things. Thanking you in advance -- Dhananjay -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Tue Feb 24 01:46:08 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 23 Feb 2009 22:46:08 -0800 Subject: Problem in accessing files with unicode fonts. In-Reply-To: References: Message-ID: <50697b2c0902232246t66922c39i9a73996be230d1a4@mail.gmail.com> A. Your reason for emailing us off-list makes no sense. The list would garner you more and about as quick responses, not to mention the value it adds through public archiving. CC-ing us /might/ have made slight sense. B. This is your problem: v = unicode(full_path,errors='skip') I'd advise you to read the docs for `unicode`, particularly what using 'skip' as the value of `errors` does. Good day. - Chris -- Follow the path of the Iguana... http://rebertia.com On Mon, Feb 23, 2009 at 10:31 PM, venu madhav wrote: > Hello, > ?? ? ? ? ? Sorry for mailing to your personal mails instead of mailing to > the group. The reason being the intensity of the problem and time factor. > > Prob: I have a folder which contains files with unicode names ( Arabic, > German etc). I am trying to obtain the attributes of those files recursively > using win32api.getFileAttributes() function. Here is the code which i have > for the same: > ---------------------------------------------------------------------- > #!/usr/bin/env python > import os > import os.path > import sys > import urllib > import win32api,string > def findFile(dir_path): > ?? ?for name in os.listdir(dir_path): > ?? ? ? ?full_path = os.path.join(dir_path, name) > ?? ? ? ?print full_path > ?? ? ? ?if os.path.isdir(full_path): > ?? ? ? ? ? ?findFile(full_path) > ?? ? ? ?else: > ?? ? ? ? ? ?v = unicode(full_path,errors='skip') > ?? ? ? ? ? ?i = win32api.GetFileAttributes(v) > > findFile("F:\\DataSet\\Unicode") > --------------------------------------------------------------- > Now when I run this scirpt, the full_path variable which should contain the > name of the file has "????" for non english ( I tried Arabic) characters. As > a result the getfileattributes function is failing to recognise that file > and is raising an exception. > full_path:?F:\DataSet\Unicode\Arabic files\Arabic?????????????????????????? > {type is str} > v:?F:\DataSet\Unicode\Arabic files\Arabic?????????????????????????? {type is > unicode} > TraceBack: > Traceback (most recent call last): > ??File "E:\venu\Testing Team\unitest.py", line 19, in > ?? ?findFile("F:\\DataSet\\Unicode") > ??File "E:\venu\Testing Team\unitest.py", line 13, in findFile > ?? ?findFile(full_path) > ??File "E:\venu\Testing Team\unitest.py", line 16, in findFile > ?? ?i = win32api.GetFileAttributes(v) > error: (123, 'GetFileAttributes', 'The filename, directory name, or volume > label syntax is incorrect.') > > Waiting for your reply. > Thank you in advance. > Venu. From clp2 at rebertia.com Tue Feb 24 01:48:11 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 23 Feb 2009 22:48:11 -0800 Subject: How to read columns in python In-Reply-To: References: Message-ID: <50697b2c0902232248q7f704629v74b8125262c206f4@mail.gmail.com> On Mon, Feb 23, 2009 at 10:41 PM, Dhananjay wrote: > I am bit new to python and programming and this might be a basic question: > > I have a file containing 3 columns. Your question is much too vague to answer. What defines a "column" for you? Tab-separated, comma-separated, or something else altogether? - Chris -- Follow the path of the Iguana... http://rebertia.com From dhananjay.c.joshi at gmail.com Tue Feb 24 02:08:29 2009 From: dhananjay.c.joshi at gmail.com (Dhananjay) Date: Tue, 24 Feb 2009 12:38:29 +0530 Subject: How to read columns in python In-Reply-To: <50697b2c0902232248q7f704629v74b8125262c206f4@mail.gmail.com> References: <50697b2c0902232248q7f704629v74b8125262c206f4@mail.gmail.com> Message-ID: Well, The three columns are tab separated and there are 200 such rows having these 3 columns in the file. First two columns are x and y coordinates and third column is the corresponding value. I want to read this file as a matrix in which column1 correspond to row, column2 corresponds to columns(in matrix) and column3 corresponds to value in the matrix. -- Dhananjay On Tue, Feb 24, 2009 at 12:18 PM, Chris Rebert wrote: > On Mon, Feb 23, 2009 at 10:41 PM, Dhananjay > wrote: > > I am bit new to python and programming and this might be a basic > question: > > > > I have a file containing 3 columns. > > Your question is much too vague to answer. What defines a "column" for > you? Tab-separated, comma-separated, or something else altogether? > > - Chris > > -- > Follow the path of the Iguana... > http://rebertia.com > -- -- -------------------------------------------------------------- Dhananjay C Joshi Project Assistant Lab of Structural Biology, C D F D, ECIL Road, Nacharam Hyderabad-500 076, INDIA Tel : +91-40-27151344 Fax : +91-40-27155610 -------------------------------------------------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: From venutaurus539 at gmail.com Tue Feb 24 02:15:33 2009 From: venutaurus539 at gmail.com (venu madhav) Date: Tue, 24 Feb 2009 12:45:33 +0530 Subject: Problem in accessing files with unicode fonts. In-Reply-To: <50697b2c0902232246t66922c39i9a73996be230d1a4@mail.gmail.com> References: <50697b2c0902232246t66922c39i9a73996be230d1a4@mail.gmail.com> Message-ID: On Tue, Feb 24, 2009 at 12:16 PM, Chris Rebert wrote: > A. Your reason for emailing us off-list makes no sense. The list would > garner you more and about as quick responses, not to mention the value > it adds through public archiving. CC-ing us /might/ have made slight > sense. > B. This is your problem: > v = unicode(full_path,errors='skip') > I'd advise you to read the docs for `unicode`, particularly what using > 'skip' as the value of `errors` does. > > Good day. > > - Chris > > -- > Follow the path of the Iguana... > http://rebertia.com > > > On Mon, Feb 23, 2009 at 10:31 PM, venu madhav > wrote: > > Hello, > > Sorry for mailing to your personal mails instead of mailing to > > the group. The reason being the intensity of the problem and time factor. > > > > Prob: I have a folder which contains files with unicode names ( Arabic, > > German etc). I am trying to obtain the attributes of those files > recursively > > using win32api.getFileAttributes() function. Here is the code which i > have > > for the same: > > ---------------------------------------------------------------------- > > #!/usr/bin/env python > > import os > > import os.path > > import sys > > import urllib > > import win32api,string > > def findFile(dir_path): > > for name in os.listdir(dir_path): > > full_path = os.path.join(dir_path, name) > > print full_path > > if os.path.isdir(full_path): > > findFile(full_path) > > else: > > v = unicode(full_path,errors='skip') > > i = win32api.GetFileAttributes(v) > > > > findFile("F:\\DataSet\\Unicode") > > --------------------------------------------------------------- > > Now when I run this scirpt, the full_path variable which should contain > the > > name of the file has "????" for non english ( I tried Arabic) characters. > As > > a result the getfileattributes function is failing to recognise that file > > and is raising an exception. > > full_path: F:\DataSet\Unicode\Arabic > files\Arabic?????????????????????????? > > {type is str} > > v: F:\DataSet\Unicode\Arabic files\Arabic?????????????????????????? {type > is > > unicode} > > TraceBack: > > Traceback (most recent call last): > > File "E:\venu\Testing Team\unitest.py", line 19, in > > findFile("F:\\DataSet\\Unicode") > > File "E:\venu\Testing Team\unitest.py", line 13, in findFile > > findFile(full_path) > > File "E:\venu\Testing Team\unitest.py", line 16, in findFile > > i = win32api.GetFileAttributes(v) > > error: (123, 'GetFileAttributes', 'The filename, directory name, or > volume > > label syntax is incorrect.') > > > > Waiting for your reply. > > Thank you in advance. > > Venu. > Hello, As you've said I went through the documentation for unicode function.It takes the file name as the first argument and then based on the second (whether you skip, ignore or strict) does the action. Any of those ways is not solving my problem. Since, using skip or ignore removes the unicode characters from the file name, the win32 function is failing to find that filename. I tried to change the default encoding to unicode in site.py scirpt but didn't give any results. Thank you, Venu -------------- next part -------------- An HTML attachment was scrubbed... URL: From mcfletch at vrplumber.com Tue Feb 24 02:30:41 2009 From: mcfletch at vrplumber.com (Mike C. Fletcher) Date: Tue, 24 Feb 2009 02:30:41 -0500 Subject: ANN: SuPy 1.6 In-Reply-To: <49A3561A.8000900@canterbury.ac.nz> References: <49A3561A.8000900@canterbury.ac.nz> Message-ID: <49A3A221.8070602@vrplumber.com> Greg Ewing wrote: ... > What is SuPy? > ------------- > > SuPy is a plugin for the Sketchup 3D modelling application > that lets you script it in Python. Hi Greg, Can you review the SuPy writeup on Py3D? I couldn't get through to your server this evening, so I couldn't check the license, if there's anything else you feel should be said about the program, let me know. http://www.vrplumber.com/py3d.py#supy Have fun, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From apardon at forel.vub.ac.be Tue Feb 24 02:54:07 2009 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 24 Feb 2009 07:54:07 GMT Subject: bool evaluations of generators vs lists References: <20090210111514.07e0480a@microvu.com> <1234294770.8528.14.camel@localhost.localdomain> <20090210125002.1f6d8597@microvu.com> Message-ID: On 2009-02-10, Albert Hopkins wrote: > On Tue, 2009-02-10 at 12:50 -0800, Josh Dukes wrote: > > I don't understand what you mean by this. But if you really want to > know if a generator is "non-empty": > > def non_empty(virgin_generator): > try: > virgin_generator.next() # note you just lost the first value > return True > except StopIteration: > return False > > The only way to get around this is to put all the values of a generator > inside a container (e.g. a list): > > l = list(generator_object) > > but in doing so you've (obviously) lost the advantages of the generator. Well he could always use a wrapper like the following: nothing = object() class BoolIterator (object): def __init__(self, iter): self.iter = iter self.value = nothing self.item = nothing def __iter__(self): return (self) def __nonzero__(self): if self.value is nothing: try: self.item = self.iter.next() self.value = True return True except StopIteration: self.value = False return False else: return self.value def next(self): if self.item is not nothing: result = self.item self.item = nothing return result if self.value is not nothing: return self.iter.next() else: try: result = self.iter.next() self.value = True return result except StopIteration: self.value = False raise it1 = BoolIterator(i for i in xrange(10)) for i in it1: print i it2 = BoolIterator(i for i in xrange(10)) if it2: print "item found" for i in it2: print i else: print "problem" it3 = BoolIterator(i for i in xrange(0)) if it3: print "problem" else: print "it3 is empty" From metolone+gmane at gmail.com Tue Feb 24 02:56:54 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Mon, 23 Feb 2009 23:56:54 -0800 Subject: Problem in accessing files with unicode fonts. References: <50697b2c0902232246t66922c39i9a73996be230d1a4@mail.gmail.com> Message-ID: Try os.walk for recursively walking directories. Also if you use a unicode parameter with os.walk or os.listdir you get unicode strings in the result. To run this successfully when you have non-ascii characters in your filenames, you will need to use an environment that supports the characters you want to print. The Windows console, for example, typically only supports a native encoding such as cp437 or cp1252 (on U.S. systems). If all else fails write the output to a file in your favorite encoding: # coding: gbk import os import codecs output = codecs.open(u'??.txt','wt',encoding='utf-8') for path,dirs,files in os.walk(u'.'): for fname in files: output.write(os.path.join(path,fname)+'\n') output.close() -Mark "venu madhav" wrote in message news:daf1e02e0902232315j7e66593ewecfdd739972ad676 at mail.gmail.com... On Tue, Feb 24, 2009 at 12:16 PM, Chris Rebert wrote: A. Your reason for emailing us off-list makes no sense. The list would garner you more and about as quick responses, not to mention the value it adds through public archiving. CC-ing us /might/ have made slight sense. B. This is your problem: v = unicode(full_path,errors='skip') I'd advise you to read the docs for `unicode`, particularly what using 'skip' as the value of `errors` does. Good day. - Chris -- Follow the path of the Iguana... http://rebertia.com On Mon, Feb 23, 2009 at 10:31 PM, venu madhav wrote: > Hello, > Sorry for mailing to your personal mails instead of mailing to > the group. The reason being the intensity of the problem and time factor. > > Prob: I have a folder which contains files with unicode names ( Arabic, > German etc). I am trying to obtain the attributes of those files recursively > using win32api.getFileAttributes() function. Here is the code which i have > for the same: > ---------------------------------------------------------------------- > #!/usr/bin/env python > import os > import os.path > import sys > import urllib > import win32api,string > def findFile(dir_path): > for name in os.listdir(dir_path): > full_path = os.path.join(dir_path, name) > print full_path > if os.path.isdir(full_path): > findFile(full_path) > else: > v = unicode(full_path,errors='skip') > i = win32api.GetFileAttributes(v) > > findFile("F:\\DataSet\\Unicode") > --------------------------------------------------------------- > Now when I run this scirpt, the full_path variable which should contain the > name of the file has "????" for non english ( I tried Arabic) characters. As > a result the getfileattributes function is failing to recognise that file > and is raising an exception. > full_path: F:\DataSet\Unicode\Arabic files\Arabic?????????????????????????? > {type is str} > v: F:\DataSet\Unicode\Arabic files\Arabic?????????????????????????? {type is > unicode} > TraceBack: > Traceback (most recent call last): > File "E:\venu\Testing Team\unitest.py", line 19, in > findFile("F:\\DataSet\\Unicode") > File "E:\venu\Testing Team\unitest.py", line 13, in findFile > findFile(full_path) > File "E:\venu\Testing Team\unitest.py", line 16, in findFile > i = win32api.GetFileAttributes(v) > error: (123, 'GetFileAttributes', 'The filename, directory name, or volume > label syntax is incorrect.') > > Waiting for your reply. > Thank you in advance. > Venu. Hello, As you've said I went through the documentation for unicode function.It takes the file name as the first argument and then based on the second (whether you skip, ignore or strict) does the action. Any of those ways is not solving my problem. Since, using skip or ignore removes the unicode characters from the file name, the win32 function is failing to find that filename. I tried to change the default encoding to unicode in site.py scirpt but didn't give any results. Thank you, Venu ------------------------------------------------------------------------------ -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From ccormie at aussiemail.com.au Tue Feb 24 03:00:26 2009 From: ccormie at aussiemail.com.au (Chris Cormie) Date: Tue, 24 Feb 2009 19:00:26 +1100 Subject: How does one get from "ImportError: DLL load failed:..." to a culprit .dll and symbol? In-Reply-To: <68447ae6-0b51-47ca-9a10-35d806f9b7e1@v15g2000yqn.googlegroups.com> References: <01b213c7$0$20626$c3e8da3@news.astraweb.com> <5850dc46-638f-4a3c-8d9a-f84bf7523979@o11g2000yql.googlegroups.com> <01b28edb$0$20619$c3e8da3@news.astraweb.com> <01b364cd$0$5185$c3e8da3@news.astraweb.com> <68447ae6-0b51-47ca-9a10-35d806f9b7e1@v15g2000yqn.googlegroups.com> Message-ID: <01b39e7f$0$20621$c3e8da3@news.astraweb.com> > My reading of the Python 2.6.1 version of dynload_win.c tells me that: > > 1. It uses LoadLibraryEx() to attempt to load the pyd given its full > pathname > > 2. If that fails, it gets the Windows error code using GetLastError() > > 3. It gets the Windows message text using FormatMessage() > > 4. It assembles the message as "DLL load failed: " plus the Windows > message text (less any trailing "\r\n"). > > Note that if the pyd load succeeds, it rummages in memory to find the > pythonxx.dll used by the pyd so that it can be checked for > consistency. Then and only then it uses GetProcAddress() to get the > address of the initFOO function. > > Do you know a way of getting more info out of Windows than GetLastError > ()? Thank you for your help, it is much appreciated: In summary: Q) How can one get Python to tell you which symbol is causing a problem when it loads an extension with a bad reference to a symbol in a DLL it uses? A) There is no such way: you *must* use external tools: When a symbol is missing form a DLL that a Python extension depends on, the failure will be picked up in Python immediately on attempting to load the extension: the extension code is never reached and there is no specific attempt made in Python to resolve the problem symbol. further, The normal platform APIs lack the ability to determine the cause of the load failure. > Do you know a way of getting more info out of Windows than GetLastError > ()? No, but presumably the ability to determine in code that a DLL has a bad reference and which symbol is bad exists because the depends program is able to do it. Of course it's a separate question as to whether Python wants to load itself down with complex platform specific code for a small corner case. Best Regards, Chris. From sjmachin at lexicon.net Tue Feb 24 03:07:50 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 24 Feb 2009 00:07:50 -0800 (PST) Subject: read csv error question References: <77e831100902231518q7a29e251s956be0b77d2613d@mail.gmail.com> Message-ID: <1a434a76-f956-4848-a1eb-e46f96476f61@v39g2000yqm.googlegroups.com> On Feb 24, 10:42?am, rdmur... at bitdance.com wrote: > Vincent Davis wrote: > > I am trying to read a csv file from excel on a mac. I get the following > > error.SystemExit: file some.csv, line 1: new-line character seen in unquoted > > field - do you need to open the file in universal-newline mode? > > I was using the example code > > import csv, sys > > > reader = csv.reader(open('/Volumes/vincentdavis > > 2/match/data/matchdata2008.csv', "rb")) > > try: > > ? ? for row in reader: > > ? ? ? ? print row > > except csv.Error, e: > > ? ? sys.exit('file %s, line %d: %s' % (filename, reader.line_num, e)) > > > I think this has to do with the end of line character but I am unsure how to > > fix it. I don't what to change the actual csv file I would like to fix the > > code. > > You could try reading the error message and looking at the documentation > of the 'open' function. ?Pay particular attention to the keywords > 'universal-newline mode'. > > Hint: 'rb' is almost the opposite of universal newline mode, and > it is very rare that you'd want to use 'b' to read a text file. > > --RDM A CSV file is *NOT* a text file. See the module docs. Also see this: http://bugs.python.org/issue4847 From gagsl-py2 at yahoo.com.ar Tue Feb 24 03:39:17 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 24 Feb 2009 06:39:17 -0200 Subject: opening files with names in non-english characters. References: <5b6a03dc-0393-46e6-bff0-c36669a67340@w34g2000yqm.googlegroups.com> <1378a511-fe4e-4fe2-a8b0-46022e472d24@x10g2000yqk.googlegroups.com> Message-ID: En Tue, 24 Feb 2009 01:29:07 -0200, venutaurus539 at gmail.com escribi?: > First of all thanks for your response. I've written a function > as shown below to recurse a directory and return a file based on the > value of n. I am calling this fucntion from my main code to catch that > filename. The folder which it recurses through contains a folder > having files with unicode names (as an example i've given earlier. > --------------------------------------------------------------- > def findFile(dir_path): > for name in os.listdir(dir_path): > full_path = os.path.join(dir_path, name) > print full_path > if os.path.isdir(full_path): > findFile(full_path) Here, you're simply discarding the result from the recursive call. Try something like this: result = findFile(full_path) if result is not None: return result > else: > n = n - 1 > if(n ==0): > return full_path > --------------------------------------------------------------- Now, what happens if you forget about findFile and try with a direct name instead? fpath = r"E:\DataSet\Unicode\UnicodeFiles_8859\001_0006_test_folder\0003testUnicode_??I?NOK?????U???UU?a??????ic?e?e??idnok?????u???uu.txt.txt" st = os.stat(path) print st -- Gabriel Genellina From andrew at acooke.org Tue Feb 24 03:44:01 2009 From: andrew at acooke.org (andrew cooke) Date: Tue, 24 Feb 2009 05:44:01 -0300 (CLST) Subject: Reference or Value? In-Reply-To: References: Message-ID: Steven D'Aprano wrote: > On Mon, 23 Feb 2009 08:14:34 -0300, andrew cooke wrote: > >> Steven D'Aprano wrote: >>> On Sun, 22 Feb 2009 13:37:27 -0300, andrew cooke wrote: >>> >>>> as far as i understand things, the best model is: >>>> >>>> 1 - everything is an object >>>> 2 - everything is passed by reference >>> >>> Except that is wrong. If it were true, you could do this: >> [pointer swapping] >> >> i was thinking of how the stack is used; i would have called what you >> are talking about "pointer semantics". however, on reading around a >> little, it seems that i'm in a very small minority (which is a pity, >> because if you restrict the meaning to how values are handled on the >> stack then you get a lot closer to having just values and references, >> rather than the whole pile of different terms that are apparently in >> use). >> >> sorry for the confusion, > > Why is it a pity to have a whole pile of different terms to describe a > whole lot of different behaviours? I would suggest the real confusion > would be if we had two terms to describe a dozen different parameter- > passing conventions. because: (1) it's often useful to explain things as (simpler) orthogonal components rather than globbing everything under one term; that lets you more easily carry across knowledge from previous experience. (2) while using a term that has (according to wikipedia) "widespread usage in the Python community" helps you save time and avoid confusion, it doesn't necessarily explain best to someone from outside that community what is happening. in this particular case you are getting dangerously close to having a term that is used only for one language and which, therefore, is at risk of meaning little more that "the way python does it" (which is, i think you'll agree, more tautological than helpful). andrew From gagsl-py2 at yahoo.com.ar Tue Feb 24 03:44:27 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 24 Feb 2009 06:44:27 -0200 Subject: Problem in accessing files with unicode fonts. References: <50697b2c0902232246t66922c39i9a73996be230d1a4@mail.gmail.com> Message-ID: En Tue, 24 Feb 2009 05:15:33 -0200, venu madhav escribi?: >> > def findFile(dir_path): >> > for name in os.listdir(dir_path): >> > full_path = os.path.join(dir_path, name) >> > print full_path >> > if os.path.isdir(full_path): >> > findFile(full_path) >> > else: >> > v = unicode(full_path,errors='skip') >> > i = win32api.GetFileAttributes(v) >> > >> > findFile("F:\\DataSet\\Unicode") >> > --------------------------------------------------------------- >> > Now when I run this scirpt, the full_path variable which should >> contain >> the >> > name of the file has "????" for non english ( I tried Arabic) >> characters. >> As >> > a result the getfileattributes function is failing to recognise that >> file >> > and is raising an exception. >> > i = win32api.GetFileAttributes(v) >> > error: (123, 'GetFileAttributes', 'The filename, directory name, or >> volume >> > label syntax is incorrect.') If you call os.listdir with an unicode directory, it returns unicode file names. That is (after correcting the previous error in findFile), call it using: findFile(u"F:\\DataSet\\Unicode") -- Gabriel Genellina From venutaurus539 at gmail.com Tue Feb 24 04:18:41 2009 From: venutaurus539 at gmail.com (venutaurus539 at gmail.com) Date: Tue, 24 Feb 2009 01:18:41 -0800 (PST) Subject: Problem in accessing files with unicode fonts. References: <50697b2c0902232246t66922c39i9a73996be230d1a4@mail.gmail.com> Message-ID: On Feb 24, 1:44?pm, "Gabriel Genellina" wrote: > En Tue, 24 Feb 2009 05:15:33 -0200, venu madhav ? > escribi?: > > > > >> > def findFile(dir_path): > >> > ? ? for name in os.listdir(dir_path): > >> > ? ? ? ? full_path = os.path.join(dir_path, name) > >> > ? ? ? ? print full_path > >> > ? ? ? ? if os.path.isdir(full_path): > >> > ? ? ? ? ? ? findFile(full_path) > >> > ? ? ? ? else: > >> > ? ? ? ? ? ? v = unicode(full_path,errors='skip') > >> > ? ? ? ? ? ? i = win32api.GetFileAttributes(v) > > >> > findFile("F:\\DataSet\\Unicode") > >> > --------------------------------------------------------------- > >> > Now when I run this scirpt, the full_path variable which should ? > >> contain > >> the > >> > name of the file has "????" for non english ( I tried Arabic) ? > >> characters. > >> As > >> > a result the getfileattributes function is failing to recognise that ? > >> file > >> > and is raising an exception. > >> > ? ? i = win32api.GetFileAttributes(v) > >> > error: (123, 'GetFileAttributes', 'The filename, directory name, or > >> volume > >> > label syntax is incorrect.') > > If you call os.listdir with an unicode directory, it returns unicode file ? > names. > That is (after correcting the previous error in findFile), call it using: > findFile(u"F:\\DataSet\\Unicode") > > -- > Gabriel Genellina Thank you for your solution. It really helped. But how should I give if my path is in a varialble. For ex: path has that value obtained through command line arguments. path = sys.argv[2] In such a case how can we convert the path to UNICODE? Thank you once again, Venu From nick at craig-wood.com Tue Feb 24 04:31:53 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Tue, 24 Feb 2009 03:31:53 -0600 Subject: intermediate python csv reader/writer question from a beginner References: Message-ID: Learning Python wrote: > anything related to csv, I usually use VB within excel to manipulate > the data, nonetheless, i finally got the courage to take a dive into > python. i have viewed a lot of googled csv tutorials, but none of > them address everything i need. Nonetheless, I was wondering if > someone can help me manipulate the sample csv (sample.csv) I have > generated: > > ,, > someinfo,,,,,,, > somotherinfo,,,,,,, > SEQ,Names,Test1,Test2,Date,Time,, > 1,Adam,1,2,Monday,1:00 PM,, > 2,Bob,3,4,Monday,1:00 PM,, > 3,Charlie,5,6,Monday,1:00 PM,, > 4,Adam,7,8,Monday,2:00 PM,, > 5,Bob,9,10,Monday,2:00 PM,, > 6,Charlie,11,12,Monday,2:00 PM,, > 7,Adam,13,14,Tuesday,1:00 PM,, > 8,Bob,15,16,Tuesday,1:00 PM,, > 9,Charlie,17,18,Tuesday,1:00 PM,, > > into (newfile.csv): > > Adam-Test1,Adam-Test2,Bob-Test1,Bob-Test2,Charlie-Test1,Charlie- > Test2,Date,Time > 1,2,3,4,5,6,Monday,1:00 PM > 7,8,9,10,11,12,Monday,2:00 PM > 13,14,15,16,17,18,Tuesday,1:00 PM > > note: > 1. the true header doesn't start line 4 (if this is the case would i > have to use "split"?) > 2. if there were SEQ#10-12, or 13-15, it would still be Adam, Bob, > Charlie, but with different Test1/Test2/Date/Time I'm not really sure what you are trying to calculate, but this should give you some ideas... import csv from collections import defaultdict reader = csv.reader(open("sample.csv")) result = defaultdict(list) for row in reader: # ignore unless first row is numeric if not row or not row[0].isdigit(): continue n, name, a, b, day, time = row[:6] print "n=%r, name=%r, a=%r, b=%r, day=%r, time=%r" % (n, name, a, b, day, time) result[(day, time)].append(n) writer = csv.writer(open("newfile.csv", "w")) for key, values in result.iteritems(): day, time = key values = values + [day, time] writer.writerow(values) This prints n='1', name='Adam', a='1', b='2', day='Monday', time='1:00 PM' n='2', name='Bob', a='3', b='4', day='Monday', time='1:00 PM' n='3', name='Charlie', a='5', b='6', day='Monday', time='1:00 PM' n='4', name='Adam', a='7', b='8', day='Monday', time='2:00 PM' n='5', name='Bob', a='9', b='10', day='Monday', time='2:00 PM' n='6', name='Charlie', a='11', b='12', day='Monday', time='2:00 PM' n='7', name='Adam', a='13', b='14', day='Tuesday', time='1:00 PM' n='8', name='Bob', a='15', b='16', day='Tuesday', time='1:00 PM' n='9', name='Charlie', a='17', b='18', day='Tuesday', time='1:00 PM' And leaves newfile.csv with the contents 1,2,3,Monday,1:00 PM 7,8,9,Tuesday,1:00 PM 4,5,6,Monday,2:00 PM -- Nick Craig-Wood -- http://www.craig-wood.com/nick From gagsl-py2 at yahoo.com.ar Tue Feb 24 04:36:51 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 24 Feb 2009 07:36:51 -0200 Subject: Reference or Value? References: Message-ID: En Tue, 24 Feb 2009 06:44:01 -0200, andrew cooke escribi?: > Steven D'Aprano wrote: >> On Mon, 23 Feb 2009 08:14:34 -0300, andrew cooke wrote: >> >>> Steven D'Aprano wrote: >>>> On Sun, 22 Feb 2009 13:37:27 -0300, andrew cooke wrote: >>>> >>>>> as far as i understand things, the best model is: >>>>> >>>>> 1 - everything is an object >>>>> 2 - everything is passed by reference >>>> >>>> Except that is wrong. If it were true, you could do this: >>> [pointer swapping] >>> >>> i was thinking of how the stack is used; i would have called what you >>> are talking about "pointer semantics". however, on reading around a >>> little, it seems that i'm in a very small minority (which is a pity, >>> because if you restrict the meaning to how values are handled on the >>> stack then you get a lot closer to having just values and references, >>> rather than the whole pile of different terms that are apparently in >>> use). >>> >>> sorry for the confusion, >> >> Why is it a pity to have a whole pile of different terms to describe a >> whole lot of different behaviours? I would suggest the real confusion >> would be if we had two terms to describe a dozen different parameter- >> passing conventions. > > because: > > (1) it's often useful to explain things as (simpler) orthogonal > components > rather than globbing everything under one term; that lets you more easily > carry across knowledge from previous experience. > > (2) while using a term that has (according to wikipedia) "widespread > usage > in the Python community" helps you save time and avoid confusion, it > doesn't necessarily explain best to someone from outside that community > what is happening. in this particular case you are getting dangerously > close to having a term that is used only for one language and which, > therefore, is at risk of meaning little more that "the way python does > it" > (which is, i think you'll agree, more tautological than helpful). But -paraphrasing A.E.- we should explain it in the simplest terms, but not simpler. Some people think that there exist only two possible ways to pass an argument: by value or by reference. The way Python does it doesn't have the same properties that pass-by-value nor pass-by-reference have in other languages, so both names are inapropiate. You appear to favor the "by reference" name. A couple months ago some other guy were strongly defending the "by value" name -- he even set up a website supporting his idea. The fact is, if you say "it's by value" you'll disappoint some expectations from some users, and if you say "it's by reference" you'll disappoint some other expectations. So you must say something different ("it's by reference, but the references cannot be modified (!), and...", "it's by value, but the values are references (!!), and...", or whatever description you choose). Given that, it's better to use a different name: you're going to explain the concept anyway. And Python isn't the first language using this convention; if you look in the FAQ or search recent threads in this group you'll find references going back to the '70s. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Tue Feb 24 04:45:35 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 24 Feb 2009 07:45:35 -0200 Subject: Problem in accessing files with unicode fonts. References: <50697b2c0902232246t66922c39i9a73996be230d1a4@mail.gmail.com> Message-ID: En Tue, 24 Feb 2009 07:18:41 -0200, venutaurus539 at gmail.com escribi?: > Thank you for your solution. It really helped. But how should I give > if my path is in a varialble. > > For ex: path has that value obtained through command line arguments. > > path = sys.argv[2] > > In such a case how can we convert the path to UNICODE? If you know the encoding used for your file names, use it; else try sys.getfilesystemencoding() fsencoding = sys.getfilesystemencoding() path = sys.argv[2].decode(fsencoding) -- Gabriel Genellina From andrew at acooke.org Tue Feb 24 04:58:08 2009 From: andrew at acooke.org (andrew cooke) Date: Tue, 24 Feb 2009 06:58:08 -0300 (CLST) Subject: Reference or Value? In-Reply-To: References: Message-ID: <51a82ff3d4a9eee147380c48e72e0cb2.squirrel@localhost> Gabriel Genellina wrote: > En Tue, 24 Feb 2009 06:44:01 -0200, andrew cooke > escribi?: > >> Steven D'Aprano wrote: >>> On Mon, 23 Feb 2009 08:14:34 -0300, andrew cooke wrote: >>> >>>> Steven D'Aprano wrote: >>>>> On Sun, 22 Feb 2009 13:37:27 -0300, andrew cooke wrote: >>>>> >>>>>> as far as i understand things, the best model is: >>>>>> >>>>>> 1 - everything is an object >>>>>> 2 - everything is passed by reference >>>>> >>>>> Except that is wrong. If it were true, you could do this: >>>> [pointer swapping] >>>> >>>> i was thinking of how the stack is used; i would have called what you >>>> are talking about "pointer semantics". however, on reading around a >>>> little, it seems that i'm in a very small minority (which is a pity, >>>> because if you restrict the meaning to how values are handled on the >>>> stack then you get a lot closer to having just values and references, >>>> rather than the whole pile of different terms that are apparently in >>>> use). >>>> >>>> sorry for the confusion, >>> >>> Why is it a pity to have a whole pile of different terms to describe a >>> whole lot of different behaviours? I would suggest the real confusion >>> would be if we had two terms to describe a dozen different parameter- >>> passing conventions. >> >> because: >> >> (1) it's often useful to explain things as (simpler) orthogonal >> components >> rather than globbing everything under one term; that lets you more >> easily >> carry across knowledge from previous experience. >> >> (2) while using a term that has (according to wikipedia) "widespread >> usage >> in the Python community" helps you save time and avoid confusion, it >> doesn't necessarily explain best to someone from outside that community >> what is happening. in this particular case you are getting dangerously >> close to having a term that is used only for one language and which, >> therefore, is at risk of meaning little more that "the way python does >> it" >> (which is, i think you'll agree, more tautological than helpful). > > But -paraphrasing A.E.- we should explain it in the simplest terms, but > not simpler. > > Some people think that there exist only two possible ways to pass an > argument: by value or by reference. The way Python does it doesn't have > the same properties that pass-by-value nor pass-by-reference have in other > languages, so both names are inapropiate. You appear to favor the "by > reference" name. A couple months ago some other guy were strongly > defending the "by value" name -- he even set up a website supporting his > idea. > > The fact is, if you say "it's by value" you'll disappoint some > expectations from some users, and if you say "it's by reference" you'll > disappoint some other expectations. So you must say something different > ("it's by reference, but the references cannot be modified (!), and...", > "it's by value, but the values are references (!!), and...", or whatever > description you choose). Given that, it's better to use a different name: > you're going to explain the concept anyway. if you read my post i think you'll find i was not advocating either of those. i really think this discussion has gone on far enough; i have better things to do. andrew > And Python isn't the first language using this convention; if you look in > the FAQ or search recent threads in this group you'll find references > going back to the '70s. > > -- > Gabriel Genellina > > -- > http://mail.python.org/mailman/listinfo/python-list > > From pavlovevidence at gmail.com Tue Feb 24 05:04:16 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 24 Feb 2009 02:04:16 -0800 (PST) Subject: A tale of two execs References: <7d85586a-d746-4e0f-b01b-86bf2e388971@f18g2000vbf.googlegroups.com> <794a35cc-f530-43e7-97c5-87694f27b573@x9g2000yqk.googlegroups.com> Message-ID: <9095ae87-c11d-4439-aeed-05533c610e54@m24g2000vbp.googlegroups.com> On Feb 23, 9:13?pm, aha wrote: > Hello All, > ? It occurred to me that I might just want to try copying the > subprocess.py installed in a /usr/lib/python24 installation to the > directory where I place the scripts that I need to launch my > application...I know this was mentioned earlier. ?Anyway, my > application worked under python 2.3 and later python versions as > well. ?Here is what I did: > > I renamed subprocess.py to subprocess23.py and then used the following > code: > > try: > ? import subprocess > except ImportError: > ? import subprocess23 as subprocess > > I chose this route because I took a deeper look at the code in the > subprocess module and I also realized that I would not be able to use > the popen2, because I would not be able to do things like os.setpgrp > for preexec_fn, with popen2. ?In the end, if I wanted that type of > functionality I would have to use os.dup, fork, exec, which meant > reinventing the wheel. ?I overcame the issue of dealing with msvcrt > and _subprocess under windows by requiring python24 or greater under > windows. Distributing the interpreter doesn't look quite as silly as it did this morning now, does it? Carl Banks From gagsl-py2 at yahoo.com.ar Tue Feb 24 05:33:11 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 24 Feb 2009 08:33:11 -0200 Subject: tkinter icons as bytestrings, not files? References: Message-ID: En Tue, 24 Feb 2009 02:56:12 -0200, Peter Billam escribi?: > As a newbie, starting with Python3, I'm working my way through Mark > Summerfield's tkinter examples. In the toolbar, there's lines like: > image = os.path.join(os.path.dirname(__file__), image) > image = tkinter.PhotoImage(file=image) > > which are always failing because the icons are in the wrong place > and I can't help but wonder if I can put all these little images > in the application itself, either as b'whatever' or uuencoded or > in svg etc, and then invoke some suitable variation of the > image = tkinter.PhotoImage(file=image) > or of the > button = tkinter.Button(toolbar, image=image, command=command) > command ? (I did try help('tkinter.PhotoImage') but didn't spot a > magic key (unless it's "data=something, format=something")) ... Almost; see the best documentation source for tkinter: http://effbot.org/tkinterbook/photoimage.htm -- Gabriel Genellina From yatsek at gmail.com Tue Feb 24 05:48:10 2009 From: yatsek at gmail.com (yatsek at gmail.com) Date: Tue, 24 Feb 2009 02:48:10 -0800 (PST) Subject: Python, HTTPS (SSL), tlslite and POST method (and lots of pain) References: <00e56c9a-85a7-440c-a48d-2a0ea9e00992@j35g2000yqh.googlegroups.com> Message-ID: OK I found workaround. So just for other fighting the same thing: Instead of using tlslite use pyOpenSSL and as a base for your server you can use: http://code.activestate.com/recipes/442473/ When you add do_POST method everything works greetz Jacek From steve at pearwood.info Tue Feb 24 05:49:26 2009 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 24 Feb 2009 21:49:26 +1100 Subject: Reference or Value? References: Message-ID: <01b3c619$0$23707$c3e8da3@news.astraweb.com> andrew cooke wrote: > Steven D'Aprano wrote: >> On Mon, 23 Feb 2009 08:14:34 -0300, andrew cooke wrote: >> >>> Steven D'Aprano wrote: >>>> On Sun, 22 Feb 2009 13:37:27 -0300, andrew cooke wrote: >>>> >>>>> as far as i understand things, the best model is: >>>>> >>>>> 1 - everything is an object >>>>> 2 - everything is passed by reference >>>> >>>> Except that is wrong. If it were true, you could do this: >>> [pointer swapping] >>> >>> i was thinking of how the stack is used; i would have called what you >>> are talking about "pointer semantics". however, on reading around a >>> little, it seems that i'm in a very small minority (which is a pity, >>> because if you restrict the meaning to how values are handled on the >>> stack then you get a lot closer to having just values and references, >>> rather than the whole pile of different terms that are apparently in >>> use). >>> >>> sorry for the confusion, >> >> Why is it a pity to have a whole pile of different terms to describe a >> whole lot of different behaviours? I would suggest the real confusion >> would be if we had two terms to describe a dozen different parameter- >> passing conventions. > > because: > > (1) it's often useful to explain things as (simpler) orthogonal components > rather than globbing everything under one term; "One term"? If you look at this Wikipedia page: http://en.wikipedia.org/wiki/Evaluation_strategy you should be able to count no fewer than thirteen different terms for different evaluation strategies, and "call-by-value" itself is described as a family of strategies. Who is gobbing everything under one term? Certainly not me. If anything, your preferred tactic is to gob everything under one of two terms, call-by-value and call-by-reference. That's not my preferred tactic. > that lets you more easily > carry across knowledge from previous experience. That's only useful if that previous experience *clarifies* rather than *confuses*. This very thread demonstrates that people's prior knowledge of call-by-whatever doesn't clarify Python's behaviour. > (2) while using a term that has (according to wikipedia) "widespread usage > in the Python community" helps you save time and avoid confusion, it > doesn't necessarily explain best to someone from outside that community > what is happening. And you think call-by-reference does? Python demonstrably does not behave like call-by-reference in other languages. I do not agree that it is wise to hammer the round peg of Python's actual behaviour into the square peg of newbies' concept of call-by-reference. > in this particular case you are getting dangerously > close to having a term that is used only for one language So what? What if Python was the only language that used the term? That doesn't make it inappropriate. If the users of other languages that use call-by-object semantics (Java, RealBasic, etc) choose to prefer a misleading name over a descriptive name, that's no reason for Python users to follow down their path. > and which, > therefore, is at risk of meaning little more that "the way python does it" > (which is, i think you'll agree, more tautological than helpful). No at all. Do you imagine that call-by-name means "the way Algol does it"? Algol is the only major language that uses call-by-name, it may even be the only language of any size, but that doesn't mean that call-by-name can't be defined and described independently of Algol. There's even a test, Knuth's "Man Or Boy Test", for testing how well a language implements call-by-name semantics. -- Steven From pablo.stapff at gmail.com Tue Feb 24 06:18:26 2009 From: pablo.stapff at gmail.com (PS) Date: Tue, 24 Feb 2009 03:18:26 -0800 (PST) Subject: undefined reference to `init_warnings' when compiling after freeze... Message-ID: <3d4eed77-ed87-4a14-bc68-8887ddeb4389@j12g2000vbl.googlegroups.com> Hello Python users I am trying to compile .py files using freeze with Python 2.6.1, but I get an error even when trying with hello.py from the examples. Freeze semes to do its work (last lines only): ps at linux-s7f4:~/soft/Python-2.6.1/Tools/freeze> python freeze.py hello.py generating table of frozen modules Warning: unknown modules remain: _bisect _collections _ctypes _functools _heapq _locale _random _socket _ssl _struct array binascii cPickle cStringIO fcntl itertools math operator readline select strop termios time Now run "make" to build the target: hello Now comes make: ps at linux-s7f4:~/soft/Python-2.6.1/Tools/freeze> make gcc -pthread -Xlinker -export-dynamic config.o frozen.o M_BaseHTTPServer.o M_FixTk.o M_SocketServer.o M_StringIO.o M_Tkconstants.o M_Tkinter.o M_UserDict.o M___future__.o M___main__.o M__abcoll.o M__threading_local.o M_abc.o M_base64.o M_bdb.o M_bisect.o M_cmd.o M_codecs.o M_collections.o M_copy.o M_copy_reg.o M_ctypes.oM_ctypes___endian.o M_ctypes__macholib.o M_ctypes__macholib__dyld.o M_ctypes__macholib__dylib.o M_ctypes__macholib__framework.o M_ctypes__util.o M_difflib.o M_dis.o M_distutils.o M_distutils__dep_util.o M_distutils__errors.o M_distutils__log.o M_distutils__spawn.o M_distutils__sysconfig.o M_distutils__text_file.o M_distutils__util.o M_doctest.o M_dummy_thread.o M_dummy_threading.o M_email.o M_email___parseaddr.o M_email__base64mime.o M_email__charset.o M_email__encoders.o M_email__errors.o M_email__feedparser.o M_email__message.o M_email__mime.o M_email__parser.o M_email__quoprimime.o M_email__utils.o M_encodings.o M_encodings__aliases.o M_fnmatch.o M_formatter.o M_ftplib.o M_functools.o M_genericpath.o M_getopt.o M_getpass.o M_gettext.o M_glob.o M_heapq.o M_httplib.o M_inspect.o M_keyword.o M_linecache.o M_locale.o M_macurl2path.o M_mimetools.o M_mimetypes.o M_ntpath.o M_nturl2path.o M_opcode.o M_optparse.o M_os.o M_os2emxpath.o M_pdb.o M_pickle.o M_pkgutil.o M_posixpath.o M_pprint.o M_py_compile.o M_pydoc.o M_pydoc_topics.o M_quopri.o M_random.o M_re.o M_repr.oM_rfc822.o M_shlex.o M_site.o M_socket.o M_sre_compile.o M_sre_constants.o M_sre_parse.o M_ssl.o M_stat.o M_string.o M_struct.o M_subprocess.o M_tempfile.o M_textwrap.o M_threading.o M_token.o M_tokenize.o M_traceback.o M_tty.o M_types.o M_unittest.o M_urllib.o M_urlparse.o M_uu.o M_warnings.o M_webbrowser.o /home/ps/app/lib/ python2.6/config/libpython2.6.a -lpthread -ldl -lutil -lm -o hello /home/ps/app/lib/python2.6/config/libpython2.6.a(posixmodule.o): In function `posix_tmpnam': /home/ps/soft/Python-2.6.1/./Modules/posixmodule.c:7079: warning: the use of `tmpnam_r' is dangerous, better use `mkstemp' /home/ps/app/lib/python2.6/config/libpython2.6.a(posixmodule.o): In function `posix_tempnam': /home/ps/soft/Python-2.6.1/./Modules/posixmodule.c:7034: warning: the use of `tempnam' is dangerous, betteruse `mkstemp' config.o:(.data+0x28): undefined reference to `init_warnings' collect2: ld returned 1 exit status make: *** [hello] Error 1 I tested it on OpenSuSe 11.0 and Ubuntu 8.10 with the same results. Did somebody experienced the same problem? With Python 2.5.1 it works without problems. Thanks in advance Pablo From gandalf at shopzeus.com Tue Feb 24 06:22:41 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 24 Feb 2009 12:22:41 +0100 Subject: try except question - serious foo bar question, and pulling my hair out :-) Message-ID: <49A3D881.4070500@shopzeus.com> Given this class below: import Queue import threading from sorb.util.dumpexc import dumpexc import waitablemixin PREFETCH_SIZE = 10 class Feeder(threading.Thread,waitablemixin.WaitableMixin): def __init__(self,connection_manager): self.cm = connection_manager self.expired_asins = Queue.Queue() self.logger = self.cm.loggerfactory.get_logger("feeder") threading.Thread.__init__(self) def run(self): try: try: d = self.cm.create_dispatcher() try: od_producer = d.locate('od_producer') while not self.cm.stop_requested.isSet(): try: items = od_producer.getsomeasins() if items: self.logger.info("Got %d items to process",len(items)) for item in items: self.expired_asins.put(item) if self.expired_asins.qsize()>PREFETCH_SIZE: while (self.expired_asins.qsize()>PREFETCH_SIZE) and \ not self.cm.stop_requested.isSet(): self.logger.info( "%s (>%s) items in the queue, waiting...", self.expired_asins.qsize(), PREFETCH_SIZE ) self.waitsome(1) else: self.logger.info("No more items to process, will wait 5 minutes.") self.waitsome(5*60) except Exception,e: self.logger.error("Could not get asins: %s",dumpexc(e) ) self.logger.error("Will retry in 10 seconds.") self.waitsome(10) finally: d.close() except Exception,e: self.cm.stop_requested.set() self.logger.error(dumpexc(e)) finally: self.logger.error("Feeder stopped. stop_requested = %s",str(self.cm.stop_requested.isSet())) How in the hell can I get the following log output: 2009-02-24 11:42:14,696 INFO .feeder Got 5 items to process 2009-02-24 11:42:14,732 INFO .feeder Got 5 items to process 2009-02-24 11:42:14,733 INFO .feeder 15 (>10) items in the queue, waiting... 2009-02-24 11:42:15,740 INFO .feeder 15 (>10) items in the queue, waiting... 2009-02-24 11:42:16,965 ERROR .feeder Feeder stopped. stop_requested = False It seems impossible to me. The while loop should only exit if stop_requested becomes set, OR if an exception is raised. However, all exceptions are cought and logged. But there are no exceptions logged. And stop_requested is NOT SET. (see the last line in the log). What is happening here? From gagsl-py2 at yahoo.com.ar Tue Feb 24 07:04:22 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 24 Feb 2009 10:04:22 -0200 Subject: try except question - serious foo bar question, and pulling my hair out :-) References: <49A3D881.4070500@shopzeus.com> Message-ID: En Tue, 24 Feb 2009 09:22:41 -0200, Laszlo Nagy escribi?: > Given this class below: [code removed] > It seems impossible to me. The while loop should only exit if > stop_requested becomes set, OR if an exception is raised. However, all > exceptions are cought and logged. But there are no exceptions logged. > And stop_requested is NOT SET. (see the last line in the log). I assume stop_requested is an Event object. Maybe other thread cleared it? -- Gabriel Genellina From gandalf at shopzeus.com Tue Feb 24 07:25:26 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 24 Feb 2009 13:25:26 +0100 Subject: try except question - serious foo bar question, and pulling my hair out :-) In-Reply-To: References: <49A3D881.4070500@shopzeus.com> Message-ID: <49A3E736.2020702@shopzeus.com> > > I assume stop_requested is an Event object. Maybe other thread cleared > it? > It was never set! -> nothing can clear it. From gandalf at shopzeus.com Tue Feb 24 07:34:11 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 24 Feb 2009 13:34:11 +0100 Subject: try except question - serious foo bar question, and pulling my hair out :-) In-Reply-To: <49A3E736.2020702@shopzeus.com> References: <49A3D881.4070500@shopzeus.com> <49A3E736.2020702@shopzeus.com> Message-ID: <49A3E943.3010405@shopzeus.com> >> >> I assume stop_requested is an Event object. Maybe other thread >> cleared it? >> > It was never set! -> nothing can clear it. In theory, it could be that a thread sets the event object. E.g.: #1. other thread calls stop_requested.set() #2. "while not self.stop_requested.isSet()" -- loop exists #3. other thread calls stop_requested.clear() #4. called this: self.logger.error("Feeder stopped. stop_requested = %s",str(self.cm.stop_requested.isSet())) However, this cannot happen. This application is running multiple threads (10+) and every thread monitors the global "stop_requested" flag. If there was an unexpected error in the service, stop_requested.set() is called. It will stop all threads and exit the process. stop_requested.clear() is NEVER called, so the while loop should have not been ended. So what is happening here? It drives me crazy. From patrick.oloughlin at gmail.com Tue Feb 24 07:41:30 2009 From: patrick.oloughlin at gmail.com (Paddy O'Loughlin) Date: Tue, 24 Feb 2009 12:41:30 +0000 Subject: "Byte" type? In-Reply-To: <49a36e1c$0$1586$742ec2ed@news.sonic.net> References: <4997aa38$0$1678$742ec2ed@news.sonic.net> <499859e2$0$1618$742ec2ed@news.sonic.net> <499f8a8e$0$1588$742ec2ed@news.sonic.net> <49a03081$0$1599$742ec2ed@news.sonic.net> <49A19B92.2080102@v.loewis.de> <49a36e1c$0$1586$742ec2ed@news.sonic.net> Message-ID: 2009/2/24 John Nagle : > Martin v. L?wis wrote: >>>> >>>> Please don't call something dumb that you don't fully understand. It's >>>> offenses the people who have spent lots of time developing Python -- >>>> personal, unpaid and voluntary time! > > ? Some of the people involved are on Google's payroll. Uh, what does that have to do with anything? It would only be relevant if you are saying that Google is paying them to do the work (so not just "on their payroll"). More importantly, it's also only relevant if ALL the people contributing are being paid by Google to do the work, which I'm pretty sure is not the case. There are people are spending lots of personal, unpaid and voluntary time developing Python. Paddy -- "Ray, when someone asks you if you're a god, you say YES!" From woodygar at sky.com Tue Feb 24 07:54:28 2009 From: woodygar at sky.com (Gary Wood) Date: Tue, 24 Feb 2009 12:54:28 -0000 Subject: Newby - is this what they are looking for ?? and is their a better a way Message-ID: <8C52BE9109254380A7EB5B082D23DB6B@Woodygar> ''' program. 1.What type of data will the input be? What type of data will the output be? 2.Get the phrase from the user. 3.Convert to upper case. 4.Divide the phrase into words. 5.Initialize a new empty list, letters. 6.Get the first letter of each word. 7.Append the first letter to the list letters. 8.Join the letters together, with no space between them. 9.Print the acronym. Which of these steps is in a loop? What for statement controls this loop? ''' line = input('enter a phrase') lines = line.upper() seq = lines.split() for i in seq: word = (i[0]) print(word, end='') -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Tue Feb 24 08:06:14 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 24 Feb 2009 05:06:14 -0800 Subject: Newby - is this what they are looking for ?? and is their a better a way In-Reply-To: <8C52BE9109254380A7EB5B082D23DB6B@Woodygar> References: <8C52BE9109254380A7EB5B082D23DB6B@Woodygar> Message-ID: <50697b2c0902240506nffd6afana480585cdf744bdf@mail.gmail.com> On Tue, Feb 24, 2009 at 4:54 AM, Gary Wood wrote: > ''' program. > 1.What type of data will the input be? What type of data will the output be? > 2.Get the phrase from the user. > 3.Convert to upper case. > 4.Divide the phrase into words. > 5.Initialize a new empty list, letters. > 6.Get the first letter of each word. > 7.Append the first letter to the list letters. > 8.Join the letters together, with no space between them. > 9.Print the acronym. You're not doing 5 or 7-9 right. Where's the `letters` list they asked for? > Which of these steps is in a loop? What for statement controls this loop? > ''' > > line = input('enter a phrase') > lines = line.upper() > seq = lines.split() > for i in seq: > ??? word = (i[0]) > ??? print(word, end='') Hint: `print` shouldn't be used inside the loop at all. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From gandalf at shopzeus.com Tue Feb 24 08:09:44 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 24 Feb 2009 14:09:44 +0100 Subject: try except question - serious foo bar question, and pulling my hair out :-) In-Reply-To: <49A3D881.4070500@shopzeus.com> References: <49A3D881.4070500@shopzeus.com> Message-ID: <49A3F198.4030208@shopzeus.com> > > It seems impossible to me. The while loop should only exit if > stop_requested becomes set, OR if an exception is raised. However, all > exceptions are cought and logged. But there are no exceptions logged. > And stop_requested is NOT SET. (see the last line in the log). > > What is happening here? It was a bad assumption. Not all exceptions are subclasses of "Exception". In this case, an inner call raised SystemExit(0). So be aware. Don't think that this will catch all exceptions: try: ??? except Exception,e: do_with(e) Use this instead: import sys try: ??? except: e = sys.exc_value do_with(e) Thanks, Laszlo From steve at holdenweb.com Tue Feb 24 08:17:28 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 24 Feb 2009 08:17:28 -0500 Subject: How to read columns in python In-Reply-To: References: <50697b2c0902232248q7f704629v74b8125262c206f4@mail.gmail.com> Message-ID: Dhananjay wrote: > Well, > > The three columns are tab separated and there are 200 such rows having > these 3 columns in the file. > > First two columns are x and y coordinates and third column is the > corresponding value. > > I want to read this file as a matrix in which column1 correspond to > row, column2 corresponds to columns(in matrix) and column3 corresponds > to value in the matrix. > > > > -- Dhananjay > > > > On Tue, Feb 24, 2009 at 12:18 PM, Chris Rebert > wrote: > > On Mon, Feb 23, 2009 at 10:41 PM, Dhananjay > > > wrote: > > I am bit new to python and programming and this might be a basic > question: > > > > I have a file containing 3 columns. > > Your question is much too vague to answer. What defines a "column" for > you? Tab-separated, comma-separated, or something else altogether? > Try something like f = open("datafile.txt", 'r') x = []; y = []; val = [] for line in f: xx, yy, vv = line.split() x.append(float(xx)) y.append(float(yy)) val.append(float(vv)) Of course this is only one way to represent the data - as vectors of x, y and val. If you just wanted a list of the data triples then you could have written f = open("datafile.txt", 'r') values = [] for line in f: x, y, v = line.split() values.append(float(x), float(y), float(v)) regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From stefan_ml at behnel.de Tue Feb 24 08:22:25 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 24 Feb 2009 14:22:25 +0100 Subject: Python C-API Object Allocation In-Reply-To: References: Message-ID: <49a3f491$0$30238$9b4e6d93@newsspool1.arcor-online.net> > On Feb 21, 2009, at 10:01 AM, William Newbery wrote: >> Ive been learning the C-API lately so I can write python extensions >> for some of my c++ stuff. First thing that comes to (my) mind is that you probably do not want to write code against the bare C-API. Instead, give Cython a try. http://cython.org Stefan From girish.cfc at gmail.com Tue Feb 24 08:29:21 2009 From: girish.cfc at gmail.com (Girish) Date: Tue, 24 Feb 2009 05:29:21 -0800 (PST) Subject: Extract CDATA Node Message-ID: How do I extract CDATA node in Python? I'm using dom.minidom as follows:- from xml.dom.minidom import Document class XMLDocument(): def __init__(self): self.doc = Document() def parseString(self, d): self.doc = parseString(_encode(d)) return self #Create instance of XMLDocument doc = XMLDocument() doc.parseString(open(os.curdir + '\\XML\\1.xml', 'r').read()) ..... Please help me out. Thanks, Girish From exarkun at divmod.com Tue Feb 24 08:38:37 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Tue, 24 Feb 2009 08:38:37 -0500 Subject: Extract CDATA Node In-Reply-To: Message-ID: <20090224133837.12853.1184111844.divmod.quotient.13470@henry.divmod.com> On Tue, 24 Feb 2009 05:29:21 -0800 (PST), Girish wrote: >How do I extract CDATA node in Python? I'm using dom.minidom as >follows:- > >from xml.dom.minidom import Document > >class XMLDocument(): > > def __init__(self): > self.doc = Document() > > def parseString(self, d): > self.doc = parseString(_encode(d)) > return self > >#Create instance of XMLDocument >doc = XMLDocument() >doc.parseString(open(os.curdir + '\\XML\\1.xml', 'r').read()) >..... > >Please help me out. Here's one approach. from xml.dom.minidom import parse doc = parse(file('XML/1.xml')) cdata = [] elements = [doc.documentElement] while elements: e = elements.pop(0) if e.nodeType == doc.TEXT_NODE: cdata.append(e.data) elif e.nodeType == doc.ELEMENT_NODE: elements[:0] = e.childNodes print cdata I bet there are simpler ways, though, based on other XML libraries. Jean-Paul From steve at holdenweb.com Tue Feb 24 09:06:05 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 24 Feb 2009 09:06:05 -0500 Subject: try except question - serious foo bar question, and pulling my hair out :-) In-Reply-To: <49A3E943.3010405@shopzeus.com> References: <49A3D881.4070500@shopzeus.com> <49A3E736.2020702@shopzeus.com> <49A3E943.3010405@shopzeus.com> Message-ID: Laszlo Nagy wrote: > >>> >>> I assume stop_requested is an Event object. Maybe other thread >>> cleared it? >>> >> It was never set! -> nothing can clear it. > In theory, it could be that a thread sets the event object. E.g.: > > #1. other thread calls stop_requested.set() > #2. "while not self.stop_requested.isSet()" -- loop exists > #3. other thread calls stop_requested.clear() > #4. called this: self.logger.error("Feeder stopped. stop_requested = > %s",str(self.cm.stop_requested.isSet())) > > However, this cannot happen. This application is running multiple > threads (10+) and every thread monitors the global "stop_requested" > flag. If there was an unexpected error in the service, > stop_requested.set() is called. It will stop all threads and exit the > process. stop_requested.clear() is NEVER called, so the while loop > should have not been ended. So what is happening here? It drives me crazy. > Time to get a stuffed toy and go through your code, explaining to the toy exactly why your code is right and nothing can go wrong. With luck, within half an hour you will realize what you are doing wrong ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From digitig at gmail.com Tue Feb 24 09:19:56 2009 From: digitig at gmail.com (Tim Rowe) Date: Tue, 24 Feb 2009 14:19:56 +0000 Subject: Reference or Value? In-Reply-To: <01b3c619$0$23707$c3e8da3@news.astraweb.com> References: <01b3c619$0$23707$c3e8da3@news.astraweb.com> Message-ID: 2009/2/24 Steven D'Aprano : > If you look at this Wikipedia page: > > http://en.wikipedia.org/wiki/Evaluation_strategy > > you should be able to count no fewer than thirteen different terms for > different evaluation strategies, and "call-by-value" itself is described as > a family of strategies. And that call by sharing is a member of that family even though the behaviour is (as I understand it) exactly what you would get if you pass an object by ^reference^ in C++. Wikipedia can be a double-edged sword ;-). I think the problem is that "Call by value" and "Call by reference" are terms that pre-date object orientation, and don't cope well with obect-oriented languages in general, not just with Python. That Java programmers get by thinking the mechanism is called "call by value", C++ programmers get by thinking the same mechanism is called "call by reference" and Python programmers get by thinking the same mechanism is called "call by sharing" suggests that the terms are no longer helpful. Programmers in one language simply can't know what the terminology means when applied to another language without learning the behaviour in that other language before learning the terminology. That means that Torsten's original question probably wasn't the one he wanted to ask, and wasn't a useful one. The useful question is "what is Python's parameter passing *behaviour^", with a possible supplementary "what do they call that behaviour *in the Python community*", recognising that if they asked "what is Java's parameter passing *behaviour^", with the supplementary "what do they call that behaviour *in the Java community*" they would get much the same answer for the first question (immutability is handled differently, I think, but it's there) but a totally different answer to the second. -- Tim Rowe From bnsilinux at gmail.com Tue Feb 24 09:20:48 2009 From: bnsilinux at gmail.com (Ben) Date: Tue, 24 Feb 2009 06:20:48 -0800 (PST) Subject: Extending Python Questions ..... References: Message-ID: <7e1a6ec9-8457-40ef-a3da-a16b5dac1100@r34g2000vbp.googlegroups.com> On Feb 23, 2:31?pm, Nick Craig-Wood wrote: > Ben wrote: > > ?In My S-Lag Project called, SLAG, I have some function keys that get > > ?mapped back to S-lang internal functions. > > > ?My SLAG project works pretty much like Python (as does the S-Lang). > > ?You write a S-lang script > > ?that "imports" your extension. module - and all this gets run by the > > ?shell/interpreter. > > > ?I allow function keys to be mapped back internal function(s) inside of > > ?the controlling program. > > > ?My question is which Python C api Do I need to this with ? > > Do you mean like this? > > ?http://code.google.com/p/python-slang > > Not sure how well maintained it is though. > > > Do I need to worry about my reference counting since the Python > > Program is in essence calling a function in itself? > > I'm not sure I understand you here, but in general you don't need to > worry about reference counting in Python - it all happens behind the > scenes. ?If you are writing a python extension in C then you do need > to worry about reference counting - a lot! > > -- > Nick Craig-Wood --http://www.craig-wood.com/nick No, It uses the the S-lang for video, and input control. However, SLAG is more of an abstract layer on top of that. It has a Structures that contains menus and screens (menumodule / screenmodule). One LOADS them up with parameters. such as creating a new menu is like: OpenMenu( Company name, SubSystem, this program name, mode, bottom status display) - Create initial menu structure Addtomenu(Menu Block Set name, DISPLAY line, ID, type of program, password ID ) - add to / update MENU blocks. runMenu() - Displays the whole create menu structure. The Menu structure is done in pull downs and scrollable blocks in a TUI (text User Interface) and using the S-lang screen library is fully mouseable. The screen module works mych the same way, but with the abiltity to open and close and work within "Sub Screens". For those who do not know, S-lang is a interpreted language much like Python. However, there is s direth of library modules. The original S-lang started out as library of screen of keyboard modules, but has been expanded My SLAG project does not care in reality WHICH or what language, it is simply handling menu and screen control. Hope this helps ... From gagsl-py2 at yahoo.com.ar Tue Feb 24 09:25:50 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 24 Feb 2009 12:25:50 -0200 Subject: Running script in module initialization References: <56d0c8e4-c7cd-4b3b-aef0-7dc92996efb3@m15g2000vbp.googlegroups.com> <73cffb49-642a-4d6f-8c28-cc0ee5bb738b@z1g2000yqn.googlegroups.com> Message-ID: En Mon, 23 Feb 2009 05:51:27 -0200, Kom2 escribi?: > On 20 ?n, 16:27, Steve Holden wrote: >> Kom2 wrote: >> > Hello, >> > I'm trying to convert my project from python 2.5 to python 3.0 and I >> > have the following problem. My project is PYD library written in C++. >> > So I have this PyInit_ModuleName function containing PyModule_Create >> > call and this function also call some script with declarations: >> >> > ? ?PyObject* m; >> >> > ? ?m = PyModule_Create(&PyVRDAModule); >> > ? ?if (m == NULL) { >> > ? ? ? return NULL; >> > ? ?} >> > ? ?PyObject *d, *v; >> > ? ?d = PyModule_GetDict(m); >> > ? ?v = PyRun_StringFlags(txtPyPredefinedConstants), Py_file_input, d, >> > d, NULL); >> > ? ?...... >> >> > txtPyPredefinedConstants is string with this content: >> >> > class CursorMoveType: >> > ? ?First = 0 >> > ? ?Last = 1 >> > ? ?Next = 2 >> > ? ?Previous = 3 >> > ? ?Bookmark = 4 >> > ? ?NewRecord = 5 >> >> > In Python 2.5 everything works fine, now in python3.0 >> > PyRun_StringFlags returns NULL and I get error "__build_class__ not >> > found". __build_class__ is a (hidden?) function in the builtins module. Your module isn't completely created yet, it lacks the __builtins__ attribute, so you can't execute any Python code that calls a builtin function. In 2.5 the class statement was a lot simpler, but in 3.0 it requires an auxiliary function (implemented as builtins.__build_class__) You may try setting __builtins__ to the current builtins (PyEval_GetBuiltins) before executing Python code. Or, if those 7 lines are all you need, you may just write the equivalent C code. -- Gabriel Genellina From chrysn at fsfe.org Tue Feb 24 09:27:19 2009 From: chrysn at fsfe.org (chrysn at fsfe.org) Date: Tue, 24 Feb 2009 15:27:19 +0100 Subject: variables bound in moudules are None when module is not completely imported Message-ID: <20090224142719.GA27379@hephaistos.amsuess.com> when a module being loaded is interrupted by an exception, code blocks that have the module's scope in their environment will later evaluate variables bound to that module to None, instead of preserving that scope (because it is still referenced somewhere) or raising a NameError (for which i see no reason, but which would still be better than silently returning None). this can happen, for example, when one tries to join different programs in one main loop by having the modules first hook up to events and then terminating the subprograms by replacing the call to the main loop with an exception raiser. attached, there is a tarball with two similar examples, one demonstrating that with functions instead of modules (this behaves as expected; ./function/), the other showing that when a module's block is terminated, the remaining variables are set to None (./module/); both can be run by calling `python main.py` in the respective directory. * is this a bug in the pythin implementation? (i've tested it both with 2.5 and with 3.0b2) * if yes, is it identical to [1748015]? (i suppose it is, but lacking experience with pdb i am not sure) * can / will this be fixed? * is there a workaround? * especially, is there a workaround that works w/o rewriting the modules that raise the exceptions? (otherwise, wrapping all the stuff called in the __name__=="__main__" wrapper into a main() function and then calling that would trivially solve that) answers to any of these questions would be very much appreciated regards chrysn [1748015] http://bugs.python.org/issue1748015 -- To use raw power is to make yourself infinitely vulnerable to greater powers. -- Bene Gesserit axiom -------------- next part -------------- A non-text attachment was scrubbed... Name: module_none.tar.bz2 Type: application/octet-stream Size: 1191 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 204 bytes Desc: Digital signature URL: From gagsl-py2 at yahoo.com.ar Tue Feb 24 09:52:14 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 24 Feb 2009 12:52:14 -0200 Subject: try except question - serious foo bar question, and pulling my hair out :-) References: <49A3D881.4070500@shopzeus.com> <49A3F198.4030208@shopzeus.com> Message-ID: En Tue, 24 Feb 2009 11:09:44 -0200, Laszlo Nagy escribi?: >> It seems impossible to me. The while loop should only exit if >> stop_requested becomes set, OR if an exception is raised. However, all >> exceptions are cought and logged. But there are no exceptions logged. >> And stop_requested is NOT SET. (see the last line in the log). >> >> What is happening here? > > It was a bad assumption. Not all exceptions are subclasses of > "Exception". In this case, an inner call raised SystemExit(0). Glad to see you finally found what was happening! > So be aware. Don't think that this will catch all exceptions: > > try: > ??? > except Exception,e: > do_with(e) > > > Use this instead: > > import sys > try: > ??? > except: > e = sys.exc_value > do_with(e) Only at the outermost block on your code, if ever... The fact that some exceptions don't inherit from Exception is on purpose -- usually you *dont* want to catch (and swallow) SystemExit (nor KeyboardInterrupt, and a few more I think) -- Gabriel Genellina From gabriel.rossetti at arimaz.com Tue Feb 24 09:56:59 2009 From: gabriel.rossetti at arimaz.com (Gabriel Rossetti) Date: Tue, 24 Feb 2009 15:56:59 +0100 Subject: shared lib from python code? In-Reply-To: <89a1045472ca4ec4c07f26543032058e.squirrel@acooke.dyndns.org> References: <49A27608.3050403@arimaz.com> <49A28BD6.9040701@arimaz.com> <89a1045472ca4ec4c07f26543032058e.squirrel@acooke.dyndns.org> Message-ID: <49A40ABB.6090502@arimaz.com> andrew cooke wrote: > Gabriel Rossetti wrote: > >> Ok, maybe I mis-stated my problem (or mis-understood your answers).. I >> don' t want to share code as in have multiple processes access a >> variable and have the same value, like it is done in threads, what I >> want is to not have n copies of the code (classes, functions, etc) >> loaded by n python interpreters. When you load Apache for instance, it >> runs n processes but loads only one copy of parts of it's code (so/dll), >> that's what I want to do. In C/C++ I would write a shared-lib (so/dll), >> so once the system has loaded it, it doesn' t re-load it when another >> process needs it. >> > > i think i understand what you want. the problem is that the kind of > language that python is really doesn't work well with that kind of > approach. this is (and i may be wrong - i've not really thought much > about this before) largely because python places a very strong emphasis on > late binding. that means that everything is very flexible - all kinds of > things can be changed "under the hood". and that means that it is very > difficult to share things safely because almost any solution would end up > doing what you don't want (sharing variables, like with threads (even > though they are very deeply buried variables)) rather than what you do > want (just sharing the static part of the code to save space). > > another way to see this is to see the connection with security. this is > the flip side of your case - because things are so flexible it is very > hard to run some python code in a "sandbox" in a larger python program. > there's some discussion on the dev group at the moment and it looks like > the solution is to only use function closures. but even that doesn't work > without some patches that remove certain ways to dynamically alter the > code base. > > andrew > > Ok, I see, thank you. I thought this was possible since I have used *.pyd files before and from what I had read they were dynamic library files. I guess they must be written in C/C++ then. Thank you for the explanation. Gabriel From gabriel.rossetti at arimaz.com Tue Feb 24 09:58:54 2009 From: gabriel.rossetti at arimaz.com (Gabriel Rossetti) Date: Tue, 24 Feb 2009 15:58:54 +0100 Subject: shared lib from python code? In-Reply-To: References: <49A27608.3050403@arimaz.com> Message-ID: <49A40B2E.2010601@arimaz.com> Duncan Booth wrote: > Gabriel Rossetti wrote: > > >> Ok, maybe I mis-stated my problem (or mis-understood your answers).. I >> don' t want to share code as in have multiple processes access a >> variable and have the same value, like it is done in threads, what I >> want is to not have n copies of the code (classes, functions, etc) >> loaded by n python interpreters. When you load Apache for instance, it >> runs n processes but loads only one copy of parts of it's code (so/dll), >> that's what I want to do. In C/C++ I would write a shared-lib (so/dll), >> so once the system has loaded it, it doesn' t re-load it when another >> process needs it. >> >> > > It doesn't matter how you restate it, the answer is still the one Gabriel > Genellina gave you: Python code objects are not shared between processes. > > Ok, I had though that he had misunderstood me. > Code objects are immutable, but they are still objects like everything else > in Python. That means they are reference counted and discarded when no > longer referenced. > > To share code objects between different processes you would have to change > the reference counting mechanism so it was either safe across multiple > processes or didn't reference count shared code objects (but still ref > counted non-shared objects). > > The actual code is just stored in a string, so perhaps you could share > those strings between processes: just executing the code doesn't change the > string's refcount (whereas it does change the function and the code > objects' counts). You could probably make something work simply by editing > the code constructor to move the code into shared memory and using some > other mechanism to control the shared memory storage. > > Ok, thanks for the explanation. > C extension libraries on the other hand may be shared. > > Ok, so pyd files must be C extensions then. Thanks From nick_keighley_nospam at hotmail.com Tue Feb 24 10:00:41 2009 From: nick_keighley_nospam at hotmail.com (nick_keighley_nospam at hotmail.com) Date: Tue, 24 Feb 2009 07:00:41 -0800 (PST) Subject: reading file to list References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> Message-ID: On 17 Jan, 17:16, Xah Lee wrote: > comp.lang.lisp,comp.lang.scheme,comp.lang.functional,comp.lang.python,comp.?lang.ruby > > Here's a interesting toy problem posted by Drew Krause to > comp.lang.lisp: > > ------------------------ > On Jan 16, 2:29 pm, Drew Krause wrote [paraphrased a bit]: > > OK, I want to create a nested list in Lisp (always of only integers) > from a text file, such that each line in the text file would be > represented as a sublist in the 'imported' list. > > example of a file's content > > 3 10 2 > 4 1 > 11 18 > > example of programing behavior > (make-list-from-text "blob.txt") => ((3 10 2) (4 1) (11 18)) > > ----------------- > Here's a emacs lisp version: > > (defun read-lines (file) > "Return a list of lines in FILE." > (with-temp-buffer > (insert-file-contents file) > (split-string > (buffer-substring-no-properties 1 (point-max)) "\n" t) > ) > ) > > (defvar mylist '() "result list" ) > (setq mylist '()) ; init in case eval'd again > > (mapc > (lambda (x) (setq mylist > (cons (split-string x " ") mylist )) ) > (read-lines "xxblob.txt") > ) > > The above coding style is a typical maintainable elisp. > > In a show-off context, it can be reduced to by about 50%, but still > far verbose than ruby or say perl (which is 1 or 2 lines. (python > would be 3 or 5)). > > Note that the result element is string, not numbers. There's no easy > way to convert them on the fly. 3 or so more lines will be needed to > do that. > > The ?read-lines? function really should be a built-in part of elisp. > It is not so mostly because emacs people have drawn themselves into a > elitist corner, closing off to the outside world. (i am sending a > suggestion to the official emacs dev list on adding read-line now.) scheme: (define (read-line port) (define (rec-read-line port line) (define next-char (peek-char port)) (define number #f) (cond ((eof-object? next-char) '()) ((char=? next-char #\newline) (read-char port) line) ((char-numeric? next-char) (set! number (read port)) (cons number (rec-read-line port line))) ((char=? next-char #\space) (read-char port) (rec-read-line port line)) (else (error (string-append "bad character \"" (string next-char) "\""))) )) (rec-read-line port '()) ) (define (make-int-list port) (define line (read-line port)) (if (null? line) '() (cons line (make-int-list port)))) (define (make-list-from-text file) (make-int-list (open-input-file file))) > ----------------- > > w_a_x_... at yahoo.com gave a ruby solution: > > IO.readlines("blob.txt").map{|line| line.split } > > augumented by Jilliam James for result to be numbers: > > IO.readlines("blob.txt").map{|line| line.split.map{|s| s.to_i }} > > Very beautiful. > > ------------------- > > That's really the beauty of Ruby. > > This problem and ruby code illustrates 2 fundamental problems of lisp, > namely, the cons problem, and the nested syntax pain. Both of which > are practically unfixable. > > The lisp's cons fundamentally makes nested list a pain to work with. > Lisp's nested syntax makes functional sequencing cumbersome. > > In the ruby code, its post-fix sequential notation (as a side effect > of its OOP notation) brings out the beauty of functional sequencing > paradigm (sometimes known as functional chain, sequencing, filtering, > unix piping). > > its list, like all modern high level langs such as perl, php, python, > javascript, don't have the lisp's cons problem. The cons destroys the > usability of lists up-front, untill you have some at least 2 full-time > years of coding lisp to utilize cons properly. (and even after that, > it is still a pain to work with, and all you gain is a bit of speed > optimization in rare cases that requires largish data, most of which > has better solutions such as a database.) > > Both of these problems i've published articles on. > > For more detail on the cons problem, see > the section ?The Cons Business? at > > ? Fundamental Problems of Lisp > http://xahlee.org/UnixResource_dir/writ/lisp_problems.html > > For more detail on the nested syntax problem for function chaining, > see > the section ?How Purely Nested Notation Limits The Language's Utility? > at: > > ? The Concepts and Confusions of Prefix, Infix, Postfix and Fully > Nested Notations > http://xahlee.org/UnixResource_dir/writ/notations.html From digitig at gmail.com Tue Feb 24 10:11:46 2009 From: digitig at gmail.com (Tim Rowe) Date: Tue, 24 Feb 2009 15:11:46 +0000 Subject: Newby - is this what they are looking for ?? and is their a better a way In-Reply-To: <8C52BE9109254380A7EB5B082D23DB6B@Woodygar> References: <8C52BE9109254380A7EB5B082D23DB6B@Woodygar> Message-ID: You're doing well so far. As Chris has said, you need to read the later part of the question more carefully. A couple of other things: 1. 'input' might not be the best way to get the phrase, because the user will have to put the phrase in quotes or the program will (probably) crash. Have a look at raw_input. 2. A cosmetic thing. Your users will be happier if you put a space after 'enter a phrase' 3. A "better way" might not be a better way for you. There's a very Pythonic way of doing this using something called list comprehensions, but they're almost certainly not what your tutor wants because they're rather more advanced than the level you're working at. If it wasn't for the requirement to put the acronym into the variable "letters", the whole task could be done in one Python statement. Don't try that. Keep it simple, the way you have been so far. 4. If you want to be a wise guy, ask your tutor why he/she got you to convert the whole phrase to upper case, wasting a whole pile of character conversion operations under the hood, because it's only the acronym that needs to be converted :-) -- Tim Rowe From tracyde at gmail.com Tue Feb 24 10:19:07 2009 From: tracyde at gmail.com (Derek Tracy) Date: Tue, 24 Feb 2009 10:19:07 -0500 Subject: Unix Change Passwd Python CGI Message-ID: <9999810b0902240719y750fba0dp43a87a9d840ff949@mail.gmail.com> I am using python version 2.5.1 and need to create a python cgi application to allow a user to change their unix password. Apache is running on the same system that needs the password changed. I need to keep security high and can not install additional modules at this time. I just need a general direction to start looking, and I do not have expect installed on the system. Any ideas would be wonderful! R/S -- --------------------------------- Derek Tracy tracyde at gmail.com --------------------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: From invalid at invalid Tue Feb 24 10:38:11 2009 From: invalid at invalid (Grant Edwards) Date: Tue, 24 Feb 2009 09:38:11 -0600 Subject: try except question - serious foo bar question, and pulling my hair out :-) References: <49A3D881.4070500@shopzeus.com> <49A3E736.2020702@shopzeus.com> <49A3E943.3010405@shopzeus.com> Message-ID: <6O2dnRdfEoj-iTnUnZ2dnUVZ_tbinZ2d@posted.visi> On 2009-02-24, Steve Holden wrote: >> However, this cannot happen. This application is running >> multiple threads (10+) and every thread monitors the global >> "stop_requested" flag. If there was an unexpected error in the >> service, stop_requested.set() is called. It will stop all >> threads and exit the process. stop_requested.clear() is NEVER >> called, so the while loop should have not been ended. So what >> is happening here? It drives me crazy. > > Time to get a stuffed toy and go through your code, explaining > to the toy exactly why your code is right and nothing can go > wrong. With luck, within half an hour you will realize what > you are doing wrong ... It works with a person as well as stuffed toys -- but trying to order a person on the internet gets you in a lot more trouble. It's also a little more embarassing when you realize your mistake in front of a person. OTOH, sometimes a person will ask an enlightening question; but, sometimes they just make unhelpfull wisecracks. It's a tough choice. -- Grant Edwards grante Yow! OVER the underpass! at UNDER the overpass! visi.com Around the FUTURE and BEYOND REPAIR!! From gandalf at shopzeus.com Tue Feb 24 10:45:13 2009 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 24 Feb 2009 16:45:13 +0100 Subject: try except question - serious foo bar question, and pulling my hair out :-) In-Reply-To: References: <49A3D881.4070500@shopzeus.com> <49A3F198.4030208@shopzeus.com> Message-ID: <49A41609.6090904@shopzeus.com> >> >> Use this instead: >> >> import sys >> try: >> ??? >> except: >> e = sys.exc_value >> do_with(e) > > Only at the outermost block on your code, if ever... The fact that > some exceptions don't inherit from Exception is on purpose -- usually > you *dont* want to catch (and swallow) SystemExit (nor > KeyboardInterrupt, and a few more I think) > Yes, this was at the outermost block of my thread's run method. SystemExit exception did not generate an "exception in Thread-32" type traceback on stderr because for Python, it seemed to be a "normal" exit of the thread. So I wrote an except block, to see why the thread has been stopping. In this case, catching SystemExit was desired. The problem was in my mind: I thought that "except Exception,e:" will catch everything. The solution was to replace "raise SystemExit(0)" with "raise TransportClosedException()" in another class. Thanks again, Laszlo From __peter__ at web.de Tue Feb 24 10:50:17 2009 From: __peter__ at web.de (Peter Otten) Date: Tue, 24 Feb 2009 16:50:17 +0100 Subject: Newby - is this what they are looking for ?? and is their a better a way References: <8C52BE9109254380A7EB5B082D23DB6B@Woodygar> Message-ID: Tim Rowe wrote: > 1. 'input' might not be the best way to get the phrase, because the > user will have to put the phrase in quotes or the program will > (probably) crash. Have a look at raw_input. Gary is using Python 3 where input() works like the raw_input() of yore. The giveaway is > print(word, end='') Peter From R.Brodie at rl.ac.uk Tue Feb 24 11:04:54 2009 From: R.Brodie at rl.ac.uk (Richard Brodie) Date: Tue, 24 Feb 2009 16:04:54 -0000 Subject: Python AppStore / Marketplace References: <49A311C3.80707@gmail.com> Message-ID: "Rhodri James" wrote in message news:mailman.615.1235436896.11746.python-list at python.org... > A souq is a bazaar :-) > Maybe I've just read too much arabic-themed fiction, but I was surprised not > to find the word in my trusty Chambers. Try under 'souk'. Transliterating to the Roman 'q' seems to have become popular relatively recently. From kyosohma at gmail.com Tue Feb 24 11:05:06 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Tue, 24 Feb 2009 08:05:06 -0800 (PST) Subject: March 2, 2009 Pyowa Meeting Message-ID: <02f0bb8f-4357-43ea-8f32-da3835ea3c43@f11g2000vbf.googlegroups.com> Hi, Just a quick note to say that our next Pyowa (Python Users Group of Iowa) meeting will be next Monday, March 2nd from 7-9 p.m. We will be in our original location at the Marshall County Sheriff's Office, 2369 Jessup Ave, Marshalltown, IA. Remember, it's technically NOT in Marshalltown at all. It's actually about 7 miles to the West of Marshalltown. Keep an eye on our website (www.pyowa.org) for updates and/or cancellations should the weather turn bad. We are currently going to have a presentation featuring real-life programs/scripts to give our members an idea of what Python is used for on a day-to-day basis. We'll probably open it up to the audience to see if they have anything to add. We are also hoping to have a presentation on some basic GIS scripts, but this is rather tentative. Regardless, there will be free drinks provided (pop / water). Let me know if you can make it! Mike From kraranke at gmail.com Tue Feb 24 11:42:47 2009 From: kraranke at gmail.com (kshitij) Date: Tue, 24 Feb 2009 08:42:47 -0800 (PST) Subject: thanks very much indeed for your help is there a better way to do this (python3) newby References: Message-ID: <998cde7c-07ab-4400-b36e-904640e1c2a1@e24g2000vbe.googlegroups.com> On Feb 24, 6:29?am, "Rhodri James" wrote: > On Mon, 23 Feb 2009 23:33:31 -0000, Gary Wood wrote: > > '''exercise to complete and test this function''' > > import string > > def joinStrings(items): > > ? ? '''Join all the strings in stringList into one string, > > ? ? and return the result. For example: > > ? ? >>> print joinStrings(['very', 'hot', 'day']) > > ? ? 'veryhotday' > > ? ? ''' > > ? ? for i in items: > > ? ? ? ?return (''.join(items)) > > As I'm sure your teacher will point out, this is sub-optimal :-) > That for-loop isn't doing anything, because you always return > out of it at the first iteration. > > I suspect that you're expected to concatenate the strings > together by hand and return the resulting string once you've > done them all. ?Trying writing it that way. > > PS: it helps a lot if what you say in the doc string matches > what you write in the rest of the code. ?In this case you > call your input string "items", but then say "Join all the > strings in *stringList*..." > > -- > Rhodri James *-* Wildebeeste Herder to the Masses Here is another way of doing this: print ('very' + 'hot' + 'day') Hope this helps. From see.signature at no.spam Tue Feb 24 11:52:42 2009 From: see.signature at no.spam (Eric Brunel) Date: Tue, 24 Feb 2009 17:52:42 +0100 Subject: tkinter icons as bytestrings, not files? References: Message-ID: On Tue, 24 Feb 2009 05:56:12 +0100, Peter Billam wrote: > Greetings, > > As a newbie, starting with Python3, I'm working my way through Mark > Summerfield's tkinter examples. In the toolbar, there's lines like: > for image, command in ( > ('images/filenew.gif', self.fileNew), > ('images/fileopen.gif', self.fileOpen), > ('images/filesave.gif', self.fileSave), > ('images/editadd.gif', self.editAdd), > ('images/editedit.gif', self.editEdit), > ('images/editdelete.gif', self.editDelete),): > image = os.path.join(os.path.dirname(__file__), image) > image = tkinter.PhotoImage(file=image) > self.toolbar_images.append(image) > button = tkinter.Button(toolbar, image=image, command=command) > button.grid(row=0, column=len(self.toolbar_images) -1) > > which are always failing because the icons are in the wrong place > and I can't help but wonder if I can put all these little images > in the application itself, either as b'whatever' or uuencoded or > in svg etc, and then invoke some suitable variation of the > image = tkinter.PhotoImage(file=image) > or of the > button = tkinter.Button(toolbar, image=image, command=command) > command ? (I did try help('tkinter.PhotoImage') but didn't spot a > magic key (unless it's "data=something, format=something")) ... Just dump the contents of the file as a bytestring and use: image = PhotoImage(data=the_byte_string) With no extension, I guess it'll only work with GIF files, as it is the only natively supported image format in tcl/tk (AFAIK...). HTH -- python -c "print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])" From adleslie at gmail.com Tue Feb 24 12:27:31 2009 From: adleslie at gmail.com (May) Date: Tue, 24 Feb 2009 09:27:31 -0800 (PST) Subject: python sql query in django References: <9c401cce-88c3-48b1-a6a5-288d2b897ba3@v19g2000yqn.googlegroups.com> <49a3071a$0$18735$426a34cc@news.free.fr> <49a31936$0$24803$426a74cc@news.free.fr> Message-ID: On Feb 23, 12:48?pm, Bruno Desthuilliers wrote: > May a ?crit : > (snip) > > > I may not stay with Django. > > Nope, but your question was about Django. > > > I am seriously looking for whether python > > can read data from a relational database > > Of course - as long as there's a Python adapter for your DB. > > > and send to an html template > > Of course - as long as it's either a Python templating system or there's > a Python binding for this system. > > > or do I always need some kind of wrapper/interface such as Rails > > Uh ? Rails is a Ruby framework. > > > or > > Django? ? > > No, you don't. If you prefer to reinvent the wheel on each and any part > of each an any web app you write, please feel free to do so. > > > If this is the wrong group to ask that question > > Which "that" question ?-) > > For question related to Django's ORM, the django group is indeed a > better place (as usual: always use the most specific group / maling list > / whatever first). If you have questions (like the above) that are about > Python itself, you're at the right place. Thanks for all your suggestions. From what I've experienced in Django and now that I know a little more about how Python functions, I will probably use a combination of PHP and Django, instead of trying to get Python to do the web portion of my project. Thanks again! From nick at craig-wood.com Tue Feb 24 12:31:53 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Tue, 24 Feb 2009 11:31:53 -0600 Subject: Extending Python Questions ..... References: <7e1a6ec9-8457-40ef-a3da-a16b5dac1100@r34g2000vbp.googlegroups.com> Message-ID: Ben wrote: > No, It uses the the S-lang for video, and input control. However, SLAG > is more of an abstract layer on top of that. > > It has a Structures that contains menus and screens (menumodule / > screenmodule). One LOADS them up with parameters. such as creating > a new menu is like: > > OpenMenu( Company name, SubSystem, this program name, mode, bottom > status display) - Create initial menu structure Addtomenu(Menu > Block Set name, DISPLAY line, ID, type of program, password ID ) - > add to / update MENU blocks. runMenu() - Displays the whole create > menu structure. > > The Menu structure is done in pull downs and scrollable blocks in a > TUI (text User Interface) and using the S-lang screen library is > fully mouseable. > > The screen module works mych the same way, but with the abiltity to > open and close and work within "Sub Screens". > > For those who do not know, S-lang is a interpreted language much > like Python. However, there is s direth of library modules. The > original S-lang started out as library of screen of keyboard > modules, but has been expanded > > My SLAG project does not care in reality WHICH or what language, it > is simply handling menu and screen control. So do you want to embed python into your code? I'm still not clear what you are trying to achieve with python, though I have a better idea what SLAG is now! -- Nick Craig-Wood -- http://www.craig-wood.com/nick From traversos at gmail.com Tue Feb 24 12:34:59 2009 From: traversos at gmail.com (Dario Traverso) Date: Tue, 24 Feb 2009 12:34:59 -0500 Subject: Python Image Library IOError - cannot find JPEG decoder? Message-ID: <8117677E-D022-41A3-A730-8AD76AE0F2A3@gmail.com> I've been trying to install the Python Image Library (PIL) on my Mac OSX Leopard laptop, but have been running into some difficulties. I've built the library, using the included setup.py script. The build summary checks out ok, and sounds the option libraries to all be found. I grabbed both libjpeg and freetype2 using fink. -------------------------------------------------------------------- PIL 1.1.6 BUILD SUMMARY -------------------------------------------------------------------- version 1.1.6 platform darwin 2.5.1 (r251:54863, Jan 13 2009, 10:26:13) [GCC 4.0.1 (Apple Inc. build 5465)] -------------------------------------------------------------------- --- TKINTER support ok --- JPEG support ok --- ZLIB (PNG/ZIP) support ok --- FREETYPE2 support ok -------------------------------------------------------------------- However, I then run the included self test, and 1 out of 57 tests fails. I receive an IOError. Specifically: ***************************************************************** Failure in example: _info(Image.open("Images/lena.jpg")) from line #24 of selftest.testimage Exception raised: Traceback (most recent call last): File "./doctest.py", line 499, in _run_examples_inner exec compile(source, "", "single") in globs File "", line 1, in File "./selftest.py", line 22, in _info im.load() File "PIL/ImageFile.py", line 180, in load d = Image._getdecoder(self.mode, d, a, self.decoderconfig) File "PIL/Image.py", line 375, in _getdecoder raise IOError("decoder %s not available" % decoder_name) IOError: decoder jpeg not available 1 items had failures: 1 of 57 in selftest.testimage ***Test Failed*** 1 failures. *** 1 tests of 57 failed. I've followed all of the installation instructions exactly. The build summary reported everything was "ok". What could be the problem here. Libjpeg-6b is not accessible? Thank you for any insight you can provide!! -Dario From paul at boddie.org.uk Tue Feb 24 12:39:44 2009 From: paul at boddie.org.uk (Paul Boddie) Date: Tue, 24 Feb 2009 09:39:44 -0800 (PST) Subject: Python AppStore / Marketplace References: Message-ID: <2ed478dd-0c85-4dc4-befe-478974669821@u1g2000vbb.googlegroups.com> On 22 Feb, 12:24, Marcel Luethi wrote: > > Using my iPhone I suddenly realize how easy it is to find applications > in Apple's AppStore. How easy and fast it is to install or de-install > an app. My iPhone even checks in the background if there is an upgrade > which could be installed painlessly. Yes, but this is just one platform. Can you download these iPhone applications onto Android devices and use them? How would you package your Objective-C (or whatever Apple has mandated) software for Android or Debian or anything else out there? > Then I see VMware's Virtual Appliance Marketplace, where you can > download already pre-configured "appliances" for all kind of stuff. > You can even download a basic appliance, install and configure your > servers and tools - and upload it again, so that others can profit of > your work. > > Unfortunately there's nothing like this in the Python world... That's because you first wrote about platform-specific packaging and now you're writing about language-specific packaging. And it's not as if the former area hasn't been well addressed by Free Software, either, but I suppose that's another discussion to be had. > My idea: what about having a beefed up Cheeseshop for Python apps and > an accompanying client app kind of iTunes for Python apps? > > The server side could be easily implemented with any of the current > web frameworks. It's simply a management platform for the app packages > (descriptions, versions, platforms, licenses, user's comments, number > of downloads, ...) and the package files themselves. > It should be definitely hosted by the PSF I think. Well, what you're proposing risks exactly the same problems that many other language-specific packaging solutions suffer from: it starts off with specifying platforms, dependencies (which you didn't mention), download files, and ends up with the user downloading huge amounts of stuff that may already be on their system, mostly because such solutions assume that the system doesn't really know anything about what's already installed. Consequences of this may include a lack of decent system-related tools to manage the result of installing stuff: it would be like your iPhone application being installable on Android by being dumped into the filesystem with little regard for existing content and with no obvious strategy for safely removing the application later. It's true that there are other application repositories similar to the VMware service you mention which don't really care about dependencies and just offer self-contained applications for reasons of catering to the lowest common denominator, and perhaps there's a desire to have such services out there, but then again, doing such stuff specifically for Python will lead you into making self-contained applications using those "installer" technologies, or at least mapping and providing non- Python library dependencies across multiple platforms. Or you could just make it easier for Python projects to provide self-contained applications based on VMware or Free Software alternatives - at least that would allow you to focus on one platform, although the result wouldn't be regarded as a "fully integrated" cross-platform approach because a virtual machine would be involved. > The multi-platform client should be intuitively and elegantly allow > app browsing, downloading and installing those Python apps. In that > respect it is sort of a Linux package manager (Synaptic, YUM, ...). Why wouldn't you make use of existing system package management, then? > But this is only the end-user related stuff. Furthermore it should > allow to create new apps (probably based on a previously downloaded > base app), package and upload them again (kind of Google AppEngine > Launcher). Those base packages should include some basic management > framework (for installation and configuration) and hopefully soon > after the release of this platform they will be created in a broad > variety to allow app developers to choose among many Python-version/ > platform/GUI/...-combinations. Well, system packages of Python software typically make some use of distutils to put files in the right places before bundling those files together. The resulting system packages then work within a "basic management framework", although I accept that there typically isn't much support for trivial repackaging, although it isn't that difficult to repackage, say, a Debian package and to publish it in your own repository. > IMHO an architecture like this would greatly enhance the productivity > of the whole Python community by capitalizing the knowledge of many > Python specialists. I don't have to find/install/configure all the > basic stuff myself (see above) to build my app. But I can concentrate > on my app because I'm standing on the shoulders of giants. It isn't hard to find/install/configure the basic stuff in most GNU/ Linux distributions, either. > I believe it also would make Python as a great platform more visible > to the world - because there is only one place you have to go... > > What do you think??? > Is this crazy??? Or simply stupid? > Or is this the way to world domination...? ;-) Some people - usually Windows users - seem to like the idea of a Python-specific solution, whereas others look to be able to administer packages of many different kinds of software on their own system, and in some environments people look to be able to administer packages for many different kinds of system, at which point the Python-specific interest becomes very small indeed. Generally, one has to choose one of these levels and work mostly at that level when dealing with packages, and I would argue that the best level is that of the system, making language-specific solutions fit inside the facilities (and restrictions) of the framework provided at the system level. I think there is some merit in allowing people with a Python interest to follow new developments (as can be done somewhat with the Package Index) and for references to system-specific packages to be incorporated into such a service. At one point I started writing a Web application to do this, but instead of focusing on manual editing of package details, it would be better to link the package records to other services which make the actual system packages available. There could also be unofficial build systems which provide such system packages ahead of the usual operating system distribution release schedule that people often complain about (in that they don't get the latest stuff quickly enough). For example, you'd have a package record like this: Name: XYZ Platforms: Debian: http://debian.package.server/python-xyz Windows: http://windows.package.server/python-xyz Maybe you'd delegate the versioning and architecture availability to the specific platforms. > Unfortunately I'm not expert enough to build such a system - but if > there is enough interest in the community I gladly would like to help. There is ongoing work on packaging-related matters. Perhaps you should subscribe to the catalog-sig or distutils-sig mailing lists (see mail.python.org for details). That said, I'm skeptical about language- specific packaging precisely because of the reasons given above, and to make my own Python libraries and applications work within the Debian mechanisms is something I've learned to do. Since that is all that really matters to me, I don't see that much benefit in learning something more sophisticated for Python which does less in my own environment, which I consider to be the operating system and not the language technology. Paul From digitig at gmail.com Tue Feb 24 12:42:10 2009 From: digitig at gmail.com (Tim Rowe) Date: Tue, 24 Feb 2009 17:42:10 +0000 Subject: try except question - serious foo bar question, and pulling my hair out :-) In-Reply-To: <6O2dnRdfEoj-iTnUnZ2dnUVZ_tbinZ2d@posted.visi> References: <49A3D881.4070500@shopzeus.com> <49A3E736.2020702@shopzeus.com> <49A3E943.3010405@shopzeus.com> <6O2dnRdfEoj-iTnUnZ2dnUVZ_tbinZ2d@posted.visi> Message-ID: 2009/2/24 Grant Edwards : > It works with a person as well as stuffed toys -- but trying to > order a person on the internet gets you in a lot more trouble. > It's also a little more embarassing when you realize your > mistake in front of a person. ?OTOH, sometimes a person will > ask an enlightening question; but, sometimes they just make > unhelpfull wisecracks. ?It's a tough choice. I used to use a baby, which avoids the embarrassment but can be just as problematic to order on the internet. -- Tim Rowe From nytrokiss at gmail.com Tue Feb 24 12:45:44 2009 From: nytrokiss at gmail.com (James Matthews) Date: Tue, 24 Feb 2009 19:45:44 +0200 Subject: Unix Change Passwd Python CGI In-Reply-To: <9999810b0902240719y750fba0dp43a87a9d840ff949@mail.gmail.com> References: <9999810b0902240719y750fba0dp43a87a9d840ff949@mail.gmail.com> Message-ID: <8a6b8e350902240945q3676adefjab2163ea8fdb8407@mail.gmail.com> IMHO That sounds like the biggest security hole I can think of. Anyways you can open a pipe to passwd. to have the change there password. James On Tue, Feb 24, 2009 at 5:19 PM, Derek Tracy wrote: > I am using python version 2.5.1 and need to create a python cgi application > to allow a user to change their unix password. > > Apache is running on the same system that needs the password changed. I > need to keep security high and can not install additional modules at this > time. > > I just need a general direction to start looking, and I do not have expect > installed on the system. > > Any ideas would be wonderful! > > R/S -- > --------------------------------- > Derek Tracy > tracyde at gmail.com > --------------------------------- > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- http://www.goldwatches.com/ http://www.jewelerslounge.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From mathieu.malaterre at gmail.com Tue Feb 24 12:48:56 2009 From: mathieu.malaterre at gmail.com (mathieu) Date: Tue, 24 Feb 2009 09:48:56 -0800 (PST) Subject: =?windows-1252?B?J3UnIAlPYnNlbGV0ZSB0eXBlIJYgaXQgaXMgaWRlbnRpY2FsIHRvICdkJy4gCSg3KQ==?= Message-ID: I did not know where to report that: 'u' Obselete type ? it is identical to 'd'. (7) http://docs.python.org/library/stdtypes.html#string-formatting Thanks From blogger at ferg.org Tue Feb 24 13:09:52 2009 From: blogger at ferg.org (blogger at ferg.org) Date: Tue, 24 Feb 2009 10:09:52 -0800 (PST) Subject: Python 3 and easygui problem References: <49A0D88F.4010806@internode.on.net> Message-ID: <45725a69-d020-41e1-a159-3fa16a14a555@17g2000vbf.googlegroups.com> Thanks to all for helping Peter on this. Just a bit of an update... The solution offered in this thread to Peter's original problem is the same as the once I arrived at. There is a bit of discussion about it here: http://pythonconquerstheuniverse.blogspot.com/2009/01/moving-to-python-30-part1.html The current version of EasyGui doesn't run under 3.0, but Peter and I are in contact and we're working on a version that will. (No estimated availablity date yet.) EasyGui is not in PyPI. A semi-significant revision of EasyGui is in the works (no predicted availablity date yet). Once that revision is out the door, I'll look into putting EasyGui into PyPI. Again, thanks to all who participated in this thread. -- Steve Ferg From deets at nospam.web.de Tue Feb 24 13:36:28 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 24 Feb 2009 19:36:28 +0100 Subject: python sql query in django In-Reply-To: References: <9c401cce-88c3-48b1-a6a5-288d2b897ba3@v19g2000yqn.googlegroups.com> <49a3071a$0$18735$426a34cc@news.free.fr> <49a31936$0$24803$426a74cc@news.free.fr> Message-ID: <70it1cF95tgfU1@mid.uni-berlin.de> > > Thanks for all your suggestions. From what I've experienced in Django > and now that I know a little more about how Python functions, I will > probably use a combination of PHP and Django, instead of trying to get > Python to do the web portion of my project. Thanks again! That sounds like the worst idea. Django's ORM is good when used from within django, because of all the additional goodies like the admin interface. But if you are going to do the webfrontend using PHP, what part is left for django? If it's only the ORM (for whatever you still use that anyway), there are better alternatives - SQLAlchemy, and SQLObject, for Python. They are more powerful and not interwoven with django. If you are going to hand-code the interface in PHP, I fail to see though why you don't do that in Django directly. You are not forced to use the Admin-interface. Diez From mobiledreamers at gmail.com Tue Feb 24 13:53:29 2009 From: mobiledreamers at gmail.com (mobiledreamers at gmail.com) Date: Tue, 24 Feb 2009 10:53:29 -0800 Subject: Accessing callers context from callee method Message-ID: when i call a method foo from another method func. can i access func context variables or locals() from foo so def func(): i=10 foo() in foo, can i access func's local variables on in this case i Thanks a lot -- Bidegg worlds best auction site http://bidegg.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From R.Bauer at fz-juelich.de Tue Feb 24 13:53:43 2009 From: R.Bauer at fz-juelich.de (Reimar Bauer) Date: Tue, 24 Feb 2009 19:53:43 +0100 Subject: pdftk Message-ID: Hi Does one know about a python interface to pdftk? Or something similar which can be used to fill a form by fdf data. cheers Reimar From clp2 at rebertia.com Tue Feb 24 13:56:36 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 24 Feb 2009 10:56:36 -0800 Subject: Accessing callers context from callee method In-Reply-To: References: Message-ID: <50697b2c0902241056h14e92b8cu3ea2270d3c1b5bd3@mail.gmail.com> On Tue, Feb 24, 2009 at 10:53 AM, wrote: > when i call a method foo from another method func.?can i access func context > variables or locals() from foo > so > def func(): > ??i=10 > ??foo() > > in foo, can i access func's local variables on in this case i You can, but it's an evil hack that I would avoid if at all possible; there are almost certainly better ways to accomplish whatever your goal is. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From zaheer.agadi at gmail.com Tue Feb 24 14:05:26 2009 From: zaheer.agadi at gmail.com (zaheer.agadi at gmail.com) Date: Tue, 24 Feb 2009 11:05:26 -0800 (PST) Subject: Is there any equivalent feature available in Python..? Message-ID: <54d72142-963e-4be3-b11e-7b15c6a2ee58@m24g2000vbp.googlegroups.com> Hi, Is there any Python equivalent of java jar,can I include all my sources,properties file etc into a single file.Is there anyway in Python that I can run like the following java -jar Mytest.jar --startwebserver How to so something like this in Python? Thanks From ajaksu at gmail.com Tue Feb 24 14:12:42 2009 From: ajaksu at gmail.com (ajaksu) Date: Tue, 24 Feb 2009 11:12:42 -0800 (PST) Subject: Python AppStore / Marketplace References: Message-ID: Steve Holden wrote: > And the "multiplatform client" that should "easily and elegantly allow > app browsing, downloading and installing those apps" would presumably > have to account for the many differences in package formats and install > requirements between the different platforms. And then you'd also need to re-download the app if you need it on a (sometimes slightly) different platform. Unless the Souq can beat Apple in its own game, by offering Multiversal Binaries that work across hardware platforms, OSes and their versions, GUI frameworks, Python versions and universes. Settling for Downright Obese Binaries if supporting different universes is considered overkill would be OK too. shoulda-include-a-single-asset-8-by-8-shotgun-cross-compiler-ly y'rs Daniel From clp2 at rebertia.com Tue Feb 24 14:15:50 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 24 Feb 2009 11:15:50 -0800 Subject: Is there any equivalent feature available in Python..? In-Reply-To: <54d72142-963e-4be3-b11e-7b15c6a2ee58@m24g2000vbp.googlegroups.com> References: <54d72142-963e-4be3-b11e-7b15c6a2ee58@m24g2000vbp.googlegroups.com> Message-ID: <50697b2c0902241115q24a85659le2580a4b36d7a59c@mail.gmail.com> On Tue, Feb 24, 2009 at 11:05 AM, wrote: > Hi, > > Is there any Python equivalent of java jar,can I include all my > sources,properties file etc into a single file.Is there anyway in > Python that I can run like the following > > java ?-jar Mytest.jar --startwebserver > > How to so something like this in Python? It's mostly possible. See http://docs.python.org/library/zipimport.html Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From tjreedy at udel.edu Tue Feb 24 14:19:54 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 24 Feb 2009 14:19:54 -0500 Subject: shared lib from python code? In-Reply-To: <49A40ABB.6090502@arimaz.com> References: <49A27608.3050403@arimaz.com> <49A28BD6.9040701@arimaz.com> <89a1045472ca4ec4c07f26543032058e.squirrel@acooke.dyndns.org> <49A40ABB.6090502@arimaz.com> Message-ID: Gabriel Rossetti wrote: > Ok, I see, thank you. I thought this was possible since I have used > *.pyd files before and from what I had read they were dynamic library > files. I guess they must be written in C/C++ then. Thank you for the > explanation. Yes, that can be confusing. Unlike .py, .pyc, .pyo, a .pyd is a Windows-only version of a .dll that is called .pyd instead of .dll for technical reasons I have forgotten. The difference is not directly relevant to *Python* programming. From kyosohma at gmail.com Tue Feb 24 14:19:55 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Tue, 24 Feb 2009 11:19:55 -0800 (PST) Subject: Extending Python Questions ..... References: <7e1a6ec9-8457-40ef-a3da-a16b5dac1100@r34g2000vbp.googlegroups.com> Message-ID: <1ac16d2b-d189-4fca-8a3a-ff45636f118a@s36g2000vbp.googlegroups.com> On Feb 24, 11:31?am, Nick Craig-Wood wrote: > Ben wrote: > > ?No, It uses the the S-lang for video, and input control. However, SLAG > > ?is more of an abstract layer on top of that. > > > ?It has a Structures that contains menus and screens (menumodule / > > ?screenmodule). One LOADS them up with parameters. ?such as creating > > ?a new menu is like: > > > ?OpenMenu( Company name, SubSystem, this program name, mode, bottom > > ?status display) - Create initial menu structure Addtomenu(Menu > > ?Block Set name, DISPLAY line, ID, type of program, password ID ) - > > ?add to / update MENU blocks. ?runMenu() - Displays the whole create > > ?menu structure. > > > ?The Menu structure is done in pull downs and scrollable blocks in a > > ?TUI (text User Interface) and using the S-lang screen library is > > ?fully mouseable. > > > ?The screen module works mych the same way, but with the abiltity to > > ?open and close and work within "Sub Screens". > > > ?For those who do not know, S-lang is a interpreted language much > > ?like Python. However, there is s direth of library modules. The > > ?original S-lang started out as library of screen of keyboard > > ?modules, but has been expanded > > > ?My SLAG project does not care in reality WHICH or what language, it > > ?is simply handling menu and screen control. > > So do you want to embed python into your code? > > I'm still not clear what you are trying to achieve with python, though > I have a better idea what SLAG is now! > > -- > Nick Craig-Wood --http://www.craig-wood.com/nick Maybe he wants SendKeys? Here's the link just in case: http://pypi.python.org/pypi/SendKeys/0.3 Mike From madhav.bnk at gmail.com Tue Feb 24 14:38:27 2009 From: madhav.bnk at gmail.com (madhav) Date: Tue, 24 Feb 2009 11:38:27 -0800 (PST) Subject: Run a linux system command as a superuser, using a python script Message-ID: I have got postfix installed on my machine and I am updating on of its configuration files programmatically(using python)(on some action). Since any change in the configuration needs a reload, I need to reload postfix to reflect the latest change. How can I do that in a python script. Precisely, I have something like this: import subprocess subprocess.Popen('sudo /etc/init.d/postifx reload') Since this script should be run in no-human environment(on the fly), I cant supply the sudo password or even root password(if needed). Even sudo doesn't have a flag to input the password for the command at the first shot. How do I do this? From clp2 at rebertia.com Tue Feb 24 14:44:16 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 24 Feb 2009 11:44:16 -0800 Subject: Run a linux system command as a superuser, using a python script In-Reply-To: References: Message-ID: <50697b2c0902241144x1652f4cdl85e3fe4c61338c61@mail.gmail.com> On Tue, Feb 24, 2009 at 11:38 AM, madhav wrote: > I have got postfix installed on my machine and I am updating on of its > configuration files programmatically(using python)(on some action). > Since any change in the configuration needs a reload, I need to reload > postfix to reflect the latest change. How can I do that in a python > script. Precisely, I have something like this: > > import subprocess > subprocess.Popen('sudo /etc/init.d/postifx reload') > > Since this script should be run in no-human environment(on the fly), I > cant supply the sudo password or even root password(if needed). Even > sudo doesn't have a flag to input the password for the command at the > first shot. How do I do this? pexpect may be useful in this situation - http://www.noah.org/wiki/Pexpect Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From wescpy at gmail.com Tue Feb 24 14:59:03 2009 From: wescpy at gmail.com (wesley chun) Date: Tue, 24 Feb 2009 11:59:03 -0800 Subject: [Tutor] Accessing callers context from callee method In-Reply-To: References: Message-ID: <78b3a9580902241159g3add4898na23151ebe6c0f987@mail.gmail.com> > when i call a method foo from another method func.?can i access func context > variables or locals() from foo > so > def func(): > ??i=10 > ??foo() > > in foo, can i access func's local variables A. python has statically-nested scoping, so you can do it as long as you: 1. define foo() as an inner function -- its def is contained within func()'s def: def func(): i = 10 def foo(): print i 2. you don't define a variable with the same name locally. in other words, you do have access to func()'s 'i' as long as you don't create another 'i' within foo() -- if you do, only your new local 'i' will be within your scope. B. another alterative is to pass in all of func()'s local variables to foo(): foo(**locals()) this will require you to accept the incoming dictionary in foo() and access the variables from it instead of having them be in foo()'s scope. C. in a related note, your question is similar to that of global vs. local variables. inside a function, you have access to the global as long as you don't define a local using the same name. should you only wish to manipulate the global one, i.e. assign a new value to it instead of creating a new local variable with that name, you would need to use the "global" keyword to specify that you only desire to use and update the global one. i = 0 def func(): i = 10 in this example, the local 'i' in func() hides access to the global 'i'. in the next code snippet, you state you only want to access/update the global 'i'... IOW, don't create a local one: i = 0 def func(): global i i = 10 D. this doesn't work well for inner functions yet: i = 0 def func(): i = 10 def foo(): i = 20 the 'i' in foo() shadows/hides access to func()'s 'i' as well as the global 'i'. if you issue the 'global' keyword, that only gives you access to the global one: i = 0 def func(): i = 10 def foo(): global i i = 20 you cannot get access to func()'s 'i' in this case. E. however, starting in Python 3.x, you'll be able to do somewhat better with the new 'nonlocal' keyword: i = 0 print('globally, i ==', i) def func(): i = 10 print('in func(), i ==', i) def foo(): nonlocal i i = 20 print('in foo(), i ==', i) foo() print('in func() after calling foo(), i ==', i) func() in this case, foo() modified func()'s 'i'. hope this helps! -- wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Core Python Programming", Prentice Hall, (c)2007,2001 "Python Fundamentals", Prentice Hall, (c)2009 http://corepython.com wesley.j.chun :: wescpy-at-gmail.com python training and technical consulting cyberweb.consulting : silicon valley, ca http://cyberwebconsulting.com From marduk at letterboxes.org Tue Feb 24 15:10:47 2009 From: marduk at letterboxes.org (Albert Hopkins) Date: Tue, 24 Feb 2009 15:10:47 -0500 Subject: Is there any equivalent feature available in Python..? In-Reply-To: <54d72142-963e-4be3-b11e-7b15c6a2ee58@m24g2000vbp.googlegroups.com> References: <54d72142-963e-4be3-b11e-7b15c6a2ee58@m24g2000vbp.googlegroups.com> Message-ID: <1235506247.13502.8.camel@centar.nbk> On Tue, 2009-02-24 at 11:05 -0800, zaheer.agadi at gmail.com wrote: > Hi, > > Is there any Python equivalent of java jar,can I include all my > sources,properties file etc into a single file.Is there anyway in > Python that I can run like the following > > java -jar Mytest.jar --startwebserver > > How to so something like this in Python? Similar but not equal: $ tree mytest mytest |-- __init__.py `-- main.py $ cat mytest/__init__.py if __name__ == '__main__': import sys print sys.argv import mytest.main $ cat mytest/main.py print 'hi mom' $ zip -r mytest.zip mytest adding: mytest/ (stored 0%) adding: mytest/main.py (stored 0%) adding: mytest/__init__.py (deflated 4%) $ PYTHONPATH=mytest.zip python -m mytest --startserver [None, '--startserver'] hi mom From rhamph at gmail.com Tue Feb 24 15:16:40 2009 From: rhamph at gmail.com (Adam Olsen) Date: Tue, 24 Feb 2009 12:16:40 -0800 (PST) Subject: more on unescaping escapes References: Message-ID: On Feb 23, 7:18?pm, bvdp wrote: > Gabriel Genellina wrote: > > En Mon, 23 Feb 2009 23:31:20 -0200, bvdp escribi?: > >> Gabriel Genellina wrote: > >>> En Mon, 23 Feb 2009 22:46:34 -0200, bvdp escribi?: > >>>> Chris Rebert wrote: > >>>>> On Mon, Feb 23, 2009 at 4:26 PM, bvdp wrote: > > >>>>> [problem with Python and Windows paths using backslashes] > >>>>> ?Is there any particular reason you can't just internally use regular > >>>>> forward-slashes for the paths? [...] > > >>>> you are absolutely right! Just use '/' on both systems and be done > >>>> with it. Of course I still need to use \x20 for spaces, but that is > >>>> easy. > >>> Why is that? "\x20" is exactly the same as " ". It's not like %20 in > >>> URLs, that becomes a space only after decoding. > > >> I need to use the \x20 because of my parser. I'm reading unquoted > >> lines from a file. The file creater needs to use the form "foo\x20bar" > >> without the quotes in the file so my parser can read it as a single > >> token. Later, the string/token needs to be decoded with the \x20 > >> converted to a space. > > >> So, in my file "foo bar" (no quotes) is read as 2 tokens; "foo\x20bar" > >> is one. > > >> So, it's not really a problem of what happens when you assign a string > >> in the form "foo bar", rather how to convert the \x20 in a string to a > >> space. I think the \\ just complicates the entire issue. > > > Just thinking, if you was reading the string from a file, why were you > > worried about \\ and \ in the first place? (Ok, you moved to use / so > > this is moot now). > > Just cruft introduced while I was trying to figure it all out. Having to > figure the \\ and \x20 at same time with file and keyboard input just > confused the entire issue :) Having the user set a line like > c:\\Program\x20File ... works just fine. I'll suggest he use > c:/program\x20files to make it bit simple for HIM, not my parser. > Unfortunately, due to some bad design decisions on my part about 5 years > ago I'm afraid I'm stuck with the \x20. > > Thanks. You're confusing the python source with the actual contents of the string. We already do one pass at decoding, which is why \x20 is quite literally no different from a space: >>> '\x20' ' ' However, the interactive interpreter uses repr(x), so various characters that are considered formatting, such as a tab, get reescaped when printing: >>> '\t' '\t' >>> len('\t') 1 It really is a tab that gets stored there, not the escape for one. Finally, if you give python an unknown escape it passes it leaves it as an escape. Then, when the interactive interpreter uses repr(x), it is the backslash itself that gets reescaped: >>> '\P' '\\P' >>> len('\P') 2 >>> list('\P') ['\\', 'P'] What does this all mean? If you want to test your parser with python literals you need to escape them twice, like so: >>> 'c:\\\\Program\\x20Files\\\\test' 'c:\\\\Program\\x20Files\\\\test' >>> list('c:\\\\Program\\x20Files\\\\test') ['c', ':', '\\', '\\', 'P', 'r', 'o', 'g', 'r', 'a', 'm', '\\', 'x', '2', '0', 'F', 'i', 'l', 'e', 's', '\\', '\\', 't', 'e', 's', 't'] >>> 'c:\\\\Program\\x20Files\\\\test'.decode('string-escape') 'c:\\Program Files\\test' >>> list('c:\\\\Program\\x20Files\\\\test'.decode('string-escape')) ['c', ':', '\\', 'P', 'r', 'o', 'g', 'r', 'a', 'm', ' ', 'F', 'i', 'l', 'e', 's', '\\', 't', 'e', 's', 't'] However, there's an easier way: use raw strings, which prevent python from unescaping anything: >>> r'c:\\Program\x20Files\\test' 'c:\\\\Program\\x20Files\\\\test' >>> list(r'c:\\Program\x20Files\\test') ['c', ':', '\\', '\\', 'P', 'r', 'o', 'g', 'r', 'a', 'm', '\\', 'x', '2', '0', 'F', 'i', 'l', 'e', 's', '\\', '\\', 't', 'e', 's', 't'] From sjmachin at lexicon.net Tue Feb 24 15:24:44 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 24 Feb 2009 12:24:44 -0800 (PST) Subject: =?windows-1252?Q?Re=3A_=27u=27__Obselete_type_=96_it_is_identical_to_=27d=27=2E__?= =?windows-1252?Q?=287=29?= References: Message-ID: <31fa575a-cc0d-4830-ae23-0a784fa3361f@13g2000yql.googlegroups.com> On Feb 25, 4:48?am, mathieu wrote: > I did not know where to report that: > > 'u' ? ? Obselete type ? it is identical to 'd'. ? ? ? (7) > > http://docs.python.org/library/stdtypes.html#string-formatting So what's your problem with that? Do you believe that 'u' is not accepted? That 'u' is not identical to 'd' and thus the doc should be rewritten as "its behaviour is identical to that of 'd'"? That the behaviour of 'u' is NOT identical to that of 'd'? That 'u' should not be documented? That 'u' should not be described as obselete? From rt8396 at gmail.com Tue Feb 24 15:28:58 2009 From: rt8396 at gmail.com (r) Date: Tue, 24 Feb 2009 12:28:58 -0800 (PST) Subject: Python 3D CAD -- need collaborators, or just brave souls :) References: <4993DE39.8030200@cosc.canterbury.ac.nz> <9ef65856-0f62-4434-a4b4-e15558e7c7b0@n2g2000vba.googlegroups.com> <5764d607-e323-4996-aa6f-a7f04c779110@i38g2000yqd.googlegroups.com> Message-ID: <0d1eee24-4fff-4112-8e26-09ab537c3858@m2g2000vbp.googlegroups.com> On Feb 20, 3:09?pm, Dotan Cohen wrote: > > Even 3DS or Maya is easier to learn that Blender. > > Notepad is easier to learn that VI. Not a good program does simple make. And not a good program does complex make either Yoda. Assembly language is very powerful and allows full control down to the processor level. With your logic all programs would be written in assembly. Only problem is with that logic we would be 30 years behind in development of software at this time. Abstraction is paramount to advancement. With abstraction now you can focus on the problem at hand instead of miles of steps just to get to the problem at hand. Human beings are not hardware, we need high levels of abstraction so we can do what we do best... dream, image, and create. From zorro at chez.Com Tue Feb 24 15:43:17 2009 From: zorro at chez.Com (JB) Date: Tue, 24 Feb 2009 21:43:17 +0100 Subject: pdftk In-Reply-To: References: Message-ID: <49a45bee$0$4999$426a74cc@news.free.fr> Reimar Bauer a ?crit : > Hi > > Does one know about a python interface to pdftk? > Or something similar which can be used to fill a form by fdf data. everyday i use : import os os.system("pdftk.exe source.pdf fill_form data.fdf output output.pdf flatten") and BIM ;) From yanegomi at gmail.com Tue Feb 24 15:55:15 2009 From: yanegomi at gmail.com (Garrett Cooper) Date: Tue, 24 Feb 2009 12:55:15 -0800 Subject: Cross-compiling error when compiling 2.6.1... Message-ID: <364299f40902241255i29cfe3f9h36bd5e549ab5dcc3@mail.gmail.com> I come across the following error: checking for chflags... configure: error: cannot run test program while cross compiling See `config.log' for more details. make-3.81[1]: *** [/nobackup/garrcoop/python_upgrade/contrib/python/obj-mips32/Makefile] Error 1 make-3.81[1]: Leaving directory `/nobackup/garrcoop/python_upgrade' make-3.81: *** [all] Error 2 The blurb from configure that does this test says: # On Tru64, chflags seems to be present, but calling it will # exit Python Basically this testcase (while valid for Tru64) doesn't work with many cross-compilation environments. Couldn't test instead be disabled, but the compilation continue with a warning? Erroring out the build seems like a silly decision... Thanks, -Garrett From cto at openmigration.net Tue Feb 24 16:04:36 2009 From: cto at openmigration.net (geremy condra) Date: Tue, 24 Feb 2009 16:04:36 -0500 Subject: Python AppStore / Marketplace In-Reply-To: References: Message-ID: Just a few quick questions on your proposed design: 1) What tools, if any, do you propose to help developers package for this platform? 2) How do you plan to deal with applications that change or depend on system-wide settings, ie, conf files, kernel version, or the registry? 3) What advantages do you see this having over, say, porting portage or apt-get? Thanks for your time, Geremy Condra -------------- next part -------------- An HTML attachment was scrubbed... URL: From adleslie at gmail.com Tue Feb 24 16:13:34 2009 From: adleslie at gmail.com (May) Date: Tue, 24 Feb 2009 13:13:34 -0800 (PST) Subject: python sql query in django References: <9c401cce-88c3-48b1-a6a5-288d2b897ba3@v19g2000yqn.googlegroups.com> <49a3071a$0$18735$426a34cc@news.free.fr> <49a31936$0$24803$426a74cc@news.free.fr> <70it1cF95tgfU1@mid.uni-berlin.de> Message-ID: <66633e7f-0f8c-472e-9e9d-5930042d7626@g38g2000yqd.googlegroups.com> On Feb 24, 10:36?am, "Diez B. Roggisch" wrote: > > Thanks for all your suggestions. ?From what I've experienced in Django > > and now that I know a little more about how Python functions, I will > > probably use a combination of PHP and Django, instead of trying to get > > Python to do the web portion of my project. ?Thanks again! > > That sounds like the worst idea. Django's ORM is good when used from > within django, because of all the additional goodies like the admin > interface. > > But if you are going to do the webfrontend using PHP, what part is left > for django? If it's only the ORM (for whatever you still use that > anyway), there are better alternatives - SQLAlchemy, and SQLObject, for > Python. They are more powerful and not interwoven with django. > > If you are going to hand-code the interface in PHP, I fail to see though > why you don't do that in Django directly. You are not forced to use the > Admin-interface. > > Diez Hello Diez, I think Django is fabulous for the admin-interface, a simple text search and template inheritance. I will use Django for all of those. What I'm not getting an answer to and cannot find an example of is a complex search, where I have to retrieve data from multiple tables, combine the data, remove the duplicates, etc between a web page and the database. The code that started this thread is only a small piece of the complex data retrieval I need to do. PHP is great for writing complex SQL queries right in the HTML template and I know exactly what it is doing. From bob at mellowood.ca Tue Feb 24 16:13:47 2009 From: bob at mellowood.ca (bvdp) Date: Tue, 24 Feb 2009 14:13:47 -0700 Subject: more on unescaping escapes In-Reply-To: References: Message-ID: Adam Olsen wrote: > On Feb 23, 7:18 pm, bvdp wrote: >> Gabriel Genellina wrote: >>> En Mon, 23 Feb 2009 23:31:20 -0200, bvdp escribi?: >>>> Gabriel Genellina wrote: >>>>> En Mon, 23 Feb 2009 22:46:34 -0200, bvdp escribi?: >>>>>> Chris Rebert wrote: >>>>>>> On Mon, Feb 23, 2009 at 4:26 PM, bvdp wrote: >>>>>>> [problem with Python and Windows paths using backslashes] >>>>>>> Is there any particular reason you can't just internally use regular >>>>>>> forward-slashes for the paths? [...] >>>>>> you are absolutely right! Just use '/' on both systems and be done >>>>>> with it. Of course I still need to use \x20 for spaces, but that is >>>>>> easy. >>>>> Why is that? "\x20" is exactly the same as " ". It's not like %20 in >>>>> URLs, that becomes a space only after decoding. >>>> I need to use the \x20 because of my parser. I'm reading unquoted >>>> lines from a file. The file creater needs to use the form "foo\x20bar" >>>> without the quotes in the file so my parser can read it as a single >>>> token. Later, the string/token needs to be decoded with the \x20 >>>> converted to a space. >>>> So, in my file "foo bar" (no quotes) is read as 2 tokens; "foo\x20bar" >>>> is one. >>>> So, it's not really a problem of what happens when you assign a string >>>> in the form "foo bar", rather how to convert the \x20 in a string to a >>>> space. I think the \\ just complicates the entire issue. >>> Just thinking, if you was reading the string from a file, why were you >>> worried about \\ and \ in the first place? (Ok, you moved to use / so >>> this is moot now). >> Just cruft introduced while I was trying to figure it all out. Having to >> figure the \\ and \x20 at same time with file and keyboard input just >> confused the entire issue :) Having the user set a line like >> c:\\Program\x20File ... works just fine. I'll suggest he use >> c:/program\x20files to make it bit simple for HIM, not my parser. >> Unfortunately, due to some bad design decisions on my part about 5 years >> ago I'm afraid I'm stuck with the \x20. >> >> Thanks. > > You're confusing the python source with the actual contents of the > string. We already do one pass at decoding, which is why \x20 is > quite literally no different from a space: > >>>> '\x20' > ' ' > > However, the interactive interpreter uses repr(x), so various > characters that are considered formatting, such as a tab, get > reescaped when printing: > >>>> '\t' > '\t' >>>> len('\t') > 1 > > It really is a tab that gets stored there, not the escape for one. > > Finally, if you give python an unknown escape it passes it leaves it > as an escape. Then, when the interactive interpreter uses repr(x), it > is the backslash itself that gets reescaped: > >>>> '\P' > '\\P' >>>> len('\P') > 2 >>>> list('\P') > ['\\', 'P'] > > What does this all mean? If you want to test your parser with python > literals you need to escape them twice, like so: > >>>> 'c:\\\\Program\\x20Files\\\\test' > 'c:\\\\Program\\x20Files\\\\test' >>>> list('c:\\\\Program\\x20Files\\\\test') > ['c', ':', '\\', '\\', 'P', 'r', 'o', 'g', 'r', 'a', 'm', '\\', 'x', > '2', '0', 'F', 'i', 'l', 'e', 's', '\\', '\\', 't', 'e', 's', 't'] >>>> 'c:\\\\Program\\x20Files\\\\test'.decode('string-escape') > 'c:\\Program Files\\test' >>>> list('c:\\\\Program\\x20Files\\\\test'.decode('string-escape')) > ['c', ':', '\\', 'P', 'r', 'o', 'g', 'r', 'a', 'm', ' ', 'F', 'i', > 'l', 'e', 's', '\\', 't', 'e', 's', 't'] > > However, there's an easier way: use raw strings, which prevent python > from unescaping anything: > >>>> r'c:\\Program\x20Files\\test' > 'c:\\\\Program\\x20Files\\\\test' >>>> list(r'c:\\Program\x20Files\\test') > ['c', ':', '\\', '\\', 'P', 'r', 'o', 'g', 'r', 'a', 'm', '\\', 'x', > '2', '0', 'F', 'i', 'l', 'e', 's', '\\', '\\', 't', 'e', 's', 't'] Thank you. That is very clear. Appreciate your time. From cto at openmigration.net Tue Feb 24 16:16:07 2009 From: cto at openmigration.net (geremy condra) Date: Tue, 24 Feb 2009 16:16:07 -0500 Subject: Python 3D CAD -- need collaborators, or just brave souls :) In-Reply-To: <0d1eee24-4fff-4112-8e26-09ab537c3858@m2g2000vbp.googlegroups.com> References: <4993DE39.8030200@cosc.canterbury.ac.nz> <9ef65856-0f62-4434-a4b4-e15558e7c7b0@n2g2000vba.googlegroups.com> <5764d607-e323-4996-aa6f-a7f04c779110@i38g2000yqd.googlegroups.com> <0d1eee24-4fff-4112-8e26-09ab537c3858@m2g2000vbp.googlegroups.com> Message-ID: I'm interested. If you are still serious about doing this in two months, send me an email. If you have something put together at that point we can talk about its future. Sound fair? Geremy Condra -------------- next part -------------- An HTML attachment was scrubbed... URL: From cto at openmigration.net Tue Feb 24 16:26:15 2009 From: cto at openmigration.net (geremy condra) Date: Tue, 24 Feb 2009 16:26:15 -0500 Subject: Run a linux system command as a superuser, using a python script In-Reply-To: <50697b2c0902241144x1652f4cdl85e3fe4c61338c61@mail.gmail.com> References: <50697b2c0902241144x1652f4cdl85e3fe4c61338c61@mail.gmail.com> Message-ID: Run the script as root and have it drop privs when it doesn't need them. Or set up a separate daemon to do the rootish parts of it. -------------- next part -------------- An HTML attachment was scrubbed... URL: From btaylordesign at gmail.com Tue Feb 24 16:34:39 2009 From: btaylordesign at gmail.com (Brandon Taylor) Date: Tue, 24 Feb 2009 13:34:39 -0800 (PST) Subject: Problem with environment variables and cx_Oracle Message-ID: <26f558b7-4ddb-4297-a4ff-ec499df8baa7@r24g2000vbp.googlegroups.com> Hello everyone, Here's my setup: OS X (10.5.6 - Intel), Oracle Instant Clinet 10_2, Python 2.6.1, Django trunk I have my Oracle instantclient folder at: /Users/bft228/Library/Oracle/ instantclient_10_2 In my .bash_profile, I have ORACLE_HOME and LD_LIBRARY_PATH specified as: ORACLE_HOME="$HOME/Library/Oracle/instantclient_10_2" export ORACLE_HOME LD_LIBRARY_PATH=$ORACLE_HOME export LD_LIBRARY_PATH When I try to compile cx_Oracle-4.4.1 or 5.0.1, I get an error stating that it cannot find an Oracle installation. setup.py will error here: # try to determine the Oracle home userOracleHome = os.environ.get("ORACLE_HOME") Now, here's where things get wierd... If I: echo $ORACLE_HOME = /Users/bft228/Library/Oracle/ instantclient_10_2 If I: python import os os.environ 'ORACLE_HOME': '/Users/bft228/Library/Oracle/ instantclient_10_2', 'LD_LIBRARY_PATH': '/Users/bft228/Library/Oracle/ instantclient_10_2' If I hard-code the userOracleHome, cx_Oracle will compile, but I'm getting errors wen attempting to connect to Oracle, like: cx_Oracle.InterfaceError: Unable to acquire Oracle environment handle I've been wrestling with this for quite some time. My Oracle person assures me that my user has appropriate permissions for the schema. My Oracle experience is pretty limited, but this seems like it's an issue with the environment on my Mac. Does anyone have any ideas? I would REALLY appreciate some insight. Kind regards, Brandon Taylor Senior Web Developer The University of Texas at Austin From fabiofz at gmail.com Tue Feb 24 16:36:13 2009 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Tue, 24 Feb 2009 18:36:13 -0300 Subject: Pydev 1.4.4 Released Message-ID: Hi All, Pydev and Pydev Extensions 1.4.4 have been released -- note that the release already happened 4 days ago... :) Details on Pydev Extensions: http://www.fabioz.com/pydev Details on Pydev: http://pydev.sf.net Details on its development: http://pydev.blogspot.com Release Highlights in Pydev: ---------------------------------------------- This release fixes a critical bug when configuring the interpreter (if no environment variables were specified, it was not possible to configure an interpreter) What is PyDev? --------------------------- PyDev is a plugin that enables users to use Eclipse for Python and Jython development -- making Eclipse a first class Python IDE -- It comes with many goodies such as code completion, syntax highlighting, syntax analysis, refactor, debug and many others. Cheers, -- Fabio Zadrozny ------------------------------------------------------ Software Developer Aptana http://aptana.com/python Pydev Extensions http://www.fabioz.com/pydev Pydev - Python Development Enviroment for Eclipse http://pydev.sf.net http://pydev.blogspot.com From david.birdsong at gmail.com Tue Feb 24 16:37:24 2009 From: david.birdsong at gmail.com (birdsong) Date: Tue, 24 Feb 2009 13:37:24 -0800 (PST) Subject: Run a linux system command as a superuser, using a python script References: Message-ID: <7a449358-dc80-4063-a5cd-a5a1ffd9fba8@c36g2000yqn.googlegroups.com> On Feb 24, 11:44?am, Chris Rebert wrote: > On Tue, Feb 24, 2009 at 11:38 AM, madhav wrote: > > I have got postfix installed on my machine and I am updating on of its > > configuration files programmatically(using python)(on some action). > > Since any change in the configuration needs a reload, I need to reload > > postfix to reflect the latest change. How can I do that in a python > > script. Precisely, I have something like this: > > > import subprocess > > subprocess.Popen('sudo /etc/init.d/postifx reload') > > > Since this script should be run in no-human environment(on the fly), I > > cant supply the sudo password or even root password(if needed). Even > > sudo doesn't have a flag to input the password for the command at the > > first shot. How do I do this? > > pexpect may be useful in this situation -http://www.noah.org/wiki/Pexpect > > Cheers, > Chris > > -- > Follow the path of the Iguana...http://rebertia.com I vote down the pexpect, you'd be hardcoding a password. How about adjusting the sudoers file to grant the user of this script sudo on / etc/init.d/postifx or even sudo on your python script. From yanegomi at gmail.com Tue Feb 24 16:47:02 2009 From: yanegomi at gmail.com (Garrett Cooper) Date: Tue, 24 Feb 2009 13:47:02 -0800 Subject: Cross-compiling error when compiling 2.6.1... In-Reply-To: <364299f40902241255i29cfe3f9h36bd5e549ab5dcc3@mail.gmail.com> References: <364299f40902241255i29cfe3f9h36bd5e549ab5dcc3@mail.gmail.com> Message-ID: <364299f40902241347m66cd3199h3ee40241f886effc@mail.gmail.com> On Tue, Feb 24, 2009 at 12:55 PM, Garrett Cooper wrote: > I come across the following error: > > checking for chflags... configure: error: cannot run test program > while cross compiling > See `config.log' for more details. > make-3.81[1]: *** > [/nobackup/garrcoop/python_upgrade/contrib/python/obj-mips32/Makefile] > Error 1 > make-3.81[1]: Leaving directory `/nobackup/garrcoop/python_upgrade' > make-3.81: *** [all] Error 2 > > The blurb from configure that does this test says: > > # On Tru64, chflags seems to be present, but calling it will > # exit Python > > Basically this testcase (while valid for Tru64) doesn't work with many > cross-compilation environments. Couldn't test instead be disabled, but > the compilation continue with a warning? Erroring out the build seems > like a silly decision... > > Thanks, > -Garrett I've so far tied this issue down to the chflags, lchflags, and printf with %zd support tests. After commenting out those items things run to completion. -Garrett From jason.scheirer at gmail.com Tue Feb 24 16:51:23 2009 From: jason.scheirer at gmail.com (Jason Scheirer) Date: Tue, 24 Feb 2009 13:51:23 -0800 (PST) Subject: pdftk References: <49a45bee$0$4999$426a74cc@news.free.fr> Message-ID: <173702ed-5f86-464a-8153-43a4442957c4@b16g2000yqb.googlegroups.com> On Feb 24, 12:43?pm, JB wrote: > Reimar Bauer a ?crit : > > > Hi > > > Does one know about a python interface to pdftk? > > Or something similar which can be used to fill a form by fdf data. > > everyday i use : > > import os > os.system("pdftk.exe source.pdf fill_form data.fdf output output.pdf > flatten") > > and BIM > > ;) Reportlab will let you use an existing PDF as a template, letting you use its text layout routines to overly your data on the existing page and output a new document. From steve at pearwood.info Tue Feb 24 17:06:28 2009 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 25 Feb 2009 09:06:28 +1100 Subject: 'u' Obselete type =?UTF-8?B?4oCT?= it is identical to 'd'. (7) References: Message-ID: <01b464c4$0$18215$c3e8da3@news.astraweb.com> mathieu wrote: > I did not know where to report that: > > 'u' Obselete type ? it is identical to 'd'. (7) > > http://docs.python.org/library/stdtypes.html#string-formatting > > Thanks If you google on "python bug tracker" the first link is the correct one. I don't know what you want to report, but I've reported that obsolete is mispelled: http://bugs.python.org/issue5361 -- Steven From lionel.keene at gmail.com Tue Feb 24 17:57:52 2009 From: lionel.keene at gmail.com (Lionel) Date: Tue, 24 Feb 2009 14:57:52 -0800 (PST) Subject: Getting screen dims platform specific? Say it ain't so! Message-ID: Hello people, I'm looking for a way to get the screen dimensions (in pixels) using the standard Python library. The only thing I found so far was the following: from win32api import GetSystemMetrics Width = GetSystemMetrics(0) Height = GetSystemMetrics(1) I get an error claiming "no module named win32api". It's platform specific anyway, but I thought I would try. Anyone got this? -L From sjmachin at lexicon.net Tue Feb 24 18:04:05 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 24 Feb 2009 15:04:05 -0800 (PST) Subject: =?windows-1252?Q?Re=3A_=27u=27__Obselete_type_=96_it_is_identical_to_=27d=27=2E__?= =?windows-1252?Q?=287=29?= References: <01b464c4$0$18215$c3e8da3@news.astraweb.com> Message-ID: On Feb 25, 9:06?am, Steven D'Aprano wrote: > mathieu wrote: > > I did not know where to report that: > > > 'u' ? Obselete type ? it is identical to 'd'. ? ? ? ? (7) > > >http://docs.python.org/library/stdtypes.html#string-formatting > > > Thanks > > If you google on "python bug tracker" the first link is the correct one. > > I don't know what you want to report, but I've reported that obsolete is > mispelled: > > http://bugs.python.org/issue5361 +1 Own Goal of the Year ... see http://www.yourdictionary.com/library/misspelled.html From kyrie at uh.cu Tue Feb 24 18:53:13 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Tue, 24 Feb 2009 18:53:13 -0500 Subject: Getting screen dims platform specific? Say it ain't so! In-Reply-To: References: Message-ID: <200902241853.13785.kyrie@uh.cu> On Tuesday 24 February 2009 05:57:52 pm Lionel wrote: > from win32api import GetSystemMetrics I'd guess that win32api is patform specific, as in "api for win32". -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From cto at openmigration.net Tue Feb 24 18:59:31 2009 From: cto at openmigration.net (geremy condra) Date: Tue, 24 Feb 2009 18:59:31 -0500 Subject: Getting screen dims platform specific? Say it ain't so! In-Reply-To: <200902241853.13785.kyrie@uh.cu> References: <200902241853.13785.kyrie@uh.cu> Message-ID: For X systems you can use xwininfo, ie: from commands import getstatusoutput def get_screen_dims(): status, output = getstatusoutput("xwininfo -root") if not status: On Tue, Feb 24, 2009 at 6:53 PM, Luis Zarrabeitia wrote: > On Tuesday 24 February 2009 05:57:52 pm Lionel wrote: > > from win32api import GetSystemMetrics > > I'd guess that win32api is patform specific, as in "api for win32". > > -- > Luis Zarrabeitia (aka Kyrie) > Fac. de Matem?tica y Computaci?n, UH. > http://profesores.matcom.uh.cu/~kyrie > -- > http://mail.python.org/mailman/listinfo/python-list > -- OpenMigration LLC- Open Source solutions for your business. Visit us at http://OpenMigration.net. -------------- next part -------------- An HTML attachment was scrubbed... URL: From cto at openmigration.net Tue Feb 24 19:07:47 2009 From: cto at openmigration.net (geremy condra) Date: Tue, 24 Feb 2009 19:07:47 -0500 Subject: Getting screen dims platform specific? Say it ain't so! In-Reply-To: References: <200902241853.13785.kyrie@uh.cu> Message-ID: my apologies- hit enter accidentally. anyway, just process the output of that command for the Height: and Width: lines. -------------- next part -------------- An HTML attachment was scrubbed... URL: From starsareblueandfaraway at gmail.com Tue Feb 24 19:07:58 2009 From: starsareblueandfaraway at gmail.com (Roy H. Han) Date: Tue, 24 Feb 2009 19:07:58 -0500 Subject: How do I decode unicode characters in the subject using email.message_from_string()? Message-ID: <6a5569ec0902241607y42824929l7d3c93c7571ff24b@mail.gmail.com> Dear python-list, I'm having some trouble decoding an email header using the standard imaplib.IMAP4 class and email.message_from_string method. In particular, email.message_from_string() does not seem to properly decode unicode characters in the subject. How do I decode unicode characters in the subject? I read on the documentation that the email module supports RFC 2047. But is there a way to make imaplib.IMAP4 and email.message_from_string use this protocol? I'm using Python 2.5.2 on Fedora. Perhaps this problem has been fixed already in Python 2.6. RHH From lionel.keene at gmail.com Tue Feb 24 19:12:36 2009 From: lionel.keene at gmail.com (Lionel) Date: Tue, 24 Feb 2009 16:12:36 -0800 (PST) Subject: Getting screen dims platform specific? Say it ain't so! References: Message-ID: <52d71fbc-fc15-4a2b-93ea-d915a2de0b4e@d32g2000yqe.googlegroups.com> On Feb 24, 3:53?pm, Luis Zarrabeitia wrote: > On Tuesday 24 February 2009 05:57:52 pm Lionel wrote: > > > from win32api import GetSystemMetrics > > I'd guess that win32api is patform specific, as in "api for win32". > > -- > Luis Zarrabeitia (aka Kyrie) > Fac. de Matem?tica y Computaci?n, UH.http://profesores.matcom.uh.cu/~kyrie Yes, it's platform specific. I was just trying anyway to see if it would work. In a nutshell, what I need is a way to acquire the screen dimensions (in pixels) and its dpi setting. From zvezdan at zope.com Tue Feb 24 19:28:43 2009 From: zvezdan at zope.com (Zvezdan Petkovic) Date: Tue, 24 Feb 2009 19:28:43 -0500 Subject: Problem with environment variables and cx_Oracle In-Reply-To: <26f558b7-4ddb-4297-a4ff-ec499df8baa7@r24g2000vbp.googlegroups.com> References: <26f558b7-4ddb-4297-a4ff-ec499df8baa7@r24g2000vbp.googlegroups.com> Message-ID: <267ABB0C-137A-498D-B078-D74B2E609EC9@zope.com> On Feb 24, 2009, at 4:34 PM, Brandon Taylor wrote: > Here's my setup: OS X (10.5.6 - Intel), Oracle Instant Clinet 10_2, > Python 2.6.1, Django trunk OS X is an important detail here. > In my .bash_profile, I have ORACLE_HOME and LD_LIBRARY_PATH specified > as: > > ORACLE_HOME="$HOME/Library/Oracle/instantclient_10_2" > export ORACLE_HOME > > LD_LIBRARY_PATH=$ORACLE_HOME > export LD_LIBRARY_PATH Shouldn't this be DYLD_LIBRARY_PATH for Mac? From bignose+hates-spam at benfinney.id.au Tue Feb 24 19:32:03 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Wed, 25 Feb 2009 11:32:03 +1100 Subject: 'u' Obselete type =?utf-8?Q?=E2=80=93?= it is identical to 'd'. (7) References: <01b464c4$0$18215$c3e8da3@news.astraweb.com> Message-ID: <878wnvgxvg.fsf@benfinney.id.au> John Machin writes: > On Feb 25, 9:06?am, Steven D'Aprano wrote: > > I don't know what you want to report, but I've reported that obsolete is > > mispelled: > > +1 Own Goal of the Year ... see > http://www.yourdictionary.com/library/misspelled.html Not so notable. It's merely one more incident of the law of communication variously known as McKean's Law, Skitt's Law, and Muphry's Law . -- \ ?I have never made but one prayer to God, a very short one: ?O | `\ Lord, make my enemies ridiculous!? And God granted it.? | _o__) ?Voltaire | Ben Finney From jmcmonagle at NO.SPAM.velseis.com.au Tue Feb 24 19:38:46 2009 From: jmcmonagle at NO.SPAM.velseis.com.au (John McMonagle) Date: Wed, 25 Feb 2009 10:38:46 +1000 Subject: Getting screen dims platform specific? Say it ain't so! In-Reply-To: <52d71fbc-fc15-4a2b-93ea-d915a2de0b4e@d32g2000yqe.googlegroups.com> References: <52d71fbc-fc15-4a2b-93ea-d915a2de0b4e@d32g2000yqe.googlegroups.com> Message-ID: <49a4930c@dnews.tpgi.com.au> Lionel wrote: > Yes, it's platform specific. I was just trying anyway to see if it > would work. > > In a nutshell, what I need is a way to acquire the screen dimensions > (in pixels) and its dpi setting. This should work on all platforms: from Tkinter import * r = Tk() r.withdraw() r.winfo_screenheight() r.winfo_screenwidth() r.winfo_pixels('1i') Regards, John From kyrie at uh.cu Tue Feb 24 19:41:09 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Tue, 24 Feb 2009 19:41:09 -0500 Subject: Getting screen dims platform specific? Say it ain't so! In-Reply-To: <52d71fbc-fc15-4a2b-93ea-d915a2de0b4e@d32g2000yqe.googlegroups.com> References: <52d71fbc-fc15-4a2b-93ea-d915a2de0b4e@d32g2000yqe.googlegroups.com> Message-ID: <200902241941.09240.kyrie@uh.cu> On Tuesday 24 February 2009 07:12:36 pm Lionel wrote: > In a nutshell, what I need is a way to acquire the screen dimensions > (in pixels) and its dpi setting. This is a guess, and a guess only. What do you want to know it for? If it is for painting something on the screen, maybe (just maybe - I'm guessing here big time), whatever API you are using for painting can be used for getting the dimensions of the drawing device. I don't even know if GTK or Qt have that feature, but you should look into it. If the same api you will use for painting provides that functionality, then it would be kind of irrelevant if it is on the stdlib or not. Of course, this only applies if you want to paint and your api provides that info. -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From sjmachin at lexicon.net Tue Feb 24 19:52:15 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 24 Feb 2009 16:52:15 -0800 (PST) Subject: How do I decode unicode characters in the subject using email.message_from_string()? References: Message-ID: <44432eaa-372e-45d2-baa2-da350a371d70@x9g2000yqk.googlegroups.com> On Feb 25, 11:07?am, "Roy H. Han" wrote: > Dear python-list, > > I'm having some trouble decoding an email header using the standard > imaplib.IMAP4 class and email.message_from_string method. > > In particular, email.message_from_string() does not seem to properly > decode unicode characters in the subject. > > How do I decode unicode characters in the subject? You don't. You can't. You decode str objects into unicode objects. You encode unicode objects into str objects. If your input is not a str object, you have a problem. I'm no expert on the email package, but experts don't have crystal balls, so let's gather some data for them while we're waiting for their timezones to align: Presumably your code is doing something like: msg = email.message_from_string(a_string) Please report the results of print repr(a_string) and print type(msg) print msg.items() and tell us what you expected. Cheers, John From ethan at stoneleaf.us Tue Feb 24 19:52:20 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 24 Feb 2009 16:52:20 -0800 Subject: pep 8 constants In-Reply-To: References: <4978DD2E.1090008@aim.com> Message-ID: <49A49644.80509@stoneleaf.us> Steve Holden wrote: > Brian Allen Vanderburg II wrote: > >>bockman at virgilio.it wrote: >> >>>Constants would be a nice addition in python, sure enough. >>>But I'm not sure that this can be done without a run-time check every >>>time >>>the constant is used, and python is already slow enough. Maybe a check >>>that is disabled when running with optimizing flags ? >>> >>>But I'm sure this discussion has been already made and the FINAL WORD has >>>been already spoken. >>> >>>Ciao >>>---- >>>FB >> >>One idea to make constants possible would be to extend properties to be >>able to exist at the module level as well as the class level: >> >>@property >>def pi(): >> return 3.14159..... >> >>print(pi) # prints 3.14159.... >>pi=32 # Raise an error Cannot set attribute ... >> > > I don't understand why this would print 3.14159 ... instead of __math__.pi>, or whatever. > > property would clearly have to do something very different in module > scope in order to make this work. > > regards > Steve --> class tester(object): ... @property ... def pi(self): ... return 3.141596 ... --> testee = tester() --> testee.pi 3.1415959999999998 Looks like that's how property works, so the same behavior on a module level would do as Brian suggests. -- ~Ethan~ From lionel.keene at gmail.com Tue Feb 24 20:03:03 2009 From: lionel.keene at gmail.com (Lionel) Date: Tue, 24 Feb 2009 17:03:03 -0800 (PST) Subject: Getting screen dims platform specific? Say it ain't so! References: <52d71fbc-fc15-4a2b-93ea-d915a2de0b4e@d32g2000yqe.googlegroups.com> Message-ID: On Feb 24, 4:41?pm, Luis Zarrabeitia wrote: > On Tuesday 24 February 2009 07:12:36 pm Lionel wrote: > > > In a nutshell, what I need is a way to acquire the screen dimensions > > (in pixels) and its dpi setting. > > This is a guess, and a guess only. > What do you want to know it for? If it is for painting something on the > screen, maybe (just maybe - I'm guessing here big time), whatever API you are > using for painting can be used for getting the dimensions of the drawing > device. I don't even know if GTK or Qt have that feature, but you should look > into it. If the same api you will use for painting provides that > functionality, then it would be kind of irrelevant if it is on the stdlib or > not. > > Of course, this only applies if you want to paint and your api provides that > info. > > -- > Luis Zarrabeitia (aka Kyrie) > Fac. de Matem?tica y Computaci?n, UH.http://profesores.matcom.uh.cu/~kyrie Thanks for the responses so far, everyone. Luis you are indeed a good guesser! I'm using wxPython/matplotlib and would like to size my matplotlib data figure so that it assumes a 1:1 ratio on the screen when embedded in a wxPython form. I'm playing with a 2D array with 320 rows and 177 columns and therefore would like to display the figure with a size of 320x177 pixels. The problem is that the call to instantiate the figure takes size parameters of inches and dpi! For example: matplotlib.figure.Figure((5,4), 75) is a figure with width of 5 inches, height of 4 inches, and dpi of 75. Thanks to Luis' comment I googled around and found that wxPython has the following functions: wx.GetDisplaySize() # Get dimensions in pixels. wx.GetDisplaySizeMM() # Get dimensions in millimeters. It's a little klunky to have a function that takes inches an an argument and another that produces millimeters when querying the display, no? Unless someone has a better idea I suppose I'll have to convert between the two to display at 1:1. -L SInce I want my matplotlib.figure.Figure() to assume the exact pixel dimensions of the 2D array, From sjmachin at lexicon.net Tue Feb 24 20:04:30 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 24 Feb 2009 17:04:30 -0800 (PST) Subject: =?windows-1252?B?UmU6ICd1JyBPYnNlbGV0ZSB0eXBlIJYgaXQgaXMgaWRlbnRpY2FsIHRvICdkJy4gKDc=?= =?windows-1252?B?KQ==?= References: <01b464c4$0$18215$c3e8da3@news.astraweb.com> <878wnvgxvg.fsf@benfinney.id.au> Message-ID: <1aa8bdcf-993c-4a60-aadd-1319239885d8@v15g2000yqn.googlegroups.com> On Feb 25, 11:32?am, Ben Finney wrote: > John Machin writes: > > On Feb 25, 9:06?am, Steven D'Aprano wrote: > > > I don't know what you want to report, but I've reported that obsolete is > > > mispelled: > > > +1 Own Goal of the Year ... see > > ?http://www.yourdictionary.com/library/misspelled.html > > Not so notable. It's merely one more incident of the law of > communication variously known as McKean's Law, Skitt's Law, and > Muphry's Law . Those incidents are mundane and ordinary IMHO compared with misspelling both "misspelled" and "misspelling" in the bug report. From steve at holdenweb.com Tue Feb 24 20:22:29 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 24 Feb 2009 20:22:29 -0500 Subject: pep 8 constants In-Reply-To: <49A49644.80509@stoneleaf.us> References: <4978DD2E.1090008@aim.com> <49A49644.80509@stoneleaf.us> Message-ID: <49A49D55.10705@holdenweb.com> Ethan Furman wrote: > Steve Holden wrote: >> Brian Allen Vanderburg II wrote: >> >>> bockman at virgilio.it wrote: >>> >>>> Constants would be a nice addition in python, sure enough. >>>> But I'm not sure that this can be done without a run-time check every >>>> time >>>> the constant is used, and python is already slow enough. Maybe a check >>>> that is disabled when running with optimizing flags ? >>>> >>>> But I'm sure this discussion has been already made and the FINAL >>>> WORD has >>>> been already spoken. >>>> >>>> Ciao >>>> ---- >>>> FB >>> >>> One idea to make constants possible would be to extend properties to be >>> able to exist at the module level as well as the class level: >>> >>> @property >>> def pi(): >>> return 3.14159..... >>> >>> print(pi) # prints 3.14159.... >>> pi=32 # Raise an error Cannot set attribute ... >>> >> >> I don't understand why this would print 3.14159 ... instead of > __math__.pi>, or whatever. >> >> property would clearly have to do something very different in module >> scope in order to make this work. >> >> regards >> Steve > > --> class tester(object): > ... @property > ... def pi(self): > ... return 3.141596 > ... > --> testee = tester() > --> testee.pi > 3.1415959999999998 > > Looks like that's how property works, so the same behavior on a module > level would do as Brian suggests. But that's at the class level, not the module level. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Tue Feb 24 22:15:33 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 24 Feb 2009 22:15:33 -0500 Subject: 'u' Obselete type =?ISO-8859-1?Q?--_it_is_identical_?= =?ISO-8859-1?Q?to_=27d=27=2E_=287=29?= In-Reply-To: <1aa8bdcf-993c-4a60-aadd-1319239885d8@v15g2000yqn.googlegroups.com> References: <01b464c4$0$18215$c3e8da3@news.astraweb.com> <878wnvgxvg.fsf@benfinney.id.au> <1aa8bdcf-993c-4a60-aadd-1319239885d8@v15g2000yqn.googlegroups.com> Message-ID: John Machin wrote: > On Feb 25, 11:32 am, Ben Finney > wrote: >> John Machin writes: >>> On Feb 25, 9:06 am, Steven D'Aprano wrote: >>>> I don't know what you want to report, but I've reported that obsolete is >>>> mispelled: >>> +1 Own Goal of the Year ... see >>> http://www.yourdictionary.com/library/misspelled.html >> Not so notable. It's merely one more incident of the law of >> communication variously known as McKean's Law, Skitt's Law, and >> Muphry's Law . > > Those incidents are mundane and ordinary IMHO compared with > misspelling both "misspelled" and "misspelling" in the bug report. > I thought that was Ben's point. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From king.seth at gmail.com Tue Feb 24 22:46:19 2009 From: king.seth at gmail.com (Seth) Date: Tue, 24 Feb 2009 19:46:19 -0800 (PST) Subject: Convert PySerial to python 3.0 Message-ID: <385a617c-1e43-4828-8edd-3f4aadce8604@c11g2000yqj.googlegroups.com> I am just messing around trying to get pyserial to work with 3.0. I am stuck on this line: if type(port) in [type(''), type(u'')] how can I convert this to 3.0? I tried changing the u to a d that did not do anything. Thanks From gagsl-py2 at yahoo.com.ar Tue Feb 24 22:52:45 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 25 Feb 2009 01:52:45 -0200 Subject: pep 8 constants References: <4978DD2E.1090008@aim.com> <49A49644.80509@stoneleaf.us> Message-ID: En Tue, 24 Feb 2009 22:52:20 -0200, Ethan Furman escribi?: > Steve Holden wrote: >> Brian Allen Vanderburg II wrote: >> >>> One idea to make constants possible would be to extend properties to be >>> able to exist at the module level as well as the class level: >>> >>> @property >>> def pi(): >>> return 3.14159..... >>> >>> print(pi) # prints 3.14159.... >>> pi=32 # Raise an error Cannot set attribute ... >>> >> I don't understand why this would print 3.14159 ... instead of >> > __math__.pi>, or whatever. >> property would clearly have to do something very different in module >> scope in order to make this work. >> regards >> Steve > > --> class tester(object): > ... @property > ... def pi(self): > ... return 3.141596 > ... > --> testee = tester() > --> testee.pi > 3.1415959999999998 > > Looks like that's how property works, so the same behavior on a module > level would do as Brian suggests. Note that: - you defined the property inside the *class* tester - then, you created an *instance* of such class - you retrieve pi from the instance - if you retrieve pi from the class (tester.pi), you get a property object, not a float. - if you directly attach the property to the instance, testee.pi returns a property object, not a float. Finally, consider that modules are instances of type `module`; all modules are instances of the same type. How do you propose to make properties work at the module level? -- Gabriel Genellina From clp2 at rebertia.com Tue Feb 24 22:55:44 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 24 Feb 2009 19:55:44 -0800 Subject: Convert PySerial to python 3.0 In-Reply-To: <385a617c-1e43-4828-8edd-3f4aadce8604@c11g2000yqj.googlegroups.com> References: <385a617c-1e43-4828-8edd-3f4aadce8604@c11g2000yqj.googlegroups.com> Message-ID: <50697b2c0902241955i66452d48j6ff03b6cebec4cd@mail.gmail.com> On Tue, Feb 24, 2009 at 7:46 PM, Seth wrote: > I am just messing around trying to get pyserial to work with 3.0. > > I am stuck on this line: > > if type(port) in [type(''), type(u'')] > > > how can I convert this to 3.0? I tried changing the u to a d that did > not do anything. Looks like it's doing the equivalent of the pre-3.0-ism `isinstance(port, basestring)`, but in a roundabout way. However, since basestring doesn't exist in 3.0, either: if isinstance(port, str): Or if isinstance(port, bytes): would be the appropriate replacement. Depends (obviously) on whether 'port' is supposed to be unicode or a byte sequence. Without more context, I can't really say which is what you want. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From steve at holdenweb.com Tue Feb 24 22:57:50 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 24 Feb 2009 22:57:50 -0500 Subject: pep 8 constants In-Reply-To: References: <4978DD2E.1090008@aim.com> <49A49644.80509@stoneleaf.us> Message-ID: Gabriel Genellina wrote: > En Tue, 24 Feb 2009 22:52:20 -0200, Ethan Furman > escribi?: > >> Steve Holden wrote: >>> Brian Allen Vanderburg II wrote: >>> >>>> One idea to make constants possible would be to extend properties to be >>>> able to exist at the module level as well as the class level: >>>> >>>> @property >>>> def pi(): >>>> return 3.14159..... >>>> >>>> print(pi) # prints 3.14159.... >>>> pi=32 # Raise an error Cannot set attribute ... >>>> >>> I don't understand why this would print 3.14159 ... instead of >>> >> __math__.pi>, or whatever. >>> property would clearly have to do something very different in module >>> scope in order to make this work. >>> regards >>> Steve >> >> --> class tester(object): >> ... @property >> ... def pi(self): >> ... return 3.141596 >> ... >> --> testee = tester() >> --> testee.pi >> 3.1415959999999998 >> >> Looks like that's how property works, so the same behavior on a module >> level would do as Brian suggests. > > Note that: > - you defined the property inside the *class* tester > - then, you created an *instance* of such class > - you retrieve pi from the instance > - if you retrieve pi from the class (tester.pi), you get a property > object, not a float. > - if you directly attach the property to the instance, testee.pi > returns a property object, not a float. > Finally, consider that modules are instances of type `module`; all > modules are instances of the same type. > > How do you propose to make properties work at the module level? > Thanks, Gabriel. I was beginning to think there was something terribly obvious I had completely missed. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Tue Feb 24 23:00:56 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 24 Feb 2009 23:00:56 -0500 Subject: Convert PySerial to python 3.0 In-Reply-To: <385a617c-1e43-4828-8edd-3f4aadce8604@c11g2000yqj.googlegroups.com> References: <385a617c-1e43-4828-8edd-3f4aadce8604@c11g2000yqj.googlegroups.com> Message-ID: Seth wrote: > I am just messing around trying to get pyserial to work with 3.0. > > I am stuck on this line: > > if type(port) in [type(''), type(u'')] > > > how can I convert this to 3.0? I tried changing the u to a d that did > not do anything. > How about if type(port) in (str, bytes): Untested. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve.ferg.bitbucket at gmail.com Tue Feb 24 23:08:40 2009 From: steve.ferg.bitbucket at gmail.com (steve.ferg.bitbucket at gmail.com) Date: Tue, 24 Feb 2009 20:08:40 -0800 (PST) Subject: Looking for tips on running Python version 2.6 and 3.0 together on same *WINDOWS* machine Message-ID: I'm looking for tips on installing and running Python version 2.6 and version 3.0 together on same Windows machine. I'd like to install both 2.6 and 3.0 together on the same Windows (Vista) machine, so I can test programs under both versions. Is it possible to install both versions on the same Windows machine in such a way that they are both asily available and don't interfere with one another? I'm concerned, for example, that if I install both, the second installation will over-write some Python entry in the registry. I'd like something fairly simple -- I will be sharing this information with others in my workgroup for whom virtualenv is not an option. I googled around, but couldn't find anything that seemed to address this specific question. If anybody knows of a URL with this information (a "2 to 3 Conversion FAQs"?) that would be great. Any help would be greatly appreciated. -- Steve Ferg From zaheer.agadi at gmail.com Tue Feb 24 23:17:21 2009 From: zaheer.agadi at gmail.com (zaheer.agadi at gmail.com) Date: Tue, 24 Feb 2009 20:17:21 -0800 (PST) Subject: Is there any equivalent feature available in Python..? References: <54d72142-963e-4be3-b11e-7b15c6a2ee58@m24g2000vbp.googlegroups.com> Message-ID: <5455a1b6-4e61-42fd-8088-5439732da1c6@g38g2000yqd.googlegroups.com> On Feb 25, 1:10?am, Albert Hopkins wrote: > On Tue, 2009-02-24 at 11:05 -0800, zaheer.ag... at gmail.com wrote: > > Hi, > > > Is there any Python equivalent of java jar,can I include all my > > sources,properties file etc into a single file.Is there anyway in > > Python that I can run like the following > > > java ?-jar Mytest.jar --startwebserver > > > How to so something like this in Python? > > Similar but not equal: > > $ tree mytest > mytest > |-- __init__.py > `-- main.py > > $ cat mytest/__init__.py > if __name__ == '__main__': > ? ? import sys > ? ? print sys.argv > ? ? import mytest.main > > $ cat mytest/main.py > print 'hi mom' > > $ zip -r mytest.zip mytest > ? adding: mytest/ (stored 0%) > ? adding: mytest/main.py (stored 0%) > ? adding: mytest/__init__.py (deflated 4%) > > $ PYTHONPATH=mytest.zip python -m mytest --startserver > [None, '--startserver'] > hi mom Thanks A lot this should solve my problem.Just out of curiosity how is Python eggs different from the zip file you created here From venutaurus539 at gmail.com Tue Feb 24 23:20:52 2009 From: venutaurus539 at gmail.com (venutaurus539 at gmail.com) Date: Tue, 24 Feb 2009 20:20:52 -0800 (PST) Subject: Problem with os.system() Message-ID: <452516e1-3708-4d82-aa8c-907169b985e3@v15g2000yqn.googlegroups.com> Hello, I am facing problems while using os.system() of python for copying a file from source to destination where the file name is in unicode (multi lingual characters).My python interpreter is trying to convert them to ascii and is failing. I tried giving unicode string as input for the function something like: c = u"copy "+"\""+full_path+"\" "+dest os.system (c) where the full_path contains filenames with unicode characters(unicode data type). I tried searching in google and came to know that UNICODE support wasn't there for os.system function till python2.3[1]. Currently I am using python2.6 but couldn't find anywhere whether a support has been provided or not. Can some one suggest me any work around for this. If I do a manual encoding of the file name to ascii, it results in loss of data and hence the copy command wouldn't find the file name. --------------------------------------------------------------------------------------------------------- Traceback (most recent call last): File "C:\unitest.py", line 32, in findFile(u"E:\\New Folder") File "C:\unitest.py", line 17, in findFile findFile(full_path) File "C:\unitest.py", line 17, in findFile findFile(full_path) File "C:\unitest.py", line 27, in findFile os.system (c) UnicodeEncodeError: 'ascii' codec can't encode characters in position 47-72: ordinal not in range(128) ------------------------------------------------------------------------------------------------------ [1] http://mail.python.org/pipermail/python-list/2003-January/182182.html Thanks in advance, Venu M From grante at visi.com Tue Feb 24 23:22:34 2009 From: grante at visi.com (Grant Edwards) Date: Tue, 24 Feb 2009 22:22:34 -0600 Subject: Convert PySerial to python 3.0 References: <385a617c-1e43-4828-8edd-3f4aadce8604@c11g2000yqj.googlegroups.com> Message-ID: On 2009-02-25, Chris Rebert wrote: > On Tue, Feb 24, 2009 at 7:46 PM, Seth wrote: >> I am just messing around trying to get pyserial to work with 3.0. >> >> I am stuck on this line: >> >> if type(port) in [type(''), type(u'')] >> >> how can I convert this to 3.0? I tried changing the u to a d that did >> not do anything. > > Looks like it's doing the equivalent of the pre-3.0-ism > `isinstance(port, basestring)`, but in a roundabout way. > However, since basestring doesn't exist in 3.0, either: > > if isinstance(port, str): > > Or > > if isinstance(port, bytes): > > would be the appropriate replacement. Depends (obviously) on > whether 'port' is supposed to be unicode or a byte sequence. Port can either be an integer or a file/device name. > Without more context, I can't really say which is what you > want. In the line of code in question, the conditional is inteded to be true if "port" is someting that could be passed to the OS as a file or device name. -- Grant From venutaurus539 at gmail.com Tue Feb 24 23:22:47 2009 From: venutaurus539 at gmail.com (venutaurus539 at gmail.com) Date: Tue, 24 Feb 2009 20:22:47 -0800 (PST) Subject: Problem with os.system() Message-ID: <3c216f95-0cd9-43ec-91fa-090e9ad00fbc@e5g2000vbe.googlegroups.com> Hello, I am facing problems while using os.system() of python for copying a file from source to destination where the file name is in unicode (multi lingual characters).My python interpreter is trying to convert them to ascii and is failing. I tried giving unicode string as input for the function something like: c = u"copy "+"\""+full_path+"\" "+dest os.system (c) where the full_path contains filenames with unicode characters(unicode data type). I tried searching in google and came to know that UNICODE support wasn't there for os.system function till python2.3[1]. Currently I am using python2.6 but couldn't find anywhere whether a support has been provided or not. Can some one suggest me any work around for this. If I do a manual encoding of the file name to ascii, it results in loss of data and hence the copy command wouldn't find the file name. --------------------------------------------------------------------------------------------------------- Traceback (most recent call last): File "C:\unitest.py", line 32, in findFile(u"E:\\New Folder") File "C:\unitest.py", line 17, in findFile findFile(full_path) File "C:\unitest.py", line 17, in findFile findFile(full_path) File "C:\unitest.py", line 27, in findFile os.system (c) UnicodeEncodeError: 'ascii' codec can't encode characters in position 47-72: ordinal not in range(128) ------------------------------------------------------------------------------------------------------ [1] http://mail.python.org/pipermail/python-list/2003-January/182182.html Thanks in advance, Venu M From david.birdsong at gmail.com Tue Feb 24 23:25:14 2009 From: david.birdsong at gmail.com (birdsong) Date: Tue, 24 Feb 2009 20:25:14 -0800 (PST) Subject: single thread decrement a semaphore object more than once? Message-ID: I searched but didn't see this already discussed, sorry if I didn't search hard enough. Can I decrement a semaphore's counter within the same thread more than once? I'd like to set hard and soft limits in a server I'm writing. The server upon initialization would create a semaphore: threading.Semaphore(100) Then acquire 50x to hold half of the locks before serving any requests. This allows me to grow the number of locks to the hard limit via signals or some other mechanism, but I need to know that any 1 thread has the ability to acquire up or release more than 1x and effectively acquire and release for that number of semaphore values. I could implement this by using regular threading.Lock in a pool, but the Semaphore object would be much easier. From girish.cfc at gmail.com Tue Feb 24 23:50:20 2009 From: girish.cfc at gmail.com (Girish) Date: Tue, 24 Feb 2009 20:50:20 -0800 (PST) Subject: XML Parsing Message-ID: <3766830b-b0fb-45b7-a227-56244ed84bd6@v15g2000yqn.googlegroups.com> Hello, I have a xml file which is as follows: $0000 PID .............. ............... Can anyone please tell me how to get content of tag.. that is, how to extract the data "![CDATA[Parameter Identifiers Supported - $01 to $20]]" Thanks, Girish... From steve at holdenweb.com Tue Feb 24 23:51:41 2009 From: steve at holdenweb.com (Steve Holden) Date: Tue, 24 Feb 2009 23:51:41 -0500 Subject: Looking for tips on running Python version 2.6 and 3.0 together on same *WINDOWS* machine In-Reply-To: References: Message-ID: <49A4CE5D.60702@holdenweb.com> steve.ferg.bitbucket at gmail.com wrote: > I'm looking for tips on installing and running Python version 2.6 and > version 3.0 together on same Windows machine. > > I'd like to install both 2.6 and 3.0 together on the same Windows > (Vista) machine, so I can test programs under both versions. > > Is it possible to install both versions on the same Windows machine in > such a way that they are both asily available and don't interfere with > one another? I'm concerned, for example, that if I install both, the > second installation will over-write some Python entry in the registry. > > I'd like something fairly simple -- I will be sharing this information > with others in my workgroup for whom virtualenv is not an option. > > I googled around, but couldn't find anything that seemed to address > this specific question. If anybody knows of a URL with this > information (a "2 to 3 Conversion FAQs"?) that would be great. > > Any help would be greatly appreciated. > It's easy - the registry isn't used except to associate files. The associations are made with the most-recently-installed version. I currently have 2.4, 2.5, 2.6 and 3.0 on my Windows machine. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From lists at cheimes.de Tue Feb 24 23:55:34 2009 From: lists at cheimes.de (Christian Heimes) Date: Wed, 25 Feb 2009 05:55:34 +0100 Subject: Problem with os.system() In-Reply-To: <452516e1-3708-4d82-aa8c-907169b985e3@v15g2000yqn.googlegroups.com> References: <452516e1-3708-4d82-aa8c-907169b985e3@v15g2000yqn.googlegroups.com> Message-ID: venutaurus539 at gmail.com schrieb: > Hello, > I am facing problems while using os.system() of python for > copying a file from source to destination where the file name is in > unicode (multi lingual characters).My python interpreter is trying to > convert them to ascii and is failing. I tried giving unicode string as > input for the function something like: > > c = u"copy "+"\""+full_path+"\" "+dest > os.system (c) First of all do not use os.system() to run external programs. You'll get in all sorts of trouble like quoting. You are far better of with the subprocess module. Second, why are you using an external program at all? The shutil module contains multiple functions to copy a file or directory. import shutil shutil.copy(source, dest) Christian From lists at cheimes.de Tue Feb 24 23:57:43 2009 From: lists at cheimes.de (Christian Heimes) Date: Wed, 25 Feb 2009 05:57:43 +0100 Subject: single thread decrement a semaphore object more than once? In-Reply-To: References: Message-ID: birdsong wrote: > I searched but didn't see this already discussed, sorry if I didn't > search hard enough. > > Can I decrement a semaphore's counter within the same thread more than > once? I'd like to set hard and soft limits in a server I'm writing. > The server upon initialization would create a semaphore: > > threading.Semaphore(100) Yes, you are not restricted to multiple threads. A semaphore ensures that the counter is thread safe. It doesn't force you to use threads. Christian From martin at v.loewis.de Wed Feb 25 00:20:11 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 25 Feb 2009 06:20:11 +0100 Subject: Looking for tips on running Python version 2.6 and 3.0 together on same *WINDOWS* machine In-Reply-To: References: Message-ID: <49A4D50B.4030803@v.loewis.de> > It's easy - the registry isn't used except to associate files. The > associations are made with the most-recently-installed version. > > I currently have 2.4, 2.5, 2.6 and 3.0 on my Windows machine. In addition, at install time, there is the choice of not creating associations (i.e. links what interpreter should be invoked if you double-click a .py file, and what version of IDLE should start when you select Edit from the context menu). So if you install 2.6 first, then 3.0, but deselect the installation of associations, 2.6 will continue to be associated with the .py, .pyw, and .pyc extensions. Regards, Martin From venutaurus539 at gmail.com Wed Feb 25 00:28:27 2009 From: venutaurus539 at gmail.com (venutaurus539 at gmail.com) Date: Tue, 24 Feb 2009 21:28:27 -0800 (PST) Subject: Problem with os.system() References: <452516e1-3708-4d82-aa8c-907169b985e3@v15g2000yqn.googlegroups.com> Message-ID: <5e5e1d83-4950-42e9-bf1d-51fa6ff5eeaa@d19g2000yqb.googlegroups.com> On Feb 25, 9:55?am, Christian Heimes wrote: > venutaurus... at gmail.com schrieb: > > > Hello, > > ? ? ? ? ?I am facing problems while using os.system() of python for > > copying a file from source to destination where the file name is in > > unicode (multi lingual characters).My python interpreter is trying to > > convert them to ascii and is failing. I tried giving unicode string as > > input for the function something like: > > > c = u"copy "+"\""+full_path+"\" "+dest > > os.system (c) > > First of all do not use os.system() to run external programs. You'll get > in all sorts of trouble like quoting. You are far better of with the > subprocess module. > > Second, why are you using an external program at all? The shutil module > contains multiple functions to copy a file or directory. > > import shutil > shutil.copy(source, dest) > > Christian Thanks Christian for your reply,will definitely try. From wuwei23 at gmail.com Wed Feb 25 00:38:35 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 24 Feb 2009 21:38:35 -0800 (PST) Subject: XML Parsing References: <3766830b-b0fb-45b7-a227-56244ed84bd6@v15g2000yqn.googlegroups.com> Message-ID: <660eae9c-c46a-407d-8e35-b18e2915a3fe@p20g2000yqi.googlegroups.com> On Feb 25, 2:50?pm, Girish wrote: > Can anyone please tell me how to get content of tag.. that > is, how to extract the data "![CDATA[Parameter Identifiers Supported - > $01 to $20]]" Was there something in particular about Jean-Paul Calderone's solution that didn't satisfy you? http://tinyurl.com/azgo5j From lie.1296 at gmail.com Wed Feb 25 00:43:47 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 25 Feb 2009 05:43:47 +0000 (UTC) Subject: XML Parsing References: <3766830b-b0fb-45b7-a227-56244ed84bd6@v15g2000yqn.googlegroups.com> Message-ID: On Tue, 24 Feb 2009 20:50:20 -0800, Girish wrote: > Hello, > > I have a xml file which is as follows: > > > > > $0000 > PID > to $20]]> > legislated PIDs]]> > .............. > ............... > > Can anyone please tell me how to get content of tag.. that is, > how to extract the data "![CDATA[Parameter Identifiers Supported - $01 > to $20]]" > > Thanks, > Girish... The easy one is to use re module (Regular expression). # untested import re signal_pattern = re.compile('(.*)') signals = signal_pattern.findall(xmlstring) also, you may also use the xml module, which will be more reliable if you have data like this: blah, >>> import xml.dom.minidom >>> xmldata = xml.dom.minidom.parse(open('myfile.xml')) >>> for node in xmldata.getElementsByTagName('Signal'): print node.toxml() ... From janandith at gmail.com Wed Feb 25 00:54:49 2009 From: janandith at gmail.com (janandith jayawardena) Date: Wed, 25 Feb 2009 11:24:49 +0530 Subject: Is there a way to increase memory allocated to the python interpreter Message-ID: <225bedee0902242154y245fda96o48f6b53ea2019fc@mail.gmail.com> Hi, Is there a way to configure the amount of memory allocated to the python interpreter. Can it be increased or decreased using an argument like in the Java Virtual Machine. thanks, Janandith. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ssalam at gmail.com Wed Feb 25 00:55:21 2009 From: ssalam at gmail.com (Shah Sultan Alam) Date: Wed, 25 Feb 2009 11:25:21 +0530 Subject: Does Paramiko 1.7.2 and 1.6.4 work with CentOS 4 Message-ID: Hi Groups, Can you please help me on the following... 1. Does Paramiko 1.7.2 and 1.6.4 work with CentOS 4 2. If yes, what is the exact 'yum' command to install paramiko on CentOS 4? I have tried all possible ones without success. yum install paramiko yum install python-paramiko(with and without version numbers) python-paramiko.noarch Installing it without yum throws dependency problems which are never ending : starting with python-crypto and python(abi) - which I am unable to find. Is there any change that has to be made to the yum repository to point it to look in a different place? 3. Alternatively, I also have apt-get on the CentOS box - can you tell me some repos that I can add for apt-get as well? Regds Shah From hrishys at yahoo.co.uk Wed Feb 25 01:09:25 2009 From: hrishys at yahoo.co.uk (hrishy) Date: Wed, 25 Feb 2009 06:09:25 +0000 (GMT) Subject: XML Parsing In-Reply-To: Message-ID: <498059.69062.qm@web27404.mail.ukl.yahoo.com> Hi I am just a python enthusiast and not a python user but was just wundering why didnt the list members come up with or recommen XPATH based solution which i think is very elegant for this type of a problem isnt it ? regards Hrishy --- On Wed, 25/2/09, Lie Ryan wrote: > From: Lie Ryan > Subject: Re: XML Parsing > To: python-list at python.org > Date: Wednesday, 25 February, 2009, 5:43 AM > On Tue, 24 Feb 2009 20:50:20 -0800, Girish wrote: > > > Hello, > > > > I have a xml file which is as follows: > > > > > > > > Id="pid_031605_093137_283"> > > > $0000 > > PID > > Identifiers Supported - $01 > > to $20]]> > > PID indicates which > > legislated PIDs]]> > > .............. > > ............... > > > > Can anyone please tell me how to get content of > tag.. that is, > > how to extract the data "![CDATA[Parameter > Identifiers Supported - $01 > > to $20]]" > > > > Thanks, > > Girish... > > The easy one is to use re module (Regular expression). > > # untested > import re > signal_pattern = > re.compile('(.*)') > signals = signal_pattern.findall(xmlstring) > > also, you may also use the xml module, which will be more > reliable if you > have data like this: attr="blooo">blah, > > >>> import xml.dom.minidom > >>> xmldata = > xml.dom.minidom.parse(open('myfile.xml')) > >>> for node in > xmldata.getElementsByTagName('Signal'): print > node.toxml() > ... > > -- > http://mail.python.org/mailman/listinfo/python-list From jason.scheirer at gmail.com Wed Feb 25 01:38:48 2009 From: jason.scheirer at gmail.com (Jason Scheirer) Date: Tue, 24 Feb 2009 22:38:48 -0800 (PST) Subject: Does Paramiko 1.7.2 and 1.6.4 work with CentOS 4 References: Message-ID: <134f4359-2b76-4295-aaeb-191c937fc515@l16g2000yqo.googlegroups.com> On Feb 25, 12:55?am, Shah Sultan Alam wrote: > Hi Groups, > ?Can you please help me on the following... > > 1. Does Paramiko 1.7.2 and 1.6.4 work with CentOS 4 > > 2. If yes, what is the exact 'yum' command to install paramiko on CentOS 4? > I have tried all possible ones without success. > > ? ? ? ? yum install paramiko > ? ? ? ? yum install python-paramiko(with and without version numbers) > ? ? ? ? python-paramiko.noarch > > Installing it without yum throws dependency problems which are never > ending : starting with python-crypto and python(abi) - which I am > unable to find. > > Is there any change that has to be made to the yum repository to point > it to look in a different place? > > 3. Alternatively, I also have apt-get on the CentOS box - can you tell > me some repos that I can add for apt-get as well? > > Regds > Shah This may be a question better directed at the CentOS mailing list as I doubt anyone here is a CentOS package maintainer for paramiko. You're going to need to build it yourself if it's not in yum. Make sure you have the python development headers installed, and issue the commands: wget http://www.lag.net/paramiko/download/paramiko-1.7.4.tar.gz tar xzf paramiko-1.7.4.tar.gz cd paramiko-1.7.4 python setup.py build su -c "python setup.py install" Alternately, you can issue python setup.py bdist_rpm to get an RPM you can install on other machines as well (it will show up in the ./dist/ directory relative to setup.py). Good luck. From lie.1296 at gmail.com Wed Feb 25 01:48:30 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 25 Feb 2009 17:48:30 +1100 Subject: XML Parsing In-Reply-To: <498059.69062.qm@web27404.mail.ukl.yahoo.com> References: <498059.69062.qm@web27404.mail.ukl.yahoo.com> Message-ID: <1235544510.6745.8.camel@lieryan-laptop> On Wed, 2009-02-25 at 06:09 +0000, hrishy wrote: > Hi > > I am just a python enthusiast and not a python user but was just wundering why didnt the list members come up with or recommen XPATH based solution > which i think is very elegant for this type of a problem isnt it ? Did you mean XQuery? Depending on the need, XQuery might be an overkill. And don't forget that XQuery is still an obscure, unknown language for most people (the de facto standard for querying is still SQL). From jason.scheirer at gmail.com Wed Feb 25 01:49:19 2009 From: jason.scheirer at gmail.com (Jason Scheirer) Date: Tue, 24 Feb 2009 22:49:19 -0800 (PST) Subject: Looking for tips on running Python version 2.6 and 3.0 together on same *WINDOWS* machine References: <49A4D50B.4030803@v.loewis.de> Message-ID: <61420eb1-c8a6-4651-b8f0-83b9de81a749@q9g2000yqc.googlegroups.com> On Feb 24, 9:20?pm, "Martin v. L?wis" wrote: > > It's easy - the registry isn't used except to associate files. The > > associations are made with the most-recently-installed version. > > > I currently have 2.4, 2.5, 2.6 and 3.0 on my Windows machine. > > In addition, at install time, there is the choice of not creating > associations (i.e. links what interpreter should be invoked if you > double-click a .py file, and what version of IDLE should start > when you select Edit from the context menu). > > So if you install 2.6 first, then 3.0, but deselect the installation > of associations, 2.6 will continue to be associated with the > .py, .pyw, and .pyc extensions. > > Regards, > Martin Technically not true. Python DOES use the registry, but it's per- version and isolated from each other. Each installs some configuration data in HKEY_LOCAL_MACHINE\\Software\Python\PythonCore\MAJOR.MINOR, so you'll have stuff in HKLM\\Software\Python\PythonCore\2.6 and HKLM\ \Software\Python\PythonCore\3.0. And yes, this DOES mean you can't have 2.6 and 2.6.1 cleanly installed on the machine at the same time. As long as you keep your .py and .pyw files associated with the preferred Python interpreter (2.6 I'm assuming) and EXPLICTLY call C: \Python30\Python.exe when you want to run on 3.0, you're golden. From venutaurus539 at gmail.com Wed Feb 25 02:10:37 2009 From: venutaurus539 at gmail.com (venutaurus539 at gmail.com) Date: Tue, 24 Feb 2009 23:10:37 -0800 (PST) Subject: Finding the attributes of a file Message-ID: <08b7c6a1-0de0-4aa7-b1c7-6fb30013aa5d@e24g2000vbe.googlegroups.com> Hello all, I am writing an application which has to identify the archived files in a given directory.I've tried using the function i = win32api.GetFileAttributes (full_path) to obtain the attributes.But am unable to identify based on the value it returns as it is returning 5152, 13856 etc for different files but all of them are archived. Is there any way to come to a conclusion using these numbers about whether a file is archived or not. Thanks in advance, Venu From hrishys at yahoo.co.uk Wed Feb 25 02:17:30 2009 From: hrishys at yahoo.co.uk (hrishy) Date: Wed, 25 Feb 2009 07:17:30 +0000 (GMT) Subject: XML Parsing In-Reply-To: <1235544510.6745.8.camel@lieryan-laptop> Message-ID: <574132.90483.qm@web27405.mail.ukl.yahoo.com> Hi Something like this <49A311C3.80707@gmail.com> Message-ID: <00c101c9971c$8f1709e0$0d00a8c0@hendrik> "Rhodri James" wrote: > A souq is a bazaar :-) > > Well, close enough anyway. It's another arabic word that translates as > "market" in both the mercantile and financial senses, I believe. Maybe > I've just read too much arabic-themed fiction, but I was surprised not > to find the word in my trusty Chambers. I seem to remember seeing the word being variously spelled "suq" and/or "suk". - Hendrik From lie.1296 at gmail.com Wed Feb 25 02:33:14 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 25 Feb 2009 07:33:14 +0000 (UTC) Subject: XML Parsing References: <1235544510.6745.8.camel@lieryan-laptop> <574132.90483.qm@web27405.mail.ukl.yahoo.com> Message-ID: Are you searching for answer or searching for another people that have the same answer as you? :) "Many roads lead to Rome" is a very famous quotation... From gregory.matous at gmail.com Wed Feb 25 02:34:21 2009 From: gregory.matous at gmail.com (Dutch Masters) Date: Tue, 24 Feb 2009 23:34:21 -0800 (PST) Subject: Looking for tips on running Python version 2.6 and 3.0 together on same *WINDOWS* machine References: Message-ID: <18b6c7ce-02db-498b-886d-0b811fb51e2e@v13g2000vbb.googlegroups.com> There is some documentation on the subject at: http://docs.python.org/using/windows.html In general, there are several options in maintaining separate environments: 1) Create a separate user for each environment. This allows you to keep things such as Path and file associations so that you are selecting a certain install whenever you are logged in as that user. This may NOT be an option on Vista though. The Python installer will tell you whether you can install for only the current user. 2) Use batch scripts to setup your PATH and PYTHONPATH. This will not solve the file association problem, but you can probably set up your "SEND TO" folder to handle the different versions. 3) Use something like virtualenv. I'm using option 2). A couple more hints: if you are using a windows installer for a third- party lib, (like wxpython), the installer will look in the registry for a matching python installation. If there isn't one, it shouldn't be a problem, just install it where it needs to go. (in the appropriate Python folder). You can also use the repair option for the python installer to get the registry set up for a particular install. For example, if you installed Python 3, but want to then use associations with 2.6, just use repair with the 2.6 installer. (Not sure what else repair does though) Finally, you can use the --prefix option to setup.py to get installs to go where you want on win. From sjmachin at lexicon.net Wed Feb 25 02:37:24 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 24 Feb 2009 23:37:24 -0800 (PST) Subject: Finding the attributes of a file References: <08b7c6a1-0de0-4aa7-b1c7-6fb30013aa5d@e24g2000vbe.googlegroups.com> Message-ID: <8d4fef20-97d2-4e6b-82aa-fbb125ae41b8@h5g2000yqh.googlegroups.com> On Feb 25, 6:10?pm, "venutaurus... at gmail.com" wrote: > Hello all, > ? ? ? ? ? ?I am writing an application which has to identify the > archived files in a given directory.I've tried using the function > i = win32api.GetFileAttributes (full_path) > > to obtain the attributes.But am unable to identify based on the value > it returns as it is returning 5152, 13856 etc for different files but > all of them are archived. Is there any way to come to a conclusion > using these numbers about whether a file is archived or not. Two questions: (1) What didn't you understand on the MSDN page that comes up when you fed "GetFileAttributes" into your googler and selected the first hit? """ The attributes can be one or more of the following values. Return code/value Description [... and the very first one is ...] FILE_ATTRIBUTE_ARCHIVE 320x20 A file or directory that is an archive file or directory. Applications use this attribute to mark files for backup or removal. """ Sure it slows you down slightly by having to mentally insert the missing space in "320x20", but sheeeeesh it's not that hard to find. (2) Where did you get the idea that this bit means archivED (i.e completed, past tense)? AFAIK it's always been documented the MSDN page says, with a hopeful or future-tense meaning. Of course as long as the setters of the bit and the getters of the bit are using the same protocol, it's not a problem ... could be a bit of a problem ensuring you know who all the getters and setters are, and ensuring that they are under your control. HTH, John From venutaurus539 at gmail.com Wed Feb 25 02:40:22 2009 From: venutaurus539 at gmail.com (venu madhav) Date: Wed, 25 Feb 2009 13:10:22 +0530 Subject: Problem in identifying an archived file in Windows Message-ID: Hello all, I am writing an application which has to identify the archived files in a given directory.I've tried using the function i = win32api.GetFileAttributes (full_path) to obtain the attributes.But am unable to identify based on the value it returns as it is returning 5152, 13856 etc for different files but all of them are archived. Is there any way to come to a conclusion using these numbers about whether a file is archived or not. Thanks in advance, Venu -------------- next part -------------- An HTML attachment was scrubbed... URL: From kom2 at centrum.cz Wed Feb 25 02:50:27 2009 From: kom2 at centrum.cz (Kom2) Date: Tue, 24 Feb 2009 23:50:27 -0800 (PST) Subject: Running script in module initialization References: <56d0c8e4-c7cd-4b3b-aef0-7dc92996efb3@m15g2000vbp.googlegroups.com> <73cffb49-642a-4d6f-8c28-cc0ee5bb738b@z1g2000yqn.googlegroups.com> Message-ID: <6706d803-243d-4e28-8ef0-9aa37b59c0b6@o11g2000yql.googlegroups.com> On 24 ?n, 15:25, "Gabriel Genellina" wrote: > En Mon, 23 Feb 2009 05:51:27 -0200, Kom2 escribi?: > > > > > On 20 ?n, 16:27, Steve Holden wrote: > >> Kom2 wrote: > >> > Hello, > >> > I'm trying to convert my project from python 2.5 to python 3.0 and I > >> > have the following problem. My project is PYD library written in C++. > >> > So I have this PyInit_ModuleName function containing PyModule_Create > >> > call and this function also call some script with declarations: > > >> > ? ?PyObject* m; > > >> > ? ?m = PyModule_Create(&PyVRDAModule); > >> > ? ?if (m == NULL) { > >> > ? ? ? return NULL; > >> > ? ?} > >> > ? ?PyObject *d, *v; > >> > ? ?d = PyModule_GetDict(m); > >> > ? ?v = PyRun_StringFlags(txtPyPredefinedConstants), Py_file_input, d, > >> > d, NULL); > >> > ? ?...... > > >> > txtPyPredefinedConstants is string with this content: > > >> > class CursorMoveType: > >> > ? ?First = 0 > >> > ? ?Last = 1 > >> > ? ?Next = 2 > >> > ? ?Previous = 3 > >> > ? ?Bookmark = 4 > >> > ? ?NewRecord = 5 > > >> > In Python 2.5 everything works fine, now in python3.0 > >> > PyRun_StringFlags returns NULL and I get error "__build_class__ not > >> > found". > > __build_class__ is a (hidden?) function in the builtins module. > Your module isn't completely created yet, it lacks the __builtins__ ? > attribute, so you can't execute any Python code that calls a builtin ? > function. In 2.5 the class statement was a lot simpler, but in 3.0 it ? > requires an auxiliary function (implemented as builtins.__build_class__) > You may try setting __builtins__ to the current builtins ? > (PyEval_GetBuiltins) before executing Python code. > Or, if those 7 lines are all you need, you may just write the equivalent C ? > code. > > -- > Gabriel Genellina Thanks for answer, calling PyEval_GetBuiltins could also help. I solved this issue by getting dictionary of __main__ module as global dictionary - d = PyModule_GetDict(m); PyObject* glMod = PyImport_AddModule("__main__"); if (glMod == NULL) { return NULL; } PyObject* glDict = PyModule_GetDict(glMod); v = PyRun_StringFlags(txtPyPredefinedConstants, Py_file_input, glDict, d, NULL); - and it works. From steven at REMOVE.THIS.cybersource.com.au Wed Feb 25 02:50:49 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 25 Feb 2009 07:50:49 GMT Subject: =?windows-1251?q?Re=3A_'u'__Obselete_type_=96?= it is identical to 'd'. (7) References: <01b464c4$0$18215$c3e8da3@news.astraweb.com> Message-ID: On Tue, 24 Feb 2009 15:04:05 -0800, John Machin wrote: >> I don't know what you want to report, but I've reported that obsolete >> is mispelled: >> >> http://bugs.python.org/issue5361 > > +1 Own Goal of the Year ... see > http://www.yourdictionary.com/library/misspelled.html Oh come on, it's hardly the Own Goal of the Year if it's in the (quote) "100 Most Often Misspelled Words in English". A notable own goal would be if I misspelled my own name or something. What I did was a run-of-the- mill ordinary own goal, hardly worth even noting. Besides, it's just the Time Machine in action. Come back in 10 years, and I bet "mispelled" will be accepted as a legitimate variant, just like inflammable/flammable, and in another 20 years, it will be the preferred spelling. The process is well on the way according to Google: Results 1 - 10 of about 4,850,000 for mispelled Results 1 - 10 of about 4,560,000 for misspelled Typo'ly y'rs - Stveen *wink* From david.birdsong at gmail.com Wed Feb 25 02:52:23 2009 From: david.birdsong at gmail.com (birdsong) Date: Tue, 24 Feb 2009 23:52:23 -0800 (PST) Subject: single thread decrement a semaphore object more than once? References: Message-ID: <11e41a9d-11be-4708-b47c-553ccab2e08d@t13g2000yqc.googlegroups.com> On Feb 24, 8:57?pm, Christian Heimes wrote: > birdsong wrote: > > I searched but didn't see this already discussed, sorry if I didn't > > search hard enough. > > > Can I decrement a semaphore's counter within the same thread more than > > once? ?I'd like to set hard and soft limits in a server I'm writing. > > The server upon initialization would create a semaphore: > > > threading.Semaphore(100) > > Yes, you are not restricted to multiple threads. A semaphore ensures > that the counter is thread safe. It doesn't force you to use threads. > > Christian ahh good. there will be multiple threads accessing, but yes i follow now. i guess this would have been pretty easy to test in the shell. muchas gracias. From gagsl-py2 at yahoo.com.ar Wed Feb 25 03:19:19 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 25 Feb 2009 06:19:19 -0200 Subject: Problem in identifying an archived file in Windows References: Message-ID: En Wed, 25 Feb 2009 05:40:22 -0200, venu madhav escribi?: > I am writing an application which has to identify the > archived files in a given directory.I've tried using the function > i = win32api.GetFileAttributes (full_path) > > to obtain the attributes.But am unable to identify based on the value > it returns as it is returning 5152, 13856 etc for different files but > all of them are archived. Is there any way to come to a conclusion > using these numbers about whether a file is archived or not. So you're using the pywin32 package. It comes with a help file (PyWin32.chm), you can open it right from the menu: Start, All Programs, Python XX, Python for Windows documentation. Go to the GetFileAttributes topic. It says "The return value is a combination of the win32con.FILE_ATTRIBUTE_* constants". Ok, which constants? Let Python tell us: py> import win32con py> [name for name in dir(win32con) if name.startswith("FILE_ATTRIBUTE_")] ['FILE_ATTRIBUTE_ARCHIVE', 'FILE_ATTRIBUTE_ATOMIC_WRITE', 'FILE_ATTRIBUTE_COMPRESSED', 'FILE_ATTRIBUTE_DIRECTORY', 'FILE_ATTRIBUTE_HIDDEN', 'FILE_ATTRIBUTE_NORMAL', 'FILE_ATTRIBUTE_READONLY','FILE_ATTRIBUTE_SYSTEM', 'FILE_ATTRIBUTE_TEMPORARY', 'FILE_ATTRIBUTE_XACTION_WRITE'] What do they mean? The best source is the Microsoft site. There is a very convenient link in the help topic: "Search for GetFileAttributes at msdn, google or google groups." Click on msdn, the first result is You apparently are looking for FILE_ATTRIBUTE_ARCHIVE. -- Gabriel Genellina From hrishys at yahoo.co.uk Wed Feb 25 03:20:20 2009 From: hrishys at yahoo.co.uk (hrishy) Date: Wed, 25 Feb 2009 08:20:20 +0000 (GMT) Subject: XML Parsing In-Reply-To: Message-ID: <581368.29674.qm@web27405.mail.ukl.yahoo.com> Hi Lie I am not a python guy but very interested in the langauge and i consider the people on this list to be intelligent and was wundering why you people did not suggest xpath for this kind of a problem just curious and willing to learn. I am searching for a answer but the question is why not use xpath to extract xml text from a xml doc ? regards Hrishy --- On Wed, 25/2/09, Lie Ryan wrote: > From: Lie Ryan > Subject: Re: XML Parsing > To: python-list at python.org > Date: Wednesday, 25 February, 2009, 7:33 AM > Are you searching for answer or searching for another people > that have > the same answer as you? :) > > "Many roads lead to Rome" is a very famous > quotation... > > -- > http://mail.python.org/mailman/listinfo/python-list From bruno.42.desthuilliers at websiteburo.invalid Wed Feb 25 03:45:23 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 25 Feb 2009 09:45:23 +0100 Subject: pep 8 constants In-Reply-To: References: Message-ID: <49a50517$0$3567$426a74cc@news.free.fr> Brendan Miller a ?crit : > PEP 8 doesn't mention anything about using all caps to indicate a constant. > > Is all caps meaning "don't reassign this var" a strong enough > convention to not be considered violating good python style? I see a > lot of people using it, but I also see a lot of people writing > non-pythonic code... so I thought I'd see what the consensus is. Most - if not all - of the python code I've seen so far used this convention, and I always used (and respected) it myself. From bruno.42.desthuilliers at websiteburo.invalid Wed Feb 25 03:48:27 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 25 Feb 2009 09:48:27 +0100 Subject: pep 8 constants In-Reply-To: <87fxje4lqh.fsf@benfinney.id.au> References: <87fxje4lqh.fsf@benfinney.id.au> Message-ID: <49a505cf$0$3567$426a74cc@news.free.fr> Ben Finney a ?crit : (snip - about using ALL_CAPS for pseudo-constants) > Perhaps I'd even > argue for an update to PEP 8 that endorses this as conventional. +1 I've been a bit surprised last time I checked PEP8 to find out this wasn't already the case - I would have sweared it was. From bruno.42.desthuilliers at websiteburo.invalid Wed Feb 25 04:03:17 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 25 Feb 2009 10:03:17 +0100 Subject: pep 8 constants In-Reply-To: References: Message-ID: <49a50949$0$3556$426a34cc@news.free.fr> Brian Allen Vanderburg II a ?crit : > bockman at virgilio.it wrote: >> Constants would be a nice addition in python, sure enough. >> But I'm not sure that this can be done without a run-time check every >> time >> the constant is used, and python is already slow enough. Maybe a check >> that is disabled when running with optimizing flags ? >> >> But I'm sure this discussion has been already made and the FINAL WORD has >> been already spoken. >> >> > One idea to make constants possible would be to extend properties to be > able to exist at the module level as well as the class level: > > @property > def pi(): > return 3.14159..... > > print(pi) # prints 3.14159.... > pi=32 # Raise an error Cannot set attribute ... > There are a couple problems with this suggestion: - it would require modifying lookup rules to allow the protocol descriptor to be invoked on instance attributes[1] - which is not actually the case, by design. - it adds the overhead of a method and a function call for what is mostly a simple "constant" attribute lookup. FWIW, while it would already work for class-level pseudo-constants (using a very simple custom descriptor), I'd qualify such usage as a WTF. From bruno.42.desthuilliers at websiteburo.invalid Wed Feb 25 04:07:00 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 25 Feb 2009 10:07:00 +0100 Subject: pep 8 constants In-Reply-To: References: <4978DD2E.1090008@aim.com> Message-ID: <49a50a28$0$25565$426a34cc@news.free.fr> Ethan Furman a ?crit : > Steve Holden wrote: >> Brian Allen Vanderburg II wrote: >> (snip) >>> One idea to make constants possible would be to extend properties to be >>> able to exist at the module level as well as the class level: >>> >>> @property >>> def pi(): >>> return 3.14159..... >>> >>> print(pi) # prints 3.14159.... >>> pi=32 # Raise an error Cannot set attribute ... >>> >> >> I don't understand why this would print 3.14159 ... instead of > __math__.pi>, or whatever. >> >> property would clearly have to do something very different in module >> scope in order to make this work. >> > > --> class tester(object): > ... @property > ... def pi(self): > ... return 3.141596 > ... > --> testee = tester() > --> testee.pi > 3.1415959999999998 > > Looks like that's how property works, so the same behavior on a module > level would do as Brian suggests. s/module/instance/ At runtime, modules are instances of the module type - so 'module-level' names are really instance attributes of the module instance -, and the descriptor protocol is only invoked for class attributes. From jarausch at igpm.rwth-aachen.de Wed Feb 25 04:16:38 2009 From: jarausch at igpm.rwth-aachen.de (Helmut Jarausch) Date: Wed, 25 Feb 2009 10:16:38 +0100 Subject: variable length tuple assignment Message-ID: <70kgjnFbqktdU1@mid.dfncis.de> Sorry if this is too simple but I couldn't find. I vaguely remember there is a means to assign a variable length tuple and catch the 'rest' like S="a,b,c,d" (A,B,) = S.split(',') I know I could do SL= split(',') (A,B)=SL[:2] Rest= SL[2:] but is there some shorthand for this? Many thanks for a hint, Helmut Jarausch Lehrstuhl fuer Numerische Mathematik RWTH - Aachen University D 52056 Aachen, Germany From mathieu.malaterre at gmail.com Wed Feb 25 04:26:58 2009 From: mathieu.malaterre at gmail.com (mathieu) Date: Wed, 25 Feb 2009 01:26:58 -0800 (PST) Subject: =?windows-1252?Q?Re=3A_=27u=27__Obselete_type_=96_it_is_identical_to_=27d=27=2E__?= =?windows-1252?Q?=287=29?= References: <01b464c4$0$18215$c3e8da3@news.astraweb.com> Message-ID: On Feb 24, 11:06 pm, Steven D'Aprano wrote: > mathieu wrote: > > I did not know where to report that: > > > 'u' Obselete type ? it is identical to 'd'. (7) > > >http://docs.python.org/library/stdtypes.html#string-formatting > > > Thanks > > If you google on "python bug tracker" the first link is the correct one. > > I don't know what you want to report, but I've reported that obsolete is > mispelled: > > http://bugs.python.org/issue5361 Thanks. Now I know :) From mathieu.malaterre at gmail.com Wed Feb 25 04:27:39 2009 From: mathieu.malaterre at gmail.com (mathieu) Date: Wed, 25 Feb 2009 01:27:39 -0800 (PST) Subject: =?windows-1252?B?UmU6ICd1JyBPYnNlbGV0ZSB0eXBlIJYgaXQgaXMgaWRlbnRpY2FsIHRvICdkJy4gKDc=?= =?windows-1252?B?KQ==?= References: <31fa575a-cc0d-4830-ae23-0a784fa3361f@13g2000yql.googlegroups.com> Message-ID: <93018776-530b-43b3-b728-e593d8ccbb97@x38g2000yqj.googlegroups.com> On Feb 24, 9:24 pm, John Machin wrote: > On Feb 25, 4:48 am, mathieu wrote: > > > I did not know where to report that: > > > 'u' Obselete type ? it is identical to 'd'. (7) > > >http://docs.python.org/library/stdtypes.html#string-formatting > > So what's your problem with that? Do you believe that 'u' is not > accepted? That 'u' is not identical to 'd' and thus the doc should be > rewritten as "its behaviour is identical to that of 'd'"? That the > behaviour of 'u' is NOT identical to that of 'd'? That 'u' should not > be documented? That 'u' should not be described as obselete? ^^^^^^^^ lol :) From clp2 at rebertia.com Wed Feb 25 04:41:54 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 25 Feb 2009 01:41:54 -0800 Subject: variable length tuple assignment In-Reply-To: <70kgjnFbqktdU1@mid.dfncis.de> References: <70kgjnFbqktdU1@mid.dfncis.de> Message-ID: <50697b2c0902250141s3f19a31eye857c4a637f0d7ff@mail.gmail.com> On Wed, Feb 25, 2009 at 1:16 AM, Helmut Jarausch wrote: > Sorry if this is too simple but I couldn't find. > > I vaguely remember there is a means to assign a variable length tuple > and catch the 'rest' ?like > > S="a,b,c,d" > > (A,B,) = S.split(',') In Python 3.0 (IIRC): A, B, *rest = S.split(',') Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From robin at reportlab.com Wed Feb 25 05:07:24 2009 From: robin at reportlab.com (Robin Becker) Date: Wed, 25 Feb 2009 10:07:24 +0000 Subject: pep 8 constants In-Reply-To: <49a50a28$0$25565$426a34cc@news.free.fr> References: <4978DD2E.1090008@aim.com> <49a50a28$0$25565$426a34cc@news.free.fr> Message-ID: <49A5185C.9080906@chamonix.reportlab.co.uk> well this sort of awful hackery will allow you to put read only constants on an existing module >>> import reportlab >>> reportlab.__class__ >>> class MyModule(reportlab.__class__): ... @property ... def pi(self): ... return 3 ... >>> z=MyModule('reportlab') >>> z.__dict__.update(reportlab.__dict__) >>> z.pi 3 >>> import sys >>> sys.modules['reportlab']=z >>> del reportlab >>> import reportlab >>> reportlab.pi 3 >>> reportlab.pi=4 Traceback (most recent call last): File "", line 1, in AttributeError: can't set attribute >>> so I guess if you write your own module class and then use a special importer you can create module like objects with read only attributes. -- Robin Becker From rogerb at rogerbinns.com Wed Feb 25 05:09:10 2009 From: rogerb at rogerbinns.com (Roger Binns) Date: Wed, 25 Feb 2009 02:09:10 -0800 Subject: Is there a way to increase memory allocated to the python interpreter In-Reply-To: <225bedee0902242154y245fda96o48f6b53ea2019fc@mail.gmail.com> References: <225bedee0902242154y245fda96o48f6b53ea2019fc@mail.gmail.com> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 janandith jayawardena wrote: > Is there a way to configure the amount of memory allocated to the python > interpreter. Can it be increased or decreased using an argument like in > the Java Virtual Machine. Java needs the memory allocation number because of the way garbage collection is done (or at least used to be done). The CPython interpreter doesn't have an explicit limit and will use all the address space the operating system will let it have as needed. (That typically works out as around 2GB for a 32 bit process and exhausting swap space on a 64 bit process). If you want to prevent using more than a certain amount, then use functionality provided by your operating system. On Unix/Linux systems the ulimit command will do the trick. Roger -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkmlGMMACgkQmOOfHg372QQeMACfVhyccV91nU0WZswc2CNg8KMv SlEAoMINnO48FoDp0vgxROOWAjYp2tPG =Vjcf -----END PGP SIGNATURE----- From rogerb at rogerbinns.com Wed Feb 25 05:11:38 2009 From: rogerb at rogerbinns.com (Roger Binns) Date: Wed, 25 Feb 2009 02:11:38 -0800 Subject: Unix Change Passwd Python CGI In-Reply-To: <9999810b0902240719y750fba0dp43a87a9d840ff949@mail.gmail.com> References: <9999810b0902240719y750fba0dp43a87a9d840ff949@mail.gmail.com> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Derek Tracy wrote: > Apache is running on the same system that needs the password changed. I > need to keep security high and can not install additional modules at > this time. > > I just need a general direction to start looking, and I do not have > expect installed on the system. I recommend looking in the Samba source code where they have a program that does just that. Roger -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkmlGVcACgkQmOOfHg372QTZHACdFG0+Ls2Su/jRqkc4YZyxXK35 N7AAoNKfd7bMypR7b6Ex6auaU/9D4rKa =POal -----END PGP SIGNATURE----- From wongo888 at gmail.com Wed Feb 25 05:17:33 2009 From: wongo888 at gmail.com (wongobongo) Date: Wed, 25 Feb 2009 02:17:33 -0800 (PST) Subject: Python Image Library IOError - cannot find JPEG decoder? References: Message-ID: <179a3248-0179-401e-8887-0b61e5821219@c11g2000yqj.googlegroups.com> On Feb 24, 9:34?am, Dario Traverso wrote: > I've been trying to install the Python Image Library ?(PIL) on my Mac ? > OSX Leopard laptop, but have been running into some difficulties. > > I've built the library, using the included setup.py ?script. The build ? > summary checks out ok, and sounds the option libraries to all be ? > found. I grabbed both libjpeg and freetype2 ?using ?fink. > > -------------------------------------------------------------------- > PIL 1.1.6 BUILD SUMMARY > -------------------------------------------------------------------- > version ? ? ? 1.1.6 > platform ? ? ?darwin 2.5.1 (r251:54863, Jan 13 2009, 10:26:13) > ? ? ? ? ? ? ? [GCC 4.0.1 (Apple Inc. build 5465)] > -------------------------------------------------------------------- > --- TKINTER support ok > --- JPEG support ok > --- ZLIB (PNG/ZIP) support ok > --- FREETYPE2 support ok > -------------------------------------------------------------------- > > However, ?I then run the included self test, and 1 out of 57 tests ? > fails. I receive an IOError. Specifically: > > ***************************************************************** > Failure in example: _info(Image.open("Images/lena.jpg")) > from line #24 of selftest.testimage > Exception raised: > Traceback (most recent call last): > ? File "./doctest.py", line 499, in _run_examples_inner > ? ? exec compile(source, "", "single") in globs > ? File "", line 1, in > ? File "./selftest.py", line 22, in _info > ? ? im.load() > ? File "PIL/ImageFile.py", line 180, in load > ? ? d = Image._getdecoder(self.mode, d, a, self.decoderconfig) > ? File "PIL/Image.py", line 375, in _getdecoder > ? ? raise IOError("decoder %s not available" % decoder_name) > IOError: decoder jpeg not available > 1 items had failures: > ? ?1 of ?57 in selftest.testimage > ***Test Failed*** 1 failures. > *** 1 tests of 57 failed. > > I've followed all of the installation instructions exactly. The build ? > summary reported everything was "ok". What could be the problem here. ? > Libjpeg-6b ?is not accessible? > > Thank you for any insight you can provide!! > > -Dario That would be my guess. Two things you may want to try: 1. Check that your Fink libraries and headers were used to make your PIL (check -I and -L settings on gcc after doing "python setup.py build_ext -i"). They should point to your Fink lib and include dirs. 2. Line 372 in PIL/Image.py has a debug print line. Try uncommenting that and see what comes out. That might give you some clues as to what is going on. You can always just call up Python in a terminal and try it out (from selftest.py doctests beginning on line 29). >>> import Image >>> def _info(im): ... im.load() ... return im.format, im.mode, im.size >>> im = Image.new("1", (128, 128)) >>> _info(im) (None, '1', (128, 128)) From bruno.42.desthuilliers at websiteburo.invalid Wed Feb 25 05:31:23 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 25 Feb 2009 11:31:23 +0100 Subject: pep 8 constants In-Reply-To: References: <4978DD2E.1090008@aim.com> <49a50a28$0$25565$426a34cc@news.free.fr> Message-ID: <49a51def$0$20681$426a74cc@news.free.fr> Robin Becker a ?crit : > well this sort of awful hackery will allow you to put read only > constants on an existing module > (snip example code) > > so I guess if you write your own module class and then use a special > importer you can create module like objects with read only attributes. > Fine technical solution. But, err, isn't all this a bit overkill for something that can easily be handled by a simple convention ?-) From gonsolo at gmail.com Wed Feb 25 05:36:05 2009 From: gonsolo at gmail.com (Gonsolo) Date: Wed, 25 Feb 2009 02:36:05 -0800 (PST) Subject: H-Index with Google Scholar Message-ID: I wrote a small script to compute the H-Index of an author. It is modeled after activestate's google search: http://code.activestate.com/recipes/523047/ Example use: hindex i daubechies Result: 49 The script: #!/usr/bin/python import httplib, urllib, re, sys from BeautifulSoup import BeautifulSoup terms = sys.argv[1:] limit = 100 params = urllib.urlencode( { 'q': "+".join( terms ), 'num': limit } ) headers = {'User-Agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'} url = '/scholar'+"?"+params conn = httplib.HTTPConnection( 'scholar.google.com' ) conn.request( "GET", url, {}, headers ) resp = conn.getresponse() cites = [] if resp.status == 200: html = resp.read() html = html.decode( 'ascii', 'ignore' ) soup = BeautifulSoup( html ) for record in soup( 'p', { 'class': 'g' } ): match = re.search("Cited by ([^<]*)", str(record)) if match != None: cite = int( match.group( 1 ) ) cites.append( cite ) else: print 'Error: ' print resp.status, resp.reason cites.sort() cites.reverse() h = 0 for cite in cites: if cite > h: h += 1 print h From robin at reportlab.com Wed Feb 25 05:56:04 2009 From: robin at reportlab.com (Robin Becker) Date: Wed, 25 Feb 2009 10:56:04 +0000 Subject: pep 8 constants In-Reply-To: <49a51def$0$20681$426a74cc@news.free.fr> References: <4978DD2E.1090008@aim.com> <49a50a28$0$25565$426a34cc@news.free.fr> <49a51def$0$20681$426a74cc@news.free.fr> Message-ID: <49A523C4.7030104@chamonix.reportlab.co.uk> Bruno Desthuilliers wrote: > Robin Becker a ?crit : >> well this sort of awful hackery will allow you to put read only >> constants on an existing module >> > (snip example code) >> >> so I guess if you write your own module class and then use a special >> importer you can create module like objects with read only attributes. >> > > Fine technical solution. But, err, isn't all this a bit overkill for > something that can easily be handled by a simple convention ?-) ...... no dispute about that :) -- Robin Becker From nick_keighley_nospam at hotmail.com Wed Feb 25 06:24:07 2009 From: nick_keighley_nospam at hotmail.com (nick_keighley_nospam at hotmail.com) Date: Wed, 25 Feb 2009 03:24:07 -0800 (PST) Subject: reading file to list References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> Message-ID: On 24 Feb, 15:00, nick_keighley_nos... at hotmail.com wrote: > On 17 Jan, 17:16, Xah Lee wrote: > > Here's a interesting toy problem posted by Drew Krause to > > comp.lang.lisp: > > > ------------------------ > > On Jan 16, 2:29 pm, Drew Krause wrote [paraphrased a bit]: > > > OK, I want to create a nested list in Lisp (always of only integers) > > from a text file, such that each line in the text file would be > > represented as a sublist in the 'imported' list. > > > example of a file's content > > > 3 10 2 > > 4 1 > > 11 18 > > > example of programing behavior > > (make-list-from-text "blob.txt") => ((3 10 2) (4 1) (11 18)) > scheme: > > (define (read-line port) > ? ? (define (rec-read-line port line) > ? ? ? ? (define next-char (peek-char port)) > ? ? ? ? (define number #f) > ? ? ? ? (cond ((eof-object? next-char) '()) > ? ? ? ? ? ? ? ((char=? next-char #\newline) (read-char port) line) > ? ? ? ? ? ? ? ((char-numeric? next-char) > ? ? ? ? ? ? ? ? ? ?(set! number (read port)) > ? ? ? ? ? ? ? ? ? ?(cons number (rec-read-line port line))) > ? ? ? ? ? ? ? ((char=? next-char #\space) > ? ? ? ? ? ? ? ? ? ?(read-char port) > ? ? ? ? ? ? ? ? ? ?(rec-read-line port line)) > ? ? ? ? ? ? ? (else (error (string-append "bad character \"" > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? (string next-char) "\""))) > ? ? )) > > ? ? (rec-read-line port '()) > ) > > (define (make-int-list port) > ? ? (define line (read-line port)) > ? ? (if (null? line) > ? ? ? ? '() > ? ? ? ? (cons line (make-int-list port)))) > > (define (make-list-from-text file) > ? ? (make-int-list (open-input-file file))) an assignment-free version (define (read-line port) (define (rec-read-line port line) (let ((next-char (peek-char port))) (cond ((eof-object? next-char) '()) ((char=? next-char #\newline) (read-char port) line) ((char-numeric? next-char) (let ((number (read port))) (cons number (rec-read-line port line)))) ((char=? next-char #\space) (read-char port) (rec-read-line port line)) (else (error (string-append "bad character \"" (string next-char) "\"")))))) (rec-read-line port '())) (define (make-int-list port) (let ((line (read-line port))) (if (null? line) '() (cons line (make-int-list port))))) (define (make-list-from-text file) (make-int-list (open-input-file file))) (define (mk) (make-list-from-text "blob.txt")) number was originally define'd but I discovered there were limits to where you could define things From nick_keighley_nospam at hotmail.com Wed Feb 25 06:34:33 2009 From: nick_keighley_nospam at hotmail.com (nick_keighley_nospam at hotmail.com) Date: Wed, 25 Feb 2009 03:34:33 -0800 (PST) Subject: reading file to list References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> Message-ID: On 17 Jan, 17:16, Xah Lee wrote: > comp.lang.lisp,comp.lang.scheme,comp.lang.functional,comp.lang.python,comp.?lang.ruby > The lisp's cons fundamentally makes nested list a pain to work with. > Lisp's nested syntax makes functional sequencing cumbersome. so hide it (define (make-list stream eos?) (let ((atom (stream))) (if (eos? atom) '() (cons atom (make-list stream eos?))))) (define (make-int-list port) (make-list (lambda () (read-line port)) null?)) the nasty cons then only appears in a single function which you can hide in a library > In the ruby code, its post-fix sequential notation (as a side effect > of its OOP notation) brings out the beauty of functional sequencing > paradigm (sometimes known as functional chain, sequencing, filtering, > unix piping). > > its list, like all modern high level langs such as perl, php, python, > javascript, don't have the lisp's cons problem. The cons destroys the > usability of lists up-front, untill you have some at least 2 full-time > years of coding lisp to utilize cons properly. (and even after that, > it is still a pain to work with, and all you gain is a bit of speed > optimization in rare cases that requires largish data, most of which > has better solutions such as a database.) is my code to build a list that bad? > Both of these problems i've published articles on. > > For more detail on the cons problem, see > the section ?The Cons Business? at > > ? Fundamental Problems of Lisp > ?http://xahlee.org/UnixResource_dir/writ/lisp_problems.html I read it. Your point seems to be "cons becomes difficult with deeply nested structures". Could you give an example? From python.list at tim.thechases.com Wed Feb 25 06:35:06 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 25 Feb 2009 05:35:06 -0600 Subject: variable length tuple assignment In-Reply-To: <50697b2c0902250141s3f19a31eye857c4a637f0d7ff@mail.gmail.com> References: <70kgjnFbqktdU1@mid.dfncis.de> <50697b2c0902250141s3f19a31eye857c4a637f0d7ff@mail.gmail.com> Message-ID: <49A52CEA.2000603@tim.thechases.com> Chris Rebert wrote: > On Wed, Feb 25, 2009 at 1:16 AM, Helmut Jarausch > wrote: >> Sorry if this is too simple but I couldn't find. >> >> I vaguely remember there is a means to assign a variable length tuple >> and catch the 'rest' like >> >> S="a,b,c,d" >> >> (A,B,) = S.split(',') > > In Python 3.0 (IIRC): > > A, B, *rest = S.split(',') As an aside, as of the last time I read the PEP[1] on this, I believe it exhausts (or attempts to exhaust) any iterator. IMHO, I think this exhausting is a bad idea because it prevents things like def numbers(start=0): i = start while True: yield i i += 1 CONST_A, CONST_B, CONST_C, *rest = numbers() which will hang in current Py3.0 until you blow a stack or overrun your heap somewhere because it will try to exhaust the infinite loop. It also changes the type from iter() to list() for the remaining content (not as grevious). I agree that the "internal star" usage needs to exhaust the iterator: A, *rest, C, D = s.split(',') but the terminal-star syntax should be a little more gracious with iterators. Anyways, my $0.02 (minus taxes, money for multiple bailouts, and deflated by economic conditions -- so not worth much :). -tkc [1] http://www.python.org/dev/peps/pep-3132/ From jarausch at igpm.rwth-aachen.de Wed Feb 25 07:21:03 2009 From: jarausch at igpm.rwth-aachen.de (Helmut Jarausch) Date: Wed, 25 Feb 2009 13:21:03 +0100 Subject: PyCrypto AES MODE_CBC - How to? Message-ID: <70krdfFc7rn0U1@mid.dfncis.de> Hi, I've just tried to write a simple example using PyCrypto's AES (CBC mode) #!/usr/bin/python from Crypto.Cipher import AES PWD='abcdefghijklmnop' Initial16bytes='0123456789ABCDEF' crypt = AES.new(PWD, AES.MODE_CBC,Initial16bytes) # crypt = AES.new(PWD, AES.MODE_ECB) txt = 'ea523a664dabaa4476d31226a1e3bab0' c = crypt.encrypt(txt) txt_plain=crypt.decrypt(c) print txt_plain Unfortunately, txt_plain differs from txt - why? (Using MODE_ECB does work however) What am I missing? Many thanks for a hint, Helmut Jarausch Lehrstuhl fuer Numerische Mathematik RWTH - Aachen University D 52056 Aachen, Germany From jarausch at igpm.rwth-aachen.de Wed Feb 25 07:25:13 2009 From: jarausch at igpm.rwth-aachen.de (Helmut Jarausch) Date: Wed, 25 Feb 2009 13:25:13 +0100 Subject: PyCrypto AES MODE_CBC - How to? In-Reply-To: <70krdfFc7rn0U1@mid.dfncis.de> References: <70krdfFc7rn0U1@mid.dfncis.de> Message-ID: <70krl9Fbuqj5U1@mid.dfncis.de> Helmut Jarausch wrote: > Hi, > > I've just tried to write a simple example using PyCrypto's > AES (CBC mode) > > #!/usr/bin/python > from Crypto.Cipher import AES > > PWD='abcdefghijklmnop' > Initial16bytes='0123456789ABCDEF' > > crypt = AES.new(PWD, AES.MODE_CBC,Initial16bytes) > # crypt = AES.new(PWD, AES.MODE_ECB) > > txt = 'ea523a664dabaa4476d31226a1e3bab0' > > c = crypt.encrypt(txt) > > txt_plain=crypt.decrypt(c) > > print txt_plain > > Unfortunately, txt_plain differs from txt - why? > (Using MODE_ECB does work however) > I just discovered that the following variant seems to work crypt = AES.new(PWD, AES.MODE_CBC,Initial16bytes) c = crypt.encrypt(txt) crypt = AES.new(PWD, AES.MODE_CBC,Initial16bytes) # <<< re-initialize txt_plain=crypt.decrypt(c) So, the crypt object seems to keep some state. I haven't seen this mentioned in the documentation. Helmut. -- Helmut Jarausch Lehrstuhl fuer Numerische Mathematik RWTH - Aachen University D 52056 Aachen, Germany From adisaurabh at gmail.com Wed Feb 25 07:26:29 2009 From: adisaurabh at gmail.com (aditya saurabh) Date: Wed, 25 Feb 2009 17:56:29 +0530 Subject: Lambda function Message-ID: <9d1b5e270902250426q63913a87q28c06844ef175326@mail.gmail.com> I defined two functions - lets say fa = lambda x: 2*x fb = lambda x: 3*x Now I would like to use fa*fb in terms of x is there a way? Thanks in advance -------------- next part -------------- An HTML attachment was scrubbed... URL: From king.seth at gmail.com Wed Feb 25 07:37:19 2009 From: king.seth at gmail.com (Seth) Date: Wed, 25 Feb 2009 04:37:19 -0800 (PST) Subject: Convert PySerial to python 3.0 References: <385a617c-1e43-4828-8edd-3f4aadce8604@c11g2000yqj.googlegroups.com> Message-ID: On Feb 24, 10:55?pm, Chris Rebert wrote: > On Tue, Feb 24, 2009 at 7:46 PM, Seth wrote: > > I am just messing around trying to get pyserial to work with 3.0. > > > I am stuck on this line: > > > if type(port) in [type(''), type(u'')] > > > how can I convert this to 3.0? I tried changing the u to a d that did > > not do anything. > > Looks like it's doing the equivalent of the pre-3.0-ism > `isinstance(port, basestring)`, but in a roundabout way. > However, since basestring doesn't exist in 3.0, either: > > if isinstance(port, str): > > Or > > if isinstance(port, bytes): > > would be the appropriate replacement. Depends (obviously) on whether > 'port' is supposed to be unicode or a byte sequence. > Without more context, I can't really say which is what you want. > > Cheers, > Chris > > -- > Follow the path of the Iguana...http://rebertia.com I implemented "if isinstance(port, str): " that seems to work for now. Currently I am running into: err, n = win32file.WriteFile(self.hComPort, data, self._overlappedWrite) TypeError: expected an object with a buffer interface Thanks From jcd at sdf.lonestar.org Wed Feb 25 07:37:22 2009 From: jcd at sdf.lonestar.org (J. Clifford Dyer) Date: Wed, 25 Feb 2009 07:37:22 -0500 Subject: XML Parsing In-Reply-To: <581368.29674.qm@web27405.mail.ukl.yahoo.com> References: <581368.29674.qm@web27405.mail.ukl.yahoo.com> Message-ID: <1235565442.6046.2.camel@mctell> Probably because you responded an hour after the question was posted, and in the dead of night. Newsgroups often move slower than that. But now we have posted a solution like that, so all's well in the world. :) Cheers, Cliff On Wed, 2009-02-25 at 08:20 +0000, hrishy wrote: > Hi Lie > > I am not a python guy but very interested in the langauge and i consider the people on this list to be intelligent and was wundering why you people did not suggest xpath for this kind of a problem just curious and willing to learn. > > I am searching for a answer but the question is > why not use xpath to extract xml text from a xml doc ? > > regards > Hrishy > > > --- On Wed, 25/2/09, Lie Ryan wrote: > > > From: Lie Ryan > > Subject: Re: XML Parsing > > To: python-list at python.org > > Date: Wednesday, 25 February, 2009, 7:33 AM > > Are you searching for answer or searching for another people > > that have > > the same answer as you? :) > > > > "Many roads lead to Rome" is a very famous > > quotation... > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > -- > http://mail.python.org/mailman/listinfo/python-list > From meesters at gmx.de Wed Feb 25 07:40:23 2009 From: meesters at gmx.de (Christian Meesters) Date: 25 Feb 2009 12:40:23 GMT Subject: glibc detected *** python: corrupted double-linked list Message-ID: <49a53c36$0$713$9b622d9e@news.freenet.de> Hoi, I have a problem using my software on my 64bit laptop, after an update of my system. The same code still runs on 32bit Intel, but on my laptop I provoke the crash in the title. The crash is caused - as narrowed down by me - by returning a static PyObject from a C-extension function. Well, now I wondering what to do? A web search delivered no relevant bug reports about glibc on my system (the recent Ubuntu 8.10). Is there a source for validated glibc for x86_64? Oh, and I'm using Ubuntu's ready- made Python package, version 2.5.2.. Anyone experiences with such problems? Any ideas? Information missing? TIA Christian PS The extension module itself can be found here: http:// svn.origo.ethz.ch/viewvc/sas-rigid/src/calc.c?revision=209&view=markup But, as I said, the code is perhaps far from being perfect, but it runs on 32bit computers. The crash occurs at line 164 - "return py_pofr;". From zelegolas at gmail.com Wed Feb 25 07:51:21 2009 From: zelegolas at gmail.com (zelegolas) Date: Wed, 25 Feb 2009 04:51:21 -0800 (PST) Subject: Python Imaging Library (PIL): create PDF from scratch References: Message-ID: Like David said now i used PIL for individual images and reportlab to generate a pdf. Thanks for your advices :) From alia_khouri at yahoo.com Wed Feb 25 07:56:03 2009 From: alia_khouri at yahoo.com (Alia Khouri) Date: Wed, 25 Feb 2009 04:56:03 -0800 (PST) Subject: sorting tasks by importance and urgency Message-ID: <48f61eb3-ab38-4a18-947a-02d091d96aeb@j8g2000yql.googlegroups.com> I recently considered the apparently simple problem is of how to algorithmically sort a set of business tasks which have an associated a value and a due_date, such that the most important and urgent are pushed to the top of the stack. The two example task types I am posing here are: (1) a bid on a contract and (2) leaverequest from an employee. To sort by importance: I just consider the proportional value of each task in relation to the total value of tasks. To sort by urgency: I used something along the lines of excel's percentrank function (http://office.microsoft.com/en-us/excel/ HP052092121033.aspx) to rank the tasks in percentage terms of the set of days_to delivery. The code is pretty self-explanatory, and I think the algorithm seems to work ok so far, but in case I have missed something or there exists some better way of doing this... from datetime import date weights = { 'Tender' : 1.0, 'LeaveRequest': 0.1 } rnd = lambda x: round(x,2) class Task(object): """a simple prioritizing Task class""" def __init__(self, kind, value, due_date=None): self.kind = kind self.value = value self.due_date = due_date if due_date else date.today() self.weight = weights[kind] self.urgency = 0.0 self.importance = 0.0 def __repr__(self): return '' % ( rnd(self.priority), rnd(self.importance), rnd (self.urgency), self.kind, self.days_to, self.value) def __cmp__(self, other): return cmp(self.priority, other.priority) @property def days_to(self): return (self.due_date - date.today()).days @property def priority(self): return self.weight * (self.importance + self.urgency) def relative_urgency(self, N, due_days): rank = due_days.index(self.days_to) return float(rank) / (N - 1) def relative_importance(self, total_value): return self.value / total_value @staticmethod def prioritize(tasks): print ("\n") N = len(tasks) total_value = sum(t.value for t in tasks) due_days = sorted([t.days_to for t in tasks], reverse=True) for i in tasks: i.importance = i.relative_importance(total_value) i.urgency = i.relative_urgency(N, due_days) for i in sorted(tasks, reverse=True): print i tasks = [ # name value due_date Task("Tender", 1000000.0, date(2009,4,1)), Task("Tender", 500400.0, date(2009,5,1)), Task("Tender", 1000000.0, date(2009,6,1)), Task("LeaveRequest", 0.0, date(2009,7,1)), Task("LeaveRequest", 0.0, date(2009,8,1)), ] if __name__ == '__main__': Task.prioritize(tasks) regards, AK From steve at holdenweb.com Wed Feb 25 07:58:09 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 25 Feb 2009 07:58:09 -0500 Subject: Free Python Training Message-ID: Not a joke, but a genuine offer extended to anyone who has already contributed to some open source project. See my blog for full details, and please pass this on to non-Python programmers who are interested in learning the language. http://holdenweb.blogspot.com/2009/02/free-python-training.html regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From cournape at gmail.com Wed Feb 25 08:06:37 2009 From: cournape at gmail.com (David Cournapeau) Date: Wed, 25 Feb 2009 22:06:37 +0900 Subject: glibc detected *** python: corrupted double-linked list In-Reply-To: <49a53c36$0$713$9b622d9e@news.freenet.de> References: <49a53c36$0$713$9b622d9e@news.freenet.de> Message-ID: <5b8d13220902250506u59452297ra9e4de0c9d907bb3@mail.gmail.com> On Wed, Feb 25, 2009 at 9:40 PM, Christian Meesters wrote: > Hoi, > > I have a problem using my software on my 64bit laptop, after an update of > my system. The same code still runs on 32bit Intel, but on my laptop I > provoke the crash in the title. The crash is caused - as narrowed down by > me - by returning a static PyObject from a C-extension function. Those errors are caused by writing in an invalid pointer, but not far enough to cause a direct segfault - just enough to corrupt core data structures of the runtime :) > > Well, now I wondering what to do? A web search delivered no relevant bug > reports about glibc on my system (the recent Ubuntu 8.10). Is there a > source for validated glibc for x86_64? Oh, and I'm using Ubuntu's ready- > made Python package, version 2.5.2.. It is very unlikely the problem is in glibc - I would check your code carefully first :) On Linux, the following are useful: - first, try to compile with as many warning flags as possible (-W -Wall -Wextra is a pretty good baseline) - then, if you have a small reproducible crash, run the extension under valgrind after having built the extension with -g. This will give you more informations. - if the above does not help, using gdb can help too. If the program works in 32 but not in 64, there are several things to look at (long is 8 bytes, not 4 on Linux, so some long -> int convertion may be broken). Sometimes, the program just happens to work on 32 bits, but by accident (running valgrind on both 32 and 64 bits may be helpful too). cheers, David From rdmurray at bitdance.com Wed Feb 25 08:39:58 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Wed, 25 Feb 2009 13:39:58 +0000 (UTC) Subject: How do I decode unicode characters in the subject using email.message_from_string()? References: <44432eaa-372e-45d2-baa2-da350a371d70@x9g2000yqk.googlegroups.com> Message-ID: John Machin wrote: > On Feb 25, 11:07=A0am, "Roy H. Han" > wrote: > > Dear python-list, > > > > I'm having some trouble decoding an email header using the standard > > imaplib.IMAP4 class and email.message_from_string method. > > > > In particular, email.message_from_string() does not seem to properly > > decode unicode characters in the subject. > > > > How do I decode unicode characters in the subject? > > You don't. You can't. You decode str objects into unicode objects. You > encode unicode objects into str objects. If your input is not a str > object, you have a problem. I can't speak for the OP, but I had a similar (and possibly identical-in-intent) question. Suppose you have a Subject line that looks like this: Subject: 'u' Obselete type =?ISO-8859-1?Q?--_it_is_identical_?= =?ISO-8859-1?Q?to_=27d=27=2E_=287=29?= How do you get the email module to decode that into unicode? The same question applies to the other header lines, and the answer is it isn't easy, and I had to read and reread the docs and experiment for a while to figure it out. I understand there's going to be a sprint on the email module at pycon, maybe some of this will get improved then. Here's the final version of my test program. The third to last line is one I thought ought to work given that Header has a __unicode__ method. The final line is the one that did work (note the kludge to turn None into 'ascii'...IMO 'ascii' is what deocde_header _should_ be returning, and this code shows why!) ------------------------------------------------------------------- from email import message_from_string from email.header import Header, decode_header x = message_from_string("""\ To: test Subject: 'u' Obselete type =?ISO-8859-1?Q?--_it_is_identical_?= =?ISO-8859-1?Q?to_=27d=27=2E_=287=29?= this is a test. """) print x print "--------------------" for key, header in x.items(): print key, 'type', type(header) print key+":", unicode(Header(header)).decode('utf-8') print key+":", decode_header(header) print key+":", ''.join([s.decode(t or 'ascii') for (s, t) in decode_header(header)]).encode('utf-8') ------------------------------------------------------------------- From nobody Wed Feb 25 08:35:29 2009 To: test Subject: 'u' Obselete type =?ISO-8859-1?Q?--_it_is_identical_?= =?ISO-8859-1?Q?to_=27d=27=2E_=287=29?= this is a test. -------------------- To type To: test To: [('test', None)] To: test Subject type Subject: 'u' Obselete type =?ISO-8859-1?Q?--_it_is_identical_?= =?ISO-8859-1?Q?to_=27d=27=2E_=287=29?= Subject: [("'u' Obselete type", None), ("-- it is identical to 'd'. (7)", 'iso-8859-1')] Subject: 'u' Obselete type-- it is identical to 'd'. (7) --RDM From lists at cheimes.de Wed Feb 25 08:47:03 2009 From: lists at cheimes.de (Christian Heimes) Date: Wed, 25 Feb 2009 14:47:03 +0100 Subject: Convert PySerial to python 3.0 In-Reply-To: References: <385a617c-1e43-4828-8edd-3f4aadce8604@c11g2000yqj.googlegroups.com> Message-ID: Seth wrote: > I implemented "if isinstance(port, str): " that seems to work for now. > > Currently I am running into: > > err, n = win32file.WriteFile(self.hComPort, data, > self._overlappedWrite) > TypeError: expected an object with a buffer interface Unicode objects (in Py3k: str) don't implement the buffer interface. You have to apply a bytes or bytearray instance. Christian From ra.ravi.rav at gmail.com Wed Feb 25 08:58:13 2009 From: ra.ravi.rav at gmail.com (Ravi) Date: Wed, 25 Feb 2009 05:58:13 -0800 (PST) Subject: Forwarding keyword arguments from one function to another References: Message-ID: Thnak you all. > In the future, explain "didn't work". > Wrong output? give actual (copy and paste) and expected. > Error message? give traceback (copy and paste). I will be careful. From ptmcg at austin.rr.com Wed Feb 25 09:04:23 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Wed, 25 Feb 2009 06:04:23 -0800 (PST) Subject: XML Parsing References: Message-ID: On Feb 25, 1:17?am, hrishy wrote: > Hi > > Something like this > > > Note i am not a python programmer just a enthusiast and i was curious why people on the list didnt suggest a code like above > You just beat the rest of us to it - good example of ElementTree for parsing XML (and I Iearned the '//' shortcut for one or more intervening tag levels). To the OP: if you are parsing XML, I would look hard at the modules (esp. ElementTree) that are written explicitly for XML, before considering using regular expressions. There are just too many potential surprises when trying to match XML tags - presence/absence/ order of attributes, namespaces, whitespace inside tags, to name a few. -- Paul From starsareblueandfaraway at gmail.com Wed Feb 25 09:09:49 2009 From: starsareblueandfaraway at gmail.com (Roy H. Han) Date: Wed, 25 Feb 2009 09:09:49 -0500 Subject: How do I decode unicode characters in the subject using email.message_from_string()? In-Reply-To: References: <44432eaa-372e-45d2-baa2-da350a371d70@x9g2000yqk.googlegroups.com> Message-ID: <6a5569ec0902250609l243089d9g330ef2f578569499@mail.gmail.com> Thanks for writing back, RDM and John Machin. Tomorrow I'll try the code you suggested, RDM. It looks quite helpful and I'll report the results. In the meantime, John asked for more data. The sender's email client is Microsoft Outlook 11. The recipient email client is Lotus Notes. Actual Subject =?us-ascii?Q?Inteum_C/SR_User_Tip:__Quick_Access_to_Recently_Opened_Inteu?=\r\n\t=?us-ascii?Q?m_C/SR_Records?= Expected Subject Inteum C/SR User Tip: Quick Access to Recently Opened Inteum C/SR Records X-Mailer Microsoft Office Outlook 11 X-MimeOLE Produced By Microsoft MimeOLE V6.00.2900.5579 RHH On Wed, Feb 25, 2009 at 8:39 AM, wrote: > John Machin wrote: >> On Feb 25, 11:07=A0am, "Roy H. Han" >> wrote: >> > Dear python-list, >> > >> > I'm having some trouble decoding an email header using the standard >> > imaplib.IMAP4 class and email.message_from_string method. >> > >> > In particular, email.message_from_string() does not seem to properly >> > decode unicode characters in the subject. >> > >> > How do I decode unicode characters in the subject? >> >> You don't. You can't. You decode str objects into unicode objects. You >> encode unicode objects into str objects. If your input is not a str >> object, you have a problem. > > I can't speak for the OP, but I had a similar (and possibly > identical-in-intent) question. ?Suppose you have a Subject line that > looks like this: > > ? ?Subject: 'u' Obselete type =?ISO-8859-1?Q?--_it_is_identical_?= ? =?ISO-8859-1?Q?to_=27d=27=2E_=287=29?= > > How do you get the email module to decode that into unicode? ?The same > question applies to the other header lines, and the answer is it isn't > easy, and I had to read and reread the docs and experiment for a while > to figure it out. ?I understand there's going to be a sprint on the > email module at pycon, maybe some of this will get improved then. > > Here's the final version of my test program. ?The third to last line is > one I thought ought to work given that Header has a __unicode__ method. > The final line is the one that did work (note the kludge to turn None > into 'ascii'...IMO 'ascii' is what deocde_header _should_ be returning, > and this code shows why!) > > ------------------------------------------------------------------- > from email import message_from_string > from email.header import Header, decode_header > > x = message_from_string("""\ > To: test > Subject: 'u' Obselete type =?ISO-8859-1?Q?--_it_is_identical_?= ? =?ISO-8859-1?Q?to_=27d=27=2E_=287=29?= > > this is a test. > """) > > print x > print "--------------------" > for key, header in x.items(): > ? ?print key, 'type', type(header) > ? ?print key+":", unicode(Header(header)).decode('utf-8') > ? ?print key+":", decode_header(header) > ? ?print key+":", ''.join([s.decode(t or 'ascii') for (s, t) in decode_header(header)]).encode('utf-8') > ------------------------------------------------------------------- > > > ? ?From nobody Wed Feb 25 08:35:29 2009 > ? ?To: test > ? ?Subject: 'u' Obselete type =?ISO-8859-1?Q?--_it_is_identical_?= > ? ? ? ? ? ?=?ISO-8859-1?Q?to_=27d=27=2E_=287=29?= > > ? ?this is a test. > > ? ?-------------------- > ? ?To type > ? ?To: test > ? ?To: [('test', None)] > ? ?To: test > ? ?Subject type > ? ?Subject: 'u' Obselete type =?ISO-8859-1?Q?--_it_is_identical_?= ? =?ISO-8859-1?Q?to_=27d=27=2E_=287=29?= > ? ?Subject: [("'u' Obselete type", None), ("-- it is identical to 'd'. (7)", 'iso-8859-1')] > ? ?Subject: 'u' Obselete type-- it is identical to 'd'. (7) > > > --RDM > > -- > http://mail.python.org/mailman/listinfo/python-list > From steve at holdenweb.com Wed Feb 25 09:20:21 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 25 Feb 2009 09:20:21 -0500 Subject: How do I decode unicode characters in the subject using email.message_from_string()? In-Reply-To: <6a5569ec0902250609l243089d9g330ef2f578569499@mail.gmail.com> References: <44432eaa-372e-45d2-baa2-da350a371d70@x9g2000yqk.googlegroups.com> <6a5569ec0902250609l243089d9g330ef2f578569499@mail.gmail.com> Message-ID: <49A553A5.4050309@holdenweb.com> Roy H. Han wrote: > On Wed, Feb 25, 2009 at 8:39 AM, wrote: [Top-posting corrected] >> John Machin wrote: >>> On Feb 25, 11:07=A0am, "Roy H. Han" >>> wrote: >>>> Dear python-list, >>>> >>>> I'm having some trouble decoding an email header using the standard >>>> imaplib.IMAP4 class and email.message_from_string method. >>>> >>>> In particular, email.message_from_string() does not seem to properly >>>> decode unicode characters in the subject. >>>> >>>> How do I decode unicode characters in the subject? >>> You don't. You can't. You decode str objects into unicode objects. You >>> encode unicode objects into str objects. If your input is not a str >>> object, you have a problem. >> I can't speak for the OP, but I had a similar (and possibly >> identical-in-intent) question. Suppose you have a Subject line that >> looks like this: >> >> Subject: 'u' Obselete type =?ISO-8859-1?Q?--_it_is_identical_?= =?ISO-8859-1?Q?to_=27d=27=2E_=287=29?= >> >> How do you get the email module to decode that into unicode? The same >> question applies to the other header lines, and the answer is it isn't >> easy, and I had to read and reread the docs and experiment for a while >> to figure it out. I understand there's going to be a sprint on the >> email module at pycon, maybe some of this will get improved then. >> >> Here's the final version of my test program. The third to last line is >> one I thought ought to work given that Header has a __unicode__ method. >> The final line is the one that did work (note the kludge to turn None >> into 'ascii'...IMO 'ascii' is what deocde_header _should_ be returning, >> and this code shows why!) >> >> ------------------------------------------------------------------- >> from email import message_from_string >> from email.header import Header, decode_header >> >> x = message_from_string("""\ >> To: test >> Subject: 'u' Obselete type =?ISO-8859-1?Q?--_it_is_identical_?= =?ISO-8859-1?Q?to_=27d=27=2E_=287=29?= >> >> this is a test. >> """) >> >> print x >> print "--------------------" >> for key, header in x.items(): >> print key, 'type', type(header) >> print key+":", unicode(Header(header)).decode('utf-8') >> print key+":", decode_header(header) >> print key+":", ''.join([s.decode(t or 'ascii') for (s, t) in decode_header(header)]).encode('utf-8') >> ------------------------------------------------------------------- >> >> >> From nobody Wed Feb 25 08:35:29 2009 >> To: test >> Subject: 'u' Obselete type =?ISO-8859-1?Q?--_it_is_identical_?= >> =?ISO-8859-1?Q?to_=27d=27=2E_=287=29?= >> >> this is a test. >> >> -------------------- >> To type >> To: test >> To: [('test', None)] >> To: test >> Subject type >> Subject: 'u' Obselete type =?ISO-8859-1?Q?--_it_is_identical_?= =?ISO-8859-1?Q?to_=27d=27=2E_=287=29?= >> Subject: [("'u' Obselete type", None), ("-- it is identical to 'd'. (7)", 'iso-8859-1')] >> Subject: 'u' Obselete type-- it is identical to 'd'. (7) >> >> > Thanks for writing back, RDM and John Machin. Tomorrow I'll try the > code you suggested, RDM. It looks quite helpful and I'll report the > results. > > In the meantime, John asked for more data. The sender's email client > is Microsoft Outlook 11. The recipient email client is Lotus Notes. > > > > Actual Subject > =?us-ascii?Q?Inteum_C/SR_User_Tip:__Quick_Access_to_Recently_Opened_Inteu?=\r\n\t=?us-ascii?Q?m_C/SR_Records?= > > Expected Subject > Inteum C/SR User Tip: Quick Access to Recently Opened Inteum C/SR Records > > X-Mailer > Microsoft Office Outlook 11 > > X-MimeOLE > Produced By Microsoft MimeOLE V6.00.2900.5579 > >>> from email.header import decode_header >>> print decode_header("=?us-ascii?Q?Inteum_C/SR_User_Tip:__Quick_Access_to_Recently_Opened_Inteu?=\r\n\t=?us-ascii?Q?m_C/SR_Records?=") [('Inteum C/SR User Tip: Quick Access to Recently Opened Inteum C/SR Records', 'us-ascii')] >>> regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Wed Feb 25 09:20:21 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 25 Feb 2009 09:20:21 -0500 Subject: How do I decode unicode characters in the subject using email.message_from_string()? In-Reply-To: <6a5569ec0902250609l243089d9g330ef2f578569499@mail.gmail.com> References: <44432eaa-372e-45d2-baa2-da350a371d70@x9g2000yqk.googlegroups.com> <6a5569ec0902250609l243089d9g330ef2f578569499@mail.gmail.com> Message-ID: <49A553A5.4050309@holdenweb.com> Roy H. Han wrote: > On Wed, Feb 25, 2009 at 8:39 AM, wrote: [Top-posting corrected] >> John Machin wrote: >>> On Feb 25, 11:07=A0am, "Roy H. Han" >>> wrote: >>>> Dear python-list, >>>> >>>> I'm having some trouble decoding an email header using the standard >>>> imaplib.IMAP4 class and email.message_from_string method. >>>> >>>> In particular, email.message_from_string() does not seem to properly >>>> decode unicode characters in the subject. >>>> >>>> How do I decode unicode characters in the subject? >>> You don't. You can't. You decode str objects into unicode objects. You >>> encode unicode objects into str objects. If your input is not a str >>> object, you have a problem. >> I can't speak for the OP, but I had a similar (and possibly >> identical-in-intent) question. Suppose you have a Subject line that >> looks like this: >> >> Subject: 'u' Obselete type =?ISO-8859-1?Q?--_it_is_identical_?= =?ISO-8859-1?Q?to_=27d=27=2E_=287=29?= >> >> How do you get the email module to decode that into unicode? The same >> question applies to the other header lines, and the answer is it isn't >> easy, and I had to read and reread the docs and experiment for a while >> to figure it out. I understand there's going to be a sprint on the >> email module at pycon, maybe some of this will get improved then. >> >> Here's the final version of my test program. The third to last line is >> one I thought ought to work given that Header has a __unicode__ method. >> The final line is the one that did work (note the kludge to turn None >> into 'ascii'...IMO 'ascii' is what deocde_header _should_ be returning, >> and this code shows why!) >> >> ------------------------------------------------------------------- >> from email import message_from_string >> from email.header import Header, decode_header >> >> x = message_from_string("""\ >> To: test >> Subject: 'u' Obselete type =?ISO-8859-1?Q?--_it_is_identical_?= =?ISO-8859-1?Q?to_=27d=27=2E_=287=29?= >> >> this is a test. >> """) >> >> print x >> print "--------------------" >> for key, header in x.items(): >> print key, 'type', type(header) >> print key+":", unicode(Header(header)).decode('utf-8') >> print key+":", decode_header(header) >> print key+":", ''.join([s.decode(t or 'ascii') for (s, t) in decode_header(header)]).encode('utf-8') >> ------------------------------------------------------------------- >> >> >> From nobody Wed Feb 25 08:35:29 2009 >> To: test >> Subject: 'u' Obselete type =?ISO-8859-1?Q?--_it_is_identical_?= >> =?ISO-8859-1?Q?to_=27d=27=2E_=287=29?= >> >> this is a test. >> >> -------------------- >> To type >> To: test >> To: [('test', None)] >> To: test >> Subject type >> Subject: 'u' Obselete type =?ISO-8859-1?Q?--_it_is_identical_?= =?ISO-8859-1?Q?to_=27d=27=2E_=287=29?= >> Subject: [("'u' Obselete type", None), ("-- it is identical to 'd'. (7)", 'iso-8859-1')] >> Subject: 'u' Obselete type-- it is identical to 'd'. (7) >> >> > Thanks for writing back, RDM and John Machin. Tomorrow I'll try the > code you suggested, RDM. It looks quite helpful and I'll report the > results. > > In the meantime, John asked for more data. The sender's email client > is Microsoft Outlook 11. The recipient email client is Lotus Notes. > > > > Actual Subject > =?us-ascii?Q?Inteum_C/SR_User_Tip:__Quick_Access_to_Recently_Opened_Inteu?=\r\n\t=?us-ascii?Q?m_C/SR_Records?= > > Expected Subject > Inteum C/SR User Tip: Quick Access to Recently Opened Inteum C/SR Records > > X-Mailer > Microsoft Office Outlook 11 > > X-MimeOLE > Produced By Microsoft MimeOLE V6.00.2900.5579 > >>> from email.header import decode_header >>> print decode_header("=?us-ascii?Q?Inteum_C/SR_User_Tip:__Quick_Access_to_Recently_Opened_Inteu?=\r\n\t=?us-ascii?Q?m_C/SR_Records?=") [('Inteum C/SR User Tip: Quick Access to Recently Opened Inteum C/SR Records', 'us-ascii')] >>> regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From aahz at pythoncraft.com Wed Feb 25 09:21:54 2009 From: aahz at pythoncraft.com (Aahz) Date: 25 Feb 2009 06:21:54 -0800 Subject: Free Python Training: Washington, DC (3/3-5) References: Message-ID: In article , Steve Holden wrote: > >Not a joke, but a genuine offer extended to anyone who has already >contributed to some open source project. See my blog for full details, >and please pass this on to non-Python programmers who are interested in >learning the language. > > http://holdenweb.blogspot.com/2009/02/free-python-training.html Fixed the Subject: line for you. ;-) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. From stefan_ml at behnel.de Wed Feb 25 09:39:15 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 25 Feb 2009 15:39:15 +0100 Subject: Python dictionary size/entry limit? In-Reply-To: <49a1b17d$0$28748$9b622d9e@news.freenet.de> References: <49a1b17d$0$28748$9b622d9e@news.freenet.de> Message-ID: <49a55813$0$30232$9b4e6d93@newsspool1.arcor-online.net> Martin v. L?wis wrote: > intelliminer at gmail.com wrote: >> Is there a limit to the size or number of entries that a single >> dictionary can possess? > > On a 32-bit system, the dictionary can have up to 2**31 slots, > meaning that the maximum number of keys is slightly smaller > (about 2**30). Which, in practice, means that the size is limited by the available memory. Stefan From marduk at letterboxes.org Wed Feb 25 09:42:32 2009 From: marduk at letterboxes.org (Albert Hopkins) Date: Wed, 25 Feb 2009 09:42:32 -0500 Subject: Lambda function In-Reply-To: <9d1b5e270902250426q63913a87q28c06844ef175326@mail.gmail.com> References: <9d1b5e270902250426q63913a87q28c06844ef175326@mail.gmail.com> Message-ID: <1235572952.11727.2.camel@localhost.localdomain> On Wed, 2009-02-25 at 17:56 +0530, aditya saurabh wrote: > I defined two functions - lets say > fa = lambda x: 2*x > fb = lambda x: 3*x > Now I would like to use fa*fb in terms of x > is there a way? > Thanks in advance I'm not sure what "use fa*fb in terms of x" means. But if you mean fa(x) * fb(x) then it's just: fa(x) * fb(x) -a From bnsilinux at gmail.com Wed Feb 25 09:43:35 2009 From: bnsilinux at gmail.com (Ben) Date: Wed, 25 Feb 2009 06:43:35 -0800 (PST) Subject: Extending Python Questions ..... References: <7e1a6ec9-8457-40ef-a3da-a16b5dac1100@r34g2000vbp.googlegroups.com> Message-ID: <33411bf0-396a-4aef-83ad-4d4e68b26050@l22g2000vba.googlegroups.com> On Feb 24, 11:31?am, Nick Craig-Wood wrote: > Ben wrote: > > ?No, It uses the the S-lang for video, and input control. However, SLAG > > ?is more of an abstract layer on top of that. > > > ?It has a Structures that contains menus and screens (menumodule / > > ?screenmodule). One LOADS them up with parameters. ?such as creating > > ?a new menu is like: > > > ?OpenMenu( Company name, SubSystem, this program name, mode, bottom > > ?status display) - Create initial menu structure Addtomenu(Menu > > ?Block Set name, DISPLAY line, ID, type of program, password ID ) - > > ?add to / update MENU blocks. ?runMenu() - Displays the whole create > > ?menu structure. > > > ?The Menu structure is done in pull downs and scrollable blocks in a > > ?TUI (text User Interface) and using the S-lang screen library is > > ?fully mouseable. > > > ?The screen module works mych the same way, but with the abiltity to > > ?open and close and work within "Sub Screens". > > > ?For those who do not know, S-lang is a interpreted language much > > ?like Python. However, there is s direth of library modules. The > > ?original S-lang started out as library of screen of keyboard > > ?modules, but has been expanded > > > ?My SLAG project does not care in reality WHICH or what language, it > > ?is simply handling menu and screen control. > > So do you want to embed python into your code? > > I'm still not clear what you are trying to achieve with python, though > I have a better idea what SLAG is now! > > -- > Nick Craig-Wood --http://www.craig-wood.com/nick Actually no, I want to EXTEND python using the lower levels of S-lang screen modules. My Modules are written in C and are a frame work for building pull- down menus and data entry screens. Very nice for writing business applications. Think along the lines of FoxPro and/or the "Screen" section in Cobol and you have a pretty good idea of what i have done. From rdmurray at bitdance.com Wed Feb 25 09:50:37 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Wed, 25 Feb 2009 14:50:37 +0000 (UTC) Subject: How do I decode unicode characters in the subject using email.message_from_string()? References: <44432eaa-372e-45d2-baa2-da350a371d70@x9g2000yqk.googlegroups.com> <6a5569ec0902250609l243089d9g330ef2f578569499@mail.gmail.com> <49A553A5.4050309@holdenweb.com> Message-ID: Steve Holden wrote: > >>> from email.header import decode_header > >>> print > decode_header("=?us-ascii?Q?Inteum_C/SR_User_Tip:__Quick_Access_to_Recently_Opened_Inteu?=\r\n\t=?us-ascii?Q?m_C/SR_Records?=") > [('Inteum C/SR User Tip: Quick Access to Recently Opened Inteum C/SR > Records', 'us-ascii')] > >>> It is interesting that decode_header does what I would consider to be the right thing (from a pragmatic standpoint) with that particular bit of Microsoft not-quite-standards-compliant brain-damage; but, removing the tab is not in fact standards compliant if I'm reading the RFC correctly. --RDM From king.seth at gmail.com Wed Feb 25 10:07:51 2009 From: king.seth at gmail.com (Seth) Date: Wed, 25 Feb 2009 07:07:51 -0800 (PST) Subject: Convert PySerial to python 3.0 References: <385a617c-1e43-4828-8edd-3f4aadce8604@c11g2000yqj.googlegroups.com> Message-ID: I tried all three ways you guys listed nothing seems to convert the string to bytes. It may have to do with the makeDeviceName function, but I can't find where that is defined. Any thoughts?? Here is the whole block of code: if type(port) in (str, bytes): #strings are taken directly Originally: if type(port) in [type(''), type(u'')] self.portstr = port else: self.portstr = self.makeDeviceName(port) On Feb 25, 8:47?am, Christian Heimes wrote: > Seth wrote: > > I implemented "if isinstance(port, str): " that seems to work for now. > > > Currently I am running into: > > > err, n = win32file.WriteFile(self.hComPort, data, > > self._overlappedWrite) > > TypeError: expected an object with a buffer interface > > Unicode objects (in Py3k: str) don't implement the buffer interface. You > have to apply a bytes or bytearray instance. > > Christian From gagsl-py2 at yahoo.com.ar Wed Feb 25 10:10:30 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 25 Feb 2009 13:10:30 -0200 Subject: Lambda function References: <9d1b5e270902250426q63913a87q28c06844ef175326@mail.gmail.com> <1235572952.11727.2.camel@localhost.localdomain> Message-ID: En Wed, 25 Feb 2009 12:42:32 -0200, Albert Hopkins escribi?: > On Wed, 2009-02-25 at 17:56 +0530, aditya saurabh wrote: >> I defined two functions - lets say >> fa = lambda x: 2*x >> fb = lambda x: 3*x >> Now I would like to use fa*fb in terms of x >> is there a way? >> Thanks in advance > > I'm not sure what "use fa*fb in terms of x" means. > > But if you mean fa(x) * fb(x) then it's just: > > fa(x) * fb(x) I think he wants function composition, fb(fa(x)): def compose(*funcs): def composed(x, funcs=funcs): for f in reversed(funcs): x = f(x) return x return composed def square(x): return x**2 def plus1(x): return x+1 # same as plus1 = lambda x: x+1 but I like the def syntax y = compose(square, plus1) # y=(x+1)**2 y(3) # -> 16 (or is it fa(fb(x))?) -- Gabriel Genellina From lists at cheimes.de Wed Feb 25 10:16:11 2009 From: lists at cheimes.de (Christian Heimes) Date: Wed, 25 Feb 2009 16:16:11 +0100 Subject: Convert PySerial to python 3.0 In-Reply-To: References: <385a617c-1e43-4828-8edd-3f4aadce8604@c11g2000yqj.googlegroups.com> Message-ID: Seth wrote: > I tried all three ways you guys listed nothing seems to convert the > string to bytes. > > It may have to do with the makeDeviceName function, but I can't find > where that is defined. > > Any thoughts?? > > Here is the whole block of code: > > if type(port) in (str, bytes): #strings are taken directly > Originally: if type(port) in [type(''), type(u'')] > self.portstr = port > else: > self.portstr = self.makeDeviceName(port) str and bytes are two totally unrelated things in Python 3.0. You can no longer treat them equally like str and unicode in Python 2.x. Your could should not work under Python 3.0 anyway. u'' is invalid in 3.x. Also please don't use ugly type checks like type(something) == type(''). Starting with Python 2.2 you should use isinstance, for example isinstance(number, (int, long)). Christian From starsareblueandfaraway at gmail.com Wed Feb 25 10:17:22 2009 From: starsareblueandfaraway at gmail.com (Roy H. Han) Date: Wed, 25 Feb 2009 10:17:22 -0500 Subject: How do I decode unicode characters in the subject using email.message_from_string()? In-Reply-To: References: <44432eaa-372e-45d2-baa2-da350a371d70@x9g2000yqk.googlegroups.com> <6a5569ec0902250609l243089d9g330ef2f578569499@mail.gmail.com> <49A553A5.4050309@holdenweb.com> Message-ID: <6a5569ec0902250717q7832bce3ocb6ae279184b32a0@mail.gmail.com> Cool, it works! Thanks, RDM, for stating the right approach. Thanks, Steve, for teaching by example. I wonder why the email.message_from_string() method doesn't call email.header.decode_header() automatically. On Wed, Feb 25, 2009 at 9:50 AM, wrote: > Steve Holden wrote: >> >>> from email.header import decode_header >> >>> print >> decode_header("=?us-ascii?Q?Inteum_C/SR_User_Tip:__Quick_Access_to_Recently_Opened_Inteu?=\r\n\t=?us-ascii?Q?m_C/SR_Records?=") >> [('Inteum C/SR User Tip: ?Quick Access to Recently Opened Inteum C/SR >> Records', 'us-ascii')] >> >>> > > It is interesting that decode_header does what I would consider to be > the right thing (from a pragmatic standpoint) with that particular bit > of Microsoft not-quite-standards-compliant brain-damage; but, removing > the tab is not in fact standards compliant if I'm reading the RFC > correctly. > > --RDM > > -- > http://mail.python.org/mailman/listinfo/python-list > From steve at holdenweb.com Wed Feb 25 10:24:17 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 25 Feb 2009 10:24:17 -0500 Subject: How do I decode unicode characters in the subject using email.message_from_string()? In-Reply-To: References: <44432eaa-372e-45d2-baa2-da350a371d70@x9g2000yqk.googlegroups.com> <6a5569ec0902250609l243089d9g330ef2f578569499@mail.gmail.com> <49A553A5.4050309@holdenweb.com> Message-ID: rdmurray at bitdance.com wrote: > Steve Holden wrote: >>>>> from email.header import decode_header >>>>> print >> decode_header("=?us-ascii?Q?Inteum_C/SR_User_Tip:__Quick_Access_to_Recently_Opened_Inteu?=\r\n\t=?us-ascii?Q?m_C/SR_Records?=") >> [('Inteum C/SR User Tip: Quick Access to Recently Opened Inteum C/SR >> Records', 'us-ascii')] > > It is interesting that decode_header does what I would consider to be > the right thing (from a pragmatic standpoint) with that particular bit > of Microsoft not-quite-standards-compliant brain-damage; but, removing > the tab is not in fact standards compliant if I'm reading the RFC > correctly. > You'd need to quote me chapter and verse on that. I understood that the tab simply indicated continuation, but it's a *long* time since I read the RFCs. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From music24by7 at gmail.com Wed Feb 25 10:26:30 2009 From: music24by7 at gmail.com (Sudhir Kakumanu) Date: Wed, 25 Feb 2009 20:56:30 +0530 Subject: File Path retrieving problem Message-ID: <52c4d4ea0902250726u44e4ddap95fa68cd37a8f8f3@mail.gmail.com> Hi all, I am new to Python, i have installed python 2.5.4 and it is my requirement. I need to retrieve the path of filename in python. I have found some API's to get this: from os.path import realpath print realpath("NEWS.txt") # here NEWS.txt exists and it shows the path of the file as C:\Python25\WorkSpace\NEWS.txt print realpath("abc.txt") # here abc.txt does not exist but still it shows C:\Python25\WorkSpace\abc.txt can anybody tell the reason why???? Now took some safety measures: found = lexists(realpath(filename)) if found == 0: print "Not Found" else: print realpath(filename) i have given the filename as "NEWS.txt" and "abc.txt" but i am always getting the output as "Not Found" Can anyone please tell me where am i doing wrong???? also any suggestions to retrieve the filepath from a given filename is highly appreciated. Thanks in advance. Regards, Sudhir -------------- next part -------------- An HTML attachment was scrubbed... URL: From pythonsky at sky.com Wed Feb 25 10:31:25 2009 From: pythonsky at sky.com (Gary Wood) Date: Wed, 25 Feb 2009 15:31:25 -0000 Subject: Newbie : this works in one direction but get the error on the return path Message-ID: '''Test animation of a group of objects making a face. Combine the face elements in a function, and use it twice. Have an extra level of repetition in the animation. ''' from graphics import * import time def moveAll(shapeList, dx, dy): ''' Move all shapes in shapeList by (dx, dy).''' for shape in shapeList: shape.move(dx, dy) def moveAllOnLine(shapeList, dx, dy, repetitions, delay): '''Animate the shapes in shapeList along a line. Move by (dx, dy) each time. Repeat the specified number of repetitions. Have the specified delay (in seconds) after each repeat. ''' for i in range(repetitions): moveAll(shapeList, dx, dy) time.sleep(delay) def makeFace(center, win): '''display face centered at center in window win. Return a list of the shapes in the face. ''' head = Circle(center, 25) head.setFill("yellow") head.draw(win) eye1Center = center.clone() #face positions are relative to the center eye1Center.move(-10, 5) #locate further points in relation to others eye1 = Circle(eye1Center, 5) eye1.setFill('blue') eye1.draw(win) eye2End1 = eye1Center.clone() eye2End1.move(15, 0) eye2End2 = eye2End1.clone() eye2End2.move(10, 0) eye2 = Line(eye2End1, eye2End2) eye2.setWidth(3) eye2.draw(win) noseTop = center.clone() noseTop.move(0,0) noseLeft = noseTop.clone() noseLeft.move(-2,-2) noseRight = noseLeft.clone() noseRight.move(5,0) nose = Polygon(noseTop,noseLeft,noseRight) nose.draw(win) mouthCorner1 = center.clone() mouthCorner1.move(-10, -10) mouthCorner2 = mouthCorner1.clone() mouthCorner2.move(20, -5) mouth = Oval(mouthCorner1, mouthCorner2) mouth.setFill("red") mouth.draw(win) return [head, eye1, eye2,nose, mouth] def main(): winWidth = 300 winHeight = 300 win = GraphWin('Back and Forth', winWidth, winHeight) win.setCoords(0, 0, winWidth, winHeight) #make right side up coordinates! rect = Rectangle(Point(200, 90), Point(220, 100)) rect.setFill("blue") rect.draw(win) faceList = makeFace(Point(40, 100), win) faceList2 = makeFace(Point(150,125), win) stepsAcross = 40 dx = 5 dy = 3 wait = .1 for i in range(2): moveAllOnLine(faceList, dx, 0, stepsAcross, wait) moveAllOnLine(faceList, -dx, dy, stepsAcross/2, wait) moveAllOnLine(faceList, -dx, -dy, stepsAcross//2, wait) Text(Point(winWidth/2, 20), 'Click anywhere to quit.').draw(win) win.getMouse() win.close() main() Traceback (most recent call last): File "E:/python/handson/backAndForth4.py", line 97, in main() File "E:/python/handson/backAndForth4.py", line 90, in main moveAllOnLine(faceList, -dx, dy, stepsAcross/2, wait) File "E:/python/handson/backAndForth4.py", line 21, in moveAllOnLine for i in range(repetitions): TypeError: 'float' object cannot be interpreted as an integer >>> -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Wed Feb 25 10:33:13 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 25 Feb 2009 13:33:13 -0200 Subject: glibc detected *** python: corrupted double-linked list References: <49a53c36$0$713$9b622d9e@news.freenet.de> Message-ID: En Wed, 25 Feb 2009 10:40:23 -0200, Christian Meesters escribi?: > I have a problem using my software on my 64bit laptop, after an update of > my system. The same code still runs on 32bit Intel, but on my laptop I > provoke the crash in the title. The crash is caused - as narrowed down by > me - by returning a static PyObject from a C-extension function. I think you got all the reference counts wrong, specially dummy1, dummy2 and r. (BTW, when you know the size, it's better to use PyList_New(size) + PyList_SET_ITEM instead of PyList_New(0) + PyList_Append) -- Gabriel Genellina From meesters at gmx.de Wed Feb 25 10:36:59 2009 From: meesters at gmx.de (Christian Meesters) Date: 25 Feb 2009 15:36:59 GMT Subject: glibc detected *** python: corrupted double-linked list References: <49a53c36$0$713$9b622d9e@news.freenet.de> Message-ID: <49a5659b$0$656$9b622d9e@news.freenet.de> Thanks David! It's still not debugged, but indeed: I get a bunch of warnings. And this already showed me that there are more potential problems than my first guess indicated. Alas, for my specific problem I cannot work with ints chars and doubles. I need to have unsigned longs at some points. Well, I'll sort it out. Cheers Christian From music24by7 at gmail.com Wed Feb 25 10:37:21 2009 From: music24by7 at gmail.com (music24by7 at gmail.com) Date: Wed, 25 Feb 2009 07:37:21 -0800 (PST) Subject: File Path retrieving problem Message-ID: <86a29476-fde2-4983-af62-4eb8a68425a8@w34g2000yqm.googlegroups.com> Hi all, I am new to Python, i have installed python 2.5.4 and it is my requirement. I need to retrieve the path of filename in python. I have found some API's to get this: from os.path import realpath print realpath("NEWS.txt") # here NEWS.txt exists and it shows the path of the file as C:\Python25\WorkSpace\NEWS.txt print realpath("abc.txt") # here abc.txt does not exist but still it shows C:\Python25\WorkSpace\abc.txt can anybody tell the reason why???? Now took some safety measures: found = lexists(realpath(filename)) if found == 0: print "Not Found" else: print realpath(filename) i have given the filename as "NEWS.txt" and "abc.txt" but i am always getting the output as "Not Found" Can anyone please tell me where am i doing wrong???? also any suggestions to retrieve the filepath from a given filename is highly appreciated. Thanks in advance. Regards, Sudhir From thorsten at thorstenkampe.de Wed Feb 25 10:40:31 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Wed, 25 Feb 2009 16:40:31 +0100 Subject: How do I decode unicode characters in the subject using email.message_from_string()? References: <44432eaa-372e-45d2-baa2-da350a371d70@x9g2000yqk.googlegroups.com> <6a5569ec0902250609l243089d9g330ef2f578569499@mail.gmail.com> <49A553A5.4050309@holdenweb.com> Message-ID: * Roy H. Han (Wed, 25 Feb 2009 10:17:22 -0500) > Thanks, RDM, for stating the right approach. > Thanks, Steve, for teaching by example. > > I wonder why the email.message_from_string() method doesn't call > email.header.decode_header() automatically. And I wonder why you would think the header contains Unicode characters when it says "us-ascii" ("=?us-ascii?Q?"). I think there is a tendency to label everything "Unicode" someone does not understand. Thorsten From gagsl-py2 at yahoo.com.ar Wed Feb 25 10:51:18 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 25 Feb 2009 13:51:18 -0200 Subject: Newbie : this works in one direction but get the error on the return path References: Message-ID: En Wed, 25 Feb 2009 13:31:25 -0200, Gary Wood escribi?: Start looking at the error: > Traceback (most recent call last): > File "E:/python/handson/backAndForth4.py", line 97, in > main() > File "E:/python/handson/backAndForth4.py", line 90, in main > moveAllOnLine(faceList, -dx, dy, stepsAcross/2, wait) > File "E:/python/handson/backAndForth4.py", line 21, in moveAllOnLine > for i in range(repetitions): > TypeError: 'float' object cannot be interpreted as an integer It's rather understandable - you have a float object where Python is expecting an integer. Where? The traceback says it all: > File "E:/python/handson/backAndForth4.py", line 21, in moveAllOnLine > for i in range(repetitions): Ok, so repetitions should be an integer, but it isn't. Where does it come from? It's an argument to moveAllOnLine, and was called from main (see the line above that in the traceback). Now we look near that line: > for i in range(2): > moveAllOnLine(faceList, dx, 0, stepsAcross, wait) > moveAllOnLine(faceList, -dx, dy, stepsAcross/2, wait) > moveAllOnLine(faceList, -dx, -dy, stepsAcross//2, wait) Don't you see something suspicious...? -- Gabriel Genellina From meesters at gmx.de Wed Feb 25 10:51:20 2009 From: meesters at gmx.de (Christian Meesters) Date: 25 Feb 2009 15:51:20 GMT Subject: glibc detected *** python: corrupted double-linked list References: <49a53c36$0$713$9b622d9e@news.freenet.de> Message-ID: <49a568f8$0$656$9b622d9e@news.freenet.de> Hi, >> I have a problem using my software on my 64bit laptop, after an update >> of my system. The same code still runs on 32bit Intel, but on my laptop >> I provoke the crash in the title. The crash is caused - as narrowed >> down by me - by returning a static PyObject from a C-extension >> function. > > I think you got all the reference counts wrong, specially dummy1, dummy2 > and r. Might be a good point, but can you give me a hint where to look specifically? > > (BTW, when you know the size, it's better to use PyList_New(size) + > PyList_SET_ITEM instead of PyList_New(0) + PyList_Append) Just rewrote that section. Thank you. Christian From antisuho at gmail.com Wed Feb 25 10:52:03 2009 From: antisuho at gmail.com (anti-suho) Date: Wed, 25 Feb 2009 07:52:03 -0800 (PST) Subject: How to convert image into numpy.ndarray Message-ID: <4e80357e-039e-4165-bd73-c23603a0299a@r34g2000vbp.googlegroups.com> In scipy module, there is a function named misc.lena which can return an array of numpy.ndarray type. If you use this array as parameter of matplotlib.pyplot.imshow and then call the matplotlib.pyplot.imshow function, an image will be shown. The shown image is generated by the numpy.ndarray array. How to convert an arbitrary image into an array of numpy.ndarray type? From steve at holdenweb.com Wed Feb 25 10:57:41 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 25 Feb 2009 10:57:41 -0500 Subject: File Path retrieving problem In-Reply-To: <86a29476-fde2-4983-af62-4eb8a68425a8@w34g2000yqm.googlegroups.com> References: <86a29476-fde2-4983-af62-4eb8a68425a8@w34g2000yqm.googlegroups.com> Message-ID: music24by7 at gmail.com wrote: > Hi all, > > I am new to Python, i have installed python 2.5.4 and it is my > requirement. > > I need to retrieve the path of filename in python. > > I have found some API's to get this: > > from os.path import realpath > print realpath("NEWS.txt") # here NEWS.txt exists and it shows the > path of the file as C:\Python25\WorkSpace\NEWS.txt > print realpath("abc.txt") # here abc.txt does not exist but still it > shows C:\Python25\WorkSpace\abc.txt > > can anybody tell the reason why???? > > > Now took some safety measures: > > found = lexists(realpath(filename)) > if found == 0: > print "Not Found" > else: > print realpath(filename) > > i have given the filename as "NEWS.txt" and "abc.txt" but i am always > getting the output as "Not Found" > > > Can anyone please tell me where am i doing wrong???? > It seems pretty apparent that lexists() nevert returns a true result. Why not just if os.path.exists(filename): print os.path.realpath(filename) else: print "Not found" > also any suggestions to retrieve the filepath from a given filename is > highly appreciated. > Well, realpath returns the path of the file targeted after any symbolic links have been evaluated, which may or may not be what you want. Have you looked at os.path.abspath? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From gagsl-py2 at yahoo.com.ar Wed Feb 25 11:00:16 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 25 Feb 2009 14:00:16 -0200 Subject: How do I decode unicode characters in the subject using email.message_from_string()? References: <44432eaa-372e-45d2-baa2-da350a371d70@x9g2000yqk.googlegroups.com> <6a5569ec0902250609l243089d9g330ef2f578569499@mail.gmail.com> <49A553A5.4050309@holdenweb.com> Message-ID: En Wed, 25 Feb 2009 13:40:31 -0200, Thorsten Kampe escribi?: > * Roy H. Han (Wed, 25 Feb 2009 10:17:22 -0500) >> Thanks, RDM, for stating the right approach. >> Thanks, Steve, for teaching by example. >> >> I wonder why the email.message_from_string() method doesn't call >> email.header.decode_header() automatically. > > And I wonder why you would think the header contains Unicode characters > when it says "us-ascii" ("=?us-ascii?Q?"). I think there is a tendency > to label everything "Unicode" someone does not understand. And I wonder why you would think the header does *not* contain Unicode characters when it says "us-ascii"?. I think there is a tendency here too... -- Gabriel Genellina From king.seth at gmail.com Wed Feb 25 11:07:30 2009 From: king.seth at gmail.com (Seth) Date: Wed, 25 Feb 2009 08:07:30 -0800 (PST) Subject: Convert PySerial to python 3.0 References: <385a617c-1e43-4828-8edd-3f4aadce8604@c11g2000yqj.googlegroups.com> Message-ID: <67d9d270-afad-4c4a-a585-81544ef66670@x13g2000yqf.googlegroups.com> This is not my code and I am fairly new to Python. I did not know how much it would take to convert pyserial to 3.0. Someone more knowledgeable than me could do it better and faster. I just want to see if I could help get it to work. I was wrong, it seems that if type(port) in (str, bytes): or isinstance (port, str) works just fine for setting the ports. The issue now is reading and writing the data. I got the read() to kind of work with: bytes(buf[:n]) replacing str(buf[:n]) but with readline() it seems to be missing the '\n' because it just runs indefinitely( I can see the \n if I read enough bytes with read() write seems to be related to a win32 issue. win32file.WriteFile does not like anything I convert it to: str gives the buffer error bytes gives a "string argument without an encoding" error Sorry for the confusion, I just want to be able to use all Py3k on this project that I am working on and pyserial has not been converted so I just started messing around with it. Thanks for the help. Seth On Feb 25, 10:16?am, Christian Heimes wrote: > Seth wrote: > > I tried all three ways you guys listed nothing seems to convert the > > string to bytes. > > > It may have to do with the makeDeviceName function, but I can't find > > where that is defined. > > > Any thoughts?? > > > Here is the whole block of code: > > > if type(port) in (str, bytes): ? ? ? #strings are taken directly > > Originally: ? ? if type(port) in [type(''), type(u'')] > > ? ? ? ? ? ? ? ? self.portstr = port > > ? ? ? ? ? ? else: > > ? ? ? ? ? ? ? ? self.portstr = self.makeDeviceName(port) > > str and bytes are two totally unrelated things in Python 3.0. You can no > longer treat them equally like str and unicode in Python 2.x. Your could > should not work under Python 3.0 anyway. u'' is invalid in 3.x. > > Also please don't use ugly type checks like type(something) == type(''). > Starting with Python 2.2 you should use isinstance, for example > isinstance(number, (int, long)). > > Christian From gagsl-py2 at yahoo.com.ar Wed Feb 25 11:16:47 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 25 Feb 2009 14:16:47 -0200 Subject: glibc detected *** python: corrupted double-linked list References: <49a53c36$0$713$9b622d9e@news.freenet.de> <49a568f8$0$656$9b622d9e@news.freenet.de> Message-ID: En Wed, 25 Feb 2009 13:51:20 -0200, Christian Meesters escribi?: >>> I have a problem using my software on my 64bit laptop, after an update >>> of my system. The same code still runs on 32bit Intel, but on my laptop >>> I provoke the crash in the title. The crash is caused - as narrowed >>> down by me - by returning a static PyObject from a C-extension >>> function. >> >> I think you got all the reference counts wrong, specially dummy1, dummy2 >> and r. > Might be a good point, but can you give me a hint where to look > specifically? /* parse the input arguments r & vectors */ if (!PyArg_ParseTuple(args, "OO", &r, &py_vectors)) return NULL; ... for (i=0; i < vsize; i++) { ... dummy_2 = PyList_GetItem(dummy_1, 0); ... } ... /* copy all items from pofr to py_pofr to be returned */ if (!(py_pofr = PyList_New(0))) return NULL; for (i=0; i < rlen; i++) { dummy_1 = Py_BuildValue("i", pofr[i]); if (!dummy_1) return NULL; PyList_Append(py_pofr, dummy_1); Py_CLEAR(dummy_1); } /* reference counters to zero */ Py_CLEAR(dummy_1); Py_CLEAR(dummy_2); Py_CLEAR(r); r is an argument, a borrowed reference; you can't Py_CLEAR it. dummy_1 is decremented inside the loop, and again three lines below. dummy_2 is used far above the final Py_CLEAR, and it comes from PyList_GetItem, which returns a borrowed reference - you can't decrement it either. Also there are several "return NULL" that don't decrement active objects (like "if (!dummy_1)..." above) Getting the reference count right is critical: if you err by +1, the object will never be destroyed (leaking memory). If you err by -1, the object will be still in use after it was destroyed. -- Gabriel Genellina From meesters at gmx.de Wed Feb 25 11:17:28 2009 From: meesters at gmx.de (Christian Meesters) Date: 25 Feb 2009 16:17:28 GMT Subject: How to convert image into numpy.ndarray References: <4e80357e-039e-4165-bd73-c23603a0299a@r34g2000vbp.googlegroups.com> Message-ID: <49a56f18$0$656$9b622d9e@news.freenet.de> On Wed, 25 Feb 2009 07:52:03 -0800, anti-suho wrote: > In scipy module, there is a function named misc.lena which can return an > array of numpy.ndarray type. If you use this array as parameter of > matplotlib.pyplot.imshow and then call the matplotlib.pyplot.imshow > function, an image will be shown. The shown image is generated by the > numpy.ndarray array. > > How to convert an arbitrary image into an array of numpy.ndarray type? Well, arbitrary ... But this may serve as a starting point: from scipy.misc import fromimage import Image #PIL my_array = fromimage(Image.open(_file_name_)) Of course, you should perform the appropriate error checking, too. ;-) HTH Christian From music24by7 at gmail.com Wed Feb 25 11:17:40 2009 From: music24by7 at gmail.com (music24by7 at gmail.com) Date: Wed, 25 Feb 2009 08:17:40 -0800 (PST) Subject: File Path retrieving problem References: <86a29476-fde2-4983-af62-4eb8a68425a8@w34g2000yqm.googlegroups.com> Message-ID: <9e0c2728-f28a-4b3a-8199-17e92da217fd@l38g2000vba.googlegroups.com> On Feb 25, 8:57?pm, Steve Holden wrote: > music24... at gmail.com wrote: > > Hi all, > > > I am new to Python, i have installed python 2.5.4 and it is my > > requirement. > > > I need to retrieve the path of filename in python. > > > I have found some API's to get this: > > > from os.path import realpath > > print realpath("NEWS.txt") ?# here NEWS.txt exists and it shows the > > path of the file as C:\Python25\WorkSpace\NEWS.txt > > print realpath("abc.txt") # here abc.txt does not exist but still it > > shows C:\Python25\WorkSpace\abc.txt > > > can anybody tell the reason why???? > > > Now took some safety measures: > > > found = lexists(realpath(filename)) > > ? ? ? ? if found == 0: > > ? ? ? ? ? ? print "Not Found" > > ? ? ? ? else: > > ? ? ? ? ? ? print realpath(filename) > > > i have given the filename as "NEWS.txt" and "abc.txt" but i am always > > getting the output as "Not Found" > > > Can anyone please tell me where am i doing wrong???? > > It seems pretty apparent that lexists() nevert returns a true result. > > Why not just > > if os.path.exists(filename): > ? ? print os.path.realpath(filename) > else: > ? ? print "Not found" > > > also any suggestions to retrieve the filepath from a given filename is > > highly appreciated. > > Well, realpath returns the path of the file targeted after any symbolic > links have been evaluated, which may or may not be what you want. Have > you looked at os.path.abspath? > > regards > ?Steve > -- > Steve Holden ? ? ? ?+1 571 484 6266 ? +1 800 494 3119 > Holden Web LLC ? ? ? ? ? ? ?http://www.holdenweb.com/ Hi Steve, I have tried your suggested code and also replaced os.path.realpath with os.path.abspath but still getting the same result. I want to know is there any workaround for retrieving the filepaths given only filename Regards, Sudhir From gagsl-py2 at yahoo.com.ar Wed Feb 25 11:23:32 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 25 Feb 2009 14:23:32 -0200 Subject: Convert PySerial to python 3.0 References: <385a617c-1e43-4828-8edd-3f4aadce8604@c11g2000yqj.googlegroups.com> <67d9d270-afad-4c4a-a585-81544ef66670@x13g2000yqf.googlegroups.com> Message-ID: En Wed, 25 Feb 2009 14:07:30 -0200, Seth escribi?: > This is not my code and I am fairly new to Python. I did not know how > much it would take to convert pyserial to 3.0. Someone more > knowledgeable than me could do it better and faster. I just want to > see if I could help get it to work. The last commit to pyserial repository was 8 days ago, so it's not like an abandoned project. Have you contacted the author? That said, Python 3.0 is still very recent and doesn't have a big set of 3rd party libraries as earlier versions. Maybe you should stick to 2.6 or even 2.5 for a while. -- Gabriel Genellina From Shawn at Milochik.com Wed Feb 25 11:29:25 2009 From: Shawn at Milochik.com (Shawn Milochik) Date: Wed, 25 Feb 2009 11:29:25 -0500 Subject: "Battleship" style game Message-ID: <2dc0c81b0902250829x500b8f4ald1e67bb3c5aecf51@mail.gmail.com> I started learning Java for fun, and the first project assignment in the book is to create a game like "Battleship." So, of course, I wrote it in Python first, just for fun. I haven't had the time to look up all the Java syntax. So, here it is, fully functional. I thought I'd throw it out there and see if anyone would like to offer any useful tips. I'm not claiming it's bulletproof, but it works. I just kind of came up with all the methods off of the top of my head, so if anyone has any suggestions for more elegant or efficient code, please let me know. http://shawnmilo.com/ships/ Thanks, Shawn From marco at sferacarta.com Wed Feb 25 11:38:05 2009 From: marco at sferacarta.com (Marco Mariani) Date: Wed, 25 Feb 2009 17:38:05 +0100 Subject: "Battleship" style game In-Reply-To: References: Message-ID: Shawn Milochik wrote: > I'm not claiming it's bulletproof, but it works. I just kind of came up with all the > methods off of the top of my head, so if anyone has any suggestions > for more elegant or efficient code, please let me know. Yes it's in Python alright, but it's not Pythonese yet. You could try avoiding the getter/setter stuff, and camelCase method naming, things like that, for a start. From Shawn at Milochik.com Wed Feb 25 11:50:18 2009 From: Shawn at Milochik.com (Shawn Milochik) Date: Wed, 25 Feb 2009 11:50:18 -0500 Subject: "Battleship" style game In-Reply-To: References: Message-ID: <2dc0c81b0902250850w31b6add4u35cce3e8cae82e84@mail.gmail.com> On Wed, Feb 25, 2009 at 11:38 AM, Marco Mariani wrote: > > Yes it's in Python alright, but it's not Pythonese yet. You could try > avoiding the getter/setter stuff, and camelCase method naming, things like > that, for a start. > > -- > http://mail.python.org/mailman/listinfo/python-list > What do you mean avoiding the getter/setter stuff? If I understand correctly, you're saying to directly access the attributes, which I specifically want to avoid because I may want to enforce some rules (such as not changing a ship length after it's created). The camel-case thing I get -- I use that and this_type quite a bit, probably because of the inconsistency of the languages I use regularly, and standards at work and conventions in my hobby programming. From steve at holdenweb.com Wed Feb 25 11:59:32 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 25 Feb 2009 11:59:32 -0500 Subject: File Path retrieving problem In-Reply-To: <9e0c2728-f28a-4b3a-8199-17e92da217fd@l38g2000vba.googlegroups.com> References: <86a29476-fde2-4983-af62-4eb8a68425a8@w34g2000yqm.googlegroups.com> <9e0c2728-f28a-4b3a-8199-17e92da217fd@l38g2000vba.googlegroups.com> Message-ID: music24by7 at gmail.com wrote: > On Feb 25, 8:57 pm, Steve Holden wrote: >> music24... at gmail.com wrote: >>> Hi all, >>> I am new to Python, i have installed python 2.5.4 and it is my >>> requirement. >>> I need to retrieve the path of filename in python. >>> I have found some API's to get this: >>> from os.path import realpath >>> print realpath("NEWS.txt") # here NEWS.txt exists and it shows the >>> path of the file as C:\Python25\WorkSpace\NEWS.txt >>> print realpath("abc.txt") # here abc.txt does not exist but still it >>> shows C:\Python25\WorkSpace\abc.txt >>> can anybody tell the reason why???? >>> Now took some safety measures: >>> found = lexists(realpath(filename)) >>> if found == 0: >>> print "Not Found" >>> else: >>> print realpath(filename) >>> i have given the filename as "NEWS.txt" and "abc.txt" but i am always >>> getting the output as "Not Found" >>> Can anyone please tell me where am i doing wrong???? >> It seems pretty apparent that lexists() nevert returns a true result. >> >> Why not just >> >> if os.path.exists(filename): >> print os.path.realpath(filename) >> else: >> print "Not found" >> >>> also any suggestions to retrieve the filepath from a given filename is >>> highly appreciated. >> Well, realpath returns the path of the file targeted after any symbolic >> links have been evaluated, which may or may not be what you want. Have >> you looked at os.path.abspath? >> >> regards >> Steve >> -- >> Steve Holden +1 571 484 6266 +1 800 494 3119 >> Holden Web LLC http://www.holdenweb.com/ > > > > Hi Steve, > > I have tried your suggested code and also replaced os.path.realpath > with os.path.abspath but still getting the same result. > I want to know is there any workaround for retrieving the filepaths > given only filename > What, you are saying that os.path.exists(filename) is returning false when the file exists? I find that hard to believe. Please display some evidence so I can understand this. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From thorsten at thorstenkampe.de Wed Feb 25 12:01:08 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Wed, 25 Feb 2009 18:01:08 +0100 Subject: How do I decode unicode characters in the subject using email.message_from_string()? References: <44432eaa-372e-45d2-baa2-da350a371d70@x9g2000yqk.googlegroups.com> <6a5569ec0902250609l243089d9g330ef2f578569499@mail.gmail.com> <49A553A5.4050309@holdenweb.com> Message-ID: * Gabriel Genellina (Wed, 25 Feb 2009 14:00:16 -0200) > En Wed, 25 Feb 2009 13:40:31 -0200, Thorsten Kampe > escribi?: > > * Roy H. Han (Wed, 25 Feb 2009 10:17:22 -0500) > >> Thanks, RDM, for stating the right approach. > >> Thanks, Steve, for teaching by example. > >> > >> I wonder why the email.message_from_string() method doesn't call > >> email.header.decode_header() automatically. > > > > And I wonder why you would think the header contains Unicode characters > > when it says "us-ascii" ("=?us-ascii?Q?"). I think there is a tendency > > to label everything "Unicode" someone does not understand. > > And I wonder why you would think the header does *not* contain Unicode > characters when it says "us-ascii"?. Basically because it didn't contain any Unicode characters (anything outside the ASCII range). Thorsten From steve at holdenweb.com Wed Feb 25 12:01:21 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 25 Feb 2009 12:01:21 -0500 Subject: "Battleship" style game In-Reply-To: <2dc0c81b0902250850w31b6add4u35cce3e8cae82e84@mail.gmail.com> References: <2dc0c81b0902250850w31b6add4u35cce3e8cae82e84@mail.gmail.com> Message-ID: Shawn Milochik wrote: > On Wed, Feb 25, 2009 at 11:38 AM, Marco Mariani wrote: >> Yes it's in Python alright, but it's not Pythonese yet. You could try >> avoiding the getter/setter stuff, and camelCase method naming, things like >> that, for a start. >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > What do you mean avoiding the getter/setter stuff? If I understand > correctly, you're saying to directly access the attributes, which I > specifically want to avoid because I may want to enforce some rules > (such as not changing a ship length after it's created). > If you wanted to enforce those restrictions you could just turn attributes into properties. > The camel-case thing I get -- I use that and this_type quite a bit, > probably because of the inconsistency of the languages I use > regularly, and standards at work and conventions in my hobby > programming. PEP 008 is the usual style recommendation. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From gagsl-py2 at yahoo.com.ar Wed Feb 25 12:07:07 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 25 Feb 2009 15:07:07 -0200 Subject: "Battleship" style game References: <2dc0c81b0902250850w31b6add4u35cce3e8cae82e84@mail.gmail.com> Message-ID: En Wed, 25 Feb 2009 14:50:18 -0200, Shawn Milochik escribi?: > On Wed, Feb 25, 2009 at 11:38 AM, Marco Mariani > wrote: >> >> Yes it's in Python alright, but it's not Pythonese yet. You could try >> avoiding the getter/setter stuff, and camelCase method naming, things >> like >> that, for a start. > > What do you mean avoiding the getter/setter stuff? If I understand > correctly, you're saying to directly access the attributes, which I > specifically want to avoid because I may want to enforce some rules > (such as not changing a ship length after it's created). I think Marco Mariani was suggesting something like this: class Ship(object): def __init__(self, length): self._length = length def get_length(self): return self._length length = property(get_length) # a read only property -- Gabriel Genellina From __peter__ at web.de Wed Feb 25 12:18:11 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 25 Feb 2009 18:18:11 +0100 Subject: File Path retrieving problem References: <86a29476-fde2-4983-af62-4eb8a68425a8@w34g2000yqm.googlegroups.com> <9e0c2728-f28a-4b3a-8199-17e92da217fd@l38g2000vba.googlegroups.com> Message-ID: Steve Holden wrote: > What, you are saying that > > os.path.exists(filename) > > is returning false when the file exists? I find that hard to believe. > > Please display some evidence so I can understand this. Maybe it's about access rights? $ mkdir alpha $ touch alpha/beta $ python -c"import os; print os.path.exists('alpha/beta')" True $ chmod u-x alpha $ python -c"import os; print os.path.exists('alpha/beta')" False $ I Don't know how this is handled on Windows... Peter From mail at timgolden.me.uk Wed Feb 25 12:27:07 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 25 Feb 2009 17:27:07 +0000 Subject: How do I decode unicode characters in the subject using email.message_from_string()? In-Reply-To: References: <44432eaa-372e-45d2-baa2-da350a371d70@x9g2000yqk.googlegroups.com> <6a5569ec0902250609l243089d9g330ef2f578569499@mail.gmail.com> <49A553A5.4050309@holdenweb.com> Message-ID: <49A57F6B.7090501@timgolden.me.uk> Thorsten Kampe wrote: > * Gabriel Genellina (Wed, 25 Feb 2009 14:00:16 -0200) >> En Wed, 25 Feb 2009 13:40:31 -0200, Thorsten Kampe >> escribi?: >>> * Roy H. Han (Wed, 25 Feb 2009 10:17:22 -0500) >>>> Thanks, RDM, for stating the right approach. >>>> Thanks, Steve, for teaching by example. >>>> >>>> I wonder why the email.message_from_string() method doesn't call >>>> email.header.decode_header() automatically. >>> And I wonder why you would think the header contains Unicode characters >>> when it says "us-ascii" ("=?us-ascii?Q?"). I think there is a tendency >>> to label everything "Unicode" someone does not understand. >> And I wonder why you would think the header does *not* contain Unicode >> characters when it says "us-ascii"?. > > Basically because it didn't contain any Unicode characters (anything > outside the ASCII range). And I imagine that Gabriel's point was -- and my point certainly is -- that Unicode includes all the characters *inside* the ASCII range. TJG From gagsl-py2 at yahoo.com.ar Wed Feb 25 12:36:22 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 25 Feb 2009 15:36:22 -0200 Subject: How do I decode unicode characters in the subject using email.message_from_string()? References: <44432eaa-372e-45d2-baa2-da350a371d70@x9g2000yqk.googlegroups.com> <6a5569ec0902250609l243089d9g330ef2f578569499@mail.gmail.com> <49A553A5.4050309@holdenweb.com> Message-ID: En Wed, 25 Feb 2009 15:01:08 -0200, Thorsten Kampe escribi?: > * Gabriel Genellina (Wed, 25 Feb 2009 14:00:16 -0200) >> En Wed, 25 Feb 2009 13:40:31 -0200, Thorsten Kampe >> escribi?: >> > * Roy H. Han (Wed, 25 Feb 2009 10:17:22 -0500) >> >> Thanks, RDM, for stating the right approach. >> >> Thanks, Steve, for teaching by example. >> >> >> >> I wonder why the email.message_from_string() method doesn't call >> >> email.header.decode_header() automatically. >> > >> > And I wonder why you would think the header contains Unicode >> characters >> > when it says "us-ascii" ("=?us-ascii?Q?"). I think there is a tendency >> > to label everything "Unicode" someone does not understand. >> >> And I wonder why you would think the header does *not* contain Unicode >> characters when it says "us-ascii"?. > > Basically because it didn't contain any Unicode characters (anything > outside the ASCII range). I think you have to revise your definition of "Unicode". -- Gabriel Genellina From blank at empty.blank Wed Feb 25 12:36:37 2009 From: blank at empty.blank (RGK) Date: Wed, 25 Feb 2009 12:36:37 -0500 Subject: coding style - try, except Message-ID: I'm still learning, so eager to see if there is some community wisdom about use of the try/except structures in this situation. I find myself with some potentially risky stuff and wrap it in a try/except structure with good functional results, though my code leaves me a bit uneasy. Maybe it's just esoteric, but your input is appreciated. Consider try: do something 1 do something 2 do something 3 do something 4 ... do something 25 except: print "Oops something didn't work" The risky things are just 1 & 2, and the others are not of concern, but are dependent on 1 & 2. The alternative is to do: wentOkay = True try: do something 1 do something 2 except: print "Oops something didn't work" wentOkay = False if wentOkay: do something 3 do something 4 ... do something 25 Which seems a bit verbose, but likely the better approach. Is there some other option I should be considering? Any input appreciated :) Ross. From rdmurray at bitdance.com Wed Feb 25 12:44:18 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Wed, 25 Feb 2009 17:44:18 +0000 (UTC) Subject: How do I decode unicode characters in the subject using email.message_from_string()? References: <44432eaa-372e-45d2-baa2-da350a371d70@x9g2000yqk.googlegroups.com> <6a5569ec0902250609l243089d9g330ef2f578569499@mail.gmail.com> <49A553A5.4050309@holdenweb.com> Message-ID: Steve Holden wrote: > rdmurray at bitdance.com wrote: > > Steve Holden wrote: > >>>>> from email.header import decode_header > >>>>> print > >> decode_header("=?us-ascii?Q?Inteum_C/SR_User_Tip:__Quick_Access_to_Recently_Opened_Inteu?=\r\n\t=?us-ascii?Q?m_C/SR_Records?=") > >> [('Inteum C/SR User Tip: Quick Access to Recently Opened Inteum C/SR > >> Records', 'us-ascii')] > > > > It is interesting that decode_header does what I would consider to be > > the right thing (from a pragmatic standpoint) with that particular bit > > of Microsoft not-quite-standards-compliant brain-damage; but, removing > > the tab is not in fact standards compliant if I'm reading the RFC > > correctly. > > > You'd need to quote me chapter and verse on that. I understood that the > tab simply indicated continuation, but it's a *long* time since I read > the RFCs. Tab is not mentioned in RFC 2822 except to say that it is a valid whitespace character. Header folding (insertion of ) can occur most places whitespace appears, and is defined in section 2.2.3 thusly: Each header field is logically a single line of characters comprising the field name, the colon, and the field body. For convenience however, and to deal with the 998/78 character limitations per line, the field body portion of a header field can be split into a multiple line representation; this is called "folding". The general rule is that wherever this standard allows for folding white space (not simply WSP characters), a CRLF may be inserted before any WSP. For example, the header field: Subject: This is a test can be represented as: Subject: This is a test [irrelevant note elided] The process of moving from this folded multiple-line representation of a header field to its single line representation is called "unfolding". Unfolding is accomplished by simply removing any CRLF that is immediately followed by WSP. Each header field should be treated in its unfolded form for further syntactic and semantic evaluation. So, the whitespace characters are supposed to be left unchanged after unfolding. --David From steve at holdenweb.com Wed Feb 25 12:51:34 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 25 Feb 2009 12:51:34 -0500 Subject: How do I decode unicode characters in the subject using email.message_from_string()? In-Reply-To: References: <44432eaa-372e-45d2-baa2-da350a371d70@x9g2000yqk.googlegroups.com> <6a5569ec0902250609l243089d9g330ef2f578569499@mail.gmail.com> <49A553A5.4050309@holdenweb.com> Message-ID: rdmurray at bitdance.com wrote: [...] > > The process of moving from this folded multiple-line representation > of a header field to its single line representation is called > "unfolding". Unfolding is accomplished by simply removing any CRLF > that is immediately followed by WSP. Each header field should be > treated in its unfolded form for further syntactic and semantic > evaluation. > > So, the whitespace characters are supposed to be left unchanged > after unfolding. > That would certainly appear to be the case. Thanks. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From loluengo at gmail.com Wed Feb 25 12:51:55 2009 From: loluengo at gmail.com (Lorenzo) Date: Wed, 25 Feb 2009 09:51:55 -0800 (PST) Subject: This application has failed to start because the application configuration is incorrect References: <822B0E83D23291469317E34324687437022249@production.2000soft.com> Message-ID: On 17 feb, 19:44, Mark Hammond wrote: > On 18/02/2009 5:49 AM, Sam Clark wrote: > > > I am receiving the message "Thisapplicationhasfailedtostartbecause > > theapplicationconfiguration is incorrect" when I attempt to run a > > compiled Python program on another machine. I have used py2exe on both a > > 2.6.1 and a 2.6.0 version of the .py and .pyw files. Everything works > > great on the machine where Python 2.6 is loaded, but fails on machines > > where I copy the .exe to the machine. I'm a beginner at python > > programming. In fact this is my first packaged program. Any thoughts at > > a beginners level would be helpful. > > This will be due to the C runtime library not being installed correctly > on the target machine. ? I had the same issue. After looking some "patch" solutions of putting manually some dlls on the dist folder, I realized that you can fix it by installing one of these packages, see which one fits your system: x86 http://www.microsoft.com/downloads/details.aspx?familyid=A5C84275-3B97-4AB7-A40D-3802B2AF5FC2&displaylang=en x64 http://www.microsoft.com/downloads/details.aspx?familyid=BA9257CA-337F-4B40-8C14-157CFDFFEE4E&displaylang=en PS: Mark, this could be added to a kind of "Deployment" entry in py2exe wiki, it would be useful. From steve at holdenweb.com Wed Feb 25 12:53:46 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 25 Feb 2009 12:53:46 -0500 Subject: coding style - try, except In-Reply-To: References: Message-ID: RGK wrote: > > I'm still learning, so eager to see if there is some community wisdom > about use of the try/except structures in this situation. > > I find myself with some potentially risky stuff and wrap it in a > try/except structure with good functional results, though my code leaves > me a bit uneasy. Maybe it's just esoteric, but your input is appreciated. > > Consider > > try: > do something 1 > do something 2 > do something 3 > do something 4 > ... > do something 25 > > except: > print "Oops something didn't work" > > > The risky things are just 1 & 2, and the others are not of concern, but > are dependent on 1 & 2. The alternative is to do: > > wentOkay = True > try: > do something 1 > do something 2 > > except: > print "Oops something didn't work" > wentOkay = False > > if wentOkay: > do something 3 > do something 4 > ... > do something 25 > > > Which seems a bit verbose, but likely the better approach. Is there > some other option I should be considering? > > Any input appreciated :) > The first form is far preferable: it expresses the logic directly and clearly, and is much easier to read than the second, which I personally find somewhat contorted. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From duncan-news at grisby.org Wed Feb 25 12:55:44 2009 From: duncan-news at grisby.org (Duncan Grisby) Date: Wed, 25 Feb 2009 17:55:44 GMT Subject: glibc detected *** python: corrupted double-linked list References: <49a53c36$0$713$9b622d9e@news.freenet.de> Message-ID: In article , David Cournapeau wrote: [...] >It is very unlikely the problem is in glibc - I would check your code >carefully first :) On Linux, the following are useful: You are right that it is extremely unlikely that the bug is in glibc. However, it is not impossible. Several of my colleagues and I spent months trying to track down a bug where Python would occasionally crash with a segfault while iterating through large lists. Of course the problem only ever happened on customer sites, and not in our lab. I eventually tracked it down to a bug in glibc's realloc() implementation, where once in a blue moon it would fail to copy all the data into the newly-allocated buffer. It turned out to be a bug that had been found before, but had been closed as invalid a few months earlier: http://sources.redhat.com/bugzilla/show_bug.cgi?id=5743 The fix had then been applied about a week before I found it myself. I'm not sure that particular fix has found it into any of the major Linux distributions yet. Cheers, Duncan. -- -- Duncan Grisby -- -- duncan at grisby.org -- -- http://www.grisby.org -- From __peter__ at web.de Wed Feb 25 13:07:11 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 25 Feb 2009 19:07:11 +0100 Subject: coding style - try, except References: Message-ID: Steve Holden wrote: > RGK wrote: >> >> I'm still learning, so eager to see if there is some community wisdom >> about use of the try/except structures in this situation. >> >> I find myself with some potentially risky stuff and wrap it in a >> try/except structure with good functional results, though my code leaves >> me a bit uneasy. Maybe it's just esoteric, but your input is appreciated. >> >> Consider >> >> try: >> do something 1 >> do something 2 >> do something 3 >> do something 4 >> ... >> do something 25 >> >> except: >> print "Oops something didn't work" If you don't want a specific treatment for errors anticipated in 1 and 2 there's no need for try...except at this level at all. Just pass control up the stack. >> The risky things are just 1 & 2, and the others are not of concern, but >> are dependent on 1 & 2. The alternative is to do: >> >> wentOkay = True >> try: >> do something 1 >> do something 2 >> >> except: >> print "Oops something didn't work" >> wentOkay = False >> >> if wentOkay: >> do something 3 >> do something 4 >> ... >> do something 25 >> >> >> Which seems a bit verbose, but likely the better approach. Is there >> some other option I should be considering? >> >> Any input appreciated :) >> > The first form is far preferable: it expresses the logic directly and > clearly, and is much easier to read than the second, which I personally > find somewhat contorted. How about try: # do something that may fail in a way you anticipate do something 1 do something 2 except SpecificError: deal with the problem or reraise else: # no errors above do something 3...25 Peter From clp2 at rebertia.com Wed Feb 25 13:08:55 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 25 Feb 2009 10:08:55 -0800 Subject: coding style - try, except In-Reply-To: References: Message-ID: <50697b2c0902251008u1756435tac03b3322e5a694a@mail.gmail.com> On Wed, Feb 25, 2009 at 9:36 AM, RGK wrote: > > I'm still learning, so eager to see if there is some community wisdom about > use of the try/except structures in this situation. > > I find myself with some potentially risky stuff and wrap it in a try/except > structure with good functional results, though my code leaves me a bit > uneasy. Maybe it's just esoteric, but your input is appreciated. > > Consider > > ?try: > ? ?do something 1 > ? ?do something 2 > ? ?do something 3 > ? ?do something 4 > ? ?... > ? ?do something 25 > > ?except: > ? ?print "Oops something didn't work" > > > The risky things are just 1 & 2, and the others are not of concern, but are > dependent on 1 & 2. ?The alternative is to do: > > ?wentOkay = True > ?try: > ? ?do something 1 > ? ?do something 2 > > ?except: > ? ?print "Oops something didn't work" > ? ?wentOkay = False > > ?if wentOkay: > ? ?do something 3 > ? ?do something 4 > ? ? ... > ? ?do something 25 > > > Which seems a bit verbose, but likely the better approach. ?Is there some > other option I should be considering? Yes. try-except-*else*. try: do_something_1() do_something_2() except: print "Houston, we have a problem" else: #runs only if no exception was thrown do_something_3() do_something_4() et_cetera() Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From xahlee at gmail.com Wed Feb 25 13:18:17 2009 From: xahlee at gmail.com (Xah Lee) Date: Wed, 25 Feb 2009 10:18:17 -0800 (PST) Subject: reading file to list References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> Message-ID: <15818a58-bcc6-4163-982f-d5534b087a6c@o36g2000yqh.googlegroups.com> On Feb 25, 3:34 am, nick_keighley_nos... at hotmail.com wrote: > the nasty cons then only appears in a single function which > you can hide in a library I think the following answers that. Q: If you don't like cons, lisp has arrays and hashmaps, too. A: Suppose there's a lang called gisp. In gisp, there's cons but also fons. Fons are just like cons except it has 3 cells with 3 accessors: car, cbr, cdr. Now, gisp is a old lang, the fons are deeply rooted in the lang. Every some 100 lines of code you'll see a use of fons with its extra accessor cbr, or any one of the cbaar, cdabr, cbbar, cbbbar, etc. You got annoyed by this. You as a critic, complains that fons is bad. But then some gisp fanatics retorts: ?If you don't like fons, gisp has cons, too!?. You see, by ?having something too?, does not solve the problem of pollution. Sure, you can use just cons in gisp, but every lib or other's code you encounter, there's a invasion of fons with its cbar, cbbar, cbbbar. The problem created by fons does not go away by ?having cons too?. above is from ? Fundamental Problems of Lisp http://xahlee.org/UnixResource_dir/writ/lisp_problems.html --------- > I read it. Your point seems to be "cons becomes difficult > with deeply nested structures". Could you give an example? There are few examples in these articles: ? The Concepts and Confusions of Prefix, Infix, Postfix and Fully Nested Notations http://xahlee.org/UnixResource_dir/writ/notations.html the above, 3rd section, gives detail about the problems of fully nested syntax. In particular, it shows a source code snippet of language with fully nested syntax, but is not lisp, so that lispers can get a fresh impression. ? A Ruby Illustration of Lisp Problems http://xahlee.org/UnixResource_dir/writ/lisp_problems_by_ruby.html the above, is a concrete example of showing how full nesting is cumbersome, by constrasting a simple program in Ruby and lisp. ? Why Lisp Do Not Have A Generic Copy-List Function http://xahlee.org/UnixResource_dir/writ/lisp_equal_copy_list.html the above, shows the cons problem, by looking Kent Pitman's article with a different perspective. A short Plain Text Excerpt of the ruby article cited above follows. ------------------------------ More specifically, 2 fundamental problems of lisp i feel this ruby example illustrates well: ? the cons impedes many aspects of lists. e.g. difficult to learn, confusing, hard to use, prevent development of coherent list manipulation functions. ? nested syntax impedes the functional programing paradigm of function chaining, esp when each function has 2 or more arguments (e.g. map). here's a short summary of the nesting problem: (map f x) ; 1 level of chaining (map g (map f x)) ; 2 levels (map h (map g (map f x))) ; 3 levels compare: x | f | g | h ----> unix pipe x // f // g // h ----> Mathematica h @ g @ f @ x ----> Mathematica x.f.g.h -------> various OOP langs, esp Ruby, javascript h g f x -------> some functional langs, Haskell, Ocaml The way the above works is that each of f, g, h is a lambda themselves that maps. (that is, something like ?(lambda (y) (map f y))?) Note, that any of the f, g, h may be complex pure functions (aka lambda). Because in lisp, each lambda itself will in general have quite a lot nested parens (which cannot be avoided), so this makes any chaining of functions of 2 args, for more than 2 or 3 levels of nesting, unusable for practical coding. One must define the functions separately and just call their names, or use function composition with lambda (which gets complex quickly). One major aspect of this problem is that the scope of vars becomes hard to understand in the deep nested source code. This is worse in elisp, because emacs is dynamically scoped, so you have to avoid using var of same name. Xah ?http://xahlee.org/ ? From thorsten at thorstenkampe.de Wed Feb 25 13:19:35 2009 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Wed, 25 Feb 2009 19:19:35 +0100 Subject: How do I decode unicode characters in the subject using email.message_from_string()? References: <44432eaa-372e-45d2-baa2-da350a371d70@x9g2000yqk.googlegroups.com> <6a5569ec0902250609l243089d9g330ef2f578569499@mail.gmail.com> <49A553A5.4050309@holdenweb.com> Message-ID: * Tim Golden (Wed, 25 Feb 2009 17:27:07 +0000) > Thorsten Kampe wrote: > > * Gabriel Genellina (Wed, 25 Feb 2009 14:00:16 -0200) > >> En Wed, 25 Feb 2009 13:40:31 -0200, Thorsten Kampe [...] > >>> And I wonder why you would think the header contains Unicode characters > >>> when it says "us-ascii" ("=?us-ascii?Q?"). I think there is a tendency > >>> to label everything "Unicode" someone does not understand. > >> And I wonder why you would think the header does *not* contain Unicode > >> characters when it says "us-ascii"?. > > > > Basically because it didn't contain any Unicode characters (anything > > outside the ASCII range). > > And I imagine that Gabriel's point was -- and my point certainly > is -- that Unicode includes all the characters *inside* the > ASCII range. I know that this was Gabriel's point. And my point was that Gabriel's point was pointless. If you call any text (or character) "Unicode" then the word "Unicode" is generalized to an extent where it doesn't mean anything at all anymore and becomes a buzz word. With the same reason you could call ASCII an Unicode encoding (which it isn't) because all ASCII characters are Unicode characters (code points). Only encodings that cover the full Unicode range can reasonably be called Unicode encodings. The OP just saw some "weird characters" in the email subject and thought "I know. It looks weird. Must be Unicode". But it wasn't. It was good ole ASCII - only Quoted Printable encoded. Thorsten From gagsl-py2 at yahoo.com.ar Wed Feb 25 13:21:58 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 25 Feb 2009 16:21:58 -0200 Subject: How do I decode unicode characters in the subject using email.message_from_string()? References: <44432eaa-372e-45d2-baa2-da350a371d70@x9g2000yqk.googlegroups.com> <6a5569ec0902250609l243089d9g330ef2f578569499@mail.gmail.com> <49A553A5.4050309@holdenweb.com> Message-ID: En Wed, 25 Feb 2009 15:44:18 -0200, escribi?: > Tab is not mentioned in RFC 2822 except to say that it is a valid > whitespace character. Header folding (insertion of ) can > occur most places whitespace appears, and is defined in section > 2.2.3 thusly: [...] > So, the whitespace characters are supposed to be left unchanged > after unfolding. Yep, there is an old bug report sleeping in the tracker about this... -- Gabriel Genellina From Scott.Daniels at Acm.Org Wed Feb 25 13:22:46 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 25 Feb 2009 10:22:46 -0800 Subject: coding style - try, except In-Reply-To: References: Message-ID: RGK wrote: > I'm still learning, so eager to see if there is some community wisdom > about use of the try/except structures in this situation.... > try: > do something 1 > do something 2 > do something 3 > do something 4 > ... > do something 25 > except: > print "Oops something didn't work" > > The risky things are just 1 & 2, and the others are not of concern, but > are dependent on 1 & 2. The alternative is to do: > > wentOkay = True > try: > do something 1 > do something 2 > except: > print "Oops something didn't work" > wentOkay = False > if wentOkay: > do something 3 > do something 4 > ... > do something 25 > Which seems a bit verbose, but likely the better approach. Is there > some other option I should be considering? What's wrong with: try: do something 1 do something 2 except (AttributeError, ValueError), why: # Don't use bare except print "Oops something didn't work: %s" % why else: do something 3 do something 4 ... do something 25 --Scott David Daniels Scott.Daniels at Acm.Org From lists at cheimes.de Wed Feb 25 13:26:23 2009 From: lists at cheimes.de (Christian Heimes) Date: Wed, 25 Feb 2009 19:26:23 +0100 Subject: coding style - try, except In-Reply-To: References: Message-ID: RGK wrote: > Any input appreciated :) How about: import logging try: # run your function some_function() except Exception: # except only the exceptions you *really* want to catch # at most you should except "Exception" since it doesn't # catch KeyboardInterrupt and SystemExit logging.exception("An error has occured") # logging is preferred over a simple print because it # also prints out a nice traceback else: # the else block is reached when no exception has occured some_other() finally: # the finally block is *always* executed at least # use it to clean up some resources some_cleanup_code() Christian From Shawn at Milochik.com Wed Feb 25 13:33:48 2009 From: Shawn at Milochik.com (Shawn Milochik) Date: Wed, 25 Feb 2009 13:33:48 -0500 Subject: "Battleship" style game In-Reply-To: References: <2dc0c81b0902250850w31b6add4u35cce3e8cae82e84@mail.gmail.com> Message-ID: <2dc0c81b0902251033m79dd4157x401283d993214e4@mail.gmail.com> Thanks. I wasn't aware of the property() function, but I read up on it. I modified the Vessels.py file, but not the board file (except where necessary to handle the changes made to Vessels. Is this better? http://shawnmilo.com/ships/ships2/ From chrysn at fsfe.org Wed Feb 25 13:48:16 2009 From: chrysn at fsfe.org (chrysn at fsfe.org) Date: Wed, 25 Feb 2009 19:48:16 +0100 Subject: variables bound in moudules are None when module is not completely imported In-Reply-To: <20090224142719.GA27379@hephaistos.amsuess.com> References: <20090224142719.GA27379@hephaistos.amsuess.com> Message-ID: <20090225184816.GC28923@hephaistos.amsuess.com> On Tue, Feb 24, 2009 at 03:27:19PM +0100, chrysn at fsfe.org wrote: > * is there a workaround? > * especially, is there a workaround that works w/o rewriting the > modules that raise the exceptions? (otherwise, wrapping all the > stuff called in the __name__=="__main__" wrapper into a main() > function and then calling that would trivially solve that) update: i've found one, but this only works if the exception is raised at a point determined by the outside. to explain why this is applicable: in the examples, i used `1/0` to raise a zero division exception inside the module whose scope i want to preserve. in my practical application, the exception is thrown by a function that was previously prepared by the outside module and monkey patched to where the inner module is expected to call a method from (in my case, the gtk main loop). now if the function raising the exception saves both `sys._getframe().f_back.f_globals` and a .copy() of that dictionary, the original dictionary can later (when the exception is caught and the module's globals are all None) be .update()d with the copy, and the original module globals are restored. as said, this is just a workaround -- the original question still remains open. regards chrysn -- To use raw power is to make yourself infinitely vulnerable to greater powers. -- Bene Gesserit axiom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 204 bytes Desc: Digital signature URL: From gagsl-py2 at yahoo.com.ar Wed Feb 25 13:59:17 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 25 Feb 2009 16:59:17 -0200 Subject: How do I decode unicode characters in the subject using email.message_from_string()? References: <44432eaa-372e-45d2-baa2-da350a371d70@x9g2000yqk.googlegroups.com> <6a5569ec0902250609l243089d9g330ef2f578569499@mail.gmail.com> <49A553A5.4050309@holdenweb.com> Message-ID: En Wed, 25 Feb 2009 16:19:35 -0200, Thorsten Kampe escribi?: > * Tim Golden (Wed, 25 Feb 2009 17:27:07 +0000) >> Thorsten Kampe wrote: >> > * Gabriel Genellina (Wed, 25 Feb 2009 14:00:16 -0200) >> >> En Wed, 25 Feb 2009 13:40:31 -0200, Thorsten Kampe > [...] >> >>> And I wonder why you would think the header contains Unicode >> characters >> >>> when it says "us-ascii" ("=?us-ascii?Q?"). I think there is a >> tendency >> >>> to label everything "Unicode" someone does not understand. >> >> And I wonder why you would think the header does *not* contain >> Unicode >> >> characters when it says "us-ascii"?. >> > >> > Basically because it didn't contain any Unicode characters (anything >> > outside the ASCII range). >> >> And I imagine that Gabriel's point was -- and my point certainly >> is -- that Unicode includes all the characters *inside* the >> ASCII range. > > I know that this was Gabriel's point. And my point was that Gabriel's > point was pointless. If you call any text (or character) "Unicode" then > the word "Unicode" is generalized to an extent where it doesn't mean > anything at all anymore and becomes a buzz word. If it's text, it should use Unicode. Maybe not now, but in a few years, it will be totally unacceptable not to properly use Unicode to process textual data. > With the same reason you could call ASCII an Unicode encoding (which it > isn't) because all ASCII characters are Unicode characters (code > points). Only encodings that cover the full Unicode range can reasonably > be called Unicode encodings. Not at all. ASCII is as valid as character encoding ("coded character set" as the Unicode guys like to say) as ISO 10646 (which covers the whole range). > The OP just saw some "weird characters" in the email subject and thought > "I know. It looks weird. Must be Unicode". But it wasn't. It was good > ole ASCII - only Quoted Printable encoded. Good f*cked ASCII is Unicode too. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Wed Feb 25 14:05:28 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 25 Feb 2009 17:05:28 -0200 Subject: variables bound in moudules are None when module is not completely imported References: <20090224142719.GA27379@hephaistos.amsuess.com> <20090225184816.GC28923@hephaistos.amsuess.com> Message-ID: En Wed, 25 Feb 2009 16:48:16 -0200, escribi?: > update: i've found one, but this only works if the exception is raised > at a point determined by the outside. > > to explain why this is applicable: in the examples, i used `1/0` to > raise a zero division exception inside the module whose scope i want to > preserve. in my practical application, the exception is thrown by a > function that was previously prepared by the outside module and monkey > patched to where the inner module is expected to call a method from (in > my case, the gtk main loop). > > now if the function raising the exception saves both > `sys._getframe().f_back.f_globals` and a .copy() of that dictionary, the > original dictionary can later (when the exception is caught and the > module's globals are all None) be .update()d with the copy, and the > original module globals are restored. That makes a strange situation where the module doesn't exist in sys.modules but its globals are still alive... > as said, this is just a workaround -- the original question still > remains open. I'd try to move all the global stuff in that module into a function, "init". Importing the module will always succeed - you have to manually call init() after importing it. -- Gabriel Genellina From aisaac at american.edu Wed Feb 25 14:07:54 2009 From: aisaac at american.edu (Alan G Isaac) Date: Wed, 25 Feb 2009 14:07:54 -0500 Subject: Free Python Training: Washington, DC (3/3-5) In-Reply-To: References: Message-ID: Great idea, but if you do it again, a bit more lead time would be helpful. Cheers, Alan Isaac From blank at empty.blank Wed Feb 25 14:12:01 2009 From: blank at empty.blank (RGK) Date: Wed, 25 Feb 2009 14:12:01 -0500 Subject: coding style - try, except In-Reply-To: References: Message-ID: I'm glad I asked :) Thanks all who posted for your replies, the else-statement is a nice option. Python again comes through to deal with those pesky feelings that something could be better :) Ross. Chris Rebert wrote: > Yes. try-except-*else*. > > try: > do_something_1() > do_something_2() > except: > print "Houston, we have a problem" > else: #runs only if no exception was thrown > do_something_3() > do_something_4() > et_cetera() > > Cheers, > Chris > From steve at holdenweb.com Wed Feb 25 14:31:49 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 25 Feb 2009 14:31:49 -0500 Subject: Free Python Training: Washington, DC (3/3-5) In-Reply-To: References: Message-ID: Alan G Isaac wrote: > Great idea, but if you do it again, a bit > more lead time would be helpful. > Appreciate that. Last-minute idea. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From deets at nospam.web.de Wed Feb 25 15:15:40 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 25 Feb 2009 21:15:40 +0100 Subject: "Battleship" style game In-Reply-To: References: <2dc0c81b0902250850w31b6add4u35cce3e8cae82e84@mail.gmail.com> Message-ID: <70ln7dFcv6phU1@mid.uni-berlin.de> Shawn Milochik schrieb: > Thanks. I wasn't aware of the property() function, but I read up on > it. I modified the Vessels.py file, but not the board file (except > where necessary to handle the changes made to Vessels. Is this better? > > http://shawnmilo.com/ships/ships2/ Not really. The point about properties is that you *can* make attribute access trigger getter or setter code. But not that you do unless there is an actual reason for that. The way you do it now is simply introducing clutter, without benefit. Your class would be half the current size - without loss of functionality. Diez From martin at v.loewis.de Wed Feb 25 15:19:41 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 25 Feb 2009 21:19:41 +0100 Subject: Python dictionary size/entry limit? In-Reply-To: <49a55813$0$30232$9b4e6d93@newsspool1.arcor-online.net> References: <49a1b17d$0$28748$9b622d9e@news.freenet.de> <49a55813$0$30232$9b4e6d93@newsspool1.arcor-online.net> Message-ID: <49a5a7dd$0$30218$9b622d9e@news.freenet.de> >> On a 32-bit system, the dictionary can have up to 2**31 slots, >> meaning that the maximum number of keys is slightly smaller >> (about 2**30). > > Which, in practice, means that the size is limited by the available memory. Right. Each slot takes 12 bytes, so the storage for the slots alone would consume all available address space. >From that point of view, you can't possibly have more than 314M slots in a 32-bit address space (roughly 2**28). Regards, Martin From vincent at vincentdavis.net Wed Feb 25 15:20:28 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Wed, 25 Feb 2009 13:20:28 -0700 Subject: PYTHONPATH on Mac 10.5 Message-ID: <77e831100902251220k6ed40cdbseb039227eb3cde8@mail.gmail.com> I have looked around for a good howto setup PYTHONPATH on Mac os x 10.5 Although I get many results I am not sure which is correct. I am not sure if it is different for 10.5 over previous versions. Does anyone know of a well documented set of instructions. In my python scripts I specify which python I want to use like this #!/Library/Frameworks/Python.framework/Versions/4.1.30101/bin/python Is there a way to specify a module location or working directory? Which is best? Or should I just add location to PYTHONPATH? Thanks Vincent Davis -------------- next part -------------- An HTML attachment was scrubbed... URL: From irmen.NOSPAM at xs4all.nl Wed Feb 25 15:39:57 2009 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Wed, 25 Feb 2009 21:39:57 +0100 Subject: Python Image Library IOError - cannot find JPEG decoder? In-Reply-To: <179a3248-0179-401e-8887-0b61e5821219@c11g2000yqj.googlegroups.com> References: <179a3248-0179-401e-8887-0b61e5821219@c11g2000yqj.googlegroups.com> Message-ID: <49a5aca0$0$193$e4fe514c@news.xs4all.nl> wongobongo wrote: > On Feb 24, 9:34 am, Dario Traverso wrote: >> I've been trying to install the Python Image Library (PIL) on my Mac >> OSX Leopard laptop, but have been running into some difficulties. >> >> I've built the library, using the included setup.py script. The build >> summary checks out ok, and sounds the option libraries to all be >> found. I grabbed both libjpeg and freetype2 using fink. >> I did a similar thing, but not using Fink, on my mac (running osx 10.4) I documented the procedure I had to take to get it to work: http://www.razorvine.net/frog/user/irmen/article/2008-08-02/127 It's in Dutch but you can probably figure it out. I guess since you were on 10.5 that you have to adapt the 'DEPLOMENT_TARGET' variable in a suitable manner. Hope it helps, --irmen From bdesth.quelquechose at free.quelquepart.fr Wed Feb 25 15:48:45 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Wed, 25 Feb 2009 21:48:45 +0100 Subject: python sql query in django In-Reply-To: <66633e7f-0f8c-472e-9e9d-5930042d7626@g38g2000yqd.googlegroups.com> References: <9c401cce-88c3-48b1-a6a5-288d2b897ba3@v19g2000yqn.googlegroups.com> <49a3071a$0$18735$426a34cc@news.free.fr> <49a31936$0$24803$426a74cc@news.free.fr> <70it1cF95tgfU1@mid.uni-berlin.de> <66633e7f-0f8c-472e-9e9d-5930042d7626@g38g2000yqd.googlegroups.com> Message-ID: <49a5bc40$0$2662$426a74cc@news.free.fr> May a ?crit : > On Feb 24, 10:36 am, "Diez B. Roggisch" wrote: >>> Thanks for all your suggestions. From what I've experienced in Django >>> and now that I know a little more about how Python functions, I will >>> probably use a combination of PHP and Django, instead of trying to get >>> Python to do the web portion of my project. Thanks again! >> That sounds like the worst idea. Django's ORM is good when used from >> within django, because of all the additional goodies like the admin >> interface. >> >> But if you are going to do the webfrontend using PHP, what part is left >> for django? If it's only the ORM (for whatever you still use that >> anyway), there are better alternatives - SQLAlchemy, and SQLObject, for >> Python. They are more powerful and not interwoven with django. >> >> If you are going to hand-code the interface in PHP, I fail to see though >> why you don't do that in Django directly. You are not forced to use the >> Admin-interface. >> >> Diez > > Hello Diez, > > I think Django is fabulous for the admin-interface, a simple text > search and template inheritance. And I think you really don't get what Django is good for. > I will use Django for all of those. > What I'm not getting an answer to and cannot find an example of is a > complex search, where I have to retrieve data from multiple tables, > combine the data, remove the duplicates, etc Django's ORM is mostly a wrapper above the db-api. It's intended to make most common db access a no-brainer, not to replace full-blown SQL for complex things. Now the good news is that you *still* can drop to a lower raw-sql level - the one you'd get using either PHP or Python's db-api - for more complex things. IOW, PHP won't buy you anything here. > The code that started this thread is only a small piece > of the complex data retrieval I need to do. The "code that started this thread" is a total no-brainer using Django (as you would know by now if you had reposted your question on django's group - or even just read the FineManual, where this use case is fully documented), and doesn't even require going down to raw sql. > PHP is great for writing > complex SQL queries right in the HTML template What the .... a complex SQL query has to do in a template anyway ??? Sorry, but what you're saying here is that PHP is great for writing unmaintainable spaghetti code. FWIW, even PHP coders are trying to get out of this kind of mess nowadays. From Shawn at Milochik.com Wed Feb 25 15:54:46 2009 From: Shawn at Milochik.com (Shawn Milochik) Date: Wed, 25 Feb 2009 15:54:46 -0500 Subject: "Battleship" style game In-Reply-To: <70ln7dFcv6phU1@mid.uni-berlin.de> References: <2dc0c81b0902250850w31b6add4u35cce3e8cae82e84@mail.gmail.com> <70ln7dFcv6phU1@mid.uni-berlin.de> Message-ID: <2dc0c81b0902251254s431f903buc612c738ab3f4987@mail.gmail.com> On Wed, Feb 25, 2009 at 3:15 PM, Diez B. Roggisch wrote: > Not really. The point about properties is that you *can* make attribute > access trigger getter or setter code. > > But not that you do unless there is an actual reason for that. The way you > do it now is simply introducing clutter, without benefit. Your class would > be half the current size - without loss of functionality. > > > > Diez > -- > http://mail.python.org/mailman/listinfo/python-list > It is true that it would be fewer lines of code with the same functionality, but it's better practice to have that framework in place so that any changes made in the future wouldn't break any of the code accessing my class. Obviously this is a fairly simple game that has a fixed set of rules, but I'm trying to cultivate good habits, and I don't think that doing it this way is anti-Pythonic. Unless, of course, anything I said is wrong, which is always possible. If I'm missing a bigger-picture idea, I'd like to know about it. Thanks, Shawn From steve at holdenweb.com Wed Feb 25 16:07:36 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 25 Feb 2009 16:07:36 -0500 Subject: "Battleship" style game In-Reply-To: <2dc0c81b0902251254s431f903buc612c738ab3f4987@mail.gmail.com> References: <2dc0c81b0902250850w31b6add4u35cce3e8cae82e84@mail.gmail.com> <70ln7dFcv6phU1@mid.uni-berlin.de> <2dc0c81b0902251254s431f903buc612c738ab3f4987@mail.gmail.com> Message-ID: Shawn Milochik wrote: > On Wed, Feb 25, 2009 at 3:15 PM, Diez B. Roggisch wrote: > >> Not really. The point about properties is that you *can* make attribute >> access trigger getter or setter code. >> >> But not that you do unless there is an actual reason for that. The way you >> do it now is simply introducing clutter, without benefit. Your class would >> be half the current size - without loss of functionality. >> >> >> >> Diez >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > It is true that it would be fewer lines of code with the same > functionality, but it's better practice to have that framework in > place so that any changes made in the future wouldn't break any of the > code accessing my class. Obviously this is a fairly simple game that > has a fixed set of rules, but I'm trying to cultivate good habits, and > I don't think that doing it this way is anti-Pythonic. > > Unless, of course, anything I said is wrong, which is always possible. > If I'm missing a bigger-picture idea, I'd like to know about it. > The point of using property() is that you can start out using attribute access on its own (which is the standard Python way to do things: getters and setters are seen by most as redundant code). Once you need programmed access on read and/or write, leave the client code (the code that accesses the attributes) as it is, but turn the attributes into properties so that the functions are invoked automatically on attribute-style access. So I believe what Diez was saying is that by using properties in your existing code you are getting the worst of both worlds - unnecessarily complex objects, and code that uses those objects by calling methods when it could be accessing attributes (or properties - depending on the implementation). At least this is true of your Ship test code. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From jcd at sdf.lonestar.org Wed Feb 25 16:14:58 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Wed, 25 Feb 2009 16:14:58 -0500 Subject: "Battleship" style game In-Reply-To: <2dc0c81b0902251254s431f903buc612c738ab3f4987@mail.gmail.com> References: <2dc0c81b0902250850w31b6add4u35cce3e8cae82e84@mail.gmail.com> <70ln7dFcv6phU1@mid.uni-berlin.de> <2dc0c81b0902251254s431f903buc612c738ab3f4987@mail.gmail.com> Message-ID: <1235596498.7621.8.camel@aalcdl07> On Wed, 2009-02-25 at 15:54 -0500, Shawn Milochik wrote: > On Wed, Feb 25, 2009 at 3:15 PM, Diez B. Roggisch wrote: > > > Not really. The point about properties is that you *can* make attribute > > access trigger getter or setter code. > > > > But not that you do unless there is an actual reason for that. The way you > > do it now is simply introducing clutter, without benefit. Your class would > > be half the current size - without loss of functionality. > > > > > > > > Diez > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > It is true that it would be fewer lines of code with the same > functionality, but it's better practice to have that framework in > place so that any changes made in the future wouldn't break any of the > code accessing my class. Obviously this is a fairly simple game that > has a fixed set of rules, but I'm trying to cultivate good habits, and > I don't think that doing it this way is anti-Pythonic. > > Unless, of course, anything I said is wrong, which is always possible. > If I'm missing a bigger-picture idea, I'd like to know about it. > The piece you're missing is exactly why properties are so cool. They take what looks like attribute access from the client side, and pass it through a method. So while you can add any sort of changes you want to make can be made without breaking any client code. To them, it still looks like attribute access. class Foo(object): a = 4 class Bar(object): def __init__(self): self._a = 4 def _get_a(self): return self._a def _set_a(self, value): if not value % 2: self._a = value a = property(_get_a, _set_a) >>> foo = Foo() >>> foo.a 4 >>> foo.a = 5 >>> foo.a 5 >>> bar = Bar() >>> bar.a 4 >>> bar.a = 5 >>> bar.a 4 >>> bar.a = 6 >>> bar.a 6 > Thanks, > Shawn > -- > http://mail.python.org/mailman/listinfo/python-list > From deets at nospam.web.de Wed Feb 25 16:32:53 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 25 Feb 2009 22:32:53 +0100 Subject: "Battleship" style game In-Reply-To: References: <2dc0c81b0902250850w31b6add4u35cce3e8cae82e84@mail.gmail.com> <70ln7dFcv6phU1@mid.uni-berlin.de> Message-ID: <70lro5Fdnc6aU1@mid.uni-berlin.de> Shawn Milochik schrieb: > On Wed, Feb 25, 2009 at 3:15 PM, Diez B. Roggisch wrote: > >> Not really. The point about properties is that you *can* make attribute >> access trigger getter or setter code. >> >> But not that you do unless there is an actual reason for that. The way you >> do it now is simply introducing clutter, without benefit. Your class would >> be half the current size - without loss of functionality. >> >> >> >> Diez >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > It is true that it would be fewer lines of code with the same > functionality, but it's better practice to have that framework in > place so that any changes made in the future wouldn't break any of the > code accessing my class. Obviously this is a fairly simple game that > has a fixed set of rules, but I'm trying to cultivate good habits, and > I don't think that doing it this way is anti-Pythonic. > > Unless, of course, anything I said is wrong, which is always possible. > If I'm missing a bigger-picture idea, I'd like to know about it. You miss that Java has no properties, and thus forces prorgammers to wrap all attribute-access into getter/setters - just in case one wants something other than pure attribute access in some distant future to come. In Python this is not needed. If something starts as an attribute, and then evolves so that it needs more complex logic when being accessed, you introduce a property of the same name. Don't waste time coding for a future you can't even pretend to know. Do what is needed to solve the actual problem. Diez From emile at fenx.com Wed Feb 25 16:35:34 2009 From: emile at fenx.com (Emile van Sebille) Date: Wed, 25 Feb 2009 13:35:34 -0800 Subject: File Path retrieving problem In-Reply-To: References: <86a29476-fde2-4983-af62-4eb8a68425a8@w34g2000yqm.googlegroups.com> <9e0c2728-f28a-4b3a-8199-17e92da217fd@l38g2000vba.googlegroups.com> Message-ID: Peter Otten wrote: > Maybe it's about access rights? > > $ mkdir alpha > $ touch alpha/beta > $ python -c"import os; print os.path.exists('alpha/beta')" > True > $ chmod u-x alpha > $ python -c"import os; print os.path.exists('alpha/beta')" > False > $ > > I Don't know how this is handled on Windows... > Here's one way.... Microsoft Windows XP [Version 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp. C:\>mkdir alpha C:\>touch alpha\beta # cygwin at work here... C:\>python -c"import os; print os.path.exists('alpha/beta')" True C:\>cacls alpha /E /R "Everyone" processed dir: C:\alpha C:\>cacls alpha /E /R "Users" processed dir: C:\alpha C:\>cacls alpha /E /R "Administrators" processed dir: C:\alpha C:\>python -c"import os; print os.path.exists('alpha/beta')" False From invalid at invalid Wed Feb 25 16:39:09 2009 From: invalid at invalid (Grant Edwards) Date: Wed, 25 Feb 2009 15:39:09 -0600 Subject: "Battleship" style game References: <2dc0c81b0902250850w31b6add4u35cce3e8cae82e84@mail.gmail.com> <70ln7dFcv6phU1@mid.uni-berlin.de> <70lro5Fdnc6aU1@mid.uni-berlin.de> Message-ID: On 2009-02-25, Diez B. Roggisch wrote: > Don't waste time coding for a future you can't even pretend to > know. Do what is needed to solve the actual problem. Premature obfuscation is even worse than premature optimization. -- Grant Edwards grante Yow! Well, O.K. at I'll compromise with my visi.com principles because of EXISTENTIAL DESPAIR! From Olivier.Darge at gmail.com Wed Feb 25 17:03:22 2009 From: Olivier.Darge at gmail.com (OdarR) Date: Wed, 25 Feb 2009 14:03:22 -0800 (PST) Subject: Python Image Library IOError - cannot find JPEG decoder? References: Message-ID: On 24 f?v, 18:34, Dario Traverso wrote: > I've been trying to install the Python Image Library ?(PIL) on my Mac ? > OSX Leopard laptop, but have been running into some difficulties. > > I've built the library, using the included setup.py ?script. The build ? > summary checks out ok, and sounds the option libraries to all be ? > found. I grabbed both libjpeg and freetype2 ?using ?fink. I did'nt build it, maybe you don't want too. I used the PIL package for Python 2.5 listed here: http://pythonmac.org/packages/py25-fat/index.html hth, Olivier From mobiledreamers at gmail.com Wed Feb 25 17:24:55 2009 From: mobiledreamers at gmail.com (mobiledreamers at gmail.com) Date: Wed, 25 Feb 2009 14:24:55 -0800 Subject: [Tutor] Accessing callers context from callee method In-Reply-To: <78b3a9580902241159g3add4898na23151ebe6c0f987@mail.gmail.com> References: <78b3a9580902241159g3add4898na23151ebe6c0f987@mail.gmail.com> Message-ID: i found the solution This is my first attempt at memcaching html page using cheetah since cheetah render needs locals() i use getCallerInfo() to get the locals() and send to memcached let me know if it is possible to better do this *notice getCallerInfo * *utils.py* @log_time_func def renderpage(key, htmlfile, deleteafter=3600): from globaldb import mc try:page = mc.get(key) except: page=None clogger.info('except error mc.get '+ key) if not page: clogger.info(key+ ' rendering cheetah page') terms = getCallerInfo(1) #print terms page = str(web.render(htmlfile, asTemplate=True, terms=terms)) try:mc.set(key, page, deleteafter) except: clogger.info('except error mc.set '+ key) return page @log_time_func @memcachethis def mcrenderpage(key, htmlfile, deleteafter=3600): terms = getCallerInfo(2) #print terms return str(web.render(htmlfile, asTemplate=True, terms=terms)) def getCallerInfo(decorators=0): '''returns locals of caller using frame.optional pass number of decorators\nFrom Dig deep into python internals http://www.devx.com/opensource/Article/31593/1954' '' f = sys._getframe(2+decorators) args = inspect.getargvalues(f) return args[3] *Usage* key=facebookstuff.APP_NAME+'newstart'+str(uid) return utils.renderpage(key, 'pick.html') -- Bidegg worlds best auction site http://bidegg.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From exarkun at divmod.com Wed Feb 25 17:31:55 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Wed, 25 Feb 2009 17:31:55 -0500 Subject: "Battleship" style game In-Reply-To: <2dc0c81b0902251254s431f903buc612c738ab3f4987@mail.gmail.com> Message-ID: <20090225223155.12853.747455496.divmod.quotient.13878@henry.divmod.com> On Wed, 25 Feb 2009 15:54:46 -0500, Shawn Milochik wrote: >On Wed, Feb 25, 2009 at 3:15 PM, Diez B. Roggisch wrote: > >> Not really. The point about properties is that you *can* make attribute >> access trigger getter or setter code. >> >> But not that you do unless there is an actual reason for that. The way you >> do it now is simply introducing clutter, without benefit. Your class would >> be half the current size - without loss of functionality. >> >> >> >> Diez >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > >It is true that it would be fewer lines of code with the same >functionality, but it's better practice to have that framework in >place so that any changes made in the future wouldn't break any of the >code accessing my class. Obviously this is a fairly simple game that >has a fixed set of rules, but I'm trying to cultivate good habits, and >I don't think that doing it this way is anti-Pythonic. > >Unless, of course, anything I said is wrong, which is always possible. >If I'm missing a bigger-picture idea, I'd like to know about it. Much better practice would be writing unit tests for the behavior you want. This is a vastly greater measure of protection against future maintenance introducing bugs than the restrictions you're adding to your implementation. So if you're looking for good habits to pick up, start with unit testing. Your test.py files show you're at least thinking about testing, but you should take a look at something like the `unittest? module in the standard library and take things to the next level. Jean-Paul From steve at pearwood.info Wed Feb 25 18:08:25 2009 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 26 Feb 2009 10:08:25 +1100 Subject: variable length tuple assignment References: <70kgjnFbqktdU1@mid.dfncis.de> <50697b2c0902250141s3f19a31eye857c4a637f0d7ff@mail.gmail.com> Message-ID: <01b5c4c2$0$20652$c3e8da3@news.astraweb.com> Tim Chase wrote: > As an aside, as of the last time I read the PEP[1] on this, I > believe it exhausts (or attempts to exhaust) any iterator. IMHO, > I think this exhausting is a bad idea because it prevents things like > > def numbers(start=0): > i = start > while True: > yield i > i += 1 > > CONST_A, CONST_B, CONST_C, *rest = numbers() > > which will hang in current Py3.0 until you blow a stack or > overrun your heap somewhere because it will try to exhaust the > infinite loop. But what else can it do? Do you expect Python to read your mind and magically know when you intend to use rest and when you're intending to just throw it away? Perhaps Python could do that, via static analysis -- if rest is never used again, don't bother exhausting the iterator. But that will lead to differences in iterators that have side-effects. It will also have a subtle difference in behaviour here: it = xrange(5) # for example a, b, c, *rest = it L = list(it) # L is now [3, 4] versus a, b, c, *rest = xrange(5) parrot(rest) L = list(it) # L is now [] > It also changes the type from iter() to list() > for the remaining content (not as grevious). But that's what unpacking does. It would be a major semantic change for x, *s = some_iterator to make s an alias of some_iterator. And why would you want it to? If you do, just do this: x, s = some_iterator.next(), some_iterator -- Steven From deets at nospam.web.de Wed Feb 25 18:12:33 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 26 Feb 2009 00:12:33 +0100 Subject: python sql query in django In-Reply-To: <66633e7f-0f8c-472e-9e9d-5930042d7626@g38g2000yqd.googlegroups.com> References: <9c401cce-88c3-48b1-a6a5-288d2b897ba3@v19g2000yqn.googlegroups.com> <49a3071a$0$18735$426a34cc@news.free.fr> <49a31936$0$24803$426a74cc@news.free.fr> <70it1cF95tgfU1@mid.uni-berlin.de> <66633e7f-0f8c-472e-9e9d-5930042d7626@g38g2000yqd.googlegroups.com> Message-ID: <70m1j1Fe33teU1@mid.uni-berlin.de> > I think Django is fabulous for the admin-interface, a simple text > search and template inheritance. I will use Django for all of those. > What I'm not getting an answer to and cannot find an example of is a > complex search, where I have to retrieve data from multiple tables, > combine the data, remove the duplicates, etc between a web page and > the database. The code that started this thread is only a small piece > of the complex data retrieval I need to do. PHP is great for writing > complex SQL queries right in the HTML template and I know exactly what > it is doing. First of all, mixing technologies without need is most of the times a bad idea - so if it is really the case that you can't solve all of your issues in django, you shouldn't use it at all, but solve them in PHP. But to be honest - I doubt that django isn't capable of solving your problem. See http://docs.djangoproject.com/en/dev/topics/db/queries/#topics-db-queries for a introduction to the multitude of query-options. I doubt that your rather simple m:n-relationship is covered there. I myself use SQLAlchemy, and that can for sure query and filter those relationships. Diez From deets at nospam.web.de Wed Feb 25 18:14:28 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 26 Feb 2009 00:14:28 +0100 Subject: python sql query in django In-Reply-To: <70m1j1Fe33teU1@mid.uni-berlin.de> References: <9c401cce-88c3-48b1-a6a5-288d2b897ba3@v19g2000yqn.googlegroups.com> <49a3071a$0$18735$426a34cc@news.free.fr> <49a31936$0$24803$426a74cc@news.free.fr> <70it1cF95tgfU1@mid.uni-berlin.de> <66633e7f-0f8c-472e-9e9d-5930042d7626@g38g2000yqd.googlegroups.com> <70m1j1Fe33teU1@mid.uni-berlin.de> Message-ID: <70m1mkFe33teU2@mid.uni-berlin.de> > for a introduction to the multitude of query-options. I doubt that your > rather simple m:n-relationship is covered there. s/is/isn't/ Diez From chrysn at fsfe.org Wed Feb 25 18:24:33 2009 From: chrysn at fsfe.org (chrysn at fsfe.org) Date: Thu, 26 Feb 2009 00:24:33 +0100 Subject: variables bound in moudules are None when module is not completely imported In-Reply-To: References: <20090224142719.GA27379@hephaistos.amsuess.com> <20090225184816.GC28923@hephaistos.amsuess.com> Message-ID: <20090225232433.GD28923@hephaistos.amsuess.com> On Wed, Feb 25, 2009 at 05:05:28PM -0200, Gabriel Genellina wrote: > I'd try to move all the global stuff in that module into a function, > "init". Importing the module will always succeed - you have to manually > call init() after importing it. i normally do that anyway and would also have done so here (afaik, it's best practice anyway), but this is in this case not possible as the modules in question are not under my control at all. as pep 299 has been turned down, this can't really be considered a bug of those files. anyway, it would just be another workaround around the globals disappearing. > That makes a strange situation where the module doesn't exist in > sys.modules but its globals are still alive... is this a known bug? i mean from a garbage collection / refcount point of view, at least everything that is still referenced somewhere should be preserved. thanks chrysn -- To use raw power is to make yourself infinitely vulnerable to greater powers. -- Bene Gesserit axiom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 204 bytes Desc: Digital signature URL: From LuHe at gmx.at Wed Feb 25 18:57:25 2009 From: LuHe at gmx.at (Lukas Hetzenecker) Date: Thu, 26 Feb 2009 00:57:25 +0100 Subject: logging.Handler not working with QThreads Message-ID: <200902251627.16827.LuHe@gmx.at> Hello, I created a QTextEdit where I wanted to display log messages. A logging.Handler should do this job. It worked with one thread well, but when I start a QThread the text on all widgets is removed and I get many errors in my konsole: X Error: RenderBadGlyphSet (invalid GlyphSet parameter) 177 Extension: 152 (RENDER) Minor opcode: 25 (RenderCompositeGlyphs32) Resource id: 0x0 X Error: RenderBadGlyphSet (invalid GlyphSet parameter) 177 Extension: 152 (RENDER) Minor opcode: 25 (RenderCompositeGlyphs32) Resource id: 0x0 X Error: RenderBadGlyphSet (invalid GlyphSet parameter) 177 Extension: 152 (RENDER) Minor opcode: 25 (RenderCompositeGlyphs32) Resource id: 0x0 .. and so on I attatched a small example to this mail. Could anybody tell me what I'm doing wrong? Thanks for you help, Lukas -------------- next part -------------- A non-text attachment was scrubbed... Name: logging_error.py Type: text/x-python Size: 3262 bytes Desc: not available URL: From skippy.hammond at gmail.com Wed Feb 25 19:35:55 2009 From: skippy.hammond at gmail.com (Mark Hammond) Date: Thu, 26 Feb 2009 11:35:55 +1100 Subject: This application has failed to start because the application configuration is incorrect In-Reply-To: References: <822B0E83D23291469317E34324687437022249@production.2000soft.com> Message-ID: <49A5E3EB.6090907@gmail.com> On 26/02/2009 4:51 AM, Lorenzo wrote: > PS: Mark, this could be added to a kind of "Deployment" entry in > py2exe wiki, it would be useful. IIRC, I've never edited the py2exe wiki (despite appearances to the contrary sometimes, I don't formally maintain that package!). But that is the cool thing about Wiki's - *anyone* can add such information ;) Cheers, Mark From xahlee at gmail.com Wed Feb 25 19:46:52 2009 From: xahlee at gmail.com (Xah Lee) Date: Wed, 25 Feb 2009 16:46:52 -0800 (PST) Subject: reading file to list References: <54a7d868-34ec-4ba6-a244-f0475d245f31@z27g2000prd.googlegroups.com> <15818a58-bcc6-4163-982f-d5534b087a6c@o36g2000yqh.googlegroups.com> Message-ID: On Feb 25, 10:18 am, Xah Lee wrote: > On Feb 25, 3:34 am, nick_keighley_nos... at hotmail.com wrote: > > > the nasty cons then only appears in a single function which > > you can hide in a library > > I think the following answers that. > > Q: If you don't like cons, lisp has arrays and hashmaps, too. > > A: Suppose there's a lang called gisp. In gisp, there's cons but also > fons. Fons are just like cons except it has 3 cells with 3 accessors: > car, cbr, cdr. Now, gisp is a old lang, the fons are deeply rooted in > the lang. Every some 100 lines of code you'll see a use of fons with > its extra accessor cbr, or any one of the cbaar, cdabr, cbbar, cbbbar, > etc. You got annoyed by this. You as a critic, complains that fons is > bad. But then some gisp fanatics retorts: ?If you don't like fons, > gisp has cons, too!?. > > You see, by ?having something too?, does not solve the problem of > pollution. Sure, you can use just cons in gisp, but every lib or > other's code you encounter, there's a invasion of fons with its cbar, > cbbar, cbbbar. The problem created by fons does not go away by ?having > cons too?. > > above is from > > ? Fundamental Problems of Lisp > http://xahlee.org/UnixResource_dir/writ/lisp_problems.html > > --------- > > > I read it. Your point seems to be "cons becomes difficult > > with deeply nested structures". Could you give an example? > > There are few examples in these articles: > > ? The Concepts and Confusions of Prefix, Infix, Postfix and Fully > Nested Notations > http://xahlee.org/UnixResource_dir/writ/notations.html > > the above, 3rd section, gives detail about the problems of fully > nested syntax. In particular, it shows a source code snippet of > language with fully nested syntax, but is not lisp, so that lispers > can get a fresh impression. > > ? A Ruby Illustration of Lisp Problems > http://xahlee.org/UnixResource_dir/writ/lisp_problems_by_ruby.html > > the above, is a concrete example of showing how full nesting is > cumbersome, by constrasting a simple program in Ruby and lisp. > > ? Why Lisp Do Not Have A Generic Copy-List Function > http://xahlee.org/UnixResource_dir/writ/lisp_equal_copy_list.html > > the above, shows the cons problem, by looking Kent Pitman's article > with a different perspective. > > A short Plain Text Excerpt of the ruby article cited above follows. > ------------------------------ > > More specifically, 2 fundamental problems of lisp i feel this ruby > example illustrates well: > > ? the cons impedes many aspects of lists. e.g. difficult to learn, > confusing, hard to use, prevent development of coherent list > manipulation functions. > > ? nested syntax impedes the functional programing paradigm of function > chaining, esp when each function has 2 or more arguments (e.g. map). > > here's a short summary of the nesting problem: > > (map f x) ; 1 level of chaining > (map g (map f x)) ; 2 levels > (map h (map g (map f x))) ; 3 levels > > compare: > > x | f | g | h ----> unix pipe > x // f // g // h ----> Mathematica > h @ g @ f @ x ----> Mathematica > x.f.g.h -------> various OOP langs, esp Ruby, javascript > h g f x -------> some functional langs, Haskell, Ocaml > > The way the above works is that each of f, g, h is a lambda themselves > that maps. (that is, something like ?(lambda (y) (map f y))?) > > Note, that any of the f, g, h may be complex pure functions (aka > lambda). Because in lisp, each lambda itself will in general have > quite a lot nested parens (which cannot be avoided), so this makes any > chaining of functions of 2 args, for more than 2 or 3 levels of > nesting, unusable for practical coding. One must define the functions > separately and just call their names, or use function composition with > lambda (which gets complex quickly). One major aspect of this problem > is that the scope of vars becomes hard to understand in the deep > nested source code. This is worse in elisp, because emacs is > dynamically scoped, so you have to avoid using var of same name. Here's a actual lisp code. I don't consider it readable, due to the profusion of parens. (defun lisp-complete-symbol (&optional predicate) "Perform completion on Lisp symbol preceding point. Compare that symbol against the known Lisp symbols. If no characters can be completed, display a list of possible completions. Repeating the command at that point scrolls the list. When called from a program, optional arg PREDICATE is a predicate determining which symbols are considered, e.g. `commandp'. If PREDICATE is nil, the context determines which symbols are considered. If the symbol starts just after an open-parenthesis, only symbols with function definitions are considered. Otherwise, all symbols with function definitions, values or properties are considered." (interactive) (let ((window (get-buffer-window "*Completions*" 0))) (if (and (eq last-command this-command) window (window-live-p window) (window-buffer window) (buffer-name (window-buffer window))) ;; If this command was repeated, and ;; there's a fresh completion window with a live buffer, ;; and this command is repeated, scroll that window. (with-current-buffer (window-buffer window) (if (pos-visible-in-window-p (point-max) window) (set-window-start window (point-min)) (save-selected-window (select-window window) (scroll-up)))) ;; Do completion. (let* ((end (point)) (beg (with-syntax-table emacs-lisp-mode-syntax-table (save-excursion (backward-sexp 1) (while (= (char-syntax (following-char)) ?\') (forward-char 1)) (point)))) (pattern (buffer-substring-no-properties beg end)) (predicate (or predicate (save-excursion (goto-char beg) (if (not (eq (char-before) ?\()) (lambda (sym) ;why not just nil ? -sm (or (boundp sym) (fboundp sym) (symbol-plist sym))) ;; Looks like a funcall position. Let's double check. (if (condition-case nil (progn (up-list -2) (forward-char 1) (eq (char-after) ?\()) (error nil)) ;; If the first element of the parent list is an open ;; parenthesis we are probably not in a funcall position. ;; Maybe a `let' varlist or something. nil ;; Else, we assume that a function name is expected. 'fboundp))))) (completion (try-completion pattern obarray predicate))) (cond ((eq completion t)) ((null completion) (message "Can't find completion for \"%s\"" pattern) (ding)) ((not (string= pattern completion)) (delete-region beg end) (insert completion) ;; Don't leave around a completions buffer that's out of date. (let ((win (get-buffer-window "*Completions*" 0))) (if win (with-selected-window win (bury-buffer))))) (t (let ((minibuf-is-in-use (eq (minibuffer-window) (selected-window)))) (unless minibuf-is-in-use (message "Making completion list...")) (let ((list (all-completions pattern obarray predicate))) (setq list (sort list 'string<)) (or (eq predicate 'fboundp) (let (new) (while list (setq new (cons (if (fboundp (intern (car list))) (list (car list) " ") (car list)) new)) (setq list (cdr list))) (setq list (nreverse new)))) (if (> (length list) 1) (with-output-to-temp-buffer "*Completions*" (display-completion-list list pattern)) ;; Don't leave around a completions buffer that's ;; out of date. (let ((win (get-buffer-window "*Completions*" 0))) (if win (with-selected-window win (bury-buffer)))))) (unless minibuf-is-in-use (message "Making completion list...%s" "done"))))))))) Xah ? http://xahlee.org/ ? From philip at semanchuk.com Wed Feb 25 19:48:04 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 25 Feb 2009 19:48:04 -0500 Subject: PYTHONPATH on Mac 10.5 In-Reply-To: <77e831100902251220k6ed40cdbseb039227eb3cde8@mail.gmail.com> References: <77e831100902251220k6ed40cdbseb039227eb3cde8@mail.gmail.com> Message-ID: On Feb 25, 2009, at 3:20 PM, Vincent Davis wrote: > I have looked around for a good howto setup PYTHONPATH on Mac os x > 10.5 Although I get many results I am not sure which is correct. I > am not > sure if it is different for 10.5 over previous versions. Does anyone > know of > a well documented set of instructions. > > Is there a way to specify a module location or working directory? > Which is > best? Or should I just add location to PYTHONPATH? Hi Vincent, There are different instructions on how to set PYTHONPATH because it solves a problem (how to organize one's Python modules) that has more than one solution. It's sort of like asking "How should I organize my email?" Different strokes for different folks. Me, I don't use PYTHONPATH at all. Most of the stuff I want to import is already available in site-packages. If not, I can add a .pth file to site-packages that tells Python where to find the source. You can read about .pth files here: http://docs.python.org/library/site.html > In my python scripts I specify which python I want to use like this > #!/Library/Frameworks/Python.framework/Versions/4.1.30101/bin/python Yikes! Your scripts won't be too portable then, will they? I'm on OS X 10.5 and I don't have a directory like that. A common, more portable alternative is this: #!/usr/bin/env python That relies (obviously) on /usr/bin/env being present which means that your scripts won't work on Windows machines, for instance. But it's a whole lot more portable than what you've got now. You don't need a shebang line at all if you're willing to launch your scripts by typing `python foo.py` at the command line. That will merely execute whichever python appears first in your path. I used to always use the / usr/bin/env shebang line that I described above, but I do so less often now. It's one less dependency to deal with. So, in short, PYTHONPATH doesn't need to be set at all, and you can switch the shebang line to this: #!/usr/bin/env python Or do away with it entirely. This isn't a complete answer but has it been at least somewhat helpful? Cheers Philip From rhodri at wildebst.demon.co.uk Wed Feb 25 20:11:49 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 26 Feb 2009 01:11:49 -0000 Subject: pep 8 constants In-Reply-To: <49a505cf$0$3567$426a74cc@news.free.fr> References: <87fxje4lqh.fsf@benfinney.id.au> <49a505cf$0$3567$426a74cc@news.free.fr> Message-ID: On Wed, 25 Feb 2009 08:48:27 -0000, Bruno Desthuilliers wrote: > Ben Finney a ?crit : > (snip - about using ALL_CAPS for pseudo-constants) >> Perhaps I'd even >> argue for an update to PEP 8 that endorses this as conventional. > > +1 > > I've been a bit surprised last time I checked PEP8 to find out this > wasn't already the case - I would have sweared it was. It is. Aahz added it a few weeks ago. -- Rhodri James *-* Wildebeeste Herder to the Masses From gagsl-py2 at yahoo.com.ar Wed Feb 25 20:18:00 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 25 Feb 2009 23:18:00 -0200 Subject: variables bound in moudules are None when module is not completely imported References: <20090224142719.GA27379@hephaistos.amsuess.com> <20090225184816.GC28923@hephaistos.amsuess.com> <20090225232433.GD28923@hephaistos.amsuess.com> Message-ID: En Wed, 25 Feb 2009 21:24:33 -0200, escribi?: > On Wed, Feb 25, 2009 at 05:05:28PM -0200, Gabriel Genellina wrote: >> I'd try to move all the global stuff in that module into a function, >> "init". Importing the module will always succeed - you have to manually >> call init() after importing it. > > i normally do that anyway and would also have done so here (afaik, it's > best practice anyway), but this is in this case not possible as the > modules in question are not under my control at all. as pep 299 has been > turned down, this can't really be considered a bug of those files. You might ask the module author for this feature... At least, try to move the "registration" at the end, after any code likely to raise exceptions. > anyway, it would just be another workaround around the globals > disappearing. > >> That makes a strange situation where the module doesn't exist in >> sys.modules but its globals are still alive... > > is this a known bug? Not that I know. > i mean from a garbage collection / refcount point > of view, at least everything that is still referenced somewhere should > be preserved. In older Python versions, an error when importing a module could leave a module object in sys.module partially initialized. That's very bad! Now, the entry in sys.modules is removed in such cases. Note that functions and classes defined inside a module don't have a reference to the module itself - their __module__ attribute is a string (although functions *do* have a reference to the module namespace, as you have remarked). So the entry in sys.modules is likely to be the last and only reference, and when it's removed, the module is deleted. This is a very tricky operation and at some stage involves setting all globals to None; if not were for any external references (like a callback registered somewhere else, as in your case) the module plus the functions and classes and objects defined inside it plus its global namespace, all of these should disappear, kaput, gone. You should report it at http://bugs.python.org -- I don't think this is likely to be "fixed" now, but at least it's on record. And when someone attempts to improve the module destruction sequence, there is a better chance this is taken into account too. -- Gabriel Genellina From zvezdan at zope.com Wed Feb 25 20:44:50 2009 From: zvezdan at zope.com (Zvezdan Petkovic) Date: Wed, 25 Feb 2009 20:44:50 -0500 Subject: Python Image Library IOError - cannot find JPEG decoder? In-Reply-To: <179a3248-0179-401e-8887-0b61e5821219@c11g2000yqj.googlegroups.com> References: <179a3248-0179-401e-8887-0b61e5821219@c11g2000yqj.googlegroups.com> Message-ID: > On Feb 24, 9:34 am, Dario Traverso wrote: >> I've been trying to install the Python Image Library (PIL) on my Mac >> OSX Leopard laptop, but have been running into some difficulties. >> ... >> I've followed all of the installation instructions exactly. The build >> summary reported everything was "ok". What could be the problem here. >> Libjpeg-6b is not accessible? >> That would be my guess. It could be something obvious and something you have done, but it's worth asking: 1. Do you have the path to fink binaries, such as djpeg, in your shell PATH (e.g., /opt/local/bin for MacPorts)? 2. Did you set up the path to the libraries you linked with in the environment variable DYLD_LIBRARY_PATH? For example, DYLD_LIBRARY_PATH=/opt/local/lib for MacPorts 3. Did you execute your app with this variable available. $ env DYLD_LIBRARY_PATH=/opt/local/lib your-app Once you confirm what is missing you can write a Python wrapper to call your app with the right environment. From zvezdan at zope.com Wed Feb 25 21:11:13 2009 From: zvezdan at zope.com (Zvezdan Petkovic) Date: Wed, 25 Feb 2009 21:11:13 -0500 Subject: "Battleship" style game In-Reply-To: <2dc0c81b0902251254s431f903buc612c738ab3f4987@mail.gmail.com> References: <2dc0c81b0902250850w31b6add4u35cce3e8cae82e84@mail.gmail.com> <70ln7dFcv6phU1@mid.uni-berlin.de> <2dc0c81b0902251254s431f903buc612c738ab3f4987@mail.gmail.com> Message-ID: On Feb 25, 2009, at 3:54 PM, Shawn Milochik wrote: > It is true that it would be fewer lines of code with the same > functionality, but it's better practice to have that framework in > place so that any changes made in the future wouldn't break any of the > code accessing my class. Obviously this is a fairly simple game that > has a fixed set of rules, but I'm trying to cultivate good habits, and > I don't think that doing it this way is anti-Pythonic. Well, they are trying to help you with the best practices. You offered the code for review and they reviewed it. Whether you'll accept what they say or deny it is your call, of course. FWIW, the Pythonic way would be: >>> class Ship(object): ... def __init__(self, length): ... self._length = length ... @property ... def length(self): ... return self._length ... >>> s = Ship(5) >>> s.length 5 >>> # notice how the property is read-only which is what you wanted >>> s.length = 7 Traceback (most recent call last): File "", line 1, in AttributeError: can't set attribute >>> ^D Using @property decorator makes a read-only property. If you need a read/write property there are several ways to define setter and deleter methods with or without decorators. I hope you see that x = s.length s.position = y is a completely different style than x = s.get_length() s.set_position(y) Most of the people who program in Python prefer the first style above. From newptcai at gmail.com Wed Feb 25 21:14:40 2009 From: newptcai at gmail.com (=?GB2312?B?0rvK18qr?=) Date: Wed, 25 Feb 2009 18:14:40 -0800 (PST) Subject: Is this the right way to use unicode in a user defined Exception? Message-ID: <4fd105ea-8611-463c-a051-06130975cf20@r18g2000vbi.googlegroups.com> #------------------------------------------------ class MyError(Exception): def __init__(self): self.message = u'Some Chinese:??' def __str__(self): return self.message.encode('utf8') #------------------------------------------------ This is an exception that I defined. I have to pass it to third party libraries. As many libraries simply use str(e) to log, if I don't encode it in __str___, they will fail. But I am not quite certain if it's the right thing to do. Shouldn't every library expect to use unicode everywhere? Shouldn't they use something like : log(unicode(e)) From david.birdsong at gmail.com Wed Feb 25 21:39:30 2009 From: david.birdsong at gmail.com (birdsong) Date: Wed, 25 Feb 2009 18:39:30 -0800 (PST) Subject: thread safe to lock on key,val pairs on a dict instead of entire dict? Message-ID: Dictionaries just store references to objects, right? So is it thread safe to lock a specific key/val pair on a dictionary and modify its val and release the lock? example snippet: # assuming d_lock was initialized long ago in a thread-safe manner d_lock.acquire() d = {} d[1] = (threading.Lock(), []) d_lock.release() # test key level locking for key, data in d.items(): row_lock, rows = data row_lock.acquire() rows.append(1) row_lock.release() Of course, I'll have to lock the entire dict when adding keys that dont exist, but further calls and acquire the key specific lock before doing any write operations. From mmcclaf at gmail.com Wed Feb 25 22:31:00 2009 From: mmcclaf at gmail.com (mmcclaf) Date: Wed, 25 Feb 2009 19:31:00 -0800 (PST) Subject: Using cPickle References: <4d5ead6c-4e8a-4003-86c6-519a638da1e1@y38g2000prg.googlegroups.com> <60dcd0f0-367f-4404-a9d2-62b96ddee389@i24g2000prf.googlegroups.com> Message-ID: <1f34f542-8042-42a1-b2cf-95aa00256466@l39g2000yqn.googlegroups.com> Thanks! All fixed! From music24by7 at gmail.com Wed Feb 25 22:37:38 2009 From: music24by7 at gmail.com (music24by7 at gmail.com) Date: Wed, 25 Feb 2009 19:37:38 -0800 (PST) Subject: File Path retrieving problem References: <86a29476-fde2-4983-af62-4eb8a68425a8@w34g2000yqm.googlegroups.com> <9e0c2728-f28a-4b3a-8199-17e92da217fd@l38g2000vba.googlegroups.com> Message-ID: On Feb 26, 2:35?am, Emile van Sebille wrote: > Peter Otten wrote: > > Maybe it's about access rights? > > > $ mkdir alpha > > $ touch alpha/beta > > $ python -c"import os; print os.path.exists('alpha/beta')" > > True > > $ chmod u-x alpha > > $ python -c"import os; print os.path.exists('alpha/beta')" > > False > > $ > > > I Don't know how this is handled on Windows... > > Here's one way.... > > Microsoft Windows XP [Version 5.1.2600] > (C) Copyright 1985-2001 Microsoft Corp. > C:\>mkdir alpha > C:\>touch alpha\beta ?# cygwin at work here... > > C:\>python -c"import os; print os.path.exists('alpha/beta')" > True > > C:\>cacls alpha /E /R "Everyone" > processed dir: C:\alpha > C:\>cacls alpha /E /R "Users" > processed dir: C:\alpha > C:\>cacls alpha /E /R "Administrators" > processed dir: C:\alpha > > C:\>python -c"import os; print os.path.exists('alpha/beta')" > False Hi, This is the following code which i have used to retrieve the pathname of a filename given by the user filename = self.enText.get() # get the text entered in the text box if os.path.exists(filename): # checking if the filename exists , had replaced it with os.path.exists(os.path.abspath (filename)) print os.path.abspath(filename) else: print "Not found" actually i need to list all the files/folders with the given filename alongwith path and store it in an CSV file with index. But i am unable to get even a single filepath correctly. Whatever filename i enter the output is as : C:\Python25\WorkSpace \xyz i.e the name i entered is being appended to my workspace and displayed. Guys, i am not able to understand what shall i do here...plz help me out. Regards, Sudhir From steve at holdenweb.com Wed Feb 25 23:03:09 2009 From: steve at holdenweb.com (Steve Holden) Date: Wed, 25 Feb 2009 23:03:09 -0500 Subject: File Path retrieving problem In-Reply-To: References: <86a29476-fde2-4983-af62-4eb8a68425a8@w34g2000yqm.googlegroups.com> <9e0c2728-f28a-4b3a-8199-17e92da217fd@l38g2000vba.googlegroups.com> Message-ID: music24by7 at gmail.com wrote: > On Feb 26, 2:35 am, Emile van Sebille wrote: >> Peter Otten wrote: >>> Maybe it's about access rights? >>> $ mkdir alpha >>> $ touch alpha/beta >>> $ python -c"import os; print os.path.exists('alpha/beta')" >>> True >>> $ chmod u-x alpha >>> $ python -c"import os; print os.path.exists('alpha/beta')" >>> False >>> $ >>> I Don't know how this is handled on Windows... >> Here's one way.... >> >> Microsoft Windows XP [Version 5.1.2600] >> (C) Copyright 1985-2001 Microsoft Corp. >> C:\>mkdir alpha >> C:\>touch alpha\beta # cygwin at work here... >> >> C:\>python -c"import os; print os.path.exists('alpha/beta')" >> True >> >> C:\>cacls alpha /E /R "Everyone" >> processed dir: C:\alpha >> C:\>cacls alpha /E /R "Users" >> processed dir: C:\alpha >> C:\>cacls alpha /E /R "Administrators" >> processed dir: C:\alpha >> >> C:\>python -c"import os; print os.path.exists('alpha/beta')" >> False > > Hi, > > This is the following code which i have used to retrieve the pathname > of a filename given by the user > > filename = self.enText.get() # get the text entered in the > text box > if os.path.exists(filename): # checking if the filename > exists , had replaced it with os.path.exists(os.path.abspath > (filename)) > print os.path.abspath(filename) > else: > print "Not found" > > actually i need to list all the files/folders with the given filename > alongwith path and store it in an CSV file with index. > > But i am unable to get even a single filepath correctly. > Whatever filename i enter the output is as : C:\Python25\WorkSpace > \xyz > i.e the name i entered is being appended to my workspace and > displayed. > Guys, i am not able to understand what shall i do here...plz help me > out. > Look, we aren't psychic. We can't debug code and directories we can't see. Work with us here - give us the information we need to help you. The actual code. A directory listing? Any error messages? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From mmcclaf at gmail.com Wed Feb 25 23:04:36 2009 From: mmcclaf at gmail.com (mmcclaf) Date: Wed, 25 Feb 2009 20:04:36 -0800 (PST) Subject: Queries Message-ID: I have to make some queries for 4 tables I have. The following relations are: Classes(class, type, country, numGuns, bore, displacement) Ships (name, class, launched) Battles (name, date) Outcomes (ship, battle, result) The three queries I'm stuck on are the following: 1. Find the classes that have only one ship as a member of that class (not all ships are listed in the Ship table) 2. Find the countries that had both battleships and battlecruisers (those fall under type in Classes) 3. Find those ships that "lived to fight another day"; they were damaged in one battle, but later fought in another. The best way for me to understand would be relational algebra for each of the statements. Any help in this would be greatly appreciated. From music24by7 at gmail.com Wed Feb 25 23:16:39 2009 From: music24by7 at gmail.com (music24by7 at gmail.com) Date: Wed, 25 Feb 2009 20:16:39 -0800 (PST) Subject: File Path retrieving problem References: <86a29476-fde2-4983-af62-4eb8a68425a8@w34g2000yqm.googlegroups.com> <9e0c2728-f28a-4b3a-8199-17e92da217fd@l38g2000vba.googlegroups.com> Message-ID: <69c346c0-33e2-48d9-95c9-22a11c0d47ad@p11g2000yqe.googlegroups.com> On Feb 26, 9:03?am, Steve Holden wrote: > music24... at gmail.com wrote: > > On Feb 26, 2:35 am, Emile van Sebille wrote: > >> Peter Otten wrote: > >>> Maybe it's about access rights? > >>> $ mkdir alpha > >>> $ touch alpha/beta > >>> $ python -c"import os; print os.path.exists('alpha/beta')" > >>> True > >>> $ chmod u-x alpha > >>> $ python -c"import os; print os.path.exists('alpha/beta')" > >>> False > >>> $ > >>> I Don't know how this is handled on Windows... > >> Here's one way.... > > >> Microsoft Windows XP [Version 5.1.2600] > >> (C) Copyright 1985-2001 Microsoft Corp. > >> C:\>mkdir alpha > >> C:\>touch alpha\beta ?# cygwin at work here... > > >> C:\>python -c"import os; print os.path.exists('alpha/beta')" > >> True > > >> C:\>cacls alpha /E /R "Everyone" > >> processed dir: C:\alpha > >> C:\>cacls alpha /E /R "Users" > >> processed dir: C:\alpha > >> C:\>cacls alpha /E /R "Administrators" > >> processed dir: C:\alpha > > >> C:\>python -c"import os; print os.path.exists('alpha/beta')" > >> False > > > Hi, > > > This is the following code which i have used to retrieve the pathname > > of a filename given by the user > > > ? ? ? ? filename = self.enText.get() # get the text entered in the > > text box > > ? ? ? ? if os.path.exists(filename): # checking if the filename > > exists , had replaced it with os.path.exists(os.path.abspath > > (filename)) > > ? ? ? ? ? ? print os.path.abspath(filename) > > ? ? ? ? else: > > ? ? ? ? ? ? print "Not found" > > > actually i need to list all the files/folders with the given filename > > alongwith path and store it in an CSV file with index. > > > But i am unable to get even a single filepath correctly. > > Whatever filename i enter the output is as : C:\Python25\WorkSpace > > \xyz > > i.e the name i entered is being appended to my workspace and > > displayed. > > Guys, i am not able to understand what shall i do here...plz help me > > out. > > Look, we aren't psychic. We can't debug code and directories we can't > see. Work with us here - give us the information we need to help you. > > The actual code. A directory listing? Any error messages? > > regards > ?Steve > -- > Steve Holden ? ? ? ?+1 571 484 6266 ? +1 800 494 3119 > Holden Web LLC ? ? ? ? ? ? ?http://www.holdenweb.com/ Hi Steve, Following is the code which i have written to display a GUI textbox and get any name entered by the user and search the path of this filename and then list it into an CSV file. For this i initially created an textbox widget and added an button to it. Now, i have entered a filename (like NEWS.txt) in the text boz, as you can see when i press the button i retrieve the text and then search its filepath. currently i am printing this filepath on the shell. from Tkinter import * import os from os.path import realpath, exists, abspath import tkMessageBox import Tkinter #import filePath class GUIFrameWork(Frame): """This is the GUI""" def __init__(self,master=None): """Initialize yourself""" """Initialise the base class""" Frame.__init__(self,master) """Set the Window Title""" self.master.title("Enter Text to search") """Display the main window" with a little bit of padding""" self.grid(padx=10,pady=10) self.CreateWidgets() def CreateWidgets(self): self.enText = Entry(self) self.enText.grid(row=0, column=1, columnspan=3) """Create the Button, set the text and the command that will be called when the button is clicked""" self.btnDisplay = Button(self, text="Display!", command=self.Display) self.btnDisplay.grid(row=0, column=4) def Display(self): """Called when btnDisplay is clicked, displays the contents of self.enText""" filename = self.enText.get() if os.path.exists(os.path.abspath(filename)): print os.path.abspath(filename) else: print "Not found" #tkMessageBox.showinfo("Text", "You typed: %s" % os.path.abspath(os.path.dirname(filename))) #filepath.mydir(self.enText.get()) if __name__ == "__main__": guiFrame = GUIFrameWork() guiFrame.mainloop() User Input: NEWS.txt Output: Not Found (though this file is actually present) Regards, Sudhir From sjmachin at lexicon.net Thu Feb 26 00:11:56 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 25 Feb 2009 21:11:56 -0800 (PST) Subject: File Path retrieving problem References: <86a29476-fde2-4983-af62-4eb8a68425a8@w34g2000yqm.googlegroups.com> <9e0c2728-f28a-4b3a-8199-17e92da217fd@l38g2000vba.googlegroups.com> <69c346c0-33e2-48d9-95c9-22a11c0d47ad@p11g2000yqe.googlegroups.com> Message-ID: On Feb 26, 3:16?pm, music24... at gmail.com wrote: > On Feb 26, 9:03?am, Steve Holden wrote: > > > > > music24... at gmail.com wrote: > > > On Feb 26, 2:35 am, Emile van Sebille wrote: > > >> Peter Otten wrote: > > >>> Maybe it's about access rights? > > >>> $ mkdir alpha > > >>> $ touch alpha/beta > > >>> $ python -c"import os; print os.path.exists('alpha/beta')" > > >>> True > > >>> $ chmod u-x alpha > > >>> $ python -c"import os; print os.path.exists('alpha/beta')" > > >>> False > > >>> $ > > >>> I Don't know how this is handled on Windows... > > >> Here's one way.... > > > >> Microsoft Windows XP [Version 5.1.2600] > > >> (C) Copyright 1985-2001 Microsoft Corp. > > >> C:\>mkdir alpha > > >> C:\>touch alpha\beta ?# cygwin at work here... > > > >> C:\>python -c"import os; print os.path.exists('alpha/beta')" > > >> True > > > >> C:\>cacls alpha /E /R "Everyone" > > >> processed dir: C:\alpha > > >> C:\>cacls alpha /E /R "Users" > > >> processed dir: C:\alpha > > >> C:\>cacls alpha /E /R "Administrators" > > >> processed dir: C:\alpha > > > >> C:\>python -c"import os; print os.path.exists('alpha/beta')" > > >> False > > > > Hi, > > > > This is the following code which i have used to retrieve the pathname > > > of a filename given by the user > > > > ? ? ? ? filename = self.enText.get() # get the text entered in the > > > text box > > > ? ? ? ? if os.path.exists(filename): # checking if the filename > > > exists , had replaced it with os.path.exists(os.path.abspath > > > (filename)) > > > ? ? ? ? ? ? print os.path.abspath(filename) > > > ? ? ? ? else: > > > ? ? ? ? ? ? print "Not found" > > > > actually i need to list all the files/folders with the given filename > > > alongwith path and store it in an CSV file with index. > > > > But i am unable to get even a single filepath correctly. > > > Whatever filename i enter the output is as : C:\Python25\WorkSpace > > > \xyz > > > i.e the name i entered is being appended to my workspace and > > > displayed. > > > Guys, i am not able to understand what shall i do here...plz help me > > > out. > > > Look, we aren't psychic. We can't debug code and directories we can't > > see. Work with us here - give us the information we need to help you. > > > The actual code. A directory listing? Any error messages? > > > regards > > ?Steve > > -- > > Steve Holden ? ? ? ?+1 571 484 6266 ? +1 800 494 3119 > > Holden Web LLC ? ? ? ? ? ? ?http://www.holdenweb.com/ > > Hi Steve, > > Following is the code which i have written to display a GUI textbox > and get any name entered by the user and search the path of this > filename and then list it into an CSV file. > > For this i initially created an textbox widget and added an button to > it. > Now, i have entered a filename (like NEWS.txt) in the text boz, > as you can see when i press the button i retrieve the text and then > search its filepath. > currently i am printing this filepath on the shell. > > from Tkinter import * > import os > from os.path import realpath, exists, abspath > import tkMessageBox > import Tkinter > #import filePath > > class GUIFrameWork(Frame): > ? ? """This is the GUI""" > > ? ? def __init__(self,master=None): > ? ? ? ? """Initialize yourself""" > > ? ? ? ? """Initialise the base class""" > ? ? ? ? Frame.__init__(self,master) > > ? ? ? ? """Set the Window Title""" > ? ? ? ? self.master.title("Enter Text to search") > > ? ? ? ? """Display the main window" > ? ? ? ? with a little bit of padding""" > ? ? ? ? self.grid(padx=10,pady=10) > ? ? ? ? self.CreateWidgets() > > ? ? def CreateWidgets(self): > > ? ? ? ? self.enText = Entry(self) > ? ? ? ? self.enText.grid(row=0, column=1, columnspan=3) > > ? ? ? ? """Create the Button, set the text and the > ? ? ? ? command that will be called when the button is clicked""" > ? ? ? ? self.btnDisplay = Button(self, text="Display!", > command=self.Display) > ? ? ? ? self.btnDisplay.grid(row=0, column=4) > > ? ? def Display(self): > ? ? ? ? """Called when btnDisplay is clicked, displays the contents of > self.enText""" > ? ? ? ? filename = self.enText.get() Add some more code in here: print "filename", repr(filename) cwd = os.getcwd() print "cwd", cwd abspath = os.path.abspath(filename) print "abspath", repr(abspath) exists = os.path.exists(abspath) print "exists", exists and copy/paste the output into your reply. Also tell us the name of the folder that the file allegedly exists in, with a folder listing to prove it. Also show us the result of using the ATTRIB command on your file, like in the following examples: C:\junk>attrib c:\io.sys SHR C:\IO.SYS C:\junk>attrib c:\python26\python.exe A C:\python26\python.exe Again, use copy/paste in your reply. > ? ? ? ? if os.path.exists(os.path.abspath(filename)): > ? ? ? ? ? ? print os.path.abspath(filename) > ? ? ? ? else: > ? ? ? ? ? ? print "Not found" > ? ? ? ? #tkMessageBox.showinfo("Text", "You typed: %s" % > os.path.abspath(os.path.dirname(filename))) > > ? ? ? ? #filepath.mydir(self.enText.get()) > > if __name__ == "__main__": > ? ? guiFrame = GUIFrameWork() > ? ? guiFrame.mainloop() > > User Input: NEWS.txt > Output: Not Found (though this file is actually present) From hrishys at yahoo.co.uk Thu Feb 26 00:36:04 2009 From: hrishys at yahoo.co.uk (hrishy) Date: Thu, 26 Feb 2009 05:36:04 +0000 (GMT) Subject: XML Parsing In-Reply-To: Message-ID: <206436.56338.qm@web27404.mail.ukl.yahoo.com> Ha the guru himself responding :-) --- On Wed, 25/2/09, Paul McGuire wrote: > From: Paul McGuire > Subject: Re: XML Parsing > To: python-list at python.org > Date: Wednesday, 25 February, 2009, 2:04 PM > On Feb 25, 1:17?am, hrishy > wrote: > > Hi > > > > Something like this > > > > > > > Note i am not a python programmer just a enthusiast > and i was curious why people on the list didnt suggest a > code like above > > > > You just beat the rest of us to it - good example of > ElementTree for > parsing XML (and I Iearned the '//' shortcut for > one or more > intervening tag levels). > > To the OP: if you are parsing XML, I would look hard at the > modules > (esp. ElementTree) that are written explicitly for XML, > before > considering using regular expressions. There are just too > many > potential surprises when trying to match XML tags - > presence/absence/ > order of attributes, namespaces, whitespace inside tags, to > name a > few. > > -- Paul > -- > http://mail.python.org/mailman/listinfo/python-list From hrishys at yahoo.co.uk Thu Feb 26 00:39:39 2009 From: hrishys at yahoo.co.uk (hrishy) Date: Thu, 26 Feb 2009 05:39:39 +0000 (GMT) Subject: XML Parsing In-Reply-To: <1235565442.6046.2.camel@mctell> Message-ID: <486443.55132.qm@web27405.mail.ukl.yahoo.com> Hi Cliff Thanks so using elementree is the right way to handle this problem regards Hrishy --- On Wed, 25/2/09, J. Clifford Dyer wrote: > From: J. Clifford Dyer > Subject: Re: XML Parsing > To: hrishys at yahoo.co.uk > Cc: python-list at python.org, "Lie Ryan" > Date: Wednesday, 25 February, 2009, 12:37 PM > Probably because you responded an hour after the question > was posted, > and in the dead of night. Newsgroups often move slower > than that. But > now we have posted a solution like that, so all's well > in the world. :) > > Cheers, > Cliff > > > On Wed, 2009-02-25 at 08:20 +0000, hrishy wrote: > > Hi Lie > > > > I am not a python guy but very interested in the > langauge and i consider the people on this list to be > intelligent and was wundering why you people did not suggest > xpath for this kind of a problem just curious and willing to > learn. > > > > I am searching for a answer but the question is > > why not use xpath to extract xml text from a xml doc ? > > > > regards > > Hrishy > > > > > > --- On Wed, 25/2/09, Lie Ryan > wrote: > > > > > From: Lie Ryan > > > Subject: Re: XML Parsing > > > To: python-list at python.org > > > Date: Wednesday, 25 February, 2009, 7:33 AM > > > Are you searching for answer or searching for > another people > > > that have > > > the same answer as you? :) > > > > > > "Many roads lead to Rome" is a very > famous > > > quotation... > > > > > > -- > > > > http://mail.python.org/mailman/listinfo/python-list > > > > > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > From gherron at islandtraining.com Thu Feb 26 01:45:36 2009 From: gherron at islandtraining.com (Gary Herron) Date: Wed, 25 Feb 2009 22:45:36 -0800 Subject: Queries In-Reply-To: References: Message-ID: <49A63A90.4080003@islandtraining.com> mmcclaf wrote: > I have to make some queries for 4 tables I have. The following > relations are: > > Classes(class, type, country, numGuns, bore, displacement) > Ships (name, class, launched) > Battles (name, date) > Outcomes (ship, battle, result) > > The three queries I'm stuck on are the following: > > 1. Find the classes that have only one ship as a member of that class > (not all ships are listed in the Ship table) > 2. Find the countries that had both battleships and battlecruisers > (those fall under type in Classes) > 3. Find those ships that "lived to fight another day"; they were > damaged in one battle, but later fought in another. > > The best way for me to understand would be relational algebra for each > of the statements. > Sounds like a homework assignment. Good luck with it. > Any help in this would be greatly appreciated. > -- > http://mail.python.org/mailman/listinfo/python-list > From pythonnutter at gmail.com Thu Feb 26 02:09:05 2009 From: pythonnutter at gmail.com (Python Nutter) Date: Thu, 26 Feb 2009 18:09:05 +1100 Subject: PYTHONPATH on Mac 10.5 In-Reply-To: References: <77e831100902251220k6ed40cdbseb039227eb3cde8@mail.gmail.com> Message-ID: +1 for site packages and standard shebang, still lets you launch with python first followed by .py file or followed by .py file also for some clues, just open up a terminal in your Mac OS X computer and check out your exports your PATH will be different depending on all the software and development environments you may or may not be using on your Mac, in particular: declare -x PATH="/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/Current/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin" declare -x PYTHONSTARTUP="/Users/pythonnutter/.pythonstartup" for the ultra curious, my custom python startup: $cat .pythonstartup # python startup file import readline import rlcompleter import atexit import os # tab completion readline.parse_and_bind('tab: complete') # history file histfile = os.path.join(os.environ['HOME'], '.pythonhistory') try: readline.read_history_file(histfile) except IOError: pass atexit.register(readline.write_history_file, histfile) del os, histfile, readline, rlcompleter On Windows you don't have much control in standard batch files but the way I keep my Windows box (at work mind you, none at home) multi-python'd is I configure the environment for Framework 2.5.4, and all the path environment variables are configured for the standard directory and the scripts subdirectory. in 25's scripts is go26.bat which just pre-pends the 2.6.1 path on the head of PATH, and of course a go3.bat that pre-pends in 3.0.1 if you want to get fancy, since there is no pop in batch files that I know of, you could drop a .py script in to read in PATH, pop off two entries and modify the environment PATH so you fall back down the tree (might need some list reversing in there to finish the massaging for pops) most times I get by with just exiting the terminal session in windows and a new cmd session will once again take on the defaults for 2.5.4 From qq13234722 at gmail.com Thu Feb 26 02:38:36 2009 From: qq13234722 at gmail.com (qq13234722 at gmail.com) Date: Wed, 25 Feb 2009 23:38:36 -0800 (PST) Subject: The Python's regex different from Perl's ,I want know what's the different? Message-ID: <6934d4d5-257f-451d-b318-0fabe42c84e8@q11g2000yqh.googlegroups.com> The Python's regex different from Perl's ,I want know what's the different? From dan.barbus at gmail.com Thu Feb 26 02:46:01 2009 From: dan.barbus at gmail.com (Dan Barbus) Date: Wed, 25 Feb 2009 23:46:01 -0800 (PST) Subject: class property not working in python 2.5.1 Message-ID: <2704d479-2f52-4ada-a60e-b4b49b089a7f@z9g2000yqi.googlegroups.com> Hi, I have a problem with setting a property to a class instance, in python 2.5.1. The property is defined through get and set methods, but when I set it, the setter doesn't get called. Instead, I believe the property in the instance gets replaced with a new object (string). I have the following code (stripped down from my program): class Model(): def __init__(self, title = ''): self._views, self._title = [], None self.setTitle(title) def addView(self, view): self._views.append(view) view.onModelUpdated() def updateViews(self, trigger = None): for view in self._views: view.onModelUpdated(trigger) def getTitle(self): return self._title def setTitle(self, t): #if self.debug: if self._title != t: self._title = t self.updateViews() title = property(fget=getTitle, fset=setTitle) # client code: class CountUpdatesView(): def __init__(self): self.updates = 0 def onModelUpdated(self, trigger): self.updates += 1 m = Model('test') v = CountUpdatesView() m.addView(v) # addView calls into v.onModelUpdated() and # v.updates will be 1 after this m.title = 'new title' # Model.setTitle calls into v.onModelUpdated () # and v.updates should become 2 print m._title # should print 'new title'; instead, prints 'test' When assigning to m.title, v.updates is not changed, and the last line prints the original value, passed to the constructor. Am I missing something? I noticed that if I put m.setTitle('new title') in the client code, the code works correctly. From lists at cheimes.de Thu Feb 26 02:56:30 2009 From: lists at cheimes.de (Christian Heimes) Date: Thu, 26 Feb 2009 08:56:30 +0100 Subject: class property not working in python 2.5.1 In-Reply-To: <2704d479-2f52-4ada-a60e-b4b49b089a7f@z9g2000yqi.googlegroups.com> References: <2704d479-2f52-4ada-a60e-b4b49b089a7f@z9g2000yqi.googlegroups.com> Message-ID: Dan Barbus schrieb: > Hi, > > I have a problem with setting a property to a class instance, in > python 2.5.1. The property is defined through get and set methods, but > when I set it, the setter doesn't get called. Instead, I believe the > property in the instance gets replaced with a new object (string). > > I have the following code (stripped down from my program): > > class Model(): > def __init__(self, title = ''): > self._views, self._title = [], None > self.setTitle(title) *snip* Properties don't work correctly on old style classes. You have to subclass from object in order to get a new style class. class Model(object): pass Christian From tjreedy at udel.edu Thu Feb 26 03:12:02 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 26 Feb 2009 03:12:02 -0500 Subject: Is this the right way to use unicode in a user defined Exception? In-Reply-To: <4fd105ea-8611-463c-a051-06130975cf20@r18g2000vbi.googlegroups.com> References: <4fd105ea-8611-463c-a051-06130975cf20@r18g2000vbi.googlegroups.com> Message-ID: ??? wrote: > #------------------------------------------------ > class MyError(Exception): > def __init__(self): > self.message = u'Some Chinese:??' > > def __str__(self): > return self.message.encode('utf8') > #------------------------------------------------ > > This is an exception that I defined. I have to pass it to third > party libraries. > > As many libraries simply use str(e) to log, if I don't encode it in > __str___, they will fail. > > But I am not quite certain if it's the right thing to do. Shouldn't > every library expect to use unicode everywhere? > > Shouldn't they use something like : > > log(unicode(e)) In 3.0, text is unicode. So libraries will mostly expect it. From chelaskk at gmail.com Thu Feb 26 04:05:06 2009 From: chelaskk at gmail.com (lameck kassana) Date: Thu, 26 Feb 2009 12:05:06 +0300 Subject: i have problem with glob.glob() in remotely directory Message-ID: <967cd34f0902260105q7d8b33adk579956b275b2d68b@mail.gmail.com> hey i want to count number of files in remote computer example of my code is import glob import os import time from datetime import date today=date.today() dir_count, file_count=0, 0 for files in glob.glob('\\192.168.0.45\files\*.txt'): file_count += len(files) print '----the count of ',today, '-------' print 'Found', dir_count, 'sub-directories in cwd' print 'Found', file_count, 'files in cwd' print 'Found', dir_count + file_count, 'files & sub-directories in cwd' filename="reconciliation.txt" file_string= str(file_count)+','+ str(today)+'\n' File=open(filename,"a") File.writelines( file_string) File.close() i get zero results since glob.glob( )can not traverse in \\192.168.0.45 can I get help please how can i do that??? From python at rcn.com Thu Feb 26 04:12:24 2009 From: python at rcn.com (Raymond Hettinger) Date: Thu, 26 Feb 2009 01:12:24 -0800 (PST) Subject: Proposed implementation for an Ordered Dictionary Message-ID: <5c65efb2-0862-4b85-bb37-88687ac6fedd@q9g2000yqc.googlegroups.com> Here's a proposed implementation for Py2.7 and Py3.1: http://code.activestate.com/recipes/576669/ Would like you guys to kick the tires, exercise it a bit, and let me know what you think. The recipe runs under 2.6 and 3.0 without modification so it should be easy to play with. The main virtue of the proposed API is a near-zero learning curve. The API is a same as for regular dictionaries but it remembers the insertion order and used that for iteration, repr, etc. Raymond From clp2 at rebertia.com Thu Feb 26 04:16:16 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 26 Feb 2009 01:16:16 -0800 Subject: i have problem with glob.glob() in remotely directory In-Reply-To: <967cd34f0902260105q7d8b33adk579956b275b2d68b@mail.gmail.com> References: <967cd34f0902260105q7d8b33adk579956b275b2d68b@mail.gmail.com> Message-ID: <50697b2c0902260116t7ee6f65ei878cdea6086fad6a@mail.gmail.com> On Thu, Feb 26, 2009 at 1:05 AM, lameck kassana wrote: > hey i want to count number of files in remote computer > > example of my code is > > import glob > import os > import time > from datetime import date > today=date.today() > dir_count, file_count=0, 0 > > for files in glob.glob('\\192.168.0.45\files\*.txt'): Remember that *backslash is the escape character* in Python, so you need to double-up your backslashes in the string literal (or just use forward slashes instead, Windows doesn't seem to care for Python in most cases). Right now, the path really only starts with 1 backslash and it has a formfeed character in it (\f), so it's obviously invalid; thus, your problem. So you want: #looks ugly, doesn't it? for files in glob.glob('\\\\192.168.0.45\\files\\*.txt'): Or: #will probably but not assuredly work for files in glob.glob('//192.168.0.45/files/*.txt'): Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From music24by7 at gmail.com Thu Feb 26 04:20:17 2009 From: music24by7 at gmail.com (music24by7 at gmail.com) Date: Thu, 26 Feb 2009 01:20:17 -0800 (PST) Subject: File Path retrieving problem References: <86a29476-fde2-4983-af62-4eb8a68425a8@w34g2000yqm.googlegroups.com> Message-ID: Hi Dennis Thanks for your reply and also the detailed explanation. > Or do you mean you want something that, given a bare name, searches > your file system to find where a file with that name actually is? > Yes, this is what i exactly needed. I have found something interesting to do this using the os.walk(path) function, and it worked.... I am pasting the code which i used for this: testpath=r"C:\\" logpath=r"C:\Pathfinder.txt" csvpath=r"C:\Pathfinder.csv" import os, csv def logData(d={}, logfile="c://filename999.txt", separator="\n"): """Takes a dictionary of values and writes them to the provided file path""" logstring=separator.join([str(key)+": "+d[key] for key in d.keys()])+"\n" f=open(logfile,'a') f.write(logstring) f.close() return def walker(topPath,csvpath): fDict={} logDict={} limit=1000 freed_space=0 items=0 fileHandle = csv.writer(open(csvpath, 'w')) fileHandle.writerow(['Index','Path']) for root, dirs, files in os.walk(topPath): for name in files: fpath=os.path.join(root,name) logDict["Name"]=name logDict["Path"]=fpath if name.find("NEWS"): continue else: logData(logDict, logpath, "\t") fDict[items] = name items=len(fDict.keys()) fileHandle.writerow([items,fpath]) print "Dict entry: ",items, print "Path: ",fpath if items > limit: break if items > limit: break walker(testpath,csvpath) Finally thank you all very much for the patience to listen to me. Regards, Sudhir From dmitrey.kroshko at scipy.org Thu Feb 26 04:39:48 2009 From: dmitrey.kroshko at scipy.org (dmitrey) Date: Thu, 26 Feb 2009 01:39:48 -0800 (PST) Subject: [numerical optimization] Poll "what do you miss in OpenOpt framework" Message-ID: <1555c112-7c91-47a5-8104-315553f83b26@o11g2000yql.googlegroups.com> Hi all, I created a poll "what do you miss in OpenOpt framework", could you take participation? http://www.doodle.com/participation.html?pollId=a78g5mk9sf7dnrbe Let me remember for those ones who is not familiar with OpenOpt - it's a free Python-written numerical optimization framework: http://openopt.org I intend to take you opinions into account till next OpenOpt release 0.23 (2009-03-15) Thank you in advance, Dmitrey From xahlee at gmail.com Thu Feb 26 04:42:02 2009 From: xahlee at gmail.com (Xah Lee) Date: Thu, 26 Feb 2009 01:42:02 -0800 (PST) Subject: a look at the browser scene & emacs References: <8358de80-5198-41e5-b4a2-04e681d359d1@p20g2000yqi.googlegroups.com> <86wsbeajz6.fsf@lola.quinscape.zz> Message-ID: <002094c7-f9fd-422e-a68f-67051e0c7483@w9g2000yqa.googlegroups.com> On Feb 26, 12:57 am, Miles Bader wrote: > There is ample room for people to discuss this evolution, but approaches > that start with "first, toss out the existing user interface" aren't gonna fly. Who said to toss out existing user interface, you? Are you saying that i start my suggestion with ?throw out existing UI?? If so, please point out where. > Emacs isn't going to turn into a fancy notepad clone, regardless of what > "modern" users may (think they) want... In what way you imagine emacs is going to be a fancy Microsoft Notepad clone? I've wrote the following suggestions on emacs modernization in the past 3 years: ? The Modernization of Emacs http://xahlee.org/emacs/modernization.html ? Suggestions on Emacs's Scratch Buffer http://xahlee.org/emacs/modernization_scratch_buffer.html ? Emacs's M-?key? Notation vs Alt+?key? Notation http://xahlee.org/emacs/modernization_meta_key.html ? Emacs's Menu Usability Problem http://xahlee.org/emacs/modernization_menu.html ? Emacs's Mode Line Modernization Suggestions http://xahlee.org/emacs/modernization_mode_line.html ? Usability Problems With Emacs's Letter-Case Commands http://xahlee.org/emacs/modernization_upcase-word.html ? Suggestions on Emacs's mark-word Command http://xahlee.org/emacs/modernization_mark-word.html ? Suggestions on Emacs's Line-Cutting Commands http://xahlee.org/emacs/modernization_fill-paragraph.html ? Emacs Should Adopt HTML To Replace Texinfo http://xahlee.org/emacs/modernization_html_vs_info.html ? Emacs Should Support HTML Mail http://xahlee.org/emacs/modernization_html_mail.html ? Emacs's HTML Mode Sucks http://xahlee.org/emacs/emacs_html_sucks.html which item, in which article, do you think that emacs is going to turn into Notepad clone? is the suggestion of using modern standard shortcut set of X C V for Cut, Copy, Paste, of which Linux uses, means it is turning emacs to a fancy Notepad clone? Is fixing emacs's confusing undo and no redo, that is periodically bitched by programer in blogs, considered making emacs into a Notepad clone? Is the suggestion for a statistics based ergonomic keybinding design that are more faster to execute, easier on the fingers, and easier to remember, mean it is turning emacs to a fancy notepad clone? is the suggestion of getting rid of *scratch* buffer, and introduce a command ?New? with shortcut Ctrl+n, that creates new buffer anytime anywhere, which lets user create multiple scratch buffers defaulting to any mode and compatible for the rest of Linux's shortcuts, means it is a fancy Microsoft Notepad? is the suggestion of changing notation from C- and M- to Ctrl+ and Alt +, such that it reflects the lable on the keyboard, and Richard Stallman agrees may be a good idea, means it's Notepad? is the suggestion of supporting html mail, and interface to gmail out of the box, means it's becoming Microsoft Notepad? is it simply the fact that making things easier to use, means kissing Microsoft's ass? Is the open source Firefox, and Google's extremely advanced technologies and easy to use applications such as gmail, google map, google earth, google code, all becoming Microsoft Notepad clone? Xah ? http://xahlee.org/ ? From python-url at phaseit.net Thu Feb 26 04:58:34 2009 From: python-url at phaseit.net (Gabriel Genellina) Date: Thu, 26 Feb 2009 09:58:34 +0000 (UTC) Subject: Python-URL! - weekly Python news and links (Feb 26) Message-ID: QOTW: "I believe this is because Microsoft failed to understand the original meaning of ___________________, and persisted with this ghastly error in the name of backwards compatibility, justifying it by suggesting that _________________________." "Somebody should have cards printed up..." - the comedy duo of Steve Holden and Grant Edwards http://groups.google.com/group/comp.lang.python/msg/5f44b59ba85c94c7 Code challenge: generate all integers using only digits 1,2,3 and arithmetic operations http://groups.google.com/group/comp.lang.python/t/b387f99deb376392/ How "pythonic" is to put code inside __init__.py? http://groups.google.com/group/comp.lang.python/t/ee5fe57066843c94/ datetime.time treats midnight as False - is that sensible? http://groups.google.com/group/comp.lang.python/t/9e3914f85feb4ddc/ SQLAlchemy got very much appreciation in this thread: "does a lot more than just an ORM, but can be used as a better DB-API too" http://groups.google.com/group/comp.lang.python/t/53ddd0045c89e315/ FAQ: I create a big object and later destroy it. Why does memory usage not return to its initial value? http://groups.google.com/group/comp.lang.python/t/2c6ed3f94378b29c/ How mmap (and numpy.memmap) works: http://groups.google.com/group/comp.lang.python/t/4fc4966065012dad/ The right way to print 'bytes' in Python 3.0: http://groups.google.com/group/comp.lang.python/t/95033de64e9c35e8/ How do arguments get passed to functions? http://groups.google.com/group/comp.lang.python/t/fb8c61eb265123db/ ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous daily python url http://www.pythonware.com/daily Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers The Python Papers aims to publish "the efforts of Python enthusiats": http://pythonpapers.org/ The Python Magazine is a technical monthly devoted to Python: http://pythonmagazine.com Readers have recommended the "Planet" sites: http://planetpython.org http://planet.python.org comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ The somewhat older Vaults of Parnassus ambitiously collects references to all sorts of Python resources. http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donations/ The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions. http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes. http://code.activestate.com/recipes/langs/python/ Many Python conferences around the world are in preparation. Watch this space for links to them. Among several Python-oriented RSS/RDF feeds available, see: http://www.python.org/channews.rdf For more, see: http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://www.python.org/dev/peps/pep-0042/ del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python *Py: the Journal of the Python Language* http://www.pyzine.com Dr.Dobb's Portal is another source of Python news and articles: http://www.ddj.com/TechSearch/searchResults.jhtml?queryText=python and Python articles regularly appear at IBM DeveloperWorks: http://www.ibm.com/developerworks/search/searchResults.jsp?searchSite=dW&searchScope=dW&encodedQuery=python&rankprofile=8 Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://search.gmane.org/?query=python+URL+weekly+news+links&group=gmane.comp.python.general&sort=date http://groups.google.com/groups/search?q=Python-URL!+group%3Acomp.lang.python&start=0&scoring=d& http://lwn.net/Search/DoSearch?words=python-url&ctype3=yes&cat_25=yes There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". Write to the same address to unsubscribe. -- The Python-URL! Team-- Phaseit, Inc. (http://phaseit.net) is pleased to participate in and sponsor the "Python-URL!" project. Watch this space for upcoming news about posting archives. From tassilo at member.fsf.org Thu Feb 26 04:59:49 2009 From: tassilo at member.fsf.org (Tassilo Horn) Date: Thu, 26 Feb 2009 10:59:49 +0100 Subject: a look at the browser scene & emacs References: <8358de80-5198-41e5-b4a2-04e681d359d1@p20g2000yqi.googlegroups.com> <86wsbeajz6.fsf@lola.quinscape.zz> <002094c7-f9fd-422e-a68f-67051e0c7483@w9g2000yqa.googlegroups.com> Message-ID: <87k57dwmay.fsf@thinkpad.tsdh.de> Xah Lee writes: Hi Xah, > is the suggestion of using modern standard shortcut set of X C V for > Cut, Copy, Paste, of which Linux uses, means it is turning emacs to a > fancy Notepad clone? The functionality stays the same, but IMO it would confuse most users. Killing is not cutting, yanking is not pasting. The whole concepts (kill-ring vs. simple copy&paste) are much different. > Is fixing emacs's confusing undo and no redo, that is periodically > bitched by programer in blogs, considered making emacs into a Notepad > clone? It's much more advanced than the usual sequential undo, but I admit that it can get confusing sometimes. So instead of dropping it I'd prefer to think about a better UI for it. > Is the suggestion for a statistics based ergonomic keybinding design > that are more faster to execute, easier on the fingers, and easier to > remember, mean it is turning emacs to a fancy notepad clone? Users use different commands and your bindings may be better for you on your querty keyboard, but I'm sure they're not on my German Dvorak Type II keyboard. > is the suggestion of getting rid of *scratch* buffer, and introduce a > command ?New? with shortcut Ctrl+n, that creates new buffer anytime > anywhere, which lets user create multiple scratch buffers defaulting > to any mode and compatible for the rest of Linux's shortcuts, means it > is a fancy Microsoft Notepad? Such a easy key like C-n is much too valuable for such a rarely used command. C-x b foobar RET is ok, isn't it? > is the suggestion of changing notation from C- and M- to Ctrl+ and Alt > +, such that it reflects the lable on the keyboard, and Richard > Stallman agrees may be a good idea, means it's Notepad? Nope, but I'm not sure if it's possible for emacs to get the right key. Here, M is Alt, but Ctrl is indeed on the CapsLock key... And it makes key sequences much longer to write with little or no benefit. > is the suggestion of supporting html mail, and interface to gmail out > of the box, means it's becoming Microsoft Notepad? Definitively not. AFAIK Gnus can handle gmail accounts quite well. Reading HTML mail works nice, too (with emacs-w3m as helper). A simple editor would be nice for some people, too. But I guess that most current devs arent interested in writing one, cause in "the tech geekers" world mail is in text/plain. Bye, Tassilo From mmcclaf at gmail.com Thu Feb 26 05:02:23 2009 From: mmcclaf at gmail.com (Murray) Date: Thu, 26 Feb 2009 05:02:23 -0500 Subject: Queries In-Reply-To: <49A63A90.4080003@islandtraining.com> References: <49A63A90.4080003@islandtraining.com> Message-ID: It is, however I was able to get the first 8 done, I am struggling with these 3 particular ones. I have to make an SQL file based off of it, so this seems to be a blockage in my works. -----Original Message----- From: Gary Herron [mailto:gherron at islandtraining.com] Sent: Thursday, February 26, 2009 1:46 AM To: mmcclaf; python-list at python.org Subject: Re: Queries mmcclaf wrote: > I have to make some queries for 4 tables I have. The following > relations are: > > Classes(class, type, country, numGuns, bore, displacement) > Ships (name, class, launched) > Battles (name, date) > Outcomes (ship, battle, result) > > The three queries I'm stuck on are the following: > > 1. Find the classes that have only one ship as a member of that class > (not all ships are listed in the Ship table) > 2. Find the countries that had both battleships and battlecruisers > (those fall under type in Classes) > 3. Find those ships that "lived to fight another day"; they were > damaged in one battle, but later fought in another. > > The best way for me to understand would be relational algebra for each > of the statements. > Sounds like a homework assignment. Good luck with it. > Any help in this would be greatly appreciated. > -- > http://mail.python.org/mailman/listinfo/python-list > No virus found in this incoming message. Checked by AVG - www.avg.com Version: 8.0.237 / Virus Database: 270.11.3/1971 - Release Date: 02/25/09 06:40:00 From jrod at blacknode.net Thu Feb 26 05:05:40 2009 From: jrod at blacknode.net (Jrod) Date: Thu, 26 Feb 2009 04:05:40 -0600 Subject: Building python extensions Message-ID: <49A66974.8020501@blacknode.net> Lets say I compile python 2.6.1 without readline support due to not having the readline headers installed prior. Is there a standard way to recompile the extension without having to rebuild the entire source. Looking at the makefile, I found the gcc line (modified to dump the relocatable in the source root ): $ gcc -pthread -fPIC -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I. -I/py/site/Python-2.6.1/./Include -I. -IInclude -I./Include -I/usr/local/include -I/py/site/Python-2.6.1/Include -I/py/site/Python-2.6.1 -c /py/site/Python-2.6.1/Modules/readline.c -o build/temp.linux-x86_64-2.6/py/site/Python-2.6.1/Modules/readline.o -o readline.so This works (cp -av readline.so /py/2.6.1/lib/python2.6/lib-dynload/), but is less than ideal. Maybe I am missing something in the docs? In php there is phpize, is there something like this for python? 'python setup.py build' builds all the extensions in Modules/ This is my first time posting here and I am pretty new to python, so pardon me if my my logic is a bit off. I love reading, so feel free to link to the relevant documentation :) Jrod From visco31 at gmail.com Thu Feb 26 05:41:51 2009 From: visco31 at gmail.com (Visco Shaun) Date: Thu, 26 Feb 2009 16:11:51 +0530 Subject: subprocess module: execution of standard binaries without shell? Message-ID: <1235644911.8600.9.camel@ajc.k7> hi all while getting used to with subprocess module i failed in executuing a) but succeeded in running b). Can anyone explain me why as i am providing absolute path? Is this has to do anything with shared library.. which must be accessed based on system variables? a) pipe = subprocess.Popen("/bin/ls /", stdout=subprocess.PIPE, close_fds=True) ==>OSError: [Errno 2] No such file or directory b) pipe = subprocess.Popen("/bin/ls /", stdout=subprocess.PIPE, close_fds=True, shell=True) -- Thanks & Regards visco From lists at cheimes.de Thu Feb 26 05:46:08 2009 From: lists at cheimes.de (Christian Heimes) Date: Thu, 26 Feb 2009 11:46:08 +0100 Subject: subprocess module: execution of standard binaries without shell? In-Reply-To: <1235644911.8600.9.camel@ajc.k7> References: <1235644911.8600.9.camel@ajc.k7> Message-ID: Visco Shaun schrieb: > hi all > > while getting used to with subprocess module i failed in executuing a) > but succeeded in running b). Can anyone explain me why as i am providing > absolute path? Is this has to do anything with shared library.. which > must be accessed based on system variables? > > > a) pipe = subprocess.Popen("/bin/ls /", stdout=subprocess.PIPE, > close_fds=True) > ==>OSError: [Errno 2] No such file or directory You have to use a list instead of a string here. pipe = subprocess.Popen(["/bin/ls", "/"], stdout=subprocess.PIPE) From jkv at unixcluster.dk Thu Feb 26 05:46:24 2009 From: jkv at unixcluster.dk (jkv) Date: Thu, 26 Feb 2009 11:46:24 +0100 Subject: EOL for sys.stdin.readline() and raw_input() Message-ID: <49A67300.6050303@unixcluster.dk> Hi, Are there any way to change the EOL character for sys.stdin.readline() and raw_input()? My problem is that i cannot rely on that the clients connection to my application will end all lines with \n or \r\n. Sometimes they will use \r\000 as EOL. Example from my code: sys.stdout.write('Password: '); #IAC DO ECHO sys.stdout.write('\xFF\xFB\x01') password = raw_input() If the client sends 'qwerty\r\n' everything is fine and the password get stored in the variable. But sometimes, depending on how broken the telnet client are, the client will send 'qwerty\r\000' instead and then my application will hang at 'password = raw_input()' forever. Any suggestions? Regards, jkv From clp2 at rebertia.com Thu Feb 26 05:56:53 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 26 Feb 2009 02:56:53 -0800 Subject: subprocess module: execution of standard binaries without shell? In-Reply-To: <1235644911.8600.9.camel@ajc.k7> References: <1235644911.8600.9.camel@ajc.k7> Message-ID: <50697b2c0902260256x48051d6es44c2800ec1b89466@mail.gmail.com> On Thu, Feb 26, 2009 at 2:41 AM, Visco Shaun wrote: > hi all > > while getting used to with subprocess module i failed in executuing a) > but succeeded in running b). Can anyone explain me why as i am providing > absolute path? Is this has to do anything with shared library.. which > must be accessed based on system variables? > > > a) pipe = subprocess.Popen("/bin/ls /", stdout=subprocess.PIPE, > close_fds=True) > ? ? ? ? ? ? ? ?==>OSError: [Errno 2] No such file or directory You need to use a list of arguments, not just a string. You're currently telling Python to try and run a nonexistent directory (specifically, the "ls " subdirectory of /bin), since the string way of calling Popen assumes that the *entire* string is the path to the executable when shell=False. The correct way is to provide the path to the binary and then each of its arguments, in a list: pipe = subprocess.Popen(["/bin/ls", "/"], stdout=subprocess.PIPE, close_fds=True) > b) pipe = subprocess.Popen("/bin/ls /", stdout=subprocess.PIPE, > close_fds=True, shell=True) This works because shell=True sends the string through the shell, which tokenizes it and runs it, effectively splitting the string into a list for you. However, shell=True is dangerous as you need to be careful to escape special characters, whereas that's not necessary for the 'shell=False and list' way of calling Popen. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From jineu21 at hotmail.com Thu Feb 26 06:05:25 2009 From: jineu21 at hotmail.com (Clarendon) Date: Thu, 26 Feb 2009 03:05:25 -0800 (PST) Subject: Delete all items in the list Message-ID: Hi. This must be a simple command but I just can't find it in the Phthon manual. How do I delete all items with a certain condition from a list? For instance: L=['a', 'b', 'c', 'a'] I want to delete all 'a's from the list. But if L.remove('a') only deletes the first 'a'. How do you delete all 'a's? I would really appreciate your help. Thanks. From bjornjobb at gmail.com Thu Feb 26 06:07:21 2009 From: bjornjobb at gmail.com (Bjorn) Date: Thu, 26 Feb 2009 03:07:21 -0800 (PST) Subject: sending gmail with smtplib from behind a proxy Message-ID: Hi, I tried the script below to send mail by gmail from python using smptlib. I got the script here (http://kutuma.blogspot.com/2007/08/ sending-emails-via-gmail-with-python.html) It works fine from home, but at work not. I think it is because I am behind a http or a socks proxy server at work. Can I adapt this script to work from behind the http or socks proxy? I couldnt understand from the smtplib if I can specify this somehow? Sincerely, bjorn johansson ----Script--------- #!/usr/bin/python import smtplib from email.MIMEMultipart import MIMEMultipart from email.MIMEBase import MIMEBase from email.MIMEText import MIMEText from email import Encoders import os gmail_user = "your_email at gmail.com" gmail_pwd = "your_password" def mail(to, subject, text, attach): msg = MIMEMultipart() msg['From'] = gmail_user msg['To'] = to msg['Subject'] = subject msg.attach(MIMEText(text)) part = MIMEBase('application', 'octet-stream') part.set_payload(open(attach, 'rb').read()) Encoders.encode_base64(part) part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(attach)) msg.attach(part) mailServer = smtplib.SMTP("smtp.gmail.com", 587) mailServer.ehlo() mailServer.starttls() mailServer.ehlo() mailServer.login(gmail_user, gmail_pwd) mailServer.sendmail(gmail_user, to, msg.as_string()) # Should be mailServer.quit(), but that crashes... mailServer.close() mail("some.person at some.address.com", "Hello from python!", "This is a email sent with python", "my_picture.jpg") From clp2 at rebertia.com Thu Feb 26 06:15:49 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 26 Feb 2009 03:15:49 -0800 Subject: Delete all items in the list In-Reply-To: References: Message-ID: <50697b2c0902260315i754f9d39y3231f30435824bb5@mail.gmail.com> On Thu, Feb 26, 2009 at 3:05 AM, Clarendon wrote: > Hi. This must be a simple command but I just can't find it in the > Phthon manual. How do I delete all items with a certain condition from > a list? For instance: > > L=['a', 'b', 'c', 'a'] > > I want to delete all 'a's from the list. > But if L.remove('a') only deletes the first 'a'. > > How do you delete all 'a's? There are several ways. I'd go with a list comprehension: L = [i for i in L if i != 'a'] Or to modify the list in-place: L[:] = [i for i in L if i != 'a'] Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From python.list at tim.thechases.com Thu Feb 26 06:22:27 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 26 Feb 2009 05:22:27 -0600 Subject: The Python's regex different from Perl's ,I want know what's the different? In-Reply-To: <6934d4d5-257f-451d-b318-0fabe42c84e8@q11g2000yqh.googlegroups.com> References: <6934d4d5-257f-451d-b318-0fabe42c84e8@q11g2000yqh.googlegroups.com> Message-ID: <49A67B73.4090408@tim.thechases.com> > The Python's regex different from Perl's ,I want know what's the > different? Easy: bash$ diff <(lynx -dump http://perldoc.perl.org/perlre.html) <(lynx -dump http://docs.python.org/library/re.html) Had you tried the great Google in the sky, you might have found such pages as: http://mail.python.org/pipermail/python-list/2005-April/319030.html or even a popular book on the subject: http://oreilly.com/catalog/9780596002893/ -tkc From chelaskk at gmail.com Thu Feb 26 06:28:35 2009 From: chelaskk at gmail.com (lameck kassana) Date: Thu, 26 Feb 2009 14:28:35 +0300 Subject: i have problem with glob.glob() in remotely directory In-Reply-To: <50697b2c0902260116t7ee6f65ei878cdea6086fad6a@mail.gmail.com> References: <967cd34f0902260105q7d8b33adk579956b275b2d68b@mail.gmail.com> <50697b2c0902260116t7ee6f65ei878cdea6086fad6a@mail.gmail.com> Message-ID: <967cd34f0902260328x55d313fdpf55f8a69166f6a76@mail.gmail.com> i did try but still not working.But also i try os.walk() for remote computer like os.walk('\\192.168.0.45') it also failed> Thats it is my main problem do i need any new imports besides import os On 2/26/09, Chris Rebert wrote: > On Thu, Feb 26, 2009 at 1:05 AM, lameck kassana wrote: > > hey i want to count number of files in remote computer > > > > example of my code is > > > > import glob > > import os > > import time > > from datetime import date > > today=date.today() > > dir_count, file_count=0, 0 > > > > for files in glob.glob('\\192.168.0.45\files\*.txt'): > > > Remember that *backslash is the escape character* in Python, so you > need to double-up your backslashes in the string literal (or just use > forward slashes instead, Windows doesn't seem to care for Python in > most cases). Right now, the path really only starts with 1 backslash > and it has a formfeed character in it (\f), so it's obviously invalid; > thus, your problem. > > So you want: > #looks ugly, doesn't it? > > for files in glob.glob('\\\\192.168.0.45\\files\\*.txt'): > > > Or: > #will probably but not assuredly work > > for files in glob.glob('//192.168.0.45/files/*.txt'): > > > Cheers, > Chris > > > -- > Follow the path of the Iguana... > http://rebertia.com > From jerry at hotmail.com Thu Feb 26 06:50:22 2009 From: jerry at hotmail.com (sert) Date: Thu, 26 Feb 2009 11:50:22 +0000 (UTC) Subject: Efficient searching through objects Message-ID: I have written a program that reads data and updates the records for some people. They are represented by objects, and I need to read the data from a file, look the person up and then update his record. I have implemented this by creating a list with all the people's names and another list with their objects (their data). It works but after profiling the code it turns out that half the time spent in the program is spent in the list.index() function looking up names. Isn't there a less goofy and more efficient way of doing this? From dangoor at gmail.com Thu Feb 26 07:19:52 2009 From: dangoor at gmail.com (Kevin Dangoor (Mozilla)) Date: Thu, 26 Feb 2009 04:19:52 -0800 (PST) Subject: Is there something easier than ORM? References: <07cb23ac-3f67-45f2-a1ba-9fb80510db9b@z28g2000prd.googlegroups.com> <8C9A6CB8-80A6-4E10-8EA1-3C40EAED058D@semanchuk.com> <49f712d8783aa02d9f76692f11e1b1b9.squirrel@localhost> <26c3659d-ce14-4375-9da7-d9fefc4748ac@a39g2000prl.googlegroups.com> Message-ID: <8621b9e6-0f12-4d1d-835d-7af878217c42@13g2000yql.googlegroups.com> On Feb 17, 10:28?pm, alex23 wrote: > On Feb 18, 3:10?am, Robert Kern wrote: > > > Its public image definitely suffers from the impression that it's "an ORM" that > > can be compared on equal terms with packages that actually are just ORMs. I > > describe it as a very powerful toolkit for solving a wide variety of problems > > involving SQL databases. One of those tools happens to be an ORM. > > I'm going to have to steal that description the next time I try to > sell a co-worker on the value of SQLAlchemy. There's always a strong > reaction against the mention of ORMs, generally along the lines of it > moving the programmer too far away from the real action. But my > experience is identical to both andrew's and your's; there is far far > more of value in SQLA than the ORM alone. I just saw this thread via the weekly Python URL email and wanted to add one bit here. When I've been selling people on using SQLAlchemy, one argument that I make is that if you're using a relational database for storage but your program is using objects (and good Python programs do!), then you're doing ORM. If you're not using SQLAlchemy (or similar), you're likely doing ORM badly. SQLAlchemy's SQL layer definitely makes it a different beast from most ORMs. Kevin From rdmurray at bitdance.com Thu Feb 26 07:20:16 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Thu, 26 Feb 2009 12:20:16 +0000 (UTC) Subject: Efficient searching through objects References: Message-ID: sert wrote: > I have written a program that reads data and updates the records > for some people. They are represented by objects, and I need to > read the data from a file, look the person up and then update > his record. > > I have implemented this by creating a list with all the people's > names and another list with their objects (their data). > > It works but after profiling the code it turns out that half the > time spent in the program is spent in the list.index() function > looking up names. Isn't there a less goofy and more efficient > way of doing this? It sounds like what you are looking for is the dictionary data type. --RDM From bearophileHUGS at lycos.com Thu Feb 26 07:21:17 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Thu, 26 Feb 2009 04:21:17 -0800 (PST) Subject: Efficient searching through objects References: Message-ID: <37632421-5475-4859-be83-07ae2eca1773@r4g2000yqa.googlegroups.com> sert: > I have implemented this by creating a list with all the people's > names and another list with their objects (their data). > > It works but after profiling the code it turns out that half the > time spent in the program is spent in the list.index() function > looking up names. Isn't there a less goofy and more efficient > way of doing this? Try using a dict instead, where keys are the names and objects the values (it turns a linear search in a quick hash look up). . Then tell us the performance changes. Bye, bearophile From lkassana at gmail.com Thu Feb 26 07:38:01 2009 From: lkassana at gmail.com (lameck kassana) Date: Thu, 26 Feb 2009 15:38:01 +0300 Subject: problem with glob in remote directory or os.walk in remote directory in windos Message-ID: i am trying to write script which will count files for remote directory which having certain pattern. i tried with my code and have a look at this code. ----------------------------------------------------------------------------------- import glob import os import time from datetime import date today=date.today() dir_count, file_count=0, 0 for files in glob.glob('*\\192.168.0.45\files\*.txt'*): file_count += len(files) print '----the count of ',today, '-------' print 'Found', dir_count, 'sub-directories in cwd' print 'Found', file_count, 'files in cwd' print 'Found', dir_count + file_count, 'files & sub-directories in cwd' filename="reconciliation.txt" file_string= str(file_count)+','+ str(today)+'\n' File=open(filename,"a") File.writelines( file_string) File.close() -------------------------------------------------------------------------------------------------------- the problem the glob.glob() does not work in remotely directory especially in window environment i don't know why?? i also try os.walk() for remote directory it failed i am wondering why . Do i have to import a new module in import besides import glob,os -------------- next part -------------- An HTML attachment was scrubbed... URL: From jerry at hotmail.com Thu Feb 26 07:42:46 2009 From: jerry at hotmail.com (sert) Date: Thu, 26 Feb 2009 12:42:46 +0000 (UTC) Subject: Efficient searching through objects References: <37632421-5475-4859-be83-07ae2eca1773@r4g2000yqa.googlegroups.com> Message-ID: bearophileHUGS at lycos.com wrote in news:37632421-5475-4859-be83-07ae2eca1773 at r4g2000yqa.googlegro ups.com: > Try using a dict instead, where keys are the names and > objects the values (it turns a linear search in a quick > hash look up). . Then tell us the performance changes. > It halved the overall execution time. Thanks. From steve at holdenweb.com Thu Feb 26 07:44:36 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 26 Feb 2009 07:44:36 -0500 Subject: File Path retrieving problem In-Reply-To: <69c346c0-33e2-48d9-95c9-22a11c0d47ad@p11g2000yqe.googlegroups.com> References: <86a29476-fde2-4983-af62-4eb8a68425a8@w34g2000yqm.googlegroups.com> <9e0c2728-f28a-4b3a-8199-17e92da217fd@l38g2000vba.googlegroups.com> <69c346c0-33e2-48d9-95c9-22a11c0d47ad@p11g2000yqe.googlegroups.com> Message-ID: music24by7 at gmail.com wrote: > On Feb 26, 9:03 am, Steve Holden wrote: >> music24... at gmail.com wrote: >>> On Feb 26, 2:35 am, Emile van Sebille wrote: >>>> Peter Otten wrote: >>>>> Maybe it's about access rights? >>>>> $ mkdir alpha >>>>> $ touch alpha/beta >>>>> $ python -c"import os; print os.path.exists('alpha/beta')" >>>>> True >>>>> $ chmod u-x alpha >>>>> $ python -c"import os; print os.path.exists('alpha/beta')" >>>>> False >>>>> $ >>>>> I Don't know how this is handled on Windows... >>>> Here's one way.... >>>> Microsoft Windows XP [Version 5.1.2600] >>>> (C) Copyright 1985-2001 Microsoft Corp. >>>> C:\>mkdir alpha >>>> C:\>touch alpha\beta # cygwin at work here... >>>> C:\>python -c"import os; print os.path.exists('alpha/beta')" >>>> True >>>> C:\>cacls alpha /E /R "Everyone" >>>> processed dir: C:\alpha >>>> C:\>cacls alpha /E /R "Users" >>>> processed dir: C:\alpha >>>> C:\>cacls alpha /E /R "Administrators" >>>> processed dir: C:\alpha >>>> C:\>python -c"import os; print os.path.exists('alpha/beta')" >>>> False >>> Hi, >>> This is the following code which i have used to retrieve the pathname >>> of a filename given by the user >>> filename = self.enText.get() # get the text entered in the >>> text box >>> if os.path.exists(filename): # checking if the filename >>> exists , had replaced it with os.path.exists(os.path.abspath >>> (filename)) >>> print os.path.abspath(filename) >>> else: >>> print "Not found" >>> actually i need to list all the files/folders with the given filename >>> alongwith path and store it in an CSV file with index. >>> But i am unable to get even a single filepath correctly. >>> Whatever filename i enter the output is as : C:\Python25\WorkSpace >>> \xyz >>> i.e the name i entered is being appended to my workspace and >>> displayed. >>> Guys, i am not able to understand what shall i do here...plz help me >>> out. >> Look, we aren't psychic. We can't debug code and directories we can't >> see. Work with us here - give us the information we need to help you. >> >> The actual code. A directory listing? Any error messages? >> >> regards >> Steve >> -- >> Steve Holden +1 571 484 6266 +1 800 494 3119 >> Holden Web LLC http://www.holdenweb.com/ > > > > > > Hi Steve, > > Following is the code which i have written to display a GUI textbox > and get any name entered by the user and search the path of this > filename and then list it into an CSV file. > > For this i initially created an textbox widget and added an button to > it. > Now, i have entered a filename (like NEWS.txt) in the text boz, > as you can see when i press the button i retrieve the text and then > search its filepath. > currently i am printing this filepath on the shell. > > > from Tkinter import * So this is Python 2.x ... > import os > from os.path import realpath, exists, abspath > import tkMessageBox > import Tkinter Not sure why you bother to import Tkinter when you have above just imported everything *from* Tkinter ... > #import filePath > > class GUIFrameWork(Frame): > """This is the GUI""" > > def __init__(self,master=None): > """Initialize yourself""" > > """Initialise the base class""" > Frame.__init__(self,master) > > """Set the Window Title""" > self.master.title("Enter Text to search") > > """Display the main window" > with a little bit of padding""" > self.grid(padx=10,pady=10) > self.CreateWidgets() > > def CreateWidgets(self): > > self.enText = Entry(self) > self.enText.grid(row=0, column=1, columnspan=3) > > > > """Create the Button, set the text and the > command that will be called when the button is clicked""" > self.btnDisplay = Button(self, text="Display!", > command=self.Display) > self.btnDisplay.grid(row=0, column=4) > > def Display(self): > """Called when btnDisplay is clicked, displays the contents of > self.enText""" > filename = self.enText.get() > if os.path.exists(os.path.abspath(filename)): > print os.path.abspath(filename) First, move this line up one (losing an indent level) so you always print the full path. This will verify you are looking where you think you are looking. > else: > print "Not found" > #tkMessageBox.showinfo("Text", "You typed: %s" % > os.path.abspath(os.path.dirname(filename))) > > #filepath.mydir(self.enText.get()) > > > if __name__ == "__main__": > guiFrame = GUIFrameWork() > guiFrame.mainloop() > > > User Input: NEWS.txt > Output: Not Found (though this file is actually present) > Thanks for the information. I'm wondering whether there might be some filename encoding issue here, but others may have some better ideas. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Thu Feb 26 07:47:03 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 26 Feb 2009 07:47:03 -0500 Subject: File Path retrieving problem In-Reply-To: References: <86a29476-fde2-4983-af62-4eb8a68425a8@w34g2000yqm.googlegroups.com> Message-ID: Dennis Lee Bieber wrote: > On Wed, 25 Feb 2009 07:37:21 -0800 (PST), music24by7 at gmail.com declaimed > the following in comp.lang.python: > > WARNING -- I will probably NOT see your response; since 90+% of the > spam in comp.lang.python is injected via googlegroups and gmail > accounts, my client is configured to filter out messages with a from > address having gmail.com. I only found this message by doing fetches on > the reference header of the replies that did get by the filter. > Well, since it's more likely you'll see this, let me tell you that if you access the group via gmane (as I do) you rarely see the spam anyway. There's been a lot more work on spam filtering lately. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From bruno.42.desthuilliers at websiteburo.invalid Thu Feb 26 07:48:15 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 26 Feb 2009 13:48:15 +0100 Subject: Delete all items in the list In-Reply-To: References: Message-ID: <49a68f7b$0$2669$426a74cc@news.free.fr> Clarendon a ?crit : > Hi. This must be a simple command but I just can't find it in the > Phthon manual. How do I delete all items with a certain condition from > a list? For instance: > > L=['a', 'b', 'c', 'a'] > > I want to delete all 'a's from the list. > But if L.remove('a') only deletes the first 'a'. > > How do you delete all 'a's? L[:] = [item for item in L if item != 'a'] From steve at holdenweb.com Thu Feb 26 07:51:50 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 26 Feb 2009 07:51:50 -0500 Subject: Queries In-Reply-To: References: <49A63A90.4080003@islandtraining.com> Message-ID: Murray wrote: [top-posting corrected] > -----Original Message----- > From: Gary Herron [mailto:gherron at islandtraining.com] > Sent: Thursday, February 26, 2009 1:46 AM > To: mmcclaf; python-list at python.org > Subject: Re: Queries > > mmcclaf wrote: >> I have to make some queries for 4 tables I have. The following >> relations are: >> >> Classes(class, type, country, numGuns, bore, displacement) >> Ships (name, class, launched) >> Battles (name, date) >> Outcomes (ship, battle, result) >> >> The three queries I'm stuck on are the following: >> >> 1. Find the classes that have only one ship as a member of that class >> (not all ships are listed in the Ship table) Investigate a GROUP BY solution that selects groups having a count of 1. >> 2. Find the countries that had both battleships and battlecruisers >> (those fall under type in Classes) Look at EXISTS for one possible solutions. >> 3. Find those ships that "lived to fight another day"; they were >> damaged in one battle, but later fought in another. >> >From your model description I don't even see where the position and attitude of each ship is stored, so I don't think I can give you any help at all with this one. >> The best way for me to understand would be relational algebra for each >> of the statements. >> > > > Sounds like a homework assignment. Good luck with it. > > It is, however I was able to get the first 8 done, I am struggling with > these 3 particular ones. I have to make an SQL file based off of it, so this > seems to be a blockage in my works. > Good luck with the homework. Remember to acknowledge the help you've had from this list (particularly your earlier issues: here you just have hints). regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From venutaurus539 at gmail.com Thu Feb 26 07:55:28 2009 From: venutaurus539 at gmail.com (venutaurus539 at gmail.com) Date: Thu, 26 Feb 2009 04:55:28 -0800 (PST) Subject: Run a python script as an exe and run a new process from it Message-ID: Hello all, I've a strange requirement where I need to run a python script just as we run an exe (by double clicking through windows explorer or by typing the script name at command prompt). In that process I should be able to execute another python script in such a way that, the second script should continue running but the main one should terminate without effecting the second one. My requirement may be little confusing so please get back if you didn't understand what I meant above. Thank you, Venu. From steve at holdenweb.com Thu Feb 26 07:56:19 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 26 Feb 2009 07:56:19 -0500 Subject: i have problem with glob.glob() in remotely directory In-Reply-To: <50697b2c0902260116t7ee6f65ei878cdea6086fad6a@mail.gmail.com> References: <967cd34f0902260105q7d8b33adk579956b275b2d68b@mail.gmail.com> <50697b2c0902260116t7ee6f65ei878cdea6086fad6a@mail.gmail.com> Message-ID: Chris Rebert wrote: > On Thu, Feb 26, 2009 at 1:05 AM, lameck kassana wrote: >> hey i want to count number of files in remote computer >> >> example of my code is >> >> import glob >> import os >> import time >> from datetime import date >> today=date.today() >> dir_count, file_count=0, 0 >> >> for files in glob.glob('\\192.168.0.45\files\*.txt'): > > Remember that *backslash is the escape character* in Python, so you > need to double-up your backslashes in the string literal (or just use > forward slashes instead, Windows doesn't seem to care for Python in > most cases). Right now, the path really only starts with 1 backslash > and it has a formfeed character in it (\f), so it's obviously invalid; > thus, your problem. > > So you want: > #looks ugly, doesn't it? > for files in glob.glob('\\\\192.168.0.45\\files\\*.txt'): > > Or: > #will probably but not assuredly work > for files in glob.glob('//192.168.0.45/files/*.txt'): > Or: for files in glob.glob(r'\\192.168.0.45\files\*.txt'): Raw string literals are very useful for handling strings with lots of backslashes in them. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From bborcic at gmail.com Thu Feb 26 08:00:30 2009 From: bborcic at gmail.com (Boris Borcic) Date: Thu, 26 Feb 2009 14:00:30 +0100 Subject: Delete all items in the list In-Reply-To: <50697b2c0902260315i754f9d39y3231f30435824bb5@mail.gmail.com> References: <50697b2c0902260315i754f9d39y3231f30435824bb5@mail.gmail.com> Message-ID: Chris Rebert wrote: > On Thu, Feb 26, 2009 at 3:05 AM, Clarendon wrote: ... >> L=['a', 'b', 'c', 'a'] >> >> I want to delete all 'a's from the list. >> But if L.remove('a') only deletes the first 'a'. >> >> How do you delete all 'a's? > > There are several ways. I'd go with a list comprehension: and for a couple other ways while 'a' in L : L.remove('a') L = filter('a'.__ne__,L) From freelancer317 at gmail.com Thu Feb 26 08:03:50 2009 From: freelancer317 at gmail.com (Bret Fledderjohn) Date: Thu, 26 Feb 2009 08:03:50 -0500 Subject: Queries In-Reply-To: References: <49A63A90.4080003@islandtraining.com> Message-ID: 2009/2/26 Steve Holden > Murray wrote: > [top-posting corrected] > > > -----Original Message----- > > From: Gary Herron [mailto:gherron at islandtraining.com] > > Sent: Thursday, February 26, 2009 1:46 AM > > To: mmcclaf; python-list at python.org > > Subject: Re: Queries > > > > mmcclaf wrote: > >> I have to make some queries for 4 tables I have. The following > >> relations are: > >> > >> Classes(class, type, country, numGuns, bore, displacement) > >> Ships (name, class, launched) > >> Battles (name, date) > >> Outcomes (ship, battle, result) > >> > >> The three queries I'm stuck on are the following: > >> > >> 1. Find the classes that have only one ship as a member of that class > >> (not all ships are listed in the Ship table) > > Investigate a GROUP BY solution that selects groups having a count of 1. DISTINCT may be a simpler solution. > > > >> 2. Find the countries that had both battleships and battlecruisers > >> (those fall under type in Classes) > > Look at EXISTS for one possible solutions. > > >> 3. Find those ships that "lived to fight another day"; they were > >> damaged in one battle, but later fought in another. > >> > >From your model description I don't even see where the position and > attitude of each ship is stored, so I don't think I can give you any > help at all with this one. > > >> The best way for me to understand would be relational algebra for each > >> of the statements. > >> > > > > > > Sounds like a homework assignment. Good luck with it. > > > > It is, however I was able to get the first 8 done, I am struggling with > > these 3 particular ones. I have to make an SQL file based off of it, > so this > > seems to be a blockage in my works. > > > Good luck with the homework. Remember to acknowledge the help you've had > from this list (particularly your earlier issues: here you just have > hints). > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > Holden Web LLC http://www.holdenweb.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -- - Bret -------------- next part -------------- An HTML attachment was scrubbed... URL: From tim.wintle at teamrubber.com Thu Feb 26 08:10:15 2009 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Thu, 26 Feb 2009 13:10:15 +0000 Subject: Run a python script as an exe and run a new process from it In-Reply-To: References: Message-ID: <1235653815.7954.22.camel@tim-laptop> On Thu, 2009-02-26 at 04:55 -0800, venutaurus539 at gmail.com wrote: > Hello all, > I've a strange requirement where I need to run a python > script just as we run an exe (by double clicking through windows > explorer or by typing the script name at command prompt). I don't know how windows deals with this part > In that > process I should be able to execute another python script in such a > way that, the second script should continue running but the main one > should terminate without effecting the second one. standard daemon behavior I'd have thought This shows how you would do it (with lots of comments). Assume this should work on Windows. http://code.activestate.com/recipes/278731/ note the two child threads to prevent zombies - may not be needed on windows but good to use them anyway. From digitig at gmail.com Thu Feb 26 08:25:29 2009 From: digitig at gmail.com (Tim Rowe) Date: Thu, 26 Feb 2009 13:25:29 +0000 Subject: Efficient searching through objects In-Reply-To: References: <37632421-5475-4859-be83-07ae2eca1773@r4g2000yqa.googlegroups.com> Message-ID: 2009/2/26 sert : > bearophileHUGS at lycos.com wrote in > news:37632421-5475-4859-be83-07ae2eca1773 at r4g2000yqa.googlegro > ups.com: > >> Try using a dict instead, where keys are the names and >> objects the values (it turns a linear search in a quick >> hash look up). . Then tell us the performance changes. >> > > It halved the overall execution time. Thanks. Good to see that you've already got an improvement. For what it's worth, this seems to be classic relational database stuff, and a relational database will be optimised to do these operations and so is likely to be faster still. I think there are a couple that Python works well with, but I've never looked into that -- others will no doubt be along with recommendations now I've raised the subject. -- Tim Rowe From python.list at tim.thechases.com Thu Feb 26 08:34:11 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 26 Feb 2009 07:34:11 -0600 Subject: Efficient searching through objects In-Reply-To: References: <37632421-5475-4859-be83-07ae2eca1773@r4g2000yqa.googlegroups.com> Message-ID: <49A69A53.7040800@tim.thechases.com> > relational database will be optimised to do these operations and so is > likely to be faster still. I think there are a couple that Python > works well with, but I've never looked into that -- others will no > doubt be along with recommendations now I've raised the subject. batteries-included support for sqlite[1] was added in 2.5 which would work pretty well for this application without the overhead (resource OR administrative) of something like MySQL or PostgreSQL. -tkc [1] http://docs.python.org/library/sqlite3.html From steve at holdenweb.com Thu Feb 26 08:46:57 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 26 Feb 2009 08:46:57 -0500 Subject: problem with glob in remote directory or os.walk in remote directory in windos In-Reply-To: References: Message-ID: lameck kassana wrote: > i am trying to write script which will count files for remote directory > which having certain pattern. > Please refrain from repeating questions. When you posted this a reply had already been made to your original posting. Remember, this isn't a paid help desk ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From venutaurus539 at gmail.com Thu Feb 26 09:00:03 2009 From: venutaurus539 at gmail.com (venutaurus539 at gmail.com) Date: Thu, 26 Feb 2009 06:00:03 -0800 (PST) Subject: Run a python script as an exe and run a new process from it References: Message-ID: On Feb 26, 6:10?pm, Tim Wintle wrote: > On Thu, 2009-02-26 at 04:55 -0800, venutaurus... at gmail.com wrote: > > Hello all, > > ? ? ? ? ? ?I've a strange requirement where I need to run a python > > script just as we run an exe (by double clicking through windows > > explorer or by typing the script name at command prompt). > > I don't know how windows deals with this part> ?In that > > process I should be able to execute another python script in such a > > way that, the second script should continue running but the main one > > should terminate without effecting the second one. > > standard daemon behavior I'd have thought > > This shows how you would do it (with lots of comments). Assume this > should work on Windows. > > http://code.activestate.com/recipes/278731/ > > note the two child threads to prevent zombies - may not be needed on > windows but good to use them anyway. Thanks for the reply, Being a newbie to python, I am finding it difficult to understand the logic even after thorough reading of comments. Is there any simpler way where I can just run a python script from the main script and exit without disturbing the second one(This will end based on some other constraints which can be handled). Or can some one throw some light on where should I run the function os.system(" python script2.py") from the main one. Thank you, venu From lkassana at gmail.com Thu Feb 26 09:03:26 2009 From: lkassana at gmail.com (lameck kassana) Date: Thu, 26 Feb 2009 17:03:26 +0300 Subject: problem with glob in remote directory or os.walk in remote directory in windos In-Reply-To: References: Message-ID: ok my original question is how can count the files of ceratin pattern(eg *.txt) in remote directory .It seems use of glob.glob() for remote directory is not working .Example I want to count the files in following shared folder \\192.168.0.45\files how can do it by using glob.glob() On Thu, Feb 26, 2009 at 4:46 PM, Steve Holden wrote: > lameck kassana wrote: > > i am trying to write script which will count files for remote directory > > which having certain pattern. > > > Please refrain from repeating questions. When you posted this a reply > had already been made to your original posting. Remember, this isn't a > paid help desk ... > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > Holden Web LLC http://www.holdenweb.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dan.barbus at gmail.com Thu Feb 26 09:04:39 2009 From: dan.barbus at gmail.com (utnapistim) Date: Thu, 26 Feb 2009 06:04:39 -0800 (PST) Subject: class property not working in python 2.5.1 References: <2704d479-2f52-4ada-a60e-b4b49b089a7f@z9g2000yqi.googlegroups.com> Message-ID: <54ab1846-6dfe-4109-98d8-cd3b5371b13c@s28g2000vbp.googlegroups.com> On Feb 26, 9:56?am, Christian Heimes wrote: > Dan Barbus schrieb: > > > Hi, > > > I have a problem with setting a property to a class instance, in > > python 2.5.1. The property is defined through get and set methods, but > > when I set it, the setter doesn't get called. Instead, I believe the > > property in the instance gets replaced with a new object (string). > > > I have the following code (stripped down from my program): > > > class Model(): > > ? ? def __init__(self, title = ''): > > ? ? ? ? self._views, self._title = [], None > > ? ? ? ? self.setTitle(title) > > *snip* > > Properties don't work correctly on old style classes. You have to > subclass from object in order to get a new style class. > > class Model(object): > ? ? pass > > Christian Thanks, that solved the problem. From mmcclaf at gmail.com Thu Feb 26 09:06:48 2009 From: mmcclaf at gmail.com (mmcclaf) Date: Thu, 26 Feb 2009 06:06:48 -0800 (PST) Subject: Queries References: <49A63A90.4080003@islandtraining.com> Message-ID: <8f97b201-33b9-4c7f-a757-b76bd9db1167@f17g2000vbf.googlegroups.com> On Feb 26, 7:51?am, Steve Holden wrote: > Murray wrote: > > [top-posting corrected] > > > > > -----Original Message----- > > From: Gary Herron [mailto:gher... at islandtraining.com] > > Sent: Thursday, February 26, 2009 1:46 AM > > To: mmcclaf; python-l... at python.org > > Subject: Re: Queries > > > mmcclaf wrote: > >> I have to make ?some queries for 4 tables I have. The following > >> relations are: > > >> Classes(class, type, country, numGuns, bore, displacement) > >> Ships (name, class, launched) > >> Battles (name, date) > >> Outcomes (ship, battle, result) > > >> The three queries I'm stuck on are the following: > > >> 1. Find the classes that have only one ship as a member of that class > >> (not all ships are listed in the Ship table) > > Investigate a GROUP BY solution that selects groups having a count of 1. > > >> 2. Find the countries that had both battleships and battlecruisers > >> (those fall under type in Classes) > > Look at EXISTS for one possible solutions. > > >> 3. Find those ships that "lived to fight another day"; they were > >> damaged in one battle, but later fought in another. > > >From your model description I don't even see where the position and > > attitude of each ship is stored, so I don't think I can give you any > help at all with this one. > > >> The best way for me to understand would be relational algebra for each > >> of the statements. > > > Sounds like a homework assignment. ? ?Good luck with it. > > > It is, however I was able to get the first 8 done, I am struggling with > > these 3 particular ones. I have to make an SQL file based off of it, > so this > > seems to be a blockage in my works. > > Good luck with the homework. Remember to acknowledge the help you've had > from this list (particularly your earlier issues: here you just have hints). > > regards > ?Steve > -- > Steve Holden ? ? ? ?+1 571 484 6266?+1 800 494 3119 > Holden Web LLC ? ? ? ? ? ? ?http://www.holdenweb.com/ Yeppers always do. And thanks! As for the number 3 one... to know if they were damaged would appear in "Result" of the Outcomes table From venutaurus539 at gmail.com Thu Feb 26 09:09:22 2009 From: venutaurus539 at gmail.com (venutaurus539 at gmail.com) Date: Thu, 26 Feb 2009 06:09:22 -0800 (PST) Subject: Run a python script as an exe and run a new process from it References: Message-ID: <328c4626-9158-4957-ba4c-162ca626feed@h20g2000yqn.googlegroups.com> On Feb 26, 7:00?pm, "venutaurus... at gmail.com" wrote: > On Feb 26, 6:10?pm, Tim Wintle wrote: > > > > > On Thu, 2009-02-26 at 04:55 -0800, venutaurus... at gmail.com wrote: > > > Hello all, > > > ? ? ? ? ? ?I've a strange requirement where I need to run a python > > > script just as we run an exe (by double clicking through windows > > > explorer or by typing the script name at command prompt). > > > I don't know how windows deals with this part> ?In that > > > process I should be able to execute another python script in such a > > > way that, the second script should continue running but the main one > > > should terminate without effecting the second one. > > > standard daemon behavior I'd have thought > > > This shows how you would do it (with lots of comments). Assume this > > should work on Windows. > > >http://code.activestate.com/recipes/278731/ > > > note the two child threads to prevent zombies - may not be needed on > > windows but good to use them anyway. > > Thanks for the reply, > ? ? ? ? ? ?Being a newbie to python, I am finding it difficult to > understand the logic even after thorough reading of comments. Is there > any simpler way where I can just run a python script from the main > script and exit without disturbing the second one(This will end based > on some other constraints which can be handled). Or can some one throw > some light on where should I run the function os.system(" python > script2.py") from the main one. > > Thank you, > venu Adding to the above.. I've to do it in Windows platform and what I can see from the illustration (/dev/null) etc. they are for Unix Environment. Thank you, Venu From steve at holdenweb.com Thu Feb 26 09:15:23 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 26 Feb 2009 09:15:23 -0500 Subject: problem with glob in remote directory or os.walk in remote directory in windos In-Reply-To: References: Message-ID: <49A6A3FB.60708@holdenweb.com> lameck kassana wrote: > ok my original question is how can count the files of ceratin pattern(eg > *.txt) in remote directory .It seems use of glob.glob() for remote > directory is not working .Example I want to count the files in following > shared folder \\192.168.0.45\files how can > do it by using glob.glob() > >>> glob.glob(r"\\houseboy\sholden\*.txt") ['\\\\houseboy\\sholden\\pgin1.txt', '\\\\houseboy\\sholden\\POSTGRES.TXT', '\\\\houseboy\\sholden\\gatesquote.txt', '\\\\houseboy\\sholden\\UbuntuWhatNow.txt', '\\\\houseboy\\sholden\\patch001.txt'] >>> glob.glob(r"\\192.168.2.200\sholden\*.txt") ['\\\\192.168.2.200\\sholden\\pgin1.txt', '\\\\192.168.2.200\\sholden\\POSTGRES.TXT', '\\\\192.168.2.200\\sholden\\gatesquote.txt', '\\\\192.168.2.200\\sholden\\UbuntuWhatNow.txt', '\\\\192.168.2.200\\sholden\\patch001.txt'] >>> Working just fine for me. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From freelancer317 at gmail.com Thu Feb 26 09:20:47 2009 From: freelancer317 at gmail.com (Bret Fledderjohn) Date: Thu, 26 Feb 2009 09:20:47 -0500 Subject: Run a python script as an exe and run a new process from it In-Reply-To: <328c4626-9158-4957-ba4c-162ca626feed@h20g2000yqn.googlegroups.com> References: <328c4626-9158-4957-ba4c-162ca626feed@h20g2000yqn.googlegroups.com> Message-ID: 2009/2/26 venutaurus539 at gmail.com > On Feb 26, 7:00 pm, "venutaurus... at gmail.com" > wrote: > > On Feb 26, 6:10 pm, Tim Wintle wrote: > > > > > > > > > On Thu, 2009-02-26 at 04:55 -0800, venutaurus... at gmail.com wrote: > > > > Hello all, > > > > I've a strange requirement where I need to run a python > > > > script just as we run an exe (by double clicking through windows > > > > explorer or by typing the script name at command prompt). > > > > > I don't know how windows deals with this part> In that > > > > process I should be able to execute another python script in such a > > > > way that, the second script should continue running but the main one > > > > should terminate without effecting the second one. > > > > > standard daemon behavior I'd have thought > > > > > This shows how you would do it (with lots of comments). Assume this > > > should work on Windows. > > > > >http://code.activestate.com/recipes/278731/ > > > > > note the two child threads to prevent zombies - may not be needed on > > > windows but good to use them anyway. > > > > Thanks for the reply, > > Being a newbie to python, I am finding it difficult to > > understand the logic even after thorough reading of comments. Is there > > any simpler way where I can just run a python script from the main > > script and exit without disturbing the second one(This will end based > > on some other constraints which can be handled). Or can some one throw > > some light on where should I run the function os.system(" python > > script2.py") from the main one. > > > > Thank you, > > venu > > Adding to the above.. I've to do it in Windows platform and what I can > see from the illustration (/dev/null) etc. they are for Unix > Environment. For making a script executable try this link http://www.python.org/doc/faq/windows/#how-do-i-make-python-scripts-executable -- - Bret -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Thu Feb 26 09:27:31 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 26 Feb 2009 12:27:31 -0200 Subject: thread safe to lock on key, val pairs on a dict instead of entire dict? References: Message-ID: En Thu, 26 Feb 2009 00:39:30 -0200, birdsong escribi?: > Dictionaries just store references to objects, right? So is it thread > safe to lock a specific key/val pair on a dictionary and modify its > val and release the lock? > > example snippet: > # assuming d_lock was initialized long ago in a thread-safe manner > d_lock.acquire() > d = {} > d[1] = (threading.Lock(), []) > d_lock.release() > > # test key level locking > for key, data in d.items(): > row_lock, rows = data > row_lock.acquire() > rows.append(1) > row_lock.release() > > Of course, I'll have to lock the entire dict when adding keys that > dont exist, but further calls and acquire the key specific lock before > doing any write operations. (All of this applies to CPython only) Subscript assignment is a single opcode. If the key's __hash__ and __eq__/__cmp__ don't call any Python code, nor does the destructor of the previous dict entry, then the operation is atomic (no other thread may be executed due to the GIL). list.append is atomic. Note that the *append* operation is atomic (or the dict assignment), not the whole statement: L.append(some[values]+to**be.computed(L)) Evaluating the argument to append isn't atomic at all. References: http://effbot.org/pyfaq/what-kinds-of-global-value-mutation-are-thread-safe.htm http://effbot.org/zone/thread-synchronization.htm http://coreygoldberg.blogspot.com/2008/09/python-thread-synchronization-and.html -- Gabriel Genellina From jdnier at gmail.com Thu Feb 26 09:38:34 2009 From: jdnier at gmail.com (David Niergarth) Date: Thu, 26 Feb 2009 06:38:34 -0800 (PST) Subject: memory recycling/garbage collecting problem References: Message-ID: <4d007dac-3782-4b53-9dec-2bcd6accf750@z9g2000yqi.googlegroups.com> On Feb 16, 11:21?pm, Yuanxin Xi wrote: > Could anyone please explain why this happens? ?It seems some memory > are not freed. There is a "bug" in versions of Python prior to 2.5 where memory really isn't released back to the OS. Python 2.5 contains a new object allocator that is able to return memory to the operating system that fixes this issue. Here's an explanation: http://evanjones.ca/python-memory-part3.html What version of Python are you using? I have a machine running several long-running processes, each of which occasionally spike up to 500M memory usage, although normally they only require about 25M. Prior to 2.5, those processes never released that memory back to the OS and I would need to periodically restart them. With 2.5, this is no longer a problem. I don't always see memory usage drop back down immediately but the OS does recover the memory eventually. Make sure you use 2.5 if this is an issue for you. --David From tim.wintle at teamrubber.com Thu Feb 26 09:47:47 2009 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Thu, 26 Feb 2009 14:47:47 +0000 Subject: Run a python script as an exe and run a new process from it In-Reply-To: References: Message-ID: <1235659667.7954.56.camel@tim-laptop> On Thu, 2009-02-26 at 06:00 -0800, venutaurus539 at gmail.com wrote: > Thanks for the reply, > Being a newbie to python, I am finding it difficult to > understand the logic even after thorough reading of comments. Is there > any simpler way where I can just run a python script from the main > script and exit without disturbing the second one(This will end based > on some other constraints which can be handled). Or can some one throw > some light on where should I run the function os.system(" python > script2.py") from the main one. That would be a simple way of doing it :-) From jdnier at gmail.com Thu Feb 26 10:00:34 2009 From: jdnier at gmail.com (David Niergarth) Date: Thu, 26 Feb 2009 07:00:34 -0800 (PST) Subject: memory recycling/garbage collecting problem References: <4d007dac-3782-4b53-9dec-2bcd6accf750@z9g2000yqi.googlegroups.com> Message-ID: Tim Peters showed a way to demonstrate the fix in http://mail.python.org/pipermail/python-dev/2006-March/061991.html > For simpler fun, run this silly little program, and look at memory > consumption at the prompts: > > """ > x = [] > for i in xrange(1000000): > x.append([]) > raw_input("full ") > del x[:] > raw_input("empty ") > """ > > For example, in a release build on WinXP, VM size is about 48MB at the > "full" prompt, and drops to 3MB at the "empty" prompt. In the trunk > (without this patch), VM size falls relatively little from what it is > at the "full" prompt (the contiguous vector holding a million > PyObject* pointers is freed, but the obmalloc arenas holding a > million+1 list objects are never freed). > > For more info about the patch, see Evan's slides from _last_ year's PyCon: > > http://evanjones.ca/memory-allocator.pdf I'm not sure what deleting a slice accomplishes (del x[:]); the behavior is the same whether I do del x or del x[:]. Any ideas? --David From hv at tbz-pariv.de Thu Feb 26 10:10:02 2009 From: hv at tbz-pariv.de (Thomas Guettler) Date: Thu, 26 Feb 2009 16:10:02 +0100 Subject: OT: handling multiple software repositories Message-ID: <70npmbFgb464U1@mid.individual.net> Hi, this is a bit off topic. In our company we have several SVN repositories. According to [1] Trac by default only handles one repository. Of course Trac links like changeset [1234] would not work anymore. You would need [repro/1234] or something like this. I think many (python) programmer have several repositories and need to handle this somehow. How do you do this? I want a common wiki and a common bug tracker. It should be possible to attach a bug to several repositories. Up to now I don't use Trac, if someone has an alternative, please tell me! Thomas [1] http://trac.edgewall.org/wiki/MultipleRepositorySupport -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From ptmcg at austin.rr.com Thu Feb 26 10:11:08 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Thu, 26 Feb 2009 09:11:08 -0600 Subject: XML Parsing In-Reply-To: <206436.56338.qm@web27404.mail.ukl.yahoo.com> References: <206436.56338.qm@web27404.mail.ukl.yahoo.com> Message-ID: You flatter me sir (or madam? can't tell from your name...), but I wouldn't presume to so lofty a title among this crowd. I'd save that for the likes of Alan Gauld and Kent Johnson, who are much more prolific and informative contributors to this list than I. -- Paul -----Original Message----- From: hrishy [mailto:hrishys at yahoo.co.uk] Sent: Wednesday, February 25, 2009 11:36 PM To: python-list at python.org; Paul McGuire Subject: Re: XML Parsing Ha the guru himself responding :-) --- On Wed, 25/2/09, Paul McGuire wrote: > From: Paul McGuire > Subject: Re: XML Parsing > To: python-list at python.org > Date: Wednesday, 25 February, 2009, 2:04 PM On Feb 25, 1:17?am, hrishy > > wrote: > > Hi > > > > Something like this > > > > > > > Note i am not a python programmer just a enthusiast > and i was curious why people on the list didnt suggest a code like > above > > > > You just beat the rest of us to it - good example of ElementTree for > parsing XML (and I Iearned the '//' shortcut for one or more > intervening tag levels). > > To the OP: if you are parsing XML, I would look hard at the modules > (esp. ElementTree) that are written explicitly for XML, before > considering using regular expressions. There are just too many > potential surprises when trying to match XML tags - presence/absence/ > order of attributes, namespaces, whitespace inside tags, to name a > few. > > -- Paul > -- > http://mail.python.org/mailman/listinfo/python-list From gagsl-py2 at yahoo.com.ar Thu Feb 26 10:26:56 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 26 Feb 2009 13:26:56 -0200 Subject: Delete all items in the list References: <50697b2c0902260315i754f9d39y3231f30435824bb5@mail.gmail.com> Message-ID: En Thu, 26 Feb 2009 11:00:30 -0200, Boris Borcic escribi?: > Chris Rebert wrote: >> On Thu, Feb 26, 2009 at 3:05 AM, Clarendon wrote: > ... >>> L=['a', 'b', 'c', 'a'] >>> >>> I want to delete all 'a's from the list. >>> But if L.remove('a') only deletes the first 'a'. >>> >>> How do you delete all 'a's? >> There are several ways. I'd go with a list comprehension: > > and for a couple other ways > > while 'a' in L : L.remove('a') This is probably the worst way, takes cuadratic time (and two searches per loop). > L = filter('a'.__ne__,L) And this is probably the fastest. But not all types define __ne__ so a more generic answer would be: from functools import partial from operator import ne L = filter(partial(ne, 'a'), L) Of course, this is only relevant if L is large and there are many duplicates. In other cases I'd stick with the list comprehension as posted by Chris Rebert. -- Gabriel Genellina From mal at egenix.com Thu Feb 26 10:27:44 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Thu, 26 Feb 2009 16:27:44 +0100 Subject: PyCrypto AES MODE_CBC - How to? In-Reply-To: <70krl9Fbuqj5U1@mid.dfncis.de> References: <70krdfFc7rn0U1@mid.dfncis.de> <70krl9Fbuqj5U1@mid.dfncis.de> Message-ID: <49A6B4F0.6040600@egenix.com> On 2009-02-25 13:25, Helmut Jarausch wrote: > Helmut Jarausch wrote: >> Hi, >> >> I've just tried to write a simple example using PyCrypto's >> AES (CBC mode) >> >> #!/usr/bin/python >> from Crypto.Cipher import AES >> >> PWD='abcdefghijklmnop' >> Initial16bytes='0123456789ABCDEF' >> >> crypt = AES.new(PWD, AES.MODE_CBC,Initial16bytes) >> # crypt = AES.new(PWD, AES.MODE_ECB) >> >> txt = 'ea523a664dabaa4476d31226a1e3bab0' >> >> c = crypt.encrypt(txt) >> >> txt_plain=crypt.decrypt(c) >> >> print txt_plain >> >> Unfortunately, txt_plain differs from txt - why? >> (Using MODE_ECB does work however) >> > > I just discovered that the following variant seems to work > crypt = AES.new(PWD, AES.MODE_CBC,Initial16bytes) > c = crypt.encrypt(txt) > crypt = AES.new(PWD, AES.MODE_CBC,Initial16bytes) # <<< re-initialize > txt_plain=crypt.decrypt(c) > > So, the crypt object seems to keep some state. > I haven't seen this mentioned in the documentation. In CBC mode, all previous encryptions affect the next one, since the blocks are chained: http://en.wikipedia.org/wiki/Cipher_block_chaining#Cipher-block_chaining_.28CBC.29 In ECB mode, they are not, but then it doesn't provide much security unless you change the key frequently: http://en.wikipedia.org/wiki/Cipher_block_chaining#Electronic_codebook_.28ECB.29 (the wiki pages provide some nice graphics to see what's going on and why CBC is better than ECB) -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Feb 26 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From venutaurus539 at gmail.com Thu Feb 26 10:32:27 2009 From: venutaurus539 at gmail.com (venutaurus539 at gmail.com) Date: Thu, 26 Feb 2009 07:32:27 -0800 (PST) Subject: Run a python script as an exe and run a new process from it References: Message-ID: <74abbd25-624a-4f79-8ffe-249b625d0c74@w34g2000yqm.googlegroups.com> On Feb 26, 7:47?pm, Tim Wintle wrote: > On Thu, 2009-02-26 at 06:00 -0800, venutaurus... at gmail.com wrote: > > Thanks for the reply, > > ? ? ? ? ? ?Being a newbie to python, I am finding it difficult to > > understand the logic even after thorough reading of comments. Is there > > any simpler way where I can just run a python script from the main > > script and exit without disturbing the second one(This will end based > > on some other constraints which can be handled). Or can some one throw > > some light on where should I run the function os.system(" python > > script2.py") from the main one. > > That would be a simple way of doing it :-) When I run that script on Windows it fails throwing the below error: AttributeError: 'module' object has no attribute 'fork' Please help me out.. From Shawn at Milochik.com Thu Feb 26 10:35:44 2009 From: Shawn at Milochik.com (Shawn Milochik) Date: Thu, 26 Feb 2009 10:35:44 -0500 Subject: The Python's regex different from Perl's , I want know what's the different? In-Reply-To: <49A67B73.4090408@tim.thechases.com> References: <6934d4d5-257f-451d-b318-0fabe42c84e8@q11g2000yqh.googlegroups.com> <49A67B73.4090408@tim.thechases.com> Message-ID: <2dc0c81b0902260735u491d5cbbr9b72e021cd0ae334@mail.gmail.com> The regular expression syntax is basically exactly the same. The main difference is that a regex can't just be written into a statement as part of the syntax; you have to create a regular expression object and use its methods. So, instead of: new_thing =~ s/pattern/replacement/ it's: myPattern = re.compile(r'pattern') new_thing = myPattern.sub(replacement, input_string) or: new_thing = re.sub(pattern, replacement, input_string) Also, backreferences are \1 instead of $1, and you have to escape the backslash or use a raw string for the backslash. I've found this page to be pretty helpful: http://www.regular-expressions.info/python.html Shawn From jjposner at snet.net Thu Feb 26 10:44:03 2009 From: jjposner at snet.net (John Posner) Date: Thu, 26 Feb 2009 10:44:03 -0500 Subject: Delete all items in the list In-Reply-To: References: <50697b2c0902260315i754f9d39y3231f30435824bb5@mail.gmail.com> Message-ID: >> >> > L = filter('a'.__ne__,L) >> >> And this is probably the fastest. But not all types define >> __ne__ so a >> more generic answer would be: >> >> from functools import partial >> from operator import ne >> L = filter(partial(ne, 'a'), L) >> And don't forget this "traditional" solution: >>> L=['a', 'b', 'c', 'a'] >>> filter(lambda arg: arg != 'a', L) ['b', 'c'] -John E-mail message checked by Spyware Doctor (6.0.0.386) Database version: 5.11850 http://www.pctools.com/en/spyware-doctor-antivirus/ From jjposner at snet.net Thu Feb 26 10:52:19 2009 From: jjposner at snet.net (John Posner) Date: Thu, 26 Feb 2009 10:52:19 -0500 Subject: functools.partial (was: Delete all items in the list) In-Reply-To: References: <50697b2c0902260315i754f9d39y3231f30435824bb5@mail.gmail.com> Message-ID: >> >> from functools import partial >> from operator import ne >> L = filter(partial(ne, 'a'), L) >> I learned about functools.partial only recently (on this list). functools is implemented in C, not Python, so I couldn't answer this question for myself: Is functools.partial completely equivalent to a manually-coded closure? Help, please. -John E-mail message checked by Spyware Doctor (6.0.0.386) Database version: 5.11850 http://www.pctools.com/en/spyware-doctor-antivirus/ From mail at timgolden.me.uk Thu Feb 26 11:10:15 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 26 Feb 2009 16:10:15 +0000 Subject: OT: handling multiple software repositories In-Reply-To: <70npmbFgb464U1@mid.individual.net> References: <70npmbFgb464U1@mid.individual.net> Message-ID: <49A6BEE7.2090605@timgolden.me.uk> Thomas Guettler wrote: > Hi, > > this is a bit off topic. > > In our company we have several SVN repositories. > > According to [1] Trac by default only handles one > repository. > > Of course Trac links like changeset [1234] would not work anymore. > You would need [repro/1234] or something like this. > > I think many (python) programmer have several repositories > and need to handle this somehow. > > How do you do this? > > I want a common wiki and a common bug tracker. It should > be possible to attach a bug to several repositories. > > Up to now I don't use Trac, if someone has an alternative, please > tell me! Have a look at DrProject[1], a Trac-alike which handles multiple projects. (Not used it myself). TJG [1] https://www.drproject.org/ From mmcclaf at gmail.com Thu Feb 26 11:17:19 2009 From: mmcclaf at gmail.com (mmcclaf) Date: Thu, 26 Feb 2009 08:17:19 -0800 (PST) Subject: Queries References: <49A63A90.4080003@islandtraining.com> <8f97b201-33b9-4c7f-a757-b76bd9db1167@f17g2000vbf.googlegroups.com> Message-ID: <51a7b90d-50ee-45d4-800e-541f01e81e66@m4g2000vbp.googlegroups.com> Another problem with this assignment... I have to list all the ships mentioned in the database. All the ships may not appear in the Ships relations... I said the following in algebraic expression SELECT name(Ships UNION (SELECT ship (Outcome UNION(SELECT class (Classes))) Would that work? From google at mrabarnett.plus.com Thu Feb 26 11:18:19 2009 From: google at mrabarnett.plus.com (MRAB) Date: Thu, 26 Feb 2009 16:18:19 +0000 Subject: EOL for sys.stdin.readline() and raw_input() In-Reply-To: <49A67300.6050303@unixcluster.dk> References: <49A67300.6050303@unixcluster.dk> Message-ID: <49A6C0CB.3000704@mrabarnett.plus.com> jkv wrote: > Hi, > > Are there any way to change the EOL character for sys.stdin.readline() > and raw_input()? > My problem is that i cannot rely on that the clients connection to my > application will end all lines with \n or \r\n. Sometimes they will use > \r\000 as EOL. > > Example from my code: > > sys.stdout.write('Password: '); > #IAC DO ECHO sys.stdout.write('\xFF\xFB\x01') > password = raw_input() > > If the client sends 'qwerty\r\n' everything is fine and the password get > stored in the variable. But sometimes, depending on how broken the > telnet client are, the client will send 'qwerty\r\000' instead and then > my application will hang at 'password = raw_input()' forever. > > Any suggestions? > Could you insert some kind of filter into the input stream? The filter would replace '\r\000' with '\r\n' (or just '\000' with '\n'). old_stdin = sys.stdin try: sys.stdin = MyFilter(sys.stdin) ... finally: sys.stdin = old_stdin I don't know how many methods you would need to provide. From kyrie at uh.cu Thu Feb 26 11:22:38 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Thu, 26 Feb 2009 11:22:38 -0500 Subject: OT: handling multiple software repositories In-Reply-To: <49A6BEE7.2090605@timgolden.me.uk> References: <70npmbFgb464U1@mid.individual.net> <49A6BEE7.2090605@timgolden.me.uk> Message-ID: <200902261122.38127.kyrie@uh.cu> On Thursday 26 February 2009 11:10:15 am Tim Golden wrote: > Have a look at DrProject[1], a Trac-alike which handles > multiple projects. (Not used it myself). > > [1] https://www.drproject.org/ I've used DrProject a bit (my gf is one of the developers). If you like trac, chances are that you will love DrProject. It's quite good (and easy to install, unlike gforge), but the developers are moving on to a version 2.0 that you can find around here: http://basieproject.org/ (yeah, the website is ugly). If you like trac, take a look at DrProject and keep an eye on Basie. -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From steve at holdenweb.com Thu Feb 26 11:30:41 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 26 Feb 2009 11:30:41 -0500 Subject: memory recycling/garbage collecting problem In-Reply-To: References: <4d007dac-3782-4b53-9dec-2bcd6accf750@z9g2000yqi.googlegroups.com> Message-ID: David Niergarth wrote: > Tim Peters showed a way to demonstrate the fix in > > http://mail.python.org/pipermail/python-dev/2006-March/061991.html > >> For simpler fun, run this silly little program, and look at memory >> consumption at the prompts: >> >> """ >> x = [] >> for i in xrange(1000000): >> x.append([]) >> raw_input("full ") >> del x[:] >> raw_input("empty ") >> """ >> >> For example, in a release build on WinXP, VM size is about 48MB at the >> "full" prompt, and drops to 3MB at the "empty" prompt. In the trunk >> (without this patch), VM size falls relatively little from what it is >> at the "full" prompt (the contiguous vector holding a million >> PyObject* pointers is freed, but the obmalloc arenas holding a >> million+1 list objects are never freed). >> >> For more info about the patch, see Evan's slides from _last_ year's PyCon: >> >> http://evanjones.ca/memory-allocator.pdf > > I'm not sure what deleting a slice accomplishes (del x[:]); the > behavior is the same whether I do del x or del x[:]. Any ideas? > del x removes the name x from the current namespace, garbage collecting the object to which it referred. del x[:] leaves x referencing a cleared list. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From gagsl-py2 at yahoo.com.ar Thu Feb 26 11:41:07 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 26 Feb 2009 14:41:07 -0200 Subject: Run a python script as an exe and run a new process from it References: <74abbd25-624a-4f79-8ffe-249b625d0c74@w34g2000yqm.googlegroups.com> Message-ID: En Thu, 26 Feb 2009 13:32:27 -0200, venutaurus539 at gmail.com escribi?: > On Feb 26, 7:47?pm, Tim Wintle wrote: >> On Thu, 2009-02-26 at 06:00 -0800, venutaurus... at gmail.com wrote: >> > Thanks for the reply, >> > ? ? ? ? ? ?Being a newbie to python, I am finding it difficult to >> > understand the logic even after thorough reading of comments. Is there >> > any simpler way where I can just run a python script from the main >> > script and exit without disturbing the second one(This will end based >> > on some other constraints which can be handled). Or can some one throw >> > some light on where should I run the function os.system(" python >> > script2.py") from the main one. >> >> That would be a simple way of doing it :-) > > When I run that script on Windows it fails throwing the below error: > > AttributeError: 'module' object has no attribute 'fork' > > Please help me out.. Unless you have any special needs, just stick to os.system("...") -- Gabriel Genellina From dchandran1 at yahoo.com Thu Feb 26 11:49:24 2009 From: dchandran1 at yahoo.com (Deepak Chandran) Date: Thu, 26 Feb 2009 08:49:24 -0800 (PST) Subject: embedding Python in a shared library Message-ID: <17626.86208.qm@web111101.mail.gq1.yahoo.com> I have embedded Python in a shared library. This works fine in Windows (dll), but I get the following error is Ubuntu when I try to load modules: /usr/lib/python2.5/lib-dynload/time.so: error: symbol lookup error: undefined symbol: PyExc_ValueError I found many postings on this issue on the internet, but I was not able to find a solution that worked. I tried to load libpython2.5.so.1 into my program using dlopen, but that crashed the program for some reason. I tried building my library using the libpython2.5.a, but the same error was there. I am sure someone has a solution to this, since it seems like a general issue. -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin at python.org Thu Feb 26 11:58:43 2009 From: benjamin at python.org (Benjamin Peterson) Date: Thu, 26 Feb 2009 16:58:43 +0000 (UTC) Subject: Proposed implementation for an Ordered Dictionary References: <5c65efb2-0862-4b85-bb37-88687ac6fedd@q9g2000yqc.googlegroups.com> Message-ID: Raymond Hettinger rcn.com> writes: > > Here's a proposed implementation for Py2.7 and Py3.1: > > http://code.activestate.com/recipes/576669/ > > Would like you guys to kick the tires, exercise it a bit, and let me > know what you think. The recipe runs under 2.6 and 3.0 without > modification so it should be easy to play with. Why not just inherit from collections.MutableMapping? From tjreedy at udel.edu Thu Feb 26 13:11:31 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 26 Feb 2009 13:11:31 -0500 Subject: EOL for sys.stdin.readline() and raw_input() In-Reply-To: <49A67300.6050303@unixcluster.dk> References: <49A67300.6050303@unixcluster.dk> Message-ID: jkv wrote: > Hi, > > Are there any way to change the EOL character for sys.stdin.readline() > and raw_input()? > My problem is that i cannot rely on that the clients connection to my > application will end all lines with \n or \r\n. Sometimes they will use > \r\000 as EOL. > > Example from my code: > > sys.stdout.write('Password: '); > #IAC DO ECHO sys.stdout.write('\xFF\xFB\x01') > password = raw_input() > > If the client sends 'qwerty\r\n' everything is fine and the password get > stored in the variable. But sometimes, depending on how broken the > telnet client are, the client will send 'qwerty\r\000' instead and then > my application will hang at 'password = raw_input()' forever. Can you put that in a separate thread with timeout? From patrick.oloughlin at gmail.com Thu Feb 26 13:14:56 2009 From: patrick.oloughlin at gmail.com (Paddy O'Loughlin) Date: Thu, 26 Feb 2009 18:14:56 +0000 Subject: Run a python script as an exe and run a new process from it In-Reply-To: References: Message-ID: Try this as an outline: #### script1.py from subprocess import Popen if __name__ == '__main__': scriptname = "script2.py" Popen("python %s" % scriptname, shell=True) print "I'm done" #### script2.py from time import sleep if __name__ == '__main__': while (True): print "waiting.." sleep(2) ########################### If you install python using the Windows Installer (.exe), it should set up .py files to be opened by python when double-clicking on them. Alternatively, you can right-click on your .py file and go to "Open With..." then "choose program", then click "Browse...", you can Browse to the python executable, so Explorer will use it to open .py files when you double-click on them. As someone else mentioned there is also a py2exe program. Google it. 2009/2/26 venutaurus539 at gmail.com : > Hello all, > ? ? ? ? ? I've a strange requirement where I need to run a python > script just as we run an exe (by double clicking through windows > explorer or by typing the script name at command prompt). In that > process I should be able to execute another python script in such a > way that, the second script should continue running but the main one > should terminate without effecting the second one. > > ? ? ? ? ? ? ? ? ? ?My requirement may be little confusing so please > get back if you didn't understand what I meant above. > > > Thank you, > Venu. > -- > http://mail.python.org/mailman/listinfo/python-list > -- "Ray, when someone asks you if you're a god, you say YES!" From mkhitrov at gmail.com Thu Feb 26 13:17:42 2009 From: mkhitrov at gmail.com (Maxim Khitrov) Date: Thu, 26 Feb 2009 13:17:42 -0500 Subject: What functions, other than sleep(), can be interrupted by Ctrl-C? Message-ID: <26ddd1750902261017o7ec519ey2af03b1be2809cdb@mail.gmail.com> Greetings, I'm looking for a function in the standard library or pywin32 package that will block until a certain condition is met or it is interrupted by Ctrl-C. For example, time.sleep() would have been perfect for my needs if thread.interrupt_main() could interrupt the call from another thread in the same way that Ctrl-C does. Unfortunately, that is not the case. Another thing I tried was creating a pipe with os.pipe() and issuing a read call on it. The event to exit was a single byte written to the other end of the pipe, but Ctrl-C could not interrupt the read call. The threading.Event class does not work for me, because it uses short sleep intervals for timed waits. I need the reaction to be as close to instant as possible, something like this will not do: while not : sleep(0.01) I actually replaced threading.Event with my own version that uses native Windows events, and waits on those also cannot be interrupted by Ctrl-C. I'm trying to achieve the same effect as that while loop and I don't care what the condition to exit is, but the loop needs to exit as soon as the condition is met without waiting for up to X additional milliseconds. Any ideas? - Max From tjreedy at udel.edu Thu Feb 26 13:22:12 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 26 Feb 2009 13:22:12 -0500 Subject: memory recycling/garbage collecting problem In-Reply-To: References: <4d007dac-3782-4b53-9dec-2bcd6accf750@z9g2000yqi.googlegroups.com> Message-ID: Steve Holden wrote: > David Niergarth wrote: >> Tim Peters showed a way to demonstrate the fix in >> >> http://mail.python.org/pipermail/python-dev/2006-March/061991.html >> >>> For simpler fun, run this silly little program, and look at memory >>> consumption at the prompts: >>> >>> """ >>> x = [] >>> for i in xrange(1000000): >>> x.append([]) >>> raw_input("full ") >>> del x[:] >>> raw_input("empty ") >>> """ >>> >>> For example, in a release build on WinXP, VM size is about 48MB at the >>> "full" prompt, and drops to 3MB at the "empty" prompt. In the trunk >>> (without this patch), VM size falls relatively little from what it is >>> at the "full" prompt (the contiguous vector holding a million >>> PyObject* pointers is freed, but the obmalloc arenas holding a >>> million+1 list objects are never freed). >>> >>> For more info about the patch, see Evan's slides from _last_ year's PyCon: >>> >>> http://evanjones.ca/memory-allocator.pdf >> I'm not sure what deleting a slice accomplishes (del x[:]); the >> behavior is the same whether I do del x or del x[:]. Any ideas? >> > del x removes the name x from the current namespace, garbage collecting > the object to which it referred. If there is another reference to the list, which there well might be in an actual application with memory problems, then 'del x' only disassociates the name but the object and its large contents are not gc'ed. > del x[:] leaves x referencing a cleared list. which is guaranteed to be cleared, regardless of other refs. Terry From tjreedy at udel.edu Thu Feb 26 13:22:18 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 26 Feb 2009 13:22:18 -0500 Subject: Delete all items in the list In-Reply-To: References: <50697b2c0902260315i754f9d39y3231f30435824bb5@mail.gmail.com> Message-ID: Gabriel Genellina wrote: > >> L = filter('a'.__ne__,L) > > And this is probably the fastest. But not all types define __ne__ In Py3, all classes inherit .__ne__ from 'object'. From steve at holdenweb.com Thu Feb 26 13:40:04 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 26 Feb 2009 13:40:04 -0500 Subject: memory recycling/garbage collecting problem In-Reply-To: References: <4d007dac-3782-4b53-9dec-2bcd6accf750@z9g2000yqi.googlegroups.com> Message-ID: Terry Reedy wrote: > Steve Holden wrote: >> David Niergarth wrote: [...] >>> I'm not sure what deleting a slice accomplishes (del x[:]); the >>> behavior is the same whether I do del x or del x[:]. Any ideas? >>> >> del x removes the name x from the current namespace, garbage collecting >> the object to which it referred. > > If there is another reference to the list, which there well might be in > an actual application with memory problems, then 'del x' only > disassociates the name but the object and its large contents are not gc'ed. > >> del x[:] leaves x referencing a cleared list. > > which is guaranteed to be cleared, regardless of other refs. > Nice catch, Terry! You correctly spotted I was assuming that d represented the only reference to the list. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Thu Feb 26 13:42:51 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 26 Feb 2009 13:42:51 -0500 Subject: Delete all items in the list In-Reply-To: References: <50697b2c0902260315i754f9d39y3231f30435824bb5@mail.gmail.com> Message-ID: Terry Reedy wrote: > Gabriel Genellina wrote: > >> >>> L = filter('a'.__ne__,L) >> >> And this is probably the fastest. But not all types define __ne__ > > In Py3, all classes inherit .__ne__ from 'object'. > Isn't that inherited method just an identity comparison? However in this particular case the main point is that str *does* implement __ne__. So as long as that built-in method doesn't call the other operand's __ne__ there should be no problem. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From skip at pobox.com Thu Feb 26 13:59:03 2009 From: skip at pobox.com (skip at pobox.com) Date: Thu, 26 Feb 2009 12:59:03 -0600 Subject: EOL for sys.stdin.readline() and raw_input() In-Reply-To: <49A6C0CB.3000704@mrabarnett.plus.com> References: <49A67300.6050303@unixcluster.dk> <49A6C0CB.3000704@mrabarnett.plus.com> Message-ID: <18854.58999.266079.542928@montanaro.dyndns.org> What is it about with statements that makes you want to so frequently embed them in try/except statements? Skip From jkv at unixcluster.dk Thu Feb 26 14:06:06 2009 From: jkv at unixcluster.dk (jkv) Date: Thu, 26 Feb 2009 20:06:06 +0100 Subject: EOL for sys.stdin.readline() and raw_input() In-Reply-To: References: <49A67300.6050303@unixcluster.dk> Message-ID: <49A6E81E.80802@unixcluster.dk> Terry Reedy wrote: > jkv wrote: >> Hi, >> >> Are there any way to change the EOL character for >> sys.stdin.readline() and raw_input()? >> My problem is that i cannot rely on that the clients connection to my >> application will end all lines with \n or \r\n. Sometimes they will >> use \r\000 as EOL. >> >> Example from my code: >> >> sys.stdout.write('Password: '); >> #IAC DO ECHO sys.stdout.write('\xFF\xFB\x01') >> password = raw_input() >> >> If the client sends 'qwerty\r\n' everything is fine and the password >> get stored in the variable. But sometimes, depending on how broken >> the telnet client are, the client will send 'qwerty\r\000' instead >> and then my application will hang at 'password = raw_input()' forever. > > Can you put that in a separate thread with timeout? I guess i could - wouldn't know how thou, just getting started in python. Is there any way i can read stdin character by character? In C i would loop over 'ch = getch();' and in each iteration push the character to the password variable unless ch equals to \r. Anyway to do something like this in python? Regards, jkv From exarkun at divmod.com Thu Feb 26 14:42:46 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Thu, 26 Feb 2009 14:42:46 -0500 Subject: EOL for sys.stdin.readline() and raw_input() In-Reply-To: <49A67300.6050303@unixcluster.dk> Message-ID: <20090226194246.12853.561696535.divmod.quotient.14283@henry.divmod.com> On Thu, 26 Feb 2009 11:46:24 +0100, jkv wrote: >Hi, > >Are there any way to change the EOL character for sys.stdin.readline() and >raw_input()? >My problem is that i cannot rely on that the clients connection to my >application will end all lines with \n or \r\n. Sometimes they will use >\r\000 as EOL. > >Example from my code: > > sys.stdout.write('Password: '); > #IAC DO ECHO sys.stdout.write('\xFF\xFB\x01') > password = raw_input() > >If the client sends 'qwerty\r\n' everything is fine and the password get >stored in the variable. But sometimes, depending on how broken the telnet >client are, the client will send 'qwerty\r\000' instead and then my >application will hang at 'password = raw_input()' forever. > >Any suggestions? It sounds like you might want to use a real implementation of the telnet protocol in your application. Such an implementation would deal with the fact that telnet encodes \r as \r\0 for you. Twisted includes a telnet implementation, as well as facilities for reading stdin asynchronously (which will let you avoid indefinite hangs). Jean-Paul From cosmo_general at yahoo.com Thu Feb 26 15:19:07 2009 From: cosmo_general at yahoo.com (Muddy Coder) Date: Thu, 26 Feb 2009 12:19:07 -0800 (PST) Subject: How to parse form in client side? Message-ID: Hi Folks, cgi module can easily acquire the all fields of data input from client side, through a form. Then, a simple line of code: form_dict = cgi.FieldStorage() grabs all data into a dictionary form_dict. The rest becomes a piece of cake by querying the form_dict. Nice! However, it is done in the server side. Now I want to do the same in the client side. first of all, I get the source code of a HTML form by using urllib, from server, with code below: html_source = urllib.urlopen(URL).read() Then, I need to parse this html_source file, at client side. Is there a module to handle this? Can somebody help? Thanks! Muddy Coder From clp2 at rebertia.com Thu Feb 26 15:22:00 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 26 Feb 2009 12:22:00 -0800 Subject: How to parse form in client side? In-Reply-To: References: Message-ID: <50697b2c0902261222u5931dcb5p9ac17df09808578e@mail.gmail.com> On Thu, Feb 26, 2009 at 12:19 PM, Muddy Coder wrote: > Hi Folks, > > cgi module can easily acquire the all fields of data input from client > side, through a form. Then, a simple line of code: > > form_dict = cgi.FieldStorage() > > grabs all data into a dictionary form_dict. The rest becomes a piece > of cake by querying the form_dict. Nice! > > However, it is done in the server side. Now I want to do the same in > the client side. first of all, I get the source code of a HTML form by > using urllib, from server, with code below: > > html_source = urllib.urlopen(URL).read() > > Then, I need to parse this html_source file, at client side. Is there > a module to handle this? Can somebody help? Thanks! http://wwwsearch.sourceforge.net/ClientForm/ Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From gnewsg at gmail.com Thu Feb 26 15:27:26 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Thu, 26 Feb 2009 12:27:26 -0800 (PST) Subject: How can I know when a sub-process is effectively initialized? Message-ID: <375e4766-de16-4afc-a082-a03317c179f0@r4g2000yqa.googlegroups.com> Hi, I'm working on a Python module called psutil [1] for reading process information in a cross-platform way. I'm having a problem with psutil test suite. Almost all the test cases we implemented so far look like this: def test_foo(self): test_process = subprocess.Popen(sys.executable, stdout=DEVNULL, stderr=DEVNULL) time.sleep(0.1) # XXX: provisional, give some time the sub process to initialize p = psutil.Process(test_process.pid) # start test here ... As you can see we put a time.sleep(0.1) call after subprocess.Popen() as a provisional workaround to let the sub process initialize properly. We're searching for some kind of way to know when the child process is properly initialized so that we can actually start testing cases without worries. Does someone has an idea how could we do that? [1] http://code.google.com/p/psutil/ Thanks a lot in advance, --- Giampaolo [1] http://code.google.com/p/pyftpdlib From tjreedy at udel.edu Thu Feb 26 15:27:38 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 26 Feb 2009 15:27:38 -0500 Subject: Delete all items in the list In-Reply-To: References: <50697b2c0902260315i754f9d39y3231f30435824bb5@mail.gmail.com> Message-ID: Steve Holden wrote: > Terry Reedy wrote: >> Gabriel Genellina wrote: >> >>>> L = filter('a'.__ne__,L) >>> And this is probably the fastest. But not all types define __ne__ >> In Py3, all classes inherit .__ne__ from 'object'. >> > Isn't that inherited method just an identity comparison? Yes. And so is, by default, the snipped slower proposed alternative of lambda x: a!= x. > However in this particular case the main point is that str *does* > implement __ne__. So as long as that built-in method doesn't call the > other operand's __ne__ there should be no problem. > > regards > Steve From steve at holdenweb.com Thu Feb 26 15:31:06 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 26 Feb 2009 15:31:06 -0500 Subject: Delete all items in the list In-Reply-To: References: <50697b2c0902260315i754f9d39y3231f30435824bb5@mail.gmail.com> Message-ID: Terry Reedy wrote: > Steve Holden wrote: >> Terry Reedy wrote: >>> Gabriel Genellina wrote: >>> >>>>> L = filter('a'.__ne__,L) >>>> And this is probably the fastest. But not all types define __ne__ >>> In Py3, all classes inherit .__ne__ from 'object'. >>> >> Isn't that inherited method just an identity comparison? > > Yes. And so is, by default, the snipped slower proposed alternative of > lambda x: a!= x. > But shouldn't that have been lambda x: 'a' != x, which would have invoked the string (3.0, Unicode) comparison method? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From nick at craig-wood.com Thu Feb 26 15:31:53 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Thu, 26 Feb 2009 14:31:53 -0600 Subject: Extending Python Questions ..... References: <7e1a6ec9-8457-40ef-a3da-a16b5dac1100@r34g2000vbp.googlegroups.com> <33411bf0-396a-4aef-83ad-4d4e68b26050@l22g2000vba.googlegroups.com> Message-ID: Ben wrote: > On Feb 24, 11:31?am, Nick Craig-Wood wrote: > > So do you want to embed python into your code? > > > > I'm still not clear what you are trying to achieve with python, though > > I have a better idea what SLAG is now! > > Actually no, I want to EXTEND python using the lower levels of S-lang > screen modules. Ah! > My Modules are written in C and are a frame work for building pull- > down menus and data entry screens. > > Very nice for writing business applications. Think along the lines > of FoxPro and/or the "Screen" section in Cobol and you have a > pretty good idea of what i have done. You've got several choices. 1) Write a python module in C which interfaces with your C code. This is the traditional way, but it is quite time consuming and easy to slip up with reference counting. You need to learn the python API to use this. Will require compiling by your users (not a big hurdle if you make a setup.py). 2) Write an interface with ctypes If your C code presents itself as a shared object (dll/so) then this is a really nice way of using it. You don't have to write any C code or worry about any reference counting - you do it all in python. You'll need to learn how ctypes maps python onto C, but as you know C well you won't find this difficult. ctypes is included with python now. 3) Use Cython Cython is a sort of hybrid C and python which can be used for interfacing with C code. This requires learning exactly what you can and can't do in Cython (it is almost python but not quite). This will require your users to install Cython and compile stuff. Again easy if you make a setup.py but more stuff to install. 4) Use Swig A solid approach, quicker than 1) but not as quick as 2) or 3) This will require your users to install swig and a compiler. ... My prefered approach is 2) ctypes at the moment. I have used all 4 of the above approaches in the past though! -- Nick Craig-Wood -- http://www.craig-wood.com/nick From m.shanmugarajan at gmail.com Thu Feb 26 15:37:33 2009 From: m.shanmugarajan at gmail.com (Shanmuga Rajan) Date: Thu, 26 Feb 2009 15:37:33 -0500 Subject: removing duplication from a huge list. Message-ID: <269329b40902261237j2815c8a2x80d7469abba1e1e6@mail.gmail.com> Hi I have a list of Records with some details.(more than 15 million records) with duplication I need to iterate through every record and need to eliminate duplicate records. Currently i am using a script like this. counted_recs = [ ] x = some_fun() # will return a generator, this generator is the source of list. because i dont want to carry entire 15 million records in a list(need more 1 gb of memory) for rec in x: if rec[0] not in counted_recs: #some logics goes here... counted_recs.append(rec[0]) # i need to have rec[0]=name alone from record. but i am sure this is not a optimized way to do. so i came up with a different solution. but i am not confident in that solution too here my second solution. counted_recs = [] x = some_fun() #x = [ rec[0] for rec in x] for rec in x: if counted_recs.count(rec[0]) > 0 : # some logic goes here counted_recs.append(rec[0]) which one is better? if any one suggests better solution then i will be very happy. Advance thanks for any help. Shan -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Thu Feb 26 15:47:13 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 26 Feb 2009 18:47:13 -0200 Subject: What functions, other than sleep(), can be interrupted by Ctrl-C? References: <26ddd1750902261017o7ec519ey2af03b1be2809cdb@mail.gmail.com> Message-ID: En Thu, 26 Feb 2009 16:17:42 -0200, Maxim Khitrov escribi?: > I'm looking for a function in the standard library or pywin32 package > that will block until a certain condition is met or it is interrupted > by Ctrl-C. For example, time.sleep() would have been perfect for my > needs if thread.interrupt_main() could interrupt the call from another > thread in the same way that Ctrl-C does. Unfortunately, that is not > the case. > > Another thing I tried was creating a pipe with os.pipe() and issuing a > read call on it. The event to exit was a single byte written to the > other end of the pipe, but Ctrl-C could not interrupt the read call. > The threading.Event class does not work for me, because it uses short > sleep intervals for timed waits. I need the reaction to be as close to > instant as possible, something like this will not do: > > while not : > sleep(0.01) > > I actually replaced threading.Event with my own version that uses > native Windows events, and waits on those also cannot be interrupted > by Ctrl-C. I'm trying to achieve the same effect as that while loop > and I don't care what the condition to exit is, but the loop needs to > exit as soon as the condition is met without waiting for up to X > additional milliseconds. Any ideas? You may try MsgWaitForMultipleObjects - send a message to the main thread from the other thread. An alertable wait (like SleepEx) plus QueueUserAPC should work, I presume, but I've never actually tried in Python. -- Gabriel Genellina From exarkun at divmod.com Thu Feb 26 15:59:38 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Thu, 26 Feb 2009 15:59:38 -0500 Subject: How can I know when a sub-process is effectively initialized? In-Reply-To: <375e4766-de16-4afc-a082-a03317c179f0@r4g2000yqa.googlegroups.com> Message-ID: <20090226205938.12853.1013496395.divmod.quotient.14307@henry.divmod.com> On Thu, 26 Feb 2009 12:27:26 -0800 (PST), Giampaolo Rodola' wrote: >Hi, >I'm working on a Python module called psutil [1] for reading process >information in a cross-platform way. >I'm having a problem with psutil test suite. >Almost all the test cases we implemented so far look like this: > >def test_foo(self): > test_process = subprocess.Popen(sys.executable, stdout=DEVNULL, >stderr=DEVNULL) > time.sleep(0.1) # XXX: provisional, give some time the sub >process to initialize > p = psutil.Process(test_process.pid) > # start test here > ... > >As you can see we put a time.sleep(0.1) call after subprocess.Popen() >as a provisional workaround to let the sub process initialize >properly. >We're searching for some kind of way to know when the child process is >properly initialized so that we can actually start testing cases >without worries. >Does someone has an idea how could we do that? Hi Giampaolo, "Properly initialized" is application specific. Generally, what you want to do is have the child process tell you when it's ready. A common way to do this is for the child to write some bytes to a file descriptor the parent is monitoring when it is ready. The parent then just waits for those bytes. It looks like you entirely control the child in this case, so that should be possible here. Alternatively, maybe by "properly initialized" you mean something very specific about how subprocess.Popen creates processes. If so, can you elaborate a bit? Jean-Paul From mh at pixar.com Thu Feb 26 16:29:19 2009 From: mh at pixar.com (mh at pixar.com) Date: Thu, 26 Feb 2009 21:29:19 GMT Subject: best way to parse a function-call-like string? Message-ID: I have some strings that look like function calls, e.g. "junkpkg.f1" "junkpkg.f1()" "junkpkg.f1('aaa')" "junkpkg.f1('aaa','bbb')" "junkpkg.f1('aaa','bbb','ccc')" "junkpkg.f1('aaa','with,comma')" and I need to split them into the function name and list of parms, e.g. "junkpkg.f1", [] "junkpkg.f1", [] "junkpkg.f1", ['aaa'] "junkpkg.f1", ['aaa','bbb'] "junkpkg.f1", ['aaa','bbb','ccc'] "junkpkg.f1", ['aaa','with,comma'] What's the best way to do this? I would be interested in either of two approaches: - a "real" way which comprehensively - a quick-and-dirty way which handles most cases, so that I can get my coding partner running quickly while I do the "real" way. will the csv module do the right thing for the parm list? Many TIA!! Mark -- Mark Harrison Pixar Animation Studios From hniksic at xemacs.org Thu Feb 26 16:38:19 2009 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Thu, 26 Feb 2009 22:38:19 +0100 Subject: Proposed implementation for an Ordered Dictionary References: <5c65efb2-0862-4b85-bb37-88687ac6fedd@q9g2000yqc.googlegroups.com> Message-ID: <871vtk7ub8.fsf@mulj.homelinux.net> Raymond Hettinger writes: > Here's a proposed implementation for Py2.7 and Py3.1: > > http://code.activestate.com/recipes/576669/ Several methods like __contains__() and __getitem__() are not overridden, so their performance is just as fast as a regular dictionary. Methods like __setitem__ and __delitem__ are overridden but have a fast path depending on whether or not the key already exists. It seems that __delitem__ of an existing key is O(n), whereas it's amortized constant time for dicts. (__setitem__ is constant time for both.) Is there a way to avoid this? If not, it should probably be documented, since it differs from dict. From tim.wintle at teamrubber.com Thu Feb 26 16:39:09 2009 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Thu, 26 Feb 2009 21:39:09 +0000 Subject: best way to parse a function-call-like string? In-Reply-To: References: Message-ID: <1235684349.4128.14.camel@tim-laptop> On Thu, 2009-02-26 at 21:29 +0000, mh at pixar.com wrote: > I have some strings that look like function calls, e.g. > > "junkpkg.f1" > "junkpkg.f1()" > "junkpkg.f1('aaa')" > "junkpkg.f1('aaa','bbb')" > "junkpkg.f1('aaa','bbb','ccc')" > "junkpkg.f1('aaa','with,comma')" > > and I need to split them into the function name and list of parms, > e.g. > > "junkpkg.f1", [] > "junkpkg.f1", [] > "junkpkg.f1", ['aaa'] > "junkpkg.f1", ['aaa','bbb'] > "junkpkg.f1", ['aaa','bbb','ccc'] > "junkpkg.f1", ['aaa','with,comma'] > quick and dirty for s in string_list: if "(" in s and s[-1] == ")": parts = s.split("(") fn, args = s[0],s[1][:-1].split(",") Tim Wintle From mh at pixar.com Thu Feb 26 16:42:06 2009 From: mh at pixar.com (mh at pixar.com) Date: Thu, 26 Feb 2009 21:42:06 GMT Subject: best way to parse a function-call-like string? References: Message-ID: Robert Kern wrote: > On 2009-02-26 15:29, mh at pixar.com wrote: > Use the compiler module to generate an AST and walk it. That's the real > way. For me, that would also be the quick way because I am familiar with > the API, but it may take you a little bit of time to get used to it. ah, that's just what I was hoping for... in the meantime, here's my quick and dirty: import csv def fakeparse(s): print "=======" argl=[] ix=s.find('(') if ix == -1: func=s argl=[] else: func=s[0:ix] argstr=s[ix+1:] argstr=argstr[:argstr.rfind(')')] print argstr for argl in csv.reader([argstr], quotechar="'"): pass print s print func print argl return func,argl print fakeparse("junkpkg.f1") print fakeparse("junkpkg.f1()") print fakeparse("junkpkg.f1('aaa')") print fakeparse("junkpkg.f1('aaa','bbb')") print fakeparse("junkpkg.f1('aaa','bbb','ccc')") print fakeparse("junkpkg.f1('aaa','xx,yy')") -- Mark Harrison Pixar Animation Studios From tim.wintle at teamrubber.com Thu Feb 26 16:42:43 2009 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Thu, 26 Feb 2009 21:42:43 +0000 Subject: best way to parse a function-call-like string? In-Reply-To: <1235684349.4128.14.camel@tim-laptop> References: <1235684349.4128.14.camel@tim-laptop> Message-ID: <1235684563.4128.19.camel@tim-laptop> On Thu, 2009-02-26 at 21:39 +0000, Tim Wintle wrote: > On Thu, 2009-02-26 at 21:29 +0000, mh at pixar.com wrote: > > "junkpkg.f1", ['aaa','with,comma'] oops - missed this one, ignore my last reply. From robert.kern at gmail.com Thu Feb 26 16:43:32 2009 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 26 Feb 2009 15:43:32 -0600 Subject: best way to parse a function-call-like string? In-Reply-To: References: Message-ID: On 2009-02-26 15:29, mh at pixar.com wrote: > I have some strings that look like function calls, e.g. > > "junkpkg.f1" > "junkpkg.f1()" > "junkpkg.f1('aaa')" > "junkpkg.f1('aaa','bbb')" > "junkpkg.f1('aaa','bbb','ccc')" > "junkpkg.f1('aaa','with,comma')" > > and I need to split them into the function name and list of parms, e.g. > > "junkpkg.f1", [] > "junkpkg.f1", [] > "junkpkg.f1", ['aaa'] > "junkpkg.f1", ['aaa','bbb'] > "junkpkg.f1", ['aaa','bbb','ccc'] > "junkpkg.f1", ['aaa','with,comma'] > > What's the best way to do this? I would be interested in either > of two approaches: > > - a "real" way which comprehensively > > - a quick-and-dirty way which handles most cases, so that I > can get my coding partner running quickly while I do the > "real" way. will the csv module do the right thing for > the parm list? Use the compiler module to generate an AST and walk it. That's the real way. For me, that would also be the quick way because I am familiar with the API, but it may take you a little bit of time to get used to it. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From JesseAldridge at gmail.com Thu Feb 26 16:48:08 2009 From: JesseAldridge at gmail.com (Jesse Aldridge) Date: Thu, 26 Feb 2009 13:48:08 -0800 (PST) Subject: Can someone explain this behavior to me? Message-ID: I have one module called foo.py --------------------- class Foo: foo = None def get_foo(): return Foo.foo if __name__ == "__main__": import bar Foo.foo = "foo" bar.go() --------------------- And another one called bar.py --------------------- import foo def go(): assert foo.get_foo() == "foo" ---------------------- When I run foo.py, the assertion in bar.py fails. Why? From sjmachin at lexicon.net Thu Feb 26 17:02:53 2009 From: sjmachin at lexicon.net (John Machin) Date: Thu, 26 Feb 2009 14:02:53 -0800 (PST) Subject: best way to parse a function-call-like string? References: Message-ID: <41d63877-0166-4b82-872e-3ddbf6d35dff@d2g2000pra.googlegroups.com> On Feb 27, 8:29?am, m... at pixar.com wrote: > I have some strings that look like function calls, e.g. > > ? ? ? ? "junkpkg.f1" > ? ? ? ? "junkpkg.f1()" > ? ? ? ? "junkpkg.f1('aaa')" > ? ? ? ? "junkpkg.f1('aaa','bbb')" > ? ? ? ? "junkpkg.f1('aaa','bbb','ccc')" > ? ? ? ? "junkpkg.f1('aaa','with,comma')" Examples are better than no examples, but a grammar would be a great help. What about "junkpkg.f1('aaa','with)parenthesis')" "junkpkg.f1('aaa','with''ONEapostrophe')" > > and I need to split them into the function name and list of parms, e.g. > > ? ? ? ? "junkpkg.f1", [] > ? ? ? ? "junkpkg.f1", [] > ? ? ? ? "junkpkg.f1", ['aaa'] > ? ? ? ? "junkpkg.f1", ['aaa','bbb'] > ? ? ? ? "junkpkg.f1", ['aaa','bbb','ccc'] > ? ? ? ? "junkpkg.f1", ['aaa','with,comma'] > > What's the best way to do this? ?I would be interested in either > of two approaches: > > ? ?- a "real" way which comprehensively > > ? ?- a quick-and-dirty way which handles most cases, so that I > ? ? ?can get my coding partner running quickly while I do the > ? ? ?"real" way. ?will the csv module do the right thing for > ? ? ?the parm list? It should, for "most cases". Any reason you can't try it out for yourself? It appears to "work" in the sense that if you have isolated a string containing the parameters, the csv module can be used to "parse" it: | Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on win32 | Type "help", "copyright", "credits" or "license" for more information. | >>> import csv, cStringIO | >>> argstring = "'aaa','with,comma'" | >>> csvargs = lambda s: list(csv.reader(cStringIO.StringIO(s), quotechar="'")) | >>> csvargs(argstring) | [['aaa', 'with,comma']] | >>> csvargs("'aaa','with''ONEapostrophe'") | [['aaa', "with'ONEapostrophe"]] | >>> HTH John From clp2 at rebertia.com Thu Feb 26 17:13:29 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 26 Feb 2009 14:13:29 -0800 Subject: Can someone explain this behavior to me? In-Reply-To: References: Message-ID: <50697b2c0902261413p13ad7df9tffa50fa4d04662c9@mail.gmail.com> On Thu, Feb 26, 2009 at 1:48 PM, Jesse Aldridge wrote: > I have one module called foo.py > --------------------- > class Foo: > ? ?foo = None > > def get_foo(): > ? ?return Foo.foo > > if __name__ == "__main__": > ? ?import bar > ? ?Foo.foo = "foo" > ? ?bar.go() > --------------------- > And another one called bar.py > --------------------- > import foo > > def go(): > ? ?assert foo.get_foo() == "foo" > ---------------------- > When I run foo.py, the assertion in bar.py fails. ?Why? Not sure, but circular imports are *evil* anyway, so I'd suggest you just rewrite the code to avoid doing any circular imports in the first place. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From gschells at hotmail.com Thu Feb 26 17:23:27 2009 From: gschells at hotmail.com (Gary Schells) Date: Thu, 26 Feb 2009 17:23:27 -0500 Subject: PythonWin -vs- Idle Message-ID: Hello, Python newbie here. I am working with Python and geoprocessing in ArcGIS. I'm taking a training course online and the exercise I'm working on makes mention of using PythonWin instead of Idle. I am using version 2.5 and have not been able to locate PythonWin. The download just includes Idle for the environment. Can anyone point me in the right direction to download the PythonWin piece of this puzzle? Thank you _________________________________________________________________ It?s the same Hotmail?. If by ?same? you mean up to 70% faster. http://windowslive.com/online/hotmail?ocid=TXT_TAGLM_WL_HM_AE_Same_022009 -------------- next part -------------- An HTML attachment was scrubbed... URL: From mabdelkader at gmail.com Thu Feb 26 17:25:38 2009 From: mabdelkader at gmail.com (ma) Date: Thu, 26 Feb 2009 17:25:38 -0500 Subject: Can someone explain this behavior to me? In-Reply-To: <50697b2c0902261413p13ad7df9tffa50fa4d04662c9@mail.gmail.com> References: <50697b2c0902261413p13ad7df9tffa50fa4d04662c9@mail.gmail.com> Message-ID: <148918f0902261425g50a31279w9b42f55b65886fd5@mail.gmail.com> I'm pretty sure that Foo is getting replaced once you import Foo, why not pass the Foo() object to bar's go? I'm sure there are other ways, but yes, circular imports are indeed evil. On Thu, Feb 26, 2009 at 5:13 PM, Chris Rebert wrote: > On Thu, Feb 26, 2009 at 1:48 PM, Jesse Aldridge > wrote: > > I have one module called foo.py > > --------------------- > > class Foo: > > foo = None > > > > def get_foo(): > > return Foo.foo > > > > if __name__ == "__main__": > > import bar > > Foo.foo = "foo" > > bar.go() > > --------------------- > > And another one called bar.py > > --------------------- > > import foo > > > > def go(): > > assert foo.get_foo() == "foo" > > ---------------------- > > When I run foo.py, the assertion in bar.py fails. Why? > > Not sure, but circular imports are *evil* anyway, so I'd suggest you > just rewrite the code to avoid doing any circular imports in the first > place. > > Cheers, > Chris > > -- > Follow the path of the Iguana... > http://rebertia.com > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jkv at unixcluster.dk Thu Feb 26 17:33:39 2009 From: jkv at unixcluster.dk (jkv) Date: Thu, 26 Feb 2009 23:33:39 +0100 Subject: EOL for sys.stdin.readline() and raw_input() In-Reply-To: <20090226194246.12853.561696535.divmod.quotient.14283@henry.divmod.com> References: <20090226194246.12853.561696535.divmod.quotient.14283@henry.divmod.com> Message-ID: <49A718C3.2020002@unixcluster.dk> Jean-Paul Calderone wrote: > sys.stdout.write('Password: '); >> #IAC DO ECHO sys.stdout.write('\xFF\xFB\x01') >> password = raw_input() >> >> If the client sends 'qwerty\r\n' everything is fine and the password >> get stored in the variable. But sometimes, depending on how broken >> the telnet client are, the client will send 'qwerty\r\000' instead >> and then my application will hang at 'password = raw_input()' forever. >> >> Any suggestions? > > It sounds like you might want to use a real implementation of the telnet > protocol in your application. Such an implementation would deal with the > fact that telnet encodes \r as \r\0 for you. > > Twisted includes a telnet implementation, as well as facilities for > reading > stdin asynchronously (which will let you avoid indefinite hangs). I am running this script inside a wrapper (honeyd), so i cant really use twisted since i don't have raw network access - i only got stdout, stdin and stderr to play with. But i found a solution, posting it here for the archives: password = "" while 1: c = sys.stdin.read(1) if c == '\r' or c == '\n': break password = password + c Regards, jkv From Lie.1296 at gmail.com Thu Feb 26 17:39:12 2009 From: Lie.1296 at gmail.com (Lie) Date: Thu, 26 Feb 2009 14:39:12 -0800 (PST) Subject: "Battleship" style game References: Message-ID: <1dca1b53-dbc9-4b36-b4b8-18ee657b0438@v18g2000pro.googlegroups.com> On Feb 26, 3:50?am, Shawn Milochik wrote: > On Wed, Feb 25, 2009 at 11:38 AM, Marco Mariani wrote: > > > Yes it's in Python alright, but it's not Pythonese yet. You could try > > avoiding the getter/setter stuff, and camelCase method naming, things like > > that, for a start. > > > -- > >http://mail.python.org/mailman/listinfo/python-list > > What do you mean avoiding the getter/setter stuff? If I understand > correctly, you're saying to directly access the attributes, which I > specifically want to avoid because I may want to enforce some rules > (such as not changing a ship length after it's created). I just want to add the note that since you're planning to move the code to Java, although you should avoid getter and setter in python (since it's redundant because of property), you should use getter and setter in the Java version because it is the best practice in Java. > The camel-case thing I get -- I use that and this_type quite a bit, > probably because of the inconsistency of the languages I use > regularly, and standards at work and conventions in my hobby > programming. From clp2 at rebertia.com Thu Feb 26 17:40:50 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 26 Feb 2009 14:40:50 -0800 Subject: PythonWin -vs- Idle In-Reply-To: References: Message-ID: <50697b2c0902261440ja1db6a0i3512527eb835d9b@mail.gmail.com> On Thu, Feb 26, 2009 at 2:23 PM, Gary Schells wrote: > > Hello, > Python newbie here.? I am working with Python and geoprocessing in ArcGIS. > I'm taking a training course online and the exercise I'm working on makes > mention of using PythonWin instead of Idle. > > I am using version 2.5 and have not been able to locate PythonWin.? The > download just includes Idle for the environment.? Can anyone point me in the > right direction to download the PythonWin piece of this puzzle? Seems to be included in http://sourceforge.net/projects/pywin32/ Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From sjmachin at lexicon.net Thu Feb 26 17:44:40 2009 From: sjmachin at lexicon.net (John Machin) Date: Thu, 26 Feb 2009 14:44:40 -0800 (PST) Subject: Can someone explain this behavior to me? References: Message-ID: <95d96ea7-1e3d-425e-be99-655a68ffaeca@l33g2000pri.googlegroups.com> On Feb 27, 8:48?am, Jesse Aldridge wrote: > I have one module called foo.py > --------------------- > class Foo: > ? ? foo = None > > def get_foo(): > ? ? return Foo.foo > > if __name__ == "__main__": > ? ? import bar > ? ? Foo.foo = "foo" > ? ? bar.go() > --------------------- > And another one called bar.py > --------------------- > import foo > > def go(): > ? ? assert foo.get_foo() == "foo" > ---------------------- > When I run foo.py, the assertion in bar.py fails. ?Why? AFAICT from that convoluted mess, because there are two rabbit holes, __main__.Foo.foo and foo.Foo.foo, and you poked "foo" down the wrong one. In any case the other one is not the right one -- as you have already been advised, circular imports are evil. From exarkun at divmod.com Thu Feb 26 17:50:38 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Thu, 26 Feb 2009 17:50:38 -0500 Subject: EOL for sys.stdin.readline() and raw_input() In-Reply-To: <49A7186D.8050609@unixcluster.dk> Message-ID: <20090226225038.12853.1517515098.divmod.quotient.14356@henry.divmod.com> On Thu, 26 Feb 2009 23:32:13 +0100, jkv wrote: >Jean-Paul Calderone wrote: >> sys.stdout.write('Password: '); >>> #IAC DO ECHO sys.stdout.write('\xFF\xFB\x01') >>> password = raw_input() >>> >>>If the client sends 'qwerty\r\n' everything is fine and the password get >>>stored in the variable. But sometimes, depending on how broken the telnet >>>client are, the client will send 'qwerty\r\000' instead and then my >>>application will hang at 'password = raw_input()' forever. >>> >>>Any suggestions? >> >>It sounds like you might want to use a real implementation of the telnet >>protocol in your application. Such an implementation would deal with the >>fact that telnet encodes \r as \r\0 for you. >> >>Twisted includes a telnet implementation, as well as facilities for reading >>stdin asynchronously (which will let you avoid indefinite hangs). >I running this script inside a wrapper (honeyd), so i cant really use >twisted since i dont have raw network access - i only got stdout, stdin and >stderr to play with. > >But i found a solution, posting it here for the archives: > >password = "" >while 1: > c = sys.stdin.read(1) > if c == '\r' or c == '\n': > break > password = password + c > Glad you figured something out. Just for the record, you can use Twisted to write applications that interact with stdio, so the fact that you're using honeyd doesn't prevent you from using Twisted. Jean-Paul From python at rcn.com Thu Feb 26 17:54:53 2009 From: python at rcn.com (Raymond Hettinger) Date: Thu, 26 Feb 2009 14:54:53 -0800 (PST) Subject: Proposed implementation for an Ordered Dictionary References: <5c65efb2-0862-4b85-bb37-88687ac6fedd@q9g2000yqc.googlegroups.com> Message-ID: <6f96323f-6263-4306-872c-544c76ec231f@40g2000prx.googlegroups.com> [Benjamin Peterson] > Why not just inherit from collections.MutableMapping? It makes the recipe shorter to inherit some methods from dict. Also, subclassing from dict gives a speedup for __getitem__(), __len__(), and get(). From ptmcg at austin.rr.com Thu Feb 26 17:56:17 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Thu, 26 Feb 2009 14:56:17 -0800 (PST) Subject: best way to parse a function-call-like string? References: Message-ID: <64326bcf-0968-4589-bfd0-65a5c452e962@q9g2000yqc.googlegroups.com> On Feb 26, 3:29?pm, m... at pixar.com wrote: > I have some strings that look like function calls, e.g. > > ? ? ? ? "junkpkg.f1" > ? ? ? ? "junkpkg.f1()" > ? ? ? ? "junkpkg.f1('aaa')" > ? ? ? ? "junkpkg.f1('aaa','bbb')" > ? ? ? ? "junkpkg.f1('aaa','bbb','ccc')" > ? ? ? ? "junkpkg.f1('aaa','with,comma')" > > and I need to split them into the function name and list of parms, e.g. > Pyparsing will easily carve up these function declarations, and will give you some room for easy extension once your parsing job starts to grow to include other variants (like arguments other than quoted strings, for instance). Using the results names ("name" and "args"), then parsed fields are easy to get at after the parsing is done. -- Paul from pyparsing import Word, alphas, alphanums, delimitedList, \ Optional, Literal, Suppress, quotedString LPAR,RPAR = map(Suppress,"()") ident = Word(alphas+"_", alphanums+"_") fnName = delimitedList(ident,".",combine=True) arg = quotedString fnCall = fnName("name") + Optional(LPAR + Optional(delimitedList(arg)) + RPAR, default=[])("args") tests = """junkpkg.f1 junkpkg.f1() junkpkg.f1('aaa') junkpkg.f1('aaa','bbb') junkpkg.f1('aaa','bbb','ccc') junkpkg.f1('aaa','with,comma')""".splitlines() for t in tests: fn = fnCall.parseString(t) print fn.name for a in fn.args: print "-",a print Prints: junkpkg.f1 junkpkg.f1 junkpkg.f1 - 'aaa' junkpkg.f1 - 'aaa' - 'bbb' junkpkg.f1 - 'aaa' - 'bbb' - 'ccc' junkpkg.f1 - 'aaa' - 'with,comma' From python at rcn.com Thu Feb 26 17:57:26 2009 From: python at rcn.com (Raymond Hettinger) Date: Thu, 26 Feb 2009 14:57:26 -0800 (PST) Subject: Proposed implementation for an Ordered Dictionary References: <5c65efb2-0862-4b85-bb37-88687ac6fedd@q9g2000yqc.googlegroups.com> <871vtk7ub8.fsf@mulj.homelinux.net> Message-ID: [Hrvoje Niksic] > It seems that __delitem__ of an existing key is O(n), whereas it's > amortized constant time for dicts. ?(__setitem__ is constant time for > both.) ?Is there a way to avoid this? I don't see any fast/clean way. It's possible to tracking pending deletions and do them all at once but that's a bit messy and slow. > If not, it should probably be documented, since it differs from dict. That makes sense. Raymond From jgardner at jonathangardner.net Thu Feb 26 18:10:20 2009 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Thu, 26 Feb 2009 15:10:20 -0800 (PST) Subject: code challenge: generate minimal expressions using only digits 1,2,3 References: <941be713-2789-48c7-911b-422313f232d5@o36g2000yqh.googlegroups.com> Message-ID: <7d37e241-cf2a-494d-96e9-5f2dbf6f6125@k9g2000prh.googlegroups.com> On Feb 20, 6:31?am, Trip Technician wrote: > anyone interested in looking at the following problem. > > we are trying to express numbers as minimal expressions using only the > digits one two and three, with conventional arithmetic. so for > instance > > 33 = 2^(3+2)+1 = 3^3+(3*2) > > are both minimal, using 4 digits but > > 33 = ((3+2)*2+1)*3 > > using 5 is not. > > I have tried coding a function to return the minimal representation > for any integer, but haven't cracked it so far. The naive first > attempt is to generate lots of random strings, eval() them and sort by > size and value. this is inelegant and slow. > > I have a dim intuition that it could be done with a very clever bit of > recursion, but the exact form so far eludes me. Actually, representing 33 has an even shorter answer: '33' There is actually a really easy solution for this. What you are really doing is finding the shortest path from point A (the expression '') to another expression that evaluates to the target number. >From each point, you can take steps that (a) add a digit to the end or (b) add an operator---but only if it makes sense. Since operators don't count, those steps don't add anything to the distance, while the digits do. What you do is you start walking the map from point A to some mysterious point that evaluates to the result you want. Actually, you send out walkers in all directions, and tell only the walkers that have taken the fewest steps to take another step. Once a walker gets to an expression with the result, you have your answer since he is the first walker to get there. When a walker gets to an expression that has already been visited, you can tell that walker to go home since his path was no good. When a walker gets to an expression that evaluates to a value you have already seen, that walker too should go home since he has just found a longer path to the same result. So you have a set of walkers, and each walker has the expression they used to get to where they are and how many steps they took to get there. You also have a set of values you have seen before and thus values that if a walker finds you are no longer interested in. For each iteration, you take each surviving walker and spawn a new walker that takes a step in each possible direction. Then you check if any of those walkers found the value you are looking for. If so, you've found the answer. If they hit a value you've already seen, you drop that walker from the set. The only hanging point is parentheses. What you can do here is instead of building a linear expression, build a tree expression that shows the operations and the values they operate. It should be trivial to calculate all the different new trees that are one digit longer than a previous tree. From http Thu Feb 26 18:26:05 2009 From: http (Paul Rubin) Date: 26 Feb 2009 15:26:05 -0800 Subject: Proposed implementation for an Ordered Dictionary References: <5c65efb2-0862-4b85-bb37-88687ac6fedd@q9g2000yqc.googlegroups.com> <871vtk7ub8.fsf@mulj.homelinux.net> Message-ID: <7xd4d4hjaq.fsf@ruckus.brouhaha.com> Raymond Hettinger writes: > I don't see any fast/clean way. It's possible to tracking pending > deletions and do them all at once but that's a bit messy and slow. What about using a second dictionary (indexed by the incrementing counter) instead of a list to record the insertion order? Then you have O(1) deletion, and traversal takes an O(n log n) sorting operation. From python at rcn.com Thu Feb 26 18:41:39 2009 From: python at rcn.com (Raymond Hettinger) Date: Thu, 26 Feb 2009 15:41:39 -0800 (PST) Subject: Proposed implementation for an Ordered Dictionary References: <5c65efb2-0862-4b85-bb37-88687ac6fedd@q9g2000yqc.googlegroups.com> <871vtk7ub8.fsf@mulj.homelinux.net> <7xd4d4hjaq.fsf@ruckus.brouhaha.com> Message-ID: <6d818c3d-1d6d-4720-8775-427b3832c590@u18g2000pro.googlegroups.com> [Paul Rubin] > What about using a second dictionary (indexed by the incrementing > counter) instead of a list to record the insertion order? ?Then you > have O(1) deletion, and traversal takes an O(n log n) sorting > operation. My first attempt used exactly that approach and it works fine though it does complicate the code quite a bit and slows down all of the common operations by a constant factor. Raymond From python at rcn.com Thu Feb 26 18:46:05 2009 From: python at rcn.com (Raymond Hettinger) Date: Thu, 26 Feb 2009 15:46:05 -0800 (PST) Subject: Proposed implementation for an Ordered Dictionary References: <5c65efb2-0862-4b85-bb37-88687ac6fedd@q9g2000yqc.googlegroups.com> <871vtk7ub8.fsf@mulj.homelinux.net> <7xd4d4hjaq.fsf@ruckus.brouhaha.com> <6d818c3d-1d6d-4720-8775-427b3832c590@u18g2000pro.googlegroups.com> Message-ID: <60b78693-b5af-452c-8081-86ff75679e64@z6g2000pre.googlegroups.com> > > What about using a second dictionary (indexed by the incrementing > > counter) instead of a list to record the insertion order? ?Then you > > have O(1) deletion, and traversal takes an O(n log n) sorting > > operation. > My first attempt used exactly that approach and it works fine > though it does complicate the code quite a bit and slows down > all of the common operations by a constant factor. FWIW, here is the code for that approach. -------------------------------------- from collections import MutableMapping class OrderedDict(dict): def __init__(self, *args, **kwds): if len(args) > 1: raise TypeError('expected at 1 argument, got %d', len (args)) self.clear() self.update(*args, **kwds) def clear(self): self.__cached_sort = None self.__cnt = 0 self.__order = {} dict.clear(self) def __setitem__(self, key, value): if key not in self: self.__cached_sort = None self.__cnt += 1 self.__order[key] = self.__cnt dict.__setitem__(self, key, value) def __delitem__(self, key): if key in self: self.__cached_sort = None del self.__order[key] dict.__delitem__(self, key) def __sorted(self): # return keys in insertion order and cache the result if self.__cached_sort is None: self.__cached_sort = sorted(dict.keys(self), key=self.__order.__getitem__) return self.__cached_sort def __iter__(self): return iter(self.__sorted()) def __reversed__(self): return iter(reversed(self.__sorted())) def popitem(self): # O(n) cost on the first pop and O(1) on successive pops if not self: raise KeyError key = self.__sorted().pop() del self.__order[key] value = dict.pop(self, key) return key, value # Methods with indirect access via the above methods setdefault = MutableMapping.setdefault update = MutableMapping.update pop = MutableMapping.pop keys = MutableMapping.keys values = MutableMapping.values items = MutableMapping.items def __repr__(self): return '{' + ', '.join(map('%r: %r'.__mod__, self.items())) + '}' def copy(self): return self.__class__(self) @classmethod def fromkeys(cls, iterable, value=None): d = cls() for key in iterable: d[key] = value return d def __reduce__(self): # pickle an items list and any extra info in the instance dict items = list(self.items()) inst_dict = vars(self).copy() for attr in vars(self.__class__): inst_dict.pop(attr, None) return (self.__class__, (items,), inst_dict) From marduk at letterboxes.org Thu Feb 26 18:58:18 2009 From: marduk at letterboxes.org (Albert Hopkins) Date: Thu, 26 Feb 2009 18:58:18 -0500 Subject: Can someone explain this behavior to me? In-Reply-To: References: Message-ID: <1235692698.31574.17.camel@centar.nbk> On Thu, 2009-02-26 at 13:48 -0800, Jesse Aldridge wrote: > I have one module called foo.py > --------------------- > class Foo: > foo = None > > def get_foo(): > return Foo.foo > > if __name__ == "__main__": > import bar > Foo.foo = "foo" > bar.go() > --------------------- > And another one called bar.py > --------------------- > import foo > > def go(): > assert foo.get_foo() == "foo" > ---------------------- > When I run foo.py, the assertion in bar.py fails. Why? AFAICT you have 2 different "foo" modules here. The first foo is when foo.py is called as a script, but it's not called "foo" it's called "__main__" because it's called as a script. When "bar" is imported, it imports "foo", but this is different. Technically this is the first time you are *importing* foo. It's actually loaded a second time with the name "foo". A more simplified version of it is this: $ cat foo.py cat = 6 import bar print '%s: %s.cat = %s' % (__file__, __name__, cat) $ cat bar.py import foo foo.cat = 7 print '%s: %s.cat = %s' % (__file__, foo.__name__, foo.cat) $ python foo.py /home/marduk/test/foo.py: foo.cat = 6 /home/marduk/test/bar.py: foo.cat = 7 foo.py: __main__.cat = 6 OTOH: $ python -c "import foo" bar.py: foo.cat = 7 foo.py: foo.cat = 7 But, as others have said, this is confusing and should be avoided. -a From http Thu Feb 26 19:05:35 2009 From: http (Paul Rubin) Date: 26 Feb 2009 16:05:35 -0800 Subject: Proposed implementation for an Ordered Dictionary References: <5c65efb2-0862-4b85-bb37-88687ac6fedd@q9g2000yqc.googlegroups.com> <871vtk7ub8.fsf@mulj.homelinux.net> <7xd4d4hjaq.fsf@ruckus.brouhaha.com> <6d818c3d-1d6d-4720-8775-427b3832c590@u18g2000pro.googlegroups.com> Message-ID: <7x63iwg2wg.fsf@ruckus.brouhaha.com> Raymond Hettinger writes: > > What about using a second dictionary > My first attempt used exactly that approach and it works fine > though it does complicate the code quite a bit and slows down > all of the common operations by a constant factor. Ehh, I guess I'm not surprised at the slowdown and extra complexity from the second dict. Oh well. If the module really turns out to be really used a lot, another (messy) approach would be to write a C extension that uses a doubly linked list some day. From peter at www.pjb.com.au Thu Feb 26 19:08:26 2009 From: peter at www.pjb.com.au (Peter Billam) Date: 27 Feb 2009 00:08:26 GMT Subject: Delete all items in the list References: Message-ID: On 2009-02-26, Clarendon wrote: > Hi. This must be a simple command but I just can't find it in the > Phthon manual. How do I delete all items with a certain condition from > a list? For instance: > L=['a', 'b', 'c', 'a'] > I want to delete all 'a's from the list. > But if L.remove('a') > only deletes the first 'a'. How do you delete all 'a's? L2 = list(set(L)) works for me... Regards, Peter -- Peter Billam www.pjb.com.au www.pjb.com.au/comp/contact.html From rhodri at wildebst.demon.co.uk Thu Feb 26 19:10:49 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 27 Feb 2009 00:10:49 -0000 Subject: code challenge: generate minimal expressions using only digits 1,2,3 In-Reply-To: <7d37e241-cf2a-494d-96e9-5f2dbf6f6125@k9g2000prh.googlegroups.com> References: <941be713-2789-48c7-911b-422313f232d5@o36g2000yqh.googlegroups.com> <7d37e241-cf2a-494d-96e9-5f2dbf6f6125@k9g2000prh.googlegroups.com> Message-ID: On Thu, 26 Feb 2009 23:10:20 -0000, Jonathan Gardner wrote: [snip] > For each iteration, you take each surviving walker and spawn a new > walker that takes a step in each possible direction. Then you check if > any of those walkers found the value you are looking for. If so, > you've found the answer. If they hit a value you've already seen, you > drop that walker from the set. This relies each value having the same set of next states no matter how it's reached. Unfortunately that's not true. Consider what happens when you walk on from (1+3) and (2+2): One possible step from (1+3) is ((1/3)+3) == 3.33... There's no single step from (2+2) that can get you to the same place. > The only hanging point is parentheses. What you can do here is instead > of building a linear expression, build a tree expression that shows > the operations and the values they operate. It should be trivial to > calculate all the different new trees that are one digit longer than a > previous tree. Trivial yes, but the number of different new trees is large when you're dealing with four digits, and ridiculous with 5. -- Rhodri James *-* Wildebeeste Herder to the Masses From google at mrabarnett.plus.com Thu Feb 26 19:11:43 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 27 Feb 2009 00:11:43 +0000 Subject: code challenge: generate minimal expressions using only digits 1,2,3 In-Reply-To: <941be713-2789-48c7-911b-422313f232d5@o36g2000yqh.googlegroups.com> References: <941be713-2789-48c7-911b-422313f232d5@o36g2000yqh.googlegroups.com> Message-ID: <49A72FBF.8080206@mrabarnett.plus.com> Trip Technician wrote: > anyone interested in looking at the following problem. > > we are trying to express numbers as minimal expressions using only the > digits one two and three, with conventional arithmetic. so for > instance > > 33 = 2^(3+2)+1 = 3^3+(3*2) > > are both minimal, using 4 digits but > > 33 = ((3+2)*2+1)*3 > > using 5 is not. > > I have tried coding a function to return the minimal representation > for any integer, but haven't cracked it so far. The naive first > attempt is to generate lots of random strings, eval() them and sort by > size and value. this is inelegant and slow. > > I have a dim intuition that it could be done with a very clever bit of > recursion, but the exact form so far eludes me. > Here's my solution (I haven't bothered with making it efficient, BTW): import operator def solve(n): best_len = n best_expr = "" for x in range(1, n - 2): for y in range(x, n): for op, name in operator_list: # Does this pair with this op give the right answer? if op(x, y) == n: lx, ex = numbers[x - 1] ly, ey = numbers[y - 1] # How many digits in total? l = lx + ly # Fewer digits than any previous attempts? if l < best_len: # Build the expression. e = "(%s %s %s)" % (ex, name, ey) best_len, best_expr = l, e return best_len, best_expr operator_list = [(operator.add, "+"), (operator.sub, "-"), (operator.mul, "*"), (operator.div, "/"), (operator.pow, "^")] # Tuples contain number of digits used and expression. numbers = [(1, str(n)) for n in range(1, 4)] for n in range(4, 34): numbers.append(solve(n)) for i, (l, e) in enumerate(numbers): print "%2d = %s" % (i + 1, e) From clp2 at rebertia.com Thu Feb 26 19:18:18 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 26 Feb 2009 16:18:18 -0800 Subject: Delete all items in the list In-Reply-To: References: Message-ID: <50697b2c0902261618j56905e0as1c3c2a1cf00eb995@mail.gmail.com> On Thu, Feb 26, 2009 at 4:08 PM, Peter Billam wrote: > On 2009-02-26, Clarendon wrote: >> Hi. This must be a simple command but I just can't find it in the >> Phthon manual. How do I delete all items with a certain condition from >> a list? For instance: > L=['a', 'b', 'c', 'a'] >> I want to delete all 'a's from the list. ?> But if L.remove('a') >> only deletes the first 'a'. ?How do you delete all 'a's? > > L2 = list(set(L)) > > works for me... A. That doesn't by itself remove all the 'a's, although it does remove all but 1 'a' B. That also removes all but one instance of *everything* in the list, not just 'a' C. That is lossy in that it completely loses the ordering of the original list Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From xahlee at gmail.com Thu Feb 26 19:22:57 2009 From: xahlee at gmail.com (Xah Lee) Date: Thu, 26 Feb 2009 16:22:57 -0800 (PST) Subject: a look at the browser scene & emacs References: <8358de80-5198-41e5-b4a2-04e681d359d1@p20g2000yqi.googlegroups.com> <86wsbeajz6.fsf@lola.quinscape.zz> <002094c7-f9fd-422e-a68f-67051e0c7483@w9g2000yqa.googlegroups.com> <87k57dwmay.fsf@thinkpad.tsdh.de> Message-ID: On Feb 26, 1:59 am, Tassilo Horn wrote: > Xah Lee writes: > > Hi Xah, > > > is the suggestion of using modern standard shortcut set of X C V for > > Cut, Copy, Paste, of which Linux uses, means it is turning emacs to a > > fancy Notepad clone? > > The functionality stays the same, but IMO it would confuse most users. > Killing is not cutting, yanking is not pasting. The whole concepts > (kill-ring vs. simple copy&paste) are much different. emacs's killing/yaning/kill-ring is basically the same idea as copy/ cut/paste-board. Basically, emacs's pasteboard is just a extended version, such that it keeps a record of previous copied contents. To users, effectively, this means you can do paste-previous. That's all there is to it. So, it's brainless to make emacs intuitive to people and adopt modern UI standards. Basically, copy, cut, paste, is all the same, except in emacs you have also paste previous. > > Is fixing emacs's confusing undo and no redo, that is periodically > > bitched by programer in blogs, considered making emacs into a Notepad > > clone? > > It's much more advanced than the usual sequential undo, but I admit that > it can get confusing sometimes. So instead of dropping it I'd prefer to > think about a better UI for it. > > > Is the suggestion for a statistics based ergonomic keybinding design > > that are more faster to execute, easier on the fingers, and easier to > > remember, mean it is turning emacs to a fancy notepad clone? > > Users use different commands and your bindings may be better for you on > your querty keyboard, but I'm sure they're not on my German Dvorak Type > II keyboard. If your are on a special keyboard, you are on your own. The ergonomic keybinding ? Ergoemacs Keybindings http://xahlee.org/emacs/ergonomic_emacs_keybinding.html plays well with modern UI in Windows, Mac, Linux. It improves emacs keybinding, but also support standard shortcut sets. In no way, it loses any emacs advantage, while, it makes emacs compatible and intuitive for vast majority of computer users, and improve efficiency for those heavy touch typists and programers who are into the concept of not leaving hands off the keyboard. > > is the suggestion of getting rid of *scratch* buffer, and introduce a > > command ?New? with shortcut Ctrl+n, that creates new buffer anytime > > anywhere, which lets user create multiple scratch buffers defaulting > > to any mode and compatible for the rest of Linux's shortcuts, means it > > is a fancy Microsoft Notepad? > > Such a easy key like C-n is much too valuable for such a rarely used > command. C-x b foobar RET is ok, isn't it? This issues is discussed before in some hundred or 2 hundred thread in 2008. the proposal in detail is here: ? Suggestions on Emacs's Scratch Buffer http://xahlee.org/emacs/modernization_scratch_buffer.html In no way it sacrifices emacs operational efficiency. The proposal is careful thought out, so that in not only doesn't sacrifice emacs operational efficient in any possible way, but improve it, yet meanwhile makes it compatible with modern UI and intuitive to the masses. As for the Ctrl+n for New, it must be used in conjunction with the ergonomic keybinding set mentioned above. In the end, users can intuitive press Ctrl+n for creating a new file, one or multiple of it, can be used as elisp *scratch*, and can be set to default to any major mode, and can be saved by simply pressing Ctrl +s, and it will ask if user wants to save instead of like emacs *scratch* it risk losing data. > > is the suggestion of changing notation from C- and M- to Ctrl+ and Alt > > +, such that it reflects the lable on the keyboard, and Richard > > Stallman agrees may be a good idea, means it's Notepad? > > Nope, but I'm not sure if it's possible for emacs to get the right key. > Here, M is Alt, but Ctrl is indeed on the CapsLock key... > > And it makes key sequences much longer to write with little or no > benefit. What the fuck r u talking about?? Really, what the fuck are you talking about? Give concrete, specific point please. As for the CapsLock for Control, it's a industry myth. For detail, see: ? Why You Should Not Swap Caps Lock With Control http://xahlee.org/emacs/swap_CapsLock_Ctrl.html > > is the suggestion of supporting html mail, and interface to gmail out > > of the box, means it's becoming Microsoft Notepad? > > Definitively not. AFAIK Gnus can handle gmail accounts quite well. Quite well my ass. Thank you for your feedback. I think it would be nice if you do some research on each particular issue. I can't spend my time to write detailed things to teach every poster. And i often have to repeat multiple times of the same issue. For example of a research, suppose you find my claim about Ctrl and Caps Lock switch incredible. Then, you can do research on this subject. Spending 1 hour on it, or days. You can go to library to research ergonomics, or ask professors, or try to hire experts for opinion, or set out experiments and test out hypothesis etc. For example, you can write a program to statistically log your keystroke, timing, etc. You can also set out key sequences set, A, and B, and type them for one hour each, to see which is causing your hand pain, etc. The above is just beginner suggestions, on one particular example of contention. On each and every issue, you can start a research. Btw, you are prob a typical tech geekers, where you don't understand nothing about research or social sciences. One short concrete advice i can give about your situation when researching, is not based on your views on slashdot, or the tech geeking blogs, or ?my emacs buddies did this or that? type of thinking. Another concrete advices is that whatever you did for the research, must cost you. If it came easily without much cost, chances are, it's bullshit in your head. What dose cost mean? Ok, it means your time, for example. Are you, willing, to put aside say 10 hours of your time, on a issue mentioned here? Alternatively, say, are you willing, to spend $100 USD for research on particular issue we are debating here? For example, the money can be used to pay professional services that does research for you. It's probably peanuts and most such research services won't take. But it's a start on thinking. You can spend it on someone who are known expert for example. As a quick example, say you disbelieve one of my claim about ergonomics, then you can spend the $100 USD to say ask some known ergonomics expert to dinner or buy him beer, and ask about his opinion. I typed the above as fast as i can, just to give you some ideas. There are too many issues, aspects, technical, social, concrete, philosophical, that i can cover, and have written a lot in the past years. I can't repeat them all here, and frankly i discussed only a small part. But i hope you have some basic ideas about the issue. Love & knowledge, Xah ? http://xahlee.org/ ? From peter at www.pjb.com.au Thu Feb 26 19:26:30 2009 From: peter at www.pjb.com.au (Peter Billam) Date: 27 Feb 2009 00:26:30 GMT Subject: Delete all items in the list References: Message-ID: On 2009-02-27, Chris Rebert wrote: > On Thu, Feb 26, 2009 at 4:08 PM, Peter Billam wrote: >> On 2009-02-26, Clarendon wrote: >>> How do you delete all 'a's? >> >> L2 = list(set(L)) >> works for me... > > A. That doesn't by itself remove all the 'a's, although it does > remove all but 1 'a' > B. That also removes all but one instance of *everything* in the > list, not just 'a' > C. That is lossy in that it completely loses the ordering of the > original list Sorry, points taken... Regards, Peter -- Peter Billam www.pjb.com.au www.pjb.com.au/comp/contact.html From gagsl-py2 at yahoo.com.ar Thu Feb 26 19:27:26 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 26 Feb 2009 22:27:26 -0200 Subject: Delete all items in the list References: Message-ID: En Thu, 26 Feb 2009 22:08:26 -0200, Peter Billam escribi?: > On 2009-02-26, Clarendon wrote: >> Hi. This must be a simple command but I just can't find it in the >> Phthon manual. How do I delete all items with a certain condition from >> a list? For instance: > L=['a', 'b', 'c', 'a'] >> I want to delete all 'a's from the list. > But if L.remove('a') >> only deletes the first 'a'. How do you delete all 'a's? > > L2 = list(set(L)) > > works for me... For a very strange definition of "works": py> L = ['a','b','c','a','j','b','z','b','a'] py> L2 ['a', 'c', 'b', 'z', 'j'] py> L2 = list(set(L)) py> L2 ['a', 'c', 'b', 'z', 'j'] I still see an 'a', there are things missing, and the order is totally lost. -- Gabriel Genellina From xahlee at gmail.com Thu Feb 26 19:29:06 2009 From: xahlee at gmail.com (Xah Lee) Date: Thu, 26 Feb 2009 16:29:06 -0800 (PST) Subject: a look at the browser scene & emacs References: <8358de80-5198-41e5-b4a2-04e681d359d1@p20g2000yqi.googlegroups.com> <86wsbeajz6.fsf@lola.quinscape.zz> <002094c7-f9fd-422e-a68f-67051e0c7483@w9g2000yqa.googlegroups.com> <87k57dwmay.fsf@thinkpad.tsdh.de> Message-ID: <4b5e5587-39c4-43a5-b28c-739eea8605af@d19g2000prh.googlegroups.com> On Feb 26, 1:59 am, Tassilo Horn wrote: > Xah Lee writes: > > Hi Xah, > > > is the suggestion of using modern standard shortcut set of X C V for > > Cut, Copy, Paste, of which Linux uses, means it is turning emacs to a > > fancy Notepad clone? > > The functionality stays the same, but IMO it would confuse most users. > Killing is not cutting, yanking is not pasting. The whole concepts > (kill-ring vs. simple copy&paste) are much different. emacs's killing/yaning/kill-ring is basically the same idea as copy/ cut/paste-board. Basically, emacs's pasteboard is just a extended version, such that it keeps a record of previous copied contents. To users, effectively, this means you can do paste-previous. That's all there is to it. So, it's brainless to make emacs intuitive to people and adopt modern UI standards. Basically, copy, cut, paste, is all the same, except in emacs you have also paste previous. > > Is fixing emacs's confusing undo and no redo, that is periodically > > bitched by programer in blogs, considered making emacs into a Notepad > > clone? > > It's much more advanced than the usual sequential undo, but I admit that > it can get confusing sometimes. So instead of dropping it I'd prefer to > think about a better UI for it. > > > Is the suggestion for a statistics based ergonomic keybinding design > > that are more faster to execute, easier on the fingers, and easier to > > remember, mean it is turning emacs to a fancy notepad clone? > > Users use different commands and your bindings may be better for you on > your querty keyboard, but I'm sure they're not on my German Dvorak Type > II keyboard. If your are on a special keyboard, you are on your own. The ergonomic keybinding ? Ergoemacs Keybindings http://xahlee.org/emacs/ergonomic_emacs_keybinding.html plays well with modern UI in Windows, Mac, Linux. It improves emacs keybinding, but also support standard shortcut sets. In no way, it loses any emacs advantage, while, it makes emacs compatible and intuitive for vast majority of computer users, and improve efficiency for those heavy touch typists and programers who are into the concept of not leaving hands off the keyboard. > > is the suggestion of getting rid of *scratch* buffer, and introduce a > > command ?New? with shortcut Ctrl+n, that creates new buffer anytime > > anywhere, which lets user create multiple scratch buffers defaulting > > to any mode and compatible for the rest of Linux's shortcuts, means it > > is a fancy Microsoft Notepad? > > Such a easy key like C-n is much too valuable for such a rarely used > command. C-x b foobar RET is ok, isn't it? This issues is discussed before in some hundred or 2 hundred thread in 2008. the proposal in detail is here: ? Suggestions on Emacs's Scratch Buffer http://xahlee.org/emacs/modernization_scratch_buffer.html In no way it sacrifices emacs operational efficiency. The proposal is careful thought out, so that in not only doesn't sacrifice emacs operational efficient in any possible way, but improve it, yet meanwhile makes it compatible with modern UI and intuitive to the masses. As for the Ctrl+n for New, it must be used in conjunction with the ergonomic keybinding set mentioned above. In the end, users can intuitive press Ctrl+n for creating a new file, one or multiple of it, can be used as elisp *scratch*, and can be set to default to any major mode, and can be saved by simply pressing Ctrl +s, and it will ask if user wants to save instead of like emacs *scratch* it risk losing data. > > is the suggestion of changing notation from C- and M- to Ctrl+ and Alt > > +, such that it reflects the lable on the keyboard, and Richard > > Stallman agrees may be a good idea, means it's Notepad? > > Nope, but I'm not sure if it's possible for emacs to get the right key. > Here, M is Alt, but Ctrl is indeed on the CapsLock key... > > And it makes key sequences much longer to write with little or no > benefit. What the fuck r u talking about?? Really, what the fuck are you talking about? Give concrete, specific point please. As for the CapsLock for Control, it's a industry myth. For detail, see: ? Why You Should Not Swap Caps Lock With Control http://xahlee.org/emacs/swap_CapsLock_Ctrl.html > > is the suggestion of supporting html mail, and interface to gmail out > > of the box, means it's becoming Microsoft Notepad? > > Definitively not. AFAIK Gnus can handle gmail accounts quite well. Quite well my ass. Thank you for your feedback. I think it would be nice if you do some research on each particular issue. I can't spend my time to write detailed things to teach every poster. And i often have to repeat multiple times of the same issue. For example of a research, suppose you find my claim about Ctrl and Caps Lock switch incredible. Then, you can do research on this subject. Spending 1 hour on it, or days. You can go to library to research ergonomics, or ask professors, or try to hire experts for opinion, or set out experiments and test out hypothesis etc. For example, you can write a program to statistically log your keystroke, timing, etc. You can also set out key sequences set, A, and B, and type them for one hour each, to see which is causing your hand pain, etc. The above is just beginner suggestions, on one particular example of contention. On each and every issue, you can start a research. Btw, you are prob a typical tech geekers, where you don't understand nothing about research or social sciences. One short concrete advice i can give about your situation when researching, is not based on your views on slashdot, or the tech geeking blogs, or ?my emacs buddies did this or that? type of thinking. Another concrete advices is that whatever you did for the research, must cost you. If it came easily without much cost, chances are, it's bullshit in your head. What dose cost mean? Ok, it means your time, for example. Are you, willing, to put aside say 10 hours of your time, on a issue mentioned here? Alternatively, say, are you willing, to spend $100 USD for research on particular issue we are debating here? For example, the money can be used to pay professional services that does research for you. It's probably peanuts and most such research services won't take. But it's a start on thinking. You can spend it on someone who are known expert for example. As a quick example, say you disbelieve one of my claim about ergonomics, then you can spend the $100 USD to say ask some known ergonomics expert to dinner or buy him beer, and ask about his opinion. I typed the above as fast as i can, just to give you some ideas. There are too many issues, aspects, technical, social, concrete, philosophical, that i can cover, and have written a lot in the past years. I can't repeat them all here, and frankly i discussed only a small part. But i hope you have some basic ideas about the issue. Love & knowledge, Xah ? http://xahlee.org/ ? --------------------------- On Feb 26, 3:23 am, Tassilo Horn wrote: > Klaus Straubinger writes: > > Hi Klaus, > > >> Reading HTML mail works nice, too (with emacs-w3m as helper). A > >> simple editor would be nice for some people, too. But I guess that > >> most current devs arent interested in writing one, cause in "the tech > >> geekers" world mail is in text/plain. > > > In Emacs, there is Enriched Mode if you want formatted text. The info > > file says > > > | "Enriched mode" is a minor mode for editing files that contain > > | formatted text in WYSIWYG fashion, as in a word processor. Currently, > > | formatted text in Enriched mode can specify fonts, colors, underlining, > > | margins, and types of filling and justification. In the future, we plan > > | to implement other formatting features as well. > > | > > | Enriched mode is a minor mode. It is typically used in conjunction > > | with Text mode, but you can also use it with other major modes such > > | as Outline mode and Paragraph-Indent Text mode. > > | > > | Potentially, Emacs can store formatted text files in various file > > | formats. Currently, only one format is implemented: "text/enriched" > > | format, which is defined by the MIME protocol. > > > One could write a converter to HTML if another format is desired. > > Yes, nice. I guess that would be possible without too much effort. So > Xah, why not do it yourself? Me? I started a project in Jan, called emacs2010. Here: http://code.google.com/p/emacs2010/ You see, one of the things tech geekers do, is to throw piss around. So, instead of telling me something and something and something, for a change, why don't you join my project and contribute code, for the good of humanity? It's GPL, btw. With your approval, i'll add you as a member. Xah ? http://xahlee.org/ ? From steve at holdenweb.com Thu Feb 26 19:29:56 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 26 Feb 2009 19:29:56 -0500 Subject: Delete all items in the list In-Reply-To: References: Message-ID: Peter Billam wrote: > On 2009-02-26, Clarendon wrote: >> Hi. This must be a simple command but I just can't find it in the >> Phthon manual. How do I delete all items with a certain condition from >> a list? For instance: > L=['a', 'b', 'c', 'a'] >> I want to delete all 'a's from the list. > But if L.remove('a') >> only deletes the first 'a'. How do you delete all 'a's? > > L2 = list(set(L)) > > works for me... I have to wonder for what value of "works" this works. The simplest problem is it doesn't remove all the "a"s. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From lilhedges69 at yahoo.com Thu Feb 26 19:32:40 2009 From: lilhedges69 at yahoo.com (Brett Hedges) Date: Thu, 26 Feb 2009 16:32:40 -0800 (PST) Subject: Using xreadlines Message-ID: <910645.78379.qm@web30707.mail.mud.yahoo.com> Hi, I am using both xreadlines and files iterators for a script that I need to finish. I am iterating over the entire file but stopping to use xreadlines to grab certain lines as strings to process them. My question is how do I go to a previous line in the file? xreadlines has a file.next() statement that gives the next line, and I need a statement that gives me the previous line. My script has a loop that looks for a certain word then breaks the loop. But I need to go to the previous line before I break since the script uses that line (which gets processed). I'm sure there is an easier way to do this but since I am new to python and have spent a lot of time on this script I can't really go back and change a lot of things unless there is no possible way. Something like the example below. f.open("text.txt",'r') files = f.xreadlines() Name = "Section 1" for line in f: if Name in line: while x<20 field = files.next() if "2.6" in field: *****files.previousline()***** break x=x+1 Thanks, Brett From gagsl-py2 at yahoo.com.ar Thu Feb 26 19:37:06 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 26 Feb 2009 22:37:06 -0200 Subject: Delete all items in the list References: <50697b2c0902261618j56905e0as1c3c2a1cf00eb995@mail.gmail.com> Message-ID: En Thu, 26 Feb 2009 22:18:18 -0200, Chris Rebert escribi?: > On Thu, Feb 26, 2009 at 4:08 PM, Peter Billam > wrote: >> On 2009-02-26, Clarendon wrote: >>> Hi. This must be a simple command but I just can't find it in the >>> Phthon manual. How do I delete all items with a certain condition from >>> a list? For instance: > L=['a', 'b', 'c', 'a'] >>> I want to delete all 'a's from the list. ?> But if L.remove('a') >>> only deletes the first 'a'. ?How do you delete all 'a's? >> >> L2 = list(set(L)) >> >> works for me... > > A. That doesn't by itself remove all the 'a's, although it does remove > all but 1 'a' > B. That also removes all but one instance of *everything* in the list, > not just 'a' > C. That is lossy in that it completely loses the ordering of the > original list I said the very same things! There are other issues too, like this only works with hashable objects, but I've chosen exactly the same remarks and exactly in the same order! What a coincidence... -- Gabriel Genellina From steve at holdenweb.com Thu Feb 26 19:37:49 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 26 Feb 2009 19:37:49 -0500 Subject: Can someone explain this behavior to me? In-Reply-To: References: Message-ID: Jesse Aldridge wrote: > I have one module called foo.py > --------------------- > class Foo: > foo = None > > def get_foo(): > return Foo.foo > > if __name__ == "__main__": > import bar > Foo.foo = "foo" > bar.go() > --------------------- > And another one called bar.py > --------------------- > import foo > > def go(): > assert foo.get_foo() == "foo" > ---------------------- > When I run foo.py, the assertion in bar.py fails. Why? There are actually two get_foo()s, since foo.py is run (giving it the name "__main__") and imported (giving it the name "foo"). You will probably find that __main__.get_foo() == "foo". regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From clp2 at rebertia.com Thu Feb 26 19:39:50 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 26 Feb 2009 16:39:50 -0800 Subject: Delete all items in the list In-Reply-To: References: <50697b2c0902261618j56905e0as1c3c2a1cf00eb995@mail.gmail.com> Message-ID: <50697b2c0902261639w42574390jab7191bf1ca8ccc8@mail.gmail.com> On Thu, Feb 26, 2009 at 4:37 PM, Gabriel Genellina wrote: > En Thu, 26 Feb 2009 22:18:18 -0200, Chris Rebert > escribi?: >> >> On Thu, Feb 26, 2009 at 4:08 PM, Peter Billam >> wrote: >>> >>> On 2009-02-26, Clarendon wrote: >>>> >>>> Hi. This must be a simple command but I just can't find it in the >>>> Phthon manual. How do I delete all items with a certain condition from >>>> a list? For instance: > L=['a', 'b', 'c', 'a'] >>>> I want to delete all 'a's from the list. ?> But if L.remove('a') >>>> only deletes the first 'a'. ?How do you delete all 'a's? >>> >>> L2 = list(set(L)) >>> >>> works for me... >> >> A. That doesn't by itself remove all the 'a's, although it does remove >> all but 1 'a' >> B. That also removes all but one instance of *everything* in the list, >> not just 'a' >> C. That is lossy in that it completely loses the ordering of the original >> list > > I said the very same things! > There are other issues too, like this only works with hashable objects, but > I've chosen exactly the same remarks and exactly in the same order! What a > coincidence... Indeed, USENET and mail<->news lags doth create interesting situations sometimes. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From steve at holdenweb.com Thu Feb 26 19:40:11 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 26 Feb 2009 19:40:11 -0500 Subject: PythonWin -vs- Idle In-Reply-To: <50697b2c0902261440ja1db6a0i3512527eb835d9b@mail.gmail.com> References: <50697b2c0902261440ja1db6a0i3512527eb835d9b@mail.gmail.com> Message-ID: Chris Rebert wrote: > On Thu, Feb 26, 2009 at 2:23 PM, Gary Schells wrote: >> Hello, >> Python newbie here. I am working with Python and geoprocessing in ArcGIS. >> I'm taking a training course online and the exercise I'm working on makes >> mention of using PythonWin instead of Idle. >> >> I am using version 2.5 and have not been able to locate PythonWin. The >> download just includes Idle for the environment. Can anyone point me in the >> right direction to download the PythonWin piece of this puzzle? > > Seems to be included in http://sourceforge.net/projects/pywin32/ > And it's well worth getting, since it's the recommended programming environment for ArcGIS. IIRC it uses the COM server capabilities to achieve some of the required magic. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From clp2 at rebertia.com Thu Feb 26 19:46:22 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 26 Feb 2009 16:46:22 -0800 Subject: Using xreadlines In-Reply-To: <910645.78379.qm@web30707.mail.mud.yahoo.com> References: <910645.78379.qm@web30707.mail.mud.yahoo.com> Message-ID: <50697b2c0902261646q3192cad3j1cdab7084a177e2f@mail.gmail.com> On Thu, Feb 26, 2009 at 4:32 PM, Brett Hedges wrote: > > Hi, > > I am using both xreadlines and files iterators for a script that I need to finish. I am iterating over the entire file but stopping to use xreadlines to grab certain lines as strings to process them. > > My question is how do I go to a previous line in the file? xreadlines has a file.next() statement that gives the next line, and I need a statement that gives me the previous line. > > My script has a loop that looks for a certain word then breaks the loop. But I need to go to the previous line before I break since the script uses that line (which gets processed). I'm sure there is an easier way to do this but since I am new to python and have spent a lot of time on this script I can't really go back and change a lot of things unless there is no possible way. Something like the example below. > > f.open("text.txt",'r') > files = f.xreadlines() > Name = "Section 1" > > prev_line = None > for line in f: > if Name in line: > while x<20 > field = files.next() > if "2.6" in field: use(prev_line) > *****files.previousline()***** > break prev_line = line > x=x+1 Also, you could probably make the loop prettier by using enumerate() or range() to track `x`. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From bearophileHUGS at lycos.com Thu Feb 26 20:09:22 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Thu, 26 Feb 2009 17:09:22 -0800 (PST) Subject: Using xreadlines References: Message-ID: <82c7db91-fb61-491e-9ff5-38761c3424e9@g38g2000yqd.googlegroups.com> Brett Hedges: > My question is how do I go to a previous line in the file? xreadlines has a file.next() statement that gives the next line, and I need a statement that gives me the previous line.< In modern versions of Python you usually don't need xreadlines, because files are iterable. If your files are small, you can just read all the lines in a list with open(...).readlines(), and then just use the item of the list with the n-1 index. If the file is quite large or you like to keep things lazy, then you have to keep memory of the previous line, using an auxiliary variable. You can also wrap this idiom into a generator function (or iterable class, probably) that yields items and keeps memory of the last one (but you can't ask the previous of the first item, of course). You can also keep track of the absolute position of the lines in the file, etc, or step back looking for newlines, etc, but it's not handy. Bye, bearophile From cto at openmigration.net Thu Feb 26 20:57:43 2009 From: cto at openmigration.net (geremy condra) Date: Thu, 26 Feb 2009 20:57:43 -0500 Subject: code challenge: generate minimal expressions using only digits 1,2,3 In-Reply-To: <941be713-2789-48c7-911b-422313f232d5@o36g2000yqh.googlegroups.com> References: <941be713-2789-48c7-911b-422313f232d5@o36g2000yqh.googlegroups.com> Message-ID: Use 1 and 2 and treat them as equivalent to boolean true and false. -------------- next part -------------- An HTML attachment was scrubbed... URL: From astan.chee at al.com.au Thu Feb 26 21:06:47 2009 From: astan.chee at al.com.au (Astan Chee) Date: Fri, 27 Feb 2009 13:06:47 +1100 Subject: factoring wx.Image Message-ID: <49A74AB7.8010808@al.com.au> Hi, I want to factor (red, green and blue at the same time) an image using wx but without any GUI display or windows but it keeps crashing and if I set the checks to ignore it, it doesn't produce the images at all. It looks like this: import wx img = wx.Image("star.jpg",wx.BITMAP_TYPE_BMP) factor = 1 for i in range(1,30): image = img.AdjustChannels(factor, factor, factor, 1) fname = "star." + str(factor) + ".jpg" img.SaveFile(fname,wx.BITMAP_TYPE_JPEG) factor+=1 What am I missing here? What am I doing wrong? Can this even be done with only wx? Thanks for any help. Cheers Astan From mail at anjanesh.net Thu Feb 26 22:11:18 2009 From: mail at anjanesh.net (Anjanesh Lekshminarayanan) Date: Fri, 27 Feb 2009 08:41:18 +0530 Subject: Multiple conditional expression Message-ID: <1a7951080902261911h62798085uf3c4336f2aa631a0@mail.gmail.com> How do I achieve something like this using python ? spaces = (form.has_key('spaces') ? form.getvalue('spaces') == 1 ? True : False : False) spaces = True if form.getvalue('spaces') == 1 if form.has_key('spaces') else False else False -- Anjanesh Lekshmnarayanan From steve at holdenweb.com Thu Feb 26 22:14:50 2009 From: steve at holdenweb.com (Steve Holden) Date: Thu, 26 Feb 2009 22:14:50 -0500 Subject: Multiple conditional expression In-Reply-To: <1a7951080902261911h62798085uf3c4336f2aa631a0@mail.gmail.com> References: <1a7951080902261911h62798085uf3c4336f2aa631a0@mail.gmail.com> Message-ID: Anjanesh Lekshminarayanan wrote: > How do I achieve something like this using python ? > spaces = (form.has_key('spaces') ? form.getvalue('spaces') == 1 ? True > : False : False) > > spaces = True if form.getvalue('spaces') == 1 if > form.has_key('spaces') else False else False If you've got any sense at all, you don't. Write the logic so it makes some sense to the casual reader. You will be that casual reader in a few months. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From clp2 at rebertia.com Thu Feb 26 22:17:20 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 26 Feb 2009 19:17:20 -0800 Subject: Multiple conditional expression In-Reply-To: <1a7951080902261911h62798085uf3c4336f2aa631a0@mail.gmail.com> References: <1a7951080902261911h62798085uf3c4336f2aa631a0@mail.gmail.com> Message-ID: <50697b2c0902261917n14b2aa2dxdb173c2d8ddbe895@mail.gmail.com> On Thu, Feb 26, 2009 at 7:11 PM, Anjanesh Lekshminarayanan wrote: > How do I achieve something like this using python ? > spaces = (form.has_key('spaces') ? form.getvalue('spaces') == 1 ? True > : False : False) > > spaces = True if form.getvalue('spaces') == 1 if > form.has_key('spaces') else False else False That seems to just be an overly complicated way of writing: spaces = bool(form.has_key('spaces') and form.getvalue('spaces') == 1) Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From grante at visi.com Thu Feb 26 22:26:09 2009 From: grante at visi.com (Grant Edwards) Date: Thu, 26 Feb 2009 21:26:09 -0600 Subject: Multiple conditional expression References: Message-ID: On 2009-02-27, Anjanesh Lekshminarayanan wrote: > How do I achieve something like this using python ? > spaces = (form.has_key('spaces') ? form.getvalue('spaces') == 1 ? True : False : False) if form.has_key('spaces'): spaces = form.getvalue('spaces') == 1 else: spaces = False However, my code is not acheiving entirely the same thing as your example code. The object 'spaces' ends up with the same value, but my code fails to acheive the other presumed objective: confusing the reader. -- Grant From http Thu Feb 26 22:34:29 2009 From: http (Paul Rubin) Date: 26 Feb 2009 19:34:29 -0800 Subject: Multiple conditional expression References: <1a7951080902261911h62798085uf3c4336f2aa631a0@mail.gmail.com> Message-ID: <7xhc2gv9h6.fsf@ruckus.brouhaha.com> Chris Rebert writes: > spaces = bool(form.has_key('spaces') and form.getvalue('spaces') == 1) spaces = form.has_key('spaces') and form.getvalue('spaces') == 1 or even (this is about the cgi module, I think) spaces = form.getvalue('spaces', None) == 1 But the == 1 comparison will always fail, since getvalue returns a string. From mail at anjanesh.net Thu Feb 26 22:51:30 2009 From: mail at anjanesh.net (Anjanesh Lekshminarayanan) Date: Fri, 27 Feb 2009 09:21:30 +0530 Subject: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to In-Reply-To: References: <1a7951080901290824p424caee3jb74b1343ce884916@mail.gmail.com> <1a7951080901290909x4590d3c6m5d7d9c2185511ca6@mail.gmail.com> Message-ID: <1a7951080902261951j1fd72f38hf3a9af92ea9bc3bc@mail.gmail.com> > (1) what is produced on Anjanesh's machine >>> sys.getdefaultencoding() 'utf-8' > (2) it looks like a small snippet from a Python source file! Its a file containing just JSON data - but has some unicode characters as well as it has data from the web. > Anjanesh, Is it a .py file Its a .json file. I have a bunch of these json files which Im parsing. using json library. > Instead of "something like", please report exactly what is there: > > print(ascii(open('the_file', 'rb').read()[10442-20:10442+21])) >>> print(ascii(open('the_file', 'rb').read()[10442-20:10442+21])) b'":42,"query":"0 1\xc2\xbb\xc3\x9d \\u2021 0\\u201a0 \\u2' > Trouble with cases like this is as soon as they become interesting, the OP often snatches somebody's one-liner that "works" (i.e. doesn't raise an exception), makes a quick break for the county line, and they're not seen again :-) Actually, I moved the files to my Ubuntu PC which has Python 2.5.2 and didnt give the encoding issue. I just couldnt spend that much time on why a couple of these files had encoding issues in Py3 since I had to parse a whole lot of files. From wuwei23 at gmail.com Thu Feb 26 23:16:55 2009 From: wuwei23 at gmail.com (alex23) Date: Thu, 26 Feb 2009 20:16:55 -0800 (PST) Subject: PythonWin -vs- Idle References: Message-ID: On Feb 27, 8:40?am, Chris Rebert wrote: > On Thu, Feb 26, 2009 at 2:23 PM, Gary Schells wrote: > > I am using version 2.5 and have not been able to locate PythonWin.? The > > download just includes Idle for the environment.? Can anyone point me in the > > right direction to download the PythonWin piece of this puzzle? > > Seems to be included in http://sourceforge.net/projects/pywin32/ It's also bundled with ActiveState's ActivePython: http://www.activestate.com/activepython/ From JesseAldridge at gmail.com Thu Feb 26 23:30:38 2009 From: JesseAldridge at gmail.com (Jesse Aldridge) Date: Thu, 26 Feb 2009 20:30:38 -0800 (PST) Subject: Can someone explain this behavior to me? References: Message-ID: Ah, I get it. Thanks for clearing that up, guys. From grante at visi.com Thu Feb 26 23:33:24 2009 From: grante at visi.com (Grant Edwards) Date: Thu, 26 Feb 2009 22:33:24 -0600 Subject: Multiple conditional expression References: <1a7951080902261911h62798085uf3c4336f2aa631a0@mail.gmail.com> <7xhc2gv9h6.fsf@ruckus.brouhaha.com> Message-ID: On 2009-02-27, Paul Rubin wrote: > But the == 1 comparison will always fail, since getvalue returns a string. How do we know that from the what the OP posted? -- Grant From mail at anjanesh.net Thu Feb 26 23:39:39 2009 From: mail at anjanesh.net (Anjanesh Lekshminarayanan) Date: Fri, 27 Feb 2009 10:09:39 +0530 Subject: Multiple conditional expression In-Reply-To: References: <1a7951080902261911h62798085uf3c4336f2aa631a0@mail.gmail.com> <7xhc2gv9h6.fsf@ruckus.brouhaha.com> Message-ID: <1a7951080902262039l14c296f0m72a51281f1ad7626@mail.gmail.com> > How do we know that from the what the OP posted? Its CGI alright. spaces = form.has_key('spaces') and form.getvalue('spaces') == '1' But I just dont see how spaces = (form.has_key('spaces') ? form.getvalue('spaces') == 1 ? True: False : False) is complicated in anyway. Its not that hard to read at all. Thanks. From dg.gmane at thesamovar.net Thu Feb 26 23:49:08 2009 From: dg.gmane at thesamovar.net (Dan Goodman) Date: Fri, 27 Feb 2009 05:49:08 +0100 Subject: code challenge: generate minimal expressions using only digits 1,2,3 In-Reply-To: <49A72FBF.8080206@mrabarnett.plus.com> References: <941be713-2789-48c7-911b-422313f232d5@o36g2000yqh.googlegroups.com> <49A72FBF.8080206@mrabarnett.plus.com> Message-ID: MRAB wrote: > Here's my solution (I haven't bothered with making it efficient, BTW): > > import operator > > def solve(n): > best_len = n > best_expr = "" > for x in range(1, n - 2): > for y in range(x, n): > for op, name in operator_list: > # Does this pair with this op give the right answer? > if op(x, y) == n: > lx, ex = numbers[x - 1] > ly, ey = numbers[y - 1] > # How many digits in total? > l = lx + ly > # Fewer digits than any previous attempts? > if l < best_len: > # Build the expression. > e = "(%s %s %s)" % (ex, name, ey) > best_len, best_expr = l, e > return best_len, best_expr > > operator_list = [(operator.add, "+"), (operator.sub, "-"), > (operator.mul, "*"), (operator.div, "/"), (operator.pow, "^")] > > # Tuples contain number of digits used and expression. > numbers = [(1, str(n)) for n in range(1, 4)] > > for n in range(4, 34): > numbers.append(solve(n)) > > for i, (l, e) in enumerate(numbers): > print "%2d = %s" % (i + 1, e) Sadly this doesn't work because you're assuming that the shortest expression always involves increasing the size of the numbers at every step. For example, your algorithm for 63 gives: (3 * (3 * (1 + (2 * 3)))) which involves 4 operations, whereas the simplest is: 2**(2*3)-1 which only involves 3 (but has an intermediate value 2**6=64 above the target value). Fixing this is actually pretty hard, because the search space becomes very large if you allow yourself arbitrarily large numbers. You can't do any obvious pruning that I can think of, because operations between very large numbers can end up very small (for example, 13**3-3**7=10 even though 13**3=2197 and 3**7=2187 are both very large), and the shortest path to a small number might go through very large numbers (I bet with a bit more thought than I have put into it, you could come up with some examples where the intermediate calculations are arbitrarily larger than the end result). As well as the growth of the search space, the computations get hairy too, try computing 3**3**3**3 for example (or better, don't, because it has 3638334640025 digits). I haven't got a solution that can be guaranteed correct and is feasible to compute for anything but very small examples - anyone done better? Dan From benjamin at python.org Thu Feb 26 23:49:54 2009 From: benjamin at python.org (Benjamin Peterson) Date: Fri, 27 Feb 2009 04:49:54 +0000 (UTC) Subject: removing duplication from a huge list. References: <269329b40902261237j2815c8a2x80d7469abba1e1e6@mail.gmail.com> Message-ID: Shanmuga Rajan gmail.com> writes: > f any one suggests better solution then i will be very happy.Advance thanks for any help.Shan Use a set. From python at rcn.com Thu Feb 26 23:54:40 2009 From: python at rcn.com (Raymond Hettinger) Date: Thu, 26 Feb 2009 20:54:40 -0800 (PST) Subject: Proposed implementation for an Ordered Dictionary References: <5c65efb2-0862-4b85-bb37-88687ac6fedd@q9g2000yqc.googlegroups.com> <871vtk7ub8.fsf@mulj.homelinux.net> <7xd4d4hjaq.fsf@ruckus.brouhaha.com> <6d818c3d-1d6d-4720-8775-427b3832c590@u18g2000pro.googlegroups.com> <7x63iwg2wg.fsf@ruckus.brouhaha.com> Message-ID: <6f52f838-d435-40b8-865e-55f3aed1bb1e@w24g2000prd.googlegroups.com> [Paul Rubin] > Ehh, I guess I'm not surprised at the slowdown and extra complexity > from the second dict. ?Oh well. ?If the module really turns out to be > really used a lot, another (messy) approach would be to write a C > extension that uses a doubly linked list some day. That seems like an ideal implementation to me. O(1): appending, popping, searching, and deletion O(n): traversal Raymond From clp2 at rebertia.com Fri Feb 27 00:11:28 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 26 Feb 2009 21:11:28 -0800 Subject: Multiple conditional expression In-Reply-To: <1a7951080902262039l14c296f0m72a51281f1ad7626@mail.gmail.com> References: <1a7951080902261911h62798085uf3c4336f2aa631a0@mail.gmail.com> <7xhc2gv9h6.fsf@ruckus.brouhaha.com> <1a7951080902262039l14c296f0m72a51281f1ad7626@mail.gmail.com> Message-ID: <50697b2c0902262111o4f566fd8r6d4a13f1fcd6c632@mail.gmail.com> On Thu, Feb 26, 2009 at 8:39 PM, Anjanesh Lekshminarayanan wrote: >> How do we know that from the what the OP posted? > Its CGI alright. > spaces = form.has_key('spaces') and form.getvalue('spaces') == '1' > > But I just dont see how > spaces = (form.has_key('spaces') ? form.getvalue('spaces') == 1 ? > True: False : False) > is complicated in anyway. Its not that hard to read at all. You have /nested/ /ternary/ expressions /without/ any disambiguating parentheses. And you unnecessarily use boolean constants. The latter and the stuff in italics is what makes your code hard to understand. As I showed, you can write the *exact same thing* without using ternary expressions at all (win!), much less nested ones, and without any boolean constants. And it's even 16 characters shorter. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From clp2 at rebertia.com Fri Feb 27 00:15:39 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 26 Feb 2009 21:15:39 -0800 Subject: removing duplication from a huge list. In-Reply-To: References: <269329b40902261237j2815c8a2x80d7469abba1e1e6@mail.gmail.com> Message-ID: <50697b2c0902262115x37b098b2s908710fbc79529ec@mail.gmail.com> On Thu, Feb 26, 2009 at 8:49 PM, Benjamin Peterson wrote: > Shanmuga Rajan gmail.com> writes: > >> f any one suggests better solution then i will be very happy.Advance thanks > for any help.Shan > > Use a set. To expand on that a bit: counted_recs = set(rec[0] for rec in some_fun()) #or in Python 3.0: counted_recs = {rec[0] for rec in some_fun()} Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From venutaurus539 at gmail.com Fri Feb 27 00:16:42 2009 From: venutaurus539 at gmail.com (venutaurus539 at gmail.com) Date: Thu, 26 Feb 2009 21:16:42 -0800 (PST) Subject: Run a python script as an exe and run a new process from it References: Message-ID: On Feb 26, 11:14?pm, "Paddy O'Loughlin" wrote: > Try this as an outline: > #### script1.py > from subprocess import Popen > > if __name__ == '__main__': > ? ? ? ? scriptname = "script2.py" > > ? ? ? ? Popen("python %s" % scriptname, shell=True) > > ? ? ? ? print "I'm done" > > #### script2.py > from time import sleep > > if __name__ == '__main__': > ? ? while (True): > ? ? ? ? print "waiting.." > ? ? ? ? sleep(2) > > ########################### > If you install python using the Windows Installer (.exe), it should > set up .py files to be opened by python when double-clicking on them. > Alternatively, you can right-click on your .py file and go to "Open > With..." then "choose program", then click "Browse...", you can Browse > to the python executable, so Explorer will use it to open .py files > when you double-click on them. > > As someone else mentioned there is also a py2exe program. Google it. > > 2009/2/26 venutaurus... at gmail.com : > > > > > Hello all, > > ? ? ? ? ? I've a strange requirement where I need to run a python > > script just as we run an exe (by double clicking through windows > > explorer or by typing the script name at command prompt). In that > > process I should be able to execute another python script in such a > > way that, the second script should continue running but the main one > > should terminate without effecting the second one. > > > ? ? ? ? ? ? ? ? ? ?My requirement may be little confusing so please > > get back if you didn't understand what I meant above. > > > Thank you, > > Venu. > > -- > >http://mail.python.org/mailman/listinfo/python-list > > -- > "Ray, when someone asks you if you're a god, you say YES!" Thanks for the reply,, I am trying to use the above application using psexec()in command line.But it failed returning the error message exited with error code 255. But when I ran the application normally it worked fine.Do I need to add anything to my python script(either the main one or the script which is calling it) to make it work. Thank you, Venu Madhav. From tarundevnani at gmail.com Fri Feb 27 00:47:44 2009 From: tarundevnani at gmail.com (tarun) Date: Fri, 27 Feb 2009 11:17:44 +0530 Subject: Killing Child Process Message-ID: Hello Group, I've spwaned a process using os.spwanl. As part of this process, I spwan one more process, using subprocess.Popen. After I close the the process spwaned using os.spwanl, the child process started by it using subprocess.Popen, doesn't get closed. Is there any way to do this in python 2.5.1? Thanks, Tarun -------------- next part -------------- An HTML attachment was scrubbed... URL: From odeits at gmail.com Fri Feb 27 01:17:58 2009 From: odeits at gmail.com (odeits) Date: Thu, 26 Feb 2009 22:17:58 -0800 (PST) Subject: removing duplication from a huge list. References: <269329b40902261237j2815c8a2x80d7469abba1e1e6@mail.gmail.com> Message-ID: On Feb 26, 9:15?pm, Chris Rebert wrote: > On Thu, Feb 26, 2009 at 8:49 PM, Benjamin Peterson wrote: > > Shanmuga Rajan gmail.com> writes: > > >> f any one suggests better solution then i will be very happy.Advance thanks > > for any help.Shan > > > Use a set. > > To expand on that a bit: > > counted_recs = set(rec[0] for rec in some_fun()) > #or in Python 3.0: > counted_recs = {rec[0] for rec in some_fun()} > > Cheers, > Chris > > -- > Follow the path of the Iguana...http://rebertia.com How big of a list are we talking about? If the list is so big that the entire list cannot fit in memory at the same time this approach wont work e.g. removing duplicate lines from a very large file. A couple of things come into play at that point. If order does not matter then I would suggest looking at some recipes for first sorting the large file and then iterating through the lines removing duplicates as you go ( if cur_line != last_line: write cur_line; last_line = cur_line ) If order does matter then let me know and I will post a recipe for that. From niklas.norrthon at hotmail.com Fri Feb 27 01:23:10 2009 From: niklas.norrthon at hotmail.com (Niklas Norrthon) Date: Thu, 26 Feb 2009 22:23:10 -0800 (PST) Subject: PythonWin -vs- Idle References: <50697b2c0902261440ja1db6a0i3512527eb835d9b@mail.gmail.com> Message-ID: <6eb932a4-74d3-4925-9c78-6cc8ae957e02@a39g2000yqc.googlegroups.com> On 27 Feb, 01:40, Steve Holden wrote: > Chris Rebert wrote: > > On Thu, Feb 26, 2009 at 2:23 PM, Gary Schells wrote: > >> Hello, > >> Python newbie here. ?I am working with Python and geoprocessing in ArcGIS. > >> I'm taking a training course online and the exercise I'm working on makes > >> mention of using PythonWin instead of Idle. > > >> I am using version 2.5 and have not been able to locate PythonWin. ?The > >> download just includes Idle for the environment. ?Can anyone point me in the > >> right direction to download the PythonWin piece of this puzzle? > > > Seems to be included inhttp://sourceforge.net/projects/pywin32/ > > And it's well worth getting, since it's the recommended programming > environment for ArcGIS. IIRC it uses the COM server capabilities to > achieve some of the required magic. It's the recommended programming environment in ESRI's geoprocessing classes. The only stuff that is specific to PythonWin is the debugging, (which you can do in IDLE too, just in a slightly different way). Personally I do most of my python hacking in emacs, both when my code calls arcgisscripting and otherwise. Sometimes I use IDLE, since in emacs (and PythonWin) I miss the ability to restart the interpreter process to get a clean environment. There is one thing I use the pywin32 library for, and that is a little hack to get around the issue that each version of ArcGIS is bound to a specific python version: try: import arcgisscripting except ImportError: import win32com.client class arcgisscripting(object): @staticmethod def create(): return win32com.client.Dispatch ('esriGeoprocessing.GpDispatch.1') With this little code snippet in a utility module, I can use python 2.6 with ArcGIS, and I can test my scritps with python 2.4, to ensure that they run in ArcGIS 9.2 environments. /Niklas Norrthon From odeits at gmail.com Fri Feb 27 01:26:18 2009 From: odeits at gmail.com (odeits) Date: Thu, 26 Feb 2009 22:26:18 -0800 (PST) Subject: Delete all items in the list References: Message-ID: <35df0b67-3403-444b-93ba-c516bf67d110@p2g2000prf.googlegroups.com> On Feb 26, 3:05?am, Clarendon wrote: > Hi. This must be a simple command but I just can't find it in the > Phthon manual. How do I delete all items with a certain condition from > a list? For instance: > > L=['a', 'b', 'c', 'a'] > > I want to delete all 'a's from the list. > But if L.remove('a') only deletes the first 'a'. > > How do you delete all 'a's? > I would really appreciate your help. > > Thanks. while 'a' in L: L.remove('a') not the most efficient but it works From clp2 at rebertia.com Fri Feb 27 01:59:54 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 26 Feb 2009 22:59:54 -0800 Subject: Delete all items in the list In-Reply-To: <35df0b67-3403-444b-93ba-c516bf67d110@p2g2000prf.googlegroups.com> References: <35df0b67-3403-444b-93ba-c516bf67d110@p2g2000prf.googlegroups.com> Message-ID: <50697b2c0902262259t4820cdffj643531e2bbe8cb0d@mail.gmail.com> On Thu, Feb 26, 2009 at 10:26 PM, odeits wrote: > On Feb 26, 3:05?am, Clarendon wrote: >> Hi. This must be a simple command but I just can't find it in the >> Phthon manual. How do I delete all items with a certain condition from >> a list? For instance: >> >> L=['a', 'b', 'c', 'a'] >> >> I want to delete all 'a's from the list. >> But if L.remove('a') only deletes the first 'a'. >> >> How do you delete all 'a's? >> I would really appreciate your help. >> >> Thanks. > > while 'a' in L: > ? L.remove('a') > > not the most efficient but it works "Not the most efficient"; it's terribly inefficient! It's 2*O(M*N) [M = number of 'a's in L], versus just N. And that's not even accounting for all the extra element movement done by .remove() Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From hv at tbz-pariv.de Fri Feb 27 03:20:17 2009 From: hv at tbz-pariv.de (Thomas Guettler) Date: Fri, 27 Feb 2009 09:20:17 +0100 Subject: OT: handling multiple software repositories In-Reply-To: References: <70npmbFgb464U1@mid.individual.net> <49A6BEE7.2090605@timgolden.me.uk> Message-ID: <70pm22Fh2534U1@mid.individual.net> Luis Zarrabeitia schrieb: ... > It's quite good (and easy to install, unlike gforge), but the developers are > moving on to a version 2.0 that you can find around here: > > http://basieproject.org/ (yeah, the website is ugly). Is uses django. That's nice since I know it. But the page looks like it is not ready for public. But it looks promising. Thomas -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From bearophileHUGS at lycos.com Fri Feb 27 03:49:57 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Fri, 27 Feb 2009 00:49:57 -0800 (PST) Subject: Proposed implementation for an Ordered Dictionary References: <5c65efb2-0862-4b85-bb37-88687ac6fedd@q9g2000yqc.googlegroups.com> <871vtk7ub8.fsf@mulj.homelinux.net> <7xd4d4hjaq.fsf@ruckus.brouhaha.com> <6d818c3d-1d6d-4720-8775-427b3832c590@u18g2000pro.googlegroups.com> <7x63iwg2wg.fsf@ruckus.brouhaha.com> <6f52f838-d435-40b8-865e-55f3aed1bb1e@w24g2000prd.googlegroups.com> Message-ID: <5a96c945-7b61-4dba-af20-a324fd3b3394@z9g2000yqi.googlegroups.com> Raymond Hettinger: >Paul Rubin: >>another (messy) approach would be to write a C >>extension that uses a doubly linked list some day. > > That seems like an ideal implementation to me. This was my Python implementation, where the delete too is O(1), but it's slow: http://code.activestate.com/recipes/498195/ I think the C extension with the doubly linked list is the best approach. Note that in modern CPUs caches are able to change the performance a lot. So reducing the memory used is very important. So using the XOR (or subtraction) trick to use only 1 pointer for each key-value may be useful to keep performance not too much far from the normal python dicts: http://en.wikipedia.org/wiki/XOR_linked_list Bye, bearophile From bearophileHUGS at lycos.com Fri Feb 27 03:55:06 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Fri, 27 Feb 2009 00:55:06 -0800 (PST) Subject: Multiple conditional expression References: <1a7951080902261911h62798085uf3c4336f2aa631a0@mail.gmail.com> Message-ID: Chris Rebert: > That seems to just be an overly complicated way of writing: > > spaces = bool(form.has_key('spaces') and form.getvalue('spaces') == 1) Better: spaces = bool(('spaces' in form) and form.getvalue('spaces') == 1) Bye, bearophile From bearophileHUGS at lycos.com Fri Feb 27 03:58:39 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Fri, 27 Feb 2009 00:58:39 -0800 (PST) Subject: removing duplication from a huge list. References: <269329b40902261237j2815c8a2x80d7469abba1e1e6@mail.gmail.com> Message-ID: <516a626d-62ee-48c0-acc3-dbf044b163a4@q11g2000yqh.googlegroups.com> odeits: > How big of a list are we talking about? If the list is so big that the > entire list cannot fit in memory at the same time this approach wont > work e.g. removing duplicate lines from a very large file. If the data are lines of a file, and keeping the original order isn't important, then the first to try may be to use the unix (or cygwin on Windows) commands sort and uniq. Bye, bearophile From http Fri Feb 27 04:00:46 2009 From: http (Paul Rubin) Date: 27 Feb 2009 01:00:46 -0800 Subject: Proposed implementation for an Ordered Dictionary References: <5c65efb2-0862-4b85-bb37-88687ac6fedd@q9g2000yqc.googlegroups.com> <871vtk7ub8.fsf@mulj.homelinux.net> <7xd4d4hjaq.fsf@ruckus.brouhaha.com> <6d818c3d-1d6d-4720-8775-427b3832c590@u18g2000pro.googlegroups.com> <7x63iwg2wg.fsf@ruckus.brouhaha.com> <6f52f838-d435-40b8-865e-55f3aed1bb1e@w24g2000prd.googlegroups.com> <5a96c945-7b61-4dba-af20-a324fd3b3394@z9g2000yqi.googlegroups.com> Message-ID: <7xfxi08da9.fsf@ruckus.brouhaha.com> bearophileHUGS at lycos.com writes: > So using the XOR (or subtraction) trick to use only 1 pointer for > each key-value may be useful to keep performance not too much far > from the normal python dicts: http://en.wikipedia.org/wiki/XOR_linked_list I don't see how to delete a randomly chosen node if you use that trick, since the hash lookup doesn't give you two consecutive nodes in the linked list to xor together. Maybe you could do something intricate with skip lists and end up with O(log n) deletion. From lkassana at gmail.com Fri Feb 27 04:02:57 2009 From: lkassana at gmail.com (lameck kassana) Date: Fri, 27 Feb 2009 12:02:57 +0300 Subject: problem with glob in remote directory or os.walk in remote directory in windos In-Reply-To: <49A6A3FB.60708@holdenweb.com> References: <49A6A3FB.60708@holdenweb.com> Message-ID: now it is working but i wonder it brings higher number of count as if it counts files in wholes computer can you check in my code and correct me ------------------------------------------------ import glob import os file_count=0 for files in glob.glob(r"\\192.168.0.45\loader\Files\file_log\v20090225 *"): file_count += len(files) print 'Found', file_count, 'files in cwd' -------------------------------------------------------------------------------------------------------------------------------- the results are Found 435656 files in cwd --which is impossible since files are around six thousands daily. thanks in advance On Thu, Feb 26, 2009 at 5:15 PM, Steve Holden wrote: > lameck kassana wrote: > > ok my original question is how can count the files of ceratin pattern(eg > > *.txt) in remote directory .It seems use of glob.glob() for remote > > directory is not working .Example I want to count the files in following > > shared folder \\192.168.0.45\files how can > > do it by using glob.glob() > > > >>> glob.glob(r"\\houseboy\sholden\*.txt") > ['\\\\houseboy\\sholden\\pgin1.txt', > '\\\\houseboy\\sholden\\POSTGRES.TXT', > '\\\\houseboy\\sholden\\gatesquote.txt', > '\\\\houseboy\\sholden\\UbuntuWhatNow.txt', > '\\\\houseboy\\sholden\\patch001.txt'] > >>> glob.glob(r"\\192.168.2.200\sholden\*.txt") > ['\\\\192.168.2.200\\sholden\\pgin1.txt', > '\\\\192.168.2.200\\sholden\\POSTGRES.TXT', > '\\\\192.168.2.200\\sholden\\gatesquote.txt', > '\\\\192.168.2.200\\sholden\\UbuntuWhatNow.txt', > '\\\\192.168.2.200\\sholden\\patch001.txt'] > >>> > > Working just fine for me. > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > Holden Web LLC http://www.holdenweb.com/ > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Fri Feb 27 04:18:06 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 27 Feb 2009 10:18:06 +0100 Subject: removing duplication from a huge list. In-Reply-To: <516a626d-62ee-48c0-acc3-dbf044b163a4@q11g2000yqh.googlegroups.com> References: <269329b40902261237j2815c8a2x80d7469abba1e1e6@mail.gmail.com> <516a626d-62ee-48c0-acc3-dbf044b163a4@q11g2000yqh.googlegroups.com> Message-ID: <49a7afce$0$32663$9b4e6d93@newsspool2.arcor-online.net> bearophileHUGS at lycos.com wrote: > odeits: >> How big of a list are we talking about? If the list is so big that the >> entire list cannot fit in memory at the same time this approach wont >> work e.g. removing duplicate lines from a very large file. > > If the data are lines of a file, and keeping the original order isn't > important, then the first to try may be to use the unix (or cygwin on > Windows) commands sort and uniq. or preferably "sort -u", in case that's supported. Stefan From nytrokiss at gmail.com Fri Feb 27 04:20:20 2009 From: nytrokiss at gmail.com (James Matthews) Date: Fri, 27 Feb 2009 11:20:20 +0200 Subject: What functions, other than sleep(), can be interrupted by Ctrl-C? In-Reply-To: References: <26ddd1750902261017o7ec519ey2af03b1be2809cdb@mail.gmail.com> Message-ID: <8a6b8e350902270120j7ceb5faaxf773075a07eb289f@mail.gmail.com> You can hook the it on the main thread and just pass it. And let the threads execute. On Thu, Feb 26, 2009 at 10:47 PM, Gabriel Genellina wrote: > En Thu, 26 Feb 2009 16:17:42 -0200, Maxim Khitrov > escribi?: > > > I'm looking for a function in the standard library or pywin32 package >> that will block until a certain condition is met or it is interrupted >> by Ctrl-C. For example, time.sleep() would have been perfect for my >> needs if thread.interrupt_main() could interrupt the call from another >> thread in the same way that Ctrl-C does. Unfortunately, that is not >> the case. >> >> Another thing I tried was creating a pipe with os.pipe() and issuing a >> read call on it. The event to exit was a single byte written to the >> other end of the pipe, but Ctrl-C could not interrupt the read call. >> The threading.Event class does not work for me, because it uses short >> sleep intervals for timed waits. I need the reaction to be as close to >> instant as possible, something like this will not do: >> >> while not : >> sleep(0.01) >> >> I actually replaced threading.Event with my own version that uses >> native Windows events, and waits on those also cannot be interrupted >> by Ctrl-C. I'm trying to achieve the same effect as that while loop >> and I don't care what the condition to exit is, but the loop needs to >> exit as soon as the condition is met without waiting for up to X >> additional milliseconds. Any ideas? >> > > You may try MsgWaitForMultipleObjects - send a message to the main thread > from the other thread. > An alertable wait (like SleepEx) plus QueueUserAPC should work, I presume, > but I've never actually tried in Python. > > -- > Gabriel Genellina > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://www.astorandblack.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From pranny at gmail.com Fri Feb 27 04:33:44 2009 From: pranny at gmail.com (pranav) Date: Fri, 27 Feb 2009 01:33:44 -0800 (PST) Subject: String search Message-ID: <262dfa16-1169-448b-ae59-76d32ce3fbb1@r18g2000vbi.googlegroups.com> Greeting fellow pycoders, I have a script that browses large codes and replaces certain text with some other text. Of lately i observed an issue.Some of the original text were like ,N'#attributes.SOFTPREREQ#' My module does scan this code and suggests replacement to this code. But when i use the string.replace() method, it just fails. A string.find() for above code in the whole file returns code -1. Where am i going wrong? I figure it could be something to do with character encoding or else. Please someone guide me soon. I have a deadline to attend :-( Thanks in advance, Pranav From gagsl-py2 at yahoo.com.ar Fri Feb 27 04:43:48 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 27 Feb 2009 07:43:48 -0200 Subject: problem with glob in remote directory or os.walk in remote directory in windos References: <49A6A3FB.60708@holdenweb.com> Message-ID: En Fri, 27 Feb 2009 07:02:57 -0200, lameck kassana escribi?: > now it is working but i wonder it brings higher number of count as if it > counts files in wholes computer can you check in my code and correct me > ------------------------------------------------ > import glob > import os > file_count=0 > for files in > glob.glob(r"\\192.168.0.45\loader\Files\file_log\v20090225 > *"): Add this line: print files > file_count += len(files) > print 'Found', file_count, 'files in cwd' > -------------------------------------------------------------------------------------------------------------------------------- > > the results are Found 435656 files in cwd --which is impossible since > files > are around six thousands daily. -- Gabriel Genellina From CinnamonDonkey at googlemail.com Fri Feb 27 04:45:39 2009 From: CinnamonDonkey at googlemail.com (CinnamonDonkey) Date: Fri, 27 Feb 2009 01:45:39 -0800 (PST) Subject: Microsoft Message Queues Message-ID: Hi All, I am looking to use win32com to set-up a Microsoft Message Queue (MSMQ) between two or more computers connected on a LAN. I have found this posting: http://groups.google.co.uk/group/comp.lang.python/browse_thread/thread/80b42375ae84e3d7/989b864575997a9e?hl=en&lnk=gst&q=msmq#989b864575997a9e ...Which is a great start. But I am fairly new to all this python business, let alone COM. Can someone please point me in the right direction to modify this example so that it works across multiple computers connected via the LAN. I have demonstrated it working locally... I just need to progress to that next step. Regards, Shaun From arunjr at gmail.com Fri Feb 27 04:45:55 2009 From: arunjr at gmail.com (Aj) Date: Fri, 27 Feb 2009 01:45:55 -0800 (PST) Subject: decimal to string conv Message-ID: <0cd6257f-c886-4878-af14-c747f6d94936@o11g2000yql.googlegroups.com> Hi all, I am trying to convert a list to string. example [80, 89,84,72,79,78,0] is my input. I could make it to just [0x50,0x59,0x54,0x48,0x4F,0x4E,0x00]. but I wanted it to be like "PYTHON". I couldnt even convert 0x50 to 'P'. Is there any library api available to do this? it will be really helpful to me. dont bang me if its already being asked. I just 'dived' into python yesterday. cheers Aj. From clp2 at rebertia.com Fri Feb 27 04:58:26 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 27 Feb 2009 01:58:26 -0800 Subject: decimal to string conv In-Reply-To: <0cd6257f-c886-4878-af14-c747f6d94936@o11g2000yql.googlegroups.com> References: <0cd6257f-c886-4878-af14-c747f6d94936@o11g2000yql.googlegroups.com> Message-ID: <50697b2c0902270158m582bdfdcy87d2b59cde6f1314@mail.gmail.com> On Fri, Feb 27, 2009 at 1:45 AM, Aj wrote: > Hi all, > > I am trying to convert a list to string. > example [80, 89,84,72,79,78,0] is my input. I could make it to just > [0x50,0x59,0x54,0x48,0x4F,0x4E,0x00]. > but I wanted it to be like "PYTHON". > I couldnt even convert 0x50 to 'P'. Is there any library api available > to do this? it will be really helpful to me. lst = [80, 89,84,72,79,78,0] print ''.join(map(chr, lst[:-1])) Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From arunjr at gmail.com Fri Feb 27 05:07:53 2009 From: arunjr at gmail.com (Aj) Date: Fri, 27 Feb 2009 02:07:53 -0800 (PST) Subject: decimal to string conv References: <0cd6257f-c886-4878-af14-c747f6d94936@o11g2000yql.googlegroups.com> Message-ID: <2fd546ee-b57d-446d-8168-d81a97302836@e18g2000yqo.googlegroups.com> On Feb 27, 10:58?am, Chris Rebert wrote: > On Fri, Feb 27, 2009 at 1:45 AM, Aj wrote: > > Hi all, > > > I am trying to convert a list to string. > > example [80, 89,84,72,79,78,0] is my input. I could make it to just > > [0x50,0x59,0x54,0x48,0x4F,0x4E,0x00]. > > but I wanted it to be like "PYTHON". > > I couldnt even convert 0x50 to 'P'. Is there any library api available > > to do this? it will be really helpful to me. > > lst = [80, 89,84,72,79,78,0] > print ''.join(map(chr, lst[:-1])) > > Cheers, > Chris > > -- > Follow the path of the Iguana...http://rebertia.com wow... that was quick and it works perfect with my inputs. thanx & have a nice day. cheers Aj From bruno.42.desthuilliers at websiteburo.invalid Fri Feb 27 05:15:25 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 27 Feb 2009 11:15:25 +0100 Subject: String search In-Reply-To: <262dfa16-1169-448b-ae59-76d32ce3fbb1@r18g2000vbi.googlegroups.com> References: <262dfa16-1169-448b-ae59-76d32ce3fbb1@r18g2000vbi.googlegroups.com> Message-ID: <49a7bd24$0$5835$426a74cc@news.free.fr> pranav a ?crit : > Greeting fellow pycoders, > > I have a script that browses large codes and replaces certain text > with some other text. Of lately i observed an issue.Some of the > original text were like > > > ,N'#attributes.SOFTPREREQ#' > > > My module does scan this code and suggests replacement to this code. > But when i use the string.replace() method, it just fails. A > string.find() for above code in the whole file returns code -1. > Where am i going wrong? Not posting a minimal (and if possible runnable) excerpt of your code exhibiting the problem, along with test data. >I figure it could be something to do with > character encoding or else. or with white spaces (including newlines characters), or whatever. As a general guideline : any non-trivial text parsing requires a non-trivial parser. From bearophileHUGS at lycos.com Fri Feb 27 05:15:27 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Fri, 27 Feb 2009 02:15:27 -0800 (PST) Subject: Proposed implementation for an Ordered Dictionary References: <5c65efb2-0862-4b85-bb37-88687ac6fedd@q9g2000yqc.googlegroups.com> <871vtk7ub8.fsf@mulj.homelinux.net> <7xd4d4hjaq.fsf@ruckus.brouhaha.com> <6d818c3d-1d6d-4720-8775-427b3832c590@u18g2000pro.googlegroups.com> <7x63iwg2wg.fsf@ruckus.brouhaha.com> <6f52f838-d435-40b8-865e-55f3aed1bb1e@w24g2000prd.googlegroups.com> <5a96c945-7b61-4dba-af20-a324fd3b3394@z9g2000yqi.googlegroups.com> <7xfxi08da9.fsf@ruckus.brouhaha.com> Message-ID: <3d0a5145-2202-418a-97cc-cbe9c04def16@h5g2000yqh.googlegroups.com> Paul Rubin: >I don't see how to delete a randomly chosen node if you use that trick, since the hash lookup doesn't give you two consecutive nodes in the linked list to xor together.< Thank you, I think you are right, I am sorry. So on 32-bit CPUs you need to add 8 bytes to each value. On 64-bit CPUs you may use a double indexed list, instead of a double linked list. And each index can be stored in 6 bytes instead of 8 (281_474_976_710_656 buckets may be enough for most people), so you need only 12 bytes for two indexes instead of 16 bytes, this helps the L1 cache (and the small L2 cache too on Core i7) a bit. But this may slow down too much the ordered iteration. Bye, bearophile From gagsl-py2 at yahoo.com.ar Fri Feb 27 05:17:18 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 27 Feb 2009 08:17:18 -0200 Subject: String search References: <262dfa16-1169-448b-ae59-76d32ce3fbb1@r18g2000vbi.googlegroups.com> Message-ID: En Fri, 27 Feb 2009 07:33:44 -0200, pranav escribi?: > Greeting fellow pycoders, > > I have a script that browses large codes and replaces certain text > with some other text. Of lately i observed an issue.Some of the > original text were like > > > ,N'#attributes.SOFTPREREQ#' > > > My module does scan this code and suggests replacement to this code. > But when i use the string.replace() method, it just fails. A > string.find() for above code in the whole file returns code -1. > Where am i going wrong? I figure it could be something to do with > character encoding or else. Do you mean, you look for those three complete lines with a single xxxx.find(...)? Hard to guess... maybe there is some withespace at the end of a line, some additional leading whitespace in the second line, a tab character instead of spaces, maybe those ' are instead ? or `, maybe the file does not use \n as a line termination, maybe the file encoding doesn't match what you expect... If string.find() does return -1, it is because the text you're looking for is NOT inside the string. No use in questioning that. If you think the text IS there, get a decent hex editor and examine the file near the supposed match, character by character, and see WHERE is the difference (there MUST be a difference). -- Gabriel Genellina From lkassana at gmail.com Fri Feb 27 05:17:28 2009 From: lkassana at gmail.com (lameck kassana) Date: Fri, 27 Feb 2009 13:17:28 +0300 Subject: problem with glob in remote directory or os.walk in remote directory in windos In-Reply-To: References: <49A6A3FB.60708@holdenweb.com> Message-ID: At last i did it it was this wrong line file_count += len(files) ---it supposed to be file_count+=1 but thanks for help ya python masters .Steven Holden ,,,, thanks very very much for your tip about raw string On Fri, Feb 27, 2009 at 12:43 PM, Gabriel Genellina wrote: > En Fri, 27 Feb 2009 07:02:57 -0200, lameck kassana > escribi?: > > now it is working but i wonder it brings higher number of count as if it >> counts files in wholes computer can you check in my code and correct me >> ------------------------------------------------ >> import glob >> import os >> file_count=0 >> for files in >> glob.glob(r"\\192.168.0.45\loader\Files\file_log\v20090225> 192.168.0.45/loader/Files/file_log/v20090225> >> *"): >> > > Add this line: > print files > > file_count += len(files) >> print 'Found', file_count, 'files in cwd' >> >> -------------------------------------------------------------------------------------------------------------------------------- >> >> the results are Found 435656 files in cwd --which is impossible since >> files >> are around six thousands daily. >> > > -- > Gabriel Genellina > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Fri Feb 27 06:08:10 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 27 Feb 2009 09:08:10 -0200 Subject: factoring wx.Image References: <49A74AB7.8010808@al.com.au> Message-ID: En Fri, 27 Feb 2009 00:06:47 -0200, Astan Chee escribi?: > I want to factor (red, green and blue at the same time) an image using > wx but without any GUI display or windows but it keeps crashing What do you mean? Really crashing? Or do you get a Python stack trace? > and if I set the checks to ignore it, it doesn't produce the images at > all. > It looks like this: > > import wx > img = wx.Image("star.jpg",wx.BITMAP_TYPE_BMP) Are you sure the format is BITMAP_TYPE_BMP? The name seems to indicate otherwise... > factor = 1 > for i in range(1,30): > image = img.AdjustChannels(factor, factor, factor, 1) And multiplying r,g,b by 30 you'll get an almost white image - is it what you want? > fname = "star." + str(factor) + ".jpg" > img.SaveFile(fname,wx.BITMAP_TYPE_JPEG) > factor+=1 Note that you're saving the ORIGINAL image here... > > What am I missing here? What am I doing wrong? Can this even be done > with only wx? Try again... -- Gabriel Genellina From eckhardt at satorlaser.com Fri Feb 27 06:29:16 2009 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Fri, 27 Feb 2009 12:29:16 +0100 Subject: struct.unpack() on a stream Message-ID: Hi! I have a socket from which I would like to parse some data, how would I do that? Of course, I can manually read data from the socket until unpack() stops complaining about a lack of data, but that sounds rather inelegant. Any better suggestions? Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From odeits at gmail.com Fri Feb 27 06:34:34 2009 From: odeits at gmail.com (odeits) Date: Fri, 27 Feb 2009 03:34:34 -0800 (PST) Subject: String search References: <262dfa16-1169-448b-ae59-76d32ce3fbb1@r18g2000vbi.googlegroups.com> Message-ID: On Feb 27, 2:17?am, "Gabriel Genellina" wrote: > En Fri, 27 Feb 2009 07:33:44 -0200, pranav escribi?: > > > Greeting fellow pycoders, > > > I have a script that browses large codes and replaces certain text > > with some other text. Of lately i observed an issue.Some of the > > original text were like > > > > > ? ? ,N'#attributes.SOFTPREREQ#' > > > > > My module does scan this code and suggests replacement to this code. > > But when i use the string.replace() method, it just fails. A > > string.find() for above code in the whole file returns code -1. > > Where am i going wrong? I figure it could be something to do with > > character encoding or else. > > Do you mean, you look for those three complete lines with a single ? > xxxx.find(...)? > Hard to guess... maybe there is some withespace at the end of a line, some ? > additional leading whitespace in the second line, a tab character instead ? > of spaces, maybe those ' are instead ? or `, maybe the file does not use ? > \n as a line termination, maybe the file encoding doesn't match what you ? > expect... > > If string.find() does return -1, it is because the text you're looking for ? > is NOT inside the string. No use in questioning that. If you think the ? > text IS there, get a decent hex editor and examine the file near the ? > supposed match, character by character, and see WHERE is the difference ? > (there MUST be a difference). > > -- > Gabriel Genellina Try looking into regular expressions.... http://docs.python.org/library/re.html From gagsl-py2 at yahoo.com.ar Fri Feb 27 06:52:38 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 27 Feb 2009 09:52:38 -0200 Subject: struct.unpack() on a stream References: Message-ID: En Fri, 27 Feb 2009 09:29:16 -0200, Ulrich Eckhardt escribi?: > I have a socket from which I would like to parse some data, how would I > do > that? Of course, I can manually read data from the socket until unpack() > stops complaining about a lack of data, but that sounds rather inelegant. > > Any better suggestions? Read until you get the required bytes; use the size attribute. -- Gabriel Genellina From google at mrabarnett.plus.com Fri Feb 27 07:10:39 2009 From: google at mrabarnett.plus.com (MRAB) Date: Fri, 27 Feb 2009 12:10:39 +0000 Subject: struct.unpack() on a stream In-Reply-To: References: Message-ID: <49A7D83F.6060904@mrabarnett.plus.com> Gabriel Genellina wrote: > En Fri, 27 Feb 2009 09:29:16 -0200, Ulrich Eckhardt > escribi?: > >> I have a socket from which I would like to parse some data, how would >> I do >> that? Of course, I can manually read data from the socket until unpack() >> stops complaining about a lack of data, but that sounds rather inelegant. >> >> Any better suggestions? > > Read until you get the required bytes; use the size attribute. > The struct module has a function called "calcsize", eg: >>> import struct >>> struct.calcsize(" References: <49A6A3FB.60708@holdenweb.com> Message-ID: <49A7D9A0.1060803@holdenweb.com> lameck kassana wrote: > now it is working but i wonder it brings higher number of count as if it > counts files in wholes computer can you check in my code and correct me > ------------------------------------------------ > import glob > import os > file_count=0 > for files in glob.glob(r"\\192.168.0.45\loader\Files\file_log\v20090225 > *"): > file_count += len(files) > print 'Found', file_count, 'files in cwd' > -------------------------------------------------------------------------------------------------------------------------------- > > the results are Found 435656 files in cwd --which is impossible since > files are around six thousands daily. > thanks in advance > Please don't use "reply all" - I subscribe to the list, and will see your posting there. I am pretty sure by now someone has pointed out that you are adding the lengths of the filenames, and what you instead need is file_count = len(glob.glob(...)) regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steven.oldner at gmail.com Fri Feb 27 07:42:29 2009 From: steven.oldner at gmail.com (steven.oldner) Date: Fri, 27 Feb 2009 04:42:29 -0800 (PST) Subject: Data Coding suggestions Message-ID: Just learning Python and have a project to create a weekly menu and a shopping list from the menu. This is something I do manually now, so I'm automating it. What I'd like is a list of menu choices, such as: CODE- Description - Est Cost 'B01 - Pancakes, Sausage,and Eggs - $5.80, 'L01 - Tuna Fish sandwices and chips -$ 4.25 , 'D01 - Dirty Rice and Garlic Bread' - $5.70. >From the choices, I'll create a weekly menu, print the menu, and then print list of ingredients ( and sum the commom items) CODE- Item - Qty. - Unit B01 - pancake mix - 1 - box B01 - milk - .3 -gal B01 - eggs - 10 - each D01 - dirty rice mix - 1 - box D01 - milk - .3 - gal. I would like to expand the ingredient list to include other fields like 'last purchase date' and 'reorder point'. I've used an example program and started to code it but just realized I've been coding ABAP in Python, that is set up a data structure and use that. What I want is to learn code Python in Python. Question: How should I set up the data? I'm looking at maybe 70 menu items and maybe 1000 items for the shopping list. I need to be able to maintain each item also. I am using python 2.6 but would like to use 3.0. Thanks for any suggestions! From alecla at bluewin.ch Fri Feb 27 07:46:37 2009 From: alecla at bluewin.ch (alex) Date: Fri, 27 Feb 2009 04:46:37 -0800 (PST) Subject: TextCtrl fully expanding at program start Message-ID: Hi all I have a gridsizer consisting of two vertically stacked panels, one with a StaticBox and the other with a TextCtrl. I would like that the TextCtrl expands at program start fully to the allocated panel size (lower panel of gridSizer). Instead of like now, fully expanding in the width but not exapnding in the height direction (two lines high). I am currently running in circles so maybe can anybody help me? See below for my best effort (OS WinXP, Python 2.5). Thank you, regards Alex import wx class Frame(wx.Frame): def __init__(self, title, pos, size): wx.Frame.__init__(self, None, -1, title, pos, size) self.panel = wx.Panel(self) self.panel.SetBackgroundColour(wx.Colour(220, 220, 220)) box1 = wx.StaticBox(self.panel, -1, "Program Preferences") box2 = wx.TextCtrl(self.panel, -1, size=(-1,-1),style = wx.TE_MULTILINE|wx.TE_READONLY) gs = wx.GridSizer(2, 1, 0, 0) windowOneSizer = wx.BoxSizer(wx.VERTICAL) windowTwoSizer = wx.BoxSizer(wx.VERTICAL) windowOneSizer.Add(box1, 0, wx.ALL|wx.EXPAND, 0) windowTwoSizer.Add(box2, 0, wx.ALL|wx.EXPAND, 0) gs.Add(windowOneSizer, 0, wx.ALL|wx.EXPAND, 2) gs.Add(windowTwoSizer, 0, wx.ALL|wx.EXPAND, 2) self.panel.SetSizer(gs) self.Centre() self.Show(True) class App(wx.App): def OnInit(self): frame = Frame("My Frame", (100, 100), (400, 250)) frame.Show() self.SetTopWindow(frame) return True # # if __name__ == '__main__': # app = App() app.MainLoop() # # From odeits at gmail.com Fri Feb 27 07:49:39 2009 From: odeits at gmail.com (odeits) Date: Fri, 27 Feb 2009 04:49:39 -0800 (PST) Subject: removing duplication from a huge list. References: <269329b40902261237j2815c8a2x80d7469abba1e1e6@mail.gmail.com> <516a626d-62ee-48c0-acc3-dbf044b163a4@q11g2000yqh.googlegroups.com> <49a7afce$0$32663$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <2c31654a-ca32-4d91-af0c-9cb72d0da793@o8g2000pre.googlegroups.com> On Feb 27, 1:18?am, Stefan Behnel wrote: > bearophileH... at lycos.com wrote: > > odeits: > >> How big of a list are we talking about? If the list is so big that the > >> entire list cannot fit in memory at the same time this approach wont > >> work e.g. removing duplicate lines from a very large file. > > > If the data are lines of a file, and keeping the original order isn't > > important, then the first to try may be to use the unix (or cygwin on > > Windows) commands sort and uniq. > > or preferably "sort -u", in case that's supported. > > Stefan Although this is true, that is more of an answer to the question "How do i remove duplicates from a huge list in Unix?". From bearophileHUGS at lycos.com Fri Feb 27 07:57:11 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Fri, 27 Feb 2009 04:57:11 -0800 (PST) Subject: removing duplication from a huge list. References: <269329b40902261237j2815c8a2x80d7469abba1e1e6@mail.gmail.com> <516a626d-62ee-48c0-acc3-dbf044b163a4@q11g2000yqh.googlegroups.com> <49a7afce$0$32663$9b4e6d93@newsspool2.arcor-online.net> <2c31654a-ca32-4d91-af0c-9cb72d0da793@o8g2000pre.googlegroups.com> Message-ID: <2a4bdb93-50aa-48f6-8979-277a5d2ca5e8@v19g2000yqn.googlegroups.com> odeits: > Although this is true, that is more of an answer to the question "How > do i remove duplicates from a huge list in Unix?". Don't you like cygwin? Bye, bearophile From gagsl-py2 at yahoo.com.ar Fri Feb 27 07:58:51 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 27 Feb 2009 10:58:51 -0200 Subject: struct.unpack() on a stream References: <49A7D83F.6060904@mrabarnett.plus.com> Message-ID: En Fri, 27 Feb 2009 10:10:39 -0200, MRAB escribi?: > Gabriel Genellina wrote: >> En Fri, 27 Feb 2009 09:29:16 -0200, Ulrich Eckhardt >> escribi?: >> >>> I have a socket from which I would like to parse some data, how would >>> I do >>> that? Of course, I can manually read data from the socket until >>> unpack() >>> stops complaining about a lack of data, but that sounds rather >>> inelegant. >>> >>> Any better suggestions? >> Read until you get the required bytes; use the size attribute. >> > The struct module has a function called "calcsize", eg: > > >>> import struct > >>> struct.calcsize(" 2 > > That will tell you how many bytes to read. The struct module defines also a Struct class; instead of using the module functions, it's more efficient to create a Struct instance and call its methods when one is going to use the same format more than once: py> s = struct.Struct(" s.size 2 py> s.unpack("\x40\x00") (64,) That's the size attribute I was talking about - too tersely perhaps. -- Gabriel Genellina From steve at holdenweb.com Fri Feb 27 08:03:32 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 27 Feb 2009 08:03:32 -0500 Subject: Queries In-Reply-To: References: Message-ID: Dennis Lee Bieber wrote: [...] > {Oh, and since I saw, at work, a later post with a bunch of nested UNION > statements: UNION requires all the tables to have the same number/type > of columns -- you don't have that} A rather fine point, but technically all that's required is the the united *queries* have the same number and type of columns. I assume that the OP was selecting *, though ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Fri Feb 27 08:05:23 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 27 Feb 2009 08:05:23 -0500 Subject: problem with glob in remote directory or os.walk in remote directory in windos In-Reply-To: References: <49A6A3FB.60708@holdenweb.com> Message-ID: lameck kassana wrote: > At last i did it it was this wrong line file_count += len(files) ---it > supposed to be file_count+=1 > but thanks for help ya python masters .Steven Holden ,,,, thanks very > very much for your tip about raw string > Lameck: Please note that file_count = 0 for files in (...): file_count += 1 can be *much* more efficiently expressed as file_count = len(...) regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Fri Feb 27 08:08:42 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 27 Feb 2009 08:08:42 -0500 Subject: Proposed implementation for an Ordered Dictionary In-Reply-To: <3d0a5145-2202-418a-97cc-cbe9c04def16@h5g2000yqh.googlegroups.com> References: <5c65efb2-0862-4b85-bb37-88687ac6fedd@q9g2000yqc.googlegroups.com> <871vtk7ub8.fsf@mulj.homelinux.net> <7xd4d4hjaq.fsf@ruckus.brouhaha.com> <6d818c3d-1d6d-4720-8775-427b3832c590@u18g2000pro.googlegroups.com> <7x63iwg2wg.fsf@ruckus.brouhaha.com> <6f52f838-d435-40b8-865e-55f3aed1bb1e@w24g2000prd.googlegroups.com> <5a96c945-7b61-4dba-af20-a324fd3b3394@z9g2000yqi.googlegroups.com> <7xfxi08da9.fsf@ruckus.brouhaha.com> <3d0a5145-2202-418a-97cc-cbe9c04def16@h5g2000yqh.googlegroups.com> Message-ID: bearophileHUGS at lycos.com wrote: > Paul Rubin: >> I don't see how to delete a randomly chosen node if you use that trick, since the hash lookup doesn't give you two consecutive nodes in the linked list to xor together.< > > Thank you, I think you are right, I am sorry. > So on 32-bit CPUs you need to add 8 bytes to each value. > > On 64-bit CPUs you may use a double indexed list, instead of a double > linked list. And each index can be stored in 6 bytes instead of 8 > (281_474_976_710_656 buckets may be enough for most people), so you > need only 12 bytes for two indexes instead of 16 bytes, this helps the > L1 cache (and the small L2 cache too on Core i7) a bit. But this may > slow down too much the ordered iteration. > A sort of premature pessimization, then. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Fri Feb 27 08:10:30 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 27 Feb 2009 08:10:30 -0500 Subject: Delete all items in the list In-Reply-To: <50697b2c0902262259t4820cdffj643531e2bbe8cb0d@mail.gmail.com> References: <35df0b67-3403-444b-93ba-c516bf67d110@p2g2000prf.googlegroups.com> <50697b2c0902262259t4820cdffj643531e2bbe8cb0d@mail.gmail.com> Message-ID: Chris Rebert wrote: > On Thu, Feb 26, 2009 at 10:26 PM, odeits wrote: [...] >> while 'a' in L: >> L.remove('a') >> >> not the most efficient but it works > > "Not the most efficient"; it's terribly inefficient! It's 2*O(M*N) [M > = number of 'a's in L], versus just N. And that's not even accounting > for all the extra element movement done by .remove() > Surely 2*O(M*N) is O(M*N) since constant factors are irrelevant in assessing performance order? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Fri Feb 27 08:13:35 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 27 Feb 2009 08:13:35 -0500 Subject: Multiple conditional expression In-Reply-To: <1a7951080902262039l14c296f0m72a51281f1ad7626@mail.gmail.com> References: <1a7951080902261911h62798085uf3c4336f2aa631a0@mail.gmail.com> <7xhc2gv9h6.fsf@ruckus.brouhaha.com> <1a7951080902262039l14c296f0m72a51281f1ad7626@mail.gmail.com> Message-ID: <49A7E6FF.8060703@holdenweb.com> Anjanesh Lekshminarayanan wrote: >> How do we know that from the what the OP posted? > Its CGI alright. > spaces = form.has_key('spaces') and form.getvalue('spaces') == '1' > > But I just dont see how > spaces = (form.has_key('spaces') ? form.getvalue('spaces') == 1 ? > True: False : False) > is complicated in anyway. Its not that hard to read at all. > In that case I fear Python will be far too simple for your clearly impressive mind. You've been programming for way too long ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Fri Feb 27 08:27:53 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 27 Feb 2009 08:27:53 -0500 Subject: Data Coding suggestions In-Reply-To: References: Message-ID: steven.oldner wrote: > Just learning Python and have a project to create a weekly menu and a > shopping list from the menu. This is something I do manually now, so > I'm automating it. > > What I'd like is a list of menu choices, such as: > CODE- Description - Est Cost > > 'B01 - Pancakes, Sausage,and Eggs - $5.80, > 'L01 - Tuna Fish sandwices and chips -$ 4.25 , > 'D01 - Dirty Rice and Garlic Bread' - $5.70. > >>From the choices, I'll create a weekly menu, print the menu, and then > print list of ingredients ( and sum the commom items) > > CODE- Item - Qty. - Unit > B01 - pancake mix - 1 - box > B01 - milk - .3 -gal > B01 - eggs - 10 - each > D01 - dirty rice mix - 1 - box > D01 - milk - .3 - gal. > > I would like to expand the ingredient list to include other fields > like 'last purchase date' and 'reorder point'. > > I've used an example program and started to code it but just realized > I've been coding ABAP in Python, that is set up a data structure and > use that. What I want is to learn code Python in Python. > > Question: How should I set up the data? I'm looking at maybe 70 menu > items and maybe 1000 items for the shopping list. I need to be able > to maintain each item also. > > I am using python 2.6 but would like to use 3.0. > Well from the nature of the task it seems evident that the data should be long-lived, and therefore need to be stored on disk. The natural way to deal with them in the program would be to have recipes, each of which was associated with a number of ingredient requirements, each of which was associated with an ingredient. That way, you can adjust the prices of your ingredients as the market varies. Recent versions of Python come with sqlite, a low-cost but surprisingly efficient relational database implementation. I'd suggest using that, with the following tables: Recipe: id integer primary key name string Ingredient id integer primary key name string unit string [oz, gal, etc.] cost number [cost per unit] Requirement recipe integer [id of recipe] ingredient integer [id of ingredient] quantity number [amount required for one serving] So each recipe will have one row in the recipe table, a number of rows in the requirement table, each of which points also to the relevant ingredient. >From there it's a relatively simple task to work out how much of which ingredients is required to create N helpings of a specific recipe, and the cost as well. It will mean understanding a little more about database than you perhaps do right now, but that's a useful addition to any programmer's bag of tricks. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From clp2 at rebertia.com Fri Feb 27 08:46:47 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 27 Feb 2009 05:46:47 -0800 Subject: Delete all items in the list In-Reply-To: References: <35df0b67-3403-444b-93ba-c516bf67d110@p2g2000prf.googlegroups.com> <50697b2c0902262259t4820cdffj643531e2bbe8cb0d@mail.gmail.com> Message-ID: <50697b2c0902270546l1badb577kde883f998a24575@mail.gmail.com> On Fri, Feb 27, 2009 at 5:10 AM, Steve Holden wrote: > Chris Rebert wrote: >> On Thu, Feb 26, 2009 at 10:26 PM, odeits wrote: > [...] >>> while 'a' in L: >>> ? L.remove('a') >>> >>> not the most efficient but it works >> >> "Not the most efficient"; it's terribly inefficient! It's 2*O(M*N) [M >> = number of 'a's in L], versus just N. And that's not even accounting >> for all the extra element movement done by .remove() >> > Surely 2*O(M*N) is O(M*N) since constant factors are irrelevant in > assessing performance order? Obviously that equivalence is true, but in this case I'm emphasizing that it's even worse than that when constant factors are taken into account. Big-O is nice in the abstract, but in the real-world those constant factors can matter. In pure big-O, it is indeed O(M*N) vs. O(N) Including constant factors, the performance is roughly 2*M*N*X [X = overhead of remove()] vs. N, which makes the badness of the algorithm all the more apparent. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From loretta at fhv.at Fri Feb 27 08:51:49 2009 From: loretta at fhv.at (Loretta SALINO) Date: Fri, 27 Feb 2009 14:51:49 +0100 Subject: OT: handling multiple software repositories References: <70npmbFgb464U1@mid.individual.net> Message-ID: <49a7eff5$0$12126$3b214f66@aconews.univie.ac.at> Tim Golden wrote: > Thomas Guettler wrote: >> Hi, >> >> this is a bit off topic. >> >> In our company we have several SVN repositories. >> >> According to [1] Trac by default only handles one >> repository. >> >> Of course Trac links like changeset [1234] would not work anymore. >> You would need [repro/1234] or something like this. >> >> I think many (python) programmer have several repositories >> and need to handle this somehow. >> >> How do you do this? >> >> I want a common wiki and a common bug tracker. It should >> be possible to attach a bug to several repositories. >> >> Up to now I don't use Trac, if someone has an alternative, please >> tell me! > > > Have a look at DrProject[1], a Trac-alike which handles > multiple projects. (Not used it myself). > > TJG > > [1] https://www.drproject.org/ Good hint, thanks! I'm in the same situation and have been installing Trac right these days. However, where is DrProject? Following the links pointing to TGZs fails and installing from svn doesn't work poperly (error messages about PyDispatcher). So, how did/do you install DrProject? Kind regards Loretta From andrei.avk at gmail.com Fri Feb 27 08:57:34 2009 From: andrei.avk at gmail.com (Rainy) Date: Fri, 27 Feb 2009 05:57:34 -0800 (PST) Subject: ANN: updates to Python-by-example Message-ID: <379a7319-376d-4486-954a-fc7035b0deb9@j38g2000yqa.googlegroups.com> Python-by-example http:// pbe.lightbird.net has some new modules added: pickle, shelve, sqlite3, gzip, csv, configparser, optparse, logging. I also changed over to using excellent sphinx package to generate documentation, this will allow me to add pdf and windows help formats soon (I ran into some issues with that, actually). More modules coming soon, too! -AK From ra.ravi.rav at gmail.com Fri Feb 27 08:59:11 2009 From: ra.ravi.rav at gmail.com (Ravi) Date: Fri, 27 Feb 2009 05:59:11 -0800 (PST) Subject: Make a python property with the same name as the class member name Message-ID: Is it possible in python to create a property with the same name as the member variable name of the class. e.g. Class X: ... self.i = 10 # marker ... property(fget = get_i, fset = set_i) Please tell me how I can do so. Because if I do so, for the statement at marker I get stack overflow for the assingm From mail at timgolden.me.uk Fri Feb 27 09:05:57 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 27 Feb 2009 14:05:57 +0000 Subject: OT: handling multiple software repositories In-Reply-To: <49a7eff5$0$12126$3b214f66@aconews.univie.ac.at> References: <70npmbFgb464U1@mid.individual.net> <49a7eff5$0$12126$3b214f66@aconews.univie.ac.at> Message-ID: <49A7F345.7060402@timgolden.me.uk> Loretta SALINO wrote: > Tim Golden wrote: > >> Thomas Guettler wrote: >>> Hi, >>> >>> this is a bit off topic. >>> >>> In our company we have several SVN repositories. >>> >>> According to [1] Trac by default only handles one >>> repository. >>> >>> Of course Trac links like changeset [1234] would not work anymore. >>> You would need [repro/1234] or something like this. >>> >>> I think many (python) programmer have several repositories >>> and need to handle this somehow. >>> >>> How do you do this? >>> >>> I want a common wiki and a common bug tracker. It should >>> be possible to attach a bug to several repositories. >>> >>> Up to now I don't use Trac, if someone has an alternative, please >>> tell me! >> >> Have a look at DrProject[1], a Trac-alike which handles >> multiple projects. (Not used it myself). >> >> TJG >> >> [1] https://www.drproject.org/ > > Good hint, thanks! I'm in the same situation and have been installing Trac > right these days. However, where is DrProject? > > Following the links pointing to TGZs fails and installing from svn doesn't > work poperly (error messages about PyDispatcher). So, how did/do you > install DrProject? I didn't, I'm afraid (cf above). Hopefully someone who has, or even one of the maintainers, can chip in. TJG From et1ssgmiller at gmail.com Fri Feb 27 09:12:30 2009 From: et1ssgmiller at gmail.com (Greg Miller) Date: Fri, 27 Feb 2009 06:12:30 -0800 (PST) Subject: starting a Python 2.5 executable without the DOS window Message-ID: <40fb0b57-84de-406c-833a-8eaf3a0b921a@e1g2000pra.googlegroups.com> I am working on a program that controls a piece of equipment. The GUI/ control software is written with Python2.5/wxPython. I would like to know if there is a way of starting the GUI without the DOS window having to launch? I would like only the application itself to appear, no DOS window. Thanks for any information. Greg Miller From vlastimil.brom at gmail.com Fri Feb 27 09:14:49 2009 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Fri, 27 Feb 2009 15:14:49 +0100 Subject: TextCtrl fully expanding at program start In-Reply-To: References: Message-ID: <9fdb569a0902270614k12a011bbu42394e0630b9e9a7@mail.gmail.com> 2009/2/27 alex : > Hi all > I have a gridsizer consisting of two vertically stacked panels, one > with a StaticBox and the other with a TextCtrl. > I would like that the TextCtrl expands at program start fully to the > allocated panel size (lower panel of gridSizer). > Instead of like now, fully expanding in the width but not exapnding in > the height direction (two lines high). ... > Hi, changing the proportion for adding the textctrl into the sizer to 1 should expand it to the lower half of the panel. try changing: windowTwoSizer.Add(box2, 0, wx.ALL|wx.EXPAND, 0) TO: windowTwoSizer.Add(box2, 1, wx.ALL|wx.EXPAND, 0) See http://www.wxpython.org/docs/api/wx.Sizer-class.html#Add for the options for adding into the sizer. hth vbr From eckhardt at satorlaser.com Fri Feb 27 09:26:27 2009 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Fri, 27 Feb 2009 15:26:27 +0100 Subject: starting a Python 2.5 executable without the DOS window References: <40fb0b57-84de-406c-833a-8eaf3a0b921a@e1g2000pra.googlegroups.com> Message-ID: Greg Miller wrote: > I would like to know if there is a way of starting the GUI > without the DOS window having to launch? Use pythonw.exe instead of python.exe. Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From pruebauno at latinmail.com Fri Feb 27 09:28:12 2009 From: pruebauno at latinmail.com (pruebauno at latinmail.com) Date: Fri, 27 Feb 2009 06:28:12 -0800 (PST) Subject: starting a Python 2.5 executable without the DOS window References: <40fb0b57-84de-406c-833a-8eaf3a0b921a@e1g2000pra.googlegroups.com> Message-ID: <5db4e50e-6882-4c23-83cf-df50315896c0@a39g2000yqc.googlegroups.com> On Feb 27, 9:12?am, Greg Miller wrote: > I am working on a program that controls a piece of equipment. ?The GUI/ > control software is written with Python2.5/wxPython. ?I would like to > know if there is a way of starting the GUI without the DOS window > having to launch? ?I would like only the application itself to appear, > no DOS window. ?Thanks for any information. > Greg Miller change the extension of your python program from ".py" to ".pyw". Alternatively make sure that your program gets started by pythonw.exe (insted of python.exe). From python at bdurham.com Fri Feb 27 09:40:27 2009 From: python at bdurham.com (python at bdurham.com) Date: Fri, 27 Feb 2009 09:40:27 -0500 Subject: ANN: updates to Python-by-example In-Reply-To: <379a7319-376d-4486-954a-fc7035b0deb9@j38g2000yqa.googlegroups.com> References: <379a7319-376d-4486-954a-fc7035b0deb9@j38g2000yqa.googlegroups.com> Message-ID: <1235745627.24512.1302731601@webmail.messagingengine.com> Rainy, Great stuff! Thanks for your examples with the community!! Regards, Malcolm From gnewsg at gmail.com Fri Feb 27 09:48:20 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Fri, 27 Feb 2009 06:48:20 -0800 (PST) Subject: How can I know when a sub-process is effectively initialized? References: Message-ID: <792949e0-f098-4262-96bf-2c99e2e708e2@a39g2000yqc.googlegroups.com> On 26 Feb, 21:59, Jean-Paul Calderone wrote: > On Thu, 26 Feb 2009 12:27:26 -0800 (PST), Giampaolo Rodola' wrote: > >Hi, > >I'm working on a Python module called psutil [1] for reading process > >information in a cross-platform way. > >I'm having a problem with psutil test suite. > >Almost all the test cases we implemented so far look like this: > > >def test_foo(self): > > ? ?test_process = subprocess.Popen(sys.executable, stdout=DEVNULL, > >stderr=DEVNULL) > > ? ?time.sleep(0.1) ?# XXX: provisional, give some time the sub > >process to initialize > > ? ?p = psutil.Process(test_process.pid) > > ? ?# start test here > > ? ?... > > >As you can see we put a time.sleep(0.1) call after subprocess.Popen() > >as a provisional workaround to let the sub process initialize > >properly. > >We're searching for some kind of way to know when the child process is > >properly initialized so that we can actually start testing cases > >without worries. > >Does someone has an idea how could we do that? > > Hi Giampaolo, > > "Properly initialized" is application specific. ?Generally, what you want > to do is have the child process tell you when it's ready. ?A common way > to do this is for the child to write some bytes to a file descriptor the > parent is monitoring when it is ready. ?The parent then just waits for > those bytes. ?It looks like you entirely control the child in this case, > so that should be possible here. > > Alternatively, maybe by "properly initialized" you mean something very > specific about how subprocess.Popen creates processes. ?If so, can you > elaborate a bit? > > Jean-Paul By "properly initialized" I mean when I can actually start fetching information from the process (e.g. name, path, parent pid, etc...). Anyway, I came out with this solution: def wait_for_pid(pid, timeout=1): """Wait for pid to show up in the process list then return. Used in the test suite to give time the sub process to initialize. """ raise_at = time.time() + timeout while 1: if pid in psutil.get_pid_list(): return time.sleep(0.0001) if time.time() >= raise_at: raise RuntimeError("Timed out") def test_foo(): proc = subprocess.Popen(PYTHON, stdout=DEVNULL, stderr=DEVNULL) wait_for_pid(proc.pid) ... It seems to work fine on posix but we still got problems on Windows where it seems that waiting for pid to show up in the system process list is not enough for considering the process effectively initialized. Anyway, I think it's a problem in our code. Thanks for your help, anyway. --- Giampaolo http://code.google.com/p/pyftpdlib From mail at timgolden.me.uk Fri Feb 27 09:54:10 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 27 Feb 2009 14:54:10 +0000 Subject: How can I know when a sub-process is effectively initialized? In-Reply-To: <792949e0-f098-4262-96bf-2c99e2e708e2@a39g2000yqc.googlegroups.com> References: <792949e0-f098-4262-96bf-2c99e2e708e2@a39g2000yqc.googlegroups.com> Message-ID: <49A7FE92.2050705@timgolden.me.uk> Giampaolo Rodola' wrote: > It seems to work fine on posix but we still got problems on Windows > where it seems that waiting for pid to show up in the system process > list is not enough for considering the process effectively > initialized. > Anyway, I think it's a problem in our code. > Thanks for your help, anyway. On Windows, I'd just wait on a Windows event. The child process sets it; the parent waits on it. If you need various of them, the parent can pass a suitable id on the commandline to the child. There are alternatives but this one is very easy to achieve. TJG From support.desk.ipg at gmail.com Fri Feb 27 09:58:58 2009 From: support.desk.ipg at gmail.com (Support Desk) Date: Fri, 27 Feb 2009 08:58:58 -0600 Subject: Capture Keystrokes from a USB Wireless Keyboard. In-Reply-To: References: Message-ID: <3C62F42D051F490FB51503F50DFEB282@office.ipglobal.net> Does anybody know of a way to capture keystrokes form a wireless USB keyboard using python? From sgeiger at councilforeconed.org Fri Feb 27 10:09:18 2009 From: sgeiger at councilforeconed.org (Shane Geiger) Date: Fri, 27 Feb 2009 10:09:18 -0500 Subject: Capture Keystrokes from a USB Wireless Keyboard. In-Reply-To: <3C62F42D051F490FB51503F50DFEB282@office.ipglobal.net> References: <3C62F42D051F490FB51503F50DFEB282@office.ipglobal.net> Message-ID: <49A8021E.10200@councilforeconed.org> Here's one option: http://pykeylogger.sourceforge.net/wiki/index.php/PyKeylogger:FAQ Support Desk wrote: > Does anybody know of a way to capture keystrokes form a wireless USB > keyboard using python? > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Shane Geiger, IT Director Council For Economic Education / www.councilforeconed.org sgeiger at councilforeconed.org / 402-438-8958 Teaching Opportunity From bearophileHUGS at lycos.com Fri Feb 27 10:16:02 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Fri, 27 Feb 2009 07:16:02 -0800 (PST) Subject: Proposed implementation for an Ordered Dictionary References: <5c65efb2-0862-4b85-bb37-88687ac6fedd@q9g2000yqc.googlegroups.com> <871vtk7ub8.fsf@mulj.homelinux.net> <7xd4d4hjaq.fsf@ruckus.brouhaha.com> <6d818c3d-1d6d-4720-8775-427b3832c590@u18g2000pro.googlegroups.com> <7x63iwg2wg.fsf@ruckus.brouhaha.com> <6f52f838-d435-40b8-865e-55f3aed1bb1e@w24g2000prd.googlegroups.com> <5a96c945-7b61-4dba-af20-a324fd3b3394@z9g2000yqi.googlegroups.com> <7xfxi08da9.fsf@ruckus.brouhaha.com> <3d0a5145-2202-418a-97cc-cbe9c04def16@h5g2000yqh.googlegroups.com> Message-ID: <9c2718dd-ee86-47d8-a47f-98c92b6a772e@d19g2000yqb.googlegroups.com> Steve Holden: > A sort of premature pessimization, then. Maybe not, the save in memory may lead to higher speed anyway. So you need to test it to know the overall balance. And in data structures with general purpose you want all the speed you can get. Bye, bearophile From support.desk.ipg at gmail.com Fri Feb 27 10:19:35 2009 From: support.desk.ipg at gmail.com (Support Desk) Date: Fri, 27 Feb 2009 09:19:35 -0600 Subject: Capture Keystrokes from a USB Wireless Keyboard. In-Reply-To: <49A8021E.10200@councilforeconed.org> References: <3C62F42D051F490FB51503F50DFEB282@office.ipglobal.net> <49A8021E.10200@councilforeconed.org> Message-ID: Thanks, I'm looking for something I can integrate into a simple game I'm working on that will run in Linux. -----Original Message----- From: Shane Geiger [mailto:sgeiger at councilforeconed.org] Sent: Friday, February 27, 2009 9:09 AM To: Support Desk Cc: python-list at python.org Subject: Re: Capture Keystrokes from a USB Wireless Keyboard. Here's one option: http://pykeylogger.sourceforge.net/wiki/index.php/PyKeylogger:FAQ Support Desk wrote: > Does anybody know of a way to capture keystrokes form a wireless USB > keyboard using python? > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Shane Geiger, IT Director Council For Economic Education / www.councilforeconed.org sgeiger at councilforeconed.org / 402-438-8958 Teaching Opportunity From vlastimil.brom at gmail.com Fri Feb 27 10:19:55 2009 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Fri, 27 Feb 2009 16:19:55 +0100 Subject: starting a Python 2.5 executable without the DOS window In-Reply-To: <228d17df0902270624i2a463b40u6c245077afe48a7c@mail.gmail.com> References: <40fb0b57-84de-406c-833a-8eaf3a0b921a@e1g2000pra.googlegroups.com> <9fdb569a0902270621r279e7fb7kf75281d74a8415a2@mail.gmail.com> <228d17df0902270624i2a463b40u6c245077afe48a7c@mail.gmail.com> Message-ID: <9fdb569a0902270719y40e9d2c2m2385e5b75d94cfb1@mail.gmail.com> >> 2009/2/27 Greg Miller : >> > I am working on a program that controls a piece of equipment. ?The GUI/ >> > control software is written with Python2.5/wxPython. ?I would like to >> > know if there is a way of starting the GUI without the DOS window >> > having to launch? ?I would like only the application itself to appear, >> > no DOS window. ?Thanks for any information. >> > Greg Miller >> > -- 2009/2/27 Greg Miller : > Sorry, I should have been a bit more specific, it is an executable, .exe, > application created with PytoExe. > Ok, then you can adjust your setup script for py2exe to contain setup(windows=["sourcefile.py"] ... ) instead of setup(console=["sourcefile.py"] ...) which you probably have now. hth, vbr From digitig at gmail.com Fri Feb 27 10:33:54 2009 From: digitig at gmail.com (Tim Rowe) Date: Fri, 27 Feb 2009 15:33:54 +0000 Subject: removing duplication from a huge list. In-Reply-To: References: <269329b40902261237j2815c8a2x80d7469abba1e1e6@mail.gmail.com> Message-ID: 2009/2/27 odeits : > How big of a list are we talking about? If the list is so big that the > entire list cannot fit in memory at the same time this approach wont > work e.g. removing duplicate lines from a very large file. We were told in the original question: more than 15 million records, and it won't all fit into memory. So your observation is pertinent. -- Tim Rowe From steven.oldner at gmail.com Fri Feb 27 10:35:08 2009 From: steven.oldner at gmail.com (steven.oldner) Date: Fri, 27 Feb 2009 07:35:08 -0800 (PST) Subject: ANN: updates to Python-by-example References: <379a7319-376d-4486-954a-fc7035b0deb9@j38g2000yqa.googlegroups.com> Message-ID: <49ff5759-61da-4de2-a226-5f34cd6b324d@x13g2000yqf.googlegroups.com> On Feb 27, 8:40?am, pyt... at bdurham.com wrote: > Rainy, > > Great stuff! Thanks for your examples with the community!! > > Regards, > Malcolm Let me add my thanks! I using it now... From stefan_ml at behnel.de Fri Feb 27 10:38:31 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 27 Feb 2009 16:38:31 +0100 Subject: How to parse form in client side? In-Reply-To: References: Message-ID: <49a808f7$0$32681$9b4e6d93@newsspool2.arcor-online.net> Muddy Coder wrote: > cgi module can easily acquire the all fields of data input from client > side, through a form. Then, a simple line of code: > > form_dict = cgi.FieldStorage() > > grabs all data into a dictionary form_dict. The rest becomes a piece > of cake by querying the form_dict. Nice! > > However, it is done in the server side. Now I want to do the same in > the client side. first of all, I get the source code of a HTML form by > using urllib, from server, with code below: > > html_source = urllib.urlopen(URL).read() > > Then, I need to parse this html_source file, at client side. Is there > a module to handle this? Can somebody help? Thanks! lxml.html has good form handling support: http://codespeak.net/lxml/lxmlhtml.html#forms Stefan From lilhedges69 at yahoo.com Fri Feb 27 11:07:03 2009 From: lilhedges69 at yahoo.com (Brett Hedges) Date: Fri, 27 Feb 2009 08:07:03 -0800 (PST) Subject: Using xreadlines In-Reply-To: <82c7db91-fb61-491e-9ff5-38761c3424e9@g38g2000yqd.googlegroups.com> Message-ID: <830721.69929.qm@web30703.mail.mud.yahoo.com> > You can also keep track of the absolute position of the lines in the file, etc, or step back looking for newlines, etc, but it's not handy. How would I keep track of the absolute position of the lines? I have tried to use the files.seek() command with the files.tell() command and it does not seem to work. The files.tell() command seems to give me a number but when I use the files.next() command with xreadlines it does not change the line number the next time I use files.tell(). Thanks, Brett --- On Thu, 2/26/09, bearophileHUGS at lycos.com wrote: > From: bearophileHUGS at lycos.com > Subject: Re: Using xreadlines > To: python-list at python.org > Date: Thursday, February 26, 2009, 8:09 PM > Brett Hedges: > > My question is how do I go to a previous line in the > file? xreadlines has a file.next() statement that gives the > next line, and I need a statement that gives me the previous > line.< > > In modern versions of Python you usually don't need > xreadlines, > because files are iterable. > > If your files are small, you can just read all the lines in > a list > with open(...).readlines(), and then just use the item of > the list > with the n-1 index. > > If the file is quite large or you like to keep things lazy, > then you > have to keep memory of the previous line, using an > auxiliary variable. > You can also wrap this idiom into a generator function (or > iterable > class, probably) that yields items and keeps memory of the > last one > (but you can't ask the previous of the first item, of > course). > > You can also keep track of the absolute position of the > lines in the > file, etc, or step back looking for newlines, etc, but > it's not handy. > > Bye, > bearophile > -- > http://mail.python.org/mailman/listinfo/python-list From clp2 at rebertia.com Fri Feb 27 11:43:15 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 27 Feb 2009 08:43:15 -0800 Subject: Make a python property with the same name as the class member name In-Reply-To: References: Message-ID: <50697b2c0902270843j5d0dce8flafcdd7b7494474b2@mail.gmail.com> On Fri, Feb 27, 2009 at 5:59 AM, Ravi wrote: > Is it possible in python to create a property with the same name as > the member variable name of the class. e.g. No, because accessing the property and the instance variable are *syntactically identical* (it's the raison detre of properties) so there's no way for Python to know which one you mean when. Typically, people name the variable used internally by the property as an underscore followed by the property name (e.g. self._i). > Class X: > ? ?... > ? ?self.i = 10 # marker > ? ?... > ? ?property(fget = get_i, fset = set_i) Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com From bearophileHUGS at lycos.com Fri Feb 27 11:43:43 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Fri, 27 Feb 2009 08:43:43 -0800 (PST) Subject: Using xreadlines References: Message-ID: Brett Hedges: > How would I keep track of the absolute position of the lines? You may have to do all things manually (tell, seek and looking for newlines manually, iterating chars), that's why I have said it's not handy. The other solutions are simpler. Bye, bearophile From garrickp at gmail.com Fri Feb 27 11:55:50 2009 From: garrickp at gmail.com (Falcolas) Date: Fri, 27 Feb 2009 08:55:50 -0800 (PST) Subject: removing duplication from a huge list. References: <269329b40902261237j2815c8a2x80d7469abba1e1e6@mail.gmail.com> Message-ID: <50551f16-066d-4eac-a060-9d4c096f1480@v1g2000prd.googlegroups.com> On Feb 27, 8:33?am, Tim Rowe wrote: > 2009/2/27 odeits : > > > How big of a list are we talking about? If the list is so big that the > > entire list cannot fit in memory at the same time this approach wont > > work e.g. removing duplicate lines from a very large file. > > We were told in the original question: more than 15 million records, > and it won't all fit into memory. So your observation is pertinent. > > -- > Tim Rowe If order did matter, and the list itself couldn't be stored in memory, I would personally do some sort of hash of each item (or something as simple as first 5 bytes, last 5 bytes and length), keeping a reference to which item the hash belongs, sort and identify duplicates in the hash, and using the reference check to see if the actual items in question match as well. Pretty brutish and slow, but it's the first algorithm which comes to mind. Of course, I'm assuming that the list items are long enough to warrant using a hash and not the values themselves. ~G From mkhitrov at gmail.com Fri Feb 27 12:00:50 2009 From: mkhitrov at gmail.com (Maxim Khitrov) Date: Fri, 27 Feb 2009 12:00:50 -0500 Subject: What functions, other than sleep(), can be interrupted by Ctrl-C? In-Reply-To: References: <26ddd1750902261017o7ec519ey2af03b1be2809cdb@mail.gmail.com> Message-ID: <26ddd1750902270900s5fc3d3aq3b8565acd2d95b98@mail.gmail.com> On Thu, Feb 26, 2009 at 3:47 PM, Gabriel Genellina wrote: >> I'm looking for a function in the standard library or pywin32 package >> that will block until a certain condition is met or it is interrupted >> by Ctrl-C. For example, time.sleep() would have been perfect for my >> needs if thread.interrupt_main() could interrupt the call from another >> thread in the same way that Ctrl-C does. Unfortunately, that is not >> the case. > > You may try MsgWaitForMultipleObjects - send a message to the main thread > from the other thread. > An alertable wait (like SleepEx) plus QueueUserAPC should work, I presume, > but I've never actually tried in Python. I tried using MsgWaitForMultipleObjects, but even with a wake mask of 0xffff Ctrl-C still did not interrupt the call. Maybe it has to do with the way pywin32 implements it. QueueUserAPC is not available in pywin32, but I suppose I can try getting to it via ctypes. - Max From starsareblueandfaraway at gmail.com Fri Feb 27 12:03:38 2009 From: starsareblueandfaraway at gmail.com (Roy H. Han) Date: Fri, 27 Feb 2009 12:03:38 -0500 Subject: Using xreadlines In-Reply-To: References: Message-ID: <6a5569ec0902270903p1f2f6a54ta2bc7502565d3561@mail.gmail.com> Brett, I'm not sure what exactly you're trying to do, but you can keep track of line numbers using itertools. import itertools for lineIndex, line in itertools.izip(itertools.count(1), open('text.txt')): print lineIndex, line Here is sample code for breaking on a word and returning the previous line def breakOnWord(filePath, word): previousLine = '' for line in open(filePath): if word in line: return previousLine previousLine = line On Fri, Feb 27, 2009 at 11:43 AM, wrote: > Brett Hedges: >> How would I keep track of the absolute position of the lines? > > You may have to do all things manually (tell, seek and looking for > newlines manually, iterating chars), that's why I have said it's not > handy. The other solutions are simpler. > > Bye, > bearophile > -- > http://mail.python.org/mailman/listinfo/python-list > From steve at holdenweb.com Fri Feb 27 12:07:41 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 27 Feb 2009 12:07:41 -0500 Subject: removing duplication from a huge list. In-Reply-To: <50551f16-066d-4eac-a060-9d4c096f1480@v1g2000prd.googlegroups.com> References: <269329b40902261237j2815c8a2x80d7469abba1e1e6@mail.gmail.com> <50551f16-066d-4eac-a060-9d4c096f1480@v1g2000prd.googlegroups.com> Message-ID: Falcolas wrote: > On Feb 27, 8:33 am, Tim Rowe wrote: >> 2009/2/27 odeits : >> >>> How big of a list are we talking about? If the list is so big that the >>> entire list cannot fit in memory at the same time this approach wont >>> work e.g. removing duplicate lines from a very large file. >> We were told in the original question: more than 15 million records, >> and it won't all fit into memory. So your observation is pertinent. >> >> -- >> Tim Rowe > > If order did matter, and the list itself couldn't be stored in memory, > I would personally do some sort of hash of each item (or something as > simple as first 5 bytes, last 5 bytes and length), keeping a reference > to which item the hash belongs, sort and identify duplicates in the > hash, and using the reference check to see if the actual items in > question match as well. > Assuming no duplicates, how does this help? You still have to verify collisions. > Pretty brutish and slow, but it's the first algorithm which comes to > mind. Of course, I'm assuming that the list items are long enough to > warrant using a hash and not the values themselves. > The problem is you can't guarantee any hash value will be unique, so ultimately you have to check whether list entries hashing to the same value are or are not equal. Which would mean either having the whole list in memory or having access to it via some other random access method. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From Scott.Daniels at Acm.Org Fri Feb 27 12:20:19 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 27 Feb 2009 09:20:19 -0800 Subject: Using xreadlines In-Reply-To: References: Message-ID: (1) Please do not top post in comp.lang.python, it violates conventions. Brett Hedges (should have written): > bearophile wrote: ... >> You can also keep track of the absolute position of the lines in the file, etc, or step >> back looking for newlines, etc, but it's not handy.... > > How would I keep track of the absolute position of the lines? > I have tried to use the files.seek() command with the files.tell() > command and it does not seem to work. The files.tell() command seems > to give me a number but when I use the files.next() command with > xreadlines it does not change the line number the next time I use > files.tell(). The answer to your question depends on what version of Python you are running. Give python version and platform to any question when you don't _know_ they are irrelevant. If you want an answer without any other input, try this: The simplest way to solve this for the moment is (re)defining xreadlines: def xreadlines(source): for line in iter(src.readline, ''): yield line --Scott David Daniels Scott.Daniels at Acm.Org From patrick.oloughlin at gmail.com Fri Feb 27 12:22:21 2009 From: patrick.oloughlin at gmail.com (Paddy O'Loughlin) Date: Fri, 27 Feb 2009 17:22:21 +0000 Subject: Run a python script as an exe and run a new process from it In-Reply-To: References: Message-ID: 2009/2/27 venutaurus539 at gmail.com : > Thanks for the reply,, > ? ? ? ? ? ?I am trying to use the above application using psexec()in > command line.But it failed returning the error message > > ?exited with error code 255. > > ? ? ? ? ? ? ?But when I ran the application normally it worked > fine.Do I need to add anything to my python script(either the main one > or the script which is calling it) to make it work. I don't have any experience with psexec, so I'm not sure if I can help you with that. I assume this means that you are trying to run the script on a remote computer? (Elsewise, why use psexec?) I took a look at it though and it seems that it always exits with *some* error code. I think it's more usual for that error code to be zero, though (it does when I run it on my machine). You might try "psexec start script1.py", which might work if you've successfully set Explorer to run .py files with python.exe when you double-click on them. "psexec python script1.py" will work if the python.exe is in the correct path. You can also specify the full path to your python.exe. if you know it e.g.: "psexec C:\python25\python.exe script1.py" -- "Ray, when someone asks you if you're a god, you say YES!" From python.list at tim.thechases.com Fri Feb 27 12:30:45 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 27 Feb 2009 11:30:45 -0600 Subject: removing duplication from a huge list. In-Reply-To: References: <269329b40902261237j2815c8a2x80d7469abba1e1e6@mail.gmail.com> Message-ID: <49A82345.1040101@tim.thechases.com> >> How big of a list are we talking about? If the list is so big that the >> entire list cannot fit in memory at the same time this approach wont >> work e.g. removing duplicate lines from a very large file. > > We were told in the original question: more than 15 million records, > and it won't all fit into memory. So your observation is pertinent. Assuming the working set of unique items will still fit within memory, it can be done with the following regardless of the input-file's size: def deduplicator(iterable): seen = set() for item in iterable: if item not in seen: seen.add(item) yield item s = [7,6,5,4,3,6,9,5,4,3,2,5,4,3,2,1] print list(deduplicator(s)) for line in deduplicator(file('huge_test.txt')): print line It maintains order, emitting only new items as they're encountered. -tkc From ethan at stoneleaf.us Fri Feb 27 12:34:11 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 27 Feb 2009 09:34:11 -0800 Subject: pep 8 constants In-Reply-To: References: <4978DD2E.1090008@aim.com> <49A49644.80509@stoneleaf.us> Message-ID: <49A82413.8080609@stoneleaf.us> Steve Holden wrote: > Gabriel Genellina wrote: > >>En Tue, 24 Feb 2009 22:52:20 -0200, Ethan Furman >>escribi?: >> >> >>>Steve Holden wrote: >>> >>>>Brian Allen Vanderburg II wrote: >>>> >>>> >>>>>One idea to make constants possible would be to extend properties to be >>>>>able to exist at the module level as well as the class level: >>>>> >>>>>@property >>>>>def pi(): >>>>> return 3.14159..... >>>>> >>>>>print(pi) # prints 3.14159.... >>>>>pi=32 # Raise an error Cannot set attribute ... >>>>> >>>> >>>> I don't understand why this would print 3.14159 ... instead of >>>>>>>__math__.pi>, or whatever. >>>> property would clearly have to do something very different in module >>>>scope in order to make this work. >>>> regards >>>> Steve >>> >>>--> class tester(object): >>>... @property >>>... def pi(self): >>>... return 3.141596 >>>... >>>--> testee = tester() >>>--> testee.pi >>>3.1415959999999998 >>> >>>Looks like that's how property works, so the same behavior on a module >>>level would do as Brian suggests. >> >>Note that: >> - you defined the property inside the *class* tester >> - then, you created an *instance* of such class >> - you retrieve pi from the instance >> - if you retrieve pi from the class (tester.pi), you get a property >>object, not a float. >> - if you directly attach the property to the instance, testee.pi >>returns a property object, not a float. >>Finally, consider that modules are instances of type `module`; all >>modules are instances of the same type. >> >>How do you propose to make properties work at the module level? >> > > Thanks, Gabriel. I was beginning to think there was something terribly > obvious I had completely missed. > > regards > Steve Yes, Thanks, Gabriel! You're extra comments made clarified the issue for me. Much appreciated. ~Ethan~ From pcooke at philc.net Fri Feb 27 12:35:06 2009 From: pcooke at philc.net (PhilC) Date: Fri, 27 Feb 2009 12:35:06 -0500 Subject: Marching Cubes example Message-ID: Does anyone know of sample code showing how the marching cubes algorithm may be implimented using Python? Ref:- http://local.wasp.uwa.edu.au/~pbourke/geometry/polygonise/ I can set up the cubes and test to see if their vertices are inside the isosurface. I can produce a resulting "metaball" but definition is poor and some faces are reversed. (but not in any pattern that I can effectivly debug). My particular issues are:- 1) Finding the point at which the isosurface cuts the cube being tested. Using a mid point produces poor results. 2) Getting the resulting triangular faces to all face outwards. I'd prefer not to get into using VTK or matlab if possible. Thanks :) From digitig at gmail.com Fri Feb 27 12:54:21 2009 From: digitig at gmail.com (Tim Rowe) Date: Fri, 27 Feb 2009 17:54:21 +0000 Subject: removing duplication from a huge list. In-Reply-To: References: <269329b40902261237j2815c8a2x80d7469abba1e1e6@mail.gmail.com> <50551f16-066d-4eac-a060-9d4c096f1480@v1g2000prd.googlegroups.com> Message-ID: 2009/2/27 Steve Holden : > Assuming no duplicates, how does this help? You still have to verify > collisions. > >> Pretty brutish and slow, but it's the first algorithm which comes to >> mind. Of course, I'm assuming that the list items are long enough to >> warrant using a hash and not the values themselves. >> > The problem is you can't guarantee any hash value will be unique, so > ultimately you have to check whether list entries hashing to the same > value are or are not equal. Which would mean either having the whole > list in memory or having access to it via some other random access method. You don't need random access to the whole list, just to the records that collide on a hash. although you do end up using the external storage as random access, which can be very slow, you've possibly drastically reduced the number of such random accesses, which should be a big saving. The best case is if the number of collisions is low enough for the random access to be dealt with in buffering, avoiding wasteful seeks of the external storage, in which case it's a complete win. Remember that if the identical hashes are not collisions but genuine duplicates you can throw them away as soon as they're checked, so with some clever buffering you can stop them from clogging up the buffer. The worst case is if there are a lot of genuine collisions, in which case it's probably not a very good hash. -- Tim Rowe From daniel.watrous at gmail.com Fri Feb 27 13:14:35 2009 From: daniel.watrous at gmail.com (Daniel) Date: Fri, 27 Feb 2009 10:14:35 -0800 (PST) Subject: starting a Python 2.5 executable without the DOS window References: <40fb0b57-84de-406c-833a-8eaf3a0b921a@e1g2000pra.googlegroups.com> <9fdb569a0902270621r279e7fb7kf75281d74a8415a2@mail.gmail.com> <228d17df0902270624i2a463b40u6c245077afe48a7c@mail.gmail.com> Message-ID: <87db03a9-e384-4c33-9965-6f5c4f787b65@p11g2000yqe.googlegroups.com> On Feb 27, 8:19?am, Vlastimil Brom wrote: > >> 2009/2/27 Greg Miller : > >> > I am working on a program that controls a piece of equipment. ?The GUI/ > >> > control software is written with Python2.5/wxPython. ?I would like to > >> > know if there is a way of starting the GUI without the DOS window > >> > having to launch? ?I would like only the application itself to appear, > >> > no DOS window. ?Thanks for any information. > >> > Greg Miller > >> > -- > > 2009/2/27 Greg Miller : > > > Sorry, I should have been a bit more specific, it is an executable, .exe, > > application created with PytoExe. > > Ok, then you can adjust your setup script for py2exe to contain > > setup(windows=["sourcefile.py"] ... ) > > instead of > > setup(console=["sourcefile.py"] ...) which you probably have now. > > hth, > ? vbr Just giving it the .pyw extension also seems to work (as I remember) From alecla at bluewin.ch Fri Feb 27 13:39:55 2009 From: alecla at bluewin.ch (alex) Date: Fri, 27 Feb 2009 10:39:55 -0800 (PST) Subject: TextCtrl fully expanding at program start References: Message-ID: On 27 Feb., 15:14, Vlastimil Brom wrote: > 2009/2/27 alex : > > > Hi all > > I have a gridsizer consisting of two vertically stacked panels, one > > with a StaticBox and the other with a TextCtrl. > > I would like that the TextCtrl expands at program start fully to the > > allocated panel size (lower panel of gridSizer). > > Instead of like now, fully expanding in the width but not exapnding in > > the height direction (two lines high). > ... > > Hi, > changing the proportion for adding the textctrl into the sizer to 1 > should expand it to the lower half of the panel. > > try changing: > ? ? ? ? windowTwoSizer.Add(box2, 0, wx.ALL|wx.EXPAND, 0) > TO: > ? ? ? ? windowTwoSizer.Add(box2, 1, wx.ALL|wx.EXPAND, 0) > > Seehttp://www.wxpython.org/docs/api/wx.Sizer-class.html#Add > for the options for adding into the sizer. > > hth > ? ?vbr Hi Vlastimil I must have overlooked it. Too much reading and trying... Thank you, it works perfect. Regards Alex From garrickp at gmail.com Fri Feb 27 15:01:29 2009 From: garrickp at gmail.com (Falcolas) Date: Fri, 27 Feb 2009 12:01:29 -0800 (PST) Subject: removing duplication from a huge list. References: <269329b40902261237j2815c8a2x80d7469abba1e1e6@mail.gmail.com> <50551f16-066d-4eac-a060-9d4c096f1480@v1g2000prd.googlegroups.com> Message-ID: <364a986d-ec91-4bd2-873b-9adf3701ba61@z6g2000pre.googlegroups.com> On Feb 27, 10:07?am, Steve Holden wrote: > Assuming no duplicates, how does this help? You still have to verify > collisions. Absolutely. But a decent hashing function (particularly since you know quite a bit about the data beforehand) will have very few collisions (theoretically no collisions, again since we know the data beforehand). > The problem is you can't guarantee any hash value will be unique, so > ultimately you have to check whether list entries hashing to the same > value are or are not equal. Which would mean either having the whole > list in memory or having access to it via some other random access method. Again, absolutely. But as Tim pointed out, with a decent hash the number of superfluous checks should be minimal, so your checks will mostly occur on valid duplicate values. It's worth noting that I picked this algorithm with the assumption that any storage to physical memory (such as required by using a set) would be out of the question. ~G From rpdooling at gmail.com Fri Feb 27 15:04:15 2009 From: rpdooling at gmail.com (Rick Dooling) Date: Fri, 27 Feb 2009 12:04:15 -0800 (PST) Subject: Data Coding suggestions References: Message-ID: <477a8bf4-1b3e-4708-affe-7aaef1ac1691@w34g2000yqm.googlegroups.com> On Feb 27, 6:42?am, "steven.oldner" wrote: > Just learning Python and have a project to create a weekly menu and a > shopping list from the menu. ? > Question: ?How should I set up the data? ?I'm looking at maybe 70 menu > items and maybe 1000 items for the shopping list. ?I need to be able > to maintain each item also. > I agree with Mr. Holden. It's a perfect exercise for using Python with sqlite3. And the nice thing about this documentation is it has plenty of good examples: http://docs.python.org/library/sqlite3.html Good luck, RD From starsareblueandfaraway at gmail.com Fri Feb 27 15:04:43 2009 From: starsareblueandfaraway at gmail.com (Roy H. Han) Date: Fri, 27 Feb 2009 15:04:43 -0500 Subject: Using xreadlines In-Reply-To: References: Message-ID: <6a5569ec0902271204j39c86ff9hdf3464918d7a5d93@mail.gmail.com> On Fri, Feb 27, 2009 at 12:20 PM, Scott David Daniels wrote: > (1) Please do not top post in comp.lang.python, it violates conventions. > > Brett Hedges (should have written): >> bearophile wrote: ... >>> >>> You can also keep track of the absolute position of the lines in the >>> file, etc, or step > >>> back looking for newlines, etc, but it's not handy.... >> >> How would I keep track of the absolute position of the lines? > >> I have tried to use the files.seek() command with the files.tell() >> command and it does not seem to work. The files.tell() command seems >> ?to give me a number but when I use the files.next() command with >> xreadlines it does not change the line number the next time I use >> files.tell(). > > The answer to your question depends on what version of Python you are > running. ?Give python version and platform to any question when you > don't _know_ they are irrelevant. > > If you want an answer without any other input, try this: > > The simplest way to solve this for the moment is (re)defining > xreadlines: > > ? ?def xreadlines(source): > ? ? ? ?for line in iter(src.readline, ''): > ? ? ? ? ? ?yield line > > --Scott David Daniels > Scott.Daniels at Acm.Org > -- > http://mail.python.org/mailman/listinfo/python-list > Sorry for top-posting. http://en.wikipedia.org/wiki/Posting_style From steve at holdenweb.com Fri Feb 27 15:31:51 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 27 Feb 2009 15:31:51 -0500 Subject: removing duplication from a huge list. In-Reply-To: <364a986d-ec91-4bd2-873b-9adf3701ba61@z6g2000pre.googlegroups.com> References: <269329b40902261237j2815c8a2x80d7469abba1e1e6@mail.gmail.com> <50551f16-066d-4eac-a060-9d4c096f1480@v1g2000prd.googlegroups.com> <364a986d-ec91-4bd2-873b-9adf3701ba61@z6g2000pre.googlegroups.com> Message-ID: Falcolas wrote: > On Feb 27, 10:07 am, Steve Holden wrote: >> Assuming no duplicates, how does this help? You still have to verify >> collisions. > > Absolutely. But a decent hashing function (particularly since you know > quite a bit about the data beforehand) will have very few collisions > (theoretically no collisions, again since we know the data > beforehand). > >> The problem is you can't guarantee any hash value will be unique, so >> ultimately you have to check whether list entries hashing to the same >> value are or are not equal. Which would mean either having the whole >> list in memory or having access to it via some other random access method. > > Again, absolutely. But as Tim pointed out, with a decent hash the > number of superfluous checks should be minimal, so your checks will > mostly occur on valid duplicate values. > > It's worth noting that I picked this algorithm with the assumption > that any storage to physical memory (such as required by using a set) > would be out of the question. > I take your point about the relatively rare collisions. Devising a zero-collision algorithm is far from trivial, since at the minimum it requires storing all hashes in a set to verify each new hash doesn't collide with previous ones. But unless you can *guarantee* zero collisions you do still need a mapping from hash values to the original data, since this is the only way to determine whether collisions represent a duplicate value or not. That's not a trivial detail for fifteen million values, though it depends some on the format of the OP's "records". I suppose a list of file positions stored with each hash might be usable assuming either fixed-length or properly delimited records. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From fredbasset1000 at gmail.com Fri Feb 27 15:54:58 2009 From: fredbasset1000 at gmail.com (fredbasset1000 at gmail.com) Date: Fri, 27 Feb 2009 12:54:58 -0800 (PST) Subject: Define a constant in Python C extension Message-ID: <22eda701-7048-458c-9e56-80bafbbcb81f@z6g2000pre.googlegroups.com> I'm writing a C extension for Python, is it possible to define constants in the C code and have them visible from Python? From robert.kern at gmail.com Fri Feb 27 16:03:39 2009 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 27 Feb 2009 15:03:39 -0600 Subject: Define a constant in Python C extension In-Reply-To: <22eda701-7048-458c-9e56-80bafbbcb81f@z6g2000pre.googlegroups.com> References: <22eda701-7048-458c-9e56-80bafbbcb81f@z6g2000pre.googlegroups.com> Message-ID: On 2009-02-27 14:54, fredbasset1000 at gmail.com wrote: > I'm writing a C extension for Python, is it possible to define > constants in the C code and have them visible from Python? In your init function, create Python objects from the constants and insert them into the module using PyModule_AddObject(). The initspam() function in this section does this (though not with #defined constants): http://docs.python.org/extending/extending.html#providing-a-c-api-for-an-extension-module -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From mwilson at the-wire.com Fri Feb 27 16:15:18 2009 From: mwilson at the-wire.com (Mel) Date: Fri, 27 Feb 2009 16:15:18 -0500 Subject: Define a constant in Python C extension References: <22eda701-7048-458c-9e56-80bafbbcb81f@z6g2000pre.googlegroups.com> Message-ID: fredbasset1000 at gmail.com wrote: > I'm writing a C extension for Python, is it possible to define > constants in the C code and have them visible from Python? There's an API function to create a module-level name with a given value, e.g. PyModule_AddIntConstant (module, "S_IRUSR", S_IRUSR); // user read In this example, S_IRUSR was defined in one of the .h files for the functions being wrapped. Mel. From ntwrkd at gmail.com Fri Feb 27 17:08:22 2009 From: ntwrkd at gmail.com (ntwrkd) Date: Fri, 27 Feb 2009 14:08:22 -0800 Subject: Guidance on writing a top-like console Message-ID: I am interested in writing an application that functions like a Unix or Linux top in the way it displays data. It should be command-line based but dynamically refreshing. I'm not sure what I should take into account or how I might go about implementing this? Any suggestions are appreciated. From http Fri Feb 27 17:18:36 2009 From: http (Paul Rubin) Date: 27 Feb 2009 14:18:36 -0800 Subject: removing duplication from a huge list. References: <269329b40902261237j2815c8a2x80d7469abba1e1e6@mail.gmail.com> Message-ID: <7xprh3ikw3.fsf@ruckus.brouhaha.com> Tim Rowe writes: > We were told in the original question: more than 15 million records, > and it won't all fit into memory. So your observation is pertinent. That is not terribly many records by today's standards. The knee-jerk approach is to sort them externally, then make a linear pass skipping the duplicates. Is the exercise to write an external sort in Python? It's worth doing if you've never done it before. From http Fri Feb 27 17:19:24 2009 From: http (Paul Rubin) Date: 27 Feb 2009 14:19:24 -0800 Subject: Guidance on writing a top-like console References: Message-ID: <7xljrrikur.fsf@ruckus.brouhaha.com> ntwrkd writes: > I'm not sure what I should take into account or how I might go about > implementing this? Maybe the curses module. http://docs.python.org/library/curses.html From kyosohma at gmail.com Fri Feb 27 17:20:27 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Fri, 27 Feb 2009 14:20:27 -0800 (PST) Subject: Guidance on writing a top-like console References: Message-ID: <3cd95fd8-c975-425f-b01a-141bad52b408@q11g2000yqh.googlegroups.com> On Feb 27, 4:08?pm, ntwrkd wrote: > I am interested in writing an application that functions like a Unix > or Linux top in the way it displays data. > It should be command-line based but dynamically refreshing. > > I'm not sure what I should take into account or how I might go about > implementing this? > Any suggestions are appreciated. Perhaps you're looking for the curses module? http://www.amk.ca/python/howto/curses/ Mike From python.list at tim.thechases.com Fri Feb 27 17:35:14 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 27 Feb 2009 16:35:14 -0600 Subject: Guidance on writing a top-like console In-Reply-To: References: Message-ID: <49A86AA2.30304@tim.thechases.com> > I am interested in writing an application that functions like a Unix > or Linux top in the way it displays data. > It should be command-line based but dynamically refreshing. You might look at the sourcecode for "iotop"[1] which would make a good example (it's a "top"-like program written in Python, used for monitoring I/O transactions on a per-process basis) -tkc [1] http://guichaz.free.fr/iotop/ From ntwrkd at gmail.com Fri Feb 27 17:38:59 2009 From: ntwrkd at gmail.com (ntwrkd) Date: Fri, 27 Feb 2009 14:38:59 -0800 Subject: Guidance on writing a top-like console In-Reply-To: <49A86AA2.30304@tim.thechases.com> References: <49A86AA2.30304@tim.thechases.com> Message-ID: Thanks. These are all great suggestions. On Fri, Feb 27, 2009 at 2:35 PM, Tim Chase wrote: >> I am interested in writing an application that functions like a Unix >> or Linux top in the way it displays data. >> It should be command-line based but dynamically refreshing. > > You might look at the sourcecode for "iotop"[1] which would make a good > example (it's a "top"-like program written in Python, used for monitoring > I/O transactions on a per-process basis) > > -tkc > > > [1] > http://guichaz.free.fr/iotop/ > > > > > > From mmcclaf at gmail.com Fri Feb 27 18:39:13 2009 From: mmcclaf at gmail.com (mmcclaf) Date: Fri, 27 Feb 2009 15:39:13 -0800 (PST) Subject: Queries References: Message-ID: This came in the Python groups, and I put one up in the database group, since I will later have to use Python to access the SQL file, so therefore tackling one thing at a time. Also, there were no answers that were coming up in the .database group. On top of that: > Really? You can have ships in the Outcomes relation that DO NOT >APPEAR in the Ships relation... Goodbye referential integrity. > > Besides which, if they don't appear in the Ships relation, then >there is NO INFORMATION to tell you what ship CLASS it is a member of -- >do you group them all as "UNKNOWN" class, or do you declare each to be >the only ship of its class (and thereby use the ship name as the class >name)? This meant that some ships weren't listed in the Ship table provided but did show up in the Outcome. Therefore, they are not directly referenced one to the other. > Another gmail user found only by back referencing responses... What is meant by this statement? So in short of the responses given, I need to study further: GROUP BY, HAVING, AS, COUNT, and subselect queries, right? The relational algebra, I am able to translate it into SQL, or most of it, meaning turning it into the queries of SQL. This is not an advanced database course, but more a basic intro to database systems. From vinay_sajip at yahoo.co.uk Fri Feb 27 18:48:39 2009 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Fri, 27 Feb 2009 15:48:39 -0800 (PST) Subject: logging.Handler not working with QThreads References: Message-ID: On Feb 25, 11:57?pm, Lukas Hetzenecker wrote: > Hello, > > I created a QTextEdit where I wanted to display log messages. > A logging.Handler should do this job. > > It worked with one thread well, but when I start a QThread the text on all > widgets is removed and I get many errors in my konsole: > > X Error: RenderBadGlyphSet (invalid GlyphSet parameter) 177 > ? Extension: ? ?152 (RENDER) > ? Minor opcode: 25 (RenderCompositeGlyphs32) > ? Resource id: ?0x0 > X Error: RenderBadGlyphSet (invalid GlyphSet parameter) 177 > ? Extension: ? ?152 (RENDER) > ? Minor opcode: 25 (RenderCompositeGlyphs32) > ? Resource id: ?0x0 > X Error: RenderBadGlyphSet (invalid GlyphSet parameter) 177 > ? Extension: ? ?152 (RENDER) > ? Minor opcode: 25 (RenderCompositeGlyphs32) > ? Resource id: ?0x0 > > .. and so on > > I attatched a small example to this mail. > > Could anybody tell me what I'm doing wrong? > Thanks for you help, > Lukas > > ?logging_error.py > 3KViewDownload I'm not sure what exactly your problem is - I had no problem running a slightly modified version of your script. I don't have a version of Qt with a QPlainTextEdit, so I used a plain QTextEdit instead ('scuse the play on words). I also modified the thread run method slightly, like so... def run(self): s = self.currentThreadId() for i in range(10): self.log.info("Thread %s (%d)", s, i) self.sleep(1) With these changes (and replacing the appendPlainText with just plain append, the script worked fine. I was able to get messages from multiple running threads and the main window/log window into the single QTextEdit. My testing was conducted on Kubuntu Hardy with SIP 4.7.9 and PyQt 4.4.4. The modified script is at http://dpaste.com/hold/2947/ Best regards, Vinay Sajip From ethan at stoneleaf.us Fri Feb 27 18:55:43 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 27 Feb 2009 15:55:43 -0800 Subject: why cannot assign to function call In-Reply-To: References: <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <0178651d$0$8693$c3e8da3@news.astraweb.com> Message-ID: <49A87D7F.8090500@stoneleaf.us> Mark Wooding wrote: > Steven D'Aprano wrote: > >>On the one hand, some people (me and possibly rurpy) consider "this is >>pass-by-foo" to be a statement about behaviour directly visible to the >>programmer. We have a set of behavioral traits in mind, and if a language >>exhibits those behaviours, then it is clearly and obviously pass-by-foo >>no matter how that behaviour is implemented. I'll call these the >>behaviorists. > > Here's the problem. I think I'm in that camp too! > > I'm going to move away from the formal semantics stuff and try a > different tack. Here's what I think is the defining property of > pass-by-value (distilled from the formal approach I described earlier, > but shorn of the symbolism): > > The callee's parameters are /new variables/, initialized /as if by > assignment/ from the values of caller's argument expressions. > > My soundbite definition for pass-by-reference is this: > > The callee's parameters are merely /new names/ for the caller's > argument variables -- as far as that makes sense. > > There's a caveat there for argument expressions which don't correspond > directly to variables -- and I've glossed over the issue of lvalue > expressions which designate locations and all of that. Greetings, Mark! A little background on myself, hopefully making my soon-to-follow question less idiotic. I've been in the PC world for 20+ years now, and dabbled with programming through much of that time. I've written small utilities in Assembly (x86) and CL (AS/400), I just recently wrote a dbf module for python, and I've studied (in and out of the classroom) C, Fortran, Pascal, Java, Perl, Php, and Basic. While I have had some formal training, my degree is in Business (long story -- I would rather have done CS), and much of your explanation in previous posts was waaaaay over my head. I am in complete agreement with Steven's description of the behaviorist point of view for pass-by-value and pass-by-reference, and if asked I would say Python is pass-by-object. I offer this so you know where I'm coming from, not from any hostile motive. I was hoping you might be able to clarify those last two sound bites for me -- I think I understand what you are saying, but I'm confused about how they relate to Python... Specifically, how is a new name (pbr) different, in Python, from a new name initialized as if by assignment (pbv)? It seems to me than you end up with the same thing in either case (in Python, at least), making the distinction non-existent. def func(bar): bar.pop() Pass-by-reference: foo = ['Ethan','Furman'] func(foo) # bar = foo Pass-by-value: foo = ['Python','Rocks!'] func(foo) # bar is new name for foo # is this any different from above? If I have this right, in both cases foo will be reduced to a single-item list after func. Any further explanation you care to provide will be greatly appreciated! ~Ethan~ From rhodri at wildebst.demon.co.uk Fri Feb 27 19:08:30 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sat, 28 Feb 2009 00:08:30 -0000 Subject: why cannot assign to function call In-Reply-To: <49A87D7F.8090500@stoneleaf.us> References: <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <0178651d$0$8693$c3e8da3@news.astraweb.com> <49A87D7F.8090500@stoneleaf.us> Message-ID: On Fri, 27 Feb 2009 23:55:43 -0000, Ethan Furman wrote: I'm not Mark, but you did post to the whole group! [snippety snip] > Specifically, how is a new name (pbr) different, in Python, from a new > name initialized as if by assignment (pbv)? It seems to me than you end > up with the same thing in either case (in Python, at least), making the > distinction non-existent. > > def func(bar): > bar.pop() > > Pass-by-reference: > foo = ['Ethan','Furman'] > func(foo) # bar = foo > > Pass-by-value: > foo = ['Python','Rocks!'] > func(foo) # bar is new name for foo With true pass-by-value, this comment is not true. Bar would be a copy of foo, not a new name. What happens to bar is then not reflected in foo (depending on how deep the copy is), which is the objective of pass-by-value. -- Rhodri James *-* Wildebeeste Herder to the Masses From vinay_sajip at yahoo.co.uk Fri Feb 27 19:29:05 2009 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Fri, 27 Feb 2009 16:29:05 -0800 (PST) Subject: logging.Handler not working with QThreads References: Message-ID: On Feb 25, 11:57 pm, Lukas Hetzenecker wrote: > Hello, > > I created a QTextEdit where I wanted to display log messages. > A logging.Handler should do this job. > > It worked with one thread well, but when I start a QThread the text on all > widgets is removed and I get many errors in my konsole: > > X Error: RenderBadGlyphSet (invalid GlyphSet parameter) 177 > Extension: 152 (RENDER) > Minor opcode: 25 (RenderCompositeGlyphs32) > Resource id: 0x0 > X Error: RenderBadGlyphSet (invalid GlyphSet parameter) 177 > Extension: 152 (RENDER) > Minor opcode: 25 (RenderCompositeGlyphs32) > Resource id: 0x0 > X Error: RenderBadGlyphSet (invalid GlyphSet parameter) 177 > Extension: 152 (RENDER) > Minor opcode: 25 (RenderCompositeGlyphs32) > Resource id: 0x0 > > .. and so on > > I attatched a small example to this mail. > > Could anybody tell me what I'm doing wrong? > Thanks for you help, > Lukas > > logging_error.py > 3KViewDownload Google seems to have swallowed my first attempt to reply, trying again... The following slightly modified script http://dpaste.com/hold/2947/ seems to work as expected (see screenshot at http://i722.photobucket.com/albums/ww224/vsajip/screenshot.png) I just changed the script because my KDE doesn't have QPlainTextEdit, so I used just plain QTextEdit instead. I also modified the thread run method to loop over 10 seconds, so that I could show multiple threads interleaving their output with messages from main window/log window. Tested on Kubuntu (Hardy, KDE3) with SIP 4.7.9 and PyQt 4.4.4 running on Qt 4.3.4. Regards, Vinay Sajip From wuwei23 at gmail.com Fri Feb 27 22:17:23 2009 From: wuwei23 at gmail.com (alex23) Date: Fri, 27 Feb 2009 19:17:23 -0800 (PST) Subject: Guidance on writing a top-like console References: Message-ID: On Feb 28, 8:08?am, ntwrkd wrote: > I am interested in writing an application that functions like a Unix > or Linux top in the way it displays data. > It should be command-line based but dynamically refreshing. > > I'm not sure what I should take into account or how I might go about > implementing this? > Any suggestions are appreciated. Urwid is a Python console UI lib and is definitely what I'd turn to for something like this: http://excess.org/urwid/ From sammo2828 at gmail.com Fri Feb 27 22:21:53 2009 From: sammo2828 at gmail.com (Sammo) Date: Fri, 27 Feb 2009 19:21:53 -0800 (PST) Subject: What's so wrong about execfile? Message-ID: Given that execfile has been removed in py3k, I want to understand exactly why. Okay, I get that execfile is bad from the following thread: On Jul 29 2007, 2:39 pm, Steven D'Aprano wrote: > (1) Don't use eval, exec or execfile. > > (2) If you're an expert, don't use eval, exec or execfile. > > (3) If you're an expert, and are fully aware of the security risks, don't > use eval, exec or execfile. > > (4) If you're an expert, and are fully aware of the security risks, and > have a task that can only be solved by using eval, exec or execfile, find > another solution. > > (5) If there really is no other solution, you haven't looked hard enough. > > (6) If you've looked REALLY hard, and can't find another solution, AND > you're an expert and are fully aware of the security risks, THEN you can > think about using eval, exec or execfile. What are some of the reasons why execfile should not be used? What are some examples of cases where execfile is the correct way of doing something? From steve at holdenweb.com Fri Feb 27 23:09:36 2009 From: steve at holdenweb.com (Steve Holden) Date: Fri, 27 Feb 2009 23:09:36 -0500 Subject: Queries In-Reply-To: References: Message-ID: Dennis Lee Bieber wrote: > On Fri, 27 Feb 2009 15:39:13 -0800 (PST), mmcclaf > declaimed the following in gmane.comp.python.general: > >> This came in the Python groups, and I put one up in the database >> group, since I will later have to use Python to access the SQL file, [...] >> The relational algebra, I am able to translate it into SQL, or most of > > ... and formal relational algebra is a notation many users of database > engines like MySQL, SQLite, Access/JET, Visual FoxPro, Paradox, Sybase, > etc. have never encountered -- heck, Access tries to hide SQL from the > user via a form of QBE interface. > > If I were to attempt a textual version of relational algebra, you'd > be getting something on the order of: > > t1 = Ships x Classes > t2 = restrict t1(Ships.class = Classes.class) > res = project t2(Ships.name, Classes.class, Classes.country) > > instead of straight forward SQL > > select Ships.name, Classes.class, Classes.country from Ships > inner join Classes > on Ships.class = Classes.class > > I think the real problem is that the database design the OP is using os far from normalized. This will tend to contort the logic, as well as making the programming harder to understand. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From pavlovevidence at gmail.com Sat Feb 28 00:15:15 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 27 Feb 2009 21:15:15 -0800 (PST) Subject: What's so wrong about execfile? References: Message-ID: On Feb 27, 7:21?pm, Sammo wrote: > Given that execfile has been removed in py3k, I want to understand > exactly why. > > Okay, I get that execfile is bad from the following thread: > > On Jul 29 2007, 2:39 pm, Steven D'Aprano > > > > wrote: > > (1) Don't use eval, exec or execfile. > > > (2) If you're an expert, don't use eval, exec or execfile. > > > (3) If you're an expert, and are fully aware of the security risks, don't > > use eval, exec or execfile. > > > (4) If you're an expert, and are fully aware of the security risks, and > > have a task that can only be solved by using eval, exec or execfile, find > > another solution. > > > (5) If there really is no other solution, you haven't looked hard enough. > > > (6) If you've looked REALLY hard, and can't find another solution, AND > > you're an expert and are fully aware of the security risks, THEN you can > > think about using eval, exec or execfile. > > What are some of the reasons why execfile should not be used? > > What are some examples of cases where execfile is the correct way of > doing something? You didn't quote the context of Steven's reply, so I don't know if he was talking in general, or for a particular situation. I suspect it was the latter, though. Anyway, there is one generally valid use case for these three: when it's your deliberate intention to give the user the power to run arbitrary Python code. If you really want to give the user this power, and the user is trusted on whatever machine they are running it on, go ahead and use it. No apology necessary. [For instance, the package I use to generate my web site uses exec and eval, because it processes templates with embedded Python code. It's all generated statically, on my own desktop, and I author all the pages myself, so there is no security risk. If I were to distribute this package (and I do, though not many people use it, because everyone just writes their own HTML templates), there would be no risk because the user is expected to be able to run Python, and if they can be trusted to run Python on their own system, they can be trusted to run my program, which execs templates that they write themselves.] I would suggest, however, that even if that is your intention that you consider leveraging Python's built-in import infrastructure. Instead of execfile, you could have your program simply import a module the user writes (after adding a user-specific directory to sys.path). Now, here are a few situations where you should follow Steven's advice above (i.e., don't, ever): - Don't ever use exec or eval to construct a variable name dynamically. Don't ever do this, for instance: x = eval("self","%s%d" % (name,index)) This is unforgiveable. Python has better and safer ways to do this (use getattr, setattr, globals, and locals built-ins). And if you find yourself using them a lot, it's a red flag that you should be using dicts instead. - Don't ever pass any data to exec or eval that you didn't either write, or thoroughly inspect, yourself. Especially don't pass it any data you received over the network. You have to be the super extreme expert that Steven described, and own a lot of liability insurance, befor you can do that. Carl Banks From zaheer.agadi at gmail.com Sat Feb 28 00:17:41 2009 From: zaheer.agadi at gmail.com (zaheer.agadi at gmail.com) Date: Fri, 27 Feb 2009 21:17:41 -0800 (PST) Subject: what does this mean....? Message-ID: <5dbba95b-de47-4ba6-bcd1-e5198fbaa13f@v19g2000yqn.googlegroups.com> I am trying to download a file from the server, I am getting this error,what does this mean localFile = open(localFileName, 'wb') TypeError: coercing to Unicode: need string or buffer, type found From python at rcn.com Sat Feb 28 00:26:44 2009 From: python at rcn.com (Raymond Hettinger) Date: Fri, 27 Feb 2009 21:26:44 -0800 (PST) Subject: Proposed implementation for an Ordered Dictionary References: <5c65efb2-0862-4b85-bb37-88687ac6fedd@q9g2000yqc.googlegroups.com> <871vtk7ub8.fsf@mulj.homelinux.net> <7xd4d4hjaq.fsf@ruckus.brouhaha.com> <6d818c3d-1d6d-4720-8775-427b3832c590@u18g2000pro.googlegroups.com> <7x63iwg2wg.fsf@ruckus.brouhaha.com> <6f52f838-d435-40b8-865e-55f3aed1bb1e@w24g2000prd.googlegroups.com> <5a96c945-7b61-4dba-af20-a324fd3b3394@z9g2000yqi.googlegroups.com> <7xfxi08da9.fsf@ruckus.brouhaha.com> <3d0a5145-2202-418a-97cc-cbe9c04def16@h5g2000yqh.googlegroups.com> Message-ID: <0cde26ce-4fa8-4975-961a-ab4e4512715a@i2g2000prd.googlegroups.com> [Steve Holden] > A sort of premature pessimization, then. QOTW! _ ~ @ @ \_/ Raymond From sjmachin at lexicon.net Sat Feb 28 00:50:27 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 27 Feb 2009 21:50:27 -0800 (PST) Subject: what does this mean....? References: <5dbba95b-de47-4ba6-bcd1-e5198fbaa13f@v19g2000yqn.googlegroups.com> Message-ID: On Feb 28, 4:17?pm, zaheer.ag... at gmail.com wrote: > I am trying to download a file from the server, I am getting this > error,what does this mean > > ? ?localFile = open(localFileName, 'wb') > TypeError: coercing to Unicode: need string or buffer, type found the name localFileName is bound to a type ... and of course it's expecting a string. You must have done something weird with localFileName, like this: | >>> fname = type(2) | >>> fname | | >>> f = open(fname) | Traceback (most recent call last): | File "", line 1, in | TypeError: coercing to Unicode: need string or buffer, type found | >>> From rhodri at wildebst.demon.co.uk Sat Feb 28 00:50:38 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sat, 28 Feb 2009 05:50:38 -0000 Subject: what does this mean....? In-Reply-To: <5dbba95b-de47-4ba6-bcd1-e5198fbaa13f@v19g2000yqn.googlegroups.com> References: <5dbba95b-de47-4ba6-bcd1-e5198fbaa13f@v19g2000yqn.googlegroups.com> Message-ID: On Sat, 28 Feb 2009 05:17:41 -0000, wrote: > I am trying to download a file from the server, I am getting this > error,what does this mean > > localFile = open(localFileName, 'wb') > TypeError: coercing to Unicode: need string or buffer, type found The rest of the traceback and enough of your code to make sense of it would have helped. Without context, my best guess is that "localFileName" isn't actually a string. -- Rhodri James *-* Wildebeeste Herder to the Masses From ken at seehart.com Sat Feb 28 01:06:26 2009 From: ken at seehart.com (Ken Seehart) Date: Fri, 27 Feb 2009 22:06:26 -0800 Subject: How do I count the distance between strings in a list? In-Reply-To: <05e9fe5f-f0ea-475f-b8f6-b9e6c99f3c21@t11g2000yqg.googlegroups.com> References: <05e9fe5f-f0ea-475f-b8f6-b9e6c99f3c21@t11g2000yqg.googlegroups.com> Message-ID: <49A8D462.1090108@seehart.com> collin wrote: > For example, if I were to have the code > > randomlist = ["1", "2", "3", "4"] > > And I want to count the distance between strings "1" and "4" which is > 3, what command can I use to do this? > -- > http://mail.python.org/mailman/listinfo/python-list > > randomlist.index("4") - randomlist.index("1") Ken From stefan_ml at behnel.de Sat Feb 28 01:38:41 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 28 Feb 2009 07:38:41 +0100 Subject: Define a constant in Python C extension In-Reply-To: <22eda701-7048-458c-9e56-80bafbbcb81f@z6g2000pre.googlegroups.com> References: <22eda701-7048-458c-9e56-80bafbbcb81f@z6g2000pre.googlegroups.com> Message-ID: <49a8dbf1$0$32679$9b4e6d93@newsspool2.arcor-online.net> fredbasset1000 at gmail.com wrote: > I'm writing a C extension for Python, is it possible to define > constants in the C code and have them visible from Python? Have you looked at Cython? It allows you to define e.g. enums as "public" and will generate the rest for you. http://cython.org Stefan From zaheer.agadi at gmail.com Sat Feb 28 01:44:28 2009 From: zaheer.agadi at gmail.com (zaheer.agadi at gmail.com) Date: Fri, 27 Feb 2009 22:44:28 -0800 (PST) Subject: what does this mean....? References: <5dbba95b-de47-4ba6-bcd1-e5198fbaa13f@v19g2000yqn.googlegroups.com> Message-ID: On Feb 28, 10:50 am, "Rhodri James" wrote: > On Sat, 28 Feb 2009 05:17:41 -0000, wrote: > > I am trying to download a file from the server, I am getting this > > error,what does this mean > > > localFile = open(localFileName, 'wb') > > TypeError: coercing to Unicode: need string or buffer, type found > > The rest of the traceback and enough of your code to make sense of > it would have helped. Without context, my best guess is that > "localFileName" isn't actually a string. > > -- > Rhodri James *-* Wildebeeste Herder to the Masses Ohh thats my bad, I was actually passing a file type instead of string,thanks a lot . One question off the topic., How to create a .pyz file. I have python project that has some modules in it , I want to create a zip file so that I can use it as we use java jar file Like I want to do a mypyFiles.pyz --sendFile C:\\testFile I currently have a module that does this when run as single python module, but I want to do same this using a zip file which will have some other modules within it. Any help..? Thanks From gagsl-py2 at yahoo.com.ar Sat Feb 28 03:31:00 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 28 Feb 2009 06:31:00 -0200 Subject: what does this mean....? References: <5dbba95b-de47-4ba6-bcd1-e5198fbaa13f@v19g2000yqn.googlegroups.com> Message-ID: En Sat, 28 Feb 2009 04:44:28 -0200, escribi?: > One question off the topic., Usually it's better to post a separate message. > How to create a .pyz file. I have python project that has some modules > in it , I want to create a zip file so that I can use it as we use > java jar file > Like I want to do a > mypyFiles.pyz --sendFile C:\\testFile > I currently have a module that does this when run as single python > module, but I want to do same this using a zip file which will have > some other modules within it. Just put all your modules inside the zip, and create a __main__.py file. Execute it using: python foo.zip See http://docs.python.org/using/cmdline.html#command-line -- Gabriel Genellina From goodz158 at yahoo.com Sat Feb 28 03:41:41 2009 From: goodz158 at yahoo.com (Good Z) Date: Sat, 28 Feb 2009 00:41:41 -0800 (PST) Subject: Issues using SOAP/WSDL with HTTPS References: <415de41f-418a-4f21-97b7-6037a095ccc1@k1g2000prb.googlegroups.com> <4960d898$0$30239$9b4e6d93@newsspool1.arcor-online.net> <4960e88d$0$28676$7a628cd7@news.club-internet.fr> Message-ID: <331921.78646.qm@web35902.mail.mud.yahoo.com> Hello all, I am new to SOAP/WebServices and getting error when using HTTPS with it. Any help is appreciated. here is what i am doing: import xml import fpconst import SOAPpy from SOAPpy import WSDL wsdlFile = 'https://xxxx..com/webService.wsdl' server = WSDL.Proxy(wsdlFile) It seems the WSDL file has been read but when it tried to GET the XSD file that is there in WSDL file, we get following error. File "", line 1, in File "/var/lib/python-support/python2.5/SOAPpy/WSDL.py", line 62, in __init__ self.wsdl = reader.loadFromStream(stream, wsdlsource) File "/var/lib/python-support/python2.5/SOAPpy/wstools/WSDLTools.py", line 34, in loadFromStream wsdl.load(document) File "/var/lib/python-support/python2.5/SOAPpy/wstools/WSDLTools.py", line 260, in load schema = reader.loadFromNode(WSDLToolsAdapter(self), item) File "/var/lib/python-support/python2.5/SOAPpy/wstools/XMLSchema.py", line 80, in loadFromNode schema.load(reader) File "/var/lib/python-support/python2.5/SOAPpy/wstools/XMLSchema.py", line 1088, in load self.addImportSchema(tp.getSchema()) File "/var/lib/python-support/python2.5/SOAPpy/wstools/XMLSchema.py", line 1205, in getSchema self._schema = reader.loadFromURL(url) File "/var/lib/python-support/python2.5/SOAPpy/wstools/XMLSchema.py", line 111, in loadFromURL reader.loadFromURL(url) File "/var/lib/python-support/python2.5/SOAPpy/wstools/XMLSchema.py", line 266, in loadFromURL self.__node = DOM.loadFromURL(url) File "/var/lib/python-support/python2.5/SOAPpy/wstools/Utility.py", line 614, in loadFromURL file = urlopen(url) File "/var/lib/python-support/python2.5/SOAPpy/wstools/Utility.py", line 155, in urlopen response = conn.getresponse() File "/usr/lib/python2.5/httplib.py", line 931, in getresponse response.begin() File "/usr/lib/python2.5/httplib.py", line 388, in begin version, status, reason = self._read_status() File "/usr/lib/python2.5/httplib.py", line 352, in _read_status raise BadStatusLine(line) Regards, Mike -------------- next part -------------- An HTML attachment was scrubbed... URL: From bignose+hates-spam at benfinney.id.au Sat Feb 28 03:50:59 2009 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Sat, 28 Feb 2009 19:50:59 +1100 Subject: what does this mean....? References: <5dbba95b-de47-4ba6-bcd1-e5198fbaa13f@v19g2000yqn.googlegroups.com> Message-ID: <87wsbbaqrw.fsf@benfinney.id.au> "Gabriel Genellina" writes: > En Sat, 28 Feb 2009 04:44:28 -0200, escribi?: > > > One question off the topic., > > Usually it's better to post a separate message. More specifically (and I only say this because many people seem not to observe the distinction), when starting an entirely new topic of discussion, you should not reply to an existing message since it's then confusingly related with the same thread; instead, compose a *new* message with the appropriate subject. -- \ ?Either he's dead or my watch has stopped.? ?Groucho Marx | `\ | _o__) | Ben Finney From zaheer.agadi at gmail.com Sat Feb 28 04:13:52 2009 From: zaheer.agadi at gmail.com (zaheer.agadi at gmail.com) Date: Sat, 28 Feb 2009 01:13:52 -0800 (PST) Subject: what does this mean....? References: <5dbba95b-de47-4ba6-bcd1-e5198fbaa13f@v19g2000yqn.googlegroups.com> <87wsbbaqrw.fsf@benfinney.id.au> Message-ID: <3826c1e5-6e6c-4c77-bf6f-381739654dd7@33g2000yqm.googlegroups.com> On Feb 28, 1:50 pm, Ben Finney wrote: > "Gabriel Genellina" writes: > > En Sat, 28 Feb 2009 04:44:28 -0200, escribi?: > > > > One question off the topic., > > > Usually it's better to post a separate message. > > More specifically (and I only say this because many people seem not to > observe the distinction), when starting an entirely new topic of > discussion, you should not reply to an existing message since it's > then confusingly related with the same thread; instead, compose a > *new* message with the appropriate subject. > > -- > \ ?Either he's dead or my watch has stopped.? ?Groucho Marx | > `\ | > _o__) | > Ben Finney I agree I should have posted a new topic, Point taken.. Thanks Gabriel ,I will try this if could not get this to work will post a new thread. From jineu21 at hotmail.com Sat Feb 28 05:15:37 2009 From: jineu21 at hotmail.com (Clarendon) Date: Sat, 28 Feb 2009 02:15:37 -0800 (PST) Subject: Delete all items in the list References: <35df0b67-3403-444b-93ba-c516bf67d110@p2g2000prf.googlegroups.com> <50697b2c0902262259t4820cdffj643531e2bbe8cb0d@mail.gmail.com> Message-ID: <9d9282b1-4d5f-48bd-99d4-3bd5c23b52e1@o36g2000yqh.googlegroups.com> Thank you very much for all your replies. I actually used the while loop as the data is not large. But I was looking for a simpler, built in command, something like L.remove('a', all) or L.removeall('a'). Python has re.findall function, but why not removeall, so users have to make up long lines of expression? From nick at craig-wood.com Sat Feb 28 05:30:04 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Sat, 28 Feb 2009 04:30:04 -0600 Subject: Using xreadlines References: <82c7db91-fb61-491e-9ff5-38761c3424e9@g38g2000yqd.googlegroups.com> Message-ID: bearophileHUGS at lycos.com wrote: > Brett Hedges: > > My question is how do I go to a previous line in the file? xreadlines has a file.next() statement that gives the next line, and I need a statement that gives me the previous line.< > > In modern versions of Python you usually don't need xreadlines, > because files are iterable. > > If your files are small, you can just read all the lines in a list > with open(...).readlines(), and then just use the item of the list > with the n-1 index. There is also the linecache module http://docs.python.org/library/linecache.html Which may be useful... -- Nick Craig-Wood -- http://www.craig-wood.com/nick From python at bdurham.com Sat Feb 28 08:12:39 2009 From: python at bdurham.com (python at bdurham.com) Date: Sat, 28 Feb 2009 08:12:39 -0500 Subject: Proposed implementation for an Ordered Dictionary In-Reply-To: <0cde26ce-4fa8-4975-961a-ab4e4512715a@i2g2000prd.googlegroups.com> References: <5c65efb2-0862-4b85-bb37-88687ac6fedd@q9g2000yqc.googlegroups.com> <871vtk7ub8.fsf@mulj.homelinux.net> <7xd4d4hjaq.fsf@ruckus.brouhaha.com> <6d818c3d-1d6d-4720-8775-427b3832c590@u18g2000pro.googlegroups.com> <7x63iwg2wg.fsf@ruckus.brouhaha.com> <6f52f838-d435-40b8-865e-55f3aed1bb1e@w24g2000prd.googlegroups.com> <5a96c945-7b61-4dba-af20-a324fd3b3394@z9g2000yqi.googlegroups.com> <7xfxi08da9.fsf@ruckus.brouhaha.com> <3d0a5145-2202-418a-97cc-cbe9c04def16@h5g2000yqh.googlegroups.com> <0cde26ce-4fa8-4975-961a-ab4e4512715a@i2g2000prd.googlegroups.com> Message-ID: <1235826759.2954.1302874671@webmail.messagingengine.com> >> A sort of premature pessimization, then. QOTW! +1 Malcolm From mdw at distorted.org.uk Sat Feb 28 08:54:40 2009 From: mdw at distorted.org.uk (Mark Wooding) Date: Sat, 28 Feb 2009 13:54:40 +0000 Subject: why cannot assign to function call References: <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <0178651d$0$8693$c3e8da3@news.astraweb.com> Message-ID: <87myc6oee7.fsf.mdw@metalzone.distorted.org.uk> Ethan Furman writes: > Mark Wooding wrote: >> Here's what I think is the defining property of pass-by-value [...]: >> >> The callee's parameters are /new variables/, initialized /as if by >> assignment/ from the values of caller's argument expressions. >> >> My soundbite definition for pass-by-reference is this: >> >> The callee's parameters are merely /new names/ for the caller's >> argument variables -- as far as that makes sense. > > Greetings, Mark! You posted to the whole group -- probably using a wide-reply option while reading the mailing list. Still, I'll give an answer here in order to help any other readers of the list or newsgroup. However, as far as I'm concerned, this discussion is basically at an end and I'm not really interested in starting it up all over again. To that end, I've set followups to `poster'. I shall continue reply to private email which seems interested in a sensible discussion. > I was hoping you might be able to clarify those last two sound bites > for me -- I think I understand what you are saying, but I'm confused > about how they relate to Python... > > Specifically, how is a new name (pbr) different, in Python, from a new > name initialized as if by assignment (pbv)? It seems to me than you > end up with the same thing in either case (in Python, at least), > making the distinction non-existent. You've missed a level of indirection. In particular, `names' aren't things that you initialize. They're things that you /bind/ to variables. The crucial difference is that, in pass-by-value, new variables are created as an intrinsic part of the process, whereas in pass-by-reference, new variables are not (usually) created, and instead the formal parameter names are bound to the caller's pre-existing argument variables. It's worth noting that I use the terms `name' and `binding' in different ways from most of the Python community. This is unfortunate. The discrepancy is actually because the Python meanings of these words are not the same as the meanings in the wider computer science and mathematical communities. For example, many Python users seem to use `binding' to mean `assignment', which is a shame because it leaves the concept that is usually called `binding' without a name. So I'll stick with the wider meanings. A while ago, I posted an essay -- to this group -- which may help explain the concepts: Message-ID: <8763k14nc6.fsf.mdw at metalzone.distorted.org.uk> http://groups.google.com/group/comp.lang.python/msg/f6f1a321f819d02b On with the question. > def func(bar): > bar.pop() > > Pass-by-reference: > foo = ['Ethan','Furman'] > func(foo) # bar = foo > > Pass-by-value: > foo = ['Python','Rocks!'] > func(foo) # bar is new name for foo > # is this any different from above? > > If I have this right, in both cases foo will be reduced to a > single-item list after func. You're correct. So: we can conclude that the above test is not sufficient to distinguish the two cases. > Any further explanation you care to provide will be greatly > appreciated! This test is sufficient to distinguish: def test(x): x = 'clobbered' y = 'virgin' test(y) print y If it prints `virgin' then you have call-by-value. If it prints `clobbered' then you have call-by-reference. Let's examine the two cases, as I did in the essay I cited above. I'll do call-by-value first. First, we define a function `test'. Then, we initialize `y'. It's worth examining this process in detail. The name `y' is initially unbound. so it is implicitly bound to a fresh variable. Then, (a reference to) the string object 'virgin' is stored in this variable. We can show this diagrammatically as follows. y (in global env.) ====> [VAR] ---> 'virgin' (In the diagrams, ===> denotes a binding relationship, between names and variables; and ---> denotes a reference relationship, between variables and values.) Next, we call the `test' function. Call-by-value says that we must evaluate the argument expressions. There's only one: `x'. The value of a name is obtained by (a) finding which variable is bound to the name, and (b) extracting the value from this variable. Well, the variable is the one we just bound, and the value stored is (the reference to) the string 'virgin'. So the result of evaluating the argument expressions is simply (the reference to) that string. The function has one parameter, `y'. A new environment is constructed by extending the global environment. In this new environment, the name `y' is bound to a fresh variable -- distinct from all others, and especially from the variable bound to `x' -- and in that variable we store the value of the corresponding argument expression. Result: the function body is executed in an environment which is like the global environment except that `y' is bound to a fresh variable containing 'virgin'. y (in global env.) ====> [VAR] ---> 'virgin' ^ | x (in function `test') ====> [VAR] -------' Now there's an assignment x = 'clobbered' The name `x' is already bound to a variable. So we modify that variable so that it stores (a reference to) the string 'clobbered'. y (in global env.) ====> [VAR] ---> 'virgin' x (in function `test') ====> [VAR] ---> 'clobbered' And then the function ends. The environment we constructed is forgotten. The variable bound to `x' is lost forever, since it wasn't bound to any other name. Since modifying that variable was the only action carried out in the function, and the variable is now lost, there is no externally observable effect. When we finally print `y', we see `virgin', because the variable bound to `y' was unchanged. y (in global env.) ====> [VAR] ---> 'virgin' So much for call-by-value. How about call-by-reference? Well, everything is the same until the actual call. But then everything changes. Firstly, call-by-reference /doesn't/ evaluate the argument expressions. Instead, we just note that `y' is bound to a particular variable in the global environment. The function has a single parameter `x'. A new environment is constructed by extending the global environment (again): in this new environment, the name `x' is bound to /the same variable/ that `y' is bound to in the global environment. y (in global env.) ====> [VAR] <===== x (in function `test') | | v 'virgin' Now we assign to `x'. The detailed rules are the same: `x' is bound, so we modify the variable it's bound to, so that it stores 'clobbered'. But this time, the variable being clobbered is the /same/ variable that `y' is bound to. So finally, when we print `y', we see the string 'clobbered. y (in global env.) ====> [VAR] <===== x (in function `test') | | v 'clobbered' Now, let's look at your example. > def func(bar): > bar.pop() > > foo = ['Ethan','Furman'] > func(foo) # bar = foo I won't describe this in the same excruciating detail as I did for the one above; but I will make some observations. In call-by-reference, the environment in which the body of `func' is executed is constructed by extending the global environment with a binding of the name `bar' to the same variable as is bound to `foo' in the global environment. There is only the one variable, so obviously both names (considered as expressions) must evaluate to the same value. I won't go into the details of method invocation, which in Python is quite complicated; but `bar.pop()' mutates this value: it modifies it in place. So, when the function returns, `foo' can be seen to print differently. The value is, in some sense, the /same/ value as it was before, in that it occupies the same storage locations, but the contents of those storage locations has been altered. foo =====> [VAR] <===== bar (in global env) | (in function `func') | v ['Ethan', 'Furman'] In call-by-value, `func' executes in an environment constructed by extending the global environment with a binding of `bar' to a /fresh/ variable. This fresh variable is then initialized: we store the value of the argument expression `foo' into it. This value is a reference to the list ['Ethan', 'Furman']. (See, I've stopped parenthesizing the reference stuff, because here it really matters.) So, we have two variables, bound to `foo' and `bar', but both variables refer to the same list object. The body of `func' doesn't modify any variables; rather, it mutates the list object in place (as above). Since both variables refer to the /same/ list object, this mutation is still observable outside of the function. foo =====> [VAR] ---> ['Ethan', 'Furman'] (in global env) ^ | bar =====> [VAR'] ------------' (in function `func') So the reason that your example doesn't distinguish the two cases is because, in both cases, there's still only one value, which is mutated. But there is a conceptual difference, unobservable in this instance, because call-by-reference has two names bound to the same variable, while call-by-value has two names, bound to /distinct/ variables but which both refer to the same value. Finally, it may be instructive to remove the issue of function calling altogether. Consider: foo = ['Ethan', 'Furman'] bar = foo bar.pop() What is the final value of `foo'? Now: x = 'virgin' y = x y = 'clobbered' What is the final value of `x'? Are you enlightened? -- [mdw] From mmcclaf at gmail.com Sat Feb 28 10:00:22 2009 From: mmcclaf at gmail.com (mmcclaf) Date: Sat, 28 Feb 2009 07:00:22 -0800 (PST) Subject: Queries References: Message-ID: <8289ef1a-d128-4eef-95db-dd515c8fff92@n20g2000vba.googlegroups.com> So basically you are complaining that groups don't pick up post by GMail users? As for the SQL thing, you still don't see how I am linking this to SQL? I have to make in your terms: a textual representation of the statements I'd make in SQL. The statement I made with the bold SELECT, etc, replace those with the relational algebra symbols, hence needing to make a relational algebra expression. >> So in short of the responses given, I need to study further: GROUP BY, >> HAVING, AS, COUNT, and subselect queries, right? > Since it's homework, we (this group) won't be giving direct SQL statements... I never said I wanted direct SQL statements, moreso guidance as to what direction I should be heading for each of the queries. I just wanted to make sure that there might not be other things I might want to study as well that might be required for the queries. Try not to interpret what isn't there... I'm looking for help, not direct answers. From cjw at ncf.ca Sat Feb 28 10:58:10 2009 From: cjw at ncf.ca (Colin J. Williams) Date: Sat, 28 Feb 2009 10:58:10 -0500 Subject: Proposed implementation for an Ordered Dictionary In-Reply-To: <6f52f838-d435-40b8-865e-55f3aed1bb1e@w24g2000prd.googlegroups.com> References: <5c65efb2-0862-4b85-bb37-88687ac6fedd@q9g2000yqc.googlegroups.com> <871vtk7ub8.fsf@mulj.homelinux.net> <7xd4d4hjaq.fsf@ruckus.brouhaha.com> <6d818c3d-1d6d-4720-8775-427b3832c590@u18g2000pro.googlegroups.com> <7x63iwg2wg.fsf@ruckus.brouhaha.com> <6f52f838-d435-40b8-865e-55f3aed1bb1e@w24g2000prd.googlegroups.com> Message-ID: <49A95F12.3010906@ncf.ca> Raymond Hettinger wrote: > [Paul Rubin] >> Ehh, I guess I'm not surprised at the slowdown and extra complexity >> from the second dict. Oh well. If the module really turns out to be >> really used a lot, another (messy) approach would be to write a C >> extension that uses a doubly linked list some day. > > That seems like an ideal implementation to me. > > O(1): appending, popping, searching, and deletion > O(n): traversal > > Raymond Sometimes, it's useful to be able to obtain the data in the sorted sequence. You might consider adding functionality like: def seqItems(self): '''To return the items, sorted by key. ''' return [self[k] for k in self.seqKeys()] def seqKeys(self): ''' To return the keys sorted. ''' k= self.keys() k.sort() return k def seqValues(self): ''' To return the values, with their keys, sorted by value. ''' v= [(it[1], it[0]) for it in self.items()] v.sort() return v Colin W. From steve at pearwood.info Sat Feb 28 10:59:18 2009 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 01 Mar 2009 02:59:18 +1100 Subject: Delete all items in the list References: <35df0b67-3403-444b-93ba-c516bf67d110@p2g2000prf.googlegroups.com> <50697b2c0902262259t4820cdffj643531e2bbe8cb0d@mail.gmail.com> Message-ID: <01b9549a$0$20612$c3e8da3@news.astraweb.com> Chris Rebert wrote: > Obviously that equivalence is true, but in this case I'm emphasizing > that it's even worse than that when constant factors are taken into > account. Big-O is nice in the abstract, but in the real-world those > constant factors can matter. > > In pure big-O, it is indeed O(M*N) vs. O(N) > Including constant factors, the performance is roughly 2*M*N*X [X = > overhead of remove()] vs. N, which makes the badness of the algorithm > all the more apparent. So, what you're saying is that if you include a constant factor on one side of the comparison, and neglect the constant factors on the other, the side with the constant factor is worse. Well, duh :) I forget which specific O(N) algorithm you're referring to, but I think it was probably a list comp: L[:] = [x for x in L if x != 'a'] As a wise man once said *wink*, "Big-O is nice in the abstract, but in the real-world those constant factors can matter". This is very true... in this case, the list comp requires creating a new list, potentially resizing it an arbitrary number of times, then possibly garbage collecting the previous contents of L. These operations are not free, and for truly huge lists requiring paging, it could get very expensive. Big Oh notation is good for estimating asymptotic behaviour, which means it is good for predicting how an algorithm will scale as the size of the input increases. It is useless for predicting how fast that algorithm will run, since the actual speed depends on those constant factors that Big Oh neglects. That's not a criticism of Big Oh -- predicting execution speed is not what it is for. For what it's worth, for very small lists, the while...remove algorithm is actually faster that using a list comprehension, despite being O(M*N) versus O(N), at least according to my tests. It's *trivially* faster, but if you're interested in (premature) micro-optimisation, you might save one or two microseconds by using a while loop for short lists (say, around N<=12 or so according to my tests), and swapping to a list comp only for larger input. Now, this sounds silly, and in fact it is silly for the specific problem we're discussing, but as a general technique it is very powerful. For instance, until Python 2.3, list.sort() used a low-overhead but O(N**2) insertion sort for small lists, only kicking off a high-overhead but O(N) sample sort above a certain size. The current timsort does something similar, only faster and more complicated. If I understand correctly, it uses insertion sort to make up short runs of increasing or decreasing values, and then efficiently merges them. -- Steven From steven.oldner at gmail.com Sat Feb 28 11:08:17 2009 From: steven.oldner at gmail.com (steven.oldner) Date: Sat, 28 Feb 2009 08:08:17 -0800 (PST) Subject: Data Coding suggestions References: <477a8bf4-1b3e-4708-affe-7aaef1ac1691@w34g2000yqm.googlegroups.com> Message-ID: <74507389-fc4d-4c14-ba72-193566090b22@x38g2000yqj.googlegroups.com> On Feb 27, 2:04?pm, Rick Dooling wrote: > On Feb 27, 6:42?am, "steven.oldner" wrote: > > > Just learning Python and have a project to create a weekly menu and a > > shopping list from the menu. ? > > Question: ?How should I set up the data? ?I'm looking at maybe 70 menu > > items and maybe 1000 items for the shopping list. ?I need to be able > > to maintain each item also. > > I agree with Mr. Holden. It's a perfect exercise for using Python with > sqlite3. > > And the nice thing about this documentation is it has plenty of good > examples: > > http://docs.python.org/library/sqlite3.html > > Good luck, > > RD Thanks guys. While shopping today I've thought of a few more columns for my data so my first item will be building the 3 DB tables and a way to populate them. Since this was intended to automate what I do on a weekly basis, I didn't think about adding recipes since I know what I need for the family, but that's a good touch. Item 1. Build 3 db tables Item 2. Build app to populate tables. Item 3. Build app to read tables and print lists. Anything else? From steve at pearwood.info Sat Feb 28 11:27:53 2009 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 01 Mar 2009 03:27:53 +1100 Subject: Proposed implementation for an Ordered Dictionary References: <5c65efb2-0862-4b85-bb37-88687ac6fedd@q9g2000yqc.googlegroups.com> <6d818c3d-1d6d-4720-8775-427b3832c590@u18g2000pro.googlegroups.com> <6f52f838-d435-40b8-865e-55f3aed1bb1e@w24g2000prd.googlegroups.com> <49A95F12.3010906@ncf.ca> Message-ID: <01b95b4d$0$20667$c3e8da3@news.astraweb.com> Colin J. Williams wrote: > Sometimes, it's useful to be able to > obtain the data in the sorted sequence. > > You might consider adding functionality > like: > > def seqItems(self): > '''To return the items, sorted > by key. ''' > return [self[k] for k in > self.seqKeys()] Amazingly, the Python time-machine provides such functionality! Using just a handful of pre-existing pieces, you can do this: sorted(mydict.items()) sorted(mydict.keys()) [mydict[x] for x in sorted(mydict.keys)] and any other sequence you might need. That's the beauty of a general purpose programming language. You don't need everything to be a built-in *wink* -- Steven From zaheer.agadi at gmail.com Sat Feb 28 11:34:15 2009 From: zaheer.agadi at gmail.com (zaheer.agadi at gmail.com) Date: Sat, 28 Feb 2009 08:34:15 -0800 (PST) Subject: Creating Zip file like java jar file Message-ID: <10a307fa-c6bb-404a-813c-bd5f0e5fa625@v18g2000pro.googlegroups.com> Hi, I want to create zip file equivalent to java jar file,I created a zip file of my sources and added some __main__.py some how I am getting an error saying __main.py does not exist in the zip file Copyproject(main folder) | |_____src(folder) | | | |__Nertworkpackage | | | | | |__Storepackage | | | | |__FtpPackage |__module1.py | |__module2.py |____ tests |__ module3.py Copyproject(main folder) | |_____src(folder) | | | |__Nertworkpackage | | | | | |__Storepackage | | | | |__FtpPackage |__module1.py | | __module2.py |____ tests |__ module3.py Module1 takes some commandline parameters that will do some operation Like If I say " module1.py --uploadFile " A file should get uploaded (this works) Now I want to do Copyproject.zip --uploadFile to upload the file How should I do this, I tried to put __main__ parallel to src folder it says __Main__.py not found in Copyproject.zip..? From daddysean23 at yahoo.com Sat Feb 28 12:24:00 2009 From: daddysean23 at yahoo.com (Sean Novick) Date: Sat, 28 Feb 2009 09:24:00 -0800 (PST) Subject: TypeErrors Message-ID: <260144.62922.qm@web33003.mail.mud.yahoo.com> I'm having issues with?a phone-number database. Here is a code snippet: ?def menu(): ??????? ??????? print '''Please make a selection from the following options: ??????? To add an Employee - enter: 1 ??????? ??????? For a complete listing of Employees - enter: 2 ??????? To see the 'test page' and exit the database - enter: 3''' ??????? print ??????? return input(":") #Start of Program ??? foo = phonedb() ??? loop = 1 ??? choice = 0 ??? while loop == 1: ??????? choice = menu() ??????? if choice == 1: ??????????? print "Enter the Employee's full name: " ??????????? n = raw_input(':') ??????????? print "Enter the Employee's full telephone number: " ??????????? p = raw_input(':') ??????????? print "Enter the telephone number type:(0 = UNKNOWN, 1 = HOME, 2 = WORK, 3 = FAX, 4 = CELL)" ??????????? t = raw_input(':') ??????????? if t == '0': ??????????????? foo.add(n, p, UNKNOWN) ??????????? if t == '1': ??????????????? foo.add(n, p, HOME) ??????????? if t == '2': ??????????????? foo.add(n, p, WORK) ??????????? if t == '3': ??????????????? foo.add(n, p, FAX) ??????????? if t == '4': ??????????????? foo.add(n, p, CELL) ??????????????? print t ??? ??????? elif choice == 2: ??????????? print(list) ??????????? ??????? loop = 0 It works until I enter "t", then this is what I get: "Please make a selection from the following options: ??????? To add an Employee - enter: 1 ??????? ??????? For a complete listing of Employees - enter: 2 ??????? To see the 'test page' and exit the database - enter: 3" :1 Enter the Employee's full name: :john Enter the Employee's full telephone number: :123-456-7890 Enter the telephone number type:(0 = UNKNOWN, 1 = HOME, 2 = WORK, 3 = FAX, 4 = CELL) :1 First lookup: Traceback (most recent call last): ? File "F:\CSC113 Module 4 CA\sample database.py", line 72, in ??? class phonedb: ? File "F:\CSC113 Module 4 CA\sample database.py", line 146, in phonedb ??? for entry in foo.lookup('reifsch'): ? File "F:\CSC113 Module 4 CA\sample database.py", line 101, in lookup ??? if cmp(e, string) == 0: TypeError: comparison did not return an int >>> I do not know what this error means. I tried to look it up in help, but to no avail. If someone could please help or tell me where I could find an answer. Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From hongyuan1306 at gmail.com Sat Feb 28 12:35:47 2009 From: hongyuan1306 at gmail.com (Yuan HOng) Date: Sun, 1 Mar 2009 01:35:47 +0800 Subject: How best to test functions which use date.today Message-ID: <91320d220902280935l7c3893bemeafd46d1bb3f2201@mail.gmail.com> HI, In my project I have several date related methods which I want tested for correctness. The functions use date.today() in several places. Since this could change every time I run the test, I hope to find someway to fake a date.today. For illustration lets say I have a function: from datetime import date def today_is_2009(): return date.today().year == 2009 To test this I would like to write test function like: def test_today_is_2009(): set_today(date(2008, 12, 31)) assert today_is_2009() == False set_today(date(2009,1,1)) assert today_is_2009() == True The first approach of achieving this purpose is to monkey patch the date.today like: date.today = mytoday But this fails with: TypeError: can't set attributes of built-in/extension type 'datetime.date' A second possibility would be to change the system date (I am running Linux). However the standard Python module doesn't provide a method for this purpose. I could use os.system to issue a date command. But I am not very comfortable with this since changing the system time could break something undesirably. Also I will then have to have root privilege to run my test. Besides, I will have to stop the ntp daemon so it will not inadvertently correct the system clock during the test period. Is there any suggestion from the community on how best to test such functions? -- Hong Yuan ????????? ??????????? http://www.homemaster.cn -------------- next part -------------- An HTML attachment was scrubbed... URL: From rasmussen.bryan at gmail.com Sat Feb 28 12:38:45 2009 From: rasmussen.bryan at gmail.com (bryan rasmussen) Date: Sat, 28 Feb 2009 18:38:45 +0100 Subject: c.Win32_OperatingSystem question. Message-ID: <3bb44c6e0902280938m274bc60fq9c0b304a79cfcfb8@mail.gmail.com> Maybe there's a more specific list I should ask this question on but I don't know what it is. I'm using Tim Golden's wmi stuff, and putting my output into an XML document. I have the following bit of code root = et.Element("locations") ComputerInfo = et.SubElement(root, "ComputerInfo") ComputerName = et.SubElement(ComputerInfo,"ComputerName") ComputerDomain = et.SubElement(ComputerInfo,"Domain") location = et.SubElement(root, "location") locationpath = et.SubElement(location, "locationpath") locationtype = et.SubElement(location, "locationtype") currenttime = et.SubElement(location,"time") currenttimeZone = et.SubElement(ComputerInfo,"timeZone") BootDevice = et.SubElement(ComputerInfo,"BootDevice") BuildNumber = et.SubElement(ComputerInfo,"BuildNumber") BuildType = et.SubElement(ComputerInfo,"BuildType") Caption = et.SubElement(ComputerInfo,"Caption") CodeSet = et.SubElement(ComputerInfo,"CodeSet") CountryCode = et.SubElement(ComputerInfo,"CountryCode") Description = et.SubElement(ComputerInfo,"ComputerDescription") FreePhysicalMemory = et.SubElement(ComputerInfo,"FreeMemory") LocalDateTime = et.SubElement(ComputerInfo,"LocalDateTime") Locale = et.SubElement(ComputerInfo,"Locale") Manufacturer = et.SubElement(ComputerInfo,"Manufacturer") Organization = et.SubElement(ComputerInfo,"ComputerOrganization") OSType = et.SubElement(ComputerInfo,"OperatingSystem") WindowsDirectory = et.SubElement(ComputerInfo,"WindowsDirectory") # print "ok" # time.sleep(3) for oper in c.Win32_OperatingSystem(): # print "here" # time.sleep(3) ComputerName.text = str(oper.Name) ComputerDomain.text = str(oper.Domain) currenttimeZone.text = str(oper.CurrentTimeZone) try: currenttime.text = str(datetime.datetime.utcnow()) BootDevice.text = str(oper.BootDevice) BuildNumber = et.SubElement(oper.BuildNumber) BuildType.text = str(oper.BuildType) Caption.text = str(oper.Caption) CodeSet.text = str(oper.CodeSet) CountryCode.text = str(oper.CountryCode) Description.text = str(oper.ComputerDescription) FreePhysicalMemory.text = str(oper.FreeMemory) LocalDateTime.text = str(oper.LocalDateTime) Locale.text = str(oper.Locale) Manufacturer.text = str(oper.Manufacturer) Organization.text = str(oper.ComputerOrganization) OSType.text = str(oper.OperatingSystem) WindowsDirectory.text = str(oper.WindowsDirectory) At the end of that thhe only text node thaht comes out is ComputerName, WMI is running - Am I using the wrong names for things here? When I try to get the same values using WScript and WQL to extract from Win32_OperatingSystem I get all the values. Best Regards, Bryan Rasmussen From tjreedy at udel.edu Sat Feb 28 12:46:13 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 28 Feb 2009 12:46:13 -0500 Subject: Delete all items in the list In-Reply-To: <01b9549a$0$20612$c3e8da3@news.astraweb.com> References: <35df0b67-3403-444b-93ba-c516bf67d110@p2g2000prf.googlegroups.com> <50697b2c0902262259t4820cdffj643531e2bbe8cb0d@mail.gmail.com> <01b9549a$0$20612$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Big Oh notation is good for estimating asymptotic behaviour, which means it > is good for predicting how an algorithm will scale as the size of the input > increases. It is useless for predicting how fast that algorithm will run, > since the actual speed depends on those constant factors that Big Oh > neglects. That's not a criticism of Big Oh -- predicting execution speed is > not what it is for. > > For what it's worth, for very small lists, the while...remove algorithm is > actually faster that using a list comprehension, despite being O(M*N) > versus O(N), at least according to my tests. It's *trivially* faster, but > if you're interested in (premature) micro-optimisation, you might save one > or two microseconds by using a while loop for short lists (say, around > N<=12 or so according to my tests), and swapping to a list comp only for > larger input. > > Now, this sounds silly, and in fact it is silly for the specific problem > we're discussing, but as a general technique it is very powerful. For > instance, until Python 2.3, list.sort() used a low-overhead but O(N**2) > insertion sort for small lists, only kicking off a high-overhead but O(N) O(NlogN) > sample sort above a certain size. The current timsort does something > similar, only faster and more complicated. If I understand correctly, it > uses insertion sort to make up short runs of increasing or decreasing > values, and then efficiently merges them. It uses binary insertion sort to make runs of 64 (determined by empirical testing). The 'binary' part means that it uses O(logN) binary search rather than O(n) linear search to find the insertion point for each of N items, so that finding insertion points uses only O(NlogN) comparisions (which are relatively expensive). Each of the N insertions is done with a single memmove() call, which typically is relatively fast. So although binary insertion sort is still O(N*N), the coefficient of the N*N term in the time formula is relatively small. The other advantages of timsort are that it exploits existing order in a list while preserving the order of items that compare equal. Terry Jan Reedy From rasmussen.bryan at gmail.com Sat Feb 28 12:47:33 2009 From: rasmussen.bryan at gmail.com (bryan rasmussen) Date: Sat, 28 Feb 2009 18:47:33 +0100 Subject: c.Win32_OperatingSystem question. In-Reply-To: <3bb44c6e0902280938m274bc60fq9c0b304a79cfcfb8@mail.gmail.com> References: <3bb44c6e0902280938m274bc60fq9c0b304a79cfcfb8@mail.gmail.com> Message-ID: <3bb44c6e0902280947q2446c572u873dc906b5ffb7bd@mail.gmail.com> oh I noticed the problem with the BuildNumber = et.SubElement(oper.BuildNumber) instead of BuildNumber = str(oper.BuildNumber) and fixed it. No improvement in results however. Best Regards, Bryan Rasmussen On Sat, Feb 28, 2009 at 6:38 PM, bryan rasmussen wrote: > Maybe there's a more specific list I should ask this question on but I > don't know what it is. I'm using Tim Golden's wmi stuff, and putting > my output into an XML document. > > I have the following bit of code > > > ?root = et.Element("locations") > ? ? ? ?ComputerInfo = et.SubElement(root, "ComputerInfo") > ? ? ? ?ComputerName = et.SubElement(ComputerInfo,"ComputerName") > ? ? ? ?ComputerDomain = et.SubElement(ComputerInfo,"Domain") > > ? ? ? ?location = et.SubElement(root, "location") > ? ? ? ?locationpath = et.SubElement(location, "locationpath") > ? ? ? ?locationtype = et.SubElement(location, "locationtype") > ? ? ? ?currenttime = et.SubElement(location,"time") > > ? ? ? ?currenttimeZone = et.SubElement(ComputerInfo,"timeZone") > ? ? ? ?BootDevice = et.SubElement(ComputerInfo,"BootDevice") > ? ? ? ?BuildNumber = et.SubElement(ComputerInfo,"BuildNumber") > ? ? ? ?BuildType = et.SubElement(ComputerInfo,"BuildType") > ? ? ? ?Caption = et.SubElement(ComputerInfo,"Caption") > ? ? ? ?CodeSet = et.SubElement(ComputerInfo,"CodeSet") > ? ? ? ?CountryCode = et.SubElement(ComputerInfo,"CountryCode") > ? ? ? ?Description = et.SubElement(ComputerInfo,"ComputerDescription") > ? ? ? ?FreePhysicalMemory = et.SubElement(ComputerInfo,"FreeMemory") > ? ? ? ?LocalDateTime = et.SubElement(ComputerInfo,"LocalDateTime") > ? ? ? ?Locale = et.SubElement(ComputerInfo,"Locale") > ? ? ? ?Manufacturer = et.SubElement(ComputerInfo,"Manufacturer") > ? ? ? ?Organization = et.SubElement(ComputerInfo,"ComputerOrganization") > > > ? ? ? ?OSType = et.SubElement(ComputerInfo,"OperatingSystem") > ? ? ? ?WindowsDirectory = et.SubElement(ComputerInfo,"WindowsDirectory") > > ? ? ? ?# print ?"ok" > ? ? ? ?# time.sleep(3) > > > ? ? ? ?for oper in c.Win32_OperatingSystem(): > ? ? ? ? ?# print "here" > ? ? ? ? ?# time.sleep(3) > ? ? ? ? ?ComputerName.text = str(oper.Name) > ? ? ? ? ?ComputerDomain.text = str(oper.Domain) > ? ? ? ? ?currenttimeZone.text = str(oper.CurrentTimeZone) > ? ? ? ? ?try: > ? ? ? ? ? ?currenttime.text = str(datetime.datetime.utcnow()) > ? ? ? ? ? ?BootDevice.text = str(oper.BootDevice) > ? ? ? ? ? ?BuildNumber = et.SubElement(oper.BuildNumber) > ? ? ? ? ? ?BuildType.text = str(oper.BuildType) > ? ? ? ? ? ?Caption.text = str(oper.Caption) > ? ? ? ? ? ?CodeSet.text = str(oper.CodeSet) > ? ? ? ? ? ?CountryCode.text = str(oper.CountryCode) > ? ? ? ? ? ?Description.text = str(oper.ComputerDescription) > ? ? ? ? ? ?FreePhysicalMemory.text = str(oper.FreeMemory) > ? ? ? ? ? ?LocalDateTime.text = str(oper.LocalDateTime) > ? ? ? ? ? ?Locale.text = str(oper.Locale) > ? ? ? ? ? ?Manufacturer.text = str(oper.Manufacturer) > ? ? ? ? ? ?Organization.text = str(oper.ComputerOrganization) > > > ? ? ? ? ? ?OSType.text = str(oper.OperatingSystem) > ? ? ? ? ? ?WindowsDirectory.text = str(oper.WindowsDirectory) > > > At the end of that thhe only text node thaht comes out is > ComputerName, WMI is running - Am I using the wrong names for things > here? When I try to get the same values using WScript and WQL to > extract from Win32_OperatingSystem I get all the values. > > Best Regards, > Bryan Rasmussen > From lie.1296 at gmail.com Sat Feb 28 12:54:05 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 01 Mar 2009 04:54:05 +1100 Subject: How best to test functions which use date.today In-Reply-To: <91320d220902280935l7c3893bemeafd46d1bb3f2201@mail.gmail.com> References: <91320d220902280935l7c3893bemeafd46d1bb3f2201@mail.gmail.com> Message-ID: <49A97A3D.6@gmail.com> Yuan HOng wrote: > HI, > > In my project I have several date related methods which I want tested for > correctness. The functions use date.today() in several places. Since this > could change every time I run the test, I hope to find someway to fake a > date.today. > > For illustration lets say I have a function: > > > from datetime import date > def today_is_2009(): > return date.today().year == 2009 > > To test this I would like to write test function like: > > def test_today_is_2009(): > set_today(date(2008, 12, 31)) > assert today_is_2009() == False > set_today(date(2009,1,1)) > assert today_is_2009() == True > > The first approach of achieving this purpose is to monkey patch the > date.today like: > > date.today = mytoday > > But this fails with: > > TypeError: can't set attributes of built-in/extension type 'datetime.date' This is because today is an attribute. In python, we can override attribute access to become a function call. I don't have python right now, but try this: del date.today date.today = mytoday > A second possibility would be to change the system date (I am running > Linux). However the standard Python module doesn't provide a method for this > purpose. I could use os.system to issue a date command. But I am not very > comfortable with this since changing the system time could break something > undesirably. Also I will then have to have root privilege to run my test. > Besides, I will have to stop the ntp daemon so it will not inadvertently > correct the system clock during the test period. > > Is there any suggestion from the community on how best to test such > functions? It is a very bad idea to change the system date. From gagsl-py2 at yahoo.com.ar Sat Feb 28 13:15:27 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 28 Feb 2009 16:15:27 -0200 Subject: Creating Zip file like java jar file References: <10a307fa-c6bb-404a-813c-bd5f0e5fa625@v18g2000pro.googlegroups.com> Message-ID: En Sat, 28 Feb 2009 14:34:15 -0200, escribi?: > I want to create zip file equivalent to java jar file,I created a zip > file of my sources and added some __main__.py > it says __Main__.py not found in Copyproject.zip..? __main__.py must exist in the root directory. -- Gabriel Genellina From zaheer.agadi at gmail.com Sat Feb 28 13:27:45 2009 From: zaheer.agadi at gmail.com (zaheer.agadi at gmail.com) Date: Sat, 28 Feb 2009 10:27:45 -0800 (PST) Subject: Creating Zip file like java jar file References: <10a307fa-c6bb-404a-813c-bd5f0e5fa625@v18g2000pro.googlegroups.com> Message-ID: On Feb 28, 11:15 pm, "Gabriel Genellina" wrote: > En Sat, 28 Feb 2009 14:34:15 -0200, escribi?: > > > I want to create zip file equivalent to java jar file,I created a zip > > file of my sources and added some __main__.py > > it says __Main__.py not found in Copyproject.zip..? > > __main__.py must exist in the root directory. > > -- > Gabriel Genellina What do you mean by root directory..?What is this directory in Windows..?You mean the top level folder of the project?in my case copyproject folder..? From lie.1296 at gmail.com Sat Feb 28 13:33:38 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 01 Mar 2009 05:33:38 +1100 Subject: Creating Zip file like java jar file In-Reply-To: References: <10a307fa-c6bb-404a-813c-bd5f0e5fa625@v18g2000pro.googlegroups.com> Message-ID: <49A98382.8000007@gmail.com> zaheer.agadi at gmail.com wrote: > On Feb 28, 11:15 pm, "Gabriel Genellina" > wrote: >> En Sat, 28 Feb 2009 14:34:15 -0200, escribi?: >> >>> I want to create zip file equivalent to java jar file,I created a zip >>> file of my sources and added some __main__.py >>> it says __Main__.py not found in Copyproject.zip..? >> __main__.py must exist in the root directory. >> >> -- >> Gabriel Genellina > > What do you mean by root directory..?What is this directory in > Windows..?You mean the top level folder of the project?in my case > copyproject folder..? root directory is the topmost directory (imagine a tree, the root is where all the branches branched from), in this case the root directory is your copyproject main folder. From lie.1296 at gmail.com Sat Feb 28 13:33:38 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 01 Mar 2009 05:33:38 +1100 Subject: Creating Zip file like java jar file In-Reply-To: References: <10a307fa-c6bb-404a-813c-bd5f0e5fa625@v18g2000pro.googlegroups.com> Message-ID: <49A98382.8000007@gmail.com> zaheer.agadi at gmail.com wrote: > On Feb 28, 11:15 pm, "Gabriel Genellina" > wrote: >> En Sat, 28 Feb 2009 14:34:15 -0200, escribi?: >> >>> I want to create zip file equivalent to java jar file,I created a zip >>> file of my sources and added some __main__.py >>> it says __Main__.py not found in Copyproject.zip..? >> __main__.py must exist in the root directory. >> >> -- >> Gabriel Genellina > > What do you mean by root directory..?What is this directory in > Windows..?You mean the top level folder of the project?in my case > copyproject folder..? root directory is the topmost directory (imagine a tree, the root is where all the branches branched from), in this case the root directory is your copyproject main folder. From lists at cheimes.de Sat Feb 28 13:39:35 2009 From: lists at cheimes.de (Christian Heimes) Date: Sat, 28 Feb 2009 19:39:35 +0100 Subject: How best to test functions which use date.today In-Reply-To: <49A97A3D.6@gmail.com> References: <91320d220902280935l7c3893bemeafd46d1bb3f2201@mail.gmail.com> <49A97A3D.6@gmail.com> Message-ID: Lie Ryan wrote: >> But this fails with: >> >> TypeError: can't set attributes of built-in/extension type >> 'datetime.date' > > This is because today is an attribute. In python, we can override > attribute access to become a function call. I don't have python right > now, but try this: > > del date.today > date.today = mytoday It won't work. The datetime module is written in C. You can't modify a C extension. Christian From pafboing at gmail.com Sat Feb 28 13:40:23 2009 From: pafboing at gmail.com (Christian R.) Date: Sat, 28 Feb 2009 13:40:23 -0500 Subject: OTish: convince the team to drop VBScript Message-ID: <88c4def10902281040w1f23b0dfpf9367922782c8471@mail.gmail.com> Hello, Brand new to this list, I've not found a quick way to search the archives, and this is not a technical question. I've just been hired at a digital signage company. They use VBScript for simple-to-medium scripting. I've abandoned it about 8 years ago. I want to convince the manager and the two programmers to switch to Python. My main arguments for Python: - Faster - More powerful - Simpler syntax - More up-to-date, evolving - Modularity - Lots of open source modules - Better for development of "tools" (a goal stated by the mgr) Not so sure: - Easier to integrate/translate with/into C#, which is what is used there for complex development. Am I right? The company does use Python on rare occasions. It all comes down to the prejudices and habits of one of the programmers. His only argument I can't counter -because I don't see the problem- is that "Python modules cause problems for updates to customer's installations". My major points will be: - Easier for all three of us - Stay up-to-date with industry. VBScript soon obsolescent. - Better for the company (state-of-the-art skills, think about the future, assets re-use etc.) Any details or added arguments are welcome. In advance, thanks! From zaheer.agadi at gmail.com Sat Feb 28 13:51:04 2009 From: zaheer.agadi at gmail.com (zaheer.agadi at gmail.com) Date: Sat, 28 Feb 2009 10:51:04 -0800 (PST) Subject: Creating Zip file like java jar file References: <10a307fa-c6bb-404a-813c-bd5f0e5fa625@v18g2000pro.googlegroups.com> Message-ID: On Feb 28, 11:33 pm, Lie Ryan wrote: > zaheer.ag... at gmail.com wrote: > > On Feb 28, 11:15 pm, "Gabriel Genellina" > > wrote: > >> En Sat, 28 Feb 2009 14:34:15 -0200, escribi?: > > >>> I want to create zip file equivalent to java jar file,I created a zip > >>> file of my sources and added some __main__.py > >>> it says __Main__.py not found in Copyproject.zip..? > >> __main__.py must exist in the root directory. > > >> -- > >> Gabriel Genellina > > > What do you mean by root directory..?What is this directory in > > Windows..?You mean the top level folder of the project?in my case > > copyproject folder..? > > root directory is the topmost directory (imagine a tree, the root is > where all the branches branched from), in this case the root directory > is your copyproject main folder. I wonder, I do have the __main__.py in the root directory,but still getting python.exe cannot find __main__.py in CopyProject.zip I used the following command python Copyproject.zip -m __main__.py --uploadFile and also tried with python Copyproject.zip --uploadFile both give me the same error , I can see the sys.path contains the project folder. From rayvd at bludgeon.org Sat Feb 28 13:56:11 2009 From: rayvd at bludgeon.org (Ray Van Dolson) Date: Sat, 28 Feb 2009 10:56:11 -0800 Subject: Python alternatives to Text::SimpleTable? Message-ID: <20090228185611.GA29288@bludgeon.org> So I'm looking for an easy (read: lazy) way to generate output in nice ASCII tables like the Text::SimpleTable[1] module in perl. I've come across two so far in the Python world that look promising[2][3] but I'm wondering if anyone else out there has some recommendations for me. Thanks, Ray [1] http://search.cpan.org/dist/Text-SimpleTable/lib/Text/SimpleTable.pm [2] http://pypi.python.org/pypi/text_table/0.02 [3] http://jefke.free.fr/stuff/python/texttable/ From nytrokiss at gmail.com Sat Feb 28 13:58:26 2009 From: nytrokiss at gmail.com (James Matthews) Date: Sat, 28 Feb 2009 20:58:26 +0200 Subject: ANN: updates to Python-by-example In-Reply-To: <49ff5759-61da-4de2-a226-5f34cd6b324d@x13g2000yqf.googlegroups.com> References: <379a7319-376d-4486-954a-fc7035b0deb9@j38g2000yqa.googlegroups.com> <49ff5759-61da-4de2-a226-5f34cd6b324d@x13g2000yqf.googlegroups.com> Message-ID: <8a6b8e350902281058k6228a721s9c90e1fba123eed3@mail.gmail.com> Thanks for adding this. I needed to show someone some examples... On Fri, Feb 27, 2009 at 5:35 PM, steven.oldner wrote: > On Feb 27, 8:40 am, pyt... at bdurham.com wrote: > > Rainy, > > > > Great stuff! Thanks for your examples with the community!! > > > > Regards, > > Malcolm > > Let me add my thanks! I using it now... > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://www.astorandblack.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at cheimes.de Sat Feb 28 13:59:50 2009 From: lists at cheimes.de (Christian Heimes) Date: Sat, 28 Feb 2009 19:59:50 +0100 Subject: OTish: convince the team to drop VBScript In-Reply-To: <88c4def10902281040w1f23b0dfpf9367922782c8471@mail.gmail.com> References: <88c4def10902281040w1f23b0dfpf9367922782c8471@mail.gmail.com> Message-ID: <49A989A6.5080605@cheimes.de> Christian R. schrieb: > Hello, > > Brand new to this list, I've not found a quick way to search the > archives, and this is not a technical question. > > I've just been hired at a digital signage company. They use VBScript > for simple-to-medium scripting. I've abandoned it about 8 years ago. I > want to convince the manager and the two programmers to switch to > Python. My main arguments for Python: > - Faster > - More powerful > - Simpler syntax > - More up-to-date, evolving > - Modularity > - Lots of open source modules > - Better for development of "tools" (a goal stated by the mgr) - Heavily used by lots of large companies and major players like Google, NASA, CERN ... Check out http://www.python.org/about/success/ > Not so sure: > - Easier to integrate/translate with/into C#, which is what is used > there for complex development. Am I right? Well, there are IronPython and PythonDotNET. The former ist a full blown implementation of Python in .NET sponsored by Microsoft and part of the next release of Visual Studio. The later is a bridge between .NET and CPython. Christian From nytrokiss at gmail.com Sat Feb 28 14:01:27 2009 From: nytrokiss at gmail.com (James Matthews) Date: Sat, 28 Feb 2009 21:01:27 +0200 Subject: What's so wrong about execfile? In-Reply-To: References: Message-ID: <8a6b8e350902281101h2f1b17b9ud8268e0480b7b0d5@mail.gmail.com> It is considered one of the big holes in PHP (Remote file include...) However in Python things can be done securely On Sat, Feb 28, 2009 at 7:15 AM, Carl Banks wrote: > On Feb 27, 7:21 pm, Sammo wrote: > > Given that execfile has been removed in py3k, I want to understand > > exactly why. > > > > Okay, I get that execfile is bad from the following thread: > > > > On Jul 29 2007, 2:39 pm, Steven D'Aprano > > > > > > > > wrote: > > > (1) Don't use eval, exec or execfile. > > > > > (2) If you're an expert, don't use eval, exec or execfile. > > > > > (3) If you're an expert, and are fully aware of the security risks, > don't > > > use eval, exec or execfile. > > > > > (4) If you're an expert, and are fully aware of the security risks, and > > > have a task that can only be solved by using eval, exec or execfile, > find > > > another solution. > > > > > (5) If there really is no other solution, you haven't looked hard > enough. > > > > > (6) If you've looked REALLY hard, and can't find another solution, AND > > > you're an expert and are fully aware of the security risks, THEN you > can > > > think about using eval, exec or execfile. > > > > What are some of the reasons why execfile should not be used? > > > > What are some examples of cases where execfile is the correct way of > > doing something? > > You didn't quote the context of Steven's reply, so I don't know if he > was talking in general, or for a particular situation. I suspect it > was the latter, though. > > Anyway, there is one generally valid use case for these three: when > it's your deliberate intention to give the user the power to run > arbitrary Python code. If you really want to give the user this > power, and the user is trusted on whatever machine they are running it > on, go ahead and use it. No apology necessary. > > [For instance, the package I use to generate my web site uses exec and > eval, because it processes templates with embedded Python code. It's > all generated statically, on my own desktop, and I author all the > pages myself, so there is no security risk. If I were to distribute > this package (and I do, though not many people use it, because > everyone just writes their own HTML templates), there would be no risk > because the user is expected to be able to run Python, and if they can > be trusted to run Python on their own system, they can be trusted to > run my program, which execs templates that they write themselves.] > > I would suggest, however, that even if that is your intention that you > consider leveraging Python's built-in import infrastructure. Instead > of execfile, you could have your program simply import a module the > user writes (after adding a user-specific directory to sys.path). > > > Now, here are a few situations where you should follow Steven's advice > above (i.e., don't, ever): > > - Don't ever use exec or eval to construct a variable name > dynamically. Don't ever do this, for instance: > > x = eval("self","%s%d" % (name,index)) > > This is unforgiveable. Python has better and safer ways to do this > (use getattr, setattr, globals, and locals built-ins). And if you > find yourself using them a lot, it's a red flag that you should be > using dicts instead. > > - Don't ever pass any data to exec or eval that you didn't either > write, or thoroughly inspect, yourself. Especially don't pass it any > data you received over the network. You have to be the super extreme > expert that Steven described, and own a lot of liability insurance, > befor you can do that. > > > Carl Banks > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://www.goldwatches.com/ http://www.jewelerslounge.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From pataphor at gmail.com Sat Feb 28 14:02:38 2009 From: pataphor at gmail.com (pataphor) Date: Sat, 28 Feb 2009 20:02:38 +0100 Subject: KeyedList Message-ID: <20090228200238.0b7dd7f1@hyperspace> The ordered dictionary discussion made me think of another data type which seems to be somewhat related, a kind of ordered dictionary where the order of the items is arbitrary. One can insert items in the middle and still have O(1) access (I think). I have provided a very basic implementation, it could be extended to also remove items with O(1) access. I am wondering if the idea makes sense at all and what would be the best name for the type itself and for its methods. Could it be that the ordered dictionary is a result of a way of thinking which slowly extends what we currently have, while a KeyedList or whatever we ultimately choose to name it is the kind of data type we are really looking for? If accepted, I think this type could be used for Knuth's dancing links style algorithms. P. #warning, embryonic, probably very buggy implementation class Node: def __init__(self, left = None, right = None, key = None, item = None): self.left = left self.right = right self.key = key self.item = item class KeyedList: def __init__(self): self.first = Node() self.last = Node() self.last.left = self.first self.first.right = self.last self.D = {} def append(self, key, item): last = self.last prev = last.left x = Node(prev,last,key,item) prev.right = x last.left = x self.D[key] = x def insertafter(self,key1,key2,item): left = self.D[key1] right = left.right x = Node(left,right,key2,item) left.right =x right.left =x self.D[key2] = x def iteritems(self): x = self.first.right while x.right: key = x.key yield key, self.D[key].item x = x.right def test(): K = KeyedList() K.append('one','hello') K.append('two','hello') K.append('four','hello') K.insertafter('two','three','hello') for x in K.iteritems(): print x if __name__ == '__main__': test() From kwmsmith at gmail.com Sat Feb 28 14:08:07 2009 From: kwmsmith at gmail.com (Kurt Smith) Date: Sat, 28 Feb 2009 13:08:07 -0600 Subject: Data Coding suggestions In-Reply-To: <74507389-fc4d-4c14-ba72-193566090b22@x38g2000yqj.googlegroups.com> References: <477a8bf4-1b3e-4708-affe-7aaef1ac1691@w34g2000yqm.googlegroups.com> <74507389-fc4d-4c14-ba72-193566090b22@x38g2000yqj.googlegroups.com> Message-ID: On Sat, Feb 28, 2009 at 10:08 AM, steven.oldner wrote: > > Thanks guys. ?While shopping today I've thought of a few more columns > for my data so my first item will be building the 3 DB tables and a > way to populate them. ?Since this was intended to automate what I do > on a weekly basis, I didn't think about adding recipes since I know > what I need for the family, but that's a good touch. > > Item 1. Build 3 db tables > Item 2. Build app to populate tables. > Item 3. Build app to read tables and print lists. > > Anything else? You might take a look at the source code for the Gourmet Recipe Manager http://grecipe-manager.sourceforge.net/ It's written in python, has a persistent database (not sure if using sqlite3) and you might be able to adapt it to your needs. We use it for our shopping lists here and it's great. Kurt From benjamin.kaplan at case.edu Sat Feb 28 14:10:24 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sat, 28 Feb 2009 14:10:24 -0500 Subject: TypeErrors In-Reply-To: <260144.62922.qm@web33003.mail.mud.yahoo.com> References: <260144.62922.qm@web33003.mail.mud.yahoo.com> Message-ID: On Sat, Feb 28, 2009 at 12:24 PM, Sean Novick wrote: > I'm having issues with a phone-number database. > Here is a code snippet: > def menu(): > > print '''Please make a selection from the following options: > To add an Employee - enter: 1 > > For a complete listing of Employees - enter: 2 > To see the 'test page' and exit the database - enter: 3''' > print > return input(":") > #Start of Program > foo = phonedb() > loop = 1 > choice = 0 > while loop == 1: > choice = menu() > if choice == 1: > print "Enter the Employee's full name: " > n = raw_input(':') > print "Enter the Employee's full telephone number: " > p = raw_input(':') > print "Enter the telephone number type:(0 = UNKNOWN, 1 = HOME, > 2 = WORK, 3 = FAX, 4 = CELL)" > t = raw_input(':') > if t == '0': > foo.add(n, p, UNKNOWN) > if t == '1': > foo.add(n, p, HOME) > if t == '2': > foo.add(n, p, WORK) > if t == '3': > foo.add(n, p, FAX) > if t == '4': > foo.add(n, p, CELL) > print t > > elif choice == 2: > print(list) > > loop = 0 > It works until I enter "t", then this is what I get: > "Please make a selection from the following options: > To add an Employee - enter: 1 > > For a complete listing of Employees - enter: 2 > To see the 'test page' and exit the database - enter: 3" > :1 > Enter the Employee's full name: > :john > Enter the Employee's full telephone number: > :123-456-7890 > Enter the telephone number type:(0 = UNKNOWN, 1 = HOME, 2 = WORK, 3 = FAX, > 4 = CELL) > :1 > First lookup: > Traceback (most recent call last): > File "F:\CSC113 Module 4 CA\sample database.py", line 72, in > class phonedb: > File "F:\CSC113 Module 4 CA\sample database.py", line 146, in phonedb > for entry in foo.lookup('reifsch'): > File "F:\CSC113 Module 4 CA\sample database.py", line 101, in lookup > if cmp(e, string) == 0: > TypeError: comparison did not return an int > >>> > I do not know what this error means. I tried to look it up in help, but to > no avail. If someone could please help or tell me where I could find an > answer. Thanks. > Do you see the little part where it tells you? Your problem has nothing to do with the stuff you showed us. It took place in simple database.py, line 101. At the point "if cmp(e, string) == 0". First of all, why are you doing cmp(e,string)==0? Use "if e == string" instead. It's the same thing (sometimes even calls the same code), but it's easier to read. The problem was exactly what it said: the __cmp__ method in whatever class e is needs to return an int. It isn't, so you get this problem Also, in new code, it's considered better to use rich comparisons (__eq__, __ne__, etc.) rather than __cmp__. That's another reason to use e == string. If e uses __eq__, == will work. If e uses __cmp__, == will still work. -------------- next part -------------- An HTML attachment was scrubbed... URL: From kmcbrearty at yahoo.com Sat Feb 28 14:13:35 2009 From: kmcbrearty at yahoo.com (KMCB) Date: Sat, 28 Feb 2009 11:13:35 -0800 (PST) Subject: Static Map Message-ID: <1f62eead-4652-4470-8085-6bbb85932908@a12g2000yqm.googlegroups.com> Hello, I'm interested in creating a static map of a region in the US. This map would be set into a picture format, so I can add it to a document. I would like it to contain some town names and road information. Then I would like to add points, based on LAT and LONG, that can be labeled with information I provide. I have done some searching, Google Maps probably will not work because of the License. WuGeo does not seam to have the details. I was considering tw.openlayers, but do not know if that is the best starting point. If I could not create the picture from Python, would use tw and then create a screen shot to get started. Does anyone have thoughts on a better approach? KMCB From mail at timgolden.me.uk Sat Feb 28 14:15:40 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Sat, 28 Feb 2009 19:15:40 +0000 Subject: c.Win32_OperatingSystem question. In-Reply-To: <3bb44c6e0902280938m274bc60fq9c0b304a79cfcfb8@mail.gmail.com> References: <3bb44c6e0902280938m274bc60fq9c0b304a79cfcfb8@mail.gmail.com> Message-ID: <49A98D5C.2090408@timgolden.me.uk> bryan rasmussen wrote: > Maybe there's a more specific list I should ask this question on but I > don't know what it is. I'm using Tim Golden's wmi stuff, and putting > my output into an XML document. > > I have the following bit of code > [.. snip ...] > > At the end of that thhe only text node thaht comes out is > ComputerName, WMI is running - Am I using the wrong names for things > here? When I try to get the same values using WScript and WQL to > extract from Win32_OperatingSystem I get all the values. I'd love to help here, but you're not making it easy. I'm not clear if you're suggesting there's a problem with WMI or with ElementTree or with something else. Can you narrow down, please so I don't have to invent a code wrapper for your code fragment. Try producing an instantly-runnable piece of code which demonstrates the problem and I'll happily have a look from the WMI perspective at least. TJG From rdmurray at bitdance.com Sat Feb 28 14:46:00 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Sat, 28 Feb 2009 19:46:00 +0000 (UTC) Subject: why cannot assign to function call References: <01728080$0$8693$c3e8da3@news.astraweb.com> <531b4545-b26f-44b7-894f-43c0e8c56334@s9g2000prg.googlegroups.com> <2f5d382e-bdeb-4a3e-ac47-cba44e82dc6a@s9g2000prm.googlegroups.com> <01771716$0$8693$c3e8da3@news.astraweb.com> <0178651d$0$8693$c3e8da3@news.astraweb.com> <87myc6oee7.fsf.mdw@metalzone.distorted.org.uk> Message-ID: Mark Wooding wrote: > Ethan Furman writes: > > > Mark Wooding wrote: > >> Here's what I think is the defining property of pass-by-value [...]: > >> > >> The callee's parameters are /new variables/, initialized /as if by > >> assignment/ from the values of caller's argument expressions. > >> > >> My soundbite definition for pass-by-reference is this: > >> > >> The callee's parameters are merely /new names/ for the caller's > >> argument variables -- as far as that makes sense. > > > > Greetings, Mark! > > You posted to the whole group -- probably using a wide-reply option > while reading the mailing list. Still, I'll give an answer here in > order to help any other readers of the list or newsgroup. However, as > far as I'm concerned, this discussion is basically at an end and I'm not > really interested in starting it up all over again. To that end, I've > set followups to `poster'. I shall continue reply to private email > which seems interested in a sensible discussion. I just popped in to this thread, and read the whole thing in a marathon session (why, I'm not quite sure, but somehow I found it interesting :). I'm going to follow up here at the risk of annoying Mark, because I think there may be a way to reconcile the language in a way that is helpful in explaining things to Python beginners. > > I was hoping you might be able to clarify those last two sound bites > > for me -- I think I understand what you are saying, but I'm confused > > about how they relate to Python... I think this is the key point. I am an experienced Python programmer, and I had to think long and hard about what you were saying, Mark, in order to understand how it applied to Python. I think this means that your model and/or your level of abstraction is not "natural" when trying to understand Python programs, and I think I may have figured out why. > > Specifically, how is a new name (pbr) different, in Python, from a new > > name initialized as if by assignment (pbv)? It seems to me than you > > end up with the same thing in either case (in Python, at least), > > making the distinction non-existent. > > You've missed a level of indirection. In particular, `names' aren't > things that you initialize. They're things that you /bind/ to > variables. The crucial difference is that, in pass-by-value, new > variables are created as an intrinsic part of the process, whereas in > pass-by-reference, new variables are not (usually) created, and instead > the formal parameter names are bound to the caller's pre-existing > argument variables. I think that the reason Ethan missed that level of indirection is that Python hides that level of indirection from the programmer. And I think that this is where the conversation between you and Steven got hung up, Mark. You are firmly grounded in how languages work in general, so your conceptual model naturally includes details that Steven's conceptual model can ignore, because he's dealing only with the model used by Python. He can (and wants to!) ignore the level of indirection that Python doesn't even give him access to. In short, there is a reason why you almost never hear the word 'variable' from an experienced Python programmer when talking about the Python model. That level detail is abstracted into something else by the Python conceptual model: it becomes a namespace mapping names to objects. > It's worth noting that I use the terms `name' and `binding' in different > ways from most of the Python community. This is unfortunate. The > discrepancy is actually because the Python meanings of these words are > not the same as the meanings in the wider computer science and > mathematical communities. For example, many Python users seem to use > `binding' to mean `assignment', which is a shame because it leaves the > concept that is usually called `binding' without a name. So I'll stick > with the wider meanings. It seems to me from reading the thread that everyone is actually in pretty good agreement that 'name' is the symbol one types in the program source to denote...something. It's the something where things get tricky. So let's leave name itself alone. But let's replace 'assignment' and 'binding' with the concept that is more natural to Python's model, that of a "mapping". A namespace maps names to objects. If I'm understanding you correctly, Mark, in your model what I'm calling a namespace is the set of variable bindings in a particular environment. Because Python does not allow the programmer to actually rebind a variable (Python handles the association between name and variable completely behind the scenes), Python programmers naturally skip past that name-to-variable binding step, and conceptually think about the name being bound to the _value_ instead. After all, that's the only thing they can change. This may be unfortunate from a precisionist viewpoint, but it is both natural and, IMO, inevitable, because it makes thinking about Python programs more efficient. > A while ago, I posted an essay -- to this group -- which may help > explain the concepts: > > Message-ID: <8763k14nc6.fsf.mdw at metalzone.distorted.org.uk> > http://groups.google.com/group/comp.lang.python/msg/f6f1a321f819d02b > > On with the question. > > > def func(bar): > > bar.pop() > > > > Pass-by-reference: > > foo = ['Ethan','Furman'] > > func(foo) # bar = foo > > > > Pass-by-value: > > foo = ['Python','Rocks!'] > > func(foo) # bar is new name for foo > > # is this any different from above? > > > > If I have this right, in both cases foo will be reduced to a > > single-item list after func. > > You're correct. So: we can conclude that the above test is not > sufficient to distinguish the two cases. Suppose we recast this by saying that the function has a namespace, and in that namespace 'bar' maps to something. What that something is depends on what is passed in that argument position when func is called. The calling code's namespace maps 'foo' to something. When func is called, a mapping to that same object is set up in func's namespace, under the name 'bar'. In Python's conceptual model it doesn't make any sense to ask if the argument is passed by value or by reference. In reality, if I'm understanding you correctly Mark, you are absolutely correct that the 'variable' (the thing actually pointed to by 'name', which is a storage location that contains a pointer to an object) is passed by value. That is, the contents of the storage location that the caller's 'foo' is pointing to is copied into a new storage location that the callee's 'bar' points to. Conceptually, however, that is an implementation detail. Conceptually, the important thing is that a _new mapping_ in a _different namespace_ is set up to the _same object_. That is the semantics that Python the language defines. As Steven said, talking about variables seems to be drilling down into a level of abstraction that is more confusing than it is helpful when you are actually _programming_ in Python. It can be a useful level of abstraction to talk about when trying to explain what is happening to someone with previous experience of other languages, but it isn't useful (in my experience) for everyday Python programming. The reason that is true is because in Python there is _no way_ to get a second reference to the 'variable' that is pointed to by 'foo' or by 'bar'. (Unless you walk into that secret back room, of course, and even then it is hard, I think.) As I said, Python hides that level of detail from the programmer. This means that it effectively does not exist when you program Python, and _this_ is why we get all tangled up in language when we try to discuss it. You, Mark, had to go to great lengths to define your terms, and still a lot of people didn't get it, because in actual, on-the-ground Python programming, variables just don't enter in to it, because they can not be directly manipulated from the Python program. I suspect that the longer one has been a Python programmer, the harder it is to even see this blind spot, and thus the harder it is to respond sensibly to someone new to Python whose conceptual model includes variables that _can_ be accessed and manipulated from the program. I know _I_ had to read and re-read your posts before I finally figured it out (assuming I have!). (FYI, my programming learning path was roughly Basic->FORTRAN ->LISP->assembler->C->Python, and I've been programming Python since 1993 or thereabouts). (BTW, I am not claiming Python is unique in this regard, I'm just talking about how it looks from inside the Python programming mindset.) > > Any further explanation you care to provide will be greatly > > appreciated! > > This test is sufficient to distinguish: > > def test(x): > x = 'clobbered' > > y = 'virgin' > test(y) > print y > > If it prints `virgin' then you have call-by-value. If it prints > `clobbered' then you have call-by-reference. Or if you think in terms of namespace mappings, 'test' cannot change what 'y' is mapped to in the caller's namespace, because (in this function) it has no mapping to that namespace object. It _can_ make changes to the thing that y is mapped _to_, if that thing is mutable. That's the most useful way to think about it that I've found. Your reasoning about variables and call-by-reference and call-by-value, while correct and enlightening at the computer science level, confuses me and makes me less efficient if I think about it while writing a Python program. > Let's examine the two cases, as I did in the essay I cited above. I'll > do call-by-value first. First, we define a function `test'. Then, we > initialize `y'. It's worth examining this process in detail. The name > `y' is initially unbound. so it is implicitly bound to a fresh > variable. Then, (a reference to) the string object 'virgin' is stored > in this variable. We can show this diagrammatically as follows. > > y (in global env.) ====> [VAR] ---> 'virgin' > > (In the diagrams, ===> denotes a binding relationship, between names and > variables; and ---> denotes a reference relationship, between variables > and values.) This diagram is IMO accurate and correct. However, in Python we can never actually touch [VAR] except insofar as we change the right hand side element of the diagram. And we can only do _that_ if we have access to the object that is the global name space, and we mutate that object. So for reasoning about Python programs, I think like this: y (in global namespace) ---> 'virgin' > Next, we call the `test' function. Call-by-value says that we must > evaluate the argument expressions. There's only one: `x'. The value of > a name is obtained by (a) finding which variable is bound to the name, > and (b) extracting the value from this variable. Well, the variable is > the one we just bound, and the value stored is (the reference to) the > string 'virgin'. So the result of evaluating the argument expressions > is simply (the reference to) that string. > > The function has one parameter, `y'. A new environment is constructed > by extending the global environment. In this new environment, the name > `y' is bound to a fresh variable -- distinct from all others, and > especially from the variable bound to `x' -- and in that variable we > store the value of the corresponding argument expression. Result: the > function body is executed in an environment which is like the global > environment except that `y' is bound to a fresh variable containing > 'virgin'. > > y (in global env.) ====> [VAR] ---> 'virgin' > ^ > | > x (in function `test') ====> [VAR] -------' I would describe this (in Python) as follows: we call the test function, passing it x. This means we find the object that x is mapped to in the caller's namespace, and we map 'y' in the function's namespace to the same object: y (in global env.) ---> 'virgin' ^ | x (in function 'test') ---' > Now there's an assignment > > x = 'clobbered' > > The name `x' is already bound to a variable. So we modify that variable > so that it stores (a reference to) the string 'clobbered'. > > y (in global env.) ====> [VAR] ---> 'virgin' > > x (in function `test') ====> [VAR] ---> 'clobbered' Assignment in Python changes a mapping (mutates a namespace object). In this case the mapping being changed is the local function's namespace mapping. We can't affect the caller's namespace mapping, because (in this function) we don't have access to the caller's namespace object. So I would diagram it like this: y (in global env.) -----> 'virgin' x (in function 'test') ----> 'clobbered' > And then the function ends. The environment we constructed is > forgotten. The variable bound to `x' is lost forever, since it wasn't > bound to any other name. Since modifying that variable was the only > action carried out in the function, and the variable is now lost, there > is no externally observable effect. When we finally print `y', we see > `virgin', because the variable bound to `y' was unchanged. > > y (in global env.) ====> [VAR] ---> 'virgin' The function's local namespace is not accessible to the caller, so the caller can't access the object 'clobbered'. Its own namespace mapping is unchanged. The object 'virgin' is unchanged. So the caller sees no change as a result of calling the function. Now, to demonstrate that this model of namespaces-as-mappings (and first level objects themselves) is more useful to the Python programmer than the accurate but too-low-level description in terms of variables, consider this: >>> def test(x): ... x = 'clobbered' ... return locals() >>> y = 'virgin' >>> ns = test(y) >>> print y virgin >>> print ns['x'] clobbered In other words, while thinking about 'variables' and 'pass by value' is _accurate_, it does not add anything to the conceptual model a programmer needs in order to understand and write Python code. Namespaces as first level objects that map names to values, however, is an extremely useful and powerful mental model for programming in Python. The two concepts are conceptually equivalent regardless of implementation details (assuming we say a namespace immutably associates names with variables, which in turn mutably point to values), but the namespace, IMO, is the more useful of the two when reasoning about Python programs. > So much for call-by-value. How about call-by-reference? Well, > everything is the same until the actual call. But then everything > changes. > > Firstly, call-by-reference /doesn't/ evaluate the argument expressions. > Instead, we just note that `y' is bound to a particular variable in the > global environment. The function has a single parameter `x'. A new > environment is constructed by extending the global environment (again): > in this new environment, the name `x' is bound to /the same variable/ > that `y' is bound to in the global environment. > > y (in global env.) ====> [VAR] <===== x (in function `test') > | > | > v > 'virgin' And this is something that you can _never_ do in Python (short of mindbogglingly bad hackery). I know you know that, but the fact that you _cannot_ do it is why people start getting confused when talking about call-by-reference vs call-by-value in a Python context. > Now we assign to `x'. The detailed rules are the same: `x' is bound, so > we modify the variable it's bound to, so that it stores 'clobbered'. > But this time, the variable being clobbered is the /same/ variable that > `y' is bound to. So finally, when we print `y', we see the string > 'clobbered. > > > y (in global env.) ====> [VAR] <===== x (in function `test') > | > | > v > 'clobbered' > > Now, let's look at your example. > > > def func(bar): > > bar.pop() > > > > foo = ['Ethan','Furman'] > > func(foo) # bar = foo > > I won't describe this in the same excruciating detail as I did for the > one above; but I will make some observations. > > In call-by-reference, the environment in which the body of `func' is > executed is constructed by extending the global environment with a > binding of the name `bar' to the same variable as is bound to `foo' in > the global environment. There is only the one variable, so obviously > both names (considered as expressions) must evaluate to the same value. > I won't go into the details of method invocation, which in Python is > quite complicated; but `bar.pop()' mutates this value: it modifies it in > place. So, when the function returns, `foo' can be seen to print > differently. The value is, in some sense, the /same/ value as it was > before, in that it occupies the same storage locations, but the contents > of those storage locations has been altered. > > foo =====> [VAR] <===== bar > (in global env) | (in function `func') > | > v > ['Ethan', 'Furman'] And just to be crystal clear, the above case is _not_ the one Python does. > In call-by-value, `func' executes in an environment constructed by > extending the global environment with a binding of `bar' to a /fresh/ > variable. This fresh variable is then initialized: we store the value > of the argument expression `foo' into it. This value is a reference to > the list ['Ethan', 'Furman']. (See, I've stopped parenthesizing the > reference stuff, because here it really matters.) So, we have two > variables, bound to `foo' and `bar', but both variables refer to the > same list object. The body of `func' doesn't modify any variables; > rather, it mutates the list object in place (as above). Since both > variables refer to the /same/ list object, this mutation is still > observable outside of the function. > > foo =====> [VAR] ---> ['Ethan', 'Furman'] > (in global env) ^ > | > bar =====> [VAR'] ------------' > (in function `func') And for reasoning about Python programs, I would write this diagram (which _is_ the way Python does it) as: foo ---> ['Ethan', 'Furman'] (in global namespace) ^ | bar ------------' (in 'func' namespace) > So the reason that your example doesn't distinguish the two cases is > because, in both cases, there's still only one value, which is mutated. > But there is a conceptual difference, unobservable in this instance, Unobservable in Python because Python gives the programmer no way to create two pointers to the same '[VAR]'. > because call-by-reference has two names bound to the same variable, > while call-by-value has two names, bound to /distinct/ variables but > which both refer to the same value. > > Finally, it may be instructive to remove the issue of function calling > altogether. Consider: > > foo = ['Ethan', 'Furman'] > bar = foo > bar.pop() > > What is the final value of `foo'? > > Now: > > x = 'virgin' > y = x > y = 'clobbered' > > What is the final value of `x'? > > Are you enlightened? Hopefully so! Your explanation of the underlying mechanics of call by reference and call by value is the best I've ever seen, and all that effort you put in to defining your terms earlier in this thread has ultimately paid off. Although this has been long enough already (especially since I quoted your excellent article in full), I still want to go on a bit more. I want to demonstrate the explanatory power of the namespace model, which was one of your arguments with Steven: that his model of Python working directly with values couldn't explain certain things. On of the examples you gave (and I'm doing this from memory) was this: >>> l = [ lambda: x for x in [1,2,3] ] >>> [ f() for f in l ] [3, 3, 3] Your explanation was in terms of variables and environments, and frankly I had a hard time following it (though I get it now). Here's how I explain it in terms of namespaces: lambda creates a closure, and part of the closure is a reference to the locals namespace object that exists when the closure is formed. The (top level of the) list comprehension is operating in the local namespace, so it is this namespace that gets captured inside the closure. When we execute the functions later, what happens is that 'x' is looked up in this namespace, and the object that _it maps to at that time_ is returned. Since the last assignment (mapping) to X was to the object '3', '3' is what is returned by all three functions calls. The code above is equivalent to the following code, which makes is clearer what is happening: >>> l2 = [] >>> for x in 1,2,3: ... l2.append(locals()) >>> [ ns['x'] for ns in l2 ] [3, 3, 3] So in terms of namespaces it is crystal clear why we get three 3s, and why the following produces three 5s: >>> x = 5 >>> [ ns['x'] for ns in l2 ] [5, 5, 5] >>> [ f() for f in l ] [5, 5, 5] This is conceptually equivalent to your variables and environments model, but I think it is easier to understand and reason about, when talking only about Python code, because it elides that level of indirection to which the Python programmer has no access. At least, I find it so! To take the final step toward unifying your view with Steven's view, we have to admit that Python objects that reference other objects can be viewed either as having [VAR] elements containing pointers to objects, or as namespaces referencing other objects, and that these two views are conceptually equivalent. Thus, take your circular list example: >>> a [1, 2, 3] >>> a[1] = a >>> a [1, [...], 3] Your view was that this list must contain a pointer variable which points to the list itself (a reference), while Steven held that Python lists reference other objects directly, and had no problem with this Tardis-like construct. You are obviously correct that what a list is is a sequence of variable slots that can point to any object, including the list itself. But we can also view the list as a namespace whose name elements are a zero-origined, monotonically increasing set of integers, and that within this name space these names map directly to python objects. In Python (or at least in CPython), the two views are equivalent. But I argue, with Steven, that the latter view is more _useful_ for a Python programmer, and that it is in fact Python's conceptual model. I would also argue that the latter view is the one that it is more helpful to explain to newcomers to Python, with due acknowledgement being made to the reality of the behind-the-scenes variables for those coming from a background where that will be helpful. The trick is to get the long-time Python programmers to remember, when talking to such a newcomer, that those variables even exist! --RDM From rdmurray at bitdance.com Sat Feb 28 15:07:44 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Sat, 28 Feb 2009 20:07:44 +0000 (UTC) Subject: TypeErrors References: <260144.62922.qm@web33003.mail.mud.yahoo.com> Message-ID: Sean Novick wrote: > First lookup: > Traceback (most recent call last): > File "F:\CSC113 Module 4 CA\sample database.py", line 72, in > class phonedb: > File "F:\CSC113 Module 4 CA\sample database.py", line 146, in phonedb > for entry in foo.lookup('reifsch'): > File "F:\CSC113 Module 4 CA\sample database.py", line 101, in lookup > if cmp(e, string) =3D=3D 0: > TypeError: comparison did not return an int > > I do not know what this error means. I tried to look it up in help, but to no > avail. If someone could please help or tell me where I could find an answer. > Thanks. The 'cmp' function (which is depricated, by the way) asks the two arguments to compare themselves. It does this by invoking the __cmp__ method on the first object, passing it the second. (Actually it's more complicated than that, but it will do as a partial explanation for now). The __cmp__ method is expected to return an integer, which represents the results of doing the comparison (see the docs if you want to know the values...but as I said cmp and __cmp__ a depricated). So, whatever 'e' is (and we can't tell from the traceback, you'll have to work through your code to figure it out, probably by sprinkling in 'print' statements), its __cmp__ method didn't return an integer. When you fix this, I would recommend converting to using rich comparisons (__eq__, __lt__), etc, since __cmp__ is eventually going away (it doesn't exist in Python 3.x). --RDM From rdmurray at bitdance.com Sat Feb 28 15:19:36 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Sat, 28 Feb 2009 20:19:36 +0000 (UTC) Subject: OTish: convince the team to drop VBScript References: <88c4def10902281040w1f23b0dfpf9367922782c8471@mail.gmail.com> Message-ID: "Christian R." wrote: > The company does use Python on rare occasions. It all comes down to > the prejudices and habits of one of the programmers. His only argument > I can't counter -because I don't see the problem- is that "Python > modules cause problems for updates to customer's installations". You don't really need arguments so much as you need negotiation, people management and (ugh) political skills, I think. Your task is to overcome his prejudices, and you aren't going to do that with arguments, no matter how good. IMO the first thing you ought to do is dig in, really listen, and find out what his issue is with module distribution. Listening well is your most powerful asset. Overcome your own prejudices first, and his may follow :) --RDM From gagsl-py2 at yahoo.com.ar Sat Feb 28 15:32:05 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 28 Feb 2009 18:32:05 -0200 Subject: Creating Zip file like java jar file References: <10a307fa-c6bb-404a-813c-bd5f0e5fa625@v18g2000pro.googlegroups.com> Message-ID: En Sat, 28 Feb 2009 16:51:04 -0200, escribi?: > On Feb 28, 11:33 pm, Lie Ryan wrote: >> zaheer.ag... at gmail.com wrote: >> > On Feb 28, 11:15 pm, "Gabriel Genellina" >> > wrote: >> >> En Sat, 28 Feb 2009 14:34:15 -0200, >> escribi?: >> >> >>> I want to create zip file equivalent to java jar file,I created a >> zip >> >>> file of my sources and added some __main__.py >> >>> it says __Main__.py not found in Copyproject.zip..? >> >> __main__.py must exist in the root directory. >> >> > What do you mean by root directory..?What is this directory in >> > Windows..?You mean the top level folder of the project?in my case >> > copyproject folder..? >> >> root directory is the topmost directory (imagine a tree, the root is >> where all the branches branched from), in this case the root directory >> is your copyproject main folder. > > I wonder, I do have the __main__.py in the root directory,but still > getting > python.exe cannot find __main__.py in CopyProject.zip The top of the tree inside the zip file. Depth zero. Not inside any directory. Above anything else. Just a bare name. Open your zip using the zipfile module: import zipfile z = zipfile.ZipFile("xxx.zip") z.printdir() You should see a line starting with __main__.py *without* any / in it. > I used the following command > python Copyproject.zip -m __main__.py --uploadFile and also tried with > python Copyproject.zip --uploadFile Use the second one. > both give me the same error , I can see the sys.path contains the > project folder. Uh? Which project folder? Isn't it in the .zip? -- Gabriel Genellina From rdmurray at bitdance.com Sat Feb 28 15:34:35 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Sat, 28 Feb 2009 20:34:35 +0000 (UTC) Subject: How best to test functions which use date.today References: <91320d220902280935l7c3893bemeafd46d1bb3f2201@mail.gmail.com> <49A97A3D.6@gmail.com> Message-ID: Christian Heimes wrote: > Lie Ryan wrote: > >> But this fails with: > >> > >> TypeError: can't set attributes of built-in/extension type > >> 'datetime.date' > > > > This is because today is an attribute. In python, we can override > > attribute access to become a function call. I don't have python right > > now, but try this: > > > > del date.today > > date.today = mytoday > > It won't work. The datetime module is written in C. You can't modify a C > extension. Hmm. Given that, Lie, maybe what you need to do is modify your code so that you call your own special purpose function to get 'today', and replace _that_ for testing, using datetime's today for production. --RDM From gagsl-py2 at yahoo.com.ar Sat Feb 28 15:38:01 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 28 Feb 2009 18:38:01 -0200 Subject: How best to test functions which use date.today References: <91320d220902280935l7c3893bemeafd46d1bb3f2201@mail.gmail.com> Message-ID: En Sat, 28 Feb 2009 15:35:47 -0200, Yuan HOng escribi?: > In my project I have several date related methods which I want tested for > correctness. The functions use date.today() in several places. Since this > could change every time I run the test, I hope to find someway to fake a > date.today. > > For illustration lets say I have a function: > > > from datetime import date > def today_is_2009(): > return date.today().year == 2009 > > To test this I would like to write test function like: > > def test_today_is_2009(): > set_today(date(2008, 12, 31)) > assert today_is_2009() == False > set_today(date(2009,1,1)) > assert today_is_2009() == True > Instead of trying to inject a fake date, you could rewrite the function to take a date argument: def today_is_2009(today=None): if today is None: today = date.today() return today.year == 2009 Then, tests should pass a known date. This approach has a drawback -- you don't test the case when no argument is given. Another way is to use a fake date class, or a fake datetime module. Google "python mock object" -- Gabriel Genellina From rdmurray at bitdance.com Sat Feb 28 15:46:42 2009 From: rdmurray at bitdance.com (rdmurray at bitdance.com) Date: Sat, 28 Feb 2009 20:46:42 +0000 (UTC) Subject: Creating Zip file like java jar file References: <10a307fa-c6bb-404a-813c-bd5f0e5fa625@v18g2000pro.googlegroups.com> Message-ID: zaheer.agadi at gmail.com wrote: > On Feb 28, 11:33 pm, Lie Ryan wrote: > > zaheer.ag... at gmail.com wrote: > > > On Feb 28, 11:15 pm, "Gabriel Genellina" > > > wrote: > > >> En Sat, 28 Feb 2009 14:34:15 -0200, escribi= > =F3: > > > > >>> I want to create zip file equivalent to java jar file,I created a zip > > >>> file of my sources and added some __main__.py > > >>> it says __Main__.py not found in Copyproject.zip..? > > >> __main__.py must exist in the root directory. > > > > >> -- > > >> Gabriel Genellina > > > > > What do you mean by root directory..?What is this directory in > > > Windows..?You mean the top level folder of the project?in my case > > > copyproject folder..? > > > > root directory is the topmost directory (imagine a tree, the root is > > where all the branches branched from), in this case the root directory > > is your copyproject main folder. > > > I wonder, I do have the __main__.py in the root directory,but still getting > python.exe cannot find __main__.py in CopyProject.zip > > I used the following command > python Copyproject.zip -m __main__.py --uploadFile and also tried with > python Copyproject.zip --uploadFile > both give me the same error , I can see the sys.path contains the > project folder. How did you create the zip? The __main__.py file has to be at the _top level_ of the zip file. In other words: zip test.zip __main.py othermodule.py somedir works but zip test.zip myproject does not. --RDM From Scott.Daniels at Acm.Org Sat Feb 28 16:01:32 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 28 Feb 2009 13:01:32 -0800 Subject: How best to test functions which use date.today In-Reply-To: References: <91320d220902280935l7c3893bemeafd46d1bb3f2201@mail.gmail.com> Message-ID: Lie Ryan wrote: > Yuan HOng wrote: >> In my project I have several date related methods which I want tested for >> correctness. The functions use date.today() in several places. Since this >> could change every time I run the test, I hope to find someway to fake a >> date.today. >> For illustration lets say I have a function: >> >> from datetime import date >> def today_is_2009(): >> return date.today().year == 2009 >> >> To test this I would like to write test function like: >> >> def test_today_is_2009(): >> set_today(date(2008, 12, 31)) >> assert today_is_2009() == False >> set_today(date(2009,1,1)) >> assert today_is_2009() == True Try something like this: import module_to_test as sut # "sut" -> system under test from datetime import date class FakeDate(object): def __init__(self, value): self._result = value def today(self): return self._result def test_today_is_2009_too_old(): temp, sut.date = sut.date, FakeDate(date(2008, 12, 31)) try: assert not sut.today_is_2009() finally: sut.date = temp def test_today_is_2009_too_young(): temp, sut.date = sut.date, FakeDate(date(2010, 1, 1)) try: assert not sut.today_is_2009() finally: sut.date = temp def test_today_is_2009_just_right(): temp, sut.date = sut.date, FakeDate(date(2009, 1, 1)) try: assert not sut.today_is_2009() finally: sut.date = temp Note: each test should test 1 thing. --Scott David Daniels Scott.Daniels at Acm.Org From andymac at bullseye.apana.org.au Sat Feb 28 17:45:41 2009 From: andymac at bullseye.apana.org.au (Andrew MacIntyre) Date: Sun, 01 Mar 2009 09:45:41 +1100 Subject: Static Map In-Reply-To: <1f62eead-4652-4470-8085-6bbb85932908@a12g2000yqm.googlegroups.com> References: <1f62eead-4652-4470-8085-6bbb85932908@a12g2000yqm.googlegroups.com> Message-ID: <49A9BE95.8070903@bullseye.andymac.org> KMCB wrote: > Hello, > > I'm interested in creating a static map of a region in the US. This > map would be set into a picture format, so I can add it to a > document. I would like it to contain some town names and road > information. Then I would like to add points, based on LAT and LONG, > that can be labeled with information I provide. > > I have done some searching, Google Maps probably will not work because > of the License. WuGeo does not seam to have the details. I was > considering tw.openlayers, but do not know if that is the best > starting point. If I could not create the picture from Python, would > use tw and then create a screen shot to get started. > > Does anyone have thoughts on a better approach? While web-centric, you might find http://www.alistapart.com/articles/takecontrolofyourmaps an interesting read. -- ------------------------------------------------------------------------- Andrew I MacIntyre "These thoughts are mine alone..." E-mail: andymac at bullseye.apana.org.au (pref) | Snail: PO Box 370 andymac at pcug.org.au (alt) | Belconnen ACT 2616 Web: http://www.andymac.org/ | Australia From cosmo_general at yahoo.com Sat Feb 28 18:01:56 2009 From: cosmo_general at yahoo.com (Muddy Coder) Date: Sat, 28 Feb 2009 15:01:56 -0800 (PST) Subject: Bug report: ClientForm Message-ID: Hi Folks, As directed, I got ClientForm and played with it. It is cool! However, I also found a bug: When it parses a form, if the VALUE of a field has not space, it works very well. For example, if a dropdown list, there many options, such as: